@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
64 lines (53 loc) • 2.68 kB
JavaScript
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; }
import { throwOnInvliadResponse } from './http';
export 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();
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.');
}
}
}
//# sourceMappingURL=campaign.js.map