From 28ba3ae5fc64a1ff3336ac6f564c6df80f82f224 Mon Sep 17 00:00:00 2001 From: Asara Date: Sat, 10 Sep 2022 20:22:12 -0400 Subject: [PATCH] Add go mod, rename imdb -> omdb, fix a broken test --- go.mod | 5 +++++ go.sum | 2 ++ gomdb.go | 27 +++++++++++++++------------ gomdb_test.go | 4 ++-- 4 files changed, 24 insertions(+), 14 deletions(-) create mode 100644 go.mod create mode 100644 go.sum diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..36d9de3 --- /dev/null +++ b/go.mod @@ -0,0 +1,5 @@ +module git.minhas.io/asara/gomdb + +go 1.19 + +require github.com/davecgh/go-spew v1.1.1 // indirect diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..b5e2922 --- /dev/null +++ b/go.sum @@ -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= diff --git a/gomdb.go b/gomdb.go index b50c6b4..63a2fc3 100644 --- a/gomdb.go +++ b/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" @@ -37,7 +39,7 @@ type QueryData struct { Episode string } -//SearchResult is the type for the search results +// SearchResult is the type for the search results type SearchResult struct { Title string Year string @@ -45,7 +47,7 @@ type SearchResult struct { Type string } -//SearchResponse is the struct of the response in a search +// SearchResponse is the struct of the response in a search type SearchResponse struct { Search []SearchResult Response string @@ -53,7 +55,7 @@ type SearchResponse struct { totalResults int } -//MovieResult is the result struct of an specific movie search +// MovieResult is the result struct of an specific movie search type MovieResult struct { Title string Year string @@ -93,7 +95,7 @@ type MovieResult struct { Error string } -//Search for movies given a Title and year, Year is optional you can pass nil +// Search for movies given a Title and year, Year is optional you can pass nil func (api *OmdbApi) Search(query *QueryData) (*SearchResponse, error) { resp, err := api.requestAPI("search", query.Title, query.Year, query.SearchType) if err != nil { @@ -114,7 +116,7 @@ func (api *OmdbApi) Search(query *QueryData) (*SearchResponse, error) { return r, nil } -//MovieByTitle returns a MovieResult given Title +// MovieByTitle returns a MovieResult given Title func (api *OmdbApi) MovieByTitle(query *QueryData) (*MovieResult, error) { resp, err := api.requestAPI("title", query.Title, query.Year, query.SearchType, query.Season, query.Episode) @@ -135,10 +137,11 @@ func (api *OmdbApi) MovieByTitle(query *QueryData) (*MovieResult, error) { return r, nil } -//MovieByImdbID returns a MovieResult given a ImdbID ex:"tt2015381" +// 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,17 +215,17 @@ 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 } -//Stringer Interface for MovieResult +// Stringer Interface for MovieResult func (mr MovieResult) String() string { return fmt.Sprintf("#%s: %s (%s)", mr.ImdbID, mr.Title, mr.Year) } -//Stringer Interface for SearchResult +// Stringer Interface for SearchResult func (sr SearchResult) String() string { return fmt.Sprintf("#%s: %s (%s) Type: %s", sr.ImdbID, sr.Title, sr.Year, sr.Type) } diff --git a/gomdb_test.go b/gomdb_test.go index 99744a2..507cd41 100644 --- a/gomdb_test.go +++ b/gomdb_test.go @@ -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",