import axios from 'axios' ; interface Api { apiName : string ; apiSubdomain : string ; apiDocumentationUrl : string ; apiIsPrivate : boolean ; apiIsPublic : boolean ; apiIsTeam : boolean ; apiIsPersonal : boolean ; } interface ApiResult { apis : Array < Api > ; } export class ApiaryClient { constructor ( token ) { axios . defaults . headers . common . Authorization = `Bearer ${ token }` ; axios . defaults . headers . common . Authentication = `Token ${ token }` ; axios . defaults . baseURL = "https://api.apiary.io/" ; } public getApiList ( ) { return axios . get ( 'me/apis' ) . then ( this . getDataObject , this . formatError ) ; } public getApiCode ( apiName ) { return axios . get ( `blueprint/get/${ apiName }` ) . then ( this . getDataObject , this . formatError ) ; } public publishApi ( apiName , code , commitMessage = "Saving API Description Document from VSCode" ) { return axios . post ( `blueprint/publish/${ apiName }` , { code , messageToSave : commitMessage , shouldCommit : true , } ) . then ( undefined , this . formatError ) ; } private getDataObject = res => res . data ; private formatError = err => { if ( err . response !== undefined ) { if ( err . response . data . parserError !== undefined ) { throw new Error ( err . response . data . parserError ) ; } else if ( err . response . data . message !== undefined ) { throw new Error ( err . response . data . message ) ; } } throw err ; } ; }