A class responsible for proxing to faraday response
Compare the wrapper with other wrapper for equality
# File lib/github_api/response_wrapper.rb, line 148 def ==(other) return false unless other.is_a?(self.class) return false unless (other.respond_to?(:env) && other.respond_to?(:body)) self.env == other.env && self.body == other.body end
Lookup an attribute from the body if hash, otherwise behave like array index. Convert any key to string before calling.
# File lib/github_api/response_wrapper.rb, line 80 def [](key) if self.body.is_a?(Array) self.body[key] else self.body.send(:"#{key}") end end
Response raw body
# File lib/github_api/response_wrapper.rb, line 45 def body @body ? @body : response.body end
# File lib/github_api/response_wrapper.rb, line 38 def body=(value) @body = value @env[:body] = value end
# File lib/github_api/response_wrapper.rb, line 63 def client_error? status.to_i >= 400 && status.to_i < 500 end
Iterate over each resource inside the body
# File lib/github_api/response_wrapper.rb, line 108 def each body_parts = self.body.respond_to?(:each) ? self.body : [self.body] return body_parts.to_enum unless block_given? body_parts.each { |part| yield(part) } end
Check if body has an attribute
# File lib/github_api/response_wrapper.rb, line 116 def has_key?(key) self.body.is_a?(Hash) && self.body.has_key?(key) end
Return response headers
# File lib/github_api/response_wrapper.rb, line 73 def headers Github::Response::Header.new(env) end
Print only response body
# File lib/github_api/response_wrapper.rb, line 142 def inspect "#<#{self.class.name} @body=\"#{self.body}\">" end
Coerce any method calls for body attributes
# File lib/github_api/response_wrapper.rb, line 122 def method_missing(method_name, *args, &block) if self.has_key?(method_name.to_s) self.[](method_name, &block) else super end end
# File lib/github_api/response_wrapper.rb, line 59 def redirect? status.to_i >= 300 && status.to_i < 400 end
Check if method is defined on the body
# File lib/github_api/response_wrapper.rb, line 132 def respond_to?(method_name) if self.has_key?(method_name.to_s) true else super end end
# File lib/github_api/response_wrapper.rb, line 67 def server_error? status.to_i >= 500 && status.to_i < 600 end
Response status
# File lib/github_api/response_wrapper.rb, line 51 def status response.status end
# File lib/github_api/response_wrapper.rb, line 55 def success? response.success? end
Convert the ResponseWrapper into an Array
# File lib/github_api/response_wrapper.rb, line 102 def to_ary body.to_ary end
Convert the ResponseWrapper into a Hash
# File lib/github_api/response_wrapper.rb, line 96 def to_hash body.to_hash end
Return response body as string
# File lib/github_api/response_wrapper.rb, line 90 def to_s body.to_s end
Request url
# File lib/github_api/response_wrapper.rb, line 34 def url response.env[:url].to_s end
Generated with the Darkfish Rdoc Generator 2.