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

feat: add season translation #52

Merged
merged 4 commits into from
Jan 4, 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
45 changes: 45 additions & 0 deletions tv_seasons.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ type TVSeasonDetails struct {
*TVSeasonExternalIDsAppend
*TVSeasonImagesAppend
*TVSeasonVideosAppend
*TVSeasonTranslationsAppend
}

// TVSeasonCreditsAppend type is a struct
Expand All @@ -66,6 +67,27 @@ type TVSeasonImagesAppend struct {
Images *TVSeasonImages `json:"images,omitempty"`
}

// TVSeasonTranslationsAppend type is a struct
// for translations in append to response.
type TVSeasonTranslationsAppend struct {
Translations *TVSeasonTranslations `json:"translations,omitempty"`
}

// TVSeasonTranslations type is a struct
type TVSeasonTranslations struct {
ID int64 `json:"id,omitempty"`
Translations []struct {
Iso31661 string `json:"iso_3166_1"`
Iso6391 string `json:"iso_639_1"`
Name string `json:"name"`
EnglishName string `json:"english_name"`
Data struct {
Name string `json:"name"`
Overview string `json:"overview"`
} `json:"data"`
} `json:"translations"`
}

// TVSeasonVideosAppend type is a struct
// for videos in append to response.
type TVSeasonVideosAppend struct {
Expand Down Expand Up @@ -324,3 +346,26 @@ func (c *Client) GetTVSeasonVideos(
}
return &tvSeasonVideos, nil
}

// GetTVSeasonTranslations get the translation data for an season.
//
// https://developer.themoviedb.org/reference/tv-season-translations
func (c *Client) GetTVSeasonTranslations(
id int,
seasonNumber int,
) (*TVSeasonTranslations, error) {
tmdbURL := fmt.Sprintf(
"%s%s%d%s%d/translations?api_key=%s",
baseURL,
tvURL,
id,
tvSeasonURL,
seasonNumber,
c.apiKey,
)
tvSeasonTranslations := TVSeasonTranslations{}
if err := c.get(tmdbURL, &tvSeasonTranslations); err != nil {
return nil, err
}
return &tvSeasonTranslations, nil
}
11 changes: 11 additions & 0 deletions tv_seasons_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,14 @@ func (suite *TMBDTestSuite) TestGetTVSeasonVideosWithOptions() {
suite.Nil(err)
suite.NotNil(tv.ID)
}

func (suite *TMBDTestSuite) TestGetTVSeasonTranslations() {
got, err := suite.client.GetTVSeasonTranslations(gotID, 1)
suite.Nil(err)
suite.Equal(int64(gotSeasonID), got.ID)
}

func (suite *TMBDTestSuite) TestGetTVSeasonTranslationsFail() {
_, err := suite.client.GetTVSeasonTranslations(0, 1)
suite.Equal("code: 34 | success: false | message: The resource you requested could not be found.", err.Error())
}
Loading