rubik-pact 1.0.3 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/classes/Pact/methods.js +1 -0
- package/classes/Pact.js +10 -7
- package/package.json +1 -1
package/classes/Pact/methods.js
CHANGED
|
@@ -3,4 +3,5 @@ module.exports = [
|
|
|
3
3
|
{ kubikName: 'companies.conversations.messages', apiName: 'companies/{{companyId}}/conversations/{{conversationId}}/messages' },
|
|
4
4
|
{ kubikName: 'companies.conversations.messages.attachments', apiName: 'companies/{{companyId}}/conversations/{{conversationId}}/messages/attachments' },
|
|
5
5
|
{ kubikName: 'companies.conversationsGet', apiName: 'companies/{{companyId}}/conversations/{{conversationId}}' }
|
|
6
|
+
{ kubikName: 'companies.companyId', apiName: 'companies/{{companyId}}' }
|
|
6
7
|
];
|
package/classes/Pact.js
CHANGED
|
@@ -4,6 +4,7 @@ const fetch = require('node-fetch');
|
|
|
4
4
|
const set = require('lodash/set');
|
|
5
5
|
const isObject = require('lodash/isObject');
|
|
6
6
|
const get = require('lodash/get');
|
|
7
|
+
const querystring = require('querystring');
|
|
7
8
|
|
|
8
9
|
const methods = require('./Pact/methods');
|
|
9
10
|
|
|
@@ -42,7 +43,7 @@ class Pact extends Kubik {
|
|
|
42
43
|
this.version = this.version || options.version || DEFAULT_VERSION;
|
|
43
44
|
}
|
|
44
45
|
|
|
45
|
-
getUrl({ path, params, host }) {
|
|
46
|
+
getUrl({ path, queryParams, params, host }) {
|
|
46
47
|
if (!host) host = this.host;
|
|
47
48
|
if (!host) throw new TypeError('host is not defined');
|
|
48
49
|
|
|
@@ -51,7 +52,9 @@ class Pact extends Kubik {
|
|
|
51
52
|
if (params.conversationId) path = path.replace('{{conversationId}}', params.conversationId);
|
|
52
53
|
if (params.channelId) path = path.replace('{{channelId}}', params.channelId);
|
|
53
54
|
|
|
54
|
-
|
|
55
|
+
if (!queryParams) queryParams = {};
|
|
56
|
+
|
|
57
|
+
return `${host}p1/${path}?${querystring.stringify(queryParams)}`;
|
|
55
58
|
}
|
|
56
59
|
|
|
57
60
|
/**
|
|
@@ -63,13 +66,13 @@ class Pact extends Kubik {
|
|
|
63
66
|
* @param {String} [host=this.host] хост API Viber
|
|
64
67
|
* @return {Promise<Object>} ответ от Pact API
|
|
65
68
|
*/
|
|
66
|
-
async request({ path, body, params, token, host }) {
|
|
67
|
-
const url = this.getUrl({ path, params, host });
|
|
69
|
+
async request({ path, body, params, token, host, method, queryParams }) {
|
|
70
|
+
const url = this.getUrl({ path, params, host, queryParams});
|
|
68
71
|
|
|
69
72
|
if (!token) token = this.token;
|
|
70
73
|
const headers = { 'X-Private-Api-Token': token };
|
|
71
74
|
|
|
72
|
-
let method = 'POST'
|
|
75
|
+
let method = method || 'POST'
|
|
73
76
|
if (body instanceof FormData) {
|
|
74
77
|
Object.assign(headers, body.getHeaders());
|
|
75
78
|
} else if (isObject(body)) {
|
|
@@ -102,8 +105,8 @@ class Pact extends Kubik {
|
|
|
102
105
|
generateMethod({ kubikName, apiName }) {
|
|
103
106
|
const method = (options) => {
|
|
104
107
|
if (!options) options = {};
|
|
105
|
-
const { params, body, token, host } = options;
|
|
106
|
-
return this.request({ path: apiName, body, params, token, host });
|
|
108
|
+
const { params, body, token, host, queryParams, method } = options;
|
|
109
|
+
return this.request({ path: apiName, body, params, token, host, queryParams, method });
|
|
107
110
|
};
|
|
108
111
|
set(this, kubikName, method);
|
|
109
112
|
}
|