class Beds24::JSONClient
Attributes
auth_token[RW]
Public Class Methods
new(auth_token)
click to toggle source
# File lib/beds24/json_client.rb, line 8 def initialize(auth_token) @auth_token = auth_token end
Public Instance Methods
get_bookings(prop_key, options={})
click to toggle source
# File lib/beds24/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_properties()
click to toggle source
# File lib/beds24/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={})
click to toggle source
# File lib/beds24/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
Private Instance Methods
authentication(prop_key=nil)
click to toggle source
# File lib/beds24/json_client.rb, line 49 def authentication(prop_key=nil) { authentication: { apiKey: auth_token, propKey: prop_key } } end
parse!(response)
click to toggle source
# File lib/beds24/json_client.rb, line 64 def parse!(response) json = Oj.load response.body raise APIError.new( "API Error: #{json['errorCode']} #{json['error']}", json ) if json.is_a?(Hash) && !json['error'].nil? json end
payload(prop_key=nil, options={})
click to toggle source
# File lib/beds24/json_client.rb, line 58 def payload(prop_key=nil, options={}) authentication(prop_key) .merge(options) .to_json end