UNPKG

airship-server

Version:

Airship is a framework for Node.JS & TypeScript that helps you to write big, scalable and maintainable API servers.

168 lines (167 loc) 4.38 kB
/** * This is an automatically generated code (and probably compiled with TSC) * Generated at Sun Oct 08 2017 02:49:04 GMT+0300 (MSK) * Scheme version: 2 */ const API_PATH = '/api/'; require('whatwg-fetch'); import * as Responses from './Responses'; export default class AirshipApi { async call(method, params, responseType) { return fetch(API_PATH + method, { method: 'POST', body: JSON.stringify(params), headers: { 'Content-Type': 'application/serializable' } }) .then(r => { return r.json(); }) .then(json => { if (json.ok == false) throw Responses.ErrorResponse.deserialize(json); else return json; }) .then(data => { if (responseType) return responseType.deserialize(data); return data; }); } /** * * * @param {{ * groupId: (number), * userId: (number), * appUrl: (string), * userAgent: (string), * errors: (string) * }} params * * @returns {Promise<ASSuccessResponse>} */ async sendErrorReport(params) { return this.call('sendErrorReport', { groupId: params.groupId, userId: params.userId, appUrl: params.appUrl, userAgent: params.userAgent, errors: params.errors }, Responses.SuccessResponse); } /** * * * @param {{ * appParams: (string), * groupId: (number), * event: (Event) * }} params * * @returns {Promise<ASSuccessResponse>} */ async saveEvent(params) { return this.call('saveEvent', { appParams: params.appParams, groupId: params.groupId, event: params.event ? params.event.serialize() : undefined }, Responses.SuccessResponse); } /** * * * @param {{ * authKey: (string), * viewerId: (number), * groupId: (number) * }} params * * @returns {Promise<GetEventResponse>} */ async getEvent(params) { return this.call('getEvent', { authKey: params.authKey, viewerId: params.viewerId, groupId: params.groupId }, Responses.GetEventResponse); } /** * * * @param {{ * appParams: (string), * groupId: (number) * }} params * * @returns {Promise<CheckGroupTokenResponse>} */ async checkGroupToken(params) { return this.call('checkGroupToken', { appParams: params.appParams, groupId: params.groupId }, Responses.CheckGroupTokenResponse); } /** * * * @param {{ * appParams: (string), * groupId: (number), * token: (string), * scope: (number) * }} params * * @returns {Promise<ASSuccessResponse>} */ async addGroupToken(params) { return this.call('addGroupToken', { appParams: params.appParams, groupId: params.groupId, token: params.token, scope: params.scope }, Responses.SuccessResponse); } /** * * * @param {{ * authKey: (string), * viewerId: (number), * groupId: (number), * eventItemId: (number), * subscribe: (boolean) * }} params * * @returns {Promise<ASSuccessResponse>} */ async subscribeNotification(params) { return this.call('subscribeNotification', { authKey: params.authKey, viewerId: params.viewerId, groupId: params.groupId, eventItemId: params.eventItemId, subscribe: params.subscribe }, Responses.SuccessResponse); } /** * * * @param {{ * authKey: (string), * viewerId: (number), * groupId: (number) * }} params * * @returns {Promise<GetSubscribedEventItemsResponse>} */ async getSubscribedEventItems(params) { return this.call('getSubscribedEventItems', { authKey: params.authKey, viewerId: params.viewerId, groupId: params.groupId }, Responses.GetSubscribedEventItemsResponse); } }