Skip to content

Commit

Permalink
Sync: add removePlayback #126
Browse files Browse the repository at this point in the history
Use Trakt ID for testing episode scrobble.
  • Loading branch information
UweTrottmann committed Aug 29, 2024
1 parent ae6da83 commit f0f9539
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
Change Log
==========
## next

* Add `Sync.removePlayback(id)`.

## 6.14.0
_2024-07-12_
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/com/uwetrottmann/trakt5/services/Sync.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import com.uwetrottmann.trakt5.enums.RatingsFilter;
import retrofit2.Call;
import retrofit2.http.Body;
import retrofit2.http.DELETE;
import retrofit2.http.GET;
import retrofit2.http.POST;
import retrofit2.http.Path;
Expand Down Expand Up @@ -137,6 +138,18 @@ Call<List<PlaybackResponse>> getPlaybackMovies(
@Query("limit") Integer limit
);

/**
* <b>OAuth Required</b>
* <p>
* Remove a playback item from a user's playback progress list. A 404 will be returned if the id is invalid.
* <p>
* <a href="https://trakt.docs.apiary.io/#reference/sync/remove-playback/remove-a-playback-item">Online documentation</a>
*/
@DELETE("sync/playback/{id}")
Call<Void> removePlayback(
@Path("id") long id
);

/**
* <b>OAuth Required</b>
*
Expand Down
19 changes: 13 additions & 6 deletions src/test/java/com/uwetrottmann/trakt5/services/SyncTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ public void test_lastActivites() throws IOException {
@Test
public void test_getPlayback() throws IOException, InterruptedException {
// Make sure there are paused entries.
int agentsOfShield = 4420028; /* S01E01 */
SyncEpisode episode = new SyncEpisode().id(EpisodeIds.tvdb(agentsOfShield));
int agentsOfShield = 74005; /* S01E01 */
SyncEpisode episode = new SyncEpisode().id(EpisodeIds.trakt(agentsOfShield));
ScrobbleProgress episodeProgress = new ScrobbleProgress(episode, 25.0, null, null);
PlaybackResponse episodeResponse = executeCall(getTrakt().scrobble().pauseWatching(episodeProgress));
assertThat(episodeResponse.action).isEqualTo("pause");
Expand All @@ -109,8 +109,8 @@ public void test_getPlayback() throws IOException, InterruptedException {
for (PlaybackResponse playback : playbacks) {
assertThat(playback.type).isNotNull();

if (playback.episode != null && playback.episode.ids != null && playback.episode.ids.tvdb != null
&& playback.episode.ids.tvdb == agentsOfShield) {
if (playback.episode != null && playback.episode.ids != null && playback.episode.ids.trakt != null
&& playback.episode.ids.trakt == agentsOfShield) {
foundEpisode = true;
assertThat(playback.paused_at).isNotNull();
assertThat(playback.progress).isEqualTo(25.0);
Expand All @@ -124,10 +124,17 @@ public void test_getPlayback() throws IOException, InterruptedException {
}
}

if (!foundEpisode) //noinspection ResultOfMethodCallIgnored
if (!foundEpisode) {
fail("Agents of Shield episode not paused.");
if (!foundMovie) //noinspection ResultOfMethodCallIgnored
}
if (!foundMovie) {
fail("Interstellar movie not paused.");
}

for (PlaybackResponse playback : playbacks) {
assertThat(playback.id).isNotNull();
executeVoidCall(getTrakt().sync().removePlayback(playback.id));
}
}

private void assertLastActivityMore(LastActivityMore activityMore) {
Expand Down

0 comments on commit f0f9539

Please sign in to comment.