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.



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

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

Instance Attribute Details

#partial_failureObject

Whether we’re making partial failure requests.



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

def partial_failure
  @partial_failure
end

#use_mccObject

Whether we’re making MCC-level requests.



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

def use_mcc
  @use_mcc
end

#validate_onlyObject

Whether we’re making validate-only requests.



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

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.



44
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
75
76
77
78
79
80
# File 'lib/adwords_api/credential_handler.rb', line 44

def credentials(version = nil)
  validate_headers_for_server(version)
  result = case @credentials[:method]
    when :CLIENTLOGIN
      {:email => @credentials[:email],
       :password => @credentials[:password],
       :logintoken => @credentials[:logintoken],
       :logincaptcha => @credentials[:logincaptcha]}
    when :OAUTH
      {:oauth_consumer_key => @credentials[:oauth_consumer_key],
       :oauth_consumer_secret => @credentials[:oauth_consumer_secret],
       :oauth_verification_code => @credentials[:oauth_verification_code],
       :oauth_token => @credentials[:oauth_token],
       :oauth_token_secret => @credentials[:oauth_token_secret],
       :oauth_callback => @credentials[:oauth_callback],
       :oauth_method => @credentials[:oauth_method],
       :oauth_request_token => @credentials[:oauth_request_token]}
  end
  client_lib = 'AwApi-Ruby-%s|' % AdwordsApi::ApiConfig::CLIENT_LIB_VERSION
  user_agent = @credentials[:user_agent] || $0
  user_agent = client_lib + user_agent
  user_agent_symbol = (version == :v13) ? :useragent : :userAgent
  result[user_agent_symbol] = user_agent
  result[:developerToken] = @credentials[:developer_token]
  unless @use_mcc
    if @credentials[:client_customer_id]
      result[:clientCustomerId] = @credentials[:client_customer_id]
    elsif @credentials[:client_email] and version != :v201109
      result[:clientEmail] = @credentials[:client_email]
    end
  end
  if version != :v13
    result[:validateOnly] = 'true' if @validate_only
    result[:partialFailure] = 'true' if @partial_failure
  end
  return result.reject {|k,v| v.nil?}
end