Class: Echelon::UniversalStudiosOrlando

Inherits:
Object
  • Object
show all
Defined in:
lib/echelon/parks/universal_studios_orlando.rb

Defined Under Namespace

Classes: IslandsOfAdventure, Park, UniversalStudios

Constant Summary collapse

KEY =
'AndroidMobileApp'.freeze
SECRET =
'AndroidMobileAppSecretKey182014'.freeze
SHARED_HEADERS =
{
  'Accept'                          => 'application/json',
  'Accept-Language'                 => 'en-US',
  'X-UNIWebService-AppVersion'      => '1.2.1',
  'X-UNIWebService-Platform'        => 'Android',
  'X-UNIWebService-PlatformVersion' => '4.4.2',
  'X-UNIWebService-Device'          => 'samsung SM-N9005',
  'X-UNIWebService-ServiceVersion'  => '1',
  'User-Agent'                      => 'Dalvik/1.6.0 (Linux; U; Android 4.4.2; SM-N9005 Build/KOT49H)',
  'Connection'                      => 'Keep-Alive',
  'Accept-Encoding'                 => 'gzip'
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeUniversalStudiosOrlando

Returns a new instance of UniversalStudiosOrlando.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/echelon/parks/universal_studios_orlando.rb', line 27

def initialize
  uri = URI.parse('https://services.universalorlando.com/api')
  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = true
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE

  # date is always GMT, and actual GMT time, because buh?
  date = DateTime.now.strftime("%a, %d %b %Y %H:%M:%S GMT")
  digest = OpenSSL::HMAC.digest('sha256', SECRET, "#{KEY}\n#{date}\n")
  signature = Base64.encode64(digest).strip.gsub(/\=$/, "\u003d")
  params = { apikey: 'AndroidMobileApp', signature: signature }.to_json

  headers = {
    'Date'         => date,
    'Content-Type' => 'application/json; charset=UTF-8'
  }.merge(SHARED_HEADERS)

  resp = http.post(uri.path, params, headers)
  data = JSON.parse(resp.body)
  @access_token = data['Token']
  @expires_at = DateTime.parse(data['TokenExpirationString']).to_time
end

Instance Attribute Details

#access_tokenObject (readonly)

Returns the value of attribute access_token.



10
11
12
# File 'lib/echelon/parks/universal_studios_orlando.rb', line 10

def access_token
  @access_token
end

#expires_atObject (readonly)

Returns the value of attribute expires_at.



10
11
12
# File 'lib/echelon/parks/universal_studios_orlando.rb', line 10

def expires_at
  @expires_at
end

Instance Method Details

#islands_of_adventureObject



50
51
52
# File 'lib/echelon/parks/universal_studios_orlando.rb', line 50

def islands_of_adventure
  @islands_of_adventure ||= UniversalStudiosOrlando::IslandsOfAdventure.new(access_token)
end

#universal_studiosObject



54
55
56
# File 'lib/echelon/parks/universal_studios_orlando.rb', line 54

def universal_studios
  @universal_studios ||= UniversalStudiosOrlando::UniversalStudios.new(access_token)
end