Class: DisqusApi::Response
- Inherits:
-
ActiveSupport::HashWithIndifferentAccess
- Object
- ActiveSupport::HashWithIndifferentAccess
- DisqusApi::Response
- Defined in:
- lib/disqus_api/response.rb
Instance Attribute Summary collapse
-
#arguments ⇒ Object
readonly
Returns the value of attribute arguments.
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#request ⇒ Object
readonly
Returns the value of attribute request.
Instance Method Summary collapse
-
#all ⇒ Array<Hash>
Fetches all response collection entries going through pagination.
- #body ⇒ Hash (also: #response)
- #code ⇒ Integer
-
#each_page(&block) ⇒ Enumerator<Array<Hash>>
Iterates through every single page.
-
#each_resource(&block) ⇒ Enumerator<Hash>
Iterates through each response entry through all pages.
- #has_next? ⇒ Boolean
- #has_prev? ⇒ Boolean
-
#initialize(request, arguments = {}) ⇒ Response
constructor
A new instance of Response.
- #next ⇒ Response?
- #next! ⇒ Response
- #next_cursor ⇒ String
- #prev ⇒ Response?
- #prev! ⇒ Response
- #prev_cursor ⇒ String
Constructor Details
#initialize(request, arguments = {}) ⇒ Response
Returns a new instance of Response.
7 8 9 10 11 12 13 |
# File 'lib/disqus_api/response.rb', line 7 def initialize(request, arguments = {}) @request = request @arguments = arguments @content = request.perform(@arguments) super(@content) end |
Instance Attribute Details
#arguments ⇒ Object (readonly)
Returns the value of attribute arguments.
3 4 5 |
# File 'lib/disqus_api/response.rb', line 3 def arguments @arguments end |
#content ⇒ Object (readonly)
Returns the value of attribute content.
3 4 5 |
# File 'lib/disqus_api/response.rb', line 3 def content @content end |
#request ⇒ Object (readonly)
Returns the value of attribute request.
3 4 5 |
# File 'lib/disqus_api/response.rb', line 3 def request @request end |
Instance Method Details
#all ⇒ Array<Hash>
Fetches all response collection entries going through pagination
17 18 19 |
# File 'lib/disqus_api/response.rb', line 17 def all each_resource.to_a end |
#body ⇒ Hash Also known as: response
87 88 89 |
# File 'lib/disqus_api/response.rb', line 87 def body self['response'] end |
#code ⇒ Integer
93 94 95 |
# File 'lib/disqus_api/response.rb', line 93 def code self['code'] end |
#each_page(&block) ⇒ Enumerator<Array<Hash>>
Iterates through every single page
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/disqus_api/response.rb', line 31 def each_page(&block) Enumerator.new do |result| next_response = self while next_response result << next_response.body.to_a next_response = next_response.next end end.each(&block) end |
#each_resource(&block) ⇒ Enumerator<Hash>
Iterates through each response entry through all pages
23 24 25 26 27 |
# File 'lib/disqus_api/response.rb', line 23 def each_resource(&block) Enumerator.new do |result| each_page { |resources| resources.each { |resource| result << resource } } end.each(&block) end |
#has_next? ⇒ Boolean
68 69 70 |
# File 'lib/disqus_api/response.rb', line 68 def has_next? self['cursor']['hasNext'] end |
#has_prev? ⇒ Boolean
72 73 74 |
# File 'lib/disqus_api/response.rb', line 72 def has_prev? self['cursor']['hasPrev'] end |
#next ⇒ Response?
55 56 57 58 59 |
# File 'lib/disqus_api/response.rb', line 55 def next if has_next? request.response(arguments.merge(cursor: next_cursor)) end end |
#next! ⇒ Response
43 44 45 46 |
# File 'lib/disqus_api/response.rb', line 43 def next! self.merge!(self.next) if has_next? self end |
#next_cursor ⇒ String
77 78 79 |
# File 'lib/disqus_api/response.rb', line 77 def next_cursor self['cursor']['next'] end |
#prev ⇒ Response?
62 63 64 65 66 |
# File 'lib/disqus_api/response.rb', line 62 def prev if has_prev? request.response(arguments.merge(cursor: prev_cursor)) end end |
#prev! ⇒ Response
49 50 51 52 |
# File 'lib/disqus_api/response.rb', line 49 def prev! self.merge!(self.prev) if has_prev? self end |
#prev_cursor ⇒ String
82 83 84 |
# File 'lib/disqus_api/response.rb', line 82 def prev_cursor self['cursor']['prev'] end |