Class: Desmoservice::Post

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePost

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']
      message= "[[RequestParams]]\n      [" + error['key']
      if error.has_key?('parameter')
        message += ' / ' + error['parameter']
      end
      message += ']'
      if error.has_key?('value')
        message += ' ' + error['value']
      end
      log_handler.add_log_message(message)
    end
    if json.has_key?('log')
      log_handler.add_log_message(json['log'])
    end
  end
end