A class responsible for proxing to faraday response
Constant Summary Constants included from ConstantsConstants::ACCEPT, Constants::ACCEPTED_OAUTH_SCOPES, Constants::ACCEPT_CHARSET, Constants::CACHE_CONTROL, Constants::CONTENT_LENGTH, Constants::CONTENT_TYPE, Constants::DATE, Constants::ETAG, Constants::HEADER_LAST, Constants::HEADER_LINK, Constants::HEADER_NEXT, Constants::LOCATION, Constants::META_FIRST, Constants::META_LAST, Constants::META_NEXT, Constants::META_PREV, Constants::META_REL, Constants::OAUTH_SCOPES, Constants::PARAM_PAGE, Constants::PARAM_PER_PAGE, Constants::PARAM_START_PAGE, Constants::RATELIMIT_LIMIT, Constants::RATELIMIT_REMAINING, Constants::RATELIMIT_RESET, Constants::SERVER, Constants::USER_AGENT
Instance Attribute Summary collapseReturns the value of attribute current_api.
Returns the value of attribute env.
Returns the value of attribute response.
Compare the wrapper with other wrapper for equality.
Lookup an attribute from the body if hash, otherwise behave like array index.
Response raw body.
Iterate over each resource inside the body.
Check if body has an attribute.
Return response headers.
A new instance of ResponseWrapper.
Print only response body.
Coerce any method calls for body attributes.
Check if method is defined on the body.
Response status.
Convert the ResponseWrapper into an Array.
Convert the ResponseWrapper into a Hash.
Return response body as string.
Request url.
#auto_paginate, #count_pages, #each_page, #first_page, #has_next_page?, #last_page, #links, #next_page, #page, per_page_as_param, #prev_page
Constructor Details #initialize(response, current_api) ⇒ ResponseWrapperReturns a new instance of ResponseWrapper.
22 23 24 25 26 27
# File 'lib/github_api/response_wrapper.rb', line 22 def initialize(response, current_api) @response = response @current_api = current_api @env = response.env @body = nil endDynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ ObjectCoerce any method calls for body attributes
127 128 129 130 131 132 133
# File 'lib/github_api/response_wrapper.rb', line 127 def method_missing(method_name, *args, &block) if self.has_key?(method_name.to_s) self.[](method_name, &block) else super end endInstance Attribute Details #current_api ⇒ Object
Returns the value of attribute current_api.
16 17 18
# File 'lib/github_api/response_wrapper.rb', line 16 def current_api @current_api end#env ⇒ Object
Returns the value of attribute env.
18 19 20
# File 'lib/github_api/response_wrapper.rb', line 18 def env @env end#response ⇒ Object
Returns the value of attribute response.
14 15 16
# File 'lib/github_api/response_wrapper.rb', line 14 def response @response endInstance Method Details #==(other) ⇒ Object Also known as: eql?
Compare the wrapper with other wrapper for equality
153 154 155 156 157
# File 'lib/github_api/response_wrapper.rb', line 153 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#[](key) ⇒ Object
Lookup an attribute from the body if hash, otherwise behave like array index. Convert any key to string before calling.
85 86 87 88 89 90 91
# File 'lib/github_api/response_wrapper.rb', line 85 def [](key) if self.body.is_a?(Array) self.body[key] else self.body.send(:"#{key}") end end#body ⇒ Object
50 51 52
# File 'lib/github_api/response_wrapper.rb', line 50 def body @body ? @body : response.body end#body=(value) ⇒ Object
43 44 45 46
# File 'lib/github_api/response_wrapper.rb', line 43 def body=(value) @body = value @env[:body] = value end#client_error? ⇒ Boolean
68 69 70
# File 'lib/github_api/response_wrapper.rb', line 68 def client_error? status.to_i >= 400 && status.to_i < 500 end#each ⇒ Object
Iterate over each resource inside the body
113 114 115 116 117
# File 'lib/github_api/response_wrapper.rb', line 113 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#has_key?(key) ⇒ Boolean
Check if body has an attribute
121 122 123
# File 'lib/github_api/response_wrapper.rb', line 121 def has_key?(key) self.body.is_a?(Hash) && self.body.has_key?(key) end#inspect ⇒ Object
147 148 149
# File 'lib/github_api/response_wrapper.rb', line 147 def inspect "#<#{self.class.name} @body=\"#{self.body}\">" end#redirect? ⇒ Boolean
64 65 66
# File 'lib/github_api/response_wrapper.rb', line 64 def redirect? status.to_i >= 300 && status.to_i < 400 end#respond_to?(method_name, include_all = false) ⇒ Boolean
Check if method is defined on the body
137 138 139 140 141 142 143
# File 'lib/github_api/response_wrapper.rb', line 137 def respond_to?(method_name, include_all = false) if self.has_key?(method_name.to_s) true else super end end#server_error? ⇒ Boolean
72 73 74
# File 'lib/github_api/response_wrapper.rb', line 72 def server_error? status.to_i >= 500 && status.to_i < 600 end#status ⇒ Object
56 57 58
# File 'lib/github_api/response_wrapper.rb', line 56 def status response.status end#success? ⇒ Boolean
60 61 62
# File 'lib/github_api/response_wrapper.rb', line 60 def success? response.success? end#to_ary ⇒ Object
Convert the ResponseWrapper into an Array
107 108 109
# File 'lib/github_api/response_wrapper.rb', line 107 def to_ary body.to_ary end#to_hash ⇒ Object
Convert the ResponseWrapper into a Hash
101 102 103
# File 'lib/github_api/response_wrapper.rb', line 101 def to_hash body.to_hash end#to_s ⇒ Object
Return response body as string
95 96 97
# File 'lib/github_api/response_wrapper.rb', line 95 def to_s body.to_s end#url ⇒ Object
39 40 41
# File 'lib/github_api/response_wrapper.rb', line 39 def url response.env[:url].to_s end
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4