-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathexposure.js
76 lines (67 loc) · 2.44 KB
/
exposure.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
//const debug = require("debug")("mgmt");
const EXPOSURE_API_ENDPOINT_PROD =
"https://exposure.api.redbee.live/v2";
const EXPOSURE_API_ENDPOINT_STAGE =
"https://psempexposureapi.ebsd.ericsson.net/v2";
const authService = require("../services/authService");
const entitlementService = require("../services/entitlementService");
const assetService = require("../services/assetService");
const BaseApi = require("../utils/baseApi");
class ExposureAPI extends BaseApi {
constructor(customerUnit, businessUnit, options) {
options = {
environment: "production",
...options,
};
const url =
options.environment === "stage"
? EXPOSURE_API_ENDPOINT_STAGE
: EXPOSURE_API_ENDPOINT_PROD;
super(url);
this.customerUnit = customerUnit;
this.businessUnit = businessUnit;
}
async authenticate(username, password) {
if (!this.customerUnit || !this.businessUnit) return;
const url = `${this.baseUrl}/customer/${this.customerUnit}/businessunit/${this.businessUnit}/auth/login`;
return await authService.authenticate({
url,
username,
password,
});
}
async play(sessionToken, assetId) {
if (!this.customerUnit || !this.businessUnit) return;
const url = `${this.baseUrl}/customer/${this.customerUnit}/businessunit/${this.businessUnit}/entitlement/${assetId}/play`;
return await entitlementService.play({
url,
sessionToken,
});
}
async getAssets({ assetType = undefined, onlyPublished = true }) {
if (!this.customerUnit || !this.businessUnit) return;
const url = `${this.baseUrl.replace("v2", "v1")}/customer/${
this.customerUnit
}/businessunit/${this.businessUnit}/content/asset`;
return await assetService.getAllAssets({
url,
onlyPublished,
...(assetType && { assetType }),
});
}
async getAsset(assetId) {
if (!this.customerUnit || !this.businessUnit) return;
const url = `${this.baseUrl.replace("v2", "v1")}/customer/${
this.customerUnit
}/businessunit/${this.businessUnit}/content/asset/${assetId}`;
return await assetService.getAsset(`${url}?onlyPublished=false`);
}
async resolveSerie(serieId) {
if (!this.customerUnit || !this.businessUnit) return;
const url = `${this.baseUrl.replace("v2", "v1")}/customer/${
this.customerUnit
}/businessunit/${this.businessUnit}/content/asset/${serieId}`;
return await assetService.resolveSerie(url);
}
}
module.exports = ExposureAPI;