Class: Sem4rSoap::HttpConnector::ConnectorHttpClient

Inherits:
Object
  • Object
show all
Includes:
SoapDumper
Defined in:
lib/sem4r_soap/http_connector.rb

Instance Method Summary collapse

Methods included from SoapDumper

#dump_soap_options, #dump_soap_request, #dump_soap_response

Constructor Details

#initialize(logger = nil) ⇒ ConnectorHttpClient

Returns a new instance of ConnectorHttpClient.



145
146
147
# File 'lib/sem4r_soap/http_connector.rb', line 145

def initialize(logger = nil)
  @logger = logger
end

Instance Method Details

#download(url, path_name) ⇒ Object

Downloads content at url in path_name



180
181
182
183
184
185
186
187
# File 'lib/sem4r_soap/http_connector.rb', line 180

def download(url, path_name)
  client = HTTPClient.new(:agent_name => 'Ruby')
  File.open(path_name, "w") do |file|
    client.get_content(url) do |chunk|
      file.write chunk
    end
  end
end

#logger=(log) ⇒ Object



149
150
151
# File 'lib/sem4r_soap/http_connector.rb', line 149

def logger=(log)
  @logger = log
end

#post(service_url, body, headers) ⇒ Object, ...

Returns must respond to :status and :body.

Returns:

  • (Object, #status, #body)

    must respond to :status and :body



192
193
194
195
196
197
198
199
200
# File 'lib/sem4r_soap/http_connector.rb', line 192

def post(service_url, body, headers)
  client   = HTTPClient.new(:agent_name => 'Ruby')
  response = client.post(service_url, body, headers)
  unless response
    raise "Connection Error, Network is down?? :-((("
  end
  response.instance_eval { def body; content; end}
  response
end

#send(service_url, soap_action, request_xml) ⇒ String

Send a soap request

Returns:

  • (String)

    soap xml response

Raises:

  • (URI::InvalidURIError)

    when service_url is incorrect



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# File 'lib/sem4r_soap/http_connector.rb', line 158

def send(service_url, soap_action, request_xml)
  uri     = URI.parse(service_url)

  headers = {
      "Content-Type"   => "text/xml; charset=utf-8",
      "Content-Length" => request_xml.length.to_s,
      "SOAPAction"     => soap_action}

  @logger.info("Post to #{uri.path} (#{soap_action})") if @logger
  dump_soap_request(service_url, request_xml)
  response = post(service_url, request_xml, headers)
  unless response
    raise Sem4rError, "Connection Error"
  end
  response_xml = response.content
  dump_soap_response(service_url, response_xml)
  response_xml
end