Sha256: 3fa8458164cdbec34c48964cd6aafa9b8c18b52d04a2914336199d6486797ed3

Contents?: true

Size: 741 Bytes

Versions: 1

Compression:

Stored size: 741 Bytes

Contents

module Fandango
  module MoviesNear

    module_function

    def call(postal_code)
      response = request(postal_code)
      raise BadResponse.new(response) unless response.status.first == '200'

      xml = response.read
      Parser.(xml)
    end

    def request(postal_code)
      cleaned_postal_code = postal_code.to_s.gsub(' ', '')
      url_for_postal_code = "http://www.fandango.com/rss/moviesnearme_#{cleaned_postal_code}.rss"
      open(url_for_postal_code)
    end

    module Parser

      module_function

      def call(xml)
        doc = Nokogiri.XML(xml)
        doc.css('item').map do |item_node|
          Theater.parse(item_node)
        end
      end

    end

    class BadResponse < API::BadResponse; end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fandango-2.0.0 lib/fandango/api/movies_near.rb