class ActionKitRest::Response::Wrapper
Attributes
kind[R]
obj[R]
response[R]
Public Class Methods
new(response)
click to toggle source
# File lib/action_kit_rest/response/wrapper.rb, line 13 def initialize(response) @response = response if response.body.respond_to?(:meta) && response.body.meta @kind = :collection @obj = ActionKitRest::Response::Collection.new(response.body.meta, response.body.objects) else @kind = :object @obj = response.body end end
Public Instance Methods
[](key)
click to toggle source
Lookup an attribute from the body if hash, otherwise behave like array index. Convert any key to string before calling.
# File lib/action_kit_rest/response/wrapper.rb, line 72 def [](key) if body.is_a?(Array) body[key] else body.send(:"#{key}") end end
body()
click to toggle source
Response
raw body
# File lib/action_kit_rest/response/wrapper.rb, line 44 def body @body || response.body end
body=(value)
click to toggle source
# File lib/action_kit_rest/response/wrapper.rb, line 38 def body=(value) @body = value @env[:body] = value end
client_error?()
click to toggle source
# File lib/action_kit_rest/response/wrapper.rb, line 61 def client_error? status.to_i >= 400 && status.to_i < 500 end
collection?()
click to toggle source
# File lib/action_kit_rest/response/wrapper.rb, line 25 def collection? kind == :collection end
each(&block)
click to toggle source
Iterate over each resource inside the collection
# File lib/action_kit_rest/response/wrapper.rb, line 109 def each(&block) if collection? obj.each do |o| block.call(o) end else raise('can only iterate over collections') end end
method_missing(method_name, *args, &block)
click to toggle source
if a raw object, just delegate
Calls superclass method
# File lib/action_kit_rest/response/wrapper.rb, line 99 def method_missing(method_name, *args, &block) if object? obj.send(method_name, &block) else super end end
object?()
click to toggle source
# File lib/action_kit_rest/response/wrapper.rb, line 29 def object? kind == :object end
redirect?()
click to toggle source
# File lib/action_kit_rest/response/wrapper.rb, line 57 def redirect? status.to_i >= 300 && status.to_i < 400 end
server_error?()
click to toggle source
# File lib/action_kit_rest/response/wrapper.rb, line 65 def server_error? status.to_i >= 500 && status.to_i < 600 end
status()
click to toggle source
Response
status
# File lib/action_kit_rest/response/wrapper.rb, line 49 def status response.status end
success?()
click to toggle source
# File lib/action_kit_rest/response/wrapper.rb, line 53 def success? response.success? end
to_ary()
click to toggle source
Convert the ResponseWrapper into an Array
# File lib/action_kit_rest/response/wrapper.rb, line 94 def to_ary body.to_ary end
to_hash()
click to toggle source
Convert the ResponseWrapper into a Hash
# File lib/action_kit_rest/response/wrapper.rb, line 88 def to_hash body.to_hash end
to_s()
click to toggle source
Return response body as string
# File lib/action_kit_rest/response/wrapper.rb, line 82 def to_s body.to_s end
url()
click to toggle source
Request url
# File lib/action_kit_rest/response/wrapper.rb, line 34 def url response.env[:url].to_s end