From 059618bfc1e29bebf050212c382067f24f3dbaf4 Mon Sep 17 00:00:00 2001 From: Cyro Date: Thu, 20 Jun 2024 11:34:17 -0300 Subject: [PATCH] feature #65: custom base url implemented (#66) --- README.md | 6 ++++++ tmdb.go | 10 ++++++++++ tmdb_test.go | 12 ++++++++++++ 3 files changed, 28 insertions(+) diff --git a/README.md b/README.md index e7550ca..c0018e4 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,12 @@ tmdbClient.SetClientAutoRetry() // Use https://api.tmdb.org/3 instead of https://api.themoviedb.org/3. tmdbClient.SetAlternateBaseURL() +// OPTIONAL: For tests, set a custom base URL +tmdbClient.SetCustomBaseURL("http://localhost:3000") + +// Get the current base URL +tmdbClient.GetBaseURL() + // OPTIONAL: Setting a custom config for the http.Client. // The default timeout is 10 seconds. Here you can set other // options like Timeout and Transport. diff --git a/tmdb.go b/tmdb.go index fb6aaa3..4e681f9 100644 --- a/tmdb.go +++ b/tmdb.go @@ -242,6 +242,16 @@ func (c *Client) SetAlternateBaseURL() { baseURL = alternateBaseURL } +// SetCustomBaseURL sets an custom base url. +func (c *Client) SetCustomBaseURL(url string) { + baseURL = url +} + +// GetBaseURL gets the current base url. +func (c *Client) GetBaseURL() string { + return baseURL +} + // Error type represents an error returned by the TMDB API. type Error struct { StatusMessage string `json:"status_message,omitempty"` diff --git a/tmdb_test.go b/tmdb_test.go index aec6ece..74a2271 100644 --- a/tmdb_test.go +++ b/tmdb_test.go @@ -167,3 +167,15 @@ func (suite *TMBDTestSuite) TestClientV4Fail() { suite.EqualError(err, "bearer token is empty") } + +func (suite *TMBDTestSuite) TestAlternateBaseURL() { + suite.client.SetAlternateBaseURL() + + suite.Equal(suite.client.GetBaseURL(), "https://api.tmdb.org/3") +} + +func (suite *TMBDTestSuite) TestCustomBaseURL() { + suite.client.SetCustomBaseURL("https://api.themoviedb.org/3") + + suite.Equal(suite.client.GetBaseURL(), "https://api.themoviedb.org/3") +}