Class: AdcenterApi::CredentialHandler

Inherits:
AdsCommonForAdcenter::CredentialHandler
  • Object
show all
Defined in:
lib/adcenter_api/credential_handler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ CredentialHandler

Returns a new instance of CredentialHandler.



12
13
14
15
16
17
# File 'lib/adcenter_api/credential_handler.rb', line 12

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.



10
11
12
# File 'lib/adcenter_api/credential_handler.rb', line 10

def partial_failure
  @partial_failure
end

#use_mccObject

Whether we’re making MCC-level requests.



6
7
8
# File 'lib/adcenter_api/credential_handler.rb', line 6

def use_mcc
  @use_mcc
end

#validate_onlyObject

Whether we’re making validate-only requests.



8
9
10
# File 'lib/adcenter_api/credential_handler.rb', line 8

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.



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/adcenter_api/credential_handler.rb', line 21

def credentials(credentials_override = nil)
  result = super(credentials_override)
  #puts "credentials result=\n#{result}"
  validate_headers_for_server(result)

  extra_headers = {
    'userAgent' => generate_user_agent(),
    'developerToken' => result[:developer_token]
  }
  if !@use_mcc and result[:client_customer_id]
    extra_headers['clientCustomerId'] = result[:client_customer_id]
  end
  extra_headers['validateOnly'] = 'true' if @validate_only
  extra_headers['partialFailure'] = 'true' if @partial_failure
  result[:extra_headers] = extra_headers
  #puts "credentials result2=\n#{result}"
  return result
end

#generate_user_agent(extra_ids = []) ⇒ Object

Generates string to use as user agent in headers.



41
42
43
44
45
# File 'lib/adcenter_api/credential_handler.rb', line 41

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