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| URI.escape(options[:params][s], URI_ESCAPE_REGEX) || 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