diff --git a/app/src/main/java/com/h/pixeldroid/api/PixelfedAPI.kt b/app/src/main/java/com/h/pixeldroid/api/PixelfedAPI.kt index a446a49f..59fe80fd 100644 --- a/app/src/main/java/com/h/pixeldroid/api/PixelfedAPI.kt +++ b/app/src/main/java/com/h/pixeldroid/api/PixelfedAPI.kt @@ -8,9 +8,11 @@ import retrofit2.Response import retrofit2.Retrofit import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory import retrofit2.converter.gson.GsonConverterFactory +import retrofit2.http.FormUrlEncoded import retrofit2.http.GET +import retrofit2.http.POST import retrofit2.http.Query - +import retrofit2.http.Field /* Implements the Pixelfed API https://docs.pixelfed.org/technical-documentation/api-v1.html @@ -20,13 +22,22 @@ import retrofit2.http.Query interface PixelfedAPI { + @FormUrlEncoded + @POST("/api/v1/apps") + fun registerApplication( + @Field("client_name") client_name: String, + @Field("redirect_uris") redirect_uris: String, + @Field("scopes") scopes: String? = null, + @Field("website") website: String? = null + ): Call + @GET("/api/v1/timelines/public") fun timelinePublic( - @Query("local") local: Boolean?, - @Query("max_id") max_id: String?, - @Query("since_id") since_id: String?, - @Query("min_id") min_id: String?, - @Query("limit") limit: Int? + @Query("local") local: Boolean? = null, + @Query("max_id") max_id: String? = null, + @Query("since_id") since_id: String? = null, + @Query("min_id") min_id: String? = null, + @Query("limit") limit: Int? = null ): Call> companion object { diff --git a/app/src/main/java/com/h/pixeldroid/objects/Application.kt b/app/src/main/java/com/h/pixeldroid/objects/Application.kt index d58448b9..98b8ad8d 100644 --- a/app/src/main/java/com/h/pixeldroid/objects/Application.kt +++ b/app/src/main/java/com/h/pixeldroid/objects/Application.kt @@ -5,5 +5,8 @@ data class Application ( val name: String, //Optional attributes val website: String? = null, - val vapid_key: String? = null + val vapid_key: String? = null, + //Client Attributes + val client_id: String? = null, + val client_secret: String? = null ) \ No newline at end of file diff --git a/app/src/test/java/com/h/pixeldroid/APIUnitTest.kt b/app/src/test/java/com/h/pixeldroid/APIUnitTest.kt index a96b60df..c6eeb772 100644 --- a/app/src/test/java/com/h/pixeldroid/APIUnitTest.kt +++ b/app/src/test/java/com/h/pixeldroid/APIUnitTest.kt @@ -132,4 +132,24 @@ class APIUnitTest { f.emojis== emptyList() && f.reblogs_count==0 && f.favourites_count==0&& f.replies_count==0 && f.url=="https://pixelfed.de/p/Miike/140364967936397312") assert(f.in_reply_to_id==null && f.in_reply_to_account==null && f.reblog==null && f.poll==null && f.card==null && f.language==null && f.text==null && !f.favourited && !f.reblogged && !f.muted && !f.bookmarked && !f.pinned) } + + @Test + fun register_application(){ + stubFor( + post(urlEqualTo("/api/v1/apps")) + .willReturn( + aResponse() + .withStatus(200) + .withHeader("Content-Type", "application/json") + .withBody(""" {"id":3197,"name":"Pixeldroid","website":null,"redirect_uri":"urn:ietf:wg:oauth:2.0:oob","client_id":3197,"client_secret":"hhRwLupqUJPghKsZzpZtxNV67g5DBdPYCqW6XE3m","vapid_key":null}""" + ))) + val call: Call = PixelfedAPI.create("http://localhost:8089") + .registerApplication("Pixeldroid", "urn:ietf:wg:oauth:2.0:oob", "read write follow") + val application: Application = call.execute().body()!! + assertEquals("3197", application.client_id) + assertEquals("hhRwLupqUJPghKsZzpZtxNV67g5DBdPYCqW6XE3m", application.client_secret) + assertEquals("Pixeldroid", application.name) + assertEquals(null, application.website) + assertEquals(null, application.vapid_key) + } } \ No newline at end of file