github.com/readium/readium-lcp-server@v0.0.0-20240101192032-6e95190e99f1/frontend/manage/app/lsd/lsd.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 { LicenseStatus } from './license-status'
     7  
     8  declare var Config: any; //  this comes from the autogenerated config.js file
     9  
    10  @Injectable()
    11  export class LsdService {
    12      defaultHttpHeaders = new Headers(
    13          {'Content-Type': 'application/json'});
    14      baseUrl: string = Config.lsd.url;
    15  
    16      constructor (private http: Http) {
    17      }
    18  
    19      get(id: string): Promise<LicenseStatus> {
    20          let url = this.baseUrl + "/licenses/" + id + "/status";
    21          return this.http
    22              .get(
    23                  url,
    24                  { headers: this.defaultHttpHeaders })
    25              .toPromise()
    26              .then(function (response) {
    27                  if (response.ok) {
    28                      let jsonObj = response.json();
    29                      let licenseStatus = jsonObj as LicenseStatus;
    30                      return licenseStatus;
    31                  } else {
    32                      throw 'Error retrieving license ' + response.text();
    33                  }
    34              })
    35              .catch(this.handleError);
    36      }
    37  
    38      protected handleError(error: any): Promise<any> {
    39          console.error('An error occurred', error);
    40          return Promise.reject(error.message || error);
    41      }
    42  }