Stay organized with collectionsSave and categorize content based on your preferences.
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 asgoogle-ads-ad_manager.
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, seeAuthentication.
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 aNetwork.
require"google/ads/ad_manager/v1"defget_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_networkrequest# The returned object is of type Google::Ads::AdManager::V1::Network.presultend
The Ruby client library library uses the standardloggerlibrary to log HTTP requests and responses. Logging is disabled by
default.
To enable logging, set the environment variableGOOGLE_SDK_RUBY_LOGGING_GEMSto the valuegoogle-ads-ad_manager. If you use more than one Google API, you
can set the value to a comma-delimited list of client library gem names. The
default logging behavior writes logs to the standard error stream.
Alternatively, you can enable logging in your Ruby code by modifying theloggerconfiguration when constructing a client object.
All Ad Manager API errors are subclasses of::Google::Cloud::Errorin the Ruby client library.
result=client.get_networkrequestrescue::Google::Cloud::Error=>eputs"An error of type#{e.class}occurred with HTTP status#{e.status_code}"
Ad Manager API errors also include a uniquerequest_idyou can
provide tosupportfor assistance with
troubleshooting. The following example extracts therequest_idfrom the errordetails.
The client library provides helper classes for building resource names from
IDs.
require"google/ads/ad_manager/v1"# Constructs a String in the format:# "networks/{networkCode}/orders/{orderId}"order_name=Google::Ads::AdManager::V1::OrderService::Paths::order_path(:network_code=>123,:order=>456)
Configure proxy settings
The Ruby client library respects bothHTTP_PROXYandHTTPS_PROXYenvironment variables.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-28 UTC."],[],[],null,["Google provides a Ruby client library for interacting with the Ad Manager API.\nWe recommend using the client library with RubyGems.\n\nTo get started, create a new project in the IDE of your choice or add the\ndependency to an existing project. Google publishes client library to\nRubyGems as\n[`google-ads-ad_manager`](//rubygems.org/gems/google-ads-ad_manager).\n\nGemfile: \n\n gem 'google-ads-ad_manager', '~\u003e 0.1.0'\n\nInstall directly: \n\n gem install google-ads-ad_manager\n\nConfigure credentials\n\nThe Ruby client library uses OAuth2 and [Application Default Credentials](//cloud.google.com/docs/authentication/application-default-credentials)\n(ADC) to authenticate.\n\nADC searches for credentials in order in the following locations:\n\n1. `GOOGLE_APPLICATION_CREDENTIALS` environment variable.\n2. User credentials set up through the Google Cloud CLI (gcloud CLI).\n3. When running on Google Cloud, the service account attached to the Google Cloud resource.\n\nFor creating and configuring your ADC credentials, see\n[Authentication](/ad-manager/api/beta/authentication).\n\nMake your first request\n\nEach REST service has a has a corresponding Ruby class with methods for each\ncorresponding REST method. The following example reads a\n[`Network`](/ad-manager/api/beta/reference/rest/v1/networks). \n\n require \"google/ads/ad_manager/v1\"\n\n def get_network\n # Create a client object. The client can be reused for multiple calls.\n client = Google::Ads::AdManager::V1::NetworkService::Rest::Client.new\n\n # Create a request. To set request fields, pass in keyword arguments.\n request = Google::Ads::AdManager::V1::GetNetworkRequest.new(name: =\u003e 'networks/\u003cvar label=\"network code\" translate=\"no\"\u003eNETWORK_CODE\u003c/var\u003e)'\n\n # Call the get_network method.\n result = client.get_network request\n\n # The returned object is of type Google::Ads::AdManager::V1::Network.\n p result\n end \n https://github.com/googleapis/google-cloud-ruby/blob/2bb3bb02b9449ba68704169fc83793a3796de3d1/google-ads-ad_manager-v1/snippets/network_service/get_network.rb#L20-L46\n\nFor examples of other methods and resources, see the GitHub repository\n[`googleapis/google-cloud-ruby`](//github.com/googleapis/google-cloud-ruby/tree/main/google-ads-ad_manager-v1/snippets).\n\nLog HTTP requests and responses\n\nThe Ruby client library library uses the standard `logger`\nlibrary to log HTTP requests and responses. Logging is disabled by\ndefault.\n\nTo enable logging, set the environment variable `GOOGLE_SDK_RUBY_LOGGING_GEMS`\nto the value `google-ads-ad_manager`. If you use more than one Google API, you\ncan set the value to a comma-delimited list of client library gem names. The\ndefault logging behavior writes logs to the standard error stream.\n\nAlternatively, you can enable logging in your Ruby code by modifying the\n`logger` configuration when constructing a client object. \n\n require \"google/ads/ad_manager/v1\"\n require \"logger\"\n\n client = ::Google::Ads::AdManager::V1::NetworkService::Rest::Client.new do |config|\n config.logger = Logger.new \"my-app.log\"\n end\n\nHandle errors\n\nAll Ad Manager API errors are subclasses of\n[::Google::Cloud::Error](//cloud.google.com/ruby/docs/reference/google-cloud-errors/latest/Google-Cloud-Error)\nin the Ruby client library. \n\n result = client.get_network request\n rescue ::Google::Cloud::Error =\u003e e\n puts \"An error of type #{e.class} occurred with HTTP status #{e.status_code}\"\n\nAd Manager API errors also include a unique `request_id` you can\nprovide to [support](/ad-manager/api/beta/support) for assistance with\ntroubleshooting. The following example extracts the\n`request_id` from the error `details`. \n\n rescue ::Google::Cloud::Error =\u003e e\n request_info = e.details.find { |detail| detail.is_a?(Google::Rpc::RequestInfo)}\n puts request_info.request_id\n\nConstruct resource names\n\nThe client library provides helper classes for building resource names from\nIDs. \n\n require \"google/ads/ad_manager/v1\"\n\n # Constructs a String in the format:\n # \"networks/{networkCode}/orders/{orderId}\"\n order_name = Google::Ads::AdManager::V1::OrderService::Paths::order_path(:network_code =\u003e 123, :order =\u003e 456)\n\nConfigure proxy settings\n\nThe Ruby client library respects both `HTTP_PROXY` and `HTTPS_PROXY`\nenvironment variables."]]