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.
55 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 |
# File 'lib/google/ads/google_ads/google_ads_client.rb', line 55 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.
51 52 53 |
# File 'lib/google/ads/google_ads/google_ads_client.rb', line 51 def logger @logger end |
#lookup_util=(value) ⇒ Object
Allow setting the lookup_util manually for users who use it before creating the client.
53 54 55 |
# File 'lib/google/ads/google_ads/google_ads_client.rb', line 53 def lookup_util=(value) @lookup_util = value end |
Instance Method Details
#configure {|@config| ... } ⇒ Object
92 93 94 |
# File 'lib/google/ads/google_ads/google_ads_client.rb', line 92 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.
191 192 193 |
# File 'lib/google/ads/google_ads/google_ads_client.rb', line 191 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.
197 198 199 |
# File 'lib/google/ads/google_ads/google_ads_client.rb', line 197 def decode_warning(warning) StatusDecoder.decode(warning) end |
#endpoint ⇒ Object
128 129 130 |
# File 'lib/google/ads/google_ads/google_ads_client.rb', line 128 def endpoint target.split(":443").first end |
#enum ⇒ Object
168 169 170 |
# File 'lib/google/ads/google_ads/google_ads_client.rb', line 168 def enum Factories.version_alternate_for(:enums) end |
#field_mask ⇒ Object
Returns a reference to the FieldMaskUtil class for ease of access.
173 174 175 |
# File 'lib/google/ads/google_ads/google_ads_client.rb', line 173 def field_mask() Google::Ads::GoogleAds::FieldMaskUtil end |
#load_environment_config ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/google/ads/google_ads/google_ads_client.rb', line 96 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.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
137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/google/ads/google_ads/google_ads_client.rb', line 137 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
164 165 166 |
# File 'lib/google/ads/google_ads/google_ads_client.rb', line 164 def operation Factories.version_alternate_for(:operations) end |
#patch_lro_headers(class_to_return, headers) ⇒ Object
152 153 154 |
# File 'lib/google/ads/google_ads/google_ads_client.rb', line 152 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.
178 179 180 |
# File 'lib/google/ads/google_ads/google_ads_client.rb', line 178 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.
160 161 162 |
# File 'lib/google/ads/google_ads/google_ads_client.rb', line 160 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.
117 118 119 120 121 122 123 124 125 126 |
# File 'lib/google/ads/google_ads/google_ads_client.rb', line 117 def service ServiceLookup.new( lookup_util, @logger, @config, make_channel, endpoint, deprecator, ).call end |
#target ⇒ Object
132 133 134 135 |
# File 'lib/google/ads/google_ads/google_ads_client.rb', line 132 def target default_target = "googleads.googleapis.com:443" target = @config.api_endpoint || default_target end |