adapi 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. data/.gitignore +3 -0
  2. data/README.markdown +176 -0
  3. data/Rakefile +32 -0
  4. data/adapi.gemspec +7 -4
  5. data/examples/add_ad_group.rb +1 -0
  6. data/examples/add_bare_ad_group.rb +2 -6
  7. data/examples/add_bare_campaign.rb +1 -0
  8. data/examples/add_campaign.rb +1 -0
  9. data/examples/add_campaign_targets.rb +1 -0
  10. data/examples/add_invalid_ad_group.rb +1 -0
  11. data/examples/add_keywords.rb +13 -1
  12. data/examples/custom_settings.yml +2 -2
  13. data/examples/customize_configuration.rb +2 -0
  14. data/examples/delete_keyword.rb +27 -0
  15. data/examples/find_all_campaigns.rb +13 -0
  16. data/examples/find_campaign.rb +39 -0
  17. data/examples/find_campaign_ad_groups.rb +25 -0
  18. data/examples/log_to_specific_account.rb +1 -0
  19. data/examples/rollback_campaign.rb +1 -0
  20. data/lib/adapi.rb +8 -5
  21. data/lib/adapi/ad.rb +2 -0
  22. data/lib/adapi/ad/text_ad.rb +15 -0
  23. data/lib/adapi/ad_group.rb +45 -6
  24. data/lib/adapi/ad_group_criterion.rb +14 -0
  25. data/lib/adapi/api.rb +6 -0
  26. data/lib/adapi/campaign.rb +48 -5
  27. data/lib/adapi/campaign_target.rb +67 -8
  28. data/lib/adapi/config.rb +1 -0
  29. data/lib/adapi/keyword.rb +78 -11
  30. data/lib/adapi/version.rb +9 -1
  31. data/lib/httpi_request_monkeypatch.rb +1 -0
  32. data/test/factories/ad_group_factory.rb +4 -13
  33. data/test/factories/ad_text_factory.rb +1 -0
  34. data/test/test_helper.rb +3 -0
  35. data/test/unit/ad/ad_text_test.rb +2 -0
  36. data/test/unit/ad_group_test.rb +11 -2
  37. data/test/unit/ad_test.rb +2 -0
  38. data/test/unit/campaign_target_test.rb +15 -0
  39. metadata +67 -32
  40. data/README.rdoc +0 -162
  41. data/lib/collection.rb +0 -429
@@ -1,8 +1,16 @@
1
+ # encoding: utf-8
2
+
1
3
  module Adapi
2
- VERSION = "0.0.3"
4
+ VERSION = "0.0.4"
3
5
 
4
6
  # CHANGELOG:
5
7
  #
8
+ # 0.0.4
9
+ # changed README to markdown format
10
+ # updated DSL for creating campaign and campaign target
11
+ # implemented find methods for campaigns and ad groups
12
+ # implemented getting complete campaigns (in one hash with targets, ad groups, keywords and ads)
13
+ #
6
14
  # 0.0.3
7
15
  # converted to ActiveModel
8
16
  # moved common functionality to Api class
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
 
2
3
  # manually hardcode timeouts for HTTPI to 5 minutes (300 seconds)
3
4
  # HOTFIX there's no way how to do it properly through HTTPI
@@ -1,20 +1,11 @@
1
+ # encoding: utf-8
2
+
3
+ the_bids = { :xsi_type => 'ManualCPCAdGroupBids', :keyword_max_cpc => 10 }
1
4
 
2
5
  Factory.define :ad_group, :class => Adapi::AdGroup do |f|
3
6
  f.sequence(:campaign_id) { |n| n }
4
7
  f.name "AdGroup %d" % (Time.new.to_f * 1000).to_i
5
8
  f.status 'ENABLED'
6
- # f.bids {}
9
+ f.bids the_bids
7
10
  f.keywords [ 'dem codez', '"top coder"', '[-code]' ]
8
11
  end
9
-
10
- =begin
11
- ad_group_data = {
12
- :bids => {
13
- :xsi_type => 'ManualCPCAdGroupBids',
14
- :keyword_max_cpc => {
15
- :amount => {
16
- :micro_amount => 10000000
17
- }
18
- }
19
- },
20
- =end
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
 
2
3
  Factory.define :text_ad, :class => Adapi::Ad::TextAd do |f|
3
4
  f.sequence(:ad_group_id) { |n| n }
@@ -1,5 +1,7 @@
1
+ # encoding: utf-8
1
2
 
2
3
  require 'rubygems'
4
+ gem 'minitest'
3
5
  require 'test/unit'
4
6
  require 'turn'
5
7
  require 'shoulda'
@@ -17,4 +19,5 @@ class Test::Unit::TestCase
17
19
 
18
20
  FakeWeb.allow_net_connect = false
19
21
 
22
+
20
23
  end
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  require 'test_helper'
2
4
 
3
5
  module Adapi
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  require 'test_helper'
2
4
 
3
5
  module Adapi
@@ -17,8 +19,15 @@ module Adapi
17
19
  assert @ad_group.valid?
18
20
  end
19
21
 
20
- should "parse :keywords correctly" do
21
-
22
+ should "parse :bids correctly" do
23
+ # FIXME factory doesn't work in this case for some reason
24
+ ag = AdGroup.new( :bids => { :xsi_type => 'ManualCPCAdGroupBids', :keyword_max_cpc => 10 } )
25
+
26
+ assert_equal ag.bids,
27
+ {
28
+ :xsi_type => 'ManualCPCAdGroupBids',
29
+ :keyword_max_cpc => { :amount => { :micro_amount => 10000000 } }
30
+ }
22
31
  end
23
32
 
24
33
  context " / data method" do
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  require 'test_helper'
2
4
 
3
5
  module Adapi
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  require 'test_helper'
2
4
 
3
5
  module Adapi
@@ -10,6 +12,11 @@ module Adapi
10
12
  [{:language_code => 'en'}, {:language_code => 'cs'}]
11
13
  end
12
14
 
15
+ should "automatically convert :language targets to lowercase" do
16
+ assert_equal CampaignTarget.create_targets(:language, ['EN', 'CS']),
17
+ [{:language_code => 'en'}, {:language_code => 'cs'}]
18
+ end
19
+
13
20
  should "parse :geo / :country and :province targets" do
14
21
  assert_equal CampaignTarget.create_targets(:geo, {:country => 'CZ', :province => 'CZ-PR'}),
15
22
  [
@@ -18,6 +25,14 @@ module Adapi
18
25
  ]
19
26
  end
20
27
 
28
+ should "automatically convert :geo / :country and :province targets to uppercase" do
29
+ assert_equal CampaignTarget.create_targets(:geo, {:country => 'cz', :province => 'cz-pr'}),
30
+ [
31
+ {:xsi_type => 'CountryTarget', :excluded => false, :country_code => 'CZ'},
32
+ {:xsi_type => 'ProvinceTarget', :excluded => false, :province_code => 'CZ-PR'}
33
+ ]
34
+ end
35
+
21
36
  should "parse :geo / :proximity targets" do
22
37
  assert_equal CampaignTarget.create_targets(:geo,
23
38
  {:proximity => {:geo_point => '38.89859,-77.035971', :radius => '10 km'}}),
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: adapi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,12 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-09-26 00:00:00.000000000 +02:00
13
- default_executable:
12
+ date: 2011-12-22 00:00:00.000000000Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  name: google-ads-common
17
- requirement: &16900920 !ruby/object:Gem::Requirement
16
+ requirement: &15506360 !ruby/object:Gem::Requirement
18
17
  none: false
19
18
  requirements:
20
19
  - - ~>
@@ -22,10 +21,10 @@ dependencies:
22
21
  version: 0.5.0
23
22
  type: :runtime
24
23
  prerelease: false
25
- version_requirements: *16900920
24
+ version_requirements: *15506360
26
25
  - !ruby/object:Gem::Dependency
27
26
  name: google-adwords-api
28
- requirement: &16900260 !ruby/object:Gem::Requirement
27
+ requirement: &15455540 !ruby/object:Gem::Requirement
29
28
  none: false
30
29
  requirements:
31
30
  - - ~>
@@ -33,32 +32,32 @@ dependencies:
33
32
  version: 0.4.0
34
33
  type: :runtime
35
34
  prerelease: false
36
- version_requirements: *16900260
35
+ version_requirements: *15455540
37
36
  - !ruby/object:Gem::Dependency
38
37
  name: activemodel
39
- requirement: &16899620 !ruby/object:Gem::Requirement
38
+ requirement: &15454880 !ruby/object:Gem::Requirement
40
39
  none: false
41
40
  requirements:
42
41
  - - ~>
43
42
  - !ruby/object:Gem::Version
44
- version: 3.1.0
43
+ version: '3.1'
45
44
  type: :runtime
46
45
  prerelease: false
47
- version_requirements: *16899620
46
+ version_requirements: *15454880
48
47
  - !ruby/object:Gem::Dependency
49
48
  name: activesupport
50
- requirement: &16899100 !ruby/object:Gem::Requirement
49
+ requirement: &15454300 !ruby/object:Gem::Requirement
51
50
  none: false
52
51
  requirements:
53
52
  - - ~>
54
53
  - !ruby/object:Gem::Version
55
- version: 3.1.0
54
+ version: '3.1'
56
55
  type: :runtime
57
56
  prerelease: false
58
- version_requirements: *16899100
57
+ version_requirements: *15454300
59
58
  - !ruby/object:Gem::Dependency
60
59
  name: rake
61
- requirement: &16898440 !ruby/object:Gem::Requirement
60
+ requirement: &15453760 !ruby/object:Gem::Requirement
62
61
  none: false
63
62
  requirements:
64
63
  - - ~>
@@ -66,32 +65,54 @@ dependencies:
66
65
  version: 0.9.2
67
66
  type: :runtime
68
67
  prerelease: false
69
- version_requirements: *16898440
68
+ version_requirements: *15453760
70
69
  - !ruby/object:Gem::Dependency
71
70
  name: curb
72
- requirement: &16896280 !ruby/object:Gem::Requirement
71
+ requirement: &15453080 !ruby/object:Gem::Requirement
73
72
  none: false
74
73
  requirements:
75
74
  - - ~>
76
75
  - !ruby/object:Gem::Version
77
- version: 0.7.15
76
+ version: '0.7'
78
77
  type: :runtime
79
78
  prerelease: false
80
- version_requirements: *16896280
79
+ version_requirements: *15453080
80
+ - !ruby/object:Gem::Dependency
81
+ name: yard
82
+ requirement: &15452120 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ~>
86
+ - !ruby/object:Gem::Version
87
+ version: '0.7'
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: *15452120
91
+ - !ruby/object:Gem::Dependency
92
+ name: rcov
93
+ requirement: &15449500 !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ~>
97
+ - !ruby/object:Gem::Version
98
+ version: '0.9'
99
+ type: :development
100
+ prerelease: false
101
+ version_requirements: *15449500
81
102
  - !ruby/object:Gem::Dependency
82
103
  name: turn
83
- requirement: &16895700 !ruby/object:Gem::Requirement
104
+ requirement: &15423440 !ruby/object:Gem::Requirement
84
105
  none: false
85
106
  requirements:
86
- - - ! '>='
107
+ - - =
87
108
  - !ruby/object:Gem::Version
88
- version: '0'
109
+ version: 0.8.2
89
110
  type: :development
90
111
  prerelease: false
91
- version_requirements: *16895700
112
+ version_requirements: *15423440
92
113
  - !ruby/object:Gem::Dependency
93
114
  name: shoulda
94
- requirement: &16895040 !ruby/object:Gem::Requirement
115
+ requirement: &15420900 !ruby/object:Gem::Requirement
95
116
  none: false
96
117
  requirements:
97
118
  - - ! '>='
@@ -99,10 +120,10 @@ dependencies:
99
120
  version: '0'
100
121
  type: :development
101
122
  prerelease: false
102
- version_requirements: *16895040
123
+ version_requirements: *15420900
103
124
  - !ruby/object:Gem::Dependency
104
125
  name: fakeweb
105
- requirement: &16894420 !ruby/object:Gem::Requirement
126
+ requirement: &15419460 !ruby/object:Gem::Requirement
106
127
  none: false
107
128
  requirements:
108
129
  - - ! '>='
@@ -110,10 +131,21 @@ dependencies:
110
131
  version: '0'
111
132
  type: :development
112
133
  prerelease: false
113
- version_requirements: *16894420
134
+ version_requirements: *15419460
114
135
  - !ruby/object:Gem::Dependency
115
136
  name: factory_girl
116
- requirement: &16893920 !ruby/object:Gem::Requirement
137
+ requirement: &15418480 !ruby/object:Gem::Requirement
138
+ none: false
139
+ requirements:
140
+ - - ! '>='
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ type: :development
144
+ prerelease: false
145
+ version_requirements: *15418480
146
+ - !ruby/object:Gem::Dependency
147
+ name: minitest
148
+ requirement: &15417640 !ruby/object:Gem::Requirement
117
149
  none: false
118
150
  requirements:
119
151
  - - ! '>='
@@ -121,7 +153,7 @@ dependencies:
121
153
  version: '0'
122
154
  type: :development
123
155
  prerelease: false
124
- version_requirements: *16893920
156
+ version_requirements: *15417640
125
157
  description: This gem provides user-friendly interface to Google Adwords API.
126
158
  email:
127
159
  - lucastej@gmail.com
@@ -132,7 +164,7 @@ files:
132
164
  - .gitignore
133
165
  - Gemfile
134
166
  - LICENSE
135
- - README.rdoc
167
+ - README.markdown
136
168
  - Rakefile
137
169
  - adapi.gemspec
138
170
  - examples/add_ad_group.rb
@@ -146,6 +178,10 @@ files:
146
178
  - examples/add_text_ad.rb
147
179
  - examples/custom_settings.yml
148
180
  - examples/customize_configuration.rb
181
+ - examples/delete_keyword.rb
182
+ - examples/find_all_campaigns.rb
183
+ - examples/find_campaign.rb
184
+ - examples/find_campaign_ad_groups.rb
149
185
  - examples/log_to_specific_account.rb
150
186
  - examples/rollback_campaign.rb
151
187
  - examples/update_campaign.rb
@@ -161,7 +197,6 @@ files:
161
197
  - lib/adapi/config.rb
162
198
  - lib/adapi/keyword.rb
163
199
  - lib/adapi/version.rb
164
- - lib/collection.rb
165
200
  - lib/httpi_request_monkeypatch.rb
166
201
  - test/factories/.gitignore
167
202
  - test/factories/ad_group_factory.rb
@@ -172,7 +207,6 @@ files:
172
207
  - test/unit/ad_group_test.rb
173
208
  - test/unit/ad_test.rb
174
209
  - test/unit/campaign_target_test.rb
175
- has_rdoc: true
176
210
  homepage: ''
177
211
  licenses: []
178
212
  post_install_message:
@@ -193,8 +227,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
193
227
  version: '0'
194
228
  requirements: []
195
229
  rubyforge_project: adapi
196
- rubygems_version: 1.6.2
230
+ rubygems_version: 1.8.10
197
231
  signing_key:
198
232
  specification_version: 3
199
233
  summary: User-friendly interface to Google Adwords API
200
234
  test_files: []
235
+ has_rdoc:
@@ -1,162 +0,0 @@
1
- == Adapi
2
-
3
- Adapi (shortened "AdWords API") is a library for easy and painless work with
4
- Google Adwords API. Its users shouldn't bother with SOAP and tangle of XML- and
5
- API-specific objects (remember adwords4r gem?), inputs and outputs are plain
6
- Ruby arrays and hashes.
7
-
8
- Adapi is built on new Google Adwords API gems: google-ads-common and
9
- google-adwords-api. Arrays and hashes instead of objects come from there, but
10
- adapi takes it several steps further. AdWords services are represented by models
11
- with relations, so among other things it's possible to create whole campaign in
12
- single method call: Adapi::Campaign.create(campaign_data). Various convenience
13
- methods are added to the models, for example: campaign.pause! (pauses
14
- campaign). Adapi enables multiple AdWords accounts to be used at the same time.
15
-
16
- Adapi is STILL IN DEVELOPMENT and not nearly done yet! Version 1.0.0 should have
17
- all planned functionality.
18
-
19
- == Installation
20
-
21
- gem install adapi
22
-
23
- === from git repository
24
-
25
- bundle install
26
- rake install
27
-
28
- == Configuration
29
-
30
- This section explains how to connect to specific AdWords account and client.
31
-
32
- You can set many AdWords accounts to connect to and switch between while running
33
- the application. You can even update single values of the settings on-the-fly.
34
-
35
- # load the settings
36
- Adapi::Config.load_settings(:in_hash => {
37
- :coca_cola => {
38
- :authentication => {
39
- :method => 'ClientLogin',
40
- :email => 'coca_cola_email@gmail.com',
41
- :password => 'coca_cola_password',
42
- :developer_token => 'coca_cola_developer_token',
43
- :user_agent => 'Coca-Cola Adwords API Test'
44
- },
45
- :service => {
46
- :environment => 'SANDBOX'
47
- }
48
- },
49
- :pepsi => {
50
- :authentication => {
51
- :method => 'ClientLogin',
52
- :email => 'pepsi_email@gmail.com',
53
- :password => 'pepsi_password',
54
- :developer_token => 'pepsi_developer_token',
55
- :user_agent => 'Pepsi Adwords API Test'
56
- },
57
- :service => {
58
- :environment => 'SANDBOX'
59
- }
60
- }
61
- })
62
-
63
- # set to pepsi and specific client
64
- Adapi::Config.set(:pepsi, :client_customer_id => '555-666-7777')
65
-
66
- # do some stuff here...
67
-
68
- # set to coca-cola and another client
69
- Adapi::Config.set(:coca_cola, :client_customer_id => '777-666-5555')
70
-
71
- # do some stuff here...
72
-
73
- === Authentication workflow
74
-
75
- * load configuration from ~/adapi.yml
76
- * load configuration from ~/adwords_api.yml (default configuration for AdWords gems
77
- from Google)
78
- * set configuration directly to Adapi::Config (overrides previous settings)
79
-
80
- === Configuration by adapi.yml
81
-
82
- Stored in ~/adapi.yml. Supports multiple accounts, which are identifed by
83
- aliases. Example:
84
-
85
- :default:
86
- :authentication:
87
- :method: ClientLogin
88
- :email: default_email@gmail.com
89
- :password: default_password
90
- :developer_token: default_token
91
- :client_email: default_client_email@gmail.com
92
- :user_agent: My Adwords API Client
93
- :service:
94
- :environment: PRODUCTION
95
-
96
- :sandbox:
97
- :authentication:
98
- :method: ClientLogin
99
- :email: sandbox_email@gmail.com
100
- :password: sandbox_password
101
- :developer_token: sandbox_token
102
- :client_email: sandbox_client_email@gmail.com
103
- :user_agent: Adwords API Test
104
- :service:
105
- :environment: SANDBOX
106
-
107
- You tell adapi which account to use by setting an alias:
108
-
109
- Adapi::Config.set(:sandbox)
110
-
111
- :default account is, as name implies, used by default. You must either set an
112
- alias to Adapi::Config or have account with :default alias available.
113
-
114
- === Configuration by adwords_api.yml
115
-
116
- If you already have google-adwords-api gem configured and use just one account,
117
- the same configuration will also work for adapi: ~/adwords_api.yml
118
-
119
- === Configuration directly in code
120
-
121
- Before logging into the Adwords API, you can set global settings through
122
- Adapi::Config:
123
-
124
- # load the settings
125
- Adapi::Config.load_settings(:in_hash => {
126
- :sandbox => {
127
- :authentication => {
128
- :method => "ClientLogin"
129
- :email => "sandbox_email@gmail.com",
130
- :password => "sandbox_password",
131
- :developer_token => "sandbox_token",
132
- :client_email => "sandbox_client_email@gmail.com",
133
- :user_agent => "Adwords API Test"
134
- },
135
- :service => {
136
- :environment => "SANDBOX"
137
- }
138
- }
139
- })
140
-
141
- Adapi::Config.set(:sandbox)
142
-
143
- == TODO API
144
-
145
- AdWords Services are implemented as models, similar to ActiveRecord models of
146
- database tables. They are built on ActiveModel.
147
-
148
- == API Version Support
149
-
150
- Adapi supports only the latest version of Google AdWords API: v201101. Older
151
- versions will not be supported. v201101 and newer versions will still be
152
- supported when new versions are released.
153
-
154
- == Examples
155
-
156
- Example are available in /examples directory. For now, they are mostly just dumb
157
- rewrites of examples from google-adwords-api gem, but that's going to change
158
- when proper UI to AdWords models will be implemented.
159
-
160
- == Author
161
-
162
- Lukas Stejskal