1package godo
2
3// SizesService is an interface for interfacing with the size
4// endpoints of the DigitalOcean API
5// See: https://developers.digitalocean.com/documentation/v2#sizes
6type SizesService interface {
7	List(*ListOptions) ([]Size, *Response, error)
8}
9
10// SizesServiceOp handles communication with the size related methods of the
11// DigitalOcean API.
12type SizesServiceOp struct {
13	client *Client
14}
15
16var _ SizesService = &SizesServiceOp{}
17
18// Size represents a DigitalOcean Size
19type Size struct {
20	Slug         string   `json:"slug,omitempty"`
21	Memory       int      `json:"memory,omitempty"`
22	Vcpus        int      `json:"vcpus,omitempty"`
23	Disk         int      `json:"disk,omitempty"`
24	PriceMonthly float64  `json:"price_monthly,omitempty"`
25	PriceHourly  float64  `json:"price_hourly,omitempty"`
26	Regions      []string `json:"regions,omitempty"`
27	Available    bool     `json:"available,omitempty"`
28	Transfer     float64  `json:"transfer,omitempty"`
29}
30
31func (s Size) String() string {
32	return Stringify(s)
33}
34
35type sizesRoot struct {
36	Sizes []Size
37	Links *Links `json:"links"`
38}
39
40// List all images
41func (s *SizesServiceOp) List(opt *ListOptions) ([]Size, *Response, error) {
42	path := "v2/sizes"
43	path, err := addOptions(path, opt)
44	if err != nil {
45		return nil, nil, err
46	}
47
48	req, err := s.client.NewRequest("GET", path, nil)
49	if err != nil {
50		return nil, nil, err
51	}
52
53	root := new(sizesRoot)
54	resp, err := s.client.Do(req, root)
55	if err != nil {
56		return nil, resp, err
57	}
58	if l := root.Links; l != nil {
59		resp.Links = l
60	}
61
62	return root.Sizes, resp, err
63}
64