-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from fizzl/master
Let user add custom headers to requests
- Loading branch information
Showing
7 changed files
with
116 additions
and
219 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,75 +1,60 @@ | ||
/** | ||
* Created by sguilly on 17/11/16. | ||
*/ | ||
/** | ||
* Created by sguilly on 03/11/16. | ||
*/ | ||
"use strict"; | ||
|
||
var rest = require('restler'); | ||
var LoopbackModel = require('./LoopbackModel.js'); | ||
const rest = require('restler'); | ||
const LoopbackModel = require(__dirname + '/LoopbackModel.js'); | ||
|
||
class LoopbackClient { | ||
constructor(baseUrl,user,password) { | ||
|
||
this.user = user | ||
this.password = password | ||
this.token = null | ||
this.baseUrl = baseUrl | ||
constructor(baseUrl, user, password) { | ||
this.user = user; | ||
this.password = password; | ||
this.token = null; | ||
this.baseUrl = baseUrl; | ||
this.headers = {}; | ||
} | ||
|
||
getBaseUrl() | ||
{ | ||
return this.baseUrl | ||
setHeaders(headers) { | ||
this.headers = headers; | ||
} | ||
|
||
getToken() | ||
{ | ||
|
||
return this.token | ||
getBaseUrl() { | ||
return this.baseUrl; | ||
} | ||
|
||
createToken() | ||
{ | ||
var promise = new Promise((resolve, reject) => { | ||
getToken() { | ||
return this.token; | ||
} | ||
|
||
if(this.token) | ||
{ | ||
createToken() { | ||
return new Promise((resolve, reject) => { | ||
if (this.token) { | ||
resolve(this.token); | ||
} | ||
else { | ||
|
||
|
||
var data = { | ||
const data = { | ||
email: this.user, | ||
password: this.password | ||
} | ||
|
||
rest.postJson(this.baseUrl+'/users/login?include=user', data | ||
}; | ||
|
||
).on('complete', (result) =>{ | ||
const options = { | ||
headers: this.headers | ||
}; | ||
|
||
rest.postJson(this.baseUrl + '/users/login?include=user', | ||
data, options).on('complete', (result) => { | ||
if (result instanceof Error) { | ||
reject(result.message); | ||
|
||
} else { | ||
this.token = result.id | ||
this.token = result.id; | ||
resolve(this.token); | ||
} | ||
}); | ||
|
||
} | ||
|
||
}) | ||
|
||
return promise | ||
}); | ||
} | ||
|
||
getModel(name) | ||
{ | ||
return new LoopbackModel(name,this) | ||
getModel(name) { | ||
return new LoopbackModel(name, this); | ||
} | ||
} | ||
|
||
|
||
module.exports = LoopbackClient | ||
module.exports = LoopbackClient; |
Oops, something went wrong.