Class: Google::APIClient::Service::Result
- Inherits:
-
Object
- Object
- Google::APIClient::Service::Result
- Extended by:
- Forwardable
- Defined in:
- lib/google/api_client/service/result.rb
Overview
Handles an API result. Wraps around the Google::APIClient::Result class, making it easier to handle the result (e.g. pagination) and keeping it in line with the rest of the Service programming interface.
Instance Attribute Summary collapse
-
#body ⇒ String
readonly
HTTP response body.
-
#data ⇒ Object, ...
readonly
Return parsed version of the response body.
-
#data? ⇒ TrueClass, FalseClass
readonly
Check for parsable data in response.
-
#error? ⇒ TrueClass, FalseClass
readonly
Check if request failed.
-
#error_message ⇒ String
readonly
Extracts error messages from the response body.
-
#headers ⇒ Hash
readonly
HTTP response headers.
-
#media_type ⇒ String
readonly
Get the content type of the response.
-
#next_page_token ⇒ String
readonly
Get the token used for requesting the next page of data.
-
#page_token_param ⇒ String
readonly
Name of the field that contains the pagination token.
-
#pagination_type ⇒ Symbol
readonly
Pagination scheme used by this request/response.
-
#prev_page_token ⇒ String
readonly
Get the token used for requesting the previous page of data.
-
#request ⇒ Google::APIClient::Service::Request
readonly
Original request object.
- #resumable_upload ⇒ Object readonly
-
#status ⇒ Fixnum
readonly
HTTP status code.
-
#success? ⇒ TrueClass, FalseClass
readonly
Check if request was successful.
Instance Method Summary collapse
-
#initialize(request, base_result) ⇒ Result
constructor
Init the result.
-
#next_page ⇒ Google::APIClient::Service::Request
Build a request for fetching the next page of data.
-
#prev_page ⇒ Google::APIClient::Service::Request
Build a request for fetching the previous page of data.
Constructor Details
#initialize(request, base_result) ⇒ Result
Init the result.
33 34 35 36 |
# File 'lib/google/api_client/service/result.rb', line 33 def initialize(request, base_result) @request = request @base_result = base_result end |
Instance Attribute Details
#body ⇒ String (readonly)
Returns HTTP response body.
44 |
# File 'lib/google/api_client/service/result.rb', line 44 def_delegators :@base_result, :status, :headers, :body |
#data ⇒ Object, ... (readonly)
Return parsed version of the response body.
94 |
# File 'lib/google/api_client/service/result.rb', line 94 def_delegators :@base_result, :data |
#data? ⇒ TrueClass, FalseClass (readonly)
Check for parsable data in response
86 |
# File 'lib/google/api_client/service/result.rb', line 86 def_delegators :@base_result, :data? |
#error? ⇒ TrueClass, FalseClass (readonly)
Check if request failed
62 |
# File 'lib/google/api_client/service/result.rb', line 62 def_delegators :@base_result, :error? |
#error_message ⇒ String (readonly)
Extracts error messages from the response body
78 |
# File 'lib/google/api_client/service/result.rb', line 78 def_delegators :@base_result, :error_message |
#headers ⇒ Hash (readonly)
Returns HTTP response headers.
44 |
# File 'lib/google/api_client/service/result.rb', line 44 def_delegators :@base_result, :status, :headers, :body |
#media_type ⇒ String (readonly)
Get the content type of the response
54 |
# File 'lib/google/api_client/service/result.rb', line 54 def_delegators :@base_result, :media_type |
#next_page_token ⇒ String (readonly)
Get the token used for requesting the next page of data
118 |
# File 'lib/google/api_client/service/result.rb', line 118 def_delegators :@base_result, :next_page_token |
#page_token_param ⇒ String (readonly)
Name of the field that contains the pagination token
110 |
# File 'lib/google/api_client/service/result.rb', line 110 def_delegators :@base_result, :page_token_param |
#pagination_type ⇒ Symbol (readonly)
Pagination scheme used by this request/response
102 |
# File 'lib/google/api_client/service/result.rb', line 102 def_delegators :@base_result, :pagination_type |
#prev_page_token ⇒ String (readonly)
Get the token used for requesting the previous page of data
126 |
# File 'lib/google/api_client/service/result.rb', line 126 def_delegators :@base_result, :prev_page_token |
#request ⇒ Google::APIClient::Service::Request (readonly)
Returns Original request object.
47 48 49 |
# File 'lib/google/api_client/service/result.rb', line 47 def request @request end |
#resumable_upload ⇒ Object (readonly)
129 130 131 132 |
# File 'lib/google/api_client/service/result.rb', line 129 def resumable_upload # TODO(sgomes): implement resumable_upload for Service::Result raise NotImplementedError end |
#status ⇒ Fixnum (readonly)
Returns HTTP status code.
44 |
# File 'lib/google/api_client/service/result.rb', line 44 def_delegators :@base_result, :status, :headers, :body |
#success? ⇒ TrueClass, FalseClass (readonly)
Check if request was successful
70 |
# File 'lib/google/api_client/service/result.rb', line 70 def_delegators :@base_result, :success? |
Instance Method Details
#next_page ⇒ Google::APIClient::Service::Request
Build a request for fetching the next page of data
139 140 141 142 143 144 145 |
# File 'lib/google/api_client/service/result.rb', line 139 def next_page request = @request.clone # Make a deep copy of the parameters. request.parameters = Marshal.load(Marshal.dump(request.parameters)) request.parameters[page_token_param] = self.next_page_token return request end |
#prev_page ⇒ Google::APIClient::Service::Request
Build a request for fetching the previous page of data
152 153 154 155 156 157 158 |
# File 'lib/google/api_client/service/result.rb', line 152 def prev_page request = @request.clone # Make a deep copy of the parameters. request.parameters = Marshal.load(Marshal.dump(request.parameters)) request.parameters[page_token_param] = self.prev_page_token return request end |