blob: 2c64908bb114a162b14724209dd0a40aa5037ce0 [file] [log] [blame]
Samuel A. Falvo II10decf92014-02-13 17:05:35 -08001package flavors
2
3import (
Samuel A. Falvo II38c6ad02014-05-06 18:09:46 -07004 "fmt"
5 "net/url"
Samuel A. Falvo II10decf92014-02-13 17:05:35 -08006 "github.com/rackspace/gophercloud/openstack/identity"
Samuel A. Falvo II38c6ad02014-05-06 18:09:46 -07007 "strconv"
Samuel A. Falvo II10decf92014-02-13 17:05:35 -08008)
9
10type Client struct {
Samuel A. Falvo IIe246ac02014-02-13 23:20:09 -080011 endpoint string
Samuel A. Falvo II10decf92014-02-13 17:05:35 -080012 authority identity.AuthResults
Samuel A. Falvo IIe246ac02014-02-13 23:20:09 -080013 options identity.AuthOptions
Samuel A. Falvo II10decf92014-02-13 17:05:35 -080014}
15
16func NewClient(e string, a identity.AuthResults, ao identity.AuthOptions) *Client {
17 return &Client{
Samuel A. Falvo IIe246ac02014-02-13 23:20:09 -080018 endpoint: e,
Samuel A. Falvo II10decf92014-02-13 17:05:35 -080019 authority: a,
Samuel A. Falvo IIe246ac02014-02-13 23:20:09 -080020 options: ao,
Samuel A. Falvo II10decf92014-02-13 17:05:35 -080021 }
22}
23
Samuel A. Falvo II38c6ad02014-05-06 18:09:46 -070024func (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
48func (c *Client) getGetUrl(id string) string {
49 return fmt.Sprintf("%s/flavors/%s", c.endpoint, id)
Samuel A. Falvo II10decf92014-02-13 17:05:35 -080050}
51
52func (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}