-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Harsh Thakur <[email protected]>
- Loading branch information
1 parent
38c04a8
commit cbc5511
Showing
3 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package civogo | ||
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
) | ||
|
||
// MembershipResponse is the response for the memberships of a user | ||
type MembershipResponse struct { | ||
Accounts []Account | ||
Organisations []Organisation | ||
} | ||
|
||
// ListMemberships returns all the memberships(to accounts and organisations) for the user | ||
func (c *Client) ListMemberships() (*MembershipResponse, error) { | ||
resp, err := c.SendGetRequest("/v2/memberships") | ||
if err != nil { | ||
return nil, decodeError(err) | ||
} | ||
|
||
mrs := &MembershipResponse{} | ||
if err := json.NewDecoder(bytes.NewReader(resp)).Decode(&mrs); err != nil { | ||
return nil, err | ||
} | ||
|
||
return mrs, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package civogo | ||
|
||
import "testing" | ||
|
||
func TestListMemberships(t *testing.T) { | ||
client, server, _ := NewClientForTesting(map[string]string{ | ||
"/v2/memberships": `{ | ||
"accounts": [ | ||
{ | ||
"id": "4f229791-6088-42dd-8fbe-3f64ec47567f", | ||
"api_key": "75e521bc74d34b21b42827fb58fcd590", | ||
"email_address": "[email protected]", | ||
"label": "team testing", | ||
"flags": null, | ||
"salt": null, | ||
"timezone": "Europe/London", | ||
"organisation_id": "63bd4fe4-eeff-421b-aa24-1518decc5464" | ||
} | ||
], | ||
"organisations": [ | ||
{ | ||
"id": "63bd4fe4-eeff-421b-aa24-1518decc5464", | ||
"name": "Our-group Inc" | ||
} | ||
] | ||
}`, | ||
}) | ||
defer server.Close() | ||
got, err := client.ListMemberships() | ||
|
||
if err != nil { | ||
t.Errorf("Request returned an error: %s", err) | ||
return | ||
} | ||
|
||
if got.Accounts[0].ID != "4f229791-6088-42dd-8fbe-3f64ec47567f" { | ||
t.Errorf("Expected User ID %s, got %s", "4f229791-6088-42dd-8fbe-3f64ec47567f", got.Accounts[0].ID) | ||
} | ||
if got.Organisations[0].ID != "63bd4fe4-eeff-421b-aa24-1518decc5464" { | ||
t.Errorf("Expected User ID %s, got %s", "63bd4fe4-eeff-421b-aa24-1518decc5464", got.Organisations[0].ID) | ||
} | ||
|
||
} |