import { TrustpilotBusinessUnitWebLinks, TrustpilotBusinessUnit, TrustpilotSummary } from '../entities/Trustpilot'; export class TrustpilotClient { readonly businessUnitId: string; readonly baseUrl: string; readonly businessUnit: string; readonly businessUnitWebLinks: string; constructor(private $q: QService, private $http: HttpService) { this.businessUnitId = "4e71fb7f0000640005110198"; this.baseUrl = "https://api.trustpilot.com"; this.businessUnit = this.baseUrl + "/v1/business-units/" + this.businessUnitId; this.businessUnitWebLinks = this.businessUnit + "/web-links"; } private config(params?: any): ng.IRequestShortcutConfig { return { cache: true, headers: { "apikey": "mTq5iji1OECTPmvVHqwjSFMygbaNzDs5", 'If-Modified-Since': undefined, 'app-version': undefined, 'platform': undefined }, params: params }; } private getBusinessUnit(): HttpPromise { return this.$http.get(this.businessUnit, this.config()); } private getWebLinks(): HttpPromise { return this.$http.get(this.businessUnitWebLinks, this.config({ locale: "en-gb" }) ); } getSummary(): Promise { return this.$q.all({ businessUnit: this.getBusinessUnit(), webLinks: this.getWebLinks() }).then((response) => ({ trustScore: response.businessUnit.data.trustScore, numberOfReviews: response.businessUnit.data.numberOfReviews.total, profileUrl: response.webLinks.data.profileUrl, })); } }