Class: Google::Apis::Core::BaseService

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/google/apis/core/base_service.rb

Overview

Base service for all APIs. Not to be used directly.

Direct Known Subclasses

AbusiveexperiencereportV1::AbusiveExperienceReportService, AcceleratedmobilepageurlV1::AcceleratedmobilepageurlService, AccesscontextmanagerV1beta::AccessContextManagerService, Adexchangebuyer2V2beta1::AdExchangeBuyerIIService, AdexchangebuyerV1_2::AdExchangeBuyerService, AdexchangebuyerV1_3::AdExchangeBuyerService, AdexchangebuyerV1_4::AdExchangeBuyerService, AdexperiencereportV1::AdExperienceReportService, AdminDatatransferV1::DataTransferService, AdminDirectoryV1::DirectoryService, AdminReportsV1::ReportsService, AdsenseV1_4::AdSenseService, AdsensehostV4_1::AdSenseHostService, AlertcenterV1beta1::AlertCenterService, AnalyticsV2_4::AnalyticsService, AnalyticsV3::AnalyticsService, AnalyticsreportingV4::AnalyticsReportingService, AndroiddeviceprovisioningV1::AndroidProvisioningPartnerService, AndroidenterpriseV1::AndroidEnterpriseService, AndroidmanagementV1::AndroidManagementService, AndroidpublisherV1::AndroidPublisherService, AndroidpublisherV1_1::AndroidPublisherService, AndroidpublisherV2::AndroidPublisherService, AndroidpublisherV3::AndroidPublisherService, AppengineV1::AppengineService, AppengineV1alpha::AppengineService, AppengineV1beta4::AppengineService, AppengineV1beta5::AppengineService, AppengineV1beta::AppengineService, AppsactivityV1::AppsactivityService, AppsmarketV2::AppsmarketService, AppstateV1::AppStateService, BigqueryV2::BigqueryService, BigquerydatatransferV1::BigQueryDataTransferService, BigtableadminV2::BigtableAdminService, BinaryauthorizationV1beta1::BinaryAuthorizationService, BloggerV2::BloggerService, BloggerV3::BloggerService, BooksV1::BooksService, Google::Apis::CalendarV3::CalendarService, Google::Apis::ChatV1::HangoutsChatService, Google::Apis::CivicinfoV2::CivicInfoService, Google::Apis::ClassroomV1::ClassroomService, Google::Apis::CloudassetV1beta1::CloudAssetService, Google::Apis::CloudbillingV1::CloudbillingService, Google::Apis::CloudbuildV1::CloudBuildService, Google::Apis::CloudbuildV1alpha1::CloudBuildService, Google::Apis::ClouddebuggerV2::CloudDebuggerService, Google::Apis::ClouderrorreportingV1beta1::ClouderrorreportingService, Google::Apis::CloudfunctionsV1::CloudFunctionsService, Google::Apis::CloudfunctionsV1beta2::CloudFunctionsService, Google::Apis::CloudidentityV1::CloudIdentityService, Google::Apis::CloudidentityV1beta1::CloudIdentityService, Google::Apis::CloudiotV1::CloudIotService, Google::Apis::CloudkmsV1::CloudKMSService, Google::Apis::CloudprofilerV2::CloudProfilerService, Google::Apis::CloudresourcemanagerV1::CloudResourceManagerService, Google::Apis::CloudresourcemanagerV1beta1::CloudResourceManagerService, Google::Apis::CloudresourcemanagerV2::CloudResourceManagerService, Google::Apis::CloudresourcemanagerV2beta1::CloudResourceManagerService, Google::Apis::CloudschedulerV1beta1::CloudSchedulerService, Google::Apis::CloudsearchV1::CloudSearchService, Google::Apis::CloudshellV1::CloudShellService, Google::Apis::CloudshellV1alpha1::CloudShellService, Google::Apis::CloudtasksV2beta2::CloudTasksService, Google::Apis::CloudtasksV2beta3::CloudTasksService, Google::Apis::CloudtraceV1::CloudTraceService, Google::Apis::CloudtraceV2::CloudTraceService, Google::Apis::ComposerV1::CloudComposerService, Google::Apis::ComposerV1beta1::CloudComposerService, Google::Apis::ComputeAlpha::ComputeService, Google::Apis::ComputeBeta::ComputeService, Google::Apis::ComputeV1::ComputeService, Google::Apis::ContainerV1::ContainerService, Google::Apis::ContainerV1beta1::ContainerService, Google::Apis::ContaineranalysisV1alpha1::ContainerAnalysisService, Google::Apis::ContaineranalysisV1beta1::ContainerAnalysisService, Google::Apis::ContentV2::ShoppingContentService, Google::Apis::ContentV2_1::ShoppingContentService, Google::Apis::CustomsearchV1::CustomsearchService, DataflowV1b3::DataflowService, DataprocV1::DataprocService, DataprocV1beta2::DataprocService, DatastoreV1::DatastoreService, DatastoreV1beta1::DatastoreService, DatastoreV1beta3::DatastoreService, DeploymentmanagerAlpha::DeploymentManagerAlphaService, DeploymentmanagerV2::DeploymentManagerService, DeploymentmanagerV2beta::DeploymentManagerV2BetaService, DfareportingV3_1::DfareportingService, DfareportingV3_2::DfareportingService, DialogflowV2::DialogflowService, DialogflowV2beta1::DialogflowService, DigitalassetlinksV1::DigitalassetlinksService, DiscoveryV1::DiscoveryService, DlpV2::DLPService, DnsV1::DnsService, DnsV1beta2::DnsService, DnsV2beta1::DnsService, DocsV1::DocsService, DoubleclickbidmanagerV1::DoubleClickBidManagerService, DoubleclicksearchV2::DoubleclicksearchService, DriveV2::DriveService, DriveV3::DriveService, DriveactivityV2::DriveActivityService, FileV1::CloudFilestoreService, FileV1beta1::CloudFilestoreService, FirebasedynamiclinksV1::FirebaseDynamicLinksService, FirebasehostingV1beta1::FirebaseHostingService, FirebaserulesV1::FirebaseRulesService, FirestoreV1::FirestoreService, FirestoreV1beta1::FirestoreService, FirestoreV1beta2::FirestoreService, FitnessV1::FitnessService, FusiontablesV1::FusiontablesService, FusiontablesV2::FusiontablesService, GamesConfigurationV1configuration::GamesConfigurationService, GamesManagementV1management::GamesManagementService, GamesV1::GamesService, GenomicsV1::GenomicsService, GenomicsV1alpha2::GenomicsService, GenomicsV2alpha1::GenomicsService, GmailV1::GmailService, GroupsmigrationV1::GroupsMigrationService, GroupssettingsV1::GroupssettingsService, IamV1::IamService, IamcredentialsV1::IAMCredentialsService, IapV1::CloudIAPService, IapV1beta1::CloudIAPService, IdentitytoolkitV3::IdentityToolkitService, IndexingV3::IndexingService, JobsV2::CloudTalentSolutionService, JobsV3::CloudTalentSolutionService, JobsV3p1beta1::CloudTalentSolutionService, KgsearchV1::KgsearchService, LanguageV1::CloudNaturalLanguageService, LanguageV1beta1::CloudNaturalLanguageService, LanguageV1beta2::CloudNaturalLanguageService, LibraryagentV1::LibraryagentService, LicensingV1::LicensingService, LoggingV2::LoggingService, LoggingV2beta1::LoggingService, ManufacturersV1::ManufacturerCenterService, MirrorV1::MirrorService, MlV1::CloudMachineLearningEngineService, MonitoringV3::MonitoringService, Oauth2V1::Oauth2Service, Oauth2V2::Oauth2Service, OsloginV1::CloudOSLoginService, OsloginV1alpha::CloudOSLoginService, OsloginV1beta::CloudOSLoginService, PagespeedonlineV1::PagespeedonlineService, PagespeedonlineV2::PagespeedonlineService, PagespeedonlineV4::PagespeedonlineService, PagespeedonlineV5::PagespeedonlineService, PartnersV2::PartnersService, PeopleV1::PeopleServiceService, PlaycustomappV1::PlaycustomappService, PlusDomainsV1::PlusDomainsService, PlusV1::PlusService, PolyV1::PolyServiceService, ProximitybeaconV1beta1::ProximitybeaconService, PubsubV1::PubsubService, PubsubV1beta1a::PubsubService, PubsubV1beta2::PubsubService, RedisV1::CloudRedisService, RedisV1beta1::CloudRedisService, RemotebuildexecutionV1::RemoteBuildExecutionService, RemotebuildexecutionV1alpha::RemoteBuildExecutionService, RemotebuildexecutionV2::RemoteBuildExecutionService, ReplicapoolV1beta1::ReplicapoolService, ResellerV1::ResellerService, RuntimeconfigV1::CloudRuntimeConfigService, RuntimeconfigV1beta1::CloudRuntimeConfigService, SafebrowsingV4::SafebrowsingService, ScriptV1::ScriptService, SearchconsoleV1::SearchConsoleService, ServicebrokerV1::ServiceBrokerService, ServicebrokerV1alpha1::ServiceBrokerService, ServicebrokerV1beta1::ServiceBrokerService, ServiceconsumermanagementV1::ServiceConsumerManagementService, ServicecontrolV1::ServiceControlService, ServicemanagementV1::ServiceManagementService, ServicenetworkingV1beta::ServiceNetworkingService, ServiceusageV1::ServiceUsageService, ServiceusageV1beta1::ServiceUsageService, SheetsV4::SheetsService, SiteVerificationV1::SiteVerificationService, SlidesV1::SlidesService, SourcerepoV1::CloudSourceRepositoriesService, SpannerV1::SpannerService, SpeechV1::SpeechService, SpeechV1p1beta1::SpeechService, SqladminV1beta4::SQLAdminService, StorageV1::StorageService, StorageV1beta1::StorageService, StorageV1beta2::StorageService, StoragetransferV1::StoragetransferService, StreetviewpublishV1::StreetViewPublishService, SurveysV2::SurveysService, TagmanagerV1::TagManagerService, TagmanagerV2::TagManagerService, TasksV1::TasksService, TestingV1::TestingService, TexttospeechV1::TexttospeechService, TexttospeechV1beta1::TexttospeechService, ToolresultsV1beta3::ToolResultsService, TpuV1::TPUService, TpuV1alpha1::TPUService, TranslateV2::TranslateService, UrlshortenerV1::UrlshortenerService, VaultV1::VaultService, VideointelligenceV1::CloudVideoIntelligenceService, VideointelligenceV1beta2::CloudVideoIntelligenceService, VideointelligenceV1p1beta1::CloudVideoIntelligenceService, VideointelligenceV1p2beta1::CloudVideoIntelligenceService, VisionV1::VisionService, VisionV1p1beta1::VisionService, VisionV1p2beta1::VisionService, WebfontsV1::WebfontsService, WebmastersV3::WebmastersService, WebsecurityscannerV1alpha::WebSecurityScannerService, YoutubeAnalyticsV1::YouTubeAnalyticsService, YoutubeAnalyticsV1beta1::YouTubeAnalyticsService, YoutubeAnalyticsV2::YouTubeAnalyticsService, YoutubePartnerV1::YouTubePartnerService, YoutubeV3::YouTubeService, YoutubereportingV1::YouTubeReportingService

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging

#logger

Constructor Details

#initialize(root_url, base_path) ⇒ 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

Parameters:

  • root_url (String, Addressable::URI)

    Root URL for the API

  • base_path (String, Addressable::URI)

    Additional path prefix for all API methods



128
129
130
131
132
133
134
135
# File 'lib/google/apis/core/base_service.rb', line 128

def initialize(root_url, base_path)
  self.root_url = root_url
  self.base_path = base_path
  self.upload_path = "upload/#{base_path}"
  self.batch_path = 'batch'
  self.client_options = Google::Apis::ClientOptions.default.dup
  self.request_options = Google::Apis::RequestOptions.default.dup
end

Instance Attribute Details

#authorizationSignet::OAuth2::Client

Returns OAuth2 credentials

Returns:

  • (Signet::OAuth2::Client)

    OAuth2 credentials



140
141
142
# File 'lib/google/apis/core/base_service.rb', line 140

def authorization=(authorization)
  request_options.authorization = authorization
end

#base_pathAddressable::URI

Additional path prefix for all API methods

Returns:

  • (Addressable::URI)


101
102
103
# File 'lib/google/apis/core/base_service.rb', line 101

def base_path
  @base_path
end

#batch_pathAddressable::URI

Alternate path prefix for all batch methods

Returns:

  • (Addressable::URI)


109
110
111
# File 'lib/google/apis/core/base_service.rb', line 109

def batch_path
  @batch_path
end

#clientHTTPClient

Get the current HTTP client

Returns:

  • (HTTPClient)


113
114
115
# File 'lib/google/apis/core/base_service.rb', line 113

def client
  @client
end

#client_optionsGoogle::Apis::ClientOptions

General settings



117
118
119
# File 'lib/google/apis/core/base_service.rb', line 117

def client_options
  @client_options
end

#request_optionsGoogle::Apis::RequestOptions

Default options for all requests



121
122
123
# File 'lib/google/apis/core/base_service.rb', line 121

def request_options
  @request_options
end

#root_urlAddressable::URI

Root URL (host/port) for the API

Returns:

  • (Addressable::URI)


97
98
99
# File 'lib/google/apis/core/base_service.rb', line 97

def root_url
  @root_url
end

#upload_pathAddressable::URI

Alternate path prefix for media uploads

Returns:

  • (Addressable::URI)


105
106
107
# File 'lib/google/apis/core/base_service.rb', line 105

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.

Examples:

service.batch do |s|
  s.get_item(id1) do |res, err|
    # process response for 1st call
  end
  # ...
  s.get_item(idN) do |res, err|
    # process response for Nth call
  end
end

Parameters:

Yields:

  • (self)


168
169
170
171
172
173
174
175
176
177
178
179
# File 'lib/google/apis/core/base_service.rb', line 168

def batch(options = nil)
  batch_command = BatchCommand.new(:post, Addressable::URI.parse(root_url + batch_path))
  batch_command.options = request_options.merge(options)
  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.

Examples:

service.batch do |s|
  s.insert_item(upload_source: 'file1.txt') do |res, err|
    # process response for 1st call
  end
  # ...
  s.insert_item(upload_source: 'fileN.txt') do |res, err|
    # process response for Nth call
  end
end

Parameters:

Yields:

  • (self)


200
201
202
203
204
205
206
207
208
209
210
211
# File 'lib/google/apis/core/base_service.rb', line 200

def batch_upload(options = nil)
  batch_command = BatchUploadCommand.new(:put, Addressable::URI.parse(root_url + upload_path))
  batch_command.options = request_options.merge(options)
  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.

Examples:

Retrieve all files,

file_list = service.fetch_all { |token, s| s.list_files(page_token: token) }
file_list.each { |f| ... }

Parameters:

  • max (Fixnum)

    Maximum number of items to iterate over. Defaults to nil -- no upper bound.

  • items (Symbol)

    Name of the field in the result containing the items. Defaults to :items

  • cache (Boolean)

    True (default) if results should be cached so multiple iterations can be used.

Yields:

  • (token, service)

    Current page token & service instance

Yield Parameters:

  • token (String)

    Current page token to be used in the query

Returns:

  • (Enumerble)

Since:

  • 0.9.4



281
282
283
284
# File 'lib/google/apis/core/base_service.rb', line 281

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.)

Parameters:

  • method (Symbol)

    HTTP method as symbol (e.g. :get, :post, :put, ...)

  • url (String)

    URL to call

  • params (Hash<String,String>)

    Optional hash of query parameters

  • body (#read)

    Optional body for POST/PUT

  • download_dest (IO, String)

    IO stream or filename to receive content download

  • options (Google::Apis::RequestOptions)

    Request-specific options

Yields:

  • (result, err)

    Result & error if block supplied

Yield Parameters:

  • result (String)

    HTTP response body

  • err (StandardError)

    error object if request failed

Returns:

  • (String)

    HTTP response body



243
244
245
246
247
248
249
250
251
252
253
# File 'lib/google/apis/core/base_service.rb', line 243

def http(method, url, params: nil, body: nil, download_dest: nil, options: nil, &block)
  if download_dest
    command = DownloadCommand.new(method, url, body: body)
  else
    command = HttpCommand.new(method, url, body: body)
  end
  command.options = request_options.merge(options)
  apply_command_defaults(command)
  command.query.merge(Hash(params))
  execute_or_queue_command(command, &block)
end