From cff0f352699c3c503ae8c8c7e0e401e958e4df76 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Wed, 8 Mar 2017 22:08:50 +0100 Subject: [PATCH] Start work on integrating Retrofit - Mastodon API definition --- app/build.gradle | 1 + .../keylesspalace/tusky/MastodonService.java | 105 ++++++++++++++++++ .../com/keylesspalace/tusky/entity/Media.java | 49 ++++++++ .../tusky/entity/Relationship.java | 58 ++++++++++ .../tusky/entity/StatusContext.java | 27 +++++ 5 files changed, 240 insertions(+) create mode 100644 app/src/main/java/com/keylesspalace/tusky/MastodonService.java create mode 100644 app/src/main/java/com/keylesspalace/tusky/entity/Media.java create mode 100644 app/src/main/java/com/keylesspalace/tusky/entity/Relationship.java create mode 100644 app/src/main/java/com/keylesspalace/tusky/entity/StatusContext.java diff --git a/app/build.gradle b/app/build.gradle index c9c6c400b..7c6d43e27 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -35,4 +35,5 @@ dependencies { compile 'com.github.peter9870:sparkbutton:master' testCompile 'junit:junit:4.12' compile 'com.mikhaellopez:circularfillableloaders:1.2.0' + compile 'com.squareup.retrofit2:retrofit:2.2.0' } diff --git a/app/src/main/java/com/keylesspalace/tusky/MastodonService.java b/app/src/main/java/com/keylesspalace/tusky/MastodonService.java new file mode 100644 index 000000000..1a74781fe --- /dev/null +++ b/app/src/main/java/com/keylesspalace/tusky/MastodonService.java @@ -0,0 +1,105 @@ +package com.keylesspalace.tusky; + +import com.keylesspalace.tusky.entity.Media; +import com.keylesspalace.tusky.entity.Relationship; +import com.keylesspalace.tusky.entity.StatusContext; + +import java.util.List; + +import okhttp3.RequestBody; +import retrofit2.Call; +import retrofit2.http.DELETE; +import retrofit2.http.Field; +import retrofit2.http.FormUrlEncoded; +import retrofit2.http.GET; +import retrofit2.http.Multipart; +import retrofit2.http.POST; +import retrofit2.http.Part; +import retrofit2.http.Path; +import retrofit2.http.Query; + +public interface MastodonService { + @GET("api/v1/timelines/home") + Call> homeTimeline(@Query("max_id") int maxId, @Query("since_id") int sinceId, @Query("limit") int limit); + @GET("api/v1/timelines/public") + Call> publicTimeline(@Query("local") boolean local, @Query("max_id") int maxId, @Query("since_id") int sinceId, @Query("limit") int limit); + @GET("api/v1/timelines/tag/{hashtag}") + Call> hashtagTimeline(@Path("hashtag") String hashtag, @Query("local") boolean local, @Query("max_id") int maxId, @Query("since_id") int sinceId, @Query("limit") int limit); + + @GET("api/v1/notifications") + Call> notifications(@Query("max_id") int maxId, @Query("since_id") int sinceId, @Query("limit") int limit); + @POST("api/v1/notifications/clear") + Call clearNotifications(); + @GET("api/v1/notifications/{id}") + Call notification(@Path("id") int notificationId); + + @Multipart + @POST("api/v1/media") + Call uploadMedia(@Part("file") RequestBody file); + + @FormUrlEncoded + @POST("api/v1/statuses") + Call createStatus(@Field("status") String text, @Field("in_reply_to_id") int inReplyToId, @Field("spoiler_text") String warningText, @Field("visibility") String visibility, @Field("sensitive") boolean sensitive, @Field("media_ids[]") List mediaIds); + @GET("api/v1/statuses/{id}") + Call status(@Path("id") int statusId); + @GET("api/v1/statuses/{id}/context") + Call statusContext(@Path("id") int statusId); + @GET("api/v1/statuses/{id}/reblogged_by") + Call> statusRebloggedBy(@Path("id") int statusId, @Query("max_id") int maxId, @Query("since_id") int sinceId, @Query("limit") int limit); + @GET("api/v1/statuses/{id}/favourited_by") + Call> statusFavouritedBy(@Path("id") int statusId, @Query("max_id") int maxId, @Query("since_id") int sinceId, @Query("limit") int limit); + @DELETE("api/v1/statuses/{id}") + Call deleteStatus(@Path("id") int statusId); + @POST("api/v1/statuses/{id}/reblog") + Call reblogStatus(@Path("id") int statusId); + @POST("api/v1/statuses/{id}/unreblog") + Call unreblogStatus(@Path("id") int statusId); + @POST("api/v1/statuses/{id}/favourite") + Call favouriteStatus(@Path("id") int statusId); + @POST("api/v1/statuses/{id}/unfavourite") + Call unfavouriteStatus(@Path("id") int statusId); + + @GET("api/v1/accounts/verify_credentials") + Call accountVerifyCredentials(); + @GET("api/v1/accounts/search") + Call> searchAccounts(@Query("q") String q, @Query("resolve") boolean resolve, @Query("limit") int limit); + @GET("api/v1/accounts/{id}") + Call account(@Path("id") int accountId); + @GET("api/v1/accounts/{id}/statuses") + Call> accountStatuses(@Path("id") int accountId, @Query("max_id") int maxId, @Query("since_id") int sinceId, @Query("limit") int limit); + @GET("api/v1/accounts/{id}/followers") + Call> accountFollowers(@Path("id") int accountId, @Query("max_id") int maxId, @Query("since_id") int sinceId, @Query("limit") int limit); + @GET("api/v1/accounts/{id}/following") + Call> accountFollowing(@Path("id") int accountId, @Query("max_id") int maxId, @Query("since_id") int sinceId, @Query("limit") int limit); + @POST("api/v1/accounts/{id}/follow") + Call followAccount(@Path("id") int accountId); + @POST("api/v1/accounts/{id}/unfollow") + Call unfollowAccount(@Path("id") int accountId); + @POST("api/v1/accounts/{id}/block") + Call blockAccount(@Path("id") int accountId); + @POST("api/v1/accounts/{id}/unblock") + Call unblockAccount(@Path("id") int accountId); + @POST("api/v1/accounts/{id}/mute") + Call muteAccount(@Path("id") int accountId); + @POST("api/v1/accounts/{id}/unmute") + Call unmuteAccount(@Path("id") int accountId); + + @GET("api/v1/accounts/relationships") + Call> relationships(@Query("id[]") List accountIds); + + @GET("api/v1/blocks") + Call> blocks(@Query("max_id") int maxId, @Query("since_id") int sinceId, @Query("limit") int limit); + + @GET("api/v1/mutes") + Call> mutes(@Query("max_id") int maxId, @Query("since_id") int sinceId, @Query("limit") int limit); + + @GET("api/v1/favourites") + Call> favourites(@Query("max_id") int maxId, @Query("since_id") int sinceId, @Query("limit") int limit); + + @GET("api/v1/follow_requests") + Call> followRequests(@Query("max_id") int maxId, @Query("since_id") int sinceId, @Query("limit") int limit); + @POST("api/v1/follow_requests/{id}/authorize") + Call authorizeFollowRequest(@Path("id") int accountId); + @POST("api/v1/follow_requests/{id}/reject") + Call rejectFollowRequest(@Path("id") int accountId); +} diff --git a/app/src/main/java/com/keylesspalace/tusky/entity/Media.java b/app/src/main/java/com/keylesspalace/tusky/entity/Media.java new file mode 100644 index 000000000..38c40c090 --- /dev/null +++ b/app/src/main/java/com/keylesspalace/tusky/entity/Media.java @@ -0,0 +1,49 @@ +package com.keylesspalace.tusky.entity; + +public class Media { + int id; + String type; + String url; + String preview_url; + String text_url; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + public String getPreview_url() { + return preview_url; + } + + public void setPreview_url(String preview_url) { + this.preview_url = preview_url; + } + + public String getText_url() { + return text_url; + } + + public void setText_url(String text_url) { + this.text_url = text_url; + } +} diff --git a/app/src/main/java/com/keylesspalace/tusky/entity/Relationship.java b/app/src/main/java/com/keylesspalace/tusky/entity/Relationship.java new file mode 100644 index 000000000..ffffc9452 --- /dev/null +++ b/app/src/main/java/com/keylesspalace/tusky/entity/Relationship.java @@ -0,0 +1,58 @@ +package com.keylesspalace.tusky.entity; + +public class Relationship { + public boolean isFollowing() { + return following; + } + + public void setFollowing(boolean following) { + this.following = following; + } + + public boolean isFollowed_by() { + return followed_by; + } + + public void setFollowed_by(boolean followed_by) { + this.followed_by = followed_by; + } + + public boolean isBlocking() { + return blocking; + } + + public void setBlocking(boolean blocking) { + this.blocking = blocking; + } + + public boolean isMuting() { + return muting; + } + + public void setMuting(boolean muting) { + this.muting = muting; + } + + public boolean isRequested() { + return requested; + } + + public void setRequested(boolean requested) { + this.requested = requested; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + int id; + boolean following; + boolean followed_by; + boolean blocking; + boolean muting; + boolean requested; +} diff --git a/app/src/main/java/com/keylesspalace/tusky/entity/StatusContext.java b/app/src/main/java/com/keylesspalace/tusky/entity/StatusContext.java new file mode 100644 index 000000000..15d2fded6 --- /dev/null +++ b/app/src/main/java/com/keylesspalace/tusky/entity/StatusContext.java @@ -0,0 +1,27 @@ +package com.keylesspalace.tusky.entity; + +import com.keylesspalace.tusky.Status; + +import java.util.List; + +public class StatusContext { + List ancestors; + + public List getAncestors() { + return ancestors; + } + + public void setAncestors(List ancestors) { + this.ancestors = ancestors; + } + + public List getDescendants() { + return descendants; + } + + public void setDescendants(List descendants) { + this.descendants = descendants; + } + + List descendants; +}