AI-generated Key Takeaways
-
Use the
google-ads-ad_managerRuby client library and RubyGems to interact with the Ad Manager API. -
Authenticate using OAuth2 and Application Default Credentials (ADC), configuring credentials via environment variables, gcloud CLI, or Google Cloud service accounts.
-
Make API requests by creating a client object and request, then calling the corresponding method.
-
Log HTTP requests and responses by setting the
GOOGLE_SDK_RUBY_LOGGING_GEMSenvironment variable or configuring the logger in your code. -
Handle Ad Manager API errors which are subclasses of
::Google::Cloud::Errorand can include a uniquerequest_idfor troubleshooting.
Google provides a Ruby client library for interacting with the Ad Manager API. We recommend using the client library with RubyGems.
To get started, create a new project in the IDE of your choice or add the
dependency to an existing project. Google publishes client library to
RubyGems as google-ads-ad_manager
.
Gemfile:
gem 'google-ads-ad_manager', '~> 0.1.0'
Install directly:
gem
install
google-ads-ad_manager
Configure credentials
The Ruby client library uses OAuth2 and Application Default Credentials (ADC) to authenticate.
ADC searches for credentials in order in the following locations:
-
GOOGLE_APPLICATION_CREDENTIALSenvironment variable. - User credentials set up through the Google Cloud CLI (gcloud CLI).
- When running on Google Cloud, the service account attached to the Google Cloud resource.
For creating and configuring your ADC credentials, see Authentication .
Make your first request
Each REST service has a has a corresponding Ruby class with methods for each
corresponding REST method. The following example reads a Network
.
require
"google/ads/ad_manager/v1"
def
get_network
# Create a client object. The client can be reused for multiple calls.
client
=
Google
::
Ads
::
AdManager
::
V1
::
NetworkService
::
Rest
::
Client
.
new
# Create a request. To set request fields, pass in keyword arguments.
request
=
Google
::
Ads
::
AdManager
::
V1
::
GetNetworkRequest
.
new
(
name
:
=>
'networks/ NETWORK_CODE
)'
# Call the get_network method.
result
=
client
.
get_network
request
# The returned object is of type Google::Ads::AdManager::V1::Network.
p
result
end
.
rb

