Class: Google::APIClient::Service::Result

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

Instance Method Summary collapse

Constructor Details

#initialize(request, base_result) ⇒ Result

Init the result.

Parameters:



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

#bodyString (readonly)

Returns HTTP response body.

Returns:

  • (String)

    HTTP response body



44
# File 'lib/google/api_client/service/result.rb', line 44

def_delegators :@base_result, :status, :headers, :body

#dataObject, ... (readonly)

Return parsed version of the response body.

Returns:

  • (Object, Hash, String)

    Object if body parsable from API schema, Hash if JSON, raw body if unable to parse



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

Returns:

  • (TrueClass, FalseClass)

    true if body can be parsed



86
# File 'lib/google/api_client/service/result.rb', line 86

def_delegators :@base_result, :data?

#error?TrueClass, FalseClass (readonly)

Check if request failed

Returns:

  • (TrueClass, FalseClass)

    true if result of operation is an error



62
# File 'lib/google/api_client/service/result.rb', line 62

def_delegators :@base_result, :error?

#error_messageString (readonly)

Extracts error messages from the response body

Returns:

  • (String)

    error message, if available



78
# File 'lib/google/api_client/service/result.rb', line 78

def_delegators :@base_result, :error_message

#headersHash (readonly)

Returns HTTP response headers.

Returns:

  • (Hash)

    HTTP response headers



44
# File 'lib/google/api_client/service/result.rb', line 44

def_delegators :@base_result, :status, :headers, :body

#media_typeString (readonly)

Get the content type of the response

Returns:

  • (String)

    Value of content-type header



54
# File 'lib/google/api_client/service/result.rb', line 54

def_delegators :@base_result, :media_type

#next_page_tokenString (readonly)

Get the token used for requesting the next page of data

Returns:

  • (String)

    next page tokenx =



118
# File 'lib/google/api_client/service/result.rb', line 118

def_delegators :@base_result, :next_page_token

#page_token_paramString (readonly)

Name of the field that contains the pagination token

Returns:

  • (String)

    currently always ‘pageToken’



110
# File 'lib/google/api_client/service/result.rb', line 110

def_delegators :@base_result, :page_token_param

#pagination_typeSymbol (readonly)

Pagination scheme used by this request/response

Returns:

  • (Symbol)

    currently always :token



102
# File 'lib/google/api_client/service/result.rb', line 102

def_delegators :@base_result, :pagination_type

#prev_page_tokenString (readonly)

Get the token used for requesting the previous page of data

Returns:

  • (String)

    previous page token



126
# File 'lib/google/api_client/service/result.rb', line 126

def_delegators :@base_result, :prev_page_token

#requestGoogle::APIClient::Service::Request (readonly)

Returns Original request object.

Returns:



47
48
49
# File 'lib/google/api_client/service/result.rb', line 47

def request
  @request
end

#resumable_uploadObject (readonly)

Raises:

  • (NotImplementedError)


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

#statusFixnum (readonly)

Returns HTTP status code.

Returns:

  • (Fixnum)

    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

Returns:

  • (TrueClass, FalseClass)

    true if result of operation was successful



70
# File 'lib/google/api_client/service/result.rb', line 70

def_delegators :@base_result, :success?

Instance Method Details

#next_pageGoogle::APIClient::Service::Request

Build a request for fetching the next page of data

Returns:



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_pageGoogle::APIClient::Service::Request

Build a request for fetching the previous page of data

Returns:



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