class CineworldUk::Internal::ApiResponse

@api private

Constants

DEFAULTS

@api private mixin the default hash

Public Instance Methods

cinema_detail(id) click to toggle source

Detail about a specific cinema @param [Fixnum] id the id of the cinema @return [String] JSON encoded

# File lib/cineworld_uk/internal/api_response.rb, line 24
def cinema_detail(id)
  response('cinema/detail', cinema: id)
end
cinema_list() click to toggle source

Basic cinema list of ids/names @return [String] JSON encoded

# File lib/cineworld_uk/internal/api_response.rb, line 10
def cinema_list
  response('cinema/list', full: true)
end
dates(id) click to toggle source

List of dates on which there are screening for this cinema id @param [Fixnum] id the id of the cinema @return [String] JSON encoded

# File lib/cineworld_uk/internal/api_response.rb, line 17
def dates(id)
  response('dates', cinema: id)
end
film_list() click to toggle source

List of all currently showing films @return [String] JSON encoded

# File lib/cineworld_uk/internal/api_response.rb, line 30
def film_list
  response('film/list', full: true)
end
film_list_comingsoon() click to toggle source

List of all upcoming films @return [String] JSON encoded

# File lib/cineworld_uk/internal/api_response.rb, line 36
def film_list_comingsoon
  response('film/list/comingsoon', full: true)
end
performances(cinema_id, date) click to toggle source

All screenings from a specific cinema on a specific date @param [Fixnum] cinema_id the id of the cinema @param [Date] date a single date in the future @return [String] JSON encoded

# File lib/cineworld_uk/internal/api_response.rb, line 44
def performances(cinema_id, date)
  response('performances', cinema: cinema_id,
                           date: date.strftime('%Y%m%d'))
end

Private Instance Methods

fetch(uri, limit = 10) click to toggle source
# File lib/cineworld_uk/internal/api_response.rb, line 55
def fetch(uri, limit = 10)
  fail ArgumentError, 'too many HTTP redirects' if limit == 0

  case response = Net::HTTP.get_response(URI(uri))
  when Net::HTTPSuccess then response.body
  when Net::HTTPRedirection then fetch(response['location'], limit - 1)
  else response.code
  end
end
response(path, hash) click to toggle source
# File lib/cineworld_uk/internal/api_response.rb, line 65
def response(path, hash)
  uri = URI::HTTPS.build(host:  'www.cineworld.co.uk',
                         path:  "/api/#{path}",
                         query: URI.encode_www_form(hash.merge(DEFAULTS)))
  fetch(uri)
end