Permalink
Browse files

refactor method_url so that it's easier to add to the url being gener…

…ated
  • Loading branch information...
1 parent ba6907f commit 87e6d5ee58fe36255cb2f1ab7dc3fce06d97b5f6 @jduff committed Mar 11, 2011
Showing with 8 additions and 8 deletions.
  1. +8 −8 lib/tmdb_party.rb
View
@@ -19,7 +19,7 @@ def initialize(key, lang = 'en')
end
def search(query, lang = @default_lang)
- data = self.class.get(method_url('Movie.search', query, lang)).parsed_response
+ data = self.class.get(method_url('Movie.search', lang, query)).parsed_response
if data.class != Array || data.first == "Nothing found."
[]
else
@@ -28,7 +28,7 @@ def search(query, lang = @default_lang)
end
def search_person(query, lang = @default_lang)
- data = self.class.get(method_url('Person.search', query, lang)).parsed_response
+ data = self.class.get(method_url('Person.search', lang, query)).parsed_response
if data.class != Array || data.first == "Nothing found."
[]
else
@@ -37,7 +37,7 @@ def search_person(query, lang = @default_lang)
end
def imdb_lookup(imdb_id, lang = @default_lang)
- data = self.class.get(method_url('Movie.imdbLookup', imdb_id, lang)).parsed_response
+ data = self.class.get(method_url('Movie.imdbLookup', lang, imdb_id)).parsed_response
if data.class != Array || data.first == "Nothing found."
nil
else
@@ -46,17 +46,17 @@ def imdb_lookup(imdb_id, lang = @default_lang)
end
def get_info(id, lang = @default_lang)
- data = self.class.get(method_url('Movie.getInfo', id, lang)).parsed_response
+ data = self.class.get(method_url('Movie.getInfo', lang, id)).parsed_response
Movie.new(data.first, self)
end
def get_person(id, lang = @default_lang)
- data = self.class.get(method_url('Person.getInfo', id, lang)).parsed_response
+ data = self.class.get(method_url('Person.getInfo', lang, id)).parsed_response
Person.new(data.first, self)
end
def get_genres(lang = @default_lang)
- data = self.class.get(method_url('Genres.getList', nil, lang)).parsed_response
+ data = self.class.get(method_url('Genres.getList', lang)).parsed_response
data[1..-1].collect { |genre| Genre.new(genre) } # Skips the first, see spec/fixtures/genres_results.json
end
@@ -65,9 +65,9 @@ def default_path_items
['json', @api_key]
end
- def method_url(method, value, lang)
+ def method_url(method, lang, *args)
url = [method, lang, default_path_items]
- url << URI.escape(value.to_s) if value
+ url += args.collect{ |a| URI.escape(a.to_s) }
'/' + url.join('/')
end
end

0 comments on commit 87e6d5e

Please sign in to comment.