Skip to content
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

feat(users): Add users collection to SDK #52

Merged
merged 35 commits into from
Jan 23, 2019

Conversation

kwelch
Copy link
Contributor

@kwelch kwelch commented Dec 28, 2018

Description

This is a draft of the users api to be added to the SDK.

For starters, I have added the documentation so we can discuss its usage.

This will be the template we use for implementation and the go forward direction for adding more collections to the SDK.

How Has This Been Tested?

This will be tests through unit tests once implemented. We may also consider adding a simple app to this project to test this on the node and client side.

Screenshots (if appropriate):

Checklist:

  • I have read the CONTRIBUTING document.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • I have run yarn validate to ensure that tests, typescript and linting are all in order.

@kwelch-eb
Copy link
Contributor

Hey @benmvp, What do you think of this to start?

Copy link
Contributor

@benmvp benmvp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I like where this is going. I think this is much more helpful than having to make the raw call.

I would add two additional things:

  1. A link somewhere in the API docs that describes what properties exist in a User object (we don't want to have to maintain the docs here)
  2. For each method a link to the vanilla/raw API doc

docs/users.md Outdated Show resolved Hide resolved
docs/users.md Outdated Show resolved Hide resolved
docs/users.md Outdated Show resolved Hide resolved
docs/users.md Outdated Show resolved Hide resolved
docs/users.md Outdated Show resolved Hide resolved
docs/users.md Outdated Show resolved Hide resolved
docs/users.md Outdated Show resolved Hide resolved
docs/users.md Outdated Show resolved Hide resolved
src/index.ts Outdated Show resolved Hide resolved
docs/users.md Show resolved Hide resolved
src/types.ts Outdated Show resolved Hide resolved
src/users.ts Outdated Show resolved Hide resolved
src/users.ts Outdated Show resolved Hide resolved
src/users.ts Outdated Show resolved Hide resolved
src/users.ts Outdated Show resolved Hide resolved
@kwelch
Copy link
Contributor Author

kwelch commented Jan 3, 2019

I am going to beef up the test suite for this and add the other methods, unless you spot anything.

docs/users.md Outdated Show resolved Hide resolved
@kwelch-eb
Copy link
Contributor

Merged @jcreamer898 changes, and added a commit to make jsonRequest generic, so we only have to instantiate it once.

@kwelch kwelch changed the title [WIP] feat(users): Add users collection to SDK feat(users): Add users collection to SDK Jan 8, 2019
src/__tests__/users.spec.ts Outdated Show resolved Hide resolved
src/__tests__/users.spec.ts Outdated Show resolved Hide resolved
src/index.ts Outdated Show resolved Hide resolved
src/users.ts Outdated
const snakeToCamel = (str: string) =>
str.replace(SNAKE_CASE_MATCH, (chars: string) => chars[1].toUpperCase());

const transformKeysSnakeToCamel = (obj: {}): {} =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you wanna use a lib like camelize? https://yarnpkg.com/en/package/camelize. Cuz now in theory we need tests for transformKeysSnakeToCamel

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will look into a package, however that one will not work because it also converts dotCase to camel, which breaks our API. That is what led us to making this function internally.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is turning out to be difficult to find something for since it is very generic, but all of them convert expand.destination_event to expandDestinationEvent, which is undesired.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about leaving this and adding tests? It is that or I make a package of it 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved this around and added tests. Also working on adding something to camel-keys to allow us to be able to remove this.

src/users.ts Outdated Show resolved Hide resolved
docs/users.md Outdated Show resolved Hide resolved
src/users.ts Outdated Show resolved Hide resolved
}

export interface User {
id?: string;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are these really optional? The API always returns the fields right? Same with Email above

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's best to leave fields on domain objects optional so when you're doing something like...

api.create({
  name: 'foo',
  email: '[email protected]'
});

You don't have to specify each field.

The alternative is to do Partial<User>, but it's really just easier to switch them to optional.

Copy link
Contributor Author

@kwelch kwelch Jan 10, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may need to verify the model 😅. I have null first and last, but I have a name. I imagine image_id is also nullable.

{
    "emails": [
        {
            "email": "<REDACTED>", 
            "verified": false, 
            "primary": true
        }
    ], 
    "id": "<REDACTED>", 
    "name": "<REDACTED>", 
    "first_name": null, 
    "last_name": null, 
    "is_public": false, 
    "image_id": "<REDACTED>"
}

src/request.ts Outdated Show resolved Hide resolved
@kwelch
Copy link
Contributor Author

kwelch commented Jan 18, 2019

I think this is all set. Please review again.

@kwelch-eb kwelch-eb merged commit 4ac55ac into eventbrite:master Jan 23, 2019
@ebtravis
Copy link
Collaborator

🎉 This PR is included in version 1.1.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants