Skip to content

Commit 966d464

Browse files
author
Jake Barnby
committed
Add separated java + kotlin docs for android and kotlin
1 parent 998034a commit 966d464

File tree

6 files changed

+167
-6
lines changed

6 files changed

+167
-6
lines changed

src/SDK/Language/Android.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,14 @@ public function getFiles()
2828
],
2929
[
3030
'scope' => 'method',
31-
'destination' => 'docs/examples/{{service.name | caseLower}}/{{method.name | caseDash}}.md',
32-
'template' => '/android/docs/example.md.twig',
31+
'destination' => 'docs/examples/kotlin/{{service.name | caseLower}}/{{method.name | caseDash}}.md',
32+
'template' => '/android/docs/kotlin/example.md.twig',
33+
'minify' => false,
34+
],
35+
[
36+
'scope' => 'method',
37+
'destination' => 'docs/examples/java/{{service.name | caseLower}}/{{method.name | caseDash}}.md',
38+
'template' => '/android/docs/java/example.md.twig',
3339
'minify' => false,
3440
],
3541
[

src/SDK/Language/Kotlin.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,14 @@ public function getFiles()
248248
],
249249
[
250250
'scope' => 'method',
251-
'destination' => 'docs/examples/{{service.name | caseLower}}/{{method.name | caseDash}}.md',
252-
'template' => '/kotlin/docs/example.md.twig',
251+
'destination' => 'docs/examples/kotlin/{{service.name | caseLower}}/{{method.name | caseDash}}.md',
252+
'template' => '/kotlin/docs/kotlin/example.md.twig',
253+
'minify' => false,
254+
],
255+
[
256+
'scope' => 'method',
257+
'destination' => 'docs/examples/java/{{service.name | caseLower}}/{{method.name | caseDash}}.md',
258+
'template' => '/kotlin/docs/java/example.md.twig',
253259
'minify' => false,
254260
],
255261
[
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import androidx.appcompat.app.AppCompatActivity
2+
import android.os.Bundle
3+
import kotlinx.coroutines.GlobalScope
4+
import kotlinx.coroutines.launch
5+
import {{ sdk.namespace | caseDot }}.Client
6+
import {{ sdk.namespace | caseDot }}.services.{{ service.name | caseUcfirst }}
7+
8+
public class MainActivity extends AppCompatActivity {
9+
10+
@Override
11+
protected void onCreate(Bundle savedInstanceState) {
12+
super.onCreate(savedInstanceState);
13+
setContentView(R.layout.activity_main);
14+
15+
Client client = new Client(getApplicationContext())
16+
{% if method.security|length > 0 %}
17+
.setEndpoint("https://[HOSTNAME_OR_IP]/v1") // Your API Endpoint
18+
{% for node in method.security %}
19+
{% for key,header in node|keys %}
20+
.set{{header | caseUcfirst}}("{{node[header]['x-appwrite']['demo']}}"){% if loop.last %};{% endif %} // {{node[header].description}}
21+
{% endfor %}
22+
{% endfor %}
23+
{% endif %}
24+
25+
{{ service.name | caseUcfirst }} {{ service.name | caseCamel }} = new {{ service.name | caseUcfirst }}(client);
26+
27+
{{ service.name | caseCamel }}.{{ method.name | caseCamel }}({% if method.parameters.all | length == 0 %}new Continuation<Response>() {
28+
@NotNull
29+
@Override
30+
public CoroutineContext getContext() {
31+
return EmptyCoroutineContext.INSTANCE;
32+
}
33+
34+
@Override
35+
public void resumeWith(@NotNull Object o) {
36+
String json = "";
37+
try {
38+
if (o instanceof Result.Failure) {
39+
Result.Failure failure = (Result.Failure) o;
40+
throw failure.exception;
41+
} else {
42+
Response response = (Response) o;
43+
}
44+
} catch (Throwable th) {
45+
Log.e("ERROR", th.toString());
46+
}
47+
}
48+
});{% endif %}
49+
50+
{% for parameter in method.parameters.all %}
51+
{% if parameter.required %}
52+
{{ parameter | paramExample }}{% if not loop.last %}, {% endif %}
53+
54+
{% endif %}
55+
{% if loop.last %}
56+
new Continuation<Response>() {
57+
@NotNull
58+
@Override
59+
public CoroutineContext getContext() {
60+
return EmptyCoroutineContext.INSTANCE;
61+
}
62+
63+
@Override
64+
public void resumeWith(@NotNull Object o) {
65+
String json = "";
66+
try {
67+
if (o instanceof Result.Failure) {
68+
Result.Failure failure = (Result.Failure) o;
69+
throw failure.exception;
70+
} else {
71+
Response response = (Response) o;
72+
}
73+
} catch (Throwable th) {
74+
Log.e("ERROR", th.toString());
75+
}
76+
}
77+
}
78+
);
79+
{% endif %}
80+
{% endfor %}
81+
}
82+
}

templates/android/docs/example.md.twig renamed to templates/android/docs/kotlin/example.md.twig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ class MainActivity : AppCompatActivity() {
3434
)
3535
{% endif %}
3636
{% endfor %}
37-
val json = response.body?.string()
3837
}
3938
}
4039
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import {{ sdk.namespace | caseDot }}.Client
2+
import {{ sdk.namespace | caseDot }}.services.{{ service.name | caseUcfirst }}
3+
4+
public void main() {
5+
Client client = Client(context)
6+
{% if method.security|length > 0 %}
7+
.setEndpoint("https://[HOSTNAME_OR_IP]/v1") // Your API Endpoint
8+
{% for node in method.security %}
9+
{% for key,header in node|keys %}
10+
.set{{header | caseUcfirst}}("{{node[header]['x-appwrite']['demo']}}"){% if loop.last %};{% endif %} // {{node[header].description}}
11+
{% endfor %}{% endfor %}{% endif %}
12+
13+
{{ service.name | caseUcfirst }} {{ service.name | caseCamel }} = new {{ service.name | caseUcfirst }}(client);
14+
{{ service.name | caseCamel }}.{{ method.name | caseCamel }}({% if method.parameters.all | length == 0 %}new Continuation<Response>() {
15+
@NotNull
16+
@Override
17+
public CoroutineContext getContext() {
18+
return EmptyCoroutineContext.INSTANCE;
19+
}
20+
21+
@Override
22+
public void resumeWith(@NotNull Object o) {
23+
String json = "";
24+
try {
25+
if (o instanceof Result.Failure) {
26+
Result.Failure failure = (Result.Failure) o;
27+
throw failure.exception;
28+
} else {
29+
Response response = (Response) o;
30+
}
31+
} catch (Throwable th) {
32+
Log.e("ERROR", th.toString());
33+
}
34+
}
35+
});{% endif %}
36+
37+
{% for parameter in method.parameters.all %}
38+
{% if parameter.required %}
39+
{{parameter.name}} = {{ parameter | paramExample }}{% if not loop.last %},{% endif %}
40+
41+
{% endif %}
42+
{% if loop.last %}
43+
new Continuation<Response>() {
44+
@NotNull
45+
@Override
46+
public CoroutineContext getContext() {
47+
return EmptyCoroutineContext.INSTANCE;
48+
}
49+
50+
@Override
51+
public void resumeWith(@NotNull Object o) {
52+
String json = "";
53+
try {
54+
if (o instanceof Result.Failure) {
55+
Result.Failure failure = (Result.Failure) o;
56+
throw failure.exception;
57+
} else {
58+
Response response = (Response) o;
59+
}
60+
} catch (Throwable th) {
61+
Log.e("ERROR", th.toString());
62+
}
63+
}
64+
}
65+
);
66+
{% endif %}
67+
{% endfor %}
68+
}

templates/kotlin/docs/example.md.twig renamed to templates/kotlin/docs/kotlin/example.md.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ suspend fun main() {
1010
.set{{header | caseUcfirst}}("{{node[header]['x-appwrite']['demo']}}") // {{node[header].description}}
1111
{% endfor %}{% endfor %}{% endif %}
1212

13+
1314
val {{ service.name | caseCamel }} = {{ service.name | caseUcfirst }}(client)
1415
val response = {{ service.name | caseCamel }}.{{ method.name | caseCamel }}({% if method.parameters.all | length == 0 %}){% endif %}
1516

@@ -22,5 +23,4 @@ suspend fun main() {
2223
)
2324
{% endif %}
2425
{% endfor %}
25-
val json = response.body?.string()
2626
}

0 commit comments

Comments
 (0)