blob: 2ec05a8e3b80516577fdbb6e63bc50d5ebd695f4 [file] [log] [blame]
Joe Topjianf61691c2016-11-05 12:34:59 -06001package projects
2
3import (
Joe Topjian1c236d32017-01-09 15:33:32 -07004 "github.com/gophercloud/gophercloud"
Joe Topjianf61691c2016-11-05 12:34:59 -06005 "github.com/gophercloud/gophercloud/pagination"
6)
7
Joe Topjian1c236d32017-01-09 15:33:32 -07008type projectResult struct {
9 gophercloud.Result
10}
11
12// GetResult temporarily contains the response from the Get call.
13type GetResult struct {
14 projectResult
15}
16
Joe Topjianf61691c2016-11-05 12:34:59 -060017// Project is a base unit of ownership.
18type Project struct {
19 // IsDomain indicates whether the project is a domain.
20 IsDomain bool `json:"is_domain"`
21
22 // Description is the description of the project.
23 Description string `json:"description"`
24
25 // DomainID is the domain ID the project belongs to.
26 DomainID string `json:"domain_id"`
27
28 // Enabled is whether or not the project is enabled.
29 Enabled bool `json:"enabled"`
30
31 // ID is the unique ID of the project.
32 ID string `json:"id"`
33
34 // Name is the name of the project.
35 Name string `json:"name"`
36
37 // ParentID is the parent_id of the project.
38 ParentID string `json:"parent_id"`
39}
40
41// ProjectPage is a single page of Project results.
42type ProjectPage struct {
43 pagination.LinkedPageBase
44}
45
46// IsEmpty determines whether or not a page of Projects contains any results.
47func (r ProjectPage) IsEmpty() (bool, error) {
48 projects, err := ExtractProjects(r)
49 return len(projects) == 0, err
50}
51
52// NextPageURL extracts the "next" link from the links section of the result.
53func (r ProjectPage) NextPageURL() (string, error) {
54 var s struct {
55 Links struct {
56 Next string `json:"next"`
57 Previous string `json:"previous"`
58 } `json:"links"`
59 }
60 err := r.ExtractInto(&s)
61 if err != nil {
62 return "", err
63 }
64 return s.Links.Next, err
65}
66
67// ExtractProjects returns a slice of Projects contained in a single page of results.
68func ExtractProjects(r pagination.Page) ([]Project, error) {
69 var s struct {
70 Projects []Project `json:"projects"`
71 }
72 err := (r.(ProjectPage)).ExtractInto(&s)
73 return s.Projects, err
74}
Joe Topjian1c236d32017-01-09 15:33:32 -070075
76// Extract interprets any projectResults as a Project.
77func (r projectResult) Extract() (*Project, error) {
78 var s struct {
79 Project *Project `json:"project"`
80 }
81 err := r.ExtractInto(&s)
82 return s.Project, err
83}