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.
193 194 195 |
# File 'lib/google/ads/google_ads/google_ads_client.rb', line 193 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.
199 200 201 |
# File 'lib/google/ads/google_ads/google_ads_client.rb', line 199 def decode_warning(warning) StatusDecoder.decode(warning) end |
#endpoint ⇒ Object
130 131 132 |
# File 'lib/google/ads/google_ads/google_ads_client.rb', line 130 def endpoint target.split(":443").first end |
#enum ⇒ Object
170 171 172 |
# File 'lib/google/ads/google_ads/google_ads_client.rb', line 170 def enum Factories.version_alternate_for(:enums) end |
#field_mask ⇒ Object
Returns a reference to the FieldMaskUtil class for ease of access.
175 176 177 |
# File 'lib/google/ads/google_ads/google_ads_client.rb', line 175 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 |
# 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) end |
#make_channel ⇒ Object
139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/google/ads/google_ads/google_ads_client.rb', line 139 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
166 167 168 |
# File 'lib/google/ads/google_ads/google_ads_client.rb', line 166 def operation Factories.version_alternate_for(:operations) end |
#patch_lro_headers(class_to_return, headers) ⇒ Object
154 155 156 |
# File 'lib/google/ads/google_ads/google_ads_client.rb', line 154 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.
180 181 182 |
# File 'lib/google/ads/google_ads/google_ads_client.rb', line 180 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.
162 163 164 |
# File 'lib/google/ads/google_ads/google_ads_client.rb', line 162 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.
119 120 121 122 123 124 125 126 127 128 |
# File 'lib/google/ads/google_ads/google_ads_client.rb', line 119 def service ServiceLookup.new( lookup_util, @logger, @config, make_channel, endpoint, deprecator, ).call end |
#target ⇒ Object
134 135 136 137 |
# File 'lib/google/ads/google_ads/google_ads_client.rb', line 134 def target default_target = "googleads.googleapis.com:443" target = @config.api_endpoint || default_target end |