github.com/readium/readium-lcp-server@v0.0.0-20240101192032-6e95190e99f1/frontend/manage/app/license/license.service.ts (about) 1 import { Injectable } from '@angular/core'; 2 import { Http, Headers } from '@angular/http'; 3 4 import 'rxjs/add/operator/toPromise'; 5 6 import { License } from './license'; 7 import { CrudService } from '../crud/crud.service'; 8 9 declare var Config: any; // this comes from the autogenerated config.js file 10 11 @Injectable() 12 export class LicenseService{ 13 private masterFileListUrl: string; 14 private http:Http; 15 private baseUrl: string; 16 private lsdUrl: string; 17 defaultHttpHeaders = new Headers({'Content-Type': 'application/json'}); 18 19 20 constructor (http: Http) { 21 this.http = http; 22 this.baseUrl = Config.frontend.url; 23 this.lsdUrl = Config.lsd.url 24 this.masterFileListUrl = Config.frontend.url + '/api/v1/repositories/master-files'; 25 } 26 27 28 decode(jsonObj: any): License { 29 return { 30 id: jsonObj.ID, 31 publicationTitle: jsonObj.publication_title, 32 userName: jsonObj.user_name, 33 type: jsonObj.type, 34 devices: jsonObj.device_count, 35 status: jsonObj.status, 36 purchaseID: jsonObj.purchase_id 37 } 38 } 39 40 get(devices: number): Promise<License[]> { 41 var self = this 42 var headers: Headers = new Headers; 43 return this.http 44 .get( 45 this.baseUrl + "/api/v1/licenses?devices=" + devices, 46 { headers: this.defaultHttpHeaders }) 47 .toPromise() 48 .then(function (response) { 49 let items: License[] = []; 50 51 for (let jsonObj of response.json()) { 52 items.push(self.decode(jsonObj)); 53 } 54 return items; 55 }) 56 .catch(this.handleError); 57 } 58 59 protected handleError(error: any): Promise<any> { 60 console.error('An error occurred', error); 61 return Promise.reject(error.message || error); 62 } 63 }