Class: Sem4rSoap::HttpConnector::ConnectorHttpClient
- Inherits:
-
Object
- Object
- Sem4rSoap::HttpConnector::ConnectorHttpClient
- Includes:
- SoapDumper
- Defined in:
- lib/sem4r_soap/http_connector.rb
Instance Method Summary collapse
-
#download(url, path_name) ⇒ Object
Downloads content at url in path_name.
-
#initialize(logger = nil) ⇒ ConnectorHttpClient
constructor
A new instance of ConnectorHttpClient.
- #logger=(log) ⇒ Object
-
#post(service_url, body, headers) ⇒ Object, ...
Must respond to :status and :body.
-
#send(service_url, soap_action, request_xml) ⇒ String
Send a soap request.
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.
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
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 |