UNPKG

moves-client

Version:
309 lines (264 loc) 10.4 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _regenerator = require('babel-runtime/regenerator'); var _regenerator2 = _interopRequireDefault(_regenerator); var _asyncToGenerator2 = require('babel-runtime/helpers/asyncToGenerator'); var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2); var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck'); var _classCallCheck3 = _interopRequireDefault(_classCallCheck2); var _createClass2 = require('babel-runtime/helpers/createClass'); var _createClass3 = _interopRequireDefault(_createClass2); var _axios = require('axios'); var _axios2 = _interopRequireDefault(_axios); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } var MovesClient = function () { function MovesClient(accessToken) { (0, _classCallCheck3.default)(this, MovesClient); this.accessToken = accessToken; this.httpClient = _axios2.default.create({ baseURL: 'https://api.moves-app.com/api/1.1', headers: { Authorization: 'Bearer ' + this.accessToken } }); } /* https://dev.moves-app.com/docs/api_activities */ (0, _createClass3.default)(MovesClient, [{ key: 'getActivities', value: function () { var _ref = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee() { return _regenerator2.default.wrap(function _callee$(_context) { while (1) { switch (_context.prev = _context.next) { case 0: return _context.abrupt('return', this.httpClient({ method: 'get', url: '/activities' }).then(function (response) { return response.data; })); case 1: case 'end': return _context.stop(); } } }, _callee, this); })); function getActivities() { return _ref.apply(this, arguments); } return getActivities; }() /* https://dev.moves-app.com/docs/api_profile */ }, { key: 'getUserProfile', value: function () { var _ref2 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee2() { return _regenerator2.default.wrap(function _callee2$(_context2) { while (1) { switch (_context2.prev = _context2.next) { case 0: return _context2.abrupt('return', this.httpClient({ method: 'get', url: '/user/profile' }).then(function (response) { return response.data; })); case 1: case 'end': return _context2.stop(); } } }, _callee2, this); })); function getUserProfile() { return _ref2.apply(this, arguments); } return getUserProfile; }() /* https://dev.moves-app.com/docs/api_summaries date in yyyyMMdd or yyyy-MM-dd format week in yyyy-’W’ww format, for example 2013-W09 month in yyyyMM or yyyy-MM format updatedSince: if true, return only days which data has been updated since given timestamp in ISO 8601 (yyyyMMdd’T’HHmmssZ) format timeZone: use the given time zone ID for the date period and timestamps, overriding the users current time zone */ }, { key: 'getDailySummary', value: function () { var _ref3 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee3(calendarInterval) { var updatedSince = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; var timeZone = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; return _regenerator2.default.wrap(function _callee3$(_context3) { while (1) { switch (_context3.prev = _context3.next) { case 0: return _context3.abrupt('return', this.httpClient({ method: 'get', url: '/user/summary/daily/' + calendarInterval, params: { updatedSince: updatedSince, timeZone: timeZone } }).then(function (response) { return response.data; })); case 1: case 'end': return _context3.stop(); } } }, _callee3, this); })); function getDailySummary(_x) { return _ref3.apply(this, arguments); } return getDailySummary; }() }, { key: 'getDailySummaryForDate', value: function () { var _ref4 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee4(date) { var updatedSince = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; var timeZone = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; return _regenerator2.default.wrap(function _callee4$(_context4) { while (1) { switch (_context4.prev = _context4.next) { case 0: return _context4.abrupt('return', this.getDailySummary(date, updatedSince, timeZone)); case 1: case 'end': return _context4.stop(); } } }, _callee4, this); })); function getDailySummaryForDate(_x4) { return _ref4.apply(this, arguments); } return getDailySummaryForDate; }() }, { key: 'getDailySummaryForWeek', value: function () { var _ref5 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee5(week) { var updatedSince = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; var timeZone = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; return _regenerator2.default.wrap(function _callee5$(_context5) { while (1) { switch (_context5.prev = _context5.next) { case 0: return _context5.abrupt('return', this.getDailySummary(week, updatedSince, timeZone)); case 1: case 'end': return _context5.stop(); } } }, _callee5, this); })); function getDailySummaryForWeek(_x7) { return _ref5.apply(this, arguments); } return getDailySummaryForWeek; }() }, { key: 'getDailySummaryForMonth', value: function () { var _ref6 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee6(month) { var updatedSince = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; var timeZone = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; return _regenerator2.default.wrap(function _callee6$(_context6) { while (1) { switch (_context6.prev = _context6.next) { case 0: return _context6.abrupt('return', this.getDailySummary(month, updatedSince, timeZone)); case 1: case 'end': return _context6.stop(); } } }, _callee6, this); })); function getDailySummaryForMonth(_x10) { return _ref6.apply(this, arguments); } return getDailySummaryForMonth; }() }, { key: 'getDailySummaryForDateRange', value: function () { var _ref7 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee7(startDate, endDate) { var updatedSince = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; var timeZone = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null; return _regenerator2.default.wrap(function _callee7$(_context7) { while (1) { switch (_context7.prev = _context7.next) { case 0: return _context7.abrupt('return', this.httpClient({ method: 'get', url: '/user/summary/daily', params: { from: startDate, to: endDate, updatedSince: updatedSince, timeZone: timeZone } }).then(function (response) { return response.data; })); case 1: case 'end': return _context7.stop(); } } }, _callee7, this); })); function getDailySummaryForDateRange(_x13, _x14) { return _ref7.apply(this, arguments); } return getDailySummaryForDateRange; }() }, { key: 'getPastDailySummaries', value: function () { var _ref8 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee8(previousDaysCount) { var updatedSince = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; var timeZone = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; return _regenerator2.default.wrap(function _callee8$(_context8) { while (1) { switch (_context8.prev = _context8.next) { case 0: return _context8.abrupt('return', this.httpClient({ method: 'get', url: '/user/summary/daily', params: { pastDays: previousDaysCount, updatedSince: updatedSince, timeZone: timeZone } }).then(function (response) { return response.data; })); case 1: case 'end': return _context8.stop(); } } }, _callee8, this); })); function getPastDailySummaries(_x17) { return _ref8.apply(this, arguments); } return getPastDailySummaries; }() }]); return MovesClient; }(); exports.default = MovesClient;