mirror of
https://gitlab.shinice.net/pixeldroid/PixelDroid
synced 2025-01-01 17:57:42 +01:00
Add application registration endpoint to API
This commit is contained in:
parent
55d1d778b0
commit
14197355c1
@ -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<Application>
|
||||
|
||||
@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<List<Status>>
|
||||
|
||||
companion object {
|
||||
|
@ -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
|
||||
)
|
@ -132,4 +132,24 @@ class APIUnitTest {
|
||||
f.emojis== emptyList<Emoji>() && 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<Application> = 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)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user