Method: RHC::Rest::Base#rest_method

Defined in:
lib/rhc/rest/base.rb

#rest_method(link_name, payload = {}, options = {}) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/rhc/rest/base.rb', line 21

def rest_method(link_name, payload={}, options={})
  link = link(link_name)
  raise "No link defined for #{link_name}" unless link
  url = link['href']
  url = url.gsub(/:\w+/) { |s| CGI.escape(options[:params][s]) || s } if options[:params]
  method = options[:method] || link['method']

  result = client.request(options.merge({
    :url => url,
    :method => method,
    :payload => payload,
  }))
  if result.is_a?(Hash) && (result['messages'] || result['errors'])
    attributes['messages'] = Array(result['messages'])
    result = self
  end
  result
end