Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'master' of https://code.google.com/p/google-api-ads-ruby

  • Loading branch information...
commit 040162bd3ba9969351c60e8890393ca41a76bca5 2 parents 6eb61d3 + 7b3ac75
@dklimkin dklimkin authored
Showing with 125 additions and 64 deletions.
  1. +1 −0  adwords_api/ChangeLog
  2. +9 −6 adwords_api/README
  3. +2 −1  adwords_api/adwords_api.yml
  4. +2 −5 adwords_api/examples/adwords_on_rails/README
  5. +1 −1  adwords_api/examples/adwords_on_rails/config/adwords_api.yml
  6. +3 −0  adwords_api/examples/v201206/account_management/create_account.rb
  7. +3 −0  adwords_api/examples/v201206/account_management/get_account_alerts.rb
  8. +3 −0  adwords_api/examples/v201206/account_management/get_account_hierarchy.rb
  9. +3 −0  adwords_api/examples/v201206/account_management/get_client_customer_id.rb
  10. +3 −0  adwords_api/examples/v201206/account_management/get_client_unit_usage.rb
  11. +3 −0  adwords_api/examples/v201206/reporting/parallel_report_download.rb
  12. +3 −0  adwords_api/examples/v201209/account_management/create_account.rb
  13. +3 −0  adwords_api/examples/v201209/account_management/get_account_alerts.rb
  14. +3 −0  adwords_api/examples/v201209/account_management/get_account_hierarchy.rb
  15. +3 −0  adwords_api/examples/v201209/account_management/get_client_customer_id.rb
  16. +3 −0  adwords_api/examples/v201209/account_management/get_client_unit_usage.rb
  17. +3 −0  adwords_api/examples/v201209/reporting/parallel_report_download.rb
  18. +0 −6 adwords_api/lib/adwords_api/api_config.rb
  19. +3 −17 adwords_api/lib/adwords_api/credential_handler.rb
  20. +23 −9 adwords_api/test/adwords_api/test_adwords_api.rb
  21. +0 −8 adwords_api/test/adwords_api/test_api_config.rb
  22. +45 −9 adwords_api/test/adwords_api/test_credential_handler.rb
  23. +3 −2 adwords_api/test/adwords_api/test_report_utils.rb
View
1  adwords_api/ChangeLog
@@ -1,5 +1,6 @@
0.8.0:
- Removed deprecated API versions v201109, v201109_1.
+ - Removed support for deprecated Sandbox, see http://goo.gl/Plu3o
0.7.2:
- Fixed issue #87 specific to ruby1.8.
View
15 adwords_api/README
@@ -105,13 +105,16 @@ Essentially, all you have to do is follow Ruby conventions, and the library will
do the rest. All of the examples are written following this standard.
-=== 2.2 - Using the Sandbox:
+=== 2.2 - Using the Test Account:
-In order to use the sandbox, make sure that the 'environment' parameter under
-'service' in the configuration is set to Sandbox.
- config[:service] = {
- :environment => 'SANDBOX'
- }
+For testing purposes, obtain a Test Account in the production environment. Any
+request against a Test Account inccurs no API units charge. See this guide for
+more details:
+
+ https://developers.google.com/adwords/api/docs/test-accounts
+
+To use the library against a Test Account, set client_customer_id property in
+the configuration file to its client customer ID.
=== 2.3 - Logging:
View
3  adwords_api/adwords_api.yml
@@ -44,7 +44,8 @@
:client_customer_id: INSERT_YOUR_CLIENT_CUSTOMER_ID_HERE
:user_agent: INSERT_YOUR_USER_AGENT_HERE
:service:
- :environment: SANDBOX
+ # Only production environment is available now, see: http://goo.gl/Plu3o
+ :environment: PRODUCTION
:connection:
# Enable to request all responses to be compressed.
:enable_gzip: false
View
7 adwords_api/examples/adwords_on_rails/README
@@ -100,11 +100,8 @@ README:
Production accounts
-------------------
-The AdWords environment (Sandbox vs Production) has to be specified in the
-configuration file.
-
-Note: This demo is capable of accessing production accounts. Be aware that the
-API unit costs of the requests made by the AdWords on Rails application will be
+This demo is capable of accessing production accounts. Be aware that the API
+unit costs of the requests made by the AdWords on Rails application will be
recorded against the developer token specified in the credentials and may be
significant.
View
2  adwords_api/examples/adwords_on_rails/config/adwords_api.yml
@@ -24,7 +24,7 @@
# :client_customer_id: INSERT_YOUR_CLIENT_CUSTOMER_ID_HERE
:user_agent: demo-rails
:service:
- # Environment to access: SANDBOX or PRODUCTION.
+ # Only production environment is available now, see: http://goo.gl/Plu3o
:environment: PRODUCTION
:connection:
# Enable to request all responses to be compressed.
View
3  adwords_api/examples/v201206/account_management/create_account.rb
@@ -21,6 +21,9 @@
# This example illustrates how to create an account. Note by default this
# account will only be accessible via parent MCC.
#
+# Note: This code example uses MCC-level calls and won't work with Test
+# Accounts, see: https://developers.google.com/adwords/api/docs/test-accounts
+#
# Tags: ManagedCustomerService.mutate
require 'adwords_api'
View
3  adwords_api/examples/v201206/account_management/get_account_alerts.rb
@@ -21,6 +21,9 @@
# This example gets all alerts for all clients of an MCC account. The effective
# user (clientCustomerId, or authToken) must be an MCC user to get results.
#
+# Note: This code example uses MCC-level calls and won't work with Test
+# Accounts, see: https://developers.google.com/adwords/api/docs/test-accounts
+#
# Tags: AlertService.get
require 'adwords_api'
View
3  adwords_api/examples/v201206/account_management/get_account_hierarchy.rb
@@ -21,6 +21,9 @@
# This example illustrates how to retrieve the account hierarchy under an
# account.
#
+# Note: This code example uses MCC-level calls and won't work with Test
+# Accounts, see: https://developers.google.com/adwords/api/docs/test-accounts
+#
# Tags: ManagedCustomerService.get
require 'adwords_api'
View
3  adwords_api/examples/v201206/account_management/get_client_customer_id.rb
@@ -22,6 +22,9 @@
# We recommend to use this script as a one off to convert your identifiers to
# IDs and store them for future use.
#
+# Note: This code example uses MCC-level calls and won't work with Test
+# Accounts, see: https://developers.google.com/adwords/api/docs/test-accounts
+#
# Tags: InfoService.get
require 'adwords_api'
View
3  adwords_api/examples/v201206/account_management/get_client_unit_usage.rb
@@ -21,6 +21,9 @@
# This example illustrates how to retrieve the number of API units usage for a
# client account for the current month.
#
+# Note: This code example uses MCC-level calls and won't work with Test
+# Accounts, see: https://developers.google.com/adwords/api/docs/test-accounts
+#
# Tags: InfoService.get
require 'adwords_api'
View
3  adwords_api/examples/v201206/reporting/parallel_report_download.rb
@@ -19,6 +19,9 @@
# limitations under the License.
#
# This example gets and downloads an Ad Hoc report from a XML report definition.
+#
+# Note: This code example uses MCC-level calls and won't work with Test
+# Accounts, see: https://developers.google.com/adwords/api/docs/test-accounts
require 'thread'
View
3  adwords_api/examples/v201209/account_management/create_account.rb
@@ -21,6 +21,9 @@
# This example illustrates how to create an account. Note by default this
# account will only be accessible via parent MCC.
#
+# Note: This code example uses MCC-level calls and won't work with Test
+# Accounts, see: https://developers.google.com/adwords/api/docs/test-accounts
+#
# Tags: ManagedCustomerService.mutate
require 'adwords_api'
View
3  adwords_api/examples/v201209/account_management/get_account_alerts.rb
@@ -21,6 +21,9 @@
# This example gets all alerts for all clients of an MCC account. The effective
# user (clientCustomerId, or authToken) must be an MCC user to get results.
#
+# Note: This code example uses MCC-level calls and won't work with Test
+# Accounts, see: https://developers.google.com/adwords/api/docs/test-accounts
+#
# Tags: AlertService.get
require 'adwords_api'
View
3  adwords_api/examples/v201209/account_management/get_account_hierarchy.rb
@@ -21,6 +21,9 @@
# This example illustrates how to retrieve the account hierarchy under an
# account.
#
+# Note: This code example uses MCC-level calls and won't work with Test
+# Accounts, see: https://developers.google.com/adwords/api/docs/test-accounts
+#
# Tags: ManagedCustomerService.get
require 'adwords_api'
View
3  adwords_api/examples/v201209/account_management/get_client_customer_id.rb
@@ -22,6 +22,9 @@
# We recommend to use this script as a one off to convert your identifiers to
# IDs and store them for future use.
#
+# Note: This code example uses MCC-level calls and won't work with Test
+# Accounts, see: https://developers.google.com/adwords/api/docs/test-accounts
+#
# Tags: InfoService.get
require 'adwords_api'
View
3  adwords_api/examples/v201209/account_management/get_client_unit_usage.rb
@@ -21,6 +21,9 @@
# This example illustrates how to retrieve the number of API units usage for a
# client account for the current month.
#
+# Note: This code example uses MCC-level calls and won't work with Test
+# Accounts, see: https://developers.google.com/adwords/api/docs/test-accounts
+#
# Tags: InfoService.get
require 'adwords_api'
View
3  adwords_api/examples/v201209/reporting/parallel_report_download.rb
@@ -20,6 +20,9 @@
#
# This example gets and downloads an Ad Hoc report from a XML report definition
# for all accounts in hierarchy in multiple parallel threads.
+#
+# Note: This code example uses MCC-level calls and won't work with Test
+# Accounts, see: https://developers.google.com/adwords/api/docs/test-accounts
require 'thread'
View
6 adwords_api/lib/adwords_api/api_config.rb
@@ -112,12 +112,6 @@ class << ApiConfig
:header_ns => 'https://adwords.google.com/api/adwords/cm/',
:v201206 => 'https://adwords.google.com/api/adwords/',
:v201209 => 'https://adwords.google.com/api/adwords/'
- },
- :SANDBOX => {
- :oauth_scope => 'https://adwords-sandbox.google.com/api/adwords/',
- :header_ns => 'https://adwords.google.com/api/adwords/cm/',
- :v201206 => 'https://adwords-sandbox.google.com/api/adwords/',
- :v201209 => 'https://adwords-sandbox.google.com/api/adwords/'
}
}
View
20 adwords_api/lib/adwords_api/credential_handler.rb
@@ -70,8 +70,6 @@ def generate_user_agent(extra_ids = [])
# environment.
#
# Raises:
- # - AdsCommon::Error::EnvironmentMismatchError if sandbox credentials are
- # being used for production or vice-versa.
# - AdwordsApi::Errors:BadCredentialsError if supplied credentials are not
# valid.
#
@@ -90,21 +88,9 @@ def validate_headers_for_server(credentials)
end
token = credentials[:developer_token]
- sandbox_token = (token =~ /.+@.+\+\+[a-zA-Z]{3}/)
- environment = @config.read('service.environment')
- case environment
- when :PRODUCTION
- if sandbox_token
- raise AdsCommon::Errors::EnvironmentMismatchError,
- 'Attempting to connect to production with sandbox credentials.'
- end
- when :SANDBOX
- if (!sandbox_token)
- raise AdsCommon::Errors::EnvironmentMismatchError,
- 'Attempting to connect to the sandbox with malformatted ' +
- 'credentials. Please check http://code.google.com/apis/' +
- 'adwords/docs/sandbox.html#request-headers for details.'
- end
+ if token.nil? || token.empty?
+ raise AdwordsApi::Errors::BadCredentialsError,
+ 'Developer token is missing, check credentials.'
end
return nil
end
View
32 adwords_api/test/adwords_api/test_adwords_api.rb
@@ -27,20 +27,18 @@
require 'adwords_api'
class TestAdwordsApi < Test::Unit::TestCase
- # Initializes tests.
- def setup()
- @config = AdsCommon::Config.new({})
- end
+
+ API_VERSION = :v201209
def test_initialize()
assert_nothing_raised do
- adwords_api = AdwordsApi::Api.new(@config)
+ adwords_api = AdwordsApi::Api.new({})
end
end
def test_api_config()
assert_nothing_raised do
- adwords_api = AdwordsApi::Api.new(@config)
+ adwords_api = AdwordsApi::Api.new({})
api_config = adwords_api.api_config()
assert_not_nil(api_config)
assert_kind_of(AdsCommon::ApiConfig, api_config)
@@ -48,7 +46,7 @@ def test_api_config()
end
def test_use_mcc()
- adwords_api = AdwordsApi::Api.new(@config)
+ adwords_api = AdwordsApi::Api.new({})
adwords_api.use_mcc = false
assert(!adwords_api.use_mcc)
adwords_api.use_mcc do
@@ -57,7 +55,7 @@ def test_use_mcc()
end
def test_validate_only()
- adwords_api = AdwordsApi::Api.new(@config)
+ adwords_api = AdwordsApi::Api.new({})
adwords_api.validate_only = false
assert(!adwords_api.validate_only)
adwords_api.validate_only do
@@ -66,11 +64,27 @@ def test_validate_only()
end
def test_partial_failure()
- adwords_api = AdwordsApi::Api.new(@config)
+ adwords_api = AdwordsApi::Api.new({})
adwords_api.partial_failure = false
assert(!adwords_api.partial_failure)
adwords_api.partial_failure do
assert(adwords_api.partial_failure)
end
end
+
+ def test_no_sandbox_env()
+ adwords_api = AdwordsApi::Api.new({
+ :service => {:environment => 'SANDBOX'}
+ })
+ assert_raise(AdsCommon::Errors::Error) do
+ service = adwords_api.service(:ManagedCustomerService, API_VERSION)
+ end
+ end
+
+ def test_prod_env()
+ adwords_api = AdwordsApi::Api.new({
+ :service => {:environment => 'PRODUCTION'}
+ })
+ service = adwords_api.service(:ManagedCustomerService, API_VERSION)
+ end
end
View
8 adwords_api/test/adwords_api/test_api_config.rb
@@ -55,12 +55,4 @@ def test_adhoc_report_download_url_prod()
'https://adwords.google.com/api/adwords/reportdownload/v201206'
assert_equal(expected_url, url)
end
-
- # Tests AdHoc report URL generator (sandbox).
- def test_adhoc_report_download_url_sandbox()
- url = AdwordsApi::ApiConfig.adhoc_report_download_url(:SANDBOX, :v201206)
- expected_url =
- 'https://adwords-sandbox.google.com/api/adwords/reportdownload/v201206'
- assert_equal(expected_url, url)
- end
end
View
54 adwords_api/test/adwords_api/test_credential_handler.rb
@@ -38,8 +38,8 @@ class CredentialHandler
class TestCredentialHandler < Test::Unit::TestCase
def setup()
- logger = Logger.new(STDERR)
- config = AdsCommon::Config.new({:library => {:logger => logger}})
+ @logger = Logger.new(STDERR)
+ config = AdsCommon::Config.new({:library => {:logger => @logger}})
@handler = AdwordsApi::CredentialHandler.new(config)
end
@@ -51,35 +51,71 @@ def test_validate_headers_for_server_client_email()
end
def test_validate_headers_for_server_client_customer_id()
- credentials = {:client_customer_id => '123-456-7890'}
+ credentials = {
+ :client_customer_id => '123-456-7890',
+ :developer_token => 'AbC'
+ }
assert_nothing_raised {@handler.validate_headers_for_server(credentials)}
end
def test_validate_headers_for_server_valid_cid()
- credentials1 = {:client_customer_id => '123-456-7890'}
+ credentials1 = {
+ :client_customer_id => '123-456-7890',
+ :developer_token => 'AbC'
+ }
assert_nothing_raised {@handler.validate_headers_for_server(credentials1)}
- credentials2 = {:client_customer_id => '1234567890'}
+ credentials2 = {
+ :client_customer_id => '1234567890',
+ :developer_token => 'AbC'
+ }
assert_nothing_raised {@handler.validate_headers_for_server(credentials2)}
- credentials3 = {:client_customer_id => 1234567890}
+ credentials3 = {
+ :client_customer_id => 1234567890,
+ :developer_token => 'AbC'
+ }
assert_nothing_raised {@handler.validate_headers_for_server(credentials3)}
end
def test_validate_headers_for_server_invalid_cid()
- credentials1 = {:client_customer_id => 'demo@example.com'}
+ credentials1 = {
+ :client_customer_id => 'demo@example.com',
+ :developer_token => 'AbC'
+ }
assert_raise(AdwordsApi::Errors::BadCredentialsError) do
@handler.validate_headers_for_server(credentials1)
end
- credentials2 = {:client_customer_id => 'demo@example.com 1234567890'}
+ credentials2 = {
+ :client_customer_id => 'demo@example.com 1234567890',
+ :developer_token => 'AbC'
+ }
assert_raise(AdwordsApi::Errors::BadCredentialsError) do
@handler.validate_headers_for_server(credentials2)
end
- credentials3 = {:client_customer_id => '123-456-7890-'}
+ credentials3 = {
+ :client_customer_id => '123-456-7890-',
+ :developer_token => 'AbC'
+ }
assert_raise(AdwordsApi::Errors::BadCredentialsError) do
@handler.validate_headers_for_server(credentials3)
end
end
+
+ def test_validate_headers_for_server_no_developer_token()
+ credentials1 = {:client_customer_id => '123-456-7890'}
+ assert_raise(AdwordsApi::Errors::BadCredentialsError) do
+ @handler.validate_headers_for_server(credentials1)
+ end
+
+ credentials2 = {
+ :client_customer_id => '123-456-7890',
+ :developer_token => ''
+ }
+ assert_raise(AdwordsApi::Errors::BadCredentialsError) do
+ @handler.validate_headers_for_server(credentials2)
+ end
+ end
end
View
5 adwords_api/test/adwords_api/test_report_utils.rb
@@ -24,8 +24,6 @@
require 'adwords_api'
-API_VERSION = :v201206
-
# Overriding default access levels to public for tests.
module AdwordsApi
class ReportUtils
@@ -65,6 +63,9 @@ def initialize(code, body)
GZIPPED_REPORT = "\x1F\x8B\b\x00\x00\x00\x00\x00\x00\x00Sr.-.\xC9\xCFUptq\x0F\xF2\x0F\r\x88\x0Fp\rr\xF3\x0F\xF2u\xF4sv\x8D\x0Fr\r\xF0\x0F\nQ\xD0pIMV0\xD2Q0204\xD4\x05\xB1- lM%.\xE7\xC4\xDC\x82\xC4\xCC\xF4<\x05O\x17\x1D\xC7\x14\x85\xF4\xA2\xFC\xD2\x02\x10\xDB3\xB7\xA0(\xB5\xB883?\xAFX\xC79'39\eH\xE5\x17\x97p\x85\xE4\x97$\xE6\xE8(\xE8\xEA\xEA\x18\x80\xA0\x9E\x81\x01\x17\x00\xBE\x1D\xBE\xAD\x81\x00\x00\x00"
class TestReportUtils < Test::Unit::TestCase
+
+ API_VERSION = :v201209
+
# Initialize tests.
def setup()
@api = AdwordsApi::Api.new
Please sign in to comment.
Something went wrong with that request. Please try again.