Skip to content
This repository has been archived by the owner on Dec 23, 2019. It is now read-only.

Commit

Permalink
feat(voip line phone): add call to APIv7 for fetching all phones
Browse files Browse the repository at this point in the history
  • Loading branch information
Jisay committed Jan 26, 2018
1 parent 3126ad5 commit fe26eae
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/**
* @ngdoc object
* @name managerApp.object:VoipLinePhone
*
* @description
* <p>Factory that describes a phone of a service with sip or mgcp featureType with attributes returned by `/telephony/{billingAccount}/line/{serviceName}/phone` API.</p>
*
* @constructor
* @param {Object} options Options required for creating a new instance of VoipLinePhone (see {@link https://eu.api.ovh.com/console/#/telephony/%7BbillingAccount%7D/line/%7BserviceName%7D/phone#GET `telephony.Phone` enum}
* for available options properties).
*
* Note that `billingAccount` and `serviceName` options are mandatory.
*/
angular.module("managerApp").factory("VoipLinePhone", function () {
"use strict";

const mandatoryOptions = ["billingAccount", "serviceName"];

class VoipLinePhone {
constructor (options = {}) {
// check for mandatory options
mandatoryOptions.forEach((option) => {
if (!options[option]) {
throw new Error(`${option} option must be specified when creating a new VoipLinePhone`);
}
});

// populate object attributes
// mandatory attribute
this.billingAccount = options.billingAccount;
this.serviceName = options.serviceName;

// populate other object attributes
this.setOptions(options);
}

/**
* @ngdoc method
* @name managerApp.object:VoipLinePhone#setOptions
* @propertyOf managerApp.object:VoipLinePhone
*
* @description
* Set the options from `telephony.Phone` enum. This is called by default by the constructor.
*
* @param {Object} options Optional options for creating a new instance of VoipLinePhone.
*
* @return {VoipLinePhone} The `VoipLinePhone` instance with options setted.
*/
setOptions (phoneOptions) {
this.protocol = phoneOptions.protocol;
this.macAddress = phoneOptions.macAddress;
this.maxline = phoneOptions.maxline;
this.mgcpIpRestriction = phoneOptions.mgcpIpRestriction;
this.description = phoneOptions.description;
this.phoneConfiguration = phoneOptions.phoneConfiguration;
}
}

return VoipLinePhone;

});
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* @ngdoc service
* @name managerApp.service:voipLinePhone
*
* @description
* <p>Service that manage phone linked to sip and mgcp features of services with serviceType line.</p>
* <p>This service will manage API calls to `/telephony/{billingAccount}/line/{serviceName}/phone`</p>
*/
angular.module("managerApp").service("voipLinePhone", class {

constructor (VoipLinePhone, voipService, OvhApiTelephony) {
this.VoipLinePhone = VoipLinePhone;
this.voipService = voipService;
this.OvhApiTelephony = OvhApiTelephony;
}

/**
* @ngdoc method
* @name managerApp.service:voipLinePhone#fetchAll
* @methodOf managerApp.service:voipLinePhone
*
* @description
* Fetch all phone of all services of serviceType line with featureType sip or mgcp from any billingAccount. This use APIv7 with wildcard and aggregation to achieve it.
*
* @return {Promise} That return an array of VoipLinePhone instances.
*/
fetchAll () {
return this.OvhApiTelephony.Line().Phone().Erika().query().aggregate("billingAccount").aggregate("serviceName").expand().execute().$promise.then((results) => {
let phoneList = [];

results.forEach((result) => {
// first retrieve billingAccount and serviceName from path
let splittedPath = result.path.split("/");

// extend phone options
let phoneOptions = angular.extend(result.value, {
billingAccount: splittedPath[2],
serviceName: splittedPath[4]
});

phoneList.push(new this.VoipLinePhone(phoneOptions));
});

return phoneList;
});
}

});

0 comments on commit fe26eae

Please sign in to comment.