Skip to content

Commit

Permalink
feature #65: custom base url implemented (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
cyruzin committed Jun 20, 2024
1 parent 034bf76 commit 059618b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 10 additions & 0 deletions tmdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
12 changes: 12 additions & 0 deletions tmdb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

0 comments on commit 059618b

Please sign in to comment.