Class: Ably::Models::HttpPaginatedResponse
- Inherits:
-
PaginatedResult
- Object
- PaginatedResult
- Ably::Models::HttpPaginatedResponse
- Defined in:
- lib/submodules/ably-ruby/lib/ably/models/http_paginated_response.rb
Overview
HTTP respones object from Rest#request object Wraps any Ably HTTP response that supports paging and provides methods to iterate through the pages using #first, #next, PaginatedResult#has_next? and PaginatedResult#last?
Defined Under Namespace
Classes: ErrorResponse
Instance Attribute Summary
Attributes inherited from PaginatedResult
Instance Method Summary collapse
-
#error_code ⇒ Integer
Ably error code from
X-Ably-Errorcode
header if available from response. -
#error_message ⇒ String
Error message from
X-Ably-Errormessage
header if available from response. -
#first(&success_callback) ⇒ HttpPaginatedResponse, Ably::Util::SafeDeferrable
Retrieve the first page of results.
-
#headers ⇒ Hash<String, String>
Headers for the HTTP response.
-
#next(&success_callback) ⇒ HttpPaginatedResponse, Ably::Util::SafeDeferrable
Retrieve the next page of results.
-
#status_code ⇒ Integer
HTTP status code for response.
-
#success? ⇒ Boolean
True if the response is considered successful due to the HTTP status code.
Methods inherited from PaginatedResult
#has_next?, #initialize, #inspect, #last?, #supports_pagination?
Constructor Details
This class inherits a constructor from Ably::Models::PaginatedResult
Instance Method Details
#error_code ⇒ Integer
Ably error code from X-Ably-Errorcode
header if available from response
47 48 49 50 51 |
# File 'lib/submodules/ably-ruby/lib/ably/models/http_paginated_response.rb', line 47 def error_code if http_response.headers['X-Ably-Errorcode'] http_response.headers['X-Ably-Errorcode'].to_i end end |
#error_message ⇒ String
Error message from X-Ably-Errormessage
header if available from response
55 56 57 |
# File 'lib/submodules/ably-ruby/lib/ably/models/http_paginated_response.rb', line 55 def http_response.headers['X-Ably-Errormessage'] end |
#first(&success_callback) ⇒ HttpPaginatedResponse, 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.
14 15 16 17 18 19 |
# File 'lib/submodules/ably-ruby/lib/ably/models/http_paginated_response.rb', line 14 def first(&success_callback) async_wrap_if_realtime(success_callback) do return nil unless supports_pagination? HttpPaginatedResponse.new(client.get(pagination_url('first')), base_url, client, , &each_block) end end |
#headers ⇒ Hash<String, String>
Headers for the HTTP response
61 62 63 |
# File 'lib/submodules/ably-ruby/lib/ably/models/http_paginated_response.rb', line 61 def headers http_response.headers || {} end |
#next(&success_callback) ⇒ HttpPaginatedResponse, 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.
26 27 28 29 30 31 |
# File 'lib/submodules/ably-ruby/lib/ably/models/http_paginated_response.rb', line 26 def next(&success_callback) async_wrap_if_realtime(success_callback) do return nil unless has_next? HttpPaginatedResponse.new(client.get(pagination_url('next')), base_url, client, , &each_block) end end |
#status_code ⇒ Integer
HTTP status code for response
35 36 37 |
# File 'lib/submodules/ably-ruby/lib/ably/models/http_paginated_response.rb', line 35 def status_code http_response.status.to_i end |
#success? ⇒ Boolean
True if the response is considered successful due to the HTTP status code
41 42 43 |
# File 'lib/submodules/ably-ruby/lib/ably/models/http_paginated_response.rb', line 41 def success? (200..299).include?(http_response.status.to_i) end |