Class: HotelBeds::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/hotel_beds/connection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(configuration) ⇒ Connection

Returns a new instance of Connection.



9
10
11
12
13
# File 'lib/hotel_beds/connection.rb', line 9

def initialize(configuration)
  self.configuration = configuration
  self.client = initialize_client
  freeze
end

Instance Attribute Details

#configurationObject

Returns the value of attribute configuration.



6
7
8
# File 'lib/hotel_beds/connection.rb', line 6

def configuration
  @configuration
end

Instance Method Details

#call(method:, namespace:, data:) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/hotel_beds/connection.rb', line 15

def call(method:, namespace:, data:)
  message = { namespace => {
    :@xmlns => "http://www.hotelbeds.com/schemas/2005/06/messages",
    :"@xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance",
    :"@xsi:schemaLocation" => "http://www.hotelbeds.com/schemas/2005/06/messages #{namespace}.xsd",
    :@echoToken => SecureRandom.hex[0..15],
    :Credentials => {
      User: configuration.username,
      Password: configuration.password
    }
  }.merge(data) }
  # send the call
  response = client.call(method, {
    soap_action: "",
    attributes: {
      :"xmlns:hb" => "http://axis.frontend.hydra.hotelbeds.com",
      :"xsi:type" => "xsd:string",
    },
    message: message
  })
end