class BookingAutomation::XMLClient
Attributes
password[RW]
username[RW]
Public Class Methods
new(username, password)
click to toggle source
# File lib/booking_automation/xml_client.rb, line 9 def initialize(username, password) @username = username @password = password end
Public Instance Methods
get_bookings(opts = {})
click to toggle source
# File lib/booking_automation/xml_client.rb, line 21 def get_bookings(opts = {}) valid_opts = opts.slice(*Constants::VALID_XML_BOOKING_OPTS) response = self.class.post('/getBookings', body: xmlize(valid_opts)) parse! response rescue APIError => e e.response end
get_properties(opts = {})
click to toggle source
# File lib/booking_automation/xml_client.rb, line 14 def get_properties(opts = {}) response = self.class.post('/getProperties', body: xmlize(opts.slice(:propid))) parse! response rescue APIError => e e.response end
modify_booking(id, attrs = {})
click to toggle source
# File lib/booking_automation/xml_client.rb, line 29 def modify_booking(id, attrs = {}) response = self.class.post('/putBookings', body: modify_payload(id, attrs)) parse! response rescue APIError => e e.response end
Private Instance Methods
auth()
click to toggle source
# File lib/booking_automation/xml_client.rb, line 47 def auth { username: @username, password: @password } end
modify_payload(id, attrs = {})
click to toggle source
# File lib/booking_automation/xml_client.rb, line 55 def modify_payload(id, attrs = {}) payload = Nokogiri::XML(xmlize()) Nokogiri::XML::Builder.with(payload.at('request')) do |xml| xml.bookings do xml.booking(id: id, action: 'modify') do attrs.each do |prop, value| xml.public_send prop, value end end end end.doc.root.to_xml end
parse!(response)
click to toggle source
# File lib/booking_automation/xml_client.rb, line 38 def parse!(response) hash = Hash.from_xml(response.body) raise APIError.new( "API Error: #{hash['code']} #{hash['error']}", hash ) if hash.key?('error') hash end
xmlize(opts = {})
click to toggle source
# File lib/booking_automation/xml_client.rb, line 51 def xmlize(opts = {}) XMLRequest.new(auth, opts).to_xml end