Skip to content

Commit c55949a

Browse files
committed
refactor(kitsu): self - move params and headers into a config object
1 parent 8b49cc1 commit c55949a

2 files changed

Lines changed: 9 additions & 8 deletions

File tree

packages/kitsu/src/index.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -360,10 +360,9 @@ export default class Kitsu {
360360
* **Note** Requires the JSON:API server to support `filter[self]=true`
361361
*
362362
* @memberof Kitsu
363-
* @param {Object} [params] JSON-API request queries
364-
* @param {Object} [params.fields] Return a sparse fieldset with only the included attributes/relationships - [JSON:API Sparse Fieldsets](http://jsonapi.org/format/#fetching-sparse-fieldsets)
365-
* @param {string} [params.include] Include relationship data - [JSON:API Includes](http://jsonapi.org/format/#fetching-includes)
366-
* @param {Object} [headers] Additional headers to send with the request
363+
* @param {Object} [config] Additional configuration
364+
* @param {Object} [config.params] JSON:API request queries. See [#get](#get) for documentation
365+
* @param {Object} [config.headers] Additional headers to send with the request
367366
* @returns {Object} JSON-parsed response
368367
* @example <caption>Get the authenticated user's resource</caption>
369368
* api.self()
@@ -374,9 +373,11 @@ export default class Kitsu {
374373
* }
375374
* })
376375
*/
377-
async self (params = {}, headers = {}) {
376+
async self (config = {}) {
378377
try {
379-
const res = await this.get('users', Object.assign({ filter: { self: true } }, params), headers)
378+
const headers = merge(this.headers, config.headers)
379+
const params = merge(config.params, { filter: { self: true } })
380+
const res = await this.get('users', merge({ headers }, { params }))
380381
return res.data[0]
381382
} catch (E) {
382383
throw error(E)

packages/kitsu/src/self.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ describe('kitsu', () => {
2525
})
2626
return [ 200, { data: [] } ]
2727
})
28-
api.self(undefined, { extra: true }).catch(err => {
28+
api.self({ headers: { extra: true } }).catch(err => {
2929
done.fail(err)
3030
})
3131
done()
@@ -55,7 +55,7 @@ describe('kitsu', () => {
5555
const api = new Kitsu()
5656
mock.onGet('/users', { filter: { self: true }, include: 'author' }).reply(400, getError.jsonapi)
5757
try {
58-
await api.self({ include: 'author' })
58+
await api.self({ params: { include: 'author' } })
5959
} catch ({ errors }) {
6060
expect(errors).toHaveLength(1)
6161
expect(errors[0].title).toBe('Invalid field')

0 commit comments

Comments
 (0)