Skip to content

Commit

Permalink
Merge pull request #10 from restricted/master
Browse files Browse the repository at this point in the history
[Fix] #9 Task count
  • Loading branch information
atnartur authored Aug 27, 2017
2 parents f1eae79 + c8517e5 commit 103af29
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
11 changes: 11 additions & 0 deletions lib/megaplan/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,17 @@ var clientProto = {
*/
EVN_AUTH: 'auth',

/**
* UserInfo
*
* Идентификационная информация.
*
* [More info]{@link https://dev.megaplan.ru/api/API_authorization.html#id17}
* @returns {MegaplanRequest}
*/
id: function() {
return this.__request('::userinfo/id.api', 'user');
},

/**
* Authenticates the client with login-pass pair
Expand Down
1 change: 1 addition & 0 deletions lib/megaplan/dicts.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module.exports = {
':staff': 'BumsStaffApiV01',
':crm': 'BumsCrmApiV01',

'::userinfo': ':common/UserInfo',
'::user': ':common/User',
'::auth': ':common/User/authorize.api',
'::system': ':common/System',
Expand Down
10 changes: 5 additions & 5 deletions lib/megaplan/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var http = require('http')
* @param {String} secret_key
* @param {String} uri Base uri of megaplan API. Базовый URI Megaplan API
* @param {Object} [data] Some data to send to Megaplan API. Данные, которые будут отправлены в Megaplan API
* @param {String|Function} [res_data_filter] Some key to return from response instead of all data or callback to filter response data. Некоторый ключ для возвращения ответа вместо всех данных или callback для фильтрации данных
* @param {String|Function} [res_data_filter] Some key to return from response instead of all data or callback to filter response data. Некоторый ключ для возвращения ответа вместо всех данных или callback для фильтрации данных
* @param {Function} [req_data_filter] Callback to filter request data. keysToPascalCase by default. Callback дя фильтрации ответа. По умолчанию keysToPascalCase
*/
var Request = function MegaplanRequest (server, access_id, secret_key, uri, data, res_data_filter, req_data_filter) {
Expand Down Expand Up @@ -76,14 +76,15 @@ Request.prototype = {
* @param {Function} [fail] Callback for errors. Callback для ошибок
*/
send: function (success, fail) {
var req, options, req_data_filter;
var req, options, req_data_filter, total;

success = success || this.success_callback;
fail = fail || this.fail_callback;

req_data_filter = this.req_data_filter || function (h) {
return utils.convertKeysToPascalCase(h);
};
total = this.data.count || false;
data = this.data && qs.stringify(req_data_filter(this.data));
// todo: qs.stringify can't create boundaries and attach files to post body.
// need to more powerfull thing to do it
Expand Down Expand Up @@ -139,15 +140,14 @@ Request.prototype = {
result = json.data || json.json || {};
result = utils.convertKeysToUnderscore(result);
result = utils.convertValuesToNatives(result);
if (jkey && (typeof jkey === 'string') && !result[jkey]) {
if (jkey && (typeof jkey === 'string') && !result[jkey] && !total) {
throw "key " + jkey + " not exists in json";
}
if (jkey && (typeof jkey === 'function')) {
result = jkey(result);
} else if (jkey) {
} else if (jkey && !total) {
result = result[jkey];
}

return success (result);

} catch (e) {
Expand Down

0 comments on commit 103af29

Please sign in to comment.