Class: HostConnect::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/hostconnect/client.rb

Overview

Has the responsibility for the http connections

Class Method Summary collapse

Class Method Details

.http_connectionObject

Returns the http connection



27
28
29
# File 'lib/hostconnect/client.rb', line 27

def http_connection
  @@http ||= Net::HTTP.new(HostConnect.config.host, HostConnect.config.port)
end

.post_xml_request(xml) ⇒ Object

Posts a new xml request to the server, returning the response body



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/hostconnect/client.rb', line 6

def post_xml_request(xml)
  begin
    HostConnect.logger.debug "Request sent to server:\n" << xml

    req = Net::HTTP::Post.new(HostConnect.config.path)
    req['Content-Type'] = 'text/xml'
    req['Content-Length'] = xml.size.to_s
    response = http_connection.request(req, xml)

    HostConnect.logger.debug "Response:\n" << response.body
  rescue Exception
    error_description = "Error occured while sending data to HostConnect"
    HostConnect.logger.fatal "Exception thrown: " + error_description
    raise Exception, error_description
  ensure
    http_connection.finish if http_connection.started?
  end
  response.body
end