blob: d24108eba78bcd6e5709707427740ba25ac758cf [file] [log] [blame]
Jamie Hannaford4721abc2014-09-16 16:29:04 +02001package extensions
Jamie Hannaford1ce30f22014-09-16 11:23:34 +02002
3import (
4 "github.com/racker/perigee"
5 "github.com/rackspace/gophercloud"
Jamie Hannafordf0c615b2014-09-17 10:56:52 +02006 "github.com/rackspace/gophercloud/pagination"
Jamie Hannaford1ce30f22014-09-16 11:23:34 +02007)
8
Jamie Hannafordc65e1922014-09-22 13:20:58 +02009// Get retrieves information for a specific extension using its alias. If no
10// extension exists with this alias, an error will be returned.
11func Get(c *gophercloud.ServiceClient, alias string) (*Extension, error) {
Jamie Hannaford1ce30f22014-09-16 11:23:34 +020012 var ext Extension
Jamie Hannafordc65e1922014-09-22 13:20:58 +020013 _, err := perigee.Request("GET", extensionURL(c, alias), perigee.Options{
Jamie Hannaford1ce30f22014-09-16 11:23:34 +020014 MoreHeaders: c.Provider.AuthenticatedHeaders(),
15 Results: &struct {
16 Extension *Extension `json:"extension"`
17 }{&ext},
18 OkCodes: []int{200},
19 })
20
21 if err != nil {
22 return nil, err
23 }
24 return &ext, nil
25}
Jamie Hannaford4721abc2014-09-16 16:29:04 +020026
Jamie Hannafordc65e1922014-09-22 13:20:58 +020027// List returns a Pager which allows you to iterate over the full collection of
28// extensions. It does not accept query parameters.
Jamie Hannafordf0c615b2014-09-17 10:56:52 +020029func List(c *gophercloud.ServiceClient) pagination.Pager {
Jamie Hannafordc65e1922014-09-22 13:20:58 +020030 return pagination.NewPager(c, listExtensionURL(c), func(r pagination.LastHTTPResponse) pagination.Page {
Jamie Hannafordf0c615b2014-09-17 10:56:52 +020031 return ExtensionPage{pagination.SinglePageBase(r)}
32 })
Jamie Hannaford4721abc2014-09-16 16:29:04 +020033}