caymland-js
Advanced tools
Comparing version 1.0.6 to 1.0.7
const Caymland = require('./../src/index') | ||
const client = new Caymland({ | ||
baseUrl: 'https://local.caymland.app', | ||
auth: { | ||
username: 'nsaloski', | ||
password: 'nerminsa' | ||
} | ||
auth: 'bnNhbG9za2k6bmVybWluc2E=' | ||
}) | ||
@@ -19,6 +16,8 @@ | ||
console.log('## list contacts') | ||
const listContactsResponse = await client.contacts.list(encodeURI('limit=10&start=0&where[0][col]=date_identified&where[0][expr]=isNotNull&where[1][col]=owner_id&where[1][expr]=eq&where[1][val]=1')) | ||
print(listContactsResponse); | ||
const listContactsResponse = await client.contacts.list(encodeURI('search=Nermin')) | ||
const listContactsResponse2 = await client.contacts.list({ search: 'Nermin' }) | ||
print(listContactsResponse.data.total) | ||
print(listContactsResponse2.data.total) | ||
} | ||
run() |
{ | ||
"name": "caymland-js", | ||
"version": "1.0.6", | ||
"version": "1.0.7", | ||
"description": "Javascript library to the Caymland REST API - https://api.m-4.ch/#rest-api", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -25,6 +25,6 @@ const axios = require('axios') | ||
}) { | ||
this.auth = auth | ||
this.baseUrl = baseUrl | ||
this.headers = { | ||
'X-Requested-With': 'XMLHttpRequest', | ||
'Authorization': 'Basic ' + auth | ||
} | ||
@@ -42,10 +42,17 @@ this.contacts = new Contact(this) | ||
headers: this.headers, | ||
auth: this.auth | ||
}).then(responseWith).catch(responseErrWith) | ||
} | ||
list (resourceUri, params = '') { | ||
return axios.get(`${this.baseUrl}/api/${resourceUri}?${params}`, { | ||
list (resourceUri, params = {}) { | ||
let stringParams = '' | ||
let objectParams = {} | ||
if (typeof (params) === 'object') { | ||
objectParams = params | ||
} else { | ||
stringParams = '?' + params | ||
} | ||
return axios.get(`${this.baseUrl}/api/${resourceUri}${stringParams}`, { | ||
params: objectParams, | ||
headers: this.headers, | ||
auth: this.auth | ||
}).then(responseWith).catch(responseErrWith) | ||
@@ -57,3 +64,2 @@ } | ||
headers: this.headers, | ||
auth: this.auth | ||
}).then(responseWith).catch(responseErrWith) | ||
@@ -65,3 +71,2 @@ } | ||
headers: this.headers, | ||
auth: this.auth | ||
}).then(responseWith).catch(responseErrWith) | ||
@@ -73,3 +78,2 @@ } | ||
headers: this.headers, | ||
auth: this.auth | ||
}).then(responseWith).catch(responseErrWith) | ||
@@ -81,3 +85,2 @@ } | ||
headers: this.headers, | ||
auth: this.auth | ||
}).then(responseWith).catch(responseErrWith) | ||
@@ -84,0 +87,0 @@ } |
21337
479