@@ -3,18 +3,20 @@ import * as httpsModule from 'https';
3
3
import { outputConsole , currentWorkspaceFolder } from '../utils' ;
4
4
import { config } from '../extension' ;
5
5
6
+ const DEFAULT_API_VERSION : number = 3 ;
7
+
6
8
export class AtelierAPI {
7
9
private cookies : string [ ] = [ ] ;
8
10
private _config : any ;
9
11
private _namespace : string ;
10
- private _apiVersion : string ;
12
+ private static _apiVersion : number ;
11
13
12
14
private get ns ( ) : string {
13
15
return this . _namespace || this . _config . ns ;
14
16
}
15
17
16
- private get apiVersion ( ) : string {
17
- return this . _apiVersion || this . _config . apiVersion ;
18
+ private get apiVersion ( ) : number {
19
+ return AtelierAPI . _apiVersion || DEFAULT_API_VERSION ;
18
20
}
19
21
20
22
constructor ( ) {
@@ -25,8 +27,8 @@ export class AtelierAPI {
25
27
this . _namespace = namespace ;
26
28
}
27
29
28
- setApiVersion ( apiVersion : string ) {
29
- this . _apiVersion = apiVersion ;
30
+ setApiVersion ( apiVersion : number ) {
31
+ AtelierAPI . _apiVersion = apiVersion ;
30
32
}
31
33
32
34
updateCookies ( cookies : string [ ] ) {
@@ -143,7 +145,7 @@ export class AtelierAPI {
143
145
serverInfo ( ) : Promise < any > {
144
146
return this . request ( 'GET' ) ;
145
147
}
146
-
148
+ // api v1+
147
149
getDocNames ( {
148
150
generated = false ,
149
151
category = '*' ,
@@ -155,63 +157,69 @@ export class AtelierAPI {
155
157
type ?: string ;
156
158
filter ?: string ;
157
159
} ) : Promise < any > {
158
- return this . request ( 'GET' , `${ this . apiVersion } /${ this . ns } /docnames/${ category } /${ type } ` , null , {
160
+ return this . request ( 'GET' , `v ${ this . apiVersion } /${ this . ns } /docnames/${ category } /${ type } ` , null , {
159
161
filter,
160
162
generated
161
163
} ) ;
162
164
}
163
-
165
+ // api v1+
164
166
getDoc ( name : string , format ?: string ) : Promise < any > {
165
167
let params = { } ;
166
168
if ( format ) {
167
169
params = {
168
170
format
169
171
} ;
170
172
}
171
- return this . request ( 'GET' , `${ this . apiVersion } /${ this . ns } /doc/${ name } ` , params ) ;
173
+ return this . request ( 'GET' , `v ${ this . apiVersion } /${ this . ns } /doc/${ name } ` , params ) ;
172
174
}
173
-
175
+ // v1+
174
176
putDoc ( name : string , data : { enc : boolean ; content : string [ ] } , ignoreConflict ?: boolean ) : Promise < any > {
175
177
let params = { ignoreConflict } ;
176
- return this . request ( 'PUT' , `${ this . apiVersion } /${ this . ns } /doc/${ name } ` , data , params ) ;
178
+ return this . request ( 'PUT' , `v ${ this . apiVersion } /${ this . ns } /doc/${ name } ` , data , params ) ;
177
179
}
178
-
180
+ // v1+
179
181
actionIndex ( docs : string [ ] ) : Promise < any > {
180
- return this . request ( 'POST' , `${ this . apiVersion } /${ this . ns } /action/index` , docs ) ;
182
+ return this . request ( 'POST' , `v ${ this . apiVersion } /${ this . ns } /action/index` , docs ) ;
181
183
}
182
-
184
+ // v2+
183
185
actionSearch ( params : { query : string ; files ?: string ; sys ?: boolean ; gen ?: boolean ; max ?: number } ) : Promise < any > {
184
- return this . request ( 'GET' , `${ this . apiVersion } /${ this . ns } /action/search` , null , params ) ;
186
+ return this . apiVersion >= 2 ?
187
+ this . request ( 'GET' , `v${ this . apiVersion } /${ this . ns } /action/search` , null , params ) :
188
+ Promise . reject ( `Method 'search' not supported by API version ${ this . apiVersion } ` ) ;
185
189
}
186
-
190
+ // v1+
187
191
actionQuery ( query : string , parameters : string [ ] ) : Promise < any > {
188
- return this . request ( 'POST' , `${ this . apiVersion } /${ this . ns } /action/query` , {
192
+ return this . request ( 'POST' , `v ${ this . apiVersion } /${ this . ns } /action/query` , {
189
193
query,
190
194
parameters
191
195
} ) ;
192
196
}
193
-
197
+ // v1+
194
198
actionCompile ( docs : string [ ] , flags ?: string , source = false ) : Promise < any > {
195
- return this . request ( 'POST' , `${ this . apiVersion } /${ this . ns } /action/compile` , docs , { flags, source } ) ;
199
+ return this . request ( 'POST' , `v ${ this . apiVersion } /${ this . ns } /action/compile` , docs , { flags, source } ) ;
196
200
}
197
201
198
202
cvtXmlUdl ( source : string ) : Promise < any > {
199
- return this . request ( 'POST' , `${ this . apiVersion } /${ this . ns } /cvt/xml/doc` , source , { } , { 'Content-Type' : 'application/xml' } ) ;
203
+ return this . request ( 'POST' , `v ${ this . apiVersion } /${ this . ns } /cvt/xml/doc` , source , { } , { 'Content-Type' : 'application/xml' } ) ;
200
204
}
201
-
205
+ // v2+
202
206
getmacrodefinition ( docname : string , macroname : string , includes : string [ ] ) {
203
- return this . request ( 'POST' , `${ this . apiVersion } /${ this . ns } /action/getmacrodefinition` , {
204
- docname,
205
- macroname,
206
- includes
207
- } ) ;
208
- }
209
-
207
+ return this . apiVersion >= 2 ?
208
+ this . request ( 'POST' , `v${ this . apiVersion } /${ this . ns } /action/getmacrodefinition` , {
209
+ docname,
210
+ macroname,
211
+ includes
212
+ } ) :
213
+ Promise . reject ( `Method 'getmacrodefinition' not supported by API version ${ this . apiVersion } ` ) ;
214
+ }
215
+ // v2+
210
216
getmacrolocation ( docname : string , macroname : string , includes : string [ ] ) {
211
- return this . request ( 'POST' , `${ this . apiVersion } /${ this . ns } /action/getmacrolocation` , {
212
- docname,
213
- macroname,
214
- includes
215
- } ) ;
217
+ return this . apiVersion >= 2 ?
218
+ this . request ( 'POST' , `v${ this . apiVersion } /${ this . ns } /action/getmacrolocation` , {
219
+ docname,
220
+ macroname,
221
+ includes
222
+ } ) :
223
+ Promise . reject ( `Method 'getmacrolocation' not supported by API version ${ this . apiVersion } ` ) ;
216
224
}
217
225
}
0 commit comments