Skip to content

Commit

Permalink
Merge pull request #13 from dleitee/dleitee/v0.2.2
Browse files Browse the repository at this point in the history
v0.2.2
  • Loading branch information
dleitee authored Jul 9, 2018
2 parents 9799ffd + f24ab75 commit b6c9439
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 18 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fetches",
"version": "0.2.1",
"version": "0.2.2",
"description": "Smart and Modern fetch wrapper.",
"main": "./lib/module.js",
"scripts": {
Expand Down
14 changes: 14 additions & 0 deletions src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,20 @@ export class Client {
after() {
return this.options.after
}

appendBeforeMiddleware(middleware) {
const options = deepmerge(this.options, {
before: [middleware],
})
return new Client(this.getURI(), options)
}

appendAfterMiddleware(middleware) {
const options = deepmerge(this.options, {
after: [middleware],
})
return new Client(this.getURI(), options)
}
}

export const createClient = (uri, options) => new Client(uri, options)
Expand Down
11 changes: 0 additions & 11 deletions src/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,6 @@ import deepmerge from 'deepmerge'
import { appendParams } from './utils/append-params'
import { Client } from './client'

const isClientInstance = client => {
if (client instanceof Client) {
return true
}
return false
}

const getDefaultOptions = client => {
switch (client.getRequestType()) {
case 'json':
Expand Down Expand Up @@ -79,10 +72,6 @@ const request = (client, method) => {
}

export const getHTTPMethods = client => {
if (!isClientInstance(client)) {
throw new Error('Please specify a Client to get the http methods.')
}

const clientRequest = request.bind(null, client)

return {
Expand Down
2 changes: 1 addition & 1 deletion src/middlewares/json-response.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const contentTypeIsJSON = header => header && header.includes('application/json'

export default response => {
if (contentTypeIsJSON(response.headers.get('content-type'))) {
return Promise.all([response.json(), response])
return response.json()
}

return Promise.resolve(response)
Expand Down
5 changes: 0 additions & 5 deletions tests/http.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,4 @@ describe('HTTP Module', () => {
const keys = Object.keys(getHTTPMethods(client))
expect(keys).toEqual(expect.arrayContaining(httpMethods))
})
test('getHTTPMethods needs a client as parameter', () => {
expect(() => {
getHTTPMethods()
}).toThrow()
})
})

0 comments on commit b6c9439

Please sign in to comment.