domotz-remote-pawn
Version:
Domotz Agent
72 lines (59 loc) • 2.56 kB
JavaScript
/** This file is part of Domotz Agent.
* Copyright (C) 2016 Domotz Ltd
*
* Domotz Agent is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Domotz Agent is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Domotz Agent. If not, see <http://www.gnu.org/licenses/>.
**/
/**
* Created by Iacopo Papalini <ipapalini@domotz.com> on 05/07/15.
* This module fetches the User information (i.e. the owner of the Agent) from the Engine.
* It authenticates using the customer's credentials and can be used to configure the Agent itself
*/
;
var factory = function (userRequest, registerRequest) {
function create(username, password, country) {
var body = {name: username, password: password, country: country, not_confirmed: true};
console.info("Create user with e-mail: " + username);
return registerRequest.sendWithPromise('user', 'POST', body);
}
function get(username, password) {
userRequest.setCredentials(username, password);
return userRequest.sendWithPromise('user/' + username, 'GET', {});
}
function getCountries() {
return userRequest.sendWithPromise('country', 'GET', {});
}
function getRegions() {
return userRequest.sendWithPromise('region', 'GET', {});
}
function setAcceptedConditions(userId, version) {
var body = {version: version};
return userRequest.sendWithPromise('user/' + userId + '/accepted-conditions', 'PUT', body);
}
function getAcceptedConditions(userId) {
return userRequest.sendWithPromise('user/' + userId + '/accepted-conditions', 'GET', {});
}
function getAvailableLicences(userId) {
return userRequest.sendWithPromise('user/' + userId + '/available-licence', 'GET', {});
}
return {
create: create,
get: get,
getCountries: getCountries,
getRegions: getRegions,
setAcceptedConditions: setAcceptedConditions,
getAcceptedConditions: getAcceptedConditions,
getAvailableLicences: getAvailableLicences
};
};
module.exports.factory = factory;