Class: Google::Ads::GoogleAds::GoogleAdsClient
- Inherits:
-
Object
- Object
- Google::Ads::GoogleAds::GoogleAdsClient
- Defined in:
- lib/google/ads/google_ads/google_ads_client.rb
Constant Summary collapse
- DEFAULT_CONFIG_FILENAME =
"google_ads_config.rb".freeze
- SCOPE =
"https://www.googleapis.com/auth/adwords".freeze
- MAX_MESSAGE_LENGTH =
"grpc.max_receive_message_length".freeze
- MAX_METADATA_SIZE =
"grpc.max_metadata_size".freeze
Instance Attribute Summary collapse
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#lookup_util ⇒ Object
writeonly
Allow setting the lookup_util manually for users who use it before creating the client.
Instance Method Summary collapse
- #configure {|@config| ... } ⇒ Object
-
#decode_partial_failure_error(pfe) ⇒ Object
Decode a partial failure error from a response.
-
#decode_warning(warning) ⇒ Object
Identical to decoding a partial failure error as above, but duplicated so the client code is easier to follow.
- #endpoint ⇒ Object
- #enum ⇒ Object
-
#field_mask ⇒ Object
Returns a reference to the FieldMaskUtil class for ease of access.
-
#initialize(config_path = nil, &block) ⇒ GoogleAdsClient
constructor
A new instance of GoogleAdsClient.
- #load_environment_config ⇒ Object
- #make_channel ⇒ Object
- #operation ⇒ Object
- #patch_lro_headers(class_to_return, headers) ⇒ Object
-
#path(version = default_api_version) ⇒ Object
Returns a reference to the PathLookupUtil to generate resource names.
-
#resource ⇒ Object
Return a resource or common entity for the provided entity type.
-
#service ⇒ Object
Return a service for the provided entity type.
- #target ⇒ Object
Constructor Details
#initialize(config_path = nil, &block) ⇒ GoogleAdsClient
Returns a new instance of GoogleAdsClient.
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/google/ads/google_ads/google_ads_client.rb', line 56 def initialize(config_path = nil, &block) if block_given? @config = Google::Ads::GoogleAds::Config.new yield @config else if config_path.nil? config_path = ENV.fetch("GOOGLE_ADS_CONFIGURATION_FILE_PATH", File.join(ENV['HOME'], DEFAULT_CONFIG_FILENAME)) end unless File.exist?(config_path) raise ArgumentError, sprintf('No configuration file found at location "%s"', config_path) end file = File.read(config_path) eval_result = eval(file, binding, config_path) unless eval_result.instance_of?(Google::Ads::GoogleAds::Config) raise ArgumentError, sprintf( 'Configuration file did not produce expected type ' + 'Google::Ads::GoogleAds::Config, got "%s" instead', eval_result.class ) end @config = eval_result end begin @logger = create_default_logger rescue STDERR.puts( "Could not create default logger. Check your config file.") end end |
Instance Attribute Details
#logger ⇒ Object
Returns the value of attribute logger.
52 53 54 |
# File 'lib/google/ads/google_ads/google_ads_client.rb', line 52 def logger @logger end |
#lookup_util=(value) ⇒ Object
Allow setting the lookup_util manually for users who use it before creating the client.
54 55 56 |
# File 'lib/google/ads/google_ads/google_ads_client.rb', line 54 def lookup_util=(value) @lookup_util = value end |
Instance Method Details
#configure {|@config| ... } ⇒ Object
93 94 95 |
# File 'lib/google/ads/google_ads/google_ads_client.rb', line 93 def configure(&block) yield @config end |
#decode_partial_failure_error(pfe) ⇒ Object
Decode a partial failure error from a response. See Google::Ads::GoogleAds::PartialFailureErrorDecoder for full documentation.
198 199 200 |
# File 'lib/google/ads/google_ads/google_ads_client.rb', line 198 def decode_partial_failure_error(pfe) StatusDecoder.decode(pfe) end |
#decode_warning(warning) ⇒ Object
Identical to decoding a partial failure error as above, but duplicated so the client code is easier to follow.
204 205 206 |
# File 'lib/google/ads/google_ads/google_ads_client.rb', line 204 def decode_warning(warning) StatusDecoder.decode(warning) end |
#endpoint ⇒ Object
135 136 137 |
# File 'lib/google/ads/google_ads/google_ads_client.rb', line 135 def endpoint target.split(":443").first end |
#enum ⇒ Object
175 176 177 |
# File 'lib/google/ads/google_ads/google_ads_client.rb', line 175 def enum Factories.version_alternate_for(:enums) end |
#field_mask ⇒ Object
Returns a reference to the FieldMaskUtil class for ease of access.
180 181 182 |
# File 'lib/google/ads/google_ads/google_ads_client.rb', line 180 def field_mask() Google::Ads::GoogleAds::FieldMaskUtil end |
#load_environment_config ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/google/ads/google_ads/google_ads_client.rb', line 97 def load_environment_config # Generic variables @config.refresh_token = ENV.fetch("GOOGLE_ADS_REFRESH_TOKEN", @config.refresh_token) @config.client_id = ENV.fetch("GOOGLE_ADS_CLIENT_ID", @config.client_id) @config.client_secret = ENV.fetch("GOOGLE_ADS_CLIENT_SECRET", @config.client_secret) @config.keyfile = ENV.fetch("GOOGLE_ADS_JSON_KEY_FILE_PATH", @config.keyfile) @config.impersonate = ENV.fetch("GOOGLE_ADS_IMPERSONATED_EMAIL", @config.impersonate) @config.use_application_default_credentials = ENV.fetch("GOOGLE_ADS_USE_APPLICATION_DEFAULT_CREDENTIALS", @config.use_application_default_credentials) @config.developer_token = ENV.fetch("GOOGLE_ADS_DEVELOPER_TOKEN", @config.developer_token) @config.login_customer_id = ENV.fetch("GOOGLE_ADS_LOGIN_CUSTOMER_ID", @config.login_customer_id) @config.linked_customer_id = ENV.fetch("GOOGLE_ADS_LINKED_CUSTOMER_ID", @config.linked_customer_id) @config.api_endpoint = ENV.fetch("GOOGLE_ADS_ENDPOINT", @config.api_endpoint) # Client library-specific variables @config.log_level = ENV.fetch("GOOGLE_ADS_RUBY_LOG_LEVEL", @config.log_level) @config.http_proxy = ENV.fetch("GOOGLE_ADS_RUBY_HTTP_PROXY", @config.http_proxy) @config.use_cloud_org_for_api_access = ENV.fetch("GOOGLE_ADS_USE_CLOUD_ORG_FOR_API_ACCESS", @config.use_cloud_org_for_api_access) if @config.use_cloud_org_for_api_access.is_a?(String) @config.use_cloud_org_for_api_access = @config.use_cloud_org_for_api_access.downcase == "true" end @config.gaada = ENV.fetch("GOOGLE_ADS_GAADA", @config.gaada) end |
#make_channel ⇒ Object
144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/google/ads/google_ads/google_ads_client.rb', line 144 def make_channel channel_args = { MAX_MESSAGE_LENGTH => 64*1024*1024, MAX_METADATA_SIZE => 16*1024*1024, } if !@config.use_insecure_channel call_creds = GRPC::Core::CallCredentials.new(get_credentials) chan_creds = GRPC::Core::ChannelCredentials.new.compose(call_creds) GRPC::Core::Channel.new(target, channel_args, chan_creds) else GRPC::Core::Channel.new(target, channel_args, :this_channel_is_insecure) end end |
#operation ⇒ Object
171 172 173 |
# File 'lib/google/ads/google_ads/google_ads_client.rb', line 171 def operation Factories.version_alternate_for(:operations) end |
#patch_lro_headers(class_to_return, headers) ⇒ Object
159 160 161 |
# File 'lib/google/ads/google_ads/google_ads_client.rb', line 159 def patch_lro_headers(class_to_return, headers) PatchLROHeaders.new(class_to_return, headers).call end |
#path(version = default_api_version) ⇒ Object
Returns a reference to the PathLookupUtil to generate resource names.
185 186 187 |
# File 'lib/google/ads/google_ads/google_ads_client.rb', line 185 def path(version = default_api_version) lookup_util.path(version) end |
#resource ⇒ Object
Return a resource or common entity for the provided entity type. For example, passing :Campaign will return an instantiated Campaign.
Raises ArgumentError if no entity can be found for the provided type.
167 168 169 |
# File 'lib/google/ads/google_ads/google_ads_client.rb', line 167 def resource Factories.version_alternate_for(:resources) end |
#service ⇒ Object
Return a service for the provided entity type. For example, passing :Campaign will return an instantiated CampaignServiceClient.
Raises ArgumentError if no service can be found for the provided type.
124 125 126 127 128 129 130 131 132 133 |
# File 'lib/google/ads/google_ads/google_ads_client.rb', line 124 def service ServiceLookup.new( lookup_util, @logger, @config, make_channel, endpoint, deprecator, ).call end |
#target ⇒ Object
139 140 141 142 |
# File 'lib/google/ads/google_ads/google_ads_client.rb', line 139 def target default_target = "googleads.googleapis.com:443" target = @config.api_endpoint || default_target end |