Class: BookingAutomation::JSONClient

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/booking_automation/json_client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(auth_token) ⇒ JSONClient

Returns a new instance of JSONClient.



8
9
10
# File 'lib/booking_automation/json_client.rb', line 8

def initialize(auth_token)
  @auth_token = auth_token
end

Instance Attribute Details

#auth_tokenObject

Returns the value of attribute auth_token.



6
7
8
# File 'lib/booking_automation/json_client.rb', line 6

def auth_token
  @auth_token
end

Instance Method Details

#get_bookings(prop_key, options = {}) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/booking_automation/json_client.rb', line 35

def get_bookings(prop_key, options={})
  response = self.class.post(
    '/getBookings',
    body: payload(prop_key, Constants::DEFAULT_BOOKING_OPTIONS.merge(options))
  )
  parse! response
rescue Oj::ParseError
  raise Error, Constants::PARSE_ERROR_MSG
rescue APIError => e
  e.response
end

#get_propertiesObject



12
13
14
15
16
17
18
19
20
# File 'lib/booking_automation/json_client.rb', line 12

def get_properties
  response = self.class.post('/getProperties', body: authentication.to_json)
  json = parse! response
  json['getProperties']
rescue Oj::ParseError
  raise Error, Constants::PARSE_ERROR_MSG
rescue APIError => e
  e.response
end

#get_property(prop_key, options = {}) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/booking_automation/json_client.rb', line 22

def get_property(prop_key, options={})
  response = self.class.post(
    '/getProperty',
    body: payload(prop_key, Constants::DEFAULT_PROPERTY_OPTIONS.merge(options))
  )
  json = parse! response
  json['getProperty'].first
rescue Oj::ParseError
  raise Error, Constants::PARSE_ERROR_MSG
rescue APIError => e
  e.response
end