UNPKG

1.99 kBJavaScriptView Raw
1/**
2 * Copyright (c) 2018, Kinvey, Inc. All rights reserved.
3 *
4 * This software is licensed to you under the Kinvey terms of service located at
5 * http://www.kinvey.com/terms-of-use. By downloading, accessing and/or using this
6 * software, you hereby accept such terms of service (and any agreement referenced
7 * therein) and agree that you have read, understand and agree to be bound by such
8 * terms of service and are of legal age to agree to such terms with Kinvey.
9 *
10 * This software contains valuable confidential and proprietary information of
11 * KINVEY, INC and is subject to applicable licensing agreements.
12 * Unauthorized reproduction, transmission or distribution of this file and its
13 * contents is a violation of applicable laws.
14 */
15
16const fs = require('fs');
17
18const BaseService = require('./BaseService');
19const { HTTPMethod } = require('./Constants');
20const { Endpoints, isNullOrUndefined } = require('./Utils');
21
22class PushService extends BaseService {
23 getPushSettings(envId, done) {
24 const endpoint = Endpoints.push(this.cliManager.config.defaultSchemaVersion, envId);
25 this.cliManager.sendRequest({ endpoint, method: HTTPMethod.GET }, done);
26 }
27
28 configureAndroidSettings(envId, data, done) {
29 const endpoint = Endpoints.push(this.cliManager.config.defaultSchemaVersion, envId);
30 this.cliManager.sendRequest({ endpoint, data, method: HTTPMethod.PUT }, done);
31 }
32
33 configureIosSettings(envId, data, done) {
34 const formData = {
35 production: JSON.stringify(data.production),
36 upload: fs.createReadStream(data.certificateFilePath)
37 };
38
39 if (!isNullOrUndefined(data.password)) {
40 formData.password = JSON.stringify(data.password);
41 }
42
43 const endpoint = Endpoints.push(this.cliManager.config.defaultSchemaVersion, envId);
44 this.cliManager.sendRequest({
45 endpoint,
46 formData,
47 method: HTTPMethod.POST
48 }, done);
49 }
50}
51
52module.exports = PushService;