diff --git a/organization.go b/organization.go index 16b851c..357bcf8 100644 --- a/organization.go +++ b/organization.go @@ -35,6 +35,18 @@ func (c *Client) GetOrganization(orgID string, extraArgs ...Arguments) (organiza return } +// GetBoardsInOrganization takes an organization id and Arguments and either GET returns +// a slice of boards within that organization, or an error. +func (c *Client) GetBoardsInOrganization(orgID string, extraArgs ...Arguments) (boards []*Board, err error) { + args := flattenArguments(extraArgs) + path := fmt.Sprintf("organizations/%s/boards", orgID) + err = c.Get(path, args, &boards) + if err != nil { + return nil, err + } + return +} + // SetClient can be used to override this Organization's internal connection // to the Trello API. Normally, this is set automatically after API calls. func (o *Organization) SetClient(newClient *Client) { diff --git a/organization_test.go b/organization_test.go index 1290cdd..f2ea111 100644 --- a/organization_test.go +++ b/organization_test.go @@ -16,6 +16,24 @@ func TestGetOrganization(t *testing.T) { } } +func TestGetBoardsInOrganization(t *testing.T) { + organization := testOrganization(t) + if organization.DisplayName != "Culture Foundry" { + t.Errorf("Expected name 'Culture Foundry'. Got '%s'.", organization.DisplayName) + } + + client := testClient() + client.BaseURL = mockResponse("organizations", "571ab6ad9dc91c597d6e9f90", "boards", "boards.json").URL + + boards, err := client.GetBoardsInOrganization(organization.ID) + if err != nil { + t.Fatalf("Expected boards in organization to be returned. Got error: %v", err) + } + if boards == nil { + t.Fatalf("Expected boards slice to contain boards in the test organization with ID %s. Slice was nil.", organization.ID) + } +} + func TestOrganizationSetClient(t *testing.T) { o := Organization{} client := testClient() diff --git a/testdata/organizations/571ab6ad9dc91c597d6e9f90/boards/boards.json b/testdata/organizations/571ab6ad9dc91c597d6e9f90/boards/boards.json new file mode 100644 index 0000000..a34ef38 --- /dev/null +++ b/testdata/organizations/571ab6ad9dc91c597d6e9f90/boards/boards.json @@ -0,0 +1,148 @@ +[ + { + "id": "4eea4ffc91e31d1746000046", + "closed": false, + "dateLastActivity": null, + "dateLastView": null, + "desc": "This board is used in the API examples", + "descData": null, + "idOrganization": "4efe2c2f2e1efe7a4c0002c9", + "invitations": [], + "invited": false, + "labelNames": { + "green": "", + "yellow": "", + "orange": "", + "red": "", + "purple": "", + "blue": "", + "sky": "", + "lime": "", + "pink": "", + "black": "" + }, + "memberships": [ + { + "id": "4eea4ffc91e31d174600004d", + "idMember": "4ee7deffe582acdec80000ac", + "memberType": "admin", + "unconfirmed": false + }, + { + "id": "4eea507991e31d17460000fc", + "idMember": "4ee7df1be582acdec80000ae", + "memberType": "normal", + "unconfirmed": false + }, + { + "id": "4eea50bc91e31d174600016d", + "idMember": "4ee7df74e582acdec80000b6", + "memberType": "normal", + "unconfirmed": false + } + ], + "name": "Example Board", + "pinned": false, + "powerUps": [], + "prefs": { + "permissionLevel": "public", + "voting": "members", + "comments": "members", + "invitations": "members", + "selfJoin": true, + "cardCovers": true, + "calendarFeedEnabled": false, + "background": "blue", + "backgroundColor": "#0079BF", + "backgroundImage": null, + "backgroundImageScaled": null, + "backgroundTile": false, + "backgroundBrightness": "unknown", + "canBePublic": true, + "canBeOrg": true, + "canBePrivate": true, + "canInvite": true + }, + "shortLink": "OXiBYZoj", + "shortUrl": "https://trello.com/b/OXiBYZoj", + "starred": null, + "subscribed": null, + "url": "https://trello.com/b/OXiBYZoj/example-board" + }, + { + "id": "4ee7e707e582acdec800051a", + "closed": false, + "dateLastActivity": null, + "dateLastView": null, + "desc": "A board that everyone can see", + "descData": null, + "idOrganization": "", + "invitations": [], + "invited": false, + "labelNames": { + "green": "", + "yellow": "", + "orange": "", + "red": "", + "purple": "", + "blue": "", + "sky": "", + "lime": "", + "pink": "", + "black": "" + }, + "lists": [ + { + "name": "Some list", + "id": "4een4ffc91r31q174fsldk46" + } + ], + "memberships": [ + { + "id": "4ee7e707e582acdec8000521", + "idMember": "4ee7df3ce582acdec80000b2", + "memberType": "admin", + "unconfirmed": false + }, + { + "id": "4ee7e72fe582acdec8000573", + "idMember": "4ee7df1be582acdec80000ae", + "memberType": "normal", + "unconfirmed": false + }, + { + "id": "514c5f9cb569140000000016", + "idMember": "514c5f9cb569140000000014", + "memberType": "normal", + "unconfirmed": false + } + ], + "name": "Public Board", + "pinned": false, + "powerUps": [], + "prefs": { + "permissionLevel": "public", + "voting": "public", + "comments": "public", + "invitations": "members", + "selfJoin": true, + "cardCovers": true, + "calendarFeedEnabled": false, + "background": "blue", + "backgroundColor": "#0079BF", + "backgroundImage": null, + "backgroundImageScaled": null, + "backgroundTile": false, + "backgroundBrightness": "unknown", + "canBePublic": true, + "canBeOrg": true, + "canBePrivate": true, + "canInvite": true + }, + "shortLink": "IwLRbh3F", + "shortUrl": "https://trello.com/b/IwLRbh3F", + "starred": null, + "subscribed": null, + "url": "https://trello.com/b/IwLRbh3F/public-board" + } +] \ No newline at end of file