Class: AdwordsApi::CredentialHandler

Inherits:
AdsCommon::CredentialHandler
  • Object
show all
Defined in:
lib/adwords_api/credential_handler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ CredentialHandler

Returns a new instance of CredentialHandler.



30
31
32
33
34
# File 'lib/adwords_api/credential_handler.rb', line 30

def initialize(config)
  super(config)
  @validate_only = false
  @partial_failure = false
end

Instance Attribute Details

#partial_failureObject

Whether we’re making partial failure requests.



28
29
30
# File 'lib/adwords_api/credential_handler.rb', line 28

def partial_failure
  @partial_failure
end

#validate_onlyObject

Whether we’re making validate-only requests.



26
27
28
# File 'lib/adwords_api/credential_handler.rb', line 26

def validate_only
  @validate_only
end

Instance Method Details

#credentials(credentials_override = nil) ⇒ Object

Create the list of credentials to be used by the auth handler for header generation.



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/adwords_api/credential_handler.rb', line 38

def credentials(credentials_override = nil)
  result = super(credentials_override)
  validate_headers_for_server(result)

  extra_headers = {
    'userAgent' => generate_user_agent(),
    'developerToken' => result[:developer_token]
  }
  extra_headers['clientCustomerId'] = result[:client_customer_id] if
      result[:client_customer_id]
  extra_headers['validateOnly'] = 'true' if @validate_only
  extra_headers['partialFailure'] = 'true' if @partial_failure
  result[:extra_headers] = extra_headers
  return result
end

#generate_user_agent(extra_ids = []) ⇒ Object

Generates string to use as user agent in headers.



55
56
57
58
59
# File 'lib/adwords_api/credential_handler.rb', line 55

def generate_user_agent(extra_ids = [])
  agent_app = @config.read('authentication.user_agent')
  extra_ids << ['AwApi-Ruby/%s' % AdwordsApi::ApiConfig::CLIENT_LIB_VERSION]
  super(extra_ids, agent_app)
end