lib/fandango.rb in fandango-1.0.0 vs lib/fandango.rb in fandango-2.0.0
- old
+ new
@@ -1,50 +1,28 @@
require "fandango/version"
require 'open-uri'
require 'nokogiri'
-require 'fandango/parser'
+require 'fandango/api'
+require 'fandango/theater'
+require 'fandango/movie'
+require 'fandango/showtime'
+
module Fandango
- class << self
+ module_function
- def movies_near(postal_code)
- raise ArgumentError, "postal code cannot be blank" if postal_code.nil? || postal_code == ''
- response = request(postal_code)
- raise BadResponse.new(response) unless response.status.first == '200'
- source = response.read
- parse source
- end
-
- def request(postal_code)
- open(url_for_postal_code(postal_code))
- end
-
- # Given RSS source string, parse using Nokogiri.
- # Return hash of theaters and movies playing at each..
- def parse(source)
- Parser.parse(source)
- end
-
- private
-
- def url_for_postal_code(postal_code)
- cleaned_postal_code = clean_postal_code(postal_code)
- "http://www.fandango.com/rss/moviesnearme_#{cleaned_postal_code}.rss"
- end
-
- # Remove spaces.
- def clean_postal_code(postal_code)
- postal_code.to_s.gsub(' ', '')
- end
-
+ def movies_near(postal_code)
+ MoviesNear.(postal_code)
end
- class BadResponse < StandardError
- def initialize(response)
- super "Bad response:\n#{response.inspect}"
+ def theater_showtimes(showtimes_link_or_options)
+ if showtimes_link_or_options.is_a?(Hash)
+ TheaterShowtimes.by_id_and_date(showtimes_link_or_options)
+ else
+ TheaterShowtimes.(showtimes_link_or_options)
end
end
end