Added search by type

This commit is contained in:
Agniva De Sarker 2016-06-14 22:42:01 +05:30
parent 683c3c5411
commit 58cb9dcc45
2 changed files with 13 additions and 7 deletions

View file

@ -13,13 +13,17 @@ const (
baseURL = "http://www.omdbapi.com/?"
plot = "full"
tomatoes = "true"
MovieSearch = "movie"
SeriesSearch = "series"
EpisodeSearch = "episode"
)
type QueryData struct {
Title string
Year string
ImdbId string
Type string
SearchType string
}
//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
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 {
return nil, err
}
@ -101,7 +105,7 @@ func Search(query *QueryData) (*SearchResponse, error) {
//MovieByTitle returns a MovieResult given Title
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 {
return nil, err
}
@ -156,6 +160,8 @@ func requestAPI(apiCategory string, params ...string) (resp *http.Response, err
case "search":
parameters.Add("s", params[0])
parameters.Add("y", params[1])
// TODO: validate params to only the right options
parameters.Add("type", params[2])
case "title":
parameters.Add("t", params[0])
parameters.Add("y", params[1])

View file

@ -3,7 +3,7 @@ package gomdb
import "testing"
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)
if err != nil {
t.Error(err)