1- part of { {pubName } }.api ;
1+ import 'dart:convert' show json ;
22
3- class QueryParam {
4- String name;
5- String value;
3+ import 'package:http/http.dart' as Http show Client, MultipartRequest, Response;
64
7- QueryParam(this.name, this.value);
8- }
5+ import '../aspose_barcode_cloud.dart';
6+ import 'api_helper.dart';
7+ import 'auth/authentication.dart';
8+ import 'auth/oauth.dart';
9+
10+ const String SDK_VERSION = "{ {pubVersion} }";
911
1012class ApiClient {
1113
12- String basePath;
13- final client = new {{#browserClient} }Browser{ {/browserClient} }Client();
14+ late final String basePath;
15+ final httpClient = Http.Client();
16+
17+ static const String API_SDK_HEADER = " x-aspose-client" ;
18+ static const String SDK_NAME = " dart sdk" ;
19+ static const String API_CLIENT_VERSION_HEADER = " x-aspose-client-version" ;
20+
21+ Map< String, String> _defaultHeaderMap = {
22+ API_SDK_HEADER: SDK_NAME,
23+ API_CLIENT_VERSION_HEADER: SDK_VERSION,
24+ } ;
1425
15- Map<String , String > _defaultHeaderMap = { } ;
1626 late Authentication _authentication;
1727
18- final _regList = new RegExp(r'^List<(.*)>$');
19- final _regMap = new RegExp(r'^Map<String ,(.*) >$');
20-
21- ApiClient(
22- { String? clientId,
23- String? clientSecret,
24- String? accessToken,
25- tokenUrl = " https://api.aspose.cloud/connect/token" ,
26- this.basePath = " https://api.aspose.cloud/v3.0" } ) {
27- _authentication = new OAuth(
28- clientId: clientId,
29- clientSecret: clientSecret,
30- accessToken: accessToken,
31- tokenUrl: tokenUrl);
28+ final _regList = RegExp(r'^List<(.*)>$');
29+ final _regMap = RegExp(r'^Map<String ,(.*) >$');
30+
31+ ApiClient(Configuration config) {
32+ this.basePath = config.basePath;
33+ _authentication = OAuth(
34+ clientId: config.clientId,
35+ clientSecret: config.clientSecret,
36+ accessToken: config.accessToken,
37+ tokenUrl: config.tokenUrl);
3238 }
3339
3440 void addDefaultHeader(String key, String value) {
@@ -50,10 +56,10 @@ class ApiClient {
5056 { {#model} }
5157 case '{ {classname} }':
5258 { {#isEnum} }
53- return new { {classname} }.fromJson(value);
59+ return { {classname} }.fromJson(value);
5460 { {/isEnum} }
5561 { {^isEnum} }
56- return new { {classname} }.fromJson(value);
62+ return { {classname} }.fromJson(value);
5763 { {/isEnum} }
5864 { {/model} }
5965 { {/models} }
@@ -67,15 +73,15 @@ class ApiClient {
6773 } else if (value is Map &&
6874 (match = _regMap.firstMatch(targetType)) != null) {
6975 final newTargetType = match! [1];
70- return new Map.fromIterables(value.keys,
76+ return Map.fromIterables(value.keys,
7177 value.values.map((v) => _deserialize(v, newTargetType! )));
7278 }
7379 }
7480 }
7581 } on Exception catch (e, stack) {
76- throw new ApiException.withInner(0, ' Exception during deserialization.' , e, stack);
82+ throw ApiException.withInner(0, ' Exception during deserialization.' , e, stack);
7783 }
78- throw new ApiException(0, 'Could not find a suitable class for deserialization');
84+ throw ApiException(0, 'Could not find a suitable class for deserialization');
7985 }
8086
8187 dynamic deserialize(String jsonVal, String targetType) {
@@ -102,7 +108,7 @@ class ApiClient {
102108
103109 // We don't use a Map<String , String > for queryParams.
104110 // If collectionFormat is 'multi' a key might appear multiple times.
105- Future<Response > invokeAPI(String path,
111+ Future<Http . Response > invokeAPI(String path,
106112 String method,
107113 List<QueryParam > queryParams,
108114 Object? body,
@@ -123,27 +129,27 @@ class ApiClient {
123129 headerParams.addAll(_defaultHeaderMap);
124130 headerParams[' Content-Type' ] = contentType;
125131
126- if (body is MultipartRequest) {
127- final request = new MultipartRequest(method, Uri.parse(url));
132+ if (body is Http. MultipartRequest) {
133+ final request = Http. MultipartRequest(method, Uri.parse(url));
128134 request.fields.addAll(body.fields);
129135 request.files.addAll(body.files);
130136 request.headers.addAll(body.headers);
131137 request.headers.addAll(headerParams);
132- final response = await client .send(request);
133- return Response.fromStream(response);
138+ final response = await httpClient .send(request);
139+ return Http. Response.fromStream(response);
134140 } else {
135141 final msgBody = contentType == " application/x-www-form-urlencoded" ? formParams : serialize(body);
136142 switch (method) {
137143 case " POST" :
138- return client .post(Uri.parse(url), headers: headerParams, body: msgBody);
144+ return httpClient .post(Uri.parse(url), headers: headerParams, body: msgBody);
139145 case " PUT" :
140- return client .put(Uri.parse(url), headers: headerParams, body: msgBody);
146+ return httpClient .put(Uri.parse(url), headers: headerParams, body: msgBody);
141147 case " DELETE" :
142- return client .delete(Uri.parse(url), headers: headerParams);
148+ return httpClient .delete(Uri.parse(url), headers: headerParams);
143149 case " PATCH" :
144- return client .patch(Uri.parse(url), headers: headerParams, body: msgBody);
150+ return httpClient .patch(Uri.parse(url), headers: headerParams, body: msgBody);
145151 default :
146- return client .get(Uri.parse(url), headers: headerParams);
152+ return httpClient .get(Uri.parse(url), headers: headerParams);
147153 }
148154 }
149155 }
0 commit comments