Module providing the mechanism to obtain auth tokens for logging in to the AdWords API (>= v200902).
Methods
Constants
ACCOUNT_TYPE | = | 'GOOGLE' |
AUTH_HOSTNAME | = | 'www.google.com' |
AUTH_PATH | = | '/accounts/ClientLogin' |
AUTH_PORT | = | 443 |
SERVICE | = | 'adwords' |
Class Public methods
Retrieve authentication token for logging in to the AdWords API.
Args:
- email: the email address for the account being accessed
- password: the password for the account being accessed
Returns: The auth token for the account (as a string).
Raises: AdWords::Error::AuthError if authentication fails.
Source: show
# File lib/adwords4r/authtoken.rb, line 48 def self.get_token(email, password) email = CGI.escape(email) password = CGI.escape(password) http_client = Net::HTTP.new(AUTH_HOSTNAME, AUTH_PORT) http_client.use_ssl = true # Avoid annoying warning http_client.verify_mode = OpenSSL::SSL::VERIFY_NONE data = "accountType=#{ACCOUNT_TYPE}&Email=#{email}&Passwd=#{password}" + "&service=#{SERVICE}" headers = {'Content-Type' => 'application/x-www-form-urlencoded'} response = http_client.post(AUTH_PATH, data, headers) if response.code == '200' return response.body[/Auth=(.*)/, 1] else raise AdWords::Error::AuthError, "Login failed for email %s: %s (code %d)" % [CGI.unescape(email), response.message, response.code] end end