Skip to content

Commit

Permalink
Merge pull request #52 from just-tktok/master
Browse files Browse the repository at this point in the history
feat: add season translation
  • Loading branch information
cyruzin authored Jan 4, 2024
2 parents 0872059 + de7d383 commit 1ffc8ed
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
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())
}

0 comments on commit 1ffc8ed

Please sign in to comment.