jrperritt | c5c590a | 2016-11-04 14:41:15 -0500 | [diff] [blame] | 1 | package members |
| 2 | |
| 3 | import ( |
jrperritt | c5c590a | 2016-11-04 14:41:15 -0500 | [diff] [blame] | 4 | "time" |
| 5 | |
| 6 | "github.com/gophercloud/gophercloud" |
| 7 | "github.com/gophercloud/gophercloud/pagination" |
| 8 | ) |
| 9 | |
| 10 | // Member model |
| 11 | type Member struct { |
jrperritt | 98d0162 | 2017-01-12 14:24:42 -0600 | [diff] [blame] | 12 | CreatedAt time.Time `json:"created_at"` |
jrperritt | c5c590a | 2016-11-04 14:41:15 -0500 | [diff] [blame] | 13 | ImageID string `json:"image_id"` |
| 14 | MemberID string `json:"member_id"` |
| 15 | Schema string `json:"schema"` |
| 16 | Status string `json:"status"` |
jrperritt | 98d0162 | 2017-01-12 14:24:42 -0600 | [diff] [blame] | 17 | UpdatedAt time.Time `json:"updated_at"` |
jrperritt | c5c590a | 2016-11-04 14:41:15 -0500 | [diff] [blame] | 18 | } |
| 19 | |
| 20 | // Extract Member model from request if possible |
| 21 | func (r commonResult) Extract() (*Member, error) { |
| 22 | var s *Member |
| 23 | err := r.ExtractInto(&s) |
| 24 | return s, err |
| 25 | } |
| 26 | |
| 27 | // MemberPage is a single page of Members results. |
| 28 | type MemberPage struct { |
| 29 | pagination.SinglePageBase |
| 30 | } |
| 31 | |
| 32 | // ExtractMembers returns a slice of Members contained in a single page of results. |
| 33 | func ExtractMembers(r pagination.Page) ([]Member, error) { |
| 34 | var s struct { |
| 35 | Members []Member `json:"members"` |
| 36 | } |
| 37 | err := r.(MemberPage).ExtractInto(&s) |
| 38 | return s.Members, err |
| 39 | } |
| 40 | |
| 41 | // IsEmpty determines whether or not a page of Members contains any results. |
| 42 | func (r MemberPage) IsEmpty() (bool, error) { |
| 43 | members, err := ExtractMembers(r) |
| 44 | return len(members) == 0, err |
| 45 | } |
| 46 | |
| 47 | type commonResult struct { |
| 48 | gophercloud.Result |
| 49 | } |
| 50 | |
| 51 | // CreateResult result model |
| 52 | type CreateResult struct { |
| 53 | commonResult |
| 54 | } |
| 55 | |
| 56 | // DetailsResult model |
| 57 | type DetailsResult struct { |
| 58 | commonResult |
| 59 | } |
| 60 | |
| 61 | // UpdateResult model |
| 62 | type UpdateResult struct { |
| 63 | commonResult |
| 64 | } |
| 65 | |
| 66 | // DeleteResult model |
| 67 | type DeleteResult struct { |
| 68 | gophercloud.ErrResult |
| 69 | } |