Class: Ghub::API::Page

Inherits:
Object
  • Object
show all
Defined in:
lib/ghub/api/page.rb

Overview

Represents a page of an API response.

Class Method Summary collapse

Instance Method Summary collapse

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

#bodyObject



35
# File 'lib/ghub/api/page.rb', line 35

def body = response.parse

#last?Boolean

Returns:

  • (Boolean)


33
# File 'lib/ghub/api/page.rb', line 33

def last? = navigation(:last).zero?

#nextObject



31
# File 'lib/ghub/api/page.rb', line 31

def next = navigation __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