Skip to content

Commit

Permalink
Merge branch 'feature/requests_with_filters' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Francesco Faraone committed Dec 12, 2019
2 parents b0fa381 + d498876 commit 9e138c0
Show file tree
Hide file tree
Showing 17 changed files with 2,084 additions and 39 deletions.
3 changes: 2 additions & 1 deletion docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
Sphinx==2.2.1
Sphinx==1.8.5
sphinx-js==2.8
sphinx_rtd_theme==0.4.3
4 changes: 1 addition & 3 deletions lib/connect/api/conversations.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* @copyright (c) 2019. Ingram Micro. All Rights Reserved.
*/

// const _ = require('lodash');
const BaseService = require('./base');

/**
Expand All @@ -17,7 +16,7 @@ class ConversationService extends BaseService {
*
* @param {string} id The unique request identifier for which retrieve the conversationId.
*
* @returns {string} An array with the id.
* @returns {string} Conversation ID.
*/

async getConversationIdByRequest(id) {
Expand All @@ -29,7 +28,6 @@ class ConversationService extends BaseService {
return conv[0].id;
}
return null;

}
}

Expand Down
26 changes: 26 additions & 0 deletions lib/connect/api/hubs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* This file is part of the Ingram Micro Cloud Blue Connect SDK.
*
* @copyright (c) 2019. Ingram Micro. All Rights Reserved.
*/

const BaseService = require('./base');

/**
* The AccountService class provides methods to access the accounts
* endpoint of the Cloud Blue Connect API.
*/
class HubService extends BaseService {
/**
* Get a list of tier accounts.
*
* @return {Array} Returns an Array of the TierAccount object.
*/
async list() {
const response = await this.fetch('/hubs');
await this.checkResponse(response);
return response.json();
}
}

module.exports = HubService;
11 changes: 10 additions & 1 deletion lib/connect/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,14 @@ const RequestService = require('./requests');
const AccountService = require('./accounts');
const ProductService = require('./products');
const ConversationService = require('./conversations');
const HubService = require('./hubs');
const TierAccountService = require('./tierAccounts');

module.exports = { AccountService, ProductService, RequestService, ConversationService };
module.exports = {
AccountService,
ProductService,
RequestService,
ConversationService,
HubService,
TierAccountService,
};
11 changes: 4 additions & 7 deletions lib/connect/api/products.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ class ProductService extends BaseService {
}

/**
* Retrieves the list of parameters of scope asset and phase fulfillment configured for the product.
* Retrieves the list of parameters of scope asset and phase fulfillment configured for
* the product.
*
* @param {string} id The unique product identifier for which retrieve the parameters.
*
Expand All @@ -51,9 +52,7 @@ class ProductService extends BaseService {

async getAssetParametersForFulfillmentByProduct(id) {
const params = await this.getParametersByProduct(id);
return _.filter(params, param => {
return param.scope === 'asset' && param.phase === 'fulfillment';
});
return _.filter(params, (param) => param.scope === 'asset' && param.phase === 'fulfillment');
}

/**
Expand All @@ -78,9 +77,7 @@ class ProductService extends BaseService {
*/
async getProductAssetTemplates(id) {
const templates = await this.getProductTemplates(id);
return _.filter(templates, template => {
return template.scope === 'asset'
});
return _.filter(templates, (template) => template.scope === 'asset');
}
}

Expand Down
33 changes: 18 additions & 15 deletions lib/connect/api/requests.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ const { addFilterParam } = require('./utils');
* endpoint of the Cloud Blue Connect API.
*/
class RequestService extends BaseService {
/* eslint-disable max-len */
/**
* Get a list of requests that match all the filter values provided as input.
* Some fields accept an array of values (search with the `in` operator).
*
* @param {Object} filter A filter object as described below.
*
* @param {string|Array} filter.type The request type (purchase|change|suspend|resume|renew|cancel).
*
* @param {Object} filter A filter object as described below.
*
* @param {string|Array} filter.type The request type
* (purchase|change|suspend|resume|renew|cancel).
* @param {string|Array} filter.status The status of the request (pending|inquiring|failed|approved).
* @param {string|Array} filter.id The id of the request.
* @param {string|Array} filter.assetId The id of the asset that belongs to the request.
Expand All @@ -34,9 +36,10 @@ class RequestService extends BaseService {
* @param {string|Array} filter.assetTiersCustomerId The id of the customer account for this asset.
* @param {string|Array} filter.assetTiersTier1Id The id of T1 account for this asset.
* @param {string|Array} filter.assetTiersTier2Id The id of T2 account for this asset.
*
*
* @return {Array} An array of Request objects that match the provided filters.
*/
/* eslint-enable max-len */
async list({
type,
status,
Expand Down Expand Up @@ -109,7 +112,7 @@ class RequestService extends BaseService {
* @param {sring} reason Description of the reason of inquire
* @param {sring} templateId Activation Template ID
* @param {Array} params An array of parameter objects ({id, value}) to update for Request.
*
*
* @return {*} [Check return type]£
*/
async inquireRequest(id, reason, templateId, params) {
Expand All @@ -118,7 +121,7 @@ class RequestService extends BaseService {
const options = {
method: 'POST',
body: {
'template_id': templateId,
template_id: templateId,
},
};
const response = await this.fetch(url, options);
Expand All @@ -138,7 +141,7 @@ class RequestService extends BaseService {
const url = `/requests/${id}`;
const options = {
method: 'PUT',
body: request
body: request,
};
const response = await this.fetch(url, options);
await this.checkResponse(response);
Expand All @@ -160,8 +163,8 @@ class RequestService extends BaseService {
method: 'PUT',
body: {
asset: {
params
}
params,
},
},
};
if (note !== undefined) {
Expand All @@ -185,9 +188,9 @@ class RequestService extends BaseService {
const options = {
method: 'POST',
body: {
template_id: templateId
}
}
template_id: templateId,
},
};
const response = await this.fetch(url, options);
await this.checkResponse(response);
return response.json();
Expand All @@ -204,8 +207,8 @@ class RequestService extends BaseService {
const url = '/requests';
const options = {
method: 'POST',
body: req
}
body: req,
};
const response = await this.fetch(url, options);
await this.checkResponse(response);
return response.json();
Expand Down
26 changes: 26 additions & 0 deletions lib/connect/api/tierAccounts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* This file is part of the Ingram Micro Cloud Blue Connect SDK.
*
* @copyright (c) 2019. Ingram Micro. All Rights Reserved.
*/

const BaseService = require('./base');

/**
* The AccountService class provides methods to access the accounts
* endpoint of the Cloud Blue Connect API.
*/
class TierAccountService extends BaseService {
/**
* Get a list of tier accounts.
*
* @return {Array} Returns an Array of the TierAccount object.
*/
async list() {
const response = await this.fetch('/tier/accounts');
await this.checkResponse(response);
return response.json();
}
}

module.exports = TierAccountService;
40 changes: 31 additions & 9 deletions lib/connect/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,48 +37,70 @@ class ConnectClient {
this._products = new api.ProductService(this._adapter);
this._requests = new api.RequestService(this._adapter);
this._conversations = new api.ConversationService(this._adapter);
this._hubs = new api.HubService(this._adapter);
this._tierAccounts = new api.TierAccountService(this._adapter);
}

/**
* Returns an instance of the `AccountService` class to access
* Returns an instance of the `AccountService` class to access
* the `Account` resource endpoint.
*
*
* @type {AccountService}
*/
get accounts() {
return this._accounts;
}

/**
* Returns an instance of the `ConversationService` class to access
* Returns an instance of the `ConversationService` class to access
* the `Conversation` resource endpoint.
*
*
* @type {ConversationService}
*/
get conversations() {
return this._conversations;
}

/**
* Returns an instance of the `ProductService` class to access
* Returns an instance of the `ProductService` class to access
* the `Product` resource endpoint.
*
*
* @type {ProductService}
*/
get products() {
return this._products;
}

/**
* Returns an instance of the `RequestService` class to access
* Returns an instance of the `RequestService` class to access
* the `Request` resource endpoint.
*
*
* @type {RequestService}
*/
get requests() {
return this._requests;
}

/**
* Returns an instance of the `HubService` class to access
* the `Hub` resource endpoint.
*
* @type {HubService}
*/
get hubs() {
return this._hubs;
}

/**
* Returns an instance of the `TierAccountService` class to access
* the `Hub` resource endpoint.
*
* @type {TierAccountService}
*/
get tierAccounts() {
return this._tierAccounts;
}

/**
* beforeRequest hook that add the api key to the authorization header.
*
Expand Down
6 changes: 6 additions & 0 deletions lib/connect/http/adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ class DefaultHttpAdapter extends AbstractHttpAdapter {
}

prepareRequest(url, options) {
if (options.body) {
if (_.isArray(options.body) || _.isPlainObject(options.body)) {
options.body = JSON.stringify(options.body);
options.headers = _.assign({}, options.headers, { 'Content-Type': 'application/json' });
}
}
return { url, options };
}

Expand Down
25 changes: 25 additions & 0 deletions test/connect/api/hubs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* This file is part of the Ingram Micro Cloud Blue Connect SDK.
*
* @copyright (c) 2019. Ingram Micro. All Rights Reserved.
*/

const should = require('should');
const nock = require('nock');
const responses = require('./responses');
const connect = require('../../../index');
const ConnectClient = connect.ConnectClient;
const HttpError = connect.HttpError;


describe('Connect Javascript SDK - Hubs', () => {
afterEach(done => { nock.cleanAll(); done(); });
it('returns a list of hubs', async () => {
nock('https://localhost')
.get('/hubs')
.reply(200, responses.hubs.hubs_list);
const client = new ConnectClient('https://localhost', '1234567890');
const response = await client.hubs.list();
response.should.be.an.Array();
});
});
2 changes: 1 addition & 1 deletion test/connect/api/requests.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ describe('Connect Javascript SDK - Requests', () => {
});
it('approve request', async () => {
nock('https://localhost')
.post('/requests/PR-0000-0000-0000-000/approve')
.post('/requests/PR-0000-0000-0000-000/approve', {template_id: 'TL-000-000-000'})
.reply(200, responses.requests.approve_request);
const client = new ConnectClient('https://localhost', '1234567890');

Expand Down

0 comments on commit 9e138c0

Please sign in to comment.