Add go mod, rename imdb -> omdb, fix a broken test
This commit is contained in:
parent
5f94d77032
commit
28ba3ae5fc
4 changed files with 24 additions and 14 deletions
5
go.mod
Normal file
5
go.mod
Normal file
|
@ -0,0 +1,5 @@
|
|||
module git.minhas.io/asara/gomdb
|
||||
|
||||
go 1.19
|
||||
|
||||
require github.com/davecgh/go-spew v1.1.1 // indirect
|
2
go.sum
Normal file
2
go.sum
Normal file
|
@ -0,0 +1,2 @@
|
|||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
11
gomdb.go
11
gomdb.go
|
@ -7,10 +7,12 @@ import (
|
|||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
)
|
||||
|
||||
const (
|
||||
baseURL = "http://www.omdbapi.com"
|
||||
baseURL = "https://www.omdbapi.com"
|
||||
plot = "full"
|
||||
tomatoes = "true"
|
||||
|
||||
|
@ -137,8 +139,9 @@ func (api *OmdbApi) MovieByTitle(query *QueryData) (*MovieResult, error) {
|
|||
|
||||
// MovieByImdbID returns a MovieResult given a ImdbID ex:"tt2015381"
|
||||
func (api *OmdbApi) MovieByImdbID(query *QueryData) (*MovieResult, error) {
|
||||
resp, err := api.requestAPI("id", query.ImdbId, query.Year, query.SearchType, query.Season,
|
||||
query.Episode)
|
||||
spew.Dump(api.requestAPI("id", query.ImdbId, query.Year, query.SearchType, query.Season, query.Episode))
|
||||
|
||||
resp, err := api.requestAPI("id", query.ImdbId, query.Year, query.SearchType, query.Season, query.Episode)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -212,7 +215,7 @@ func (api *OmdbApi) requestAPI(apiCategory string, params ...string) (resp *http
|
|||
|
||||
func checkErr(status int) error {
|
||||
if status != 200 {
|
||||
return fmt.Errorf("Status Code %d received from IMDB", status)
|
||||
return fmt.Errorf("Status Code %d received from OMDb", status)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ func TestNoKey(t *testing.T) {
|
|||
t.Errorf("Expected to fail")
|
||||
}
|
||||
if err != nil {
|
||||
expectedErrorMsg := "Status Code 401 received from IMDB"
|
||||
expectedErrorMsg := "Status Code 401 received from OMDb"
|
||||
if err.Error() != expectedErrorMsg {
|
||||
t.Errorf("Expected- %s, Got- %s", expectedErrorMsg, err)
|
||||
}
|
||||
|
@ -178,7 +178,7 @@ func TestMediaByImdbID(t *testing.T) {
|
|||
},
|
||||
{&QueryData{ImdbId: "tt3952222", Season: "1", SearchType: SeriesSearch},
|
||||
"Killjoys",
|
||||
"2015–",
|
||||
"2015–2019",
|
||||
},
|
||||
{&QueryData{ImdbId: "tt0944947", Season: "1", Episode: "1", SearchType: EpisodeSearch},
|
||||
"Winter Is Coming",
|
||||
|
|
Loading…
Reference in a new issue