Class: Google::Apis::Core::BaseService
- Inherits:
-
Object
- Object
- Google::Apis::Core::BaseService
- Includes:
- Logging
- Defined in:
- lib/google/apis/core/base_service.rb
Overview
Base service for all APIs. Not to be used directly.
Instance Attribute Summary collapse
-
#authorization ⇒ Signet::OAuth2::Client
OAuth2 credentials.
-
#base_path ⇒ Addressable::URI
Additional path prefix for all API methods.
-
#batch_path ⇒ Addressable::URI
Alternate path prefix for all batch methods.
-
#client ⇒ HTTPClient
Get the current HTTP client.
-
#client_name ⇒ String
Client library name.
-
#client_options ⇒ Google::Apis::ClientOptions
General settings.
-
#client_version ⇒ String
Client library version.
-
#request_options ⇒ Google::Apis::RequestOptions
Default options for all requests.
-
#root_url ⇒ Addressable::URI
Root URL (host/port) for the API.
-
#upload_path ⇒ Addressable::URI
Alternate path prefix for media uploads.
Instance Method Summary collapse
-
#batch(options = nil) {|self| ... }
Perform a batch request.
-
#batch_upload(options = nil) {|self| ... }
Perform a batch upload request.
-
#fetch_all(max: nil, items: :items, cache: true, response_page_token: :next_page_token) {|token, service| ... } ⇒ Enumerble
Executes a given query with paging, automatically retrieving additional pages as necessary.
-
#http(method, url, params: nil, body: nil, download_dest: nil, options: nil) {|result, err| ... } ⇒ String
Simple escape hatch for making API requests directly to a given URL.
-
#initialize(root_url, base_path, client_name: nil, client_version: nil) ⇒ BaseService
constructor
private
A new instance of BaseService.
Methods included from Logging
Constructor Details
#initialize(root_url, base_path, client_name: nil, client_version: nil) ⇒ BaseService
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of BaseService.
139 140 141 142 143 144 145 146 147 148 |
# File 'lib/google/apis/core/base_service.rb', line 139 def initialize(root_url, base_path, client_name: nil, client_version: nil) self.root_url = root_url self.base_path = base_path self.client_name = client_name || 'google-api-ruby-client' self.client_version = client_version || Google::Apis::Core::VERSION self.upload_path = "upload/#{base_path}" self.batch_path = 'batch' self. = Google::Apis::ClientOptions.default.dup self. = Google::Apis::RequestOptions.default.dup end |
Instance Attribute Details
#authorization ⇒ Signet::OAuth2::Client
Returns OAuth2 credentials.
153 154 155 |
# File 'lib/google/apis/core/base_service.rb', line 153 def () . = end |
#base_path ⇒ Addressable::URI
Additional path prefix for all API methods
104 105 106 |
# File 'lib/google/apis/core/base_service.rb', line 104 def base_path @base_path end |
#batch_path ⇒ Addressable::URI
Alternate path prefix for all batch methods
112 113 114 |
# File 'lib/google/apis/core/base_service.rb', line 112 def batch_path @batch_path end |
#client ⇒ HTTPClient
Get the current HTTP client
116 117 118 |
# File 'lib/google/apis/core/base_service.rb', line 116 def client @client end |
#client_name ⇒ String
Client library name.
128 129 130 |
# File 'lib/google/apis/core/base_service.rb', line 128 def client_name @client_name end |
#client_options ⇒ Google::Apis::ClientOptions
General settings
120 121 122 |
# File 'lib/google/apis/core/base_service.rb', line 120 def @client_options end |
#client_version ⇒ String
Client library version.
132 133 134 |
# File 'lib/google/apis/core/base_service.rb', line 132 def client_version @client_version end |
#request_options ⇒ Google::Apis::RequestOptions
Default options for all requests
124 125 126 |
# File 'lib/google/apis/core/base_service.rb', line 124 def @request_options end |
#root_url ⇒ Addressable::URI
Root URL (host/port) for the API
100 101 102 |
# File 'lib/google/apis/core/base_service.rb', line 100 def root_url @root_url end |
#upload_path ⇒ Addressable::URI
Alternate path prefix for media uploads
108 109 110 |
# File 'lib/google/apis/core/base_service.rb', line 108 def upload_path @upload_path end |
Instance Method Details
#batch(options = nil) {|self| ... }
This method returns an undefined value.
Perform a batch request. Calls made within the block are sent in a single network request to the server.
181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/google/apis/core/base_service.rb', line 181 def batch( = nil) batch_command = BatchCommand.new(:post, Addressable::URI.parse(root_url + batch_path)) batch_command. = .merge() apply_command_defaults(batch_command) begin start_batch(batch_command) yield self ensure end_batch end batch_command.execute(client) end |
#batch_upload(options = nil) {|self| ... }
This method returns an undefined value.
Perform a batch upload request. Calls made within the block are sent in a single network request to the server. Batch uploads are useful for uploading multiple small files. For larger files, use single requests which use a resumable upload protocol.
213 214 215 216 217 218 219 220 221 222 223 224 |
# File 'lib/google/apis/core/base_service.rb', line 213 def batch_upload( = nil) batch_command = BatchUploadCommand.new(:put, Addressable::URI.parse(root_url + upload_path)) batch_command. = .merge() apply_command_defaults(batch_command) begin start_batch(batch_command) yield self ensure end_batch end batch_command.execute(client) end |
#fetch_all(max: nil, items: :items, cache: true, response_page_token: :next_page_token) {|token, service| ... } ⇒ Enumerble
Executes a given query with paging, automatically retrieving additional pages as necessary. Requires a block that returns the result set of a page. The current page token is supplied as an argument to the block.
Note: The returned enumerable also contains a last_result
field
containing the full result of the last query executed.
294 295 296 297 |
# File 'lib/google/apis/core/base_service.rb', line 294 def fetch_all(max: nil, items: :items, cache: true, response_page_token: :next_page_token, &block) fail "fetch_all may not be used inside a batch" if batch? return PagedResults.new(self, max: max, items: items, cache: cache, response_page_token: response_page_token, &block) end |
#http(method, url, params: nil, body: nil, download_dest: nil, options: nil) {|result, err| ... } ⇒ String
Simple escape hatch for making API requests directly to a given URL. This is not intended to be used as a generic HTTP client and should be used only in cases where no service method exists (e.g. fetching an export link for a Google Drive file.)
256 257 258 259 260 261 262 263 264 265 266 |
# File 'lib/google/apis/core/base_service.rb', line 256 def http(method, url, params: nil, body: nil, download_dest: nil, options: nil, &block) if download_dest command = DownloadCommand.new(method, url, body: body, client_version: client_version) else command = HttpCommand.new(method, url, body: body) end command. = .merge() apply_command_defaults(command) command.query.merge(Hash(params)) execute_or_queue_command(command, &block) end |