gnib-ads-api 0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.rdoc +121 -0
  4. data/Rakefile +38 -0
  5. data/lib/gnib-ads-api.rb +44 -0
  6. data/lib/gnib-ads-api.yml +355 -0
  7. data/lib/gnib-ads-api/api_exception.rb +42 -0
  8. data/lib/gnib-ads-api/client_proxy.rb +147 -0
  9. data/lib/gnib-ads-api/config.rb +75 -0
  10. data/lib/gnib-ads-api/constants.rb +150 -0
  11. data/lib/gnib-ads-api/data/accounts_info.rb +72 -0
  12. data/lib/gnib-ads-api/data/ad.rb +119 -0
  13. data/lib/gnib-ads-api/data/ad_group.rb +121 -0
  14. data/lib/gnib-ads-api/data/campaign.rb +40 -0
  15. data/lib/gnib-ads-api/data/report_request.rb +78 -0
  16. data/lib/gnib-ads-api/data/report_request_status.rb +48 -0
  17. data/lib/gnib-ads-api/data/reporting/account_performance_report_request.rb +176 -0
  18. data/lib/gnib-ads-api/data/reporting/campaign_performance_report_request.rb +186 -0
  19. data/lib/gnib-ads-api/data/reporting/helpers/column_helper.rb +65 -0
  20. data/lib/gnib-ads-api/data/reporting/helpers/filter_helper.rb +124 -0
  21. data/lib/gnib-ads-api/data/reporting/helpers/scope_helper.rb +51 -0
  22. data/lib/gnib-ads-api/data/reporting/helpers/time_helper.rb +69 -0
  23. data/lib/gnib-ads-api/data/reporting/performance_report_request.rb +78 -0
  24. data/lib/gnib-ads-api/data_object.rb +35 -0
  25. data/lib/gnib-ads-api/fault/ad_api_error.rb +15 -0
  26. data/lib/gnib-ads-api/fault/ad_api_fault_detail.rb +67 -0
  27. data/lib/gnib-ads-api/fault/api_fault_detail.rb +97 -0
  28. data/lib/gnib-ads-api/fault/application_fault.rb +18 -0
  29. data/lib/gnib-ads-api/fault/batch_error.rb +47 -0
  30. data/lib/gnib-ads-api/fault/operation_error.rb +22 -0
  31. data/lib/gnib-ads-api/fault/partial_errors.rb +75 -0
  32. data/lib/gnib-ads-api/service.rb +176 -0
  33. data/lib/gnib-ads-api/service/campaign_management.rb +483 -0
  34. data/lib/gnib-ads-api/service/customer_management.rb +83 -0
  35. data/lib/gnib-ads-api/service/reporting.rb +101 -0
  36. data/lib/gnib-ads-api/soap_hasheable.rb +160 -0
  37. data/lib/gnib-ads-api/version.rb +6 -0
  38. data/lib/locales/es.yml +174 -0
  39. data/lib/tasks/gnib-ads-api_tasks.rake +4 -0
  40. data/test/campaign_management_test.rb +463 -0
  41. data/test/customer_management_test.rb +44 -0
  42. data/test/data_object_test.rb +46 -0
  43. data/test/dummy/README.rdoc +261 -0
  44. data/test/dummy/Rakefile +7 -0
  45. data/test/dummy/app/assets/javascripts/application.js +15 -0
  46. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  47. data/test/dummy/app/controllers/application_controller.rb +3 -0
  48. data/test/dummy/app/helpers/application_helper.rb +2 -0
  49. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  50. data/test/dummy/config.ru +4 -0
  51. data/test/dummy/config/application.rb +56 -0
  52. data/test/dummy/config/boot.rb +10 -0
  53. data/test/dummy/config/database.yml +25 -0
  54. data/test/dummy/config/environment.rb +5 -0
  55. data/test/dummy/config/environments/development.rb +37 -0
  56. data/test/dummy/config/environments/production.rb +67 -0
  57. data/test/dummy/config/environments/test.rb +37 -0
  58. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  59. data/test/dummy/config/initializers/inflections.rb +15 -0
  60. data/test/dummy/config/initializers/mime_types.rb +5 -0
  61. data/test/dummy/config/initializers/secret_token.rb +7 -0
  62. data/test/dummy/config/initializers/session_store.rb +8 -0
  63. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  64. data/test/dummy/config/locales/en.yml +5 -0
  65. data/test/dummy/config/routes.rb +58 -0
  66. data/test/dummy/public/404.html +26 -0
  67. data/test/dummy/public/422.html +26 -0
  68. data/test/dummy/public/500.html +25 -0
  69. data/test/dummy/public/favicon.ico +0 -0
  70. data/test/dummy/script/rails +6 -0
  71. data/test/gnib-ads-api_test.rb +172 -0
  72. data/test/report_request_test.rb +312 -0
  73. data/test/reporting_test.rb +145 -0
  74. data/test/test_helper.rb +11 -0
  75. metadata +193 -0
@@ -0,0 +1,312 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require 'test_helper'
3
+
4
+ # Public : Test case for ReportRequest an its subclasses
5
+ #
6
+ # Author:: jlopezn@neonline.cl
7
+ class ReportRequestTest < ActiveSupport::TestCase
8
+
9
+ def setup
10
+
11
+ @config = GnibAdsApi::Config.instance
12
+ @options = {
13
+ :environment => :sandbox,
14
+ :username => "desarrollo_neonline",
15
+ :password => "neonline2013",
16
+ :developer_token => "BBD37VB98",
17
+ :customer_id => "21021746",
18
+ :account_id => "5978083"
19
+ }
20
+ @service = GnibAdsApi::Reporting.new(@options)
21
+
22
+ end
23
+
24
+ test "truth" do
25
+ assert_kind_of Module, GnibAdsApi
26
+ end
27
+
28
+ test "initialize report request" do
29
+ assert_nothing_raised(Exception, "Report request not instantiated") {
30
+ report_request = GnibAdsApi::ReportRequest.new(:format => :xml,
31
+ :language => :english, :report_name => "My Report",
32
+ :return_only_complete_data => true)
33
+ puts "report request"
34
+ puts report_request.to_hash(:camelcase)
35
+ }
36
+
37
+ end
38
+
39
+
40
+ test "should raise exception" do
41
+ assert_raises(Exception, "Bad format not raised") {
42
+ report_request = GnibAdsApi::ReportRequest.new(:format => :invalid,
43
+ :language => :english, :report_name => "My Report",
44
+ :return_only_complete_data => true)
45
+ }
46
+
47
+ assert_raises(Exception, "Bad language not raised") {
48
+ report_request = GnibAdsApi::ReportRequest.new(:format => :xml,
49
+ :language => :swahili, :report_name => "My Report",
50
+ :return_only_complete_data => true)
51
+ }
52
+
53
+ end
54
+
55
+
56
+ test "initialize performance report request" do
57
+ assert_nothing_raised(Exception, "Performance Report request not instantiated") {
58
+ performance_report_request = GnibAdsApi::PerformanceReportRequest.new(:format => :xml,
59
+ :language => :english, :report_name => "My Report",
60
+ :aggregation => :hourly, :time => :today)
61
+ puts "performance report request"
62
+ puts performance_report_request.to_hash(:camelcase)
63
+ }
64
+ end
65
+
66
+
67
+ test "should raise aggregation exception" do
68
+ assert_raises(Exception, "Bad aggregation not raised") {
69
+ performance_report_request = GnibAdsApi::PerformanceReportRequest.new(:format => :xml,
70
+ :language => :english, :report_name => "My Report",
71
+ :aggregation => :invalid_aggregation)
72
+ }
73
+
74
+ end
75
+
76
+
77
+ test "should raise time exception" do
78
+ assert_raises(Exception, "Bad aggregation not raised") {
79
+ performance_report_request = GnibAdsApi::PerformanceReportRequest.new(:format => :xml,
80
+ :language => :english, :report_name => "My Report",
81
+ :aggregation => :weekly)
82
+ }
83
+
84
+ end
85
+
86
+
87
+ test "initialize campaign performance report request" do
88
+ assert_nothing_raised(Exception, "CampaignPerformanceReportRequest not instantiated") {
89
+ performance_report_request = GnibAdsApi::CampaignPerformanceReportRequest.new(:format => :xml,
90
+ :language => :english, :report_name => "My Report",
91
+ :aggregation => :hourly, :time => :today,
92
+ :columns => [:account_name, :account_number, :time_period ],
93
+ :filter => {
94
+ # String as bing expected
95
+ :ad_distribution => "Search",
96
+ :device_os => "Windows",
97
+ # snake case symbol
98
+ :device_type => :computer,
99
+ # nil criteria
100
+ :status => nil
101
+ },
102
+ :scope => {:account_ids => 12345,
103
+ :campaigns => [
104
+ {:account_id => 1234, :campaign_id => 1234},
105
+ {:account_id => 1234, :campaign_id => 1234},
106
+ {:account_id => 1234, :campaign_id => 1234}]
107
+ })
108
+ puts "campaign performance report request 1"
109
+ puts performance_report_request.to_hash(:camelcase)
110
+
111
+ performance_report_request = GnibAdsApi::CampaignPerformanceReportRequest.new(:format => :xml,
112
+ :language => :english, :report_name => "My Report",
113
+ :aggregation => :hourly,
114
+ :time => {
115
+ :custom_date_range_start => {
116
+ :day => 1,
117
+ :month => 12,
118
+ :year => 2013
119
+ },
120
+ :custom_date_range_end => {
121
+ :day => 31,
122
+ :month => 12,
123
+ :year => 2013
124
+ }
125
+ },
126
+ :columns => [:account_name, :account_number, :time_period ],
127
+ :filter => {
128
+ # String as bing expected
129
+ :ad_distribution => "Search",
130
+ :device_os => "Windows",
131
+ # snake case symbol
132
+ :device_type => :computer,
133
+ # nil criteria
134
+ :status => nil
135
+ },
136
+ :scope => {:account_ids => 12345,
137
+ :campaigns => []})
138
+ puts "campaign performance report request 2"
139
+ puts performance_report_request.to_hash(:camelcase)
140
+
141
+
142
+ }
143
+ end
144
+
145
+
146
+ test "initialize account performance report request" do
147
+ assert_nothing_raised(Exception, "AccountPerformanceReportRequest not instantiated") {
148
+ performance_report_request = GnibAdsApi::AccountPerformanceReportRequest.new(:format => :xml,
149
+ :language => :english, :report_name => "My Report",
150
+ :aggregation => :hourly,
151
+ :columns => [:account_name, :account_number, :time_period ],
152
+ :filter => {
153
+ # String as bing expected
154
+ :ad_distribution => "Search",
155
+ # snake case symbol
156
+ :device_os => :windows,
157
+ # no specified value
158
+ :device_type => nil
159
+ },
160
+ :scope => {:account_ids => 12345},
161
+ :time => :today )
162
+ puts "account performance report request 1"
163
+ puts performance_report_request.to_hash(:camelcase)
164
+
165
+ performance_report_request = GnibAdsApi::AccountPerformanceReportRequest.new(:format => :xml,
166
+ :language => :english, :report_name => "My Report",
167
+ :aggregation => :hourly,
168
+ :columns => [:account_name, :account_number, :time_period ],
169
+ :filter => {
170
+ # String as bing expected
171
+ :ad_distribution => "Search",
172
+ # snake case symbol
173
+ :device_os => :windows,
174
+ # no specified value
175
+ :device_type => nil
176
+ },
177
+ :scope => {:account_ids => 12345},
178
+ :time => {
179
+ :custom_date_range_start => {
180
+ :day => 1,
181
+ :month => 12,
182
+ :year => 2013
183
+ },
184
+ :custom_date_range_end => {
185
+ :day => 31,
186
+ :month => 12,
187
+ :year => 2013
188
+ }
189
+ })
190
+ puts "account performance report request 2"
191
+ puts performance_report_request.to_hash(:camelcase)
192
+
193
+ }
194
+ end
195
+
196
+
197
+ test "should raise column exception " do
198
+ assert_raises(Exception, "Bad column name for CampaignPerformanceReportRequest not raised") {
199
+ performance_report_request = GnibAdsApi::CampaignPerformanceReportRequest.new(:format => :xml,
200
+ :language => :english, :report_name => "My Report",
201
+ :aggregation => :hourly, :time => :today,
202
+ :columns => [:account_name, :account_number, :time_period, :unknown_column ],
203
+ :scope => {:account_ids => 12345,
204
+ :campaigns => []})
205
+ }
206
+
207
+
208
+ assert_raises(Exception, "Bad column value for CampaignPerformanceReportRequest not raised") {
209
+ performance_report_request = GnibAdsApi::CampaignPerformanceReportRequest.new(:format => :xml,
210
+ :language => :english, :report_name => "My Report",
211
+ :aggregation => :hourly, :time => :today,
212
+ :columns => [:account_name, :account_number, :time_period, "UnknownColumn" ],
213
+ :scope => {:account_ids => 12345,
214
+ :campaigns => []})
215
+ }
216
+ end
217
+
218
+
219
+ test "should raise scope exception " do
220
+ assert_raises(Exception, "Bad scope for account_ids not raised") {
221
+ performance_report_request = GnibAdsApi::CampaignPerformanceReportRequest.new(:format => :xml,
222
+ :language => :english, :report_name => "My Report",
223
+ :aggregation => :hourly, :time => :today,
224
+ :columns => [:account_name, :account_number, :time_period ],
225
+ :scope => { :campaigns => []})
226
+ }
227
+
228
+ assert_raises(Exception, "Bad scope for campaigns not raised") {
229
+ performance_report_request = GnibAdsApi::CampaignPerformanceReportRequest.new(:format => :xml,
230
+ :language => :english, :report_name => "My Report",
231
+ :aggregation => :hourly, :time => :today,
232
+ :columns => [:account_name, :account_number, :time_period ],
233
+ :scope => {:account_ids => 12345 })
234
+ }
235
+
236
+ end
237
+
238
+
239
+ test "campaign performance filter " do
240
+ assert_nothing_raised(Exception, "Bad filter for CampaignPerformanceReportRequest") {
241
+ performance_report_request = GnibAdsApi::CampaignPerformanceReportRequest.new(:format => :xml,
242
+ :language => :english, :report_name => "My Report",
243
+ :aggregation => :hourly, :time => :today,
244
+ :columns => [:account_name, :account_number, :time_period ],
245
+ :filter => {
246
+ # String as bing expected
247
+ :ad_distribution => "Search",
248
+ :device_os => "Windows",
249
+ # snake case symbol
250
+ :device_type => :computer,
251
+ # nil criteria
252
+ :status => nil
253
+ },
254
+ :scope => {:account_ids => 12345,
255
+ :campaigns => []})
256
+ }
257
+ end
258
+
259
+
260
+ test "should raise campaign performance filter exception " do
261
+ assert_raises(Exception, "Bad filter string for CampaignPerformanceReportRequest not raised") {
262
+ performance_report_request = GnibAdsApi::CampaignPerformanceReportRequest.new(:format => :xml,
263
+ :language => :english, :report_name => "My Report",
264
+ :aggregation => :hourly, :time => :today,
265
+ :columns => [:account_name, :account_number, :time_period ],
266
+ :filter => {
267
+ # Wrong String as bing expected
268
+ :ad_distribution => "Searched",
269
+ :device_os => "Windows",
270
+ # snake case symbol
271
+ :device_type => :computer,
272
+ # nil criteria
273
+ :status => nil
274
+ },
275
+ :scope => {:account_ids => 12345,
276
+ :campaigns => []})
277
+ }
278
+
279
+ assert_raises(Exception, "Bad filter symbol for CampaignPerformanceReportRequest not raised") {
280
+ performance_report_request = GnibAdsApi::CampaignPerformanceReportRequest.new(:format => :xml,
281
+ :language => :english, :report_name => "My Report",
282
+ :aggregation => :hourly, :time => :today,
283
+ :columns => [:account_name, :account_number, :time_period ],
284
+ :filter => {
285
+ # Wrong String as bing expected
286
+ :ad_distribution => "Search",
287
+ :device_os => "Windows",
288
+ # Wrong snake case symbol
289
+ :device_type => :notebook,
290
+ # nil criteria
291
+ :status => nil
292
+ },
293
+ :scope => {:account_ids => 12345,
294
+ :campaigns => []})
295
+ }
296
+
297
+ assert_raises(Exception, "Bad filter criteria for CampaignPerformanceReportRequest not raised") {
298
+ performance_report_request = GnibAdsApi::CampaignPerformanceReportRequest.new(:format => :xml,
299
+ :language => :english, :report_name => "My Report",
300
+ :aggregation => :hourly, :time => :today,
301
+ :columns => [:account_name, :account_number, :time_period ],
302
+ :filter => {
303
+ # Wrong filter criteria. ie: invalid key
304
+ :not_a_valid_criteria => "Bleh",
305
+ },
306
+ :scope => {:account_ids => 12345,
307
+ :campaigns => []})
308
+ }
309
+
310
+ end
311
+
312
+ end
@@ -0,0 +1,145 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require 'test_helper'
3
+
4
+ # Public : Test case for Reporting services
5
+ #
6
+ # Author:: jlopezn@neonline.cl
7
+ class ReportingTest < ActiveSupport::TestCase
8
+
9
+ def setup
10
+
11
+ @config = GnibAdsApi::Config.instance
12
+ @options = {
13
+ :environment => :sandbox,
14
+ :username => "desarrollo_neonline",
15
+ :password => "neonline2013",
16
+ :developer_token => "BBD37VB98",
17
+ :customer_id => "21021746",
18
+ :account_id => "5978083"
19
+ }
20
+ @service = GnibAdsApi::Reporting.new(@options)
21
+
22
+ end
23
+
24
+ test "truth" do
25
+ assert_kind_of Module, GnibAdsApi
26
+ end
27
+
28
+ test "initialize" do
29
+ @service = GnibAdsApi::Reporting.new(@options)
30
+ puts @service.client_proxy.wsdl_url
31
+ assert !@service.nil?, "Reporting service not instantiated"
32
+ end
33
+
34
+
35
+ test "should submit campaign performance report" do
36
+
37
+ report_request = GnibAdsApi::CampaignPerformanceReportRequest.new(:format => :xml,
38
+ :language => :english,
39
+ :report_name => "My Report",
40
+ :aggregation => :hourly,
41
+ :columns => [:account_name, :account_number, :time_period,
42
+ :campaign_name, :campaign_id, :status, :currency_code,
43
+ :impressions, :clicks, :ctr, :average_cpc, :spend,
44
+ :conversions, :conversion_rate, :cost_per_conversion, :average_cpm ],
45
+ :filter => {
46
+ # String as bing expected
47
+ :ad_distribution => "Search",
48
+ :device_os => "Windows",
49
+ # snake case symbol
50
+ :device_type => :computer,
51
+ # nil criteria
52
+ :status => nil
53
+ },
54
+ :scope => {:account_ids => 5978083,
55
+ :campaigns => [
56
+ {:account_id => 5978083, :campaign_id => 1951230156},
57
+ {:account_id => 5978083, :campaign_id => 1951245412},
58
+ {:account_id => 5978083, :campaign_id => 1951245474}]
59
+ },
60
+ :time => {
61
+ :custom_date_range_end => {:day => 31, :month => 12, :year => 2013},
62
+ :custom_date_range_start => {:day => 1, :month => 12, :year => 2013},
63
+ })
64
+
65
+ report_request_id = nil
66
+ assert_nothing_raised(Exception, "Submit generate report raised exception") {
67
+ report_request_id = @service.submit_generate_report(report_request)
68
+ }
69
+
70
+
71
+ assert !report_request_id.nil?, "No report requeset id received"
72
+ puts "report_request_id #{report_request_id}"
73
+
74
+ end
75
+
76
+
77
+ test "should submit account performance report" do
78
+
79
+ report_request = GnibAdsApi::AccountPerformanceReportRequest.new(:format => :xml,
80
+ :language => :english,
81
+ :report_name => "My Report",
82
+ :aggregation => :hourly,
83
+ :columns => [:account_name, :account_number, :time_period,
84
+ :currency_code, :impressions, :clicks, :ctr, :average_cpc, :spend,
85
+ :conversions, :cost_per_conversion, :average_cpm ],
86
+ :filter => {
87
+ # String as bing expected
88
+ :ad_distribution => "Search",
89
+ # snake case symbol
90
+ :device_os => :windows,
91
+ # nil criteria
92
+ :device_type => nil
93
+ },
94
+ :scope => {:account_ids => 5978083 },
95
+ :time => {
96
+ :custom_date_range_end => {:day => 31, :month => 12, :year => 2013},
97
+ :custom_date_range_start => {:day => 1, :month => 12, :year => 2013},
98
+ })
99
+
100
+ report_request_id = nil
101
+ assert_nothing_raised(Exception, "Submit generate report raised exception") {
102
+ report_request_id = @service.submit_generate_report(report_request)
103
+ }
104
+
105
+
106
+ assert !report_request_id.nil?, "No report request id received"
107
+ puts "report_request_id #{report_request_id}"
108
+
109
+ end
110
+
111
+
112
+ test "initialize report request status" do
113
+ report_request_status = GnibAdsApi::ReportRequestStatus.new(:report_download_url => "http://some.url.com",
114
+ :status => "Success")
115
+ assert !report_request_status.nil?, "ReportRequestStatus not initialized"
116
+ end
117
+
118
+
119
+ test "should poll generate report" do
120
+ report_request_id = 21265212
121
+ report_request_status = nil
122
+ assert_nothing_raised(Exception, "Poll generate report raised exception") {
123
+ report_request_status = @service.poll_generate_report(report_request_id)
124
+ }
125
+
126
+ assert !report_request_status.nil?, "No report request status received"
127
+ puts "report_request_status"
128
+ puts report_request_status
129
+
130
+ assert report_request_status.error?, "report request status should not be error"
131
+ end
132
+
133
+
134
+ test "should not poll generate report" do
135
+ report_request_id = 5555555
136
+ report_request_status = nil
137
+ assert_nothing_raised(Exception, "Poll generate report raised exception") {
138
+ report_request_status = @service.poll_generate_report(report_request_id)
139
+ }
140
+
141
+ assert !report_request_status.error?, "report request status should be error"
142
+
143
+ end
144
+
145
+ end