Class: AdwordsApi::CredentialHandler

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

Constant Summary collapse

SERVICE_NAME =
'adwords'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ CredentialHandler

Returns a new instance of CredentialHandler.



36
37
38
39
40
41
# File 'lib/adwords_api/credential_handler.rb', line 36

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

Instance Attribute Details

#partial_failureObject

Whether we’re making partial failure requests.



34
35
36
# File 'lib/adwords_api/credential_handler.rb', line 34

def partial_failure
  @partial_failure
end

#use_mccObject

Whether we’re making MCC-level requests.



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

def use_mcc
  @use_mcc
end

#validate_onlyObject

Whether we’re making validate-only requests.



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

def validate_only
  @validate_only
end

Instance Method Details

#credentials(version = nil) ⇒ Object

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



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/adwords_api/credential_handler.rb', line 45

def credentials(version = nil)
  validate_headers_for_server
  result = {}
  client_lib = 'Ruby-AwApi-%s|' % AdwordsApi::ApiConfig::CLIENT_LIB_VERSION
  user_agent = @credentials[:user_agent]
  user_agent = $0 if user_agent.nil?
  user_agent = client_lib + user_agent
  if (version == :v13)
    result[:useragent] = user_agent
  else
    result[:userAgent] = user_agent
  end
  result[:email] = @credentials[:email]
  result[:password] = @credentials[:password]
  result[:developerToken] = @credentials[:developer_token]
  unless @use_mcc
    if @credentials[:client_email]
      result[:clientEmail] = @credentials[:client_email]
    elsif @credentials[:client_customer_id]
      result[:clientCustomerId] = @credentials[:client_customer_id]
    end
  end
  if version != :v13 and @validate_only
    result[:validateOnly] = 'true'
  end
  if version != :v13 and @partial_failure
    result[:partialFailure] = 'true'
  end
  return result
end