Class: BadFruit::Base
- Inherits:
-
Object
- Object
- BadFruit::Base
- Defined in:
- lib/badfruit/base.rb
Constant Summary collapse
- API_VERSION =
"v1.0"
- MOVIE_DETAIL_BASE_URL =
"http://api.rottentomatoes.com/api/public/#{API_VERSION}/movies"
- LISTS_DETAIL_BASE_URL =
"http://api.rottentomatoes.com/api/public/#{API_VERSION}/lists"
Instance Attribute Summary collapse
-
#api_key ⇒ Object
Returns the value of attribute api_key.
Instance Method Summary collapse
- #get(url) ⇒ Object
- #get_lists_action(action) ⇒ Object
- #get_movie_info(movie_id, action) ⇒ Object
-
#initialize(key) ⇒ Base
constructor
A new instance of Base.
- #lists ⇒ Object
- #movies ⇒ Object
- #parse_actors_array(hash) ⇒ Object
-
#parse_movies_array(hash) ⇒ Object
Utility Methods For Parsing.
- #search_movies(name, page_limit, page) ⇒ Object
Constructor Details
#initialize(key) ⇒ Base
Returns a new instance of Base.
11 12 13 14 15 16 |
# File 'lib/badfruit/base.rb', line 11 def initialize(key) @api_key = key @@base_api_url = "http://api.rottentomatoes.com/api/public/#{API_VERSION}" @@movies_query_url = "#{@@base_api_url}/movies.json?apikey=#{@api_key}" @@lists_query_url = "#{@@base_api_url}/lists.json?apikey=#{@api_key}" end |
Instance Attribute Details
#api_key ⇒ Object
Returns the value of attribute api_key.
3 4 5 |
# File 'lib/badfruit/base.rb', line 3 def api_key @api_key end |
Instance Method Details
#get(url) ⇒ Object
57 58 59 60 61 62 63 64 65 66 |
# File 'lib/badfruit/base.rb', line 57 def get(url) data = nil puts "Getting #{url}" resp = HTTParty.get(url) if resp.code == 200 puts "Response: OK" return resp.body end end |
#get_lists_action(action) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/badfruit/base.rb', line 39 def get_lists_action(action) url = nil case action when "new_releases" url = "#{LISTS_DETAIL_BASE_URL}/dvds/new_releases.json?apikey=#{@api_key}" when "opening" url = "#{LISTS_DETAIL_BASE_URL}/movies/opening.json?apikey=#{@api_key}" when "upcoming" url = "#{LISTS_DETAIL_BASE_URL}/movies/upcoming.json?apikey=#{@api_key}" when "in_theaters" url = "#{LISTS_DETAIL_BASE_URL}/movies/in_theaters.json?apikey=#{@api_key}" else puts "Not a valid action" return end return get(url) end |
#get_movie_info(movie_id, action) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/badfruit/base.rb', line 23 def get_movie_info(movie_id, action) url = nil case action when "details" url = "#{MOVIE_DETAIL_BASE_URL}/#{movie_id}.json?apikey=#{@api_key}" when "reviews" url = "#{MOVIE_DETAIL_BASE_URL}/#{movie_id}/reviews.json?apikey=#{@api_key}" when "cast" url = "#{MOVIE_DETAIL_BASE_URL}/#{movie_id}/cast.json?apikey=#{@api_key}" else puts "Not a valid action" return end return get(url) end |
#lists ⇒ Object
9 |
# File 'lib/badfruit/base.rb', line 9 def lists(); @list || BadFruit::Lists.new(self); end |
#movies ⇒ Object
8 |
# File 'lib/badfruit/base.rb', line 8 def movies(); @movie || BadFruit::Movies.new(self); end |
#parse_actors_array(hash) ⇒ Object
77 78 79 80 81 82 83 |
# File 'lib/badfruit/base.rb', line 77 def parse_actors_array(hash) actorsArray = Array.new hash["cast"].each do |actor| actorsArray.push(Actor.new(actor)) end return actorsArray end |
#parse_movies_array(hash) ⇒ Object
Utility Methods For Parsing
69 70 71 72 73 74 75 |
# File 'lib/badfruit/base.rb', line 69 def parse_movies_array(hash) moviesArray = Array.new hash["movies"].each do |movie| moviesArray.push(Movie.new(movie, self)) end return moviesArray end |
#search_movies(name, page_limit, page) ⇒ Object
18 19 20 21 |
# File 'lib/badfruit/base.rb', line 18 def search_movies(name, page_limit, page) url = "#{@@movies_query_url}&q=#{CGI::escape(name)}&page_limit=#{page_limit}&page=#{page}" return get(url) end |