Class: Ably::Models::PaginatedResult
- Inherits:
-
Object
- Object
- Ably::Models::PaginatedResult
- Includes:
- Ably::Modules::AsyncWrapper
- Defined in:
- lib/submodules/ably-ruby/lib/ably/models/paginated_result.rb
Overview
Instance Attribute Summary collapse
-
#items ⇒ Array
readonly
The items contained within this PaginatedResult.
Instance Method Summary collapse
-
#first(&success_callback) ⇒ PaginatedResult, Ably::Util::SafeDeferrable
Retrieve the first page of results.
-
#first? ⇒ Boolean
True if this is the first page in the paged resource set.
-
#has_next? ⇒ Boolean
True if there is a subsequent page in this paginated set available with #next.
- #initialize(http_response, base_url, client, options = {}) {|Object| ... } ⇒ PaginatedResult constructor
- #inspect ⇒ Object
-
#last? ⇒ Boolean
True if this is the last page in the paged resource set.
-
#next(&success_callback) ⇒ PaginatedResult, Ably::Util::SafeDeferrable
Retrieve the next page of results.
-
#supports_pagination? ⇒ Boolean
True if the HTTP response supports paging with the expected LINK HTTP headers.
Constructor Details
#initialize(http_response, base_url, client, options = {}) {|Object| ... } ⇒ PaginatedResult
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/submodules/ably-ruby/lib/ably/models/paginated_result.rb', line 25 def initialize(http_response, base_url, client, = {}, &each_block) @http_response = http_response @client = client @base_url = "#{base_url.gsub(%r{/[^/]*$}, '')}/" @coerce_into = [:coerce_into] @raw_body = http_response.body @each_block = each_block @make_async = .fetch(:async_blocking_operations, false) @items = http_response.body @items = coerce_items_into(items, @coerce_into) if @coerce_into @items = items.map { |item| yield item } if block_given? end |
Instance Attribute Details
#items ⇒ Array (readonly)
The items contained within this Ably::Models::PaginatedResult
14 15 16 |
# File 'lib/submodules/ably-ruby/lib/ably/models/paginated_result.rb', line 14 def items @items end |
Instance Method Details
#first(&success_callback) ⇒ PaginatedResult, Ably::Util::SafeDeferrable
Retrieve the first page of results. When used as part of the Realtime library, it will return a Util::SafeDeferrable object,
and allows an optional success callback block to be provided.
44 45 46 47 48 49 |
# File 'lib/submodules/ably-ruby/lib/ably/models/paginated_result.rb', line 44 def first(&success_callback) async_wrap_if_realtime(success_callback) do return nil unless supports_pagination? PaginatedResult.new(client.get(pagination_url('first')), base_url, client, , &each_block) end end |
#first? ⇒ Boolean
True if this is the first page in the paged resource set
74 75 76 77 |
# File 'lib/submodules/ably-ruby/lib/ably/models/paginated_result.rb', line 74 def first? !supports_pagination? || pagination_header('first') == pagination_header('current') end |
#has_next? ⇒ Boolean
True if there is a subsequent page in this paginated set available with #next
82 83 84 |
# File 'lib/submodules/ably-ruby/lib/ably/models/paginated_result.rb', line 82 def has_next? supports_pagination? && !last? end |
#inspect ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/submodules/ably-ruby/lib/ably/models/paginated_result.rb', line 93 def inspect <<-EOF.gsub(/^ /, '') #<#{self.class.name}:#{self.object_id} @base_url="#{base_url}", @first?=#{!!first?}, @last?=#{!!first?}, @has_next?=#{!!has_next?}, @items= #{items.map { |item| item.inspect }.join(",\n ") } > EOF end |
#last? ⇒ Boolean
True if this is the last page in the paged resource set
66 67 68 69 |
# File 'lib/submodules/ably-ruby/lib/ably/models/paginated_result.rb', line 66 def last? !supports_pagination? || pagination_header('next').nil? end |
#next(&success_callback) ⇒ PaginatedResult, Ably::Util::SafeDeferrable
Retrieve the next page of results. When used as part of the Realtime library, it will return a Util::SafeDeferrable object,
and allows an optional success callback block to be provided.
56 57 58 59 60 61 |
# File 'lib/submodules/ably-ruby/lib/ably/models/paginated_result.rb', line 56 def next(&success_callback) async_wrap_if_realtime(success_callback) do return nil unless has_next? PaginatedResult.new(client.get(pagination_url('next')), base_url, client, , &each_block) end end |
#supports_pagination? ⇒ Boolean
True if the HTTP response supports paging with the expected LINK HTTP headers
89 90 91 |
# File 'lib/submodules/ably-ruby/lib/ably/models/paginated_result.rb', line 89 def supports_pagination? !pagination_headers.empty? end |