Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support notes (VIP only) #152

Merged
merged 1 commit into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ Change Log

## next

* `TraktV2.notes()`: support to add, get, update and delete a note.
* `TraktV2.users().notes(...)`: Support to get all notes for a user.
* Add `Sync.removePlayback(id)`.

## 6.14.0
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/uwetrottmann/trakt5/TraktV2.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import com.uwetrottmann.trakt5.services.Episodes;
import com.uwetrottmann.trakt5.services.Genres;
import com.uwetrottmann.trakt5.services.Movies;
import com.uwetrottmann.trakt5.services.Notes;
import com.uwetrottmann.trakt5.services.People;
import com.uwetrottmann.trakt5.services.Recommendations;
import com.uwetrottmann.trakt5.services.Scrobble;
Expand Down Expand Up @@ -448,6 +449,10 @@ public Movies movies() {
return retrofit().create(Movies.class);
}

public Notes notes() {
return retrofit().create(Notes.class);
}

public People people() {
return retrofit().create(People.class);
}
Expand Down
59 changes: 59 additions & 0 deletions src/main/java/com/uwetrottmann/trakt5/entities/AddNoteRequest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright 2024 Uwe Trottmann
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.uwetrottmann.trakt5.entities;

import javax.annotation.Nonnull;

public class AddNoteRequest extends UpdateNoteRequest {

public NoteAttachedTo attached_to;
public Movie movie;
public Show show;
public Season season;
public Episode episode;
public Person person;

public AddNoteRequest(@Nonnull Movie movie, @Nonnull String notes) {
super(notes);
this.movie = movie;
}

public AddNoteRequest(@Nonnull Show show, @Nonnull String notes) {
super(notes);
this.show = show;
}

public AddNoteRequest(@Nonnull Season season, @Nonnull String notes) {
super(notes);
this.season = season;
}

public AddNoteRequest(@Nonnull Episode episode, @Nonnull String notes) {
super(notes);
this.episode = episode;
}

public AddNoteRequest(@Nonnull Person person, @Nonnull String notes) {
super(notes);
this.person = person;
}

public AddNoteRequest setAttachedTo(NoteAttachedTo attachedTo) {
this.attached_to = attachedTo;
return this;
}
}
32 changes: 32 additions & 0 deletions src/main/java/com/uwetrottmann/trakt5/entities/Note.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright 2024 Uwe Trottmann
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.uwetrottmann.trakt5.entities;

import com.uwetrottmann.trakt5.enums.Privacy;
import org.threeten.bp.OffsetDateTime;

public class Note {

public long id;
public String notes;
public Privacy privacy;
public boolean spoiler;
public OffsetDateTime created_at;
public OffsetDateTime updated_at;
public User user;

}
33 changes: 33 additions & 0 deletions src/main/java/com/uwetrottmann/trakt5/entities/NoteAttachedTo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright 2024 Uwe Trottmann
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.uwetrottmann.trakt5.entities;

import com.uwetrottmann.trakt5.enums.NoteType;

public class NoteAttachedTo {
public NoteType type;
public Long id;

public NoteAttachedTo(NoteType type) {
this.type = type;
}

public NoteAttachedTo(long id) {
this.type = NoteType.HISTORY;
this.id = id;
}
}
30 changes: 30 additions & 0 deletions src/main/java/com/uwetrottmann/trakt5/entities/NoteResponse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright 2024 Uwe Trottmann
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.uwetrottmann.trakt5.entities;

public class NoteResponse {

public NoteAttachedTo attached_to;
public String type;
public Movie movie;
public Show show;
public Season season;
public Episode episode;
public Person person;
public Note note;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright 2024 Uwe Trottmann
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.uwetrottmann.trakt5.entities;

import com.uwetrottmann.trakt5.enums.Privacy;

import javax.annotation.Nonnull;

public class UpdateNoteRequest {

String notes;
Boolean spoiler;
Privacy privacy;

public UpdateNoteRequest(@Nonnull String notes) {
this.notes = notes;
}

public UpdateNoteRequest setSpoiler(boolean spoiler) {
this.spoiler = spoiler;
return this;
}

public UpdateNoteRequest setPrivacy(@Nonnull Privacy privacy) {
this.privacy = privacy;
return this;
}
}
40 changes: 40 additions & 0 deletions src/main/java/com/uwetrottmann/trakt5/enums/NoteType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright 2024 Uwe Trottmann
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.uwetrottmann.trakt5.enums;

import com.google.gson.annotations.SerializedName;

public enum NoteType {

@SerializedName("movie")
MOVIE,
@SerializedName("show")
SHOW,
@SerializedName("season")
SEASON,
@SerializedName("episode")
EPISODE,
@SerializedName("person")
PERSON,
@SerializedName("history")
HISTORY,
@SerializedName("collection")
COLLECTION,
@SerializedName("rating")
RATING

}
31 changes: 31 additions & 0 deletions src/main/java/com/uwetrottmann/trakt5/enums/Privacy.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright 2024 Uwe Trottmann
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.uwetrottmann.trakt5.enums;

import com.google.gson.annotations.SerializedName;

public enum Privacy {

@SerializedName("private")
PRIVATE,

@SerializedName("friends")
FRIENDS,

@SerializedName("public")
PUBLIC
}
80 changes: 80 additions & 0 deletions src/main/java/com/uwetrottmann/trakt5/services/Notes.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* Copyright 2024 Uwe Trottmann
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.uwetrottmann.trakt5.services;

import com.uwetrottmann.trakt5.entities.AddNoteRequest;
import com.uwetrottmann.trakt5.entities.Note;
import com.uwetrottmann.trakt5.entities.UpdateNoteRequest;
import retrofit2.Call;
import retrofit2.http.Body;
import retrofit2.http.DELETE;
import retrofit2.http.GET;
import retrofit2.http.POST;
import retrofit2.http.PUT;
import retrofit2.http.Path;

public interface Notes {

/**
* <b>VIP Only, OAuth Required</b>
* <p>
* Add a note (maximum 500 characters). Note: this also replaces an existing note.
* <p>
* <a href="https://trakt.docs.apiary.io/#reference/notes/notes/add-notes">Online documentation</a>
*/
@POST("notes")
Call<Note> addNote(
@Body AddNoteRequest request
);

/**
* <b>VIP Only, OAuth Required</b>
* <p>
* Get a note.
* <p>
* <a href="https://trakt.docs.apiary.io/#reference/notes/note/get-a-note">Online documentation</a>
*/
@GET("notes/{id}")
Call<Note> getNote(
@Path("id") long id
);

/**
* <b>VIP Only, OAuth Required</b>
* <p>
* Update a note (maximum 500 characters).
* <p>
* <a href="https://trakt.docs.apiary.io/#reference/notes/note/update-a-note">Online documentation</a>
*/
@PUT("notes/{id}")
Call<Note> updateNote(
@Path("id") long id,
@Body UpdateNoteRequest request
);

/**
* <b>VIP Only, OAuth Required</b>
* <p>
* Delete a note.
* <p>
* <a href="https://trakt.docs.apiary.io/#reference/notes/note/delete-a-note">Online documentation</a>
*/
@DELETE("notes/{id}")
Call<Void> deleteNote(
@Path("id") long id
);
}
Loading
Loading