Skip to content

Commit

Permalink
importUsage imported from vleet (#9)
Browse files Browse the repository at this point in the history
* importUsage imported from vleet

* catch fix
  • Loading branch information
rjacolin authored Jul 8, 2016
1 parent 970f033 commit 68b8fbe
Showing 1 changed file with 27 additions and 7 deletions.
34 changes: 27 additions & 7 deletions lib/airvantage.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var SYSTEM_LIFECYCLE_OPERATIONS = ["activate", "suspend", "resume", "terminate"]

/**
* AirVantage API class
*
*
* @param {String} setup.serverUrl
* @param {String} setup.companyUid (optional)
* @param {String} setup.credentials.clientId
Expand All @@ -36,14 +36,14 @@ module.exports = AirVantage;

/**
* Authenticate this instance of AirVantage
*
* @param {Object} options,
*
* @param {Object} options,
* may contain different parameters to perform the authentication:
* - token: if you already have an access_token
* - username & password: to get authenticate different user
* These will override the one you may already have set at
* global level.
*
*
* @return {Promise} with the token
*/
AirVantage.prototype.authenticate = function(options) {
Expand Down Expand Up @@ -78,11 +78,11 @@ AirVantage.prototype.authenticate = function(options) {

/**
* Logoout this instance of AirVantage or a given token
*
*
* @param {Object} options
* - token: a token to expire instead of the default instance one
*
* @return {Promise}
*
* @return {Promise}
*/
AirVantage.prototype.logout = function(options) {
var expireUrl = [this.serverUrl, EXPIRE_TOKEN_URL].join("/");
Expand Down Expand Up @@ -194,6 +194,26 @@ _.each(SYSTEM_LIFECYCLE_OPERATIONS, function(operationName) {
})
};
});


AirVantage.prototype.importUsage = function(data) {
var resource = [this.serverUrl, BASE_API_URL, "operations/systems/usages/import"].join("/");

return got(resource, {
query: this._buildQuery(),
headers: _.extend(this._buildHeaders(), {
"Content-Type": "application/octet-stream"
}),
json: true,
body: data
})
.then(function(res) {
return res.body;
}).catch(function(error) {
console.error(error.response.body);
});
};

//////////////////////////////////////////
// OPERATOR CONNECTIONS //
//////////////////////////////////////////
Expand Down

0 comments on commit 68b8fbe

Please sign in to comment.