hostconnect 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. data/CHANGELOG +8 -0
  2. data/MIT-LICENSE +22 -0
  3. data/README.markdown +16 -0
  4. data/Rakefile +48 -0
  5. data/hostconnect.gemspec +44 -0
  6. data/lib/hostconnect/builder.rb +50 -0
  7. data/lib/hostconnect/builders/add_service_builder.rb +60 -0
  8. data/lib/hostconnect/builders/agent_info_builder.rb +19 -0
  9. data/lib/hostconnect/builders/get_booking_builder.rb +24 -0
  10. data/lib/hostconnect/builders/get_booking_payment_summary_builder.rb +20 -0
  11. data/lib/hostconnect/builders/get_locations_builder.rb +18 -0
  12. data/lib/hostconnect/builders/get_services_builder.rb +18 -0
  13. data/lib/hostconnect/builders/get_system_settings_builder.rb +18 -0
  14. data/lib/hostconnect/builders/list_bookings_builder.rb +27 -0
  15. data/lib/hostconnect/builders/new_booking_info_builder.rb +23 -0
  16. data/lib/hostconnect/builders/option_info_builder.rb +49 -0
  17. data/lib/hostconnect/builders/pax_details_builder.rb +21 -0
  18. data/lib/hostconnect/builders/ping_builder.rb +11 -0
  19. data/lib/hostconnect/builders/record_booking_payment_builder.rb +25 -0
  20. data/lib/hostconnect/builders/room_config_builder.rb +25 -0
  21. data/lib/hostconnect/builders/service_line_note_builder.rb +17 -0
  22. data/lib/hostconnect/builders/suppler_info_builder.rb +27 -0
  23. data/lib/hostconnect/client.rb +32 -0
  24. data/lib/hostconnect/coercion.rb +50 -0
  25. data/lib/hostconnect/core_extensions/string.rb +18 -0
  26. data/lib/hostconnect/core_extensions/symbol.rb +9 -0
  27. data/lib/hostconnect/response.rb +119 -0
  28. data/lib/hostconnect/responses/add_service.rb +4 -0
  29. data/lib/hostconnect/responses/agent_info.rb +7 -0
  30. data/lib/hostconnect/responses/get_booking.rb +20 -0
  31. data/lib/hostconnect/responses/get_booking_payment_summary.rb +21 -0
  32. data/lib/hostconnect/responses/get_locations.rb +21 -0
  33. data/lib/hostconnect/responses/get_services.rb +21 -0
  34. data/lib/hostconnect/responses/get_system_settings.rb +24 -0
  35. data/lib/hostconnect/responses/list_bookings.rb +14 -0
  36. data/lib/hostconnect/responses/option_info.rb +60 -0
  37. data/lib/hostconnect/responses/ping.rb +7 -0
  38. data/lib/hostconnect/responses/record_booking_payment.rb +4 -0
  39. data/lib/hostconnect/responses/supplier_info.rb +31 -0
  40. data/lib/hostconnect/rtf_document.rb +19 -0
  41. data/lib/hostconnect/translation.rb +22 -0
  42. data/lib/hostconnect.rb +58 -0
  43. data/spec/builders/add_service_builder_spec.rb +36 -0
  44. data/spec/builders/agent_info_builder_spec.rb +13 -0
  45. data/spec/builders/get_locations_builder_spec.rb +13 -0
  46. data/spec/builders/new_booking_info_builder_spec.rb +34 -0
  47. data/spec/builders/option_info_builder_spec.rb +48 -0
  48. data/spec/builders/pax_details_builder_spec.rb +41 -0
  49. data/spec/builders/ping_builder_spec.rb +23 -0
  50. data/spec/builders/room_config_builder_spec.rb +60 -0
  51. data/spec/client_spec.rb +20 -0
  52. data/spec/coercion_spec.rb +85 -0
  53. data/spec/core_extensions_spec.rb +17 -0
  54. data/spec/fixtures/requests/add_service_request/hotel_booking.xml +42 -0
  55. data/spec/fixtures/requests/agent_info.xml +8 -0
  56. data/spec/fixtures/requests/get_locations.xml +8 -0
  57. data/spec/fixtures/requests/option_info/hotel_search.xml +11 -0
  58. data/spec/fixtures/requests/option_info/hotel_search_total_stay_price.xml +18 -0
  59. data/spec/fixtures/requests/option_info/option_number.xml +10 -0
  60. data/spec/fixtures/requests/ping.xml +5 -0
  61. data/spec/fixtures/responses/add_service.xml +11 -0
  62. data/spec/fixtures/responses/agent_info.xml +12 -0
  63. data/spec/fixtures/responses/agent_info_error.xml +7 -0
  64. data/spec/fixtures/responses/get_booking.xml +40 -0
  65. data/spec/fixtures/responses/get_locations.xml +48 -0
  66. data/spec/fixtures/responses/get_system_settings.xml +28 -0
  67. data/spec/fixtures/responses/option_info/hotel_price.xml +17 -0
  68. data/spec/fixtures/responses/option_info/hotel_search.xml +721 -0
  69. data/spec/fixtures/responses/option_info/hotel_search_with_stay_price.xml +470 -0
  70. data/spec/fixtures/responses/option_info/option_number.xml +14 -0
  71. data/spec/fixtures/responses/option_info/tours.xml +74 -0
  72. data/spec/fixtures/responses/ping.xml +8 -0
  73. data/spec/responses/add_service_spec.rb +13 -0
  74. data/spec/responses/agent_info_spec.rb +24 -0
  75. data/spec/responses/get_booking_spec.rb +33 -0
  76. data/spec/responses/get_locations_spec.rb +29 -0
  77. data/spec/responses/get_system_settings_spec.rb +21 -0
  78. data/spec/responses/option_info_spec.rb +48 -0
  79. data/spec/responses/ping_spec.rb +22 -0
  80. data/spec/spec_helper.rb +13 -0
  81. data/spec/translation_spec.rb +18 -0
  82. metadata +259 -0
data/CHANGELOG ADDED
@@ -0,0 +1,8 @@
1
+ v0.1.7 Updated copyright information
2
+ v0.1.6 Correct handling of prices
3
+ v0.1.5 Fixed floating point bug
4
+ v0.1.4 Additional features
5
+ v0.1.3 Bugfixes
6
+ v0.1.2 Minor revision
7
+ v0.1.1 Minor revision
8
+ v0.1.0 Test release
data/MIT-LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2007-2010 Bjørn Arild Mæland
2
+
3
+ Permission is hereby granted, free of charge, to any person
4
+ obtaining a copy of this software and associated documentation
5
+ files (the "Software"), to deal in the Software without
6
+ restriction, including without limitation the rights to use,
7
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the
9
+ Software is furnished to do so, subject to the following
10
+ conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
data/README.markdown ADDED
@@ -0,0 +1,16 @@
1
+ # Library for connecting to hostConnect
2
+
3
+ ## Notes
4
+ * All variables passing in/out of hostConnect via XML are written in CapitalCamelCase.
5
+ We, however, use snake_case for all parameters/attributes.
6
+ * Variables that are to be defined zero or more times, should be passed in as an array.
7
+ For example ":opt => ['LONAC????????????', 'MAN??????????????']"
8
+ * For requests that return multiple results (i.e OptionInfo), we supply a size method to
9
+ display the number of results.
10
+
11
+ ## Dev docs
12
+ * hostConnect API doc: http://www.tourplan.com/support/Connector/hostConnect_2_04_170.html
13
+ * Builder: http://builder.rubyforge.org/
14
+
15
+ ## License
16
+ Copyright (c) 2007-2010 Bjørn Arild Mæland. See MIT-LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,48 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
3
+
4
+ require 'rubygems'
5
+ require 'rake'
6
+ require 'spec/rake/spectask'
7
+ require 'rake/rdoctask'
8
+ require 'echoe'
9
+
10
+ PROJECT = 'hostconnect'
11
+
12
+ Echoe.new(PROJECT) do |p|
13
+ p.author = "Bjørn Arild Mæland"
14
+ p.summary = "Library for interfacing with Tourplan's hostConnect software,
15
+ which is a web service interface for tour booking."
16
+ p.url = "http://www.github.com/Chrononaut/hostconnect/"
17
+ p.dependencies = ["activesupport", "hpricot", "builder", "rtf"]
18
+ p.ignore_pattern = FileList[".gitignore"]
19
+ p.include_rakefile = true
20
+ end
21
+
22
+ task :default => 'spec'
23
+
24
+ desc "Run specifications"
25
+ Spec::Rake::SpecTask.new('spec') do |t|
26
+ t.spec_opts = ["--format", "specdoc", "--colour"]
27
+ t.spec_files = FileList[(ENV['FILES'] || 'spec/**/*_spec.rb')]
28
+ unless ENV["NO_RCOV"]
29
+ #t.rcov = true
30
+ t.rcov_opts = ['--exclude', 'spec']
31
+ end
32
+ end
33
+
34
+ desc "Create spec docs"
35
+ Spec::Rake::SpecTask.new('spec_docs') do |t|
36
+ t.spec_opts = ["--format", "html:spec_docs.html"]
37
+ t.spec_files = FileList[(ENV['FILES'] || 'spec/**/*_spec.rb')]
38
+ end
39
+
40
+ DOCUMENTED_FILES = FileList['README.markdown', 'MIT-LICENSE', 'lib/**/*.rb']
41
+
42
+ desc "Generate Documentation"
43
+ Rake::RDocTask.new do |rdoc|
44
+ rdoc.rdoc_dir = 'doc'
45
+ rdoc.title = "HostConnect"
46
+ rdoc.options << '--line-numbers' << '--inline-source' << '--main' << 'README.markdown'
47
+ rdoc.rdoc_files.include(*DOCUMENTED_FILES)
48
+ end
@@ -0,0 +1,44 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{hostconnect}
5
+ s.version = "0.1.7"
6
+ s.authors = ["Bjørn Arild Mæland"]
7
+ s.date = %q{2008-12-02}
8
+ s.description = %q{Library for interfacing with Tourplan's hostConnect software, which is a web service interface for tour booking.}
9
+ s.email = %q{bjorn.maeland@gmail.com}
10
+ s.extra_rdoc_files = ["README.markdown", "CHANGELOG", "lib/hostconnect.rb", "lib/hostconnect/builders/agent_info_builder.rb", "lib/hostconnect/builders/pax_details_builder.rb", "lib/hostconnect/builders/record_booking_payment_builder.rb", "lib/hostconnect/builders/add_service_builder.rb", "lib/hostconnect/builders/room_config_builder.rb", "lib/hostconnect/builders/get_booking_builder.rb", "lib/hostconnect/builders/get_services_builder.rb", "lib/hostconnect/builders/get_system_settings_builder.rb", "lib/hostconnect/builders/get_locations_builder.rb", "lib/hostconnect/builders/new_booking_info_builder.rb", "lib/hostconnect/builders/suppler_info_builder.rb", "lib/hostconnect/builders/list_bookings_builder.rb", "lib/hostconnect/builders/option_info_builder.rb", "lib/hostconnect/builders/get_booking_payment_summary_builder.rb", "lib/hostconnect/builders/service_line_note_builder.rb", "lib/hostconnect/builders/ping_builder.rb", "lib/hostconnect/coercion.rb", "lib/hostconnect/core_extensions/string.rb", "lib/hostconnect/core_extensions/symbol.rb", "lib/hostconnect/translation.rb", "lib/hostconnect/responses/agent_info.rb", "lib/hostconnect/responses/get_services.rb", "lib/hostconnect/responses/list_bookings.rb", "lib/hostconnect/responses/get_locations.rb", "lib/hostconnect/responses/get_booking.rb", "lib/hostconnect/responses/record_booking_payment.rb", "lib/hostconnect/responses/option_info.rb", "lib/hostconnect/responses/get_booking_payment_summary.rb", "lib/hostconnect/responses/add_service.rb", "lib/hostconnect/responses/supplier_info.rb", "lib/hostconnect/responses/get_system_settings.rb", "lib/hostconnect/responses/ping.rb", "lib/hostconnect/rtf_document.rb", "lib/hostconnect/builder.rb", "lib/hostconnect/client.rb", "lib/hostconnect/response.rb"]
11
+ s.files = ["Rakefile", "README.markdown", "CHANGELOG", "hostconnect.gemspec", "lib/hostconnect.rb", "lib/hostconnect/builders/agent_info_builder.rb", "lib/hostconnect/builders/pax_details_builder.rb", "lib/hostconnect/builders/record_booking_payment_builder.rb", "lib/hostconnect/builders/add_service_builder.rb", "lib/hostconnect/builders/room_config_builder.rb", "lib/hostconnect/builders/get_booking_builder.rb", "lib/hostconnect/builders/get_services_builder.rb", "lib/hostconnect/builders/get_system_settings_builder.rb", "lib/hostconnect/builders/get_locations_builder.rb", "lib/hostconnect/builders/new_booking_info_builder.rb", "lib/hostconnect/builders/suppler_info_builder.rb", "lib/hostconnect/builders/list_bookings_builder.rb", "lib/hostconnect/builders/option_info_builder.rb", "lib/hostconnect/builders/get_booking_payment_summary_builder.rb", "lib/hostconnect/builders/service_line_note_builder.rb", "lib/hostconnect/builders/ping_builder.rb", "lib/hostconnect/coercion.rb", "lib/hostconnect/core_extensions/string.rb", "lib/hostconnect/core_extensions/symbol.rb", "lib/hostconnect/translation.rb", "lib/hostconnect/responses/agent_info.rb", "lib/hostconnect/responses/get_services.rb", "lib/hostconnect/responses/list_bookings.rb", "lib/hostconnect/responses/get_locations.rb", "lib/hostconnect/responses/get_booking.rb", "lib/hostconnect/responses/record_booking_payment.rb", "lib/hostconnect/responses/option_info.rb", "lib/hostconnect/responses/get_booking_payment_summary.rb", "lib/hostconnect/responses/add_service.rb", "lib/hostconnect/responses/supplier_info.rb", "lib/hostconnect/responses/get_system_settings.rb", "lib/hostconnect/responses/ping.rb", "lib/hostconnect/rtf_document.rb", "lib/hostconnect/builder.rb", "lib/hostconnect/client.rb", "lib/hostconnect/response.rb", "MIT-LICENSE", "spec/builders/new_booking_info_builder_spec.rb", "spec/builders/ping_builder_spec.rb", "spec/builders/get_locations_builder_spec.rb", "spec/builders/add_service_builder_spec.rb", "spec/builders/room_config_builder_spec.rb", "spec/builders/option_info_builder_spec.rb", "spec/builders/agent_info_builder_spec.rb", "spec/builders/pax_details_builder_spec.rb", "spec/spec_helper.rb", "spec/fixtures/requests/ping.xml", "spec/fixtures/requests/agent_info.xml", "spec/fixtures/requests/option_info/hotel_search_total_stay_price.xml", "spec/fixtures/requests/option_info/option_number.xml", "spec/fixtures/requests/option_info/hotel_search.xml", "spec/fixtures/requests/get_locations.xml", "spec/fixtures/requests/add_service_request/hotel_booking.xml", "spec/fixtures/responses/ping.xml", "spec/fixtures/responses/agent_info.xml", "spec/fixtures/responses/agent_info_error.xml", "spec/fixtures/responses/get_booking.xml", "spec/fixtures/responses/option_info/tours.xml", "spec/fixtures/responses/option_info/hotel_search_with_stay_price.xml", "spec/fixtures/responses/option_info/option_number.xml", "spec/fixtures/responses/option_info/hotel_price.xml", "spec/fixtures/responses/option_info/hotel_search.xml", "spec/fixtures/responses/get_system_settings.xml", "spec/fixtures/responses/add_service.xml", "spec/fixtures/responses/get_locations.xml", "spec/client_spec.rb", "spec/core_extensions_spec.rb", "spec/responses/get_booking_spec.rb", "spec/responses/get_system_settings_spec.rb", "spec/responses/agent_info_spec.rb", "spec/responses/option_info_spec.rb", "spec/responses/add_service_spec.rb", "spec/responses/ping_spec.rb", "spec/responses/get_locations_spec.rb", "spec/translation_spec.rb", "spec/coercion_spec.rb"]
12
+ s.has_rdoc = true
13
+ s.homepage = %q{http://www.github.com/bmaland/hostconnect/}
14
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Hostconnect", "--main", "README.markdown"]
15
+ s.require_paths = ["lib"]
16
+ s.rubyforge_project = %q{hostconnect}
17
+ s.rubygems_version = %q{1.3.1}
18
+ s.summary = %q{Library for interfacing with Tourplan's hostConnect software, which is a web service interface for tour booking.}
19
+
20
+ if s.respond_to? :specification_version then
21
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
22
+ s.specification_version = 2
23
+
24
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
25
+ s.add_runtime_dependency(%q<activesupport>, [">= 0"])
26
+ s.add_runtime_dependency(%q<hpricot>, [">= 0"])
27
+ s.add_runtime_dependency(%q<builder>, [">= 0"])
28
+ s.add_runtime_dependency(%q<rtf>, [">= 0"])
29
+ s.add_development_dependency(%q<echoe>, [">= 0"])
30
+ else
31
+ s.add_dependency(%q<activesupport>, [">= 0"])
32
+ s.add_dependency(%q<hpricot>, [">= 0"])
33
+ s.add_dependency(%q<builder>, [">= 0"])
34
+ s.add_dependency(%q<rtf>, [">= 0"])
35
+ s.add_dependency(%q<echoe>, [">= 0"])
36
+ end
37
+ else
38
+ s.add_dependency(%q<activesupport>, [">= 0"])
39
+ s.add_dependency(%q<hpricot>, [">= 0"])
40
+ s.add_dependency(%q<builder>, [">= 0"])
41
+ s.add_dependency(%q<rtf>, [">= 0"])
42
+ s.add_dependency(%q<echoe>, [">= 0"])
43
+ end
44
+ end
@@ -0,0 +1,50 @@
1
+ module HostConnect
2
+ # Abstract class which all the different builder-classes inherit from. The builders are
3
+ # used to produce valid XML requests, which are to be sent to the HostConnect server.
4
+ class AbstractBuilder
5
+ # String representation of self
6
+ def to_s
7
+ to_xml.target!
8
+ end
9
+
10
+ # Send xml to server. Returns a new object.
11
+ def submit
12
+ obj = ActiveSupport::Inflector.constantize(self.class.to_s.gsub(/Builder/, ''))
13
+ obj.new(Client.post_xml_request(to_s))
14
+ end
15
+
16
+ protected
17
+ # Returns a bare xml-builder object, containing just dtd, xml version and encoding
18
+ def bare
19
+ x = Builder::XmlMarkup.new(:indent => 2)
20
+ x.instruct!
21
+ x.declare! :DOCTYPE, :Request, :SYSTEM, HostConnect.config.dtd
22
+ x
23
+ end
24
+
25
+ private
26
+ def initialize(options = {})
27
+ @options = options
28
+ check_for_valid_options
29
+ set_attrs
30
+ end
31
+
32
+ def check_for_valid_options
33
+ @options.each_key do |k|
34
+ raise("No such option: #{k}") unless @valid_options.include?(k)
35
+ end
36
+ end
37
+
38
+ def set_attrs
39
+ @options.each do |k,v|
40
+ instance_variable_set("@#{k}", v)
41
+ end
42
+
43
+ # It should be possible to set all options after the objects creation,
44
+ # from it's accessors
45
+ unless @valid_options.blank?
46
+ @valid_options.each { |k| self.class.class_eval "attr_accessor :#{k}" }
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,60 @@
1
+ module HostConnect
2
+ # A booking is built up service by service. Each AddService request adds one
3
+ # service to a (new or existing) booking. Note that for a service to be added
4
+ # to an existing booking the agent adding the service must be the same as the
5
+ # agent who made the original booking.
6
+ class AddServiceBuilder < AbstractBuilder
7
+ def initialize(options = {})
8
+ @valid_options = [ :agent_id, :password, :new_booking_info, :opt, :date_from,
9
+ :scu_qty, :room_configs, :email, :pu_time, :pu_remark,
10
+ :do_time, :do_remark, :remarks, :ud_text1, :ud_text2,
11
+ :ud_text3, :ud_text4, :ud_text5, :agent_ref,
12
+ :service_line_notes ].freeze
13
+ super(options)
14
+ end
15
+
16
+ def to_xml
17
+ x = bare
18
+ x.Request {
19
+ x.AddServiceRequest { |i|
20
+ x.AgentID @agent_id
21
+ x.Password @password
22
+
23
+ if @new_booking_info
24
+ i << @new_booking_info.to_xml.target!
25
+ end
26
+
27
+ if @room_configs
28
+ # Stack the room configs onto the request
29
+ x.RoomConfigs { |i|
30
+ @room_configs.each { |room| i << room.to_xml.target! }
31
+ }
32
+ end
33
+
34
+ if @service_line_notes
35
+ x.ServiceLineNotes { |i|
36
+ @service_line_notes.each { |note| i << note.to_xml.target! }
37
+ }
38
+ end
39
+
40
+ x.Opt @opt if @opt
41
+ x.DateFrom @date_from if @date_from
42
+ x.SCUqty @scu_qty if @scu_qty
43
+ x.Email @email if @email
44
+ x.AgentRef @agent_ref if @agent_ref
45
+ x.puTime @pu_time if @pu_time
46
+ x.puRemark @pu_remark if @pu_remark
47
+ x.doTime @do_time if @do_time
48
+ x.doRemark @do_remark if @do_remark
49
+ x.Remarks @remarks if @remarks
50
+ x.UDText1 @ud_text1 if @ud_text1
51
+ x.UDText2 @ud_text2 if @ud_text2
52
+ x.UDText3 @ud_text3 if @ud_text3
53
+ x.UDText4 Coercion.to_hc(@ud_text4) unless @ud_text4.nil?
54
+ x.UDText5 @ud_text5 if @ud_text5
55
+ }
56
+ }
57
+ x
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,19 @@
1
+ module HostConnect
2
+ # The AgentInfo request returns information about the specified agent (and as with other
3
+ # requests that require AgentID and Password an error is reported if the
4
+ # AgentID / Password combination is invalid).
5
+ class AgentInfoBuilder < AbstractBuilder
6
+ def initialize(options = {})
7
+ @valid_options = [ :agent_id, :password ].freeze
8
+ super(options)
9
+ end
10
+
11
+ def to_xml
12
+ x = bare
13
+ x.Request {
14
+ x.AgentInfoRequest { x.AgentID @agent_id; x.Password @password }
15
+ }
16
+ x
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,24 @@
1
+ module HostConnect
2
+ # This request retrieves a booking. Note that for a booking to be retrieved
3
+ # successfully the agent requesting the booking must be the same as the agent
4
+ # who made the booking.
5
+ class GetBookingBuilder < AbstractBuilder
6
+ def initialize(options = {})
7
+ @valid_options = [ :agent_id, :password, :booking_id, :ref ].freeze
8
+ super(options)
9
+ end
10
+
11
+ def to_xml
12
+ x = bare
13
+ x.Request {
14
+ x.GetBookingRequest {
15
+ x.AgentID @agent_id
16
+ x.Password @password
17
+ x.BookingId @booking_id if @booking_id
18
+ x.Ref @ref if @ref
19
+ }
20
+ }
21
+ x
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,20 @@
1
+ module HostConnect
2
+ class GetBookingPaymentSummaryBuilder < AbstractBuilder
3
+ def initialize(options = {})
4
+ @valid_options = [ :agent_id, :password, :booking_id ].freeze
5
+ super(options)
6
+ end
7
+
8
+ def to_xml
9
+ x = bare
10
+ x.Request {
11
+ x.GetBookingPaymentSummaryRequest {
12
+ x.AgentID @agent_id
13
+ x.Password @password
14
+ x.BookingId @booking_id
15
+ }
16
+ }
17
+ x
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,18 @@
1
+ module HostConnect
2
+ # The GetLocations request returns a list of all location codes and names used
3
+ # in the system. Note that each Opt option identifier contains a location code.
4
+ class GetLocationsBuilder < AbstractBuilder
5
+ def initialize(options = {})
6
+ @valid_options = [ :agent_id, :password ].freeze
7
+ super(options)
8
+ end
9
+
10
+ def to_xml
11
+ x = bare
12
+ x.Request {
13
+ x.GetLocationsRequest { x.AgentID @agent_id; x.Password @password }
14
+ }
15
+ x
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ module HostConnect
2
+ # The GetServices request returns a list of all service codes and names used
3
+ # in the system. Note that each Opt option identifier contains a service code.
4
+ class GetServicesBuilder < AbstractBuilder
5
+ def initialize(options = {})
6
+ @valid_options = [ :agent_id, :password ].freeze
7
+ super(options)
8
+ end
9
+
10
+ def to_xml
11
+ x = bare
12
+ x.Request {
13
+ x.GetServicesRequest { x.AgentID @agent_id; x.Password @password }
14
+ }
15
+ x
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ module HostConnect
2
+ # The GetSystemSettings request returns information about the overall system
3
+ # settings.
4
+ class GetSystemSettingsBuilder < AbstractBuilder
5
+ def initialize(options = {})
6
+ @valid_options = [ :agent_id, :password ].freeze
7
+ super(options)
8
+ end
9
+
10
+ def to_xml
11
+ x = bare
12
+ x.Request {
13
+ x.GetSystemSettingsRequest { x.AgentID @agent_id; x.Password @password }
14
+ }
15
+ x
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,27 @@
1
+ module HostConnect
2
+ # The ListBookings request returns header-level details of zero or
3
+ # more bookings made by the specifed agent, and that meet all of the
4
+ # criteria specified. If a sub-login is supplied then only details of
5
+ # bookings associated with that sub-login are returned.
6
+ class ListBookingsBuilder < AbstractBuilder
7
+ def initialize(options = {})
8
+ @valid_options = [ :agent_id, :password, :travel_date_from, :travel_date_to,
9
+ :entered_date_from, :entered_date_to, :name_contains,
10
+ :agent_ref ].freeze
11
+ super(options)
12
+ end
13
+
14
+ def to_xml
15
+ x = bare
16
+ x.Request {
17
+ x.ListBookingsRequest {
18
+ @valid_options.each do |opt|
19
+ val = eval "#{opt}"
20
+ eval "x.#{opt.camelize.requestify} #{opt}" unless val.blank?
21
+ end
22
+ }
23
+ }
24
+ x
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,23 @@
1
+ module HostConnect
2
+ class NewBookingInfoBuilder < AbstractBuilder
3
+ def initialize(options = {})
4
+ @valid_options = [ :name, :qb, :branch, :department,
5
+ :sales_analysis1, :sales_analysis2, :sales_analysis3 ].freeze
6
+ super(options)
7
+ end
8
+
9
+ def to_xml
10
+ x = Builder::XmlMarkup.new(:indent => 2, :margin => 2)
11
+ x.NewBookingInfo {
12
+ x.Name @name
13
+ x.QB @qb
14
+ x.Branch @branch if @branch
15
+ x.Department @department if @department
16
+ x.SalesAnalysis1 @sales_analysis1 if @sales_analysis1
17
+ x.SalesAnalysis2 @sales_analysis2 if @sales_analysis2
18
+ x.SalesAnalysis3 @sales_analysis3 if @sales_analysis3
19
+ }
20
+ x
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,49 @@
1
+ module HostConnect
2
+ class OptionInfoBuilder < AbstractBuilder
3
+ def initialize(options = {})
4
+ @valid_options = [ :agent_id, :password, :opt, :option_number, :info,
5
+ :date_from, :date_to, :scu_qty, :a_cache, :rate_convert, :room_configs,
6
+ :minimum_availability, :sort_field, :ascending, :index_first_option,
7
+ :maximum_options, :note_category, :location_code, :locality_description,
8
+ :class_description, :description, :supplier_name, :rate_per_scu ].freeze
9
+ super(options)
10
+ end
11
+
12
+ def to_xml
13
+ x = bare
14
+ x.Request {
15
+ x.OptionInfoRequest {
16
+ # TODO: probably need to validate sanity of Info / RateConvert here,
17
+ # and raise exceptions if they are invalid
18
+
19
+ # Has to substract from @valid_options instead of @options, because
20
+ # we have to guarantee the order of elements.
21
+ (@valid_options - [ :room_configs, :opt, :option_number ]).each do |opt|
22
+ # Requestify turns Id into ID
23
+
24
+ # TODO: I guess this could be done with less eval usage.
25
+ # Basically, we build xml only for those options that are non-blank
26
+ val = eval "#{opt}"
27
+ eval "x.#{opt.camelize.requestify} #{opt}" unless val.blank?
28
+ end
29
+
30
+ if @opt
31
+ @opt.each { |o| x.Opt o }
32
+ end
33
+
34
+ if @option_number
35
+ @option_number.each { |o| x.OptionNumber o }
36
+ end
37
+
38
+ if @room_configs
39
+ # Stack the room configs onto the request
40
+ x.RoomConfigs { |i|
41
+ @room_configs.each { |room| i << room.to_xml.target! }
42
+ }
43
+ end
44
+ }
45
+ }
46
+ x
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,21 @@
1
+ module HostConnect
2
+ class PaxDetailsBuilder < AbstractBuilder
3
+ def initialize(options = {})
4
+ @valid_options = [ :title, :forename, :surname, :date_of_birth, :pax_type,
5
+ :pax_text1, :pax_text2, :pax_text3, :pax_text4,
6
+ :pax_text5 ].freeze
7
+ super(options)
8
+ end
9
+
10
+ def to_xml
11
+ x = Builder::XmlMarkup.new(:indent => 2, :margin => 5)
12
+ x.PaxDetails {
13
+ @valid_options.each do |opt|
14
+ val = eval "#{opt}"
15
+ eval "x.#{opt.camelize} #{opt}" unless val.blank?
16
+ end
17
+ }
18
+ x
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,11 @@
1
+ module HostConnect
2
+ # The Ping request is provided as a simple way of determining whether hostConnect is alive.
3
+ # No arguments needed.
4
+ class PingBuilder < AbstractBuilder
5
+ def to_xml
6
+ x = bare
7
+ x.Request { x.PingRequest }
8
+ x
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,25 @@
1
+ module HostConnect
2
+ class RecordBookingPaymentBuilder < AbstractBuilder
3
+ def initialize(options = {})
4
+ @valid_options = [ :agent_id, :password, :booking_id, :currency,
5
+ :amount, :receipt_type ].freeze
6
+ super(options)
7
+ end
8
+
9
+ def to_xml
10
+ x = bare
11
+ amount = (@amount.to_f * 100).to_i # Format amount for HostConnect
12
+ x.Request {
13
+ x.RecordBookingPaymentRequest {
14
+ x.AgentID @agent_id
15
+ x.Password @password
16
+ x.BookingId @booking_id
17
+ x.Currency @currency
18
+ x.Amount amount
19
+ x.ReceiptType @receipt_type
20
+ }
21
+ }
22
+ x
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,25 @@
1
+ module HostConnect
2
+ class RoomConfigBuilder < AbstractBuilder
3
+ # Room types: SG (single), TW (twin), DB (double), TR (triple), QD (quad)
4
+ def initialize(options = {})
5
+ @valid_options = [ :adults, :room_type, :pax_list ].freeze
6
+ super(options)
7
+ end
8
+
9
+ def to_xml
10
+ x = Builder::XmlMarkup.new(:indent => 2, :margin => 3)
11
+ x.RoomConfig {
12
+ x.Adults @adults if @adults
13
+ x.RoomType @room_type if @room_type
14
+
15
+ if @pax_list
16
+ # Stack the PaxDetails builder objects onto the request
17
+ x.PaxList { |i|
18
+ @pax_list.each { |pax| i << pax.to_xml.target! }
19
+ }
20
+ end
21
+ }
22
+ x
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,17 @@
1
+ module HostConnect
2
+ class ServiceLineNoteBuilder < AbstractBuilder
3
+ def initialize(options = {})
4
+ @valid_options = [ :note_category, :note_text ].freeze
5
+ super(options)
6
+ end
7
+
8
+ def to_xml
9
+ x = Builder::XmlMarkup.new(:indent => 2, :margin => 3)
10
+ x.ServiceLineNote {
11
+ x.NoteCategory @note_category
12
+ x.NoteText @note_text
13
+ }
14
+ x
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,27 @@
1
+ module HostConnect
2
+ class SupplierInfoBuilder < AbstractBuilder
3
+ def initialize(options = {})
4
+ @valid_options = [ :agent_id, :password, :supplier_code, :supplier_id ].freeze
5
+ super(options)
6
+ end
7
+
8
+ def to_xml
9
+ x = bare
10
+ x.Request {
11
+ x.SupplierInfoRequest {
12
+ x.AgentID @agent_id
13
+ x.Password @password
14
+
15
+ if @supplier_code
16
+ @supplier_code.each { |s| x.SupplierCode s }
17
+ end
18
+
19
+ if @supplier_id
20
+ @opt.each { |s| s.SupplierId s }
21
+ end
22
+ }
23
+ }
24
+ x
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,32 @@
1
+ module HostConnect
2
+ # Has the responsibility for the http connections
3
+ class Client
4
+ class << self
5
+ # Posts a new xml request to the server, returning the response body
6
+ def post_xml_request(xml)
7
+ begin
8
+ HostConnect.logger.debug "Request sent to server:\n" << xml
9
+
10
+ req = Net::HTTP::Post.new(HostConnect.config.path)
11
+ req['Content-Type'] = 'text/xml'
12
+ req['Content-Length'] = xml.size.to_s
13
+ response = http_connection.request(req, xml)
14
+
15
+ HostConnect.logger.debug "Response:\n" << response.body
16
+ rescue Exception
17
+ error_description = "Error occured while sending data to HostConnect"
18
+ HostConnect.logger.fatal "Exception thrown: " + error_description
19
+ raise Exception, error_description
20
+ ensure
21
+ http_connection.finish if http_connection.started?
22
+ end
23
+ response.body
24
+ end
25
+
26
+ # Returns the http connection
27
+ def http_connection
28
+ @@http ||= Net::HTTP.new(HostConnect.config.host, HostConnect.config.port)
29
+ end
30
+ end
31
+ end
32
+ end