Added search by type
This commit is contained in:
parent
683c3c5411
commit
58cb9dcc45
2 changed files with 13 additions and 7 deletions
12
gomdb.go
12
gomdb.go
|
@ -13,13 +13,17 @@ const (
|
||||||
baseURL = "http://www.omdbapi.com/?"
|
baseURL = "http://www.omdbapi.com/?"
|
||||||
plot = "full"
|
plot = "full"
|
||||||
tomatoes = "true"
|
tomatoes = "true"
|
||||||
|
|
||||||
|
MovieSearch = "movie"
|
||||||
|
SeriesSearch = "series"
|
||||||
|
EpisodeSearch = "episode"
|
||||||
)
|
)
|
||||||
|
|
||||||
type QueryData struct {
|
type QueryData struct {
|
||||||
Title string
|
Title string
|
||||||
Year string
|
Year string
|
||||||
ImdbId string
|
ImdbId string
|
||||||
Type string
|
SearchType string
|
||||||
}
|
}
|
||||||
|
|
||||||
//SearchResult is the type for the search results
|
//SearchResult is the type for the search results
|
||||||
|
@ -80,7 +84,7 @@ type MovieResult struct {
|
||||||
|
|
||||||
//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 Search(query *QueryData) (*SearchResponse, error) {
|
func Search(query *QueryData) (*SearchResponse, error) {
|
||||||
resp, err := requestAPI("search", query.Title, query.Year)
|
resp, err := requestAPI("search", query.Title, query.Year, query.SearchType)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -101,7 +105,7 @@ func Search(query *QueryData) (*SearchResponse, error) {
|
||||||
|
|
||||||
//MovieByTitle returns a MovieResult given Title
|
//MovieByTitle returns a MovieResult given Title
|
||||||
func MovieByTitle(query *QueryData) (*MovieResult, error) {
|
func MovieByTitle(query *QueryData) (*MovieResult, error) {
|
||||||
resp, err := requestAPI("title", query.Title, query.Year)
|
resp, err := requestAPI("title", query.Title, query.Year, query.SearchType)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -156,6 +160,8 @@ func requestAPI(apiCategory string, params ...string) (resp *http.Response, err
|
||||||
case "search":
|
case "search":
|
||||||
parameters.Add("s", params[0])
|
parameters.Add("s", params[0])
|
||||||
parameters.Add("y", params[1])
|
parameters.Add("y", params[1])
|
||||||
|
// TODO: validate params to only the right options
|
||||||
|
parameters.Add("type", params[2])
|
||||||
case "title":
|
case "title":
|
||||||
parameters.Add("t", params[0])
|
parameters.Add("t", params[0])
|
||||||
parameters.Add("y", params[1])
|
parameters.Add("y", params[1])
|
||||||
|
|
|
@ -3,7 +3,7 @@ package gomdb
|
||||||
import "testing"
|
import "testing"
|
||||||
|
|
||||||
func TestImdbSearchMovies(t *testing.T) {
|
func TestImdbSearchMovies(t *testing.T) {
|
||||||
query := &QueryData{Title: "Fight Club", Year: "1999"}
|
query := &QueryData{Title: "Fight Club", Year: "1999", SearchType: MovieSearch}
|
||||||
resp, err := Search(query)
|
resp, err := Search(query)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
|
|
Loading…
Reference in a new issue