# File lib/rhc/rest/base.rb, line 9 def initialize(attrs=nil, client=nil) @attributes = (attrs || {}).stringify_keys! @attributes['messages'] ||= [] @client = client end
# File lib/rhc/rest/base.rb, line 15 def add_message(msg) messages << msg end
# File lib/rhc/rest/base.rb, line 41 def has_param?(sym, name) if l = link(sym) (l['required_params'] || []).any?{ |p| p['name'] == name} or (l['optional_params'] || []).any?{ |p| p['name'] == name} end end
# File lib/rhc/rest/base.rb, line 33 def links attributes['links'] || {} end
# File lib/rhc/rest/base.rb, line 19 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(%r:\w+/) { |s| options[:params][s] } if options[:params] method = options[:method] || link['method'] client.request(options.merge({ :url => url, :method => method, :payload => payload, })) end
# File lib/rhc/rest/base.rb, line 37 def supports?(sym) !!link(sym) end
# File lib/rhc/rest/base.rb, line 54 def debug(msg, obj=nil) client.debug("#{msg}#{obj ? " #{obj}" : ''}") if client && client.debug? end
# File lib/rhc/rest/base.rb, line 58 def debug? client && client.debug? end
# File lib/rhc/rest/base.rb, line 50 def link(sym) (links[sym.to_s] || links[sym.to_s.upcase]) end