Skip to content

Commit

Permalink
draft: Support notes (VIP only)
Browse files Browse the repository at this point in the history
  • Loading branch information
UweTrottmann committed Aug 29, 2024
1 parent f0f9539 commit c551fce
Show file tree
Hide file tree
Showing 12 changed files with 432 additions and 0 deletions.
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
54 changes: 54 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,54 @@
/*
* 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;

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 AddNoteRequest(@Nonnull Movie movie, @Nonnull String notes) {
super(notes);
this.attached_to = new NoteAttachedTo(NoteType.MOVIE);
this.movie = movie;
}

public AddNoteRequest(@Nonnull Show show, @Nonnull String notes) {
super(notes);
this.attached_to = new NoteAttachedTo(NoteType.SHOW);
this.show = show;
}

public AddNoteRequest(@Nonnull Season season, @Nonnull String notes) {
super(notes);
this.attached_to = new NoteAttachedTo(NoteType.SEASON);
this.season = season;
}

public AddNoteRequest(@Nonnull Episode episode, @Nonnull String notes) {
super(notes);
this.attached_to = new NoteAttachedTo(NoteType.EPISODE);
this.episode = episode;
}
}
31 changes: 31 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,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.entities;

import org.threeten.bp.OffsetDateTime;

public class Note {

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

}
28 changes: 28 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,28 @@
/*
* 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;
}
}
29 changes: 29 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,29 @@
/*
* 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 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).
* <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

0 comments on commit c551fce

Please sign in to comment.