Class: Ably::Models::HttpPaginatedResponse

Inherits:
PaginatedResult show all
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

#items

Instance Method Summary collapse

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_codeInteger

The error code if the X-Ably-Errorcode HTTP header is sent in the response.

Returns:

  • (Integer)


61
62
63
64
65
# File 'lib/submodules/ably-ruby/lib/ably/models/http_paginated_response.rb', line 61

def error_code
  if http_response.headers['X-Ably-Errorcode']
    http_response.headers['X-Ably-Errorcode'].to_i
  end
end

#error_messageString

The error message if the X-Ably-Errormessage HTTP header is sent in the response.

Returns:

  • (String)


73
74
75
# File 'lib/submodules/ably-ruby/lib/ably/models/http_paginated_response.rb', line 73

def error_message
  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.


15
16
17
18
19
20
# File 'lib/submodules/ably-ruby/lib/ably/models/http_paginated_response.rb', line 15

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, pagination_options, &each_block)
  end
end

#headersHash<String, String>

The headers of the response.

Returns:

  • (Hash<String, String>)


83
84
85
# File 'lib/submodules/ably-ruby/lib/ably/models/http_paginated_response.rb', line 83

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.


28
29
30
31
32
33
# File 'lib/submodules/ably-ruby/lib/ably/models/http_paginated_response.rb', line 28

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, pagination_options, &each_block)
  end
end

#status_codeInteger

The HTTP status code of the response.

Returns:

  • (Integer)


41
42
43
# File 'lib/submodules/ably-ruby/lib/ably/models/http_paginated_response.rb', line 41

def status_code
  http_response.status.to_i
end

#success?Boolean

Whether statusCode indicates success. This is equivalent to 200 <= statusCode < 300.

Returns:

  • (Boolean)


51
52
53
# File 'lib/submodules/ably-ruby/lib/ably/models/http_paginated_response.rb', line 51

def success?
  (200..299).include?(http_response.status.to_i)
end