Class: AdwordsApi::ReportHeaderHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/adwords_api/report_header_handler.rb

Instance Method Summary collapse

Constructor Details

#initialize(credential_handler, auth_handler, config) ⇒ ReportHeaderHandler

Initializes a header handler.

Args:

- credential_handler: a header with credential data
- auth_handler: a header with auth data
- config: API config


32
33
34
35
36
# File 'lib/adwords_api/report_header_handler.rb', line 32

def initialize(credential_handler, auth_handler, config)
  @credential_handler = credential_handler
  @auth_handler = auth_handler
  @config = config
end

Instance Method Details

#headers(url, cid) ⇒ Object

Returns the headers set for the report request.

Args:

- url: URL for the report requests
- cid: clientCustomerId to use

Returns:

- a Hash with HTTP headers.


47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/adwords_api/report_header_handler.rb', line 47

def headers(url, cid)
  override = (cid.nil?) ? nil : {:client_customer_id => cid}
  credentials = @credential_handler.credentials(override)
  headers = {
      'Content-Type' => 'application/x-www-form-urlencoded',
      'Authorization' => @auth_handler.auth_string(credentials),
      'User-Agent' => @credential_handler.generate_user_agent(),
      'clientCustomerId' => credentials[:client_customer_id].to_s,
      'developerToken' => credentials[:developer_token]
  }
  money_in_micros = @config.read('library.return_money_in_micros')
  unless money_in_micros.nil?
    headers['returnMoneyInMicros'] = money_in_micros.to_s
  end
  return headers
end