Skip to content

Commit

Permalink
Merge branch 'master' of github.com:Syncano/syncano-node
Browse files Browse the repository at this point in the history
  • Loading branch information
mkucharz committed Sep 1, 2018
2 parents 2b34ab7 + 5eb5c1f commit 876ee10
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 64 deletions.
8 changes: 4 additions & 4 deletions packages/lib-js-core/src/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ const MAX_BATCH_SIZE = 50
* @property {Function} query Instance of syncano DataObject
*/
class Data extends QueryBuilder {
url (id) {
url (id, apiVersion) {
debug('url', id)
const {instanceName, className} = this.instance
let url = `${this._getInstanceURL(
instanceName
instanceName, apiVersion
)}/classes/${className}/objects/${id ? id + '/' : ''}`

if (this._url !== undefined) {
Expand Down Expand Up @@ -204,8 +204,8 @@ class Data extends QueryBuilder {
async list () {
debug('list')
const self = this
const urls = [this.url()].concat(this.queries.map(query =>
(this._query.query = query) && this.url()
const urls = [this.url(null, 'v3')].concat(this.queries.map(query =>
(this._query.query = query) && this.url(null, 'v3')
))
debug('urls', urls)
const uniqueIds = []
Expand Down
8 changes: 4 additions & 4 deletions packages/lib-js-core/src/instance.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import QueryBuilder from './query-builder'
* @property {Function}
*/
class Instance extends QueryBuilder {
url (instanceName) {
const baseUrl = `${this._getSyncanoURL()}/instances/`
url (instanceName, apiVersion) {
const baseUrl = `${this._getSyncanoURL(apiVersion)}/instances/`
return instanceName ? `${baseUrl}${instanceName}/` : baseUrl
}

Expand Down Expand Up @@ -49,7 +49,7 @@ class Instance extends QueryBuilder {
const headers = {
'X-API-KEY': this.instance.accountKey
}
fetch(this.url(instanceName), {}, headers)
fetch(this.url(instanceName, 'v3'), {}, headers)
.then(resolve)
.catch(reject)
})
Expand All @@ -70,7 +70,7 @@ class Instance extends QueryBuilder {
const headers = {
'X-API-KEY': this.instance.accountKey
}
fetch(this.url(), {}, headers)
fetch(this.url('', 'v3'), {}, headers)
.then(response => {
resolve(response.objects)
})
Expand Down
13 changes: 8 additions & 5 deletions packages/lib-js-core/src/query-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@ export default class QueryBuilder {
this.result = []
}

_getSyncanoURL () {
const {apiVersion, host} = this.instance
_getSyncanoURL (apiVersion) {
let apiVersionInURL = apiVersion
if (!apiVersionInURL) {
apiVersionInURL = this.instance.apiVersion
}

return `https://${host}/${apiVersion}`
return `https://${this.instance.host}/${apiVersionInURL}`
}

_getSyncanoRegistryURL () {
Expand All @@ -39,8 +42,8 @@ export default class QueryBuilder {
return `https://${this.registryHost}`
}

_getInstanceURL (instanceName) {
return `${this._getSyncanoURL()}/instances/${instanceName}`
_getInstanceURL (instanceName, apiVersion) {
return `${this._getSyncanoURL(apiVersion)}/instances/${instanceName}`
}

fetch (url, options = {}, headers = {}) {
Expand Down
4 changes: 2 additions & 2 deletions packages/lib-js-core/src/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import Data from './data'
* @property {Function}
*/
class Users extends Data {
url (id) {
url (id, apiVersion) {
const {instanceName} = this.instance
const url = `${this._getInstanceURL(instanceName)}/users/${id
const url = `${this._getInstanceURL(instanceName, apiVersion)}/users/${id
? id + '/'
: ''}`
const query = querystring.stringify(this.query)
Expand Down
Loading

0 comments on commit 876ee10

Please sign in to comment.