module Kigo
Constants
- APIUrl
- VERSION
Attributes
configuration[RW]
Public Class Methods
access(end_point, request_method, data={}, headers={})
click to toggle source
# File lib/kigo.rb, line 35 def self.access(end_point, request_method, data={}, headers={}) request = self.wrap_request(end_point, request_method, data, headers) request.on_complete do |response| return self.parse_response(response) end hydra = Typhoeus::Hydra.new hydra.queue(request) hydra.run end
access_multiple(resources=[])
click to toggle source
# File lib/kigo.rb, line 20 def self.access_multiple(resources=[]) hydra = Typhoeus::Hydra.new request_responses = [] resources.each do |resource| request = self.wrap_request(resource[:end_point], resource[:verb], resource[:params], resource[:headers]) request.on_complete do |response| request_responses << self.parse_response(response) end hydra.queue(request) end hydra.run request_responses end
configure() { |configuration| ... }
click to toggle source
# File lib/kigo/configuration.rb, line 23 def self.configure yield(configuration) end
create_confirmed_reservation(params)
click to toggle source
# File lib/kigo.rb, line 90 def self.create_confirmed_reservation(params) # params example: # { # "PROP_ID" => 1434, # "RES_CHECK_IN" => "2011-07-21", # "RES_CHECK_OUT" => "2011-07-26", # "RES_N_ADULTS" => 2, # "RES_N_CHILDREN" => 1, # "RES_N_BABIES" => 0, # "RES_GUEST" => { # "RES_GUEST_FIRSTNAME" => "Robert", # "RES_GUEST_LASTNAME" => "Roquefort", # "RES_GUEST_EMAIL" => "robert@yahoo.co.uk", # "RES_GUEST_PHONE" => "", # "RES_GUEST_COUNTRY" => "GB" # }, # "RES_COMMENT" => "", # "RES_COMMENT_GUEST" => "", # "RES_UDRA" => [ # { # "UDRA_ID" => 161, # "UDRA_CHOICE_ID" => 199 # }, # { # "UDRA_ID" => 162, # "UDRA_TEXT" => "John Smith told me about you!" # } # ] # } self.access('/createConfirmedReservation', :post, params) end
diff_property_calendar_reservations(diff_id = nil)
click to toggle source
Reservations
# File lib/kigo.rb, line 86 def self.diff_property_calendar_reservations(diff_id = nil) self.access('/diffPropertyCalendarReservations', :post, { 'DIFF_ID' => diff_id }) end
diff_property_pricing_setup(diff_id = nil)
click to toggle source
# File lib/kigo.rb, line 148 def self.diff_property_pricing_setup(diff_id = nil) self.access('/diffPropertyPricingSetup', :post, { 'DIFF_ID' => diff_id }) end
filter_array_params(array)
click to toggle source
# File lib/kigo.rb, line 76 def self.filter_array_params(array) return array.map { |a| a.is_a?(Hash) ? self.filter_params(a) : a } end
filter_params(hash)
click to toggle source
# File lib/kigo.rb, line 58 def self.filter_params(hash) filtered_attr = {} hash.each do |param_name, value| if value.is_a? Hash filtered_attr = filtered_attr.merge(param_name => filter_params(value)) elsif value.is_a? Array filtered_attr = filtered_attr.merge(param_name => filter_array_params(value)) else if value.class == ActionDispatch::Http::UploadedFile filtered_attr = filtered_attr.merge(param_name => value.tempfile) else filtered_attr = filtered_attr.merge(param_name => value) end end end return filtered_attr end
list_properties()
click to toggle source
Properties
# File lib/kigo.rb, line 123 def self.list_properties self.access('/listProperties', :post, nil) end
list_properties_2()
click to toggle source
# File lib/kigo.rb, line 127 def self.list_properties_2 self.access('/listProperties2', :post, nil) end
parse_response(response)
click to toggle source
# File lib/kigo.rb, line 45 def self.parse_response(response) if response.success? begin result = JSON.parse(response.body) return result["API_RESULT_CODE"] == "E_OK" ? result["API_REPLY"] : { 'error' => "#{result["API_RESULT_CODE"]} #{result["API_RESULT_TEXT"]}" } rescue return { 'error' => "Error parsing reply" } end else return { 'error' => "Response error. #{response.code} #{response.body}" } end end
ping()
click to toggle source
# File lib/kigo.rb, line 80 def self.ping self.access('/ping', :post, {}) end
read_property(property_id)
click to toggle source
# File lib/kigo.rb, line 131 def self.read_property(property_id) self.access('/readProperty', :post, { 'PROP_ID' => property_id }) end
read_property_2(property_id)
click to toggle source
# File lib/kigo.rb, line 135 def self.read_property_2(property_id) self.access('/readProperty2', :post, { 'PROP_ID' => property_id }) end
read_property_photo_file(property_id, photo_id)
click to toggle source
# File lib/kigo.rb, line 139 def self.read_property_photo_file(property_id, photo_id) self.access("/readPropertyPhotoFile", :post, { "PROP_ID" => property_id, "PHOTO_ID" => photo_id }) end
read_property_pricing_setup(property_id)
click to toggle source
Pricing
# File lib/kigo.rb, line 144 def self.read_property_pricing_setup(property_id) self.access('/readPropertyPricingSetup', :post, { 'PROP_ID' => property_id }) end
update_property_pricing_setup(property_id, pricing)
click to toggle source
Example of pricing hash: { “RENT” => {
"PERGUEST_CHARGE" => nil, "PERIODS" => [ { "CHECK_IN" => "2014-01-01", "CHECK_OUT" => "2014-03-01", "NAME" => "Winter 2014", "STAY_MIN" => { "UNIT" => "NIGHT", "NUMBER" => 3 }, "WEEKLY" => false, "NIGHTLY_AMOUNTS" => [ { "GUESTS_FROM" => 1, "WEEK_NIGHTS" => [ 1, 2, 3, 4, 5, 6, 7 ], "STAY_FROM" => { "UNIT" => "NIGHT", "NUMBER" => 1 }, "AMOUNT" => "100.00" } ] }, { "CHECK_IN" => "2014-03-01", "CHECK_OUT" => "2014-05-31", "NAME" => "", "STAY_MIN" => { "UNIT" => "NIGHT", "NUMBER" => 7 }, "WEEKLY" => true, "WEEKLY_AMOUNTS" => [ { "GUESTS_FROM" => 1, "AMOUNT" => "650.00" } ] } ] }
}
# File lib/kigo.rb, line 183 def self.update_property_pricing_setup(property_id, pricing) self.access('/updatePropertyPricingSetup', :post, { 'PROP_ID' => property_id, 'PRICING' => pricing }) end
wrap_request(end_point, request_method, data={}, headers={})
click to toggle source
# File lib/kigo.rb, line 8 def self.wrap_request(end_point, request_method, data={}, headers={}) basic_auth = { username: Kigo.configuration.username, password: Kigo.configuration.password } encoded_auth = "Basic #{Base64.strict_encode64("#{basic_auth[:username]}:#{basic_auth[:password]}")}" data = self.filter_params(data) unless data.nil? request_options = { method: request_method, headers: headers.merge( { 'Authorization' => encoded_auth, 'Content-Type' => 'application/json' } ) } request_options = request_options.merge(request_method == :post ? { body: data.nil? ? "null" : data.to_json } : { params: data.nil? ? "null" : data.to_json }) Typhoeus::Request.new("#{APIUrl}#{end_point}", request_options) end