Skip to content

Instantly share code, notes, and snippets.

@benmvp
Created January 2, 2019 22:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benmvp/f6b28133f08d8f30702d54d7a400840a to your computer and use it in GitHub Desktop.
Save benmvp/f6b28133f08d8f30702d54d7a400840a to your computer and use it in GitHub Desktop.
import {mapValues} from 'lodash';
import {Sdk, SdkConfig} from './types';
import request from './request';
import * as users from './users';
export * from './constants';
const DEFAULT_API_URL = 'https://www.eventbriteapi.com/v3';
const eventbrite = ({
baseUrl = DEFAULT_API_URL,
token,
}: SdkConfig = {}): Sdk => {
const requestHelper = (endpoint, options = {}) => {
const url = `${baseUrl}${endpoint}`;
let requestOptions = options;
if (token) {
requestOptions = {
...requestOptions,
headers: {
...(requestOptions.headers || {}),
Authorization: `Bearer ${token}`,
},
};
}
return request(url, requestOptions);
};
return {
request: requestHelper,
users: mapValues(users, (userMethod) => userMethod.bind(null, requestHelper))
}
};
export default eventbrite;
@kwelch
Copy link

kwelch commented Jan 2, 2019

then usage would look like

const me = (request) => request('/users/me');

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment