From f60ca5c0da369c2d180b6b166f0fa3b252b363d5 Mon Sep 17 00:00:00 2001 From: Agusti Fernandez Date: Tue, 6 Sep 2016 14:49:57 -0500 Subject: [PATCH] Replace Tmdb.Movies.search/2 for Tmdb.Search to match TMDb API (#3) * Search endpoint added * delete search module from various resources * a --- lib/tmdb/collections/collections.ex | 5 ---- lib/tmdb/companies/companies.ex | 5 ---- lib/tmdb/keywords/keywords.ex | 5 ---- lib/tmdb/lists/lists.ex | 5 ---- lib/tmdb/movies/movies.ex | 5 ---- lib/tmdb/people/people.ex | 5 ---- lib/tmdb/search/search.ex | 40 +++++++++++++++++++++++++++++ 7 files changed, 40 insertions(+), 30 deletions(-) create mode 100644 lib/tmdb/search/search.ex diff --git a/lib/tmdb/collections/collections.ex b/lib/tmdb/collections/collections.ex index 0753620..a8ea522 100644 --- a/lib/tmdb/collections/collections.ex +++ b/lib/tmdb/collections/collections.ex @@ -25,11 +25,6 @@ defmodule Tmdb.Collections do ], "total_pages" => 1, "total_results" => 18} """ - def search(query, params \\ %{}) do - params = Map.merge(params, %{"query" => query}) - get!("search/collection?#{URI.encode_query(params)}").body - end - def images(id, params \\ %{}) do get!("collection/#{id}/images?#{URI.encode_query(params)}").body end diff --git a/lib/tmdb/companies/companies.ex b/lib/tmdb/companies/companies.ex index 6cbc98f..fa708cf 100644 --- a/lib/tmdb/companies/companies.ex +++ b/lib/tmdb/companies/companies.ex @@ -34,11 +34,6 @@ defmodule Tmdb.Companies do ], "total_pages" => 1, "total_results" => 3} """ - def search(query, params \\ %{}) do - params = Map.merge(params, %{"query" => query}) - get!("search/company?#{URI.encode_query(params)}").body - end - def movies(id) do get!("company/#{id}/movies?").body end diff --git a/lib/tmdb/keywords/keywords.ex b/lib/tmdb/keywords/keywords.ex index 9313839..f78c068 100644 --- a/lib/tmdb/keywords/keywords.ex +++ b/lib/tmdb/keywords/keywords.ex @@ -53,11 +53,6 @@ defmodule Tmdb.Keywords do %{"id" => 189274, "name" => "hotel fight"}], "total_pages" => 6, "total_results" => 109} """ - def search(query, params \\ %{}) do - params = Map.merge(params, %{"query" => query}) - get!("search/keyword?#{URI.encode_query(params)}").body - end - def movies(id) do get!("keyword/#{id}/movies?").body end diff --git a/lib/tmdb/lists/lists.ex b/lib/tmdb/lists/lists.ex index 9ea2810..a178f53 100644 --- a/lib/tmdb/lists/lists.ex +++ b/lib/tmdb/lists/lists.ex @@ -5,11 +5,6 @@ defmodule Tmdb.Lists do get!("list/#{id}?").body end - def search(query, params \\ %{}) do - params = Map.merge(params, %{"query" => query}) - get!("search/list?#{URI.encode_query(params)}").body - end - def item_status(list_id, movie_id) do get!("list/#{list_id}/item_status?movie_id=#{movie_id}").body end diff --git a/lib/tmdb/movies/movies.ex b/lib/tmdb/movies/movies.ex index 5105d3d..8f87a4f 100644 --- a/lib/tmdb/movies/movies.ex +++ b/lib/tmdb/movies/movies.ex @@ -25,11 +25,6 @@ defmodule Tmdb.Movies do get!("movie/popular?#{URI.encode_query(params)}&append_to_response=videos").body end - def search(query, params \\ %{}) do - params = Map.merge(params, %{"query" => query}) - get!("search/movie?#{URI.encode_query(params)}&append_to_response=videos").body - end - def similar(id, params \\ %{}) do get!("movie/#{id}/similar?#{URI.encode_query(params)}&append_to_response=videos").body end diff --git a/lib/tmdb/people/people.ex b/lib/tmdb/people/people.ex index 6c31ed0..0ef3f98 100644 --- a/lib/tmdb/people/people.ex +++ b/lib/tmdb/people/people.ex @@ -12,9 +12,4 @@ defmodule Tmdb.People do def latest(params \\ %{}) do get!("person/latest?#{URI.encode_query(params)}").body end - - def search(query, params \\ %{}) do - params = Map.merge(params, %{"query" => query}) - get!("search/person?#{URI.encode_query(params)}").body - end end diff --git a/lib/tmdb/search/search.ex b/lib/tmdb/search/search.ex new file mode 100644 index 0000000..c6d4483 --- /dev/null +++ b/lib/tmdb/search/search.ex @@ -0,0 +1,40 @@ +defmodule Tmdb.Search do + use Tmdb.Base + + def companies(query, params \\ %{}) do + search_api("company", query, params) + end + + def collections(query, params \\ %{}) do + search_api("collection", query, params) + end + + def keywords(query, params \\ %{}) do + search_api("keyword", query, params) + end + + def lists(query, params \\ %{}) do + search_api("list", query, params) + end + + def movies(query, params \\ %{}) do + search_api("movie", query, params) + end + + def multi(query, params \\ %{}) do + search_api("multi", query, params) + end + + def persons(query, params \\ %{}) do + search_api("person", query, params) + end + + def tv(query, params \\ %{}) do + search_api("tv", query, params) + end + + defp search_api(endpoint, query, params \\ %{}) do + params = Map.merge(params, %{"query" => query}) + get!("search/#{endpoint}?#{URI.encode_query(params)}").body + end +end