module Sfx { export class HttpClient { private httpClient : Promise < Standalone . http . IHttpClient > ; constructor ( private $q , private $http ) { if ( StandaloneIntegration . isStandalone ( ) ) { this . httpClient = StandaloneIntegration . getHttpClient ( ) ; this . httpClient . then ( ( client ) => client . setRequestTemplateAsync ( { method : undefined , url : undefined , headers : [ { name : Constants . SfxVersionMetadataName , value : VersionInfo . Version } , { name : Constants . SfxBuildMetadataName , value : VersionInfo . Build } , { name : Constants . SfxTelemetryMetadataName , value : Constants . SfxTelemetryHeaderValue } ] } ) ) ; } this . $http . defaults . headers . common [ Constants . SfxVersionMetadataName ] = VersionInfo . Version ; this . $http . defaults . headers . common [ Constants . SfxBuildMetadataName ] = VersionInfo . Build ; this . $http . defaults . headers . common [ Constants . SfxTelemetryMetadataName ] = Constants . SfxTelemetryHeaderValue ; } public getAsync < T > ( url ) { return this . httpClient ? this . requestAsync ( { method : "GET" , url : url } ) : this . $http . get ( url ) ; } public postAsync < T > ( url , data ) { return this . httpClient ? this . requestAsync ( { method : "POST" , url : url , body : data } ) : this . $http . post ( url , data ) ; } public putAsync < T > ( url , data ) { return this . httpClient ? this . requestAsync ( { method : "PUT" , url : url , body : data } ) : this . $http . put ( url , data ) ; } public patchAsync < T > ( url , data ) { return this . httpClient ? this . requestAsync ( { method : "PATCH" , url : url , body : data } ) : this . $http . patch ( url , data ) ; } public deleteAsync < T > ( url ) { return this . httpClient ? this . requestAsync ( { method : "DELETE" , url : url } ) : this . $http . delete ( url ) ; } public requestAsync < T > ( request ) { return this . $q < angular . IHttpPromiseCallbackArg < T > > ( ( resolve , reject ) => { this . httpClient . then ( ( client ) => client . requestAsync ( request ) ) . then ( ( response ) => resolve ( { data : response . data , status : response . statusCode , statusText : response . statusMessage , headers : undefined , config : undefined , xhrStatus : undefined } ) , ( err ) => reject ( err ) ) ; } ) ; } } ( function ( ) { const module = angular . module ( "httpService" , [ ] ) ; module . factory ( "httpClient" , [ "$q" , "$http" , ( $q , $http ) => new HttpClient ( $q , $http ) ] ) ; } ) ( ) ; }