Class: Google::Ads::GoogleAds::V5::Services::GoogleAdsService::Client

Inherits:
Object
  • Object
show all
Includes:
Paths
Defined in:
lib/google/ads/google_ads/v5/services/google_ads_service/client.rb

Overview

Client for the GoogleAdsService service.

Service to fetch data and metrics across resources.

Defined Under Namespace

Classes: Configuration

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Paths

#account_budget_path, #account_budget_proposal_path, #account_link_path, #ad_group_ad_asset_view_path, #ad_group_ad_label_path, #ad_group_ad_path, #ad_group_audience_view_path, #ad_group_bid_modifier_path, #ad_group_criterion_label_path, #ad_group_criterion_path, #ad_group_criterion_simulation_path, #ad_group_extension_setting_path, #ad_group_feed_path, #ad_group_label_path, #ad_group_path, #ad_group_simulation_path, #ad_parameter_path, #ad_path, #ad_schedule_view_path, #age_range_view_path, #asset_path, #batch_job_path, #bidding_strategy_path, #billing_setup_path, #campaign_asset_path, #campaign_audience_view_path, #campaign_bid_modifier_path, #campaign_budget_path, #campaign_criterion_path, #campaign_criterion_simulation_path, #campaign_draft_path, #campaign_experiment_path, #campaign_extension_setting_path, #campaign_feed_path, #campaign_label_path, #campaign_path, #campaign_shared_set_path, #carrier_constant_path, #change_status_path, #click_view_path, #conversion_action_path, #currency_constant_path, #custom_interest_path, #customer_client_link_path, #customer_client_path, #customer_extension_setting_path, #customer_feed_path, #customer_label_path, #customer_manager_link_path, #customer_negative_criterion_path, #customer_path, #detail_placement_view_path, #display_keyword_view_path, #distance_view_path, #domain_category_path, #dynamic_search_ads_search_term_view_path, #expanded_landing_page_view_path, #extension_feed_item_path, #feed_item_path, #feed_item_target_path, #feed_mapping_path, #feed_path, #feed_placeholder_view_path, #gender_view_path, #geo_target_constant_path, #geographic_view_path, #group_placement_view_path, #hotel_group_view_path, #hotel_performance_view_path, #income_range_view_path, #keyword_plan_ad_group_keyword_path, #keyword_plan_ad_group_path, #keyword_plan_campaign_keyword_path, #keyword_plan_campaign_path, #keyword_plan_path, #keyword_view_path, #label_path, #landing_page_view_path, #language_constant_path, #location_view_path, #managed_placement_view_path, #media_file_path, #mobile_app_category_constant_path, #mobile_device_constant_path, #offline_user_data_job_path, #operating_system_version_constant_path, #paid_organic_search_term_view_path, #parental_status_view_path, #payments_account_path, #product_bidding_category_constant_path, #product_group_view_path, #recommendation_path, #remarketing_action_path, #search_term_view_path, #shared_criterion_path, #shared_set_path, #shopping_performance_view_path, #third_party_app_analytics_link_path, #topic_constant_path, #topic_view_path, #user_interest_path, #user_list_path, #user_location_view_path, #video_path

Constructor Details

#initialize {|config| ... } ⇒ Client

Create a new GoogleAdsService client object.

## Examples

To create a new GoogleAdsService client with the default configuration:

client = ::Google::Ads::GoogleAds::V5::Services::GoogleAdsService::Client.new

To create a new GoogleAdsService client with a custom configuration:

client = ::Google::Ads::GoogleAds::V5::Services::GoogleAdsService::Client.new do |config|
  config.timeout = 10.0
end

Yields:

  • (config)

    Configure the GoogleAdsService client.

Yield Parameters:



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'lib/google/ads/google_ads/v5/services/google_ads_service/client.rb', line 118

def initialize
  # These require statements are intentionally placed here to initialize
  # the gRPC module only when it's required.
  # See https://github.com/googleapis/toolkit/issues/446
  require "gapic/grpc"
  require "google/ads/google_ads/v5/services/google_ads_service_services_pb"

  # Create the configuration object
  @config = Configuration.new Client.configure

  # Yield the configuration if needed
  yield @config if block_given?

  # Create credentials
  credentials = @config.credentials
  credentials ||= Credentials.default scope: @config.scope
  if credentials.is_a?(String) || credentials.is_a?(Hash)
    credentials = Credentials.new credentials, scope: @config.scope
  end
  @quota_project_id = @config.quota_project
  @quota_project_id ||= credentials.quota_project_id if credentials.respond_to? :quota_project_id

  @google_ads_service_stub = ::Gapic::ServiceStub.new(
    ::Google::Ads::GoogleAds::V5::Services::GoogleAdsService::Stub,
    credentials:  credentials,
    endpoint:     @config.endpoint,
    channel_args: @config.channel_args,
    interceptors: @config.interceptors
  )
end

Instance Attribute Details



37
38
39
# File 'lib/google/ads/google_ads/v5/services/google_ads_service/client.rb', line 37

def google_ads_service_stub
  @google_ads_service_stub
end

Class Method Details

.configure {|config| ... } ⇒ Client::Configuration

Configure the GoogleAdsService Client class.

See Configuration for a description of the configuration fields.

## Example

To modify the configuration for all GoogleAdsService clients:

::Google::Ads::GoogleAds::V5::Services::GoogleAdsService::Client.configure do |config|
  config.timeout = 10.0
end

Yields:

  • (config)

    Configure the Client client.

Yield Parameters:

Returns:



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/google/ads/google_ads/v5/services/google_ads_service/client.rb', line 58

def self.configure
  @configure ||= begin
    default_config = Client::Configuration.new

    default_config.timeout = 3600.0
    default_config.retry_policy = {
      initial_delay: 5.0,
      max_delay:     60.0,
      multiplier:    1.3,
      retry_codes:   [14, 4]
    }

    default_config.rpcs.search_stream.timeout = 3600.0

    default_config
  end
  yield @configure if block_given?
  @configure
end

Instance Method Details

#configure {|config| ... } ⇒ Client::Configuration

Configure the GoogleAdsService Client instance.

The configuration is set to the derived mode, meaning that values can be changed, but structural changes (adding new fields, etc.) are not allowed. Structural changes should be made on configure.

See Configuration for a description of the configuration fields.

Yields:

  • (config)

    Configure the Client client.

Yield Parameters:

Returns:



93
94
95
96
# File 'lib/google/ads/google_ads/v5/services/google_ads_service/client.rb', line 93

def configure
  yield @config if block_given?
  @config
end

#mutate(request, options = nil) ⇒ ::Google::Ads::GoogleAds::V5::Services::MutateGoogleAdsResponse #mutate(customer_id: nil, mutate_operations: nil, partial_failure: nil, validate_only: nil, response_content_type: nil) ⇒ ::Google::Ads::GoogleAds::V5::Services::MutateGoogleAdsResponse

Creates, updates, or removes resources. This method supports atomic transactions with multiple types of resources. For example, you can atomically create a campaign and a campaign budget, or perform up to thousands of mutates atomically.

This method is essentially a wrapper around a series of mutate methods. The only features it offers over calling those methods directly are:

  • Atomic transactions

  • Temp resource names (described below)

  • Somewhat reduced latency over making a series of mutate calls

Note: Only resources that support atomic transactions are included, so this method can’t replace all calls to individual services.

## Atomic Transaction Benefits

Atomicity makes error handling much easier. If you’re making a series of changes and one fails, it can leave your account in an inconsistent state. With atomicity, you either reach the desired state directly, or the request fails and you can retry.

## Temp Resource Names

Temp resource names are a special type of resource name used to create a resource and reference that resource in the same request. For example, if a campaign budget is created with ‘resource_name` equal to `customers/123/campaignBudgets/-1`, that resource name can be reused in the `Campaign.budget` field in the same request. That way, the two resources are created and linked atomically.

To create a temp resource name, put a negative number in the part of the name that the server would normally allocate.

Note:

  • Resources must be created with a temp name before the name can be reused. For example, the previous CampaignBudget+Campaign example would fail if the mutate order was reversed.

  • Temp names are not remembered across requests.

  • There’s no limit to the number of temp names in a request.

  • Each temp name must use a unique negative number, even if the resource types differ.

## Latency

It’s important to group mutates by resource type or the request may time out and fail. Latency is roughly equal to a series of calls to individual mutate methods, where each change in resource type is a new call. For example, mutating 10 campaigns then 10 ad groups is like 2 calls, while mutating 1 campaign, 1 ad group, 1 campaign, 1 ad group is like 4 calls.

Overloads:

  • #mutate(request, options = nil) ⇒ ::Google::Ads::GoogleAds::V5::Services::MutateGoogleAdsResponse

    Pass arguments to ‘mutate` via a request object, either of type MutateGoogleAdsRequest or an equivalent Hash.

    Parameters:

    • request (::Google::Ads::GoogleAds::V5::Services::MutateGoogleAdsRequest, ::Hash)

      A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.

    • options (::Gapic::CallOptions, ::Hash) (defaults to: nil)

      Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.

  • #mutate(customer_id: nil, mutate_operations: nil, partial_failure: nil, validate_only: nil, response_content_type: nil) ⇒ ::Google::Ads::GoogleAds::V5::Services::MutateGoogleAdsResponse

    Pass arguments to ‘mutate` via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).

    Parameters:

    • customer_id (::String) (defaults to: nil)

      Required. The ID of the customer whose resources are being modified.

    • mutate_operations (::Array<::Google::Ads::GoogleAds::V5::Services::MutateOperation, ::Hash>) (defaults to: nil)

      Required. The list of operations to perform on individual resources.

    • partial_failure (::Boolean) (defaults to: nil)

      If true, successful operations will be carried out and invalid operations will return errors. If false, all operations will be carried out in one transaction if and only if they are all valid. Default is false.

    • validate_only (::Boolean) (defaults to: nil)

      If true, the request is validated but not executed. Only errors are returned, not results.

    • response_content_type (::Google::Ads::GoogleAds::V5::Enums::ResponseContentTypeEnum::ResponseContentType) (defaults to: nil)

      The response content type setting. Determines whether the mutable resource or just the resource name should be returned post mutation. The mutable resource will only be returned if the resource has the appropriate response field. E.g. MutateCampaignResult.campaign.

Yields:

  • (response, operation)

    Access the result along with the RPC operation

Yield Parameters:

Returns:

Raises:

  • (Google::Ads::GoogleAds::Error)

    if the RPC is aborted.



405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
# File 'lib/google/ads/google_ads/v5/services/google_ads_service/client.rb', line 405

def mutate request, options = nil
  raise ::ArgumentError, "request must be provided" if request.nil?

  request = ::Gapic::Protobuf.coerce request, to: ::Google::Ads::GoogleAds::V5::Services::MutateGoogleAdsRequest

  # Converts hash and nil to an options object
  options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h

  # Customize the options with defaults
   = @config.rpcs.mutate..to_h

  # Set x-goog-api-client and x-goog-user-project headers
  [:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
    lib_name: @config.lib_name, lib_version: @config.lib_version,
    gapic_version: ::Google::Ads::GoogleAds::VERSION
  [:"x-goog-user-project"] = @quota_project_id if @quota_project_id

  header_params = {
    "customer_id" => request.customer_id
  }
  request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&")
  [:"x-goog-request-params"] ||= request_params_header

  options.apply_defaults timeout:      @config.rpcs.mutate.timeout,
                         metadata:     ,
                         retry_policy: @config.rpcs.mutate.retry_policy
  options.apply_defaults metadata:     @config.,
                         retry_policy: @config.retry_policy

  @google_ads_service_stub.call_rpc :mutate, request, options: options do |response, operation|
    yield response, operation if block_given?
    return response
  end
  # rescue GRPC::BadStatus => grpc_error
  #  raise Google::Ads::GoogleAds::Error.new grpc_error.message
end

#search(request, options = nil) ⇒ ::Gapic::PagedEnumerable<::Google::Ads::GoogleAds::V5::Services::GoogleAdsRow> #search(customer_id: nil, query: nil, page_token: nil, page_size: nil, validate_only: nil, return_total_results_count: nil, summary_row_setting: nil) ⇒ ::Gapic::PagedEnumerable<::Google::Ads::GoogleAds::V5::Services::GoogleAdsRow>

Returns all rows that match the search query.

Overloads:

  • #search(request, options = nil) ⇒ ::Gapic::PagedEnumerable<::Google::Ads::GoogleAds::V5::Services::GoogleAdsRow>

    Pass arguments to ‘search` via a request object, either of type SearchGoogleAdsRequest or an equivalent Hash.

    Parameters:

    • request (::Google::Ads::GoogleAds::V5::Services::SearchGoogleAdsRequest, ::Hash)

      A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.

    • options (::Gapic::CallOptions, ::Hash) (defaults to: nil)

      Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.

  • #search(customer_id: nil, query: nil, page_token: nil, page_size: nil, validate_only: nil, return_total_results_count: nil, summary_row_setting: nil) ⇒ ::Gapic::PagedEnumerable<::Google::Ads::GoogleAds::V5::Services::GoogleAdsRow>

    Pass arguments to ‘search` via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).

    Parameters:

    • customer_id (::String) (defaults to: nil)

      Required. The ID of the customer being queried.

    • query (::String) (defaults to: nil)

      Required. The query string.

    • page_token (::String) (defaults to: nil)

      Token of the page to retrieve. If not specified, the first page of results will be returned. Use the value obtained from ‘next_page_token` in the previous response in order to request the next page of results.

    • page_size (::Integer) (defaults to: nil)

      Number of elements to retrieve in a single page. When too large a page is requested, the server may decide to further limit the number of returned resources.

    • validate_only (::Boolean) (defaults to: nil)

      If true, the request is validated but not executed.

    • return_total_results_count (::Boolean) (defaults to: nil)

      If true, the total number of results that match the query ignoring the LIMIT clause will be included in the response. Default is false.

    • summary_row_setting (::Google::Ads::GoogleAds::V5::Enums::SummaryRowSettingEnum::SummaryRowSetting) (defaults to: nil)

      Determines whether a summary row will be returned. By default, summary row is not returned. If requested, the summary row will be sent in a response by itself after all other query results are returned.

Yields:

  • (response, operation)

    Access the result along with the RPC operation

Yield Parameters:

Returns:

Raises:

  • (Google::Ads::GoogleAds::Error)

    if the RPC is aborted.



201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
# File 'lib/google/ads/google_ads/v5/services/google_ads_service/client.rb', line 201

def search request, options = nil
  raise ::ArgumentError, "request must be provided" if request.nil?

  request = ::Gapic::Protobuf.coerce request, to: ::Google::Ads::GoogleAds::V5::Services::SearchGoogleAdsRequest

  # Converts hash and nil to an options object
  options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h

  # Customize the options with defaults
   = @config.rpcs.search..to_h

  # Set x-goog-api-client and x-goog-user-project headers
  [:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
    lib_name: @config.lib_name, lib_version: @config.lib_version,
    gapic_version: ::Google::Ads::GoogleAds::VERSION
  [:"x-goog-user-project"] = @quota_project_id if @quota_project_id

  header_params = {
    "customer_id" => request.customer_id
  }
  request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&")
  [:"x-goog-request-params"] ||= request_params_header

  options.apply_defaults timeout:      @config.rpcs.search.timeout,
                         metadata:     ,
                         retry_policy: @config.rpcs.search.retry_policy
  options.apply_defaults metadata:     @config.,
                         retry_policy: @config.retry_policy

  @google_ads_service_stub.call_rpc :search, request, options: options do |response, operation|
    response = ::Gapic::PagedEnumerable.new @google_ads_service_stub, :search, request, response, operation, options
    yield response, operation if block_given?
    return response
  end
  # rescue GRPC::BadStatus => grpc_error
  #  raise Google::Ads::GoogleAds::Error.new grpc_error.message
end

#search_stream(request, options = nil) ⇒ ::Enumerable<::Google::Ads::GoogleAds::V5::Services::SearchGoogleAdsStreamResponse> #search_stream(customer_id: nil, query: nil, summary_row_setting: nil) ⇒ ::Enumerable<::Google::Ads::GoogleAds::V5::Services::SearchGoogleAdsStreamResponse>

Returns all rows that match the search stream query.

Overloads:

  • #search_stream(request, options = nil) ⇒ ::Enumerable<::Google::Ads::GoogleAds::V5::Services::SearchGoogleAdsStreamResponse>

    Pass arguments to ‘search_stream` via a request object, either of type SearchGoogleAdsStreamRequest or an equivalent Hash.

    Parameters:

    • request (::Google::Ads::GoogleAds::V5::Services::SearchGoogleAdsStreamRequest, ::Hash)

      A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.

    • options (::Gapic::CallOptions, ::Hash) (defaults to: nil)

      Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.

  • #search_stream(customer_id: nil, query: nil, summary_row_setting: nil) ⇒ ::Enumerable<::Google::Ads::GoogleAds::V5::Services::SearchGoogleAdsStreamResponse>

    Pass arguments to ‘search_stream` via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).

    Parameters:

    • customer_id (::String) (defaults to: nil)

      Required. The ID of the customer being queried.

    • query (::String) (defaults to: nil)

      Required. The query string.

    • summary_row_setting (::Google::Ads::GoogleAds::V5::Enums::SummaryRowSettingEnum::SummaryRowSetting) (defaults to: nil)

      Determines whether a summary row will be returned. By default, summary row is not returned. If requested, the summary row will be sent in a response by itself after all other query results are returned.

Yields:

  • (response, operation)

    Access the result along with the RPC operation

Yield Parameters:

Returns:

Raises:

  • (Google::Ads::GoogleAds::Error)

    if the RPC is aborted.



274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
# File 'lib/google/ads/google_ads/v5/services/google_ads_service/client.rb', line 274

def search_stream request, options = nil
  raise ::ArgumentError, "request must be provided" if request.nil?

  request = ::Gapic::Protobuf.coerce request, to: ::Google::Ads::GoogleAds::V5::Services::SearchGoogleAdsStreamRequest

  # Converts hash and nil to an options object
  options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h

  # Customize the options with defaults
   = @config.rpcs.search_stream..to_h

  # Set x-goog-api-client and x-goog-user-project headers
  [:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
    lib_name: @config.lib_name, lib_version: @config.lib_version,
    gapic_version: ::Google::Ads::GoogleAds::VERSION
  [:"x-goog-user-project"] = @quota_project_id if @quota_project_id

  header_params = {
    "customer_id" => request.customer_id
  }
  request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&")
  [:"x-goog-request-params"] ||= request_params_header

  options.apply_defaults timeout:      @config.rpcs.search_stream.timeout,
                         metadata:     ,
                         retry_policy: @config.rpcs.search_stream.retry_policy
  options.apply_defaults metadata:     @config.,
                         retry_policy: @config.retry_policy

  @google_ads_service_stub.call_rpc :search_stream, request, options: options do |response, operation|
    yield response, operation if block_given?
    return response
  end
  # rescue GRPC::BadStatus => grpc_error
  #  raise Google::Ads::GoogleAds::Error.new grpc_error.message
end