Created
January 2, 2019 22:06
-
-
Save benmvp/f6b28133f08d8f30702d54d7a400840a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
then usage would look like