Skip to content

Commit

Permalink
fix(): style
Browse files Browse the repository at this point in the history
  • Loading branch information
mkucharz committed Mar 3, 2018
1 parent 3a1d940 commit 1f25934
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
46 changes: 23 additions & 23 deletions packages/lib-js-client/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import querystring from 'querystring'
import fetch from 'axios'
import FormData from 'form-data'

function SyncanoClient(instanceName = required('instanceName'), options = {}) {
function SyncanoClient (instanceName = required('instanceName'), options = {}) {
const host = options.host || 'syncano.space'
const DEFAULT_HEADERS = {'Content-Type': 'application/json'}

Expand All @@ -14,26 +14,26 @@ function SyncanoClient(instanceName = required('instanceName'), options = {}) {
client.headers = headers => Object.assign({}, DEFAULT_HEADERS, headers)
client.post = client

client.login = function(username, password) {
client.login = function (username, password) {
const login = client.loginMethod
? client.loginMethod
: (username, password) => {
const url = `https://api.syncano.io/v2/instances/${
const url = `https://api.syncano.io/v2/instances/${
client.instanceName
}/users/auth/`
const data = JSON.stringify({username, password})
const data = JSON.stringify({username, password})

return fetch({url, data}).then(user => {
client.setToken(user.token)
return fetch({url, data}).then(user => {
client.setToken(user.token)

return user
})
}
return user
})
}

return login(username, password)
}

client.url = function(endpoint, data) {
client.url = function (endpoint, data) {
let url = `${this.baseUrl}${endpoint}/?`

if (data) {
Expand All @@ -47,43 +47,43 @@ function SyncanoClient(instanceName = required('instanceName'), options = {}) {
return url
}

client.logout = function() {
client.logout = function () {
this.token = undefined
}

client.setToken = function(token) {
client.setToken = function (token) {
this.token = token

if (typeof client.setTokenCallback === 'function') {
client.setTokenCallback(token)
}
}

client.get = function(
client.get = function (
endpoint = required('endpoint'),
data = {},
options = {}
) {
return this.post(endpoint, {...data, _method: 'GET'}, options)
}

client.delete = function(
client.delete = function (
endpoint = required('endpoint'),
data = {},
options = {}
) {
return this.post(endpoint, {...data, _method: 'DELETE'}, options)
}

client.put = function(
client.put = function (
endpoint = required('endpoint'),
data = {},
options = {}
) {
return this.post(endpoint, {...data, _method: 'PUT'}, options)
}

client.patch = function(
client.patch = function (
endpoint = required('endpoint'),
data = {},
options = {}
Expand All @@ -92,7 +92,7 @@ function SyncanoClient(instanceName = required('instanceName'), options = {}) {
}

// Used by the client.subscribe method to start polling from the correct id
client.setLastId = function(endpoint, data) {
client.setLastId = function (endpoint, data) {
const url = this.url(`${endpoint}/history`, data)
// eslint-disable-next-line camelcase
if (data.last_id) {
Expand All @@ -105,7 +105,7 @@ function SyncanoClient(instanceName = required('instanceName'), options = {}) {
})
}

client.subscribe = function(endpoint = required('endpoint'), data, callback) {
client.subscribe = function (endpoint = required('endpoint'), data, callback) {
let abort = false
const hasData = typeof data === 'object' && data !== null

Expand All @@ -124,7 +124,7 @@ function SyncanoClient(instanceName = required('instanceName'), options = {}) {
let url = client.url(endpoint, data)
const cb = hasData ? callback : data

function loop() {
function loop () {
if (abort) {
return
}
Expand Down Expand Up @@ -161,7 +161,7 @@ function SyncanoClient(instanceName = required('instanceName'), options = {}) {
}
}

client.subscribe.once = function(
client.subscribe.once = function (
endpoint = required('endpoint'),
data = {},
callback
Expand All @@ -180,7 +180,7 @@ function SyncanoClient(instanceName = required('instanceName'), options = {}) {

return client

function client(endpoint = required('endpoint'), data = {}, options = {}) {
function client (endpoint = required('endpoint'), data = {}, options = {}) {
const method = data._method || 'POST'
const headers = client.headers(options.headers)
let url = client.url(endpoint)
Expand All @@ -195,7 +195,7 @@ function SyncanoClient(instanceName = required('instanceName'), options = {}) {
}

const transformRequest = [
function(data) {
function (data) {
if (data instanceof FormData) {
return data
}
Expand All @@ -215,7 +215,7 @@ function SyncanoClient(instanceName = required('instanceName'), options = {}) {
}
}

function required(param) {
function required (param) {
throw new Error(`${param} parameter is required by SyncanoClient`)
}

Expand Down
2 changes: 1 addition & 1 deletion packages/tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
"test:e2e-single": "npx mocha --require babel-register --timeout 100000 --slow 8000",
"test:e2e:client": "npm-run-all test:e2e:client:*",
"test:e2e:client:main": "npm run test:e2e-single e2e/client/main.js",
"lint": "standard --fix --env mocha",
"lint": "standard --fix --env mocha e2e",
"format": "prettier --write --single-quote --no-semi --no-bracket-spacing *.js {src,test}/**/*.js"
},
"publishConfig": {
Expand Down

0 comments on commit 1f25934

Please sign in to comment.