Samuel A. Falvo II | 10decf9 | 2014-02-13 17:05:35 -0800 | [diff] [blame] | 1 | package flavors |
| 2 | |
| 3 | import ( |
Samuel A. Falvo II | 38c6ad0 | 2014-05-06 18:09:46 -0700 | [diff] [blame^] | 4 | "fmt" |
| 5 | "net/url" |
Samuel A. Falvo II | 10decf9 | 2014-02-13 17:05:35 -0800 | [diff] [blame] | 6 | "github.com/rackspace/gophercloud/openstack/identity" |
Samuel A. Falvo II | 38c6ad0 | 2014-05-06 18:09:46 -0700 | [diff] [blame^] | 7 | "strconv" |
Samuel A. Falvo II | 10decf9 | 2014-02-13 17:05:35 -0800 | [diff] [blame] | 8 | ) |
| 9 | |
| 10 | type Client struct { |
Samuel A. Falvo II | e246ac0 | 2014-02-13 23:20:09 -0800 | [diff] [blame] | 11 | endpoint string |
Samuel A. Falvo II | 10decf9 | 2014-02-13 17:05:35 -0800 | [diff] [blame] | 12 | authority identity.AuthResults |
Samuel A. Falvo II | e246ac0 | 2014-02-13 23:20:09 -0800 | [diff] [blame] | 13 | options identity.AuthOptions |
Samuel A. Falvo II | 10decf9 | 2014-02-13 17:05:35 -0800 | [diff] [blame] | 14 | } |
| 15 | |
| 16 | func NewClient(e string, a identity.AuthResults, ao identity.AuthOptions) *Client { |
| 17 | return &Client{ |
Samuel A. Falvo II | e246ac0 | 2014-02-13 23:20:09 -0800 | [diff] [blame] | 18 | endpoint: e, |
Samuel A. Falvo II | 10decf9 | 2014-02-13 17:05:35 -0800 | [diff] [blame] | 19 | authority: a, |
Samuel A. Falvo II | e246ac0 | 2014-02-13 23:20:09 -0800 | [diff] [blame] | 20 | options: ao, |
Samuel A. Falvo II | 10decf9 | 2014-02-13 17:05:35 -0800 | [diff] [blame] | 21 | } |
| 22 | } |
| 23 | |
Samuel A. Falvo II | 38c6ad0 | 2014-05-06 18:09:46 -0700 | [diff] [blame^] | 24 | func (c *Client) getListUrl(lfo ListFilterOptions) string { |
| 25 | v := url.Values{} |
| 26 | if lfo.ChangesSince != "" { |
| 27 | v.Set("changes-since", lfo.ChangesSince) |
| 28 | } |
| 29 | if lfo.MinDisk != 0 { |
| 30 | v.Set("minDisk", strconv.Itoa(lfo.MinDisk)) |
| 31 | } |
| 32 | if lfo.MinRam != 0 { |
| 33 | v.Set("minRam", strconv.Itoa(lfo.MinRam)) |
| 34 | } |
| 35 | if lfo.Marker != "" { |
| 36 | v.Set("marker", lfo.Marker) |
| 37 | } |
| 38 | if lfo.Limit != 0 { |
| 39 | v.Set("limit", strconv.Itoa(lfo.Limit)) |
| 40 | } |
| 41 | tail := "" |
| 42 | if len(v) > 0 { |
| 43 | tail = fmt.Sprintf("?%s", v.Encode()) |
| 44 | } |
| 45 | return fmt.Sprintf("%s/flavors/detail%s", c.endpoint, tail) |
| 46 | } |
| 47 | |
| 48 | func (c *Client) getGetUrl(id string) string { |
| 49 | return fmt.Sprintf("%s/flavors/%s", c.endpoint, id) |
Samuel A. Falvo II | 10decf9 | 2014-02-13 17:05:35 -0800 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | func (c *Client) getListHeaders() (map[string]string, error) { |
| 53 | t, err := identity.GetToken(c.authority) |
| 54 | if err != nil { |
| 55 | return map[string]string{}, err |
| 56 | } |
| 57 | |
| 58 | return map[string]string{ |
| 59 | "X-Auth-Token": t.Id, |
| 60 | }, nil |
| 61 | } |