Commit 7b21ba3b2ec2b663c125f69b9cc91e99aff7ab2e

Authored by Adhidarma Hadiwinoto
1 parent 90fbdbf1de
Exists in master

coreapi jadi folder

Showing 2 changed files with 56 additions and 56 deletions Side-by-side Diff

lib/coreapi.js
... ... @@ -1,56 +0,0 @@
1   -"use strict";
2   -
3   -const request = require('request');
4   -
5   -const coreUrl = require('komodo-sdk/core-url');
6   -const logger = require('komodo-sdk/logger');
7   -const commandError = require('./command-handler/error');
8   -
9   -function execute(coreEndpoint, params, httpMethod, cb) {
10   - const requestOptions = {
11   - url: coreUrl + coreEndpoint,
12   - method: httpMethod || 'GET'
13   - }
14   -
15   - if (requestOptions.method === 'GET') {
16   - requestOptions.qs = params;
17   - }
18   - else if (requestOptions.method === 'POST') {
19   - requestOptions.data = params;
20   - }
21   -
22   - logger.verbose('Requesting to core', {url: requestOptions.url, http_method: httpMethod, params: params});
23   -
24   - request(requestOptions, function(err, res, body) {
25   - const responseParams = {
26   - directResponse: true,
27   - httpStatusCode: res ? res.statusCode : null,
28   - body: body
29   - }
30   -
31   - if (err) {
32   - cb(commandError.ERR_INVALID_CORE_RESPONSE, null, responseParams);
33   - return;
34   - }
35   -
36   - if (res.statusCode !== 200) {
37   - cb(commandError.ERR_INVALID_CORE_HTTP_STATUS_RESPONSE, null, responseParams);
38   - return;
39   - }
40   -
41   - try {
42   - var coreResponseObject = JSON.parse(body);
43   - }
44   - catch(e) {
45   - logger.verbose(commandError.ERR_INVALID_CORE_RESPONSE, {body: body})
46   - cb(commandError.ERR_INVALID_CORE_RESPONSE, null, responseParams);
47   - return;
48   - }
49   -
50   -
51   - cb(err, coreResponseObject, responseParams);
52   - })
53   -
54   -}
55   -
56   -module.exports = execute;
57 0 \ No newline at end of file
lib/coreapi/index.js
... ... @@ -0,0 +1,56 @@
  1 +"use strict";
  2 +
  3 +const request = require('request');
  4 +
  5 +const coreUrl = require('komodo-sdk/core-url');
  6 +const logger = require('komodo-sdk/logger');
  7 +const commandError = require('../command-handler/error');
  8 +
  9 +function execute(coreEndpoint, params, httpMethod, cb) {
  10 + const requestOptions = {
  11 + url: coreUrl + coreEndpoint,
  12 + method: httpMethod || 'GET'
  13 + }
  14 +
  15 + if (requestOptions.method === 'GET') {
  16 + requestOptions.qs = params;
  17 + }
  18 + else if (requestOptions.method === 'POST') {
  19 + requestOptions.data = params;
  20 + }
  21 +
  22 + logger.verbose('Requesting to core', {url: requestOptions.url, http_method: httpMethod, params: params});
  23 +
  24 + request(requestOptions, function(err, res, body) {
  25 + const responseParams = {
  26 + directResponse: true,
  27 + httpStatusCode: res ? res.statusCode : null,
  28 + body: body
  29 + }
  30 +
  31 + if (err) {
  32 + cb(commandError.ERR_INVALID_CORE_RESPONSE, null, responseParams);
  33 + return;
  34 + }
  35 +
  36 + if (res.statusCode !== 200) {
  37 + cb(commandError.ERR_INVALID_CORE_HTTP_STATUS_RESPONSE, null, responseParams);
  38 + return;
  39 + }
  40 +
  41 + try {
  42 + var coreResponseObject = JSON.parse(body);
  43 + }
  44 + catch(e) {
  45 + logger.verbose(commandError.ERR_INVALID_CORE_RESPONSE, {body: body})
  46 + cb(commandError.ERR_INVALID_CORE_RESPONSE, null, responseParams);
  47 + return;
  48 + }
  49 +
  50 +
  51 + cb(err, coreResponseObject, responseParams);
  52 + })
  53 +
  54 +}
  55 +
  56 +module.exports = execute;
0 57 \ No newline at end of file