Skip to content

Commit ad98ff3

Browse files
Merge branch 'master' of https://github.com/appwrite/sdk-generator into feat-dotnet-exceptions
2 parents 2b09979 + b101f1f commit ad98ff3

39 files changed

+645
-189
lines changed

.travis.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
2+
dist: xenial
3+
4+
arch:
5+
- amd64
6+
7+
os: linux
8+
19
language: php
210

311
php:
@@ -24,4 +32,4 @@ install:
2432
- composer install
2533

2634
script:
27-
- vendor/bin/phpunit
35+
- vendor/bin/phpunit

src/SDK/Language/CLI.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,12 @@ public function getFiles()
226226
'template' => '/cli/app/services/init.php.twig',
227227
'minify' => false,
228228
],
229+
[
230+
'scope' => 'default',
231+
'destination' => '.travis.yml',
232+
'template' => '/cli/.travis.yml.twig',
233+
'minify' => false,
234+
],
229235
];
230236
}
231237

src/SDK/Language/Deno.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ public function getFiles()
3636
'template' => '/deno/src/service.ts.twig',
3737
'minify' => false,
3838
],
39+
[
40+
'scope' => 'default',
41+
'destination' => '/src/exception.ts',
42+
'template' => '/deno/src/exception.ts.twig',
43+
'minify' => false,
44+
],
3945
[
4046
'scope' => 'service',
4147
'destination' => '/src/services/{{service.name | caseDash}}.ts',

src/SDK/Language/Node.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ public function getFiles()
6666
'template' => '/node/package.json.twig',
6767
'minify' => false,
6868
],
69+
[
70+
'scope' => 'default',
71+
'destination' => 'lib/exception.js',
72+
'template' => '/node/lib/exception.js.twig',
73+
'minify' => false,
74+
],
6975
[
7076
'scope' => 'method',
7177
'destination' => 'docs/examples/{{service.name | caseLower}}/{{method.name | caseDash}}.md',

src/SDK/SDK.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ class SDK
5454
'shareVia' => '',
5555
'shareTags' => '',
5656
'warning' => '',
57+
'gettingStarted' => '',
5758
'readme' => '',
5859
'changelog' => '',
5960
'examples' => '',
@@ -193,6 +194,8 @@ public function __construct(Language $language, Spec $spec)
193194
*/
194195
public function setDefaultHeaders($headers) {
195196
$this->defaultHeaders = $headers;
197+
198+
return $this;
196199
}
197200

198201
/**
@@ -393,6 +396,17 @@ public function setWarning($message)
393396
return $this;
394397
}
395398

399+
/**
400+
* @param $message string
401+
* @return $this
402+
*/
403+
public function setGettingStarted($message)
404+
{
405+
$this->setParam('gettingStarted', $message);
406+
407+
return $this;
408+
}
409+
396410
/**
397411
* @param $text string
398412
* @return $this

templates/cli/.travis.yml.twig

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
os: linux
2+
dist: xenial
3+
4+
language: shell
5+
6+
services:
7+
- docker
8+
9+
before_install:
10+
- curl -fsSL https://get.docker.com | sh
11+
- echo '{"experimental":"enabled"}' | sudo tee /etc/docker/daemon.json
12+
- mkdir -p $HOME/.docker
13+
- echo '{"experimental":"enabled"}' | sudo tee $HOME/.docker/config.json
14+
- sudo service docker start
15+
- >
16+
if [ ! -z "${DOCKERHUB_PULL_USERNAME:-}" ]; then
17+
echo "${DOCKERHUB_PULL_PASSWORD}" | docker login --username "${DOCKERHUB_PULL_USERNAME}" --password-stdin
18+
fi
19+
- docker --version
20+
- docker run --rm --privileged linuxkit/binfmt:v0.8
21+
- docker buildx create --use
22+
23+
script:
24+
- docker ps; docker buildx ls
25+
26+
deploy:
27+
- provider: script
28+
edge: true
29+
script: docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v7,linux/ppc64le,linux/s390x -t appwrite/cli:$TRAVIS_TAG ./ --push
30+
on:
31+
tags: true

templates/dart/README.md.twig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ You can install packages from the command line:
3131
pub get {{ language.params.packageName }}
3232
```
3333

34+
{% if sdk.gettingStarted %}
35+
36+
{{ sdk.gettingStarted|raw }}
37+
{% endif %}
38+
3439
## Contribution
3540

3641
This library is auto-generated by Appwrite custom [SDK Generator](https://github.com/appwrite/sdk-generator). To learn more about how you can help us improve this SDK, please check the [contribution guide](https://github.com/appwrite/sdk-generator/blob/master/CONTRIBUTING.md) before sending a pull-request.

templates/dart/lib/client.dart.twig

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ part of {{ language.params.packageName }};
33
class Client {
44
String endPoint;
55
String type = 'unknown';
6-
Map<String, String> headers;
7-
Map<String, String> config;
6+
Map<String, String>? headers;
7+
late Map<String, String> config;
88
bool selfSigned;
99
bool initialized = false;
1010
Dio http;
1111

12-
Client({this.endPoint = '{{spec.endpoint}}', this.selfSigned = false, Dio http}) : this.http = http ?? Dio() {
12+
Client({this.endPoint = '{{spec.endpoint}}', this.selfSigned = false, Dio? http}) : this.http = http ?? Dio() {
1313

1414
this.headers = {
1515
'content-type': 'application/json',
@@ -48,19 +48,19 @@ class Client {
4848
}
4949

5050
Client addHeader(String key, String value) {
51-
headers[key] = value;
51+
headers![key] = value;
5252

5353
return this;
5454
}
5555

5656
Future init() async {
5757
if(!initialized) {
5858
this.http.options.baseUrl = this.endPoint;
59-
this.http.options.validateStatus = (status) => status < 400;
59+
this.http.options.validateStatus = (status) => status! < 400;
6060
}
6161
}
6262

63-
Future<Response> call(HttpMethod method, {String path = '', Map<String, String> headers = const {}, Map<String, dynamic> params = const {}, ResponseType responseType}) async {
63+
Future<Response> call(HttpMethod method, {String path = '', Map<String, String> headers = const {}, Map<String, dynamic> params = const {}, ResponseType? responseType}) async {
6464
if(selfSigned) {
6565
// Allow self signed requests
6666
(http.httpClientAdapter as DefaultHttpClientAdapter).onHttpClientCreate = (HttpClient client) {
@@ -73,14 +73,15 @@ class Client {
7373

7474
// Origin is hardcoded for testing
7575
Options options = Options(
76-
headers: {...this.headers, ...headers},
76+
headers: {...this.headers!, ...headers},
7777
method: method.name(),
78-
responseType: responseType
78+
responseType: responseType,
79+
listFormat: ListFormat.multiCompatible,
7980
);
8081
try {
8182

8283
if(headers['content-type'] == 'multipart/form-data') {
83-
return await http.request(path, data: FormData.fromMap(params), options: options);
84+
return await http.request(path, data: FormData.fromMap(params,ListFormat.multiCompatible), options: options);
8485
}
8586

8687
if (method == HttpMethod.get) {
@@ -96,9 +97,17 @@ class Client {
9697
if(e.response == null) {
9798
throw {{spec.title | caseUcfirst}}Exception(e.message);
9899
}
99-
throw {{spec.title | caseUcfirst}}Exception(e.response.data['message'],e.response.data['code'], e.response.data);
100+
if(responseType == ResponseType.bytes) {
101+
if(e.response!.headers['content-type']?.contains('application/json') ?? false) {
102+
final res = json.decode(utf8.decode(e.response!.data));
103+
throw {{spec.title | caseUcfirst}}Exception(res['message'],res['code'], res);
104+
} else {
105+
throw {{spec.title | caseUcfirst}}Exception(e.message);
106+
}
107+
}
108+
throw {{spec.title | caseUcfirst}}Exception(e.response?.data['message'],e.response?.data['code'], e.response?.data);
100109
} catch(e) {
101-
throw {{spec.title | caseUcfirst}}Exception(e.message);
110+
throw {{spec.title | caseUcfirst}}Exception(e.toString());
102111
}
103112
}
104113
}

templates/dart/lib/exception.dart.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
part of {{ language.params.packageName }};
22

33
class {{spec.title | caseUcfirst}}Exception implements Exception {
4-
final String message;
5-
final int code;
4+
final String? message;
5+
final int? code;
66
final dynamic response;
77

88
{{spec.title | caseUcfirst}}Exception([this.message = "", this.code, this.response]);

templates/dart/lib/package.dart.twig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
library {{ language.params.packageName }};
22

33
import 'dart:io';
4+
import 'dart:convert';
45
import 'package:dio/dio.dart';
56
import 'package:meta/meta.dart';
67
import 'package:dio/adapter.dart';

0 commit comments

Comments
 (0)