class Crowbar::Client::Request::Base
Base
that provides methods shared between request implementations
Attributes
attrs[RW]
request[RW]
Public Class Methods
new(attrs = {})
click to toggle source
# File lib/crowbar/client/request/base.rb, line 29 def initialize(attrs = {}) self.attrs = Hashie::Mash.new(attrs) end
Public Instance Methods
content()
click to toggle source
# File lib/crowbar/client/request/base.rb, line 37 def content @content ||= {} end
headers()
click to toggle source
# File lib/crowbar/client/request/base.rb, line 41 def headers @headers ||= { "Content-Type" => "application/json", "Accept" => "application/json" } end
params()
click to toggle source
# File lib/crowbar/client/request/base.rb, line 48 def params case method when :post [ method, content ] when :put [ method, content.to_json ] else [ method ] end end
process() { |result| ... }
click to toggle source
# File lib/crowbar/client/request/base.rb, line 67 def process result = begin request.send( *params, accept: headers["Accept"], content_type: headers["Content-Type"] ) rescue => e if e.class.superclass == RestClient::RequestFailed Hashie::Mash.new( parsed_response: { error: e.response }, code: e.http_code ) else raise e end end if block_given? yield result else result end end