UNPKG

@abl-solutions/wifi-connect

Version:

The WiFi Connect React Native SDK enables the use of WiFi WPA2-Enterprise networks on mobile devices that are managed and operated by abl solutions GmbH

74 lines (59 loc) 2.84 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CampaignServiceImpl = void 0; var _http = require("./http"); function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } class CampaignServiceImpl { constructor(campaignOptions) { _defineProperty(this, "options", void 0); this.throwIfInvalidOptions(campaignOptions); this.options = this.mergeWithDefaultOptions(campaignOptions); } async getNextCampaign(deviceId) { var _body$required, _body$notification, _body$notification2; const endpoint = `${this.options.campaignApiEndpoint}/api/v1/campaigns/next?deviceId=${deviceId}`; var response = await fetch(endpoint, { method: 'GET', headers: { Authorization: `Bearer ${this.options.accessToken}`, Accept: 'application/json' } }); const body = await response.json(); (0, _http.throwOnInvliadResponse)(response.status, body); // copy the values to ensure that the response always contains the required properties return { campaignUrl: body === null || body === void 0 ? void 0 : body.campaignUrl, required: (_body$required = body === null || body === void 0 ? void 0 : body.required) !== null && _body$required !== void 0 ? _body$required : false, notification: { title: body === null || body === void 0 ? void 0 : (_body$notification = body.notification) === null || _body$notification === void 0 ? void 0 : _body$notification.title, body: body === null || body === void 0 ? void 0 : (_body$notification2 = body.notification) === null || _body$notification2 === void 0 ? void 0 : _body$notification2.body }, type: body === null || body === void 0 ? void 0 : body.type, timeUntilNextCampaignToWatch: (body === null || body === void 0 ? void 0 : body.timeUntilNextCampaignToWatch) || 0 }; } shouldCloseCampaignView(campaignUrl) { return campaignUrl.includes('close_campaign=true'); } mergeWithDefaultOptions(options) { return { accessToken: options.accessToken, campaignApiEndpoint: (options === null || options === void 0 ? void 0 : options.campaignApiEndpoint) || 'https://api.wifi-connect.campaign-manager.ads.abl-solutions.io' }; } throwIfInvalidOptions(options) { if (!options) { throw new Error('CampaignOptions must be not null.'); } if (!options.accessToken) { throw new Error('CampaignOptions.accessToken must be not null.'); } if (options.accessToken === '') { throw new Error('CampaignOptions.accessToken must be not empty.'); } } } exports.CampaignServiceImpl = CampaignServiceImpl; //# sourceMappingURL=campaign.js.map