Skip to content

Commit 127c11b

Browse files
authored
Merge pull request #224 from appwrite/update-kotlin-docs
feat: fix kotlin documentation
2 parents 9dd1321 + d46b6ce commit 127c11b

File tree

8 files changed

+42
-16
lines changed

8 files changed

+42
-16
lines changed

templates/android/README.md.twig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# {{ spec.title }} {{sdk.name}} SDK
22

3+
![Maven Central](https://img.shields.io/maven-central/v/{{ sdk.namespace | caseDot }}/{{ sdk.gitRepoName | caseDash }}.svg?color=green&style=flat-square)
34
![License](https://img.shields.io/github/license/{{ sdk.gitUserName|url_encode }}/{{ sdk.gitRepoName|url_encode }}.svg?style=flat-square)
45
![Version](https://img.shields.io/badge/api%20version-{{ spec.version|url_encode }}-blue.svg?style=flat-square)
56
[![Build Status](https://img.shields.io/travis/com/appwrite/sdk-generator?style=flat-square)](https://travis-ci.com/appwrite/sdk-generator)

templates/android/example/src/main/java/io/appwrite/android/ui/accounts/AccountsFragment.kt.twig

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,22 @@ import android.widget.Toast
88
import androidx.activity.ComponentActivity
99
import androidx.databinding.DataBindingUtil
1010
import androidx.fragment.app.Fragment
11+
import androidx.fragment.app.viewModels
1112
import androidx.lifecycle.Observer
12-
import androidx.lifecycle.ViewModelProvider
1313
import {{ sdk.namespace | caseDot }}.android.R
1414
import {{ sdk.namespace | caseDot }}.android.databinding.FragmentAccountBinding
1515

1616

1717
class AccountsFragment : Fragment() {
1818

1919
private lateinit var binding: FragmentAccountBinding
20-
private lateinit var viewModel: AccountsViewModel
20+
private val viewModel: AccountsViewModel by viewModels()
2121

2222
override fun onCreateView(
2323
inflater: LayoutInflater ,
2424
container: ViewGroup? ,
2525
savedInstanceState: Bundle?
26-
): View? {
27-
viewModel = ViewModelProvider(this).get(AccountsViewModel::class.java)
26+
): View {
2827
binding = DataBindingUtil.inflate(
2928
inflater,
3029
R.layout.fragment_account,

templates/android/library/build.gradle.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ android {
2828
targetSdkVersion(30)
2929
versionCode = 1
3030
versionName = "1.0"
31-
31+
buildConfigField "String", "SDK_VERSION", "\"${PUBLISH_VERSION}\""
3232
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
3333
consumerProguardFiles("consumer-rules.pro")
3434
}
3535

3636
buildTypes {
37-
named("release") {
37+
release {
3838
minifyEnabled false
3939
proguardFiles(
4040
getDefaultProguardFile("proguard-android-optimize.txt"),

templates/android/library/src/main/java/io/appwrite/Client.kt.twig

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package {{ sdk.namespace | caseDot }}
33
import android.content.Context
44
import android.content.pm.PackageManager
55
import com.google.gson.Gson
6+
import io.appwrite.appwrite.BuildConfig
67
import {{ sdk.namespace | caseDot }}.exceptions.{{ spec.title | caseUcfirst }}Exception
78
import {{ sdk.namespace | caseDot }}.extensions.JsonExtensions.fromJson
89
import {{ sdk.namespace | caseDot }}.models.Error
@@ -69,7 +70,7 @@ class Client @JvmOverloads constructor(
6970
"content-type" to "application/json",
7071
"origin" to "appwrite-android://${context.packageName}",
7172
"user-agent" to "${context.packageName}/${appVersion}, ${System.getProperty("http.agent")}",
72-
"x-sdk-version" to "{{spec.title | caseDash}}:{{ language.name | caseLower }}:{{ sdk.version }}"{% if spec.global.defaultHeaders | length > 0 %},{% endif %}
73+
"x-sdk-version" to "{{spec.title | caseDash}}:{{ language.name | caseLower }}:${BuildConfig.SDK_VERSION}"{% if spec.global.defaultHeaders | length > 0 %},{% endif %}
7374

7475
{% for key,header in spec.global.defaultHeaders %}
7576
"{{ key | caseLower }}" to "{{ header }}"{% if not loop.last %},{% endif %}
@@ -207,7 +208,13 @@ class Client @JvmOverloads constructor(
207208
return@forEach
208209
}
209210
is List<*> -> {
210-
httpBuilder.addQueryParameter(it.key + "[]", it.value.toString())
211+
val list = it.value as List<*>
212+
for (index in list.indices) {
213+
httpBuilder.addQueryParameter(
214+
"${it.key}[]",
215+
list[index].toString()
216+
)
217+
}
211218
}
212219
else -> {
213220
httpBuilder.addQueryParameter(it.key, it.value.toString())

templates/kotlin/README.md.twig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# {{ spec.title }} {{sdk.name}} SDK
22

3+
![Maven Central](https://img.shields.io/maven-central/v/{{ sdk.namespace | caseDot }}/{{ sdk.gitRepoName | caseDash }}.svg?color=green&style=flat-square)
34
![License](https://img.shields.io/github/license/{{ sdk.gitUserName|url_encode }}/{{ sdk.gitRepoName|url_encode }}.svg?style=flat-square)
45
![Version](https://img.shields.io/badge/api%20version-{{ spec.version|url_encode }}-blue.svg?style=flat-square)
56
{% if sdk.twitterHandle %}

templates/kotlin/docs/example.md.twig

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,26 @@
11
import {{ sdk.namespace | caseDot }}.Client
22
import {{ sdk.namespace | caseDot }}.services.{{ service.name | caseUcfirst }}
33

4-
val client = Client(context)
4+
suspend fun main() {
5+
val client = Client(context)
56
{% if method.security|length > 0 %}
6-
.setEndpoint("https://[HOSTNAME_OR_IP]/v1") // Your API Endpoint
7+
.setEndpoint("https://[HOSTNAME_OR_IP]/v1") // Your API Endpoint
78
{% for node in method.security %}
89
{% for key,header in node|keys %}
9-
.set{{header | caseUcfirst}}("{{node[header]['x-appwrite']['demo']}}") // {{node[header].description}}
10+
.set{{header | caseUcfirst}}("{{node[header]['x-appwrite']['demo']}}") // {{node[header].description}}
1011
{% endfor %}{% endfor %}{% endif %}
1112

12-
val {{ service.name | caseCamel }}Service = {{ service.name | caseUcfirst }}(client)
13-
val response = {{ service.name | caseCamel }}Service.{{ method.name | caseCamel }}({% for parameter in method.parameters.all %}{% if parameter.required %}{% if not loop.first %}, {% endif %}{{ parameter | paramExample }}{% endif %}{% endfor %})
14-
val json = response.body?.string()
13+
val {{ service.name | caseCamel }} = {{ service.name | caseUcfirst }}(client)
14+
val response = {{ service.name | caseCamel }}.{{ method.name | caseCamel }}({% if method.parameters.all | length == 0 %}){% endif %}
15+
16+
{% for parameter in method.parameters.all %}
17+
{% if parameter.required %}
18+
{{parameter.name}} = {{ parameter | paramExample }}{% if not loop.last %},{% endif %}
19+
20+
{% endif %}
21+
{% if loop.last %}
22+
)
23+
{% endif %}
24+
{% endfor %}
25+
val json = response.body?.string()
26+
}

templates/kotlin/scripts/publish.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ publishing {
1313
repositories {
1414
maven {
1515
name = "sonatype"
16-
def releaseUrl = "https://s01.oss.sonatype.org/service/local/"
16+
def releaseUrl = "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/"
1717
def snapshotUrl = "https://s01.oss.sonatype.org/content/repositories/snapshots/"
1818
url = version.endsWith('-SNAPSHOT') ? snapshotUrl : releaseUrl
1919
credentials {

templates/kotlin/src/main/kotlin/io/appwrite/Client.kt.twig

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,13 @@ class Client @JvmOverloads constructor(
184184
return@forEach
185185
}
186186
is List<*> -> {
187-
httpBuilder.addQueryParameter(it.key + "[]", it.value.toString())
187+
val list = it.value as List<*>
188+
for (index in list.indices) {
189+
httpBuilder.addQueryParameter(
190+
"${it.key}[]",
191+
list[index].toString()
192+
)
193+
}
188194
}
189195
else -> {
190196
httpBuilder.addQueryParameter(it.key, it.value.toString())

0 commit comments

Comments
 (0)