Class: Ghub::API::Page
- Inherits:
-
Object
- Object
- Ghub::API::Page
- Defined in:
- lib/ghub/api/page.rb
Overview
Represents a page of an API response.
Class Method Summary collapse
Instance Method Summary collapse
- #body ⇒ Object
-
#initialize(response) ⇒ Page
constructor
A new instance of Page.
- #last? ⇒ Boolean
- #next ⇒ Object
- #to_response(content = []) ⇒ Object
Constructor Details
#initialize(response) ⇒ Page
Returns a new instance of Page.
27 28 29 |
# File 'lib/ghub/api/page.rb', line 27 def initialize response @response = response end |
Class Method Details
.of(index = 1, bodies: [], &request) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/ghub/api/page.rb', line 15 def self.of index = 1, bodies: [], &request yield(index).fmap { |response| new response } .fmap { |page| [page, bodies.including(page.body)] } .bind do |page, amalgam| if page.last? Success page.to_response(amalgam) else of page.next, bodies: amalgam, &request end end end |
Instance Method Details
#body ⇒ Object
35 |
# File 'lib/ghub/api/page.rb', line 35 def body = response.parse |
#last? ⇒ Boolean
33 |
# File 'lib/ghub/api/page.rb', line 33 def last? = (:last).zero? |
#next ⇒ Object
31 |
# File 'lib/ghub/api/page.rb', line 31 def next = __method__ |
#to_response(content = []) ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'lib/ghub/api/page.rb', line 37 def to_response content = [] return response if content.empty? response.class.new request: response.request, headers: response.headers, body: content.to_json, status: response.status, version: response.version end |