-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add organizations api #54
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
6cfc2d9
Start organization API docs
kwelch 1a26028
Added implementation and updated docs
kwelch daec78d
fixed up the types and pagniation to mock data
kwelch adc4e0c
added test for organizations api
kwelch f48ffd0
fix copy paste issue and lint issue on describe name
kwelch f8f813a
add jsdoc string for organization method
kwelch File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,39 @@ | ||
# Organizations | ||
|
||
This is a collection of methods that are intended to be helpful wrappers around the [organizations API endpoints](organization-api-docs). | ||
|
||
View the [Organizations response object](organization-object-reference) for details on the properties you'll get back with each response. | ||
|
||
## Table on Contents | ||
|
||
- [`sdk.organizations.getByUser(id)`](#getByUser) | ||
|
||
<a id="getByUser"></a> | ||
|
||
## `sdk.organizations.getByUser(id)` | ||
Gets the details for a specific user by their user id. | ||
|
||
**Read [`/users/:userId/organizations/` documentation](organization-by-user) for more details.** | ||
|
||
### API | ||
```js | ||
sdk.organizations.getByUser(userId: string): Promise<Paginated<Organization[]>> | ||
``` | ||
|
||
### Example | ||
|
||
```js | ||
const eventbrite = require('eventbrite'); | ||
|
||
// Create configured Eventbrite SDK | ||
const sdk = eventbrite({token: 'OATH_TOKEN_HERE'}); | ||
|
||
sdk.organizations.getByUser('1234567890').then((paginatedResponse) => { | ||
console.log(`Here are your organizations: ${paginatedResponse.organizations.join(' ')}.`); | ||
}); | ||
``` | ||
|
||
<!-- link reference section --> | ||
[organization-api-docs]: https://www.eventbrite.com/platform/api#/reference/organization | ||
[organization-object-reference]: https://www.eventbrite.com/platform/api#/reference/organization | ||
[organization-by-user]: https://www.eventbrite.com/platform/api#/reference/organization/list-organizations-by-user |
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,67 @@ | ||
import { | ||
mockFetch, | ||
getMockFetch, | ||
getMockResponse, | ||
restoreMockFetch, | ||
} from './utils'; | ||
import { | ||
MOCK_ORGS_BY_USER_SUCCESS_RESPONSE, | ||
MOCK_TRANSFORMED_ORGS_BY_USER, | ||
} from './__fixtures__'; | ||
|
||
import request from '../request'; | ||
import {OrganizationsApi} from '../organizations'; | ||
|
||
describe('OrganizationsApi', () => { | ||
describe('getByUser()', () => { | ||
it('calls fetch and calls fetch with appropriate defaults', async() => { | ||
const organizations = new OrganizationsApi(request); | ||
|
||
mockFetch(getMockResponse(MOCK_ORGS_BY_USER_SUCCESS_RESPONSE)); | ||
|
||
await expect(organizations.getByUser('fake_id')).resolves.toEqual( | ||
MOCK_TRANSFORMED_ORGS_BY_USER | ||
); | ||
|
||
expect(getMockFetch()).toHaveBeenCalledTimes(1); | ||
expect(getMockFetch()).toHaveBeenCalledWith( | ||
'/users/fake_id/organizations/', | ||
expect.objectContaining({}) | ||
); | ||
|
||
restoreMockFetch(); | ||
}); | ||
|
||
it('handle token missing requests', async() => { | ||
const organizations = new OrganizationsApi(request); | ||
|
||
mockFetch( | ||
getMockResponse( | ||
{ | ||
status_code: 401, | ||
error_description: | ||
'An OAuth token is required for all requests', | ||
error: 'NO_AUTH', | ||
}, | ||
{status: 401} | ||
) | ||
); | ||
|
||
await expect( | ||
organizations.getByUser('fake_id') | ||
).rejects.toMatchObject({ | ||
response: expect.objectContaining({ | ||
status: 401, | ||
statusText: 'Unauthorized', | ||
ok: false, | ||
}), | ||
parsedError: { | ||
description: 'An OAuth token is required for all requests', | ||
error: 'NO_AUTH', | ||
}, | ||
}); | ||
|
||
restoreMockFetch(); | ||
}); | ||
}); | ||
}); |
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,23 @@ | ||
import {BaseApi} from './baseApi'; | ||
import {PaginatedResponse} from './types'; | ||
|
||
export interface Organization { | ||
id: string; | ||
name: string; | ||
imageId: string; | ||
locale?: string; | ||
vertical?: 'Default' | 'Music'; | ||
} | ||
|
||
/** | ||
* API for working with Organizations | ||
*/ | ||
export class OrganizationsApi extends BaseApi<PaginatedResponse<Organization>> { | ||
/** | ||
* Get organizations based off a user id. | ||
* @param {string} userId | ||
*/ | ||
getByUser(userId: string) { | ||
return this.request(`/users/${userId}/organizations/`); | ||
} | ||
} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems silly, but maybe add some docs to each method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doc update pushed