Sha256: 64fcae25c389fcb495b207d09125c3ef73bcea8ac54ab645f04ae3b27f807b32

Contents?: true

Size: 1.37 KB

Versions: 2

Compression:

Stored size: 1.37 KB

Contents

require 'cfpropertylist'
require 'net/http'

module OdeonUk
  # Internal utility classes: Do not use
  # @api private
  module Internal
    # Utility class to make calls to the odeon website
    class ApiResponse
      # iOS app API version
      VERSION = '2.1'.freeze

      # cinemas information
      # @return [Hash] decoded response of api containing cinema details
      def all_cinemas
        parse(all_cinemas_raw)
      end

      # application initialize
      # @return [Hash] decoded response of api, mostly films
      def app_init
        parse(app_init_raw)
      end

      # showings for a film at a cinema
      # @return [Hash] decoded response of api, day split times
      def film_times(cinema_id, film_id)
        parse(film_times_raw(cinema_id, film_id))
      end

      private

      def all_cinemas_raw
        post('all-cinemas').body
      end

      def app_init_raw
        post('app-init').body
      end

      def film_times_raw(cinema_id, film_id)
        post('film-times', { s: cinema_id, m: film_id }).body
      end

      def post(path, request_body={})
        uri = URI("https://api.odeon.co.uk/#{VERSION}/api/#{path}")
        Net::HTTP.post_form(uri, request_body)
      end

      def parse(content)
        plist = CFPropertyList::List.new(data: content)
        CFPropertyList.native_types(plist.value).fetch('data', {})
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
odeon_uk-4.0.1 lib/odeon_uk/internal/api_response.rb
odeon_uk-4.0.0 lib/odeon_uk/internal/api_response.rb