Module: Avmtrf1::Red::Helper

Extended by:
ActiveSupport::Concern
Included in:
Client, Profile
Defined in:
lib/avmtrf1/red/helper.rb

Instance Method Summary collapse

Instance Method Details

#check_request_result(url, result) ⇒ Object


23
24
25
26
27
# File 'lib/avmtrf1/red/helper.rb', line 23

def check_request_result(url, result)
  return if result.status == 200

  raise "#{url} returned #{result.status}\n#{result.body}"
end

#http_clientObject


19
20
21
# File 'lib/avmtrf1/red/helper.rb', line 19

def http_client
  @http_client ||= ::HTTPClient.new
end

#post(url, *post_args) ⇒ Object


29
30
31
32
33
34
# File 'lib/avmtrf1/red/helper.rb', line 29

def post(url, *post_args)
  infom "Requesting \"#{url}\""
  res = http_client.post(url, *post_args)
  check_request_result(url, res)
  res.body
end

#post_xml(url_suffix, xml_body) ⇒ Object


36
37
38
39
# File 'lib/avmtrf1/red/helper.rb', line 36

def post_xml(url_suffix, xml_body)
  url = server.resource_url(url_suffix)
  ::Nokogiri::XML(post(url, xml_body))
end

#xml_content(name) ⇒ Object


41
42
43
# File 'lib/avmtrf1/red/helper.rb', line 41

def xml_content(name)
  ::ERB.new(::File.read(xml_path(name))).result(binding)
end

#xml_path(name) ⇒ Object


45
46
47
# File 'lib/avmtrf1/red/helper.rb', line 45

def xml_path(name)
  ::File.join(__dir__, self.class.name.demodulize.underscore, "#{name}.xml.erb")
end