2020-03-04 18:04:55 +01:00
|
|
|
package com.h.pixeldroid.api
|
|
|
|
|
2020-03-18 20:56:42 +01:00
|
|
|
import com.h.pixeldroid.objects.*
|
2020-03-04 18:04:55 +01:00
|
|
|
import retrofit2.Call
|
|
|
|
import retrofit2.Retrofit
|
|
|
|
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory
|
|
|
|
import retrofit2.converter.gson.GsonConverterFactory
|
2020-03-13 11:48:45 +01:00
|
|
|
import retrofit2.http.*
|
2020-03-18 20:56:42 +01:00
|
|
|
import retrofit2.http.Field
|
2020-03-06 09:00:18 +01:00
|
|
|
|
|
|
|
|
2020-03-04 18:04:55 +01:00
|
|
|
/*
|
|
|
|
Implements the Pixelfed API
|
|
|
|
https://docs.pixelfed.org/technical-documentation/api-v1.html
|
|
|
|
However, since this is mostly based on the Mastodon API, the documentation there
|
|
|
|
will be more useful: https://docs.joinmastodon.org/
|
|
|
|
*/
|
|
|
|
|
|
|
|
interface PixelfedAPI {
|
|
|
|
|
2020-03-05 19:08:57 +01:00
|
|
|
@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>
|
|
|
|
|
2020-03-06 18:24:20 +01:00
|
|
|
@FormUrlEncoded
|
|
|
|
@POST("/oauth/token")
|
|
|
|
fun obtainToken(
|
|
|
|
@Field("client_id") client_id: String,
|
|
|
|
@Field("client_secret") client_secret: String,
|
|
|
|
@Field("redirect_uri") redirect_uri: String,
|
|
|
|
@Field("scope") scope: String? = "read",
|
|
|
|
@Field("code") code: String? = null,
|
|
|
|
@Field("grant_type") grant_type: String? = null
|
|
|
|
): Call<Token>
|
|
|
|
|
2020-04-09 22:36:59 +02:00
|
|
|
@POST("api/v1/statuses/{id}/favourite")
|
|
|
|
fun likePost(
|
|
|
|
//The authorization header needs to be of the form "Bearer <token>"
|
|
|
|
@Header("Authorization") authorization: String,
|
|
|
|
@Path("id") statusId: String
|
|
|
|
) : Call<Status>
|
|
|
|
|
|
|
|
@POST("/api/v1/statuses/{id}/unfavourite")
|
|
|
|
fun unlikePost(
|
|
|
|
//The authorization header needs to be of the form "Bearer <token>"
|
|
|
|
@Header("Authorization") authorization: String,
|
|
|
|
@Path("id") statusId: String
|
|
|
|
) : Call<Status>
|
|
|
|
|
|
|
|
@POST("/api/v1/statuses/{id}/favourited_by")
|
|
|
|
fun postLikedBy(
|
|
|
|
@Path("id") statusId: String
|
|
|
|
) : Call<List<Account>>
|
|
|
|
|
|
|
|
//Used in our case to post a comment
|
|
|
|
@FormUrlEncoded
|
|
|
|
@POST("/api/v1/statuses")
|
|
|
|
fun commentStatus(
|
|
|
|
//The authorization header needs to be of the form "Bearer <token>"
|
|
|
|
@Header("Authorization") authorization: String,
|
|
|
|
@Field("status") statusText : String,
|
|
|
|
@Field("in_reply_to_id") in_reply_to_id : String,
|
|
|
|
@Field("media_ids[]") media_ids : List<String> = emptyList(),
|
|
|
|
@Field("poll[options][]") poll_options : List<String>? = null,
|
|
|
|
@Field("poll[expires_in]") poll_expires : List<String>? = null,
|
|
|
|
@Field("poll[multiple]") poll_multiple : List<String>? = null,
|
|
|
|
@Field("poll[hide_totals]") poll_hideTotals : List<String>? = null,
|
|
|
|
@Field("sensitive") sensitive : Boolean? = null,
|
|
|
|
@Field("spoiler_text") spoiler_text : String? = null,
|
|
|
|
@Field("visibility") visibility : String = "public",
|
|
|
|
@Field("scheduled_at") scheduled_at : String? = null,
|
|
|
|
@Field("language") language : String? = null
|
|
|
|
) : Call<Status>
|
|
|
|
|
|
|
|
//Used in our case to retrieve comments for a given status
|
|
|
|
@GET("/api/v1/statuses/{id}/context")
|
|
|
|
fun statusComments(
|
|
|
|
@Path("id") statusId: String,
|
|
|
|
@Header("Authorization") authorization: String? = null
|
|
|
|
) : Call<Context>
|
|
|
|
|
2020-03-07 11:00:24 +01:00
|
|
|
@GET("/api/v1/timelines/public")
|
2020-03-04 18:04:55 +01:00
|
|
|
fun timelinePublic(
|
2020-03-05 19:08:57 +01:00
|
|
|
@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,
|
2020-04-02 19:57:07 +02:00
|
|
|
@Query("limit") limit: String? = null
|
2020-03-04 18:04:55 +01:00
|
|
|
): Call<List<Status>>
|
|
|
|
|
2020-03-13 11:48:45 +01:00
|
|
|
@GET("/api/v1/timelines/home")
|
|
|
|
fun timelineHome(
|
|
|
|
//The authorization header needs to be of the form "Bearer <token>"
|
|
|
|
@Header("Authorization") authorization: String,
|
|
|
|
@Query("max_id") max_id: String? = null,
|
|
|
|
@Query("since_id") since_id: String? = null,
|
|
|
|
@Query("min_id") min_id: String? = null,
|
2020-04-02 19:57:07 +02:00
|
|
|
@Query("limit") limit: String? = null,
|
2020-03-13 11:48:45 +01:00
|
|
|
@Query("local") local: Boolean? = null
|
|
|
|
): Call<List<Status>>
|
|
|
|
|
2020-03-18 20:56:42 +01:00
|
|
|
/*
|
|
|
|
Note: as of 0.10.8, Pixelfed does not seem to respect the Mastodon API documentation,
|
|
|
|
you *need* to pass one of the so-called "optional" arguments. See:
|
|
|
|
https://github.com/pixelfed/pixelfed/blob/dev/app/Http/Controllers/Api/ApiV1Controller.php
|
|
|
|
An example that works: specify min_id as 1 (not 0 though)
|
|
|
|
*/
|
|
|
|
@GET("/api/v1/notifications")
|
|
|
|
fun notifications(
|
|
|
|
//The authorization header needs to be of the form "Bearer <token>"
|
|
|
|
@Header("Authorization") authorization: String,
|
|
|
|
@Query("max_id") max_id: String? = null,
|
|
|
|
@Query("since_id") since_id: String? = null,
|
|
|
|
@Query("min_id") min_id: String? = null,
|
|
|
|
@Query("exclude_types") limit: String? = null,
|
|
|
|
@Query("account_id") exclude_types: Boolean? = null
|
|
|
|
): Call<List<Notification>>
|
|
|
|
|
2020-03-13 11:48:45 +01:00
|
|
|
@GET("/api/v1/accounts/verify_credentials")
|
|
|
|
fun verifyCredentials(
|
|
|
|
//The authorization header needs to be of the form "Bearer <token>"
|
|
|
|
@Header("Authorization") authorization: String
|
|
|
|
): Call<Account>
|
|
|
|
|
2020-04-09 22:36:59 +02:00
|
|
|
@GET("/api/v1/accounts/{id}/statuses")
|
|
|
|
fun accountPosts(
|
|
|
|
@Header("Authorization") authorization: String,
|
|
|
|
@Path("id") account_id: String? = null
|
|
|
|
): Call<List<Status>>
|
|
|
|
|
2020-03-04 18:04:55 +01:00
|
|
|
companion object {
|
|
|
|
fun create(baseUrl: String): PixelfedAPI {
|
|
|
|
return Retrofit.Builder()
|
|
|
|
.baseUrl(baseUrl)
|
|
|
|
.addConverterFactory(GsonConverterFactory.create())
|
|
|
|
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
|
|
|
|
.build().create(PixelfedAPI::class.java)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|