# 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 46 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 38 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'] 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
# File lib/rhc/rest/base.rb, line 42 def supports?(sym) !!link(sym) end
# File lib/rhc/rest/base.rb, line 59 def debug(msg, obj=nil) client.debug("#{msg}#{obj ? " #{obj}" : ''}") if client && client.debug? end
# File lib/rhc/rest/base.rb, line 63 def debug? client && client.debug? end
# File lib/rhc/rest/base.rb, line 55 def link(sym) (links[sym.to_s] || links[sym.to_s.upcase]) end