aboutsummaryrefslogtreecommitdiff
path: root/build-logic/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'build-logic/src/main')
-rw-r--r--build-logic/src/main/kotlin/app/passwordstore/gradle/crowdin/BuildOnApiTask.kt39
-rw-r--r--build-logic/src/main/kotlin/app/passwordstore/gradle/crowdin/CrowdinPlugin.kt5
-rw-r--r--build-logic/src/main/kotlin/app/passwordstore/gradle/crowdin/api/ListProjects.kt9
3 files changed, 42 insertions, 11 deletions
diff --git a/build-logic/src/main/kotlin/app/passwordstore/gradle/crowdin/BuildOnApiTask.kt b/build-logic/src/main/kotlin/app/passwordstore/gradle/crowdin/BuildOnApiTask.kt
index 070ec2e9..8e7edaa8 100644
--- a/build-logic/src/main/kotlin/app/passwordstore/gradle/crowdin/BuildOnApiTask.kt
+++ b/build-logic/src/main/kotlin/app/passwordstore/gradle/crowdin/BuildOnApiTask.kt
@@ -1,8 +1,13 @@
package app.passwordstore.gradle.crowdin
+import app.passwordstore.gradle.crowdin.api.ListProjects
+import com.squareup.moshi.Moshi
+import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory
import java.util.concurrent.TimeUnit
+import okhttp3.MediaType.Companion.toMediaType
import okhttp3.OkHttpClient
import okhttp3.Request
+import okhttp3.RequestBody.Companion.toRequestBody
import org.gradle.api.DefaultTask
import org.gradle.api.provider.Property
import org.gradle.api.tasks.Input
@@ -26,15 +31,37 @@ abstract class BuildOnApiTask : DefaultTask() {
.readTimeout(5, TimeUnit.MINUTES)
.callTimeout(10, TimeUnit.MINUTES)
.build()
- val url =
- CROWDIN_BUILD_API_URL.format(crowdinIdentifier.get(), crowdinLogin.get(), crowdinKey.get())
- val request = Request.Builder().url(url).get().build()
- client.newCall(request).execute().close()
+ val moshi = Moshi.Builder().add(KotlinJsonAdapterFactory()).build()
+ val projectAdapter = moshi.adapter(ListProjects::class.java)
+ val projectRequest =
+ Request.Builder()
+ .url("$CROWDIN_BASE_URL/projects")
+ .header("Authorization", "Bearer ${crowdinKey.get()}")
+ .get()
+ .build()
+ client.newCall(projectRequest).execute().use { response ->
+ val projects = projectAdapter.fromJson(response.body!!.source())
+ if (projects != null) {
+ val identifier =
+ projects.projects
+ .first { data -> data.project.identifier == crowdinIdentifier.get() }
+ .project
+ .id
+ .toString()
+ val buildRequest =
+ Request.Builder()
+ .url(CROWDIN_BUILD_API_URL.format(identifier))
+ .header("Authorization", "Bearer ${crowdinKey.get()}")
+ .post("{}".toRequestBody("application/json".toMediaType()))
+ .build()
+ client.newCall(buildRequest).execute().close()
+ }
+ }
}
private companion object {
- private const val CROWDIN_BUILD_API_URL =
- "https://api.crowdin.com/api/project/%s/export?login=%s&account-key=%s"
+ private const val CROWDIN_BASE_URL = "https://api.crowdin.com/api/v2"
+ private const val CROWDIN_BUILD_API_URL = "$CROWDIN_BASE_URL/projects/%s/translations/builds"
}
}
diff --git a/build-logic/src/main/kotlin/app/passwordstore/gradle/crowdin/CrowdinPlugin.kt b/build-logic/src/main/kotlin/app/passwordstore/gradle/crowdin/CrowdinPlugin.kt
index 5442e085..83705a74 100644
--- a/build-logic/src/main/kotlin/app/passwordstore/gradle/crowdin/CrowdinPlugin.kt
+++ b/build-logic/src/main/kotlin/app/passwordstore/gradle/crowdin/CrowdinPlugin.kt
@@ -13,11 +13,6 @@ import org.gradle.api.tasks.Delete
import org.gradle.kotlin.dsl.create
import org.gradle.kotlin.dsl.register
-private const val EXCEPTION_MESSAGE =
- """Applying `crowdin-plugin` requires a projectName to be configured via the "crowdin" extension."""
-private const val CROWDIN_BUILD_API_URL =
- "https://api.crowdin.com/api/project/%s/export?login=%s&account-key=%s"
-
@Suppress("Unused")
class CrowdinDownloadPlugin : Plugin<Project> {
diff --git a/build-logic/src/main/kotlin/app/passwordstore/gradle/crowdin/api/ListProjects.kt b/build-logic/src/main/kotlin/app/passwordstore/gradle/crowdin/api/ListProjects.kt
new file mode 100644
index 00000000..e94205b6
--- /dev/null
+++ b/build-logic/src/main/kotlin/app/passwordstore/gradle/crowdin/api/ListProjects.kt
@@ -0,0 +1,9 @@
+package app.passwordstore.gradle.crowdin.api
+
+import com.squareup.moshi.Json
+
+data class ListProjects(@Json(name = "data") val projects: List<ProjectData>)
+
+data class ProjectData(@Json(name = "data") val project: Project)
+
+data class Project(val id: Long, val identifier: String)