import { HttpHeaders } from "../httpHeaders" ; import { WebResourceLike } from "../webResource" ; import { ServiceClientCredentials } from "./serviceClientCredentials" ; interface export interface ApiKeyCredentialOptions { /**
     * A key value pair of the header parameters that need to be applied to the request.
     */ inHeader ? : { [ x ] : any ; } ; /**
     * A key value pair of the query parameters that need to be applied to the request.
     */ inQuery ? : { [ x ] : any ; } ; } /**
 * Authenticates to a service using an API key.
 */ export class ApiKeyCredentials implements ServiceClientCredentials { /**
     * A key value pair of the header parameters that need to be applied to the request.
     */ private readonly inHeader ? : { [ x ] : any ; } ; /**
     * A key value pair of the query parameters that need to be applied to the request.
     */ private readonly inQuery ? : { [ x ] : any ; } ; constructor param { object } options constructor ( options ) { if ( ! options || ( options && ! options . inHeader && ! options . inQuery ) ) { throw new Error ( `options cannot be null or undefined. Either "inHeader" or "inQuery" property of the options object needs to be provided.` ) ; } this . inHeader = options . inHeader ; this . inQuery = options . inQuery ; } param { WebResource } webResource returns { Promise < WebResource > } signRequest ( webResource ) { if ( ! webResource ) { return Promise . reject ( new Error ( `webResource cannot be null or undefined and must be of type "object".` ) ) ; } if ( this . inHeader ) { if ( ! webResource . headers ) { webResource . headers = new HttpHeaders ( ) ; } for ( const headerName in this . inHeader ) { webResource . headers . set ( headerName , this . inHeader [ headerName ] ) ; } } if ( this . inQuery ) { if ( ! webResource . url ) { return Promise . reject ( new Error ( `url cannot be null in the request object.` ) ) ; } if ( webResource . url . indexOf ( "?" ) < 0 ) { webResource . url += "?" ; } for ( const key in this . inQuery ) { if ( ! webResource . url . endsWith ( "?" ) ) { webResource . url += "&" ; } webResource . url += `${ key }=${ this . inQuery [ key ] }` ; } } return Promise . resolve ( webResource ) ; } }