Skip to content
Draft
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
226 changes: 74 additions & 152 deletions account.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,9 @@ import (
"net/http"
)

// AccountDetails type is a struct for details JSON response.
type AccountDetails struct {
Avatar struct {
Gravatar struct {
Hash string `json:"hash"`
} `json:"gravatar"`
TMDB struct {
AvatarPath string `json:"avatar_path"`
} `json:"tmdb"`
} `json:"avatar"`
ID int64 `json:"id"`
Iso639_1 string `json:"iso_639_1"`
Iso3166_1 string `json:"iso_3166_1"`
Name string `json:"name"`
IncludeAdult bool `json:"include_adult"`
Username string `json:"username"`
}

// GetAccountDetails get your account details.
//
// https://developers.themoviedb.org/3/account/get-account-details
// https://developer.themoviedb.org/reference/account-details
func (c *Client) GetAccountDetails() (*AccountDetails, error) {
tmdbURL := fmt.Sprintf(
"%s/account?api_key=%s&session_id=%s",
Expand All @@ -40,50 +22,68 @@ func (c *Client) GetAccountDetails() (*AccountDetails, error) {
return &details, nil
}

// AccountCreatedLists type is a struct for created lists JSON response.
type AccountCreatedLists struct {
*AccountCreatedListsResults
PaginatedResultsMeta
}

// GetCreatedLists get all of the lists created by an account.
// Will invlude private lists if you are the owner.
// MarkAsFavorite this method allows you to mark a movie
// or TV show as a favorite item.
//
// https://developers.themoviedb.org/3/account/get-created-lists
func (c *Client) GetCreatedLists(
// https://developer.themoviedb.org/reference/account-add-favorite
func (c *Client) MarkAsFavorite(
id int,
urlOptions map[string]string,
) (*AccountCreatedLists, error) {
options := c.fmtOptions(urlOptions)
body AccountFavorite,
) (*Response, error) {
tmdbURL := fmt.Sprintf(
"%s%s%d/lists?api_key=%s&session_id=%s%s",
"%s%s%d/favorite?api_key=%s&session_id=%s",
baseURL,
accountURL,
id,
c.apiKey,
c.sessionID,
options,
)
createdLists := AccountCreatedLists{}
if err := c.get(tmdbURL, &createdLists); err != nil {
markAsFavorite := Response{}
if err := c.request(
tmdbURL,
body,
http.MethodPost,
&markAsFavorite,
); err != nil {
return nil, err
}
return &createdLists, nil
return &markAsFavorite, nil
}

// AccountFavoriteMovies type is a struct for favorite movies JSON response.
type AccountFavoriteMovies struct {
*AccountFavoriteMoviesResults
PaginatedResultsMeta
// AddToWatchlist add a movie or TV show to your watchlist.
//
// https://developer.themoviedb.org/reference/account-add-to-watchlist
func (c *Client) AddToWatchlist(
id int,
body AccountWatchlist,
) (*Response, error) {
tmdbURL := fmt.Sprintf(
"%s%s%d/watchlist?api_key=%s&session_id=%s",
baseURL,
accountURL,
id,
c.apiKey,
c.sessionID,
)
addToWatchlist := Response{}
if err := c.request(
tmdbURL,
body,
http.MethodPost,
&addToWatchlist,
); err != nil {
return nil, err
}
return &addToWatchlist, nil
}

// GetFavoriteMovies get the list of your favorite movies.
//
// https://developers.themoviedb.org/3/account/get-favorite-movies
// https://developer.themoviedb.org/reference/account-get-favorites
func (c *Client) GetFavoriteMovies(
id int,
urlOptions map[string]string,
) (*AccountFavoriteMovies, error) {
) (*PaginatedMovieResults, error) {
options := c.fmtOptions(urlOptions)
tmdbURL := fmt.Sprintf(
"%s%s%d/favorite/movies?api_key=%s&session_id=%s%s",
Expand All @@ -94,26 +94,20 @@ func (c *Client) GetFavoriteMovies(
c.sessionID,
options,
)
favoriteMovies := AccountFavoriteMovies{}
favoriteMovies := PaginatedMovieResults{}
if err := c.get(tmdbURL, &favoriteMovies); err != nil {
return nil, err
}
return &favoriteMovies, nil
}

// AccountFavoriteTVShows type is a struct for favorite tv shows JSON response.
type AccountFavoriteTVShows struct {
*AccountFavoriteTVShowsResults
PaginatedResultsMeta
}

// GetFavoriteTVShows get the list of your favorite TV shows.
//
// https://developers.themoviedb.org/3/account/get-favorite-tv-shows
// https://developer.themoviedb.org/reference/account-favorite-tv
func (c *Client) GetFavoriteTVShows(
id int,
urlOptions map[string]string,
) (*AccountFavoriteTVShows, error) {
) (*PaginatedTVShowResults, error) {
options := c.fmtOptions(urlOptions)
tmdbURL := fmt.Sprintf(
"%s%s%d/favorite/tv?api_key=%s&session_id=%s%s",
Expand All @@ -124,61 +118,45 @@ func (c *Client) GetFavoriteTVShows(
c.sessionID,
options,
)
favoriteTVShows := AccountFavoriteTVShows{}
favoriteTVShows := PaginatedTVShowResults{}
if err := c.get(tmdbURL, &favoriteTVShows); err != nil {
return nil, err
}
return &favoriteTVShows, nil
}

// AccountFavorite type is a struct for movies or TV shows
// favorite JSON request.
type AccountFavorite struct {
MediaType string `json:"media_type"`
MediaID int64 `json:"media_id"`
Favorite bool `json:"favorite"`
}

// MarkAsFavorite this method allows you to mark a movie
// or TV show as a favorite item.
// GetCreatedLists get all of the lists created by an account.
// Will invlude private lists if you are the owner.
//
// https://developers.themoviedb.org/3/account/mark-as-favorite
func (c *Client) MarkAsFavorite(
// https://developer.themoviedb.org/reference/account-lists
func (c *Client) GetCreatedLists(
id int,
title *AccountFavorite,
) (*Response, error) {
urlOptions map[string]string,
) (*PaginatedListResults, error) {
options := c.fmtOptions(urlOptions)
tmdbURL := fmt.Sprintf(
"%s%s%d/favorite?api_key=%s&session_id=%s",
"%s%s%d/lists?api_key=%s&session_id=%s%s",
baseURL,
accountURL,
id,
c.apiKey,
c.sessionID,
options,
)
markAsFavorite := Response{}
if err := c.request(
tmdbURL,
title,
http.MethodPost,
&markAsFavorite,
); err != nil {
createdLists := PaginatedListResults{}
if err := c.get(tmdbURL, &createdLists); err != nil {
return nil, err
}
return &markAsFavorite, nil
}

// AccountRatedMovies type is a struct for rated movies JSON response.
type AccountRatedMovies struct {
*AccountFavoriteMovies
return &createdLists, nil
}

// GetRatedMovies get a list of all the movies you have rated.
//
// https://developers.themoviedb.org/3/account/get-rated-movies
// https://developer.themoviedb.org/reference/account-rated-movies
func (c *Client) GetRatedMovies(
id int,
urlOptions map[string]string,
) (*AccountRatedMovies, error) {
) (*PaginatedMovieRatingResults, error) {
options := c.fmtOptions(urlOptions)
tmdbURL := fmt.Sprintf(
"%s%s%d/rated/movies?api_key=%s&session_id=%s%s",
Expand All @@ -189,25 +167,20 @@ func (c *Client) GetRatedMovies(
c.sessionID,
options,
)
ratedMovies := AccountRatedMovies{}
ratedMovies := PaginatedMovieRatingResults{}
if err := c.get(tmdbURL, &ratedMovies); err != nil {
return nil, err
}
return &ratedMovies, nil
}

// AccountRatedTVShows type is a struct for rated TV shows JSON response.
type AccountRatedTVShows struct {
*AccountFavoriteTVShows
}

// GetRatedTVShows get a list of all the TV shows you have rated.
//
// https://developers.themoviedb.org/3/account/get-rated-tv-shows
// https://developer.themoviedb.org/reference/account-rated-tv
func (c *Client) GetRatedTVShows(
id int,
urlOptions map[string]string,
) (*AccountRatedTVShows, error) {
) (*PaginatedTVShowRatingResults, error) {
options := c.fmtOptions(urlOptions)
tmdbURL := fmt.Sprintf(
"%s%s%d/rated/tv?api_key=%s&session_id=%s%s",
Expand All @@ -218,26 +191,20 @@ func (c *Client) GetRatedTVShows(
c.sessionID,
options,
)
ratedTVShows := AccountRatedTVShows{}
ratedTVShows := PaginatedTVShowRatingResults{}
if err := c.get(tmdbURL, &ratedTVShows); err != nil {
return nil, err
}
return &ratedTVShows, nil
}

// AccountRatedTVEpisodes type is a struct for rated TV episodes JSON response.
type AccountRatedTVEpisodes struct {
*AccountRatedTVEpisodesResults
PaginatedResultsMeta
}

// GetRatedTVEpisodes get a list of all the TV episodes you have rated.
//
// https://developers.themoviedb.org/3/account/get-rated-tv-episodes
// https://developer.themoviedb.org/reference/account-rated-tv-episodes
func (c *Client) GetRatedTVEpisodes(
id int,
urlOptions map[string]string,
) (*AccountRatedTVEpisodes, error) {
) (*PaginatedTVEpisodeRatingResults, error) {
options := c.fmtOptions(urlOptions)
tmdbURL := fmt.Sprintf(
"%s%s%d/rated/tv/episodes?api_key=%s&session_id=%s%s",
Expand All @@ -248,25 +215,20 @@ func (c *Client) GetRatedTVEpisodes(
c.sessionID,
options,
)
ratedTVEpisodes := AccountRatedTVEpisodes{}
ratedTVEpisodes := PaginatedTVEpisodeRatingResults{}
if err := c.get(tmdbURL, &ratedTVEpisodes); err != nil {
return nil, err
}
return &ratedTVEpisodes, nil
}

// AccountMovieWatchlist type is a struct for movie watchlist JSON response.
type AccountMovieWatchlist struct {
*AccountFavoriteMovies
}

// GetMovieWatchlist get a list of all the movies you have added to your watchlist.
//
// https://developers.themoviedb.org/3/account/get-movie-watchlist
// https://developer.themoviedb.org/reference/account-watchlist-movies
func (c *Client) GetMovieWatchlist(
id int,
urlOptions map[string]string,
) (*AccountMovieWatchlist, error) {
) (*PaginatedMovieResults, error) {
options := c.fmtOptions(urlOptions)
tmdbURL := fmt.Sprintf(
"%s%s%d/watchlist/movies?api_key=%s&session_id=%s%s",
Expand All @@ -277,25 +239,20 @@ func (c *Client) GetMovieWatchlist(
c.sessionID,
options,
)
movieWatchlist := AccountMovieWatchlist{}
movieWatchlist := PaginatedMovieResults{}
if err := c.get(tmdbURL, &movieWatchlist); err != nil {
return nil, err
}
return &movieWatchlist, nil
}

// AccountTVShowsWatchlist type is a struct for tv shows watchlist JSON response.
type AccountTVShowsWatchlist struct {
*AccountFavoriteTVShows
}

// GetTVShowsWatchlist get a list of all the TV shows you have added to your watchlist.
//
// https://developers.themoviedb.org/3/account/get-tv-show-watchlist
// https://developer.themoviedb.org/reference/account-watchlist-tv
func (c *Client) GetTVShowsWatchlist(
id int,
urlOptions map[string]string,
) (*AccountTVShowsWatchlist, error) {
) (*PaginatedTVShowResults, error) {
options := c.fmtOptions(urlOptions)
tmdbURL := fmt.Sprintf(
"%s%s%d/watchlist/tv?api_key=%s&session_id=%s%s",
Expand All @@ -306,44 +263,9 @@ func (c *Client) GetTVShowsWatchlist(
c.sessionID,
options,
)
tvShowsWatchlist := AccountTVShowsWatchlist{}
tvShowsWatchlist := PaginatedTVShowResults{}
if err := c.get(tmdbURL, &tvShowsWatchlist); err != nil {
return nil, err
}
return &tvShowsWatchlist, nil
}

// AccountWatchlist type is a struct for movies or TV shows
// watchlist JSON request.
type AccountWatchlist struct {
MediaType string `json:"media_type"`
MediaID int64 `json:"media_id"`
Watchlist bool `json:"watchlist"`
}

// AddToWatchlist add a movie or TV show to your watchlist.
//
// https://developers.themoviedb.org/3/account/add-to-watchlist
func (c *Client) AddToWatchlist(
id int,
title *AccountWatchlist,
) (*Response, error) {
tmdbURL := fmt.Sprintf(
"%s%s%d/watchlist?api_key=%s&session_id=%s",
baseURL,
accountURL,
id,
c.apiKey,
c.sessionID,
)
addToWatchlist := Response{}
if err := c.request(
tmdbURL,
title,
http.MethodPost,
&addToWatchlist,
); err != nil {
return nil, err
}
return &addToWatchlist, nil
}
Loading
Loading