Class: Desmoservice::Post
- Inherits:
-
Object
- Object
- Desmoservice::Post
- Defined in:
- lib/post.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ Post
constructor
A new instance of Post.
Constructor Details
#initialize ⇒ Post
Returns a new instance of Post.
6 7 |
# File 'lib/post.rb', line 6 def initialize end |
Class Method Details
.xml(desmoservice_conf, xml, http: nil, log_handler: nil) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/post.rb', line 9 def self.xml(desmoservice_conf, xml, http: nil, log_handler: nil) uri = desmoservice_conf.build_edition_uri if http.nil? response = Net::HTTP.post_form(uri, 'desmo' => desmoservice_conf.desmo_name, 'xml' => xml) response_body = response.body else request = Net::HTTP::Post.new(uri) request.set_form_data('desmo' => desmoservice_conf.desmo_name, 'xml' => xml) response =http.request(request) response_body = response.body end if not log_handler.nil? json = JSON.parse(response_body) if json.has_key?('error') error = json['error'] = "[[RequestParams]]\n [" + error['key'] if error.has_key?('parameter') += ' / ' + error['parameter'] end += ']' if error.has_key?('value') += ' ' + error['value'] end log_handler.() end if json.has_key?('log') log_handler.(json['log']) end end end |