sem4r 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (199) hide show
  1. data/Gemfile +11 -0
  2. data/Gemfile.lock +36 -0
  3. data/README.rdoc +30 -0
  4. data/Rakefile +15 -12
  5. data/VERSION.yml +1 -1
  6. data/examples_blog/2009-11-29-hello-world.rb +0 -1
  7. data/examples_sem4r/01_get_account.rb +1 -1
  8. data/examples_sem4r/02_get_info.rb +6 -2
  9. data/examples_sem4r/03_list_ad.rb +1 -1
  10. data/examples_sem4r/04_list_keywords.rb +1 -1
  11. data/examples_sem4r/05_request_report.rb +1 -2
  12. data/examples_sem4r/05_request_report_2010.rb +19 -4
  13. data/examples_sem4r/06_create_campaigns.rb +1 -1
  14. data/examples_sem4r/07_create_campaigns_block.rb +1 -1
  15. data/examples_sem4r/07_create_campaigns_simple.rb +1 -1
  16. data/examples_sem4r/08_ad_params.rb +1 -1
  17. data/examples_sem4r/09_targeting_idea.rb +1 -1
  18. data/examples_sem4r/10_get_location.rb +1 -1
  19. data/examples_sem4r/11_submit_bulk_job.rb +1 -1
  20. data/examples_sem4r/12_list_bulk_job.rb +1 -1
  21. data/examples_sem4r/30_prune_empty_adgroup.rb +1 -1
  22. data/examples_sem4r/31_empty_accounts.rb +1 -1
  23. data/examples_sem4r/example_helper.rb +5 -10
  24. data/lib/sem4r/account.rb +3 -306
  25. data/lib/sem4r/ad_group/ad_group.rb +16 -14
  26. data/lib/sem4r/ad_group/ad_group_bids.rb +11 -10
  27. data/lib/sem4r/ad_group/ad_group_service.rb +5 -5
  28. data/lib/sem4r/ad_group_ad/ad_group_ad.rb +1 -1
  29. data/lib/sem4r/ad_group_ad/ad_group_ad_service.rb +5 -5
  30. data/lib/sem4r/ad_group_ad/ad_group_mobile_ad.rb +9 -9
  31. data/lib/sem4r/ad_group_ad/ad_group_text_ad.rb +9 -9
  32. data/lib/sem4r/ad_group_criterion/ad_group_criterion.rb +6 -6
  33. data/lib/sem4r/ad_group_criterion/ad_group_criterion_bids.rb +5 -6
  34. data/lib/sem4r/ad_group_criterion/ad_group_criterion_operations.rb +0 -1
  35. data/lib/sem4r/ad_group_criterion/ad_group_criterion_service.rb +4 -4
  36. data/lib/sem4r/ad_group_criterion/criterion.rb +3 -3
  37. data/lib/sem4r/ad_group_criterion/criterion_keyword.rb +3 -3
  38. data/lib/sem4r/ad_group_criterion/criterion_placement.rb +2 -2
  39. data/lib/sem4r/ad_param/ad_param.rb +3 -3
  40. data/lib/sem4r/ad_param/ad_param_service.rb +5 -5
  41. data/lib/sem4r/adwords.rb +1 -0
  42. data/lib/sem4r/api_counters.rb +1 -0
  43. data/lib/sem4r/base.rb +1 -0
  44. data/lib/sem4r/bulk_mutate_job/bulk_mutate_job.rb +2 -2
  45. data/lib/sem4r/bulk_mutate_job/bulk_mutate_job_account_extension.rb +59 -0
  46. data/lib/sem4r/bulk_mutate_job/bulk_mutate_job_service.rb +5 -5
  47. data/lib/sem4r/campaign/campaign.rb +10 -10
  48. data/lib/sem4r/campaign/campaign_account_extension.rb +87 -0
  49. data/lib/sem4r/campaign/campaign_service.rb +6 -6
  50. data/lib/sem4r/campaign_target/campaign_target_service.rb +22 -22
  51. data/lib/sem4r/cli/cli_command.rb +1 -0
  52. data/lib/sem4r/cli/cli_common_args.rb +10 -3
  53. data/lib/sem4r/cli/cli_helpers.rb +1 -0
  54. data/lib/sem4r/cli/cli_sem.rb +1 -0
  55. data/lib/sem4r/cli/{cli_download_report.rb → commands/cli_download_report.rb} +2 -1
  56. data/lib/sem4r/cli/{cli_ideas.rb → commands/cli_ideas.rb} +1 -0
  57. data/lib/sem4r/cli/{cli_commands.rb → commands/cli_info.rb} +3 -23
  58. data/lib/sem4r/cli/{cli_list_ads.rb → commands/cli_list_ads.rb} +1 -0
  59. data/lib/sem4r/cli/commands/cli_list_campaign.rb +35 -0
  60. data/lib/sem4r/cli/commands/cli_list_client.rb +36 -0
  61. data/lib/sem4r/cli/{cli_list_keywords.rb → commands/cli_list_keywords.rb} +1 -0
  62. data/lib/sem4r/cli/commands/cli_list_report.rb +34 -0
  63. data/lib/sem4r/cli/commands/cli_repdef.rb +109 -0
  64. data/lib/sem4r/cli/commands/cli_report.rb +78 -0
  65. data/lib/sem4r/cli/{cli_request_report.rb → commands/cli_request_report.rb} +1 -0
  66. data/lib/sem4r/credentials.rb +1 -0
  67. data/lib/sem4r/extensions.rb +22 -1
  68. data/lib/sem4r/geo_location/geo_location_account_extension.rb +43 -0
  69. data/lib/sem4r/geo_location/geo_location_service.rb +4 -4
  70. data/lib/sem4r/info/info_account_extension.rb +48 -0
  71. data/lib/sem4r/info/info_selector.rb +108 -0
  72. data/lib/sem4r/info/info_service.rb +11 -66
  73. data/lib/sem4r/{common/operation.rb → operation.rb} +3 -1
  74. data/lib/sem4r/report_definition/report_definition.rb +75 -15
  75. data/lib/sem4r/report_definition/report_definition_account_extension.rb +79 -0
  76. data/lib/sem4r/report_definition/report_definition_operation.rb +3 -1
  77. data/lib/sem4r/report_definition/report_definition_service.rb +7 -7
  78. data/lib/sem4r/report_definition/report_field.rb +57 -0
  79. data/lib/sem4r/sem4r_error.rb +1 -0
  80. data/lib/sem4r/services/http_connector.rb +93 -0
  81. data/lib/sem4r/services/service.rb +1 -1
  82. data/lib/sem4r/services/soap_call.rb +27 -5
  83. data/lib/sem4r/services/soap_connector.rb +2 -147
  84. data/lib/sem4r/services/soap_dumper.rb +105 -0
  85. data/lib/sem4r/services/soap_message_v13.rb +15 -9
  86. data/lib/sem4r/services/{soap_message_v2009.rb → soap_message_v2010.rb} +26 -12
  87. data/lib/sem4r/targeting_idea/targeting_idea.rb +16 -11
  88. data/lib/sem4r/targeting_idea/targeting_idea_account_extension.rb +52 -0
  89. data/lib/sem4r/targeting_idea/targeting_idea_selector.rb +36 -10
  90. data/lib/sem4r/targeting_idea/targeting_idea_service.rb +5 -5
  91. data/lib/sem4r/v13_account/account_account_extension.rb +103 -0
  92. data/lib/sem4r/v13_account/billing_address.rb +10 -21
  93. data/lib/sem4r/v13_report/report.rb +8 -8
  94. data/lib/sem4r/v13_report/report_account_extension.rb +63 -0
  95. data/lib/sem4r/v13_report/report_job.rb +1 -1
  96. data/lib/sem4r.rb +27 -6
  97. data/lib/sem4r_cli.rb +4 -6
  98. data/lib/{sem4r → soap_helpers}/soap_attributes.rb +105 -13
  99. data/sem4r.gemspec +229 -190
  100. data/spec/{aggregates_spec_helper.rb → aggregates_rspec_helper.rb} +0 -0
  101. data/spec/build_fixtures.rb +84 -0
  102. data/spec/rspec_hash.rb +66 -0
  103. data/spec/{spec_helper.rb → rspec_helper.rb} +4 -2
  104. data/spec/rspec_matchers.rb +102 -0
  105. data/spec/rspec_sem4r_helper.rb +88 -0
  106. data/spec/sem4r/account_spec.rb +3 -4
  107. data/spec/sem4r/ad_group/ad_group_bids_spec.rb +4 -3
  108. data/spec/sem4r/ad_group/ad_group_service_spec.rb +8 -7
  109. data/spec/sem4r/ad_group/ad_group_spec.rb +5 -4
  110. data/spec/{fixtures/services/ad_group → sem4r/ad_group/fixtures}/get-first-req.xml +0 -0
  111. data/spec/{fixtures/services/ad_group → sem4r/ad_group/fixtures}/get-first-res.xml +0 -0
  112. data/spec/{fixtures/services/ad_group → sem4r/ad_group/fixtures}/get-manual-cpm-bids-req.xml +0 -0
  113. data/spec/{fixtures/services/ad_group → sem4r/ad_group/fixtures}/get-manual-cpm-bids-res.xml +0 -0
  114. data/spec/{fixtures/services/ad_group → sem4r/ad_group/fixtures}/mutate_add-req.xml +0 -0
  115. data/spec/{fixtures/services/ad_group → sem4r/ad_group/fixtures}/mutate_add-res.xml +0 -0
  116. data/spec/sem4r/ad_group_ad/ad_group_ad_operation_spec.rb +3 -3
  117. data/spec/sem4r/ad_group_ad/ad_group_ad_service_spec.rb +6 -5
  118. data/spec/sem4r/ad_group_ad/ad_group_ad_spec.rb +6 -5
  119. data/spec/{fixtures/services/ad_group_ad → sem4r/ad_group_ad/fixtures}/get_mobile_ad-req.xml +0 -0
  120. data/spec/{fixtures/services/ad_group_ad → sem4r/ad_group_ad/fixtures}/get_mobile_ad-res.xml +0 -0
  121. data/spec/{fixtures/services/ad_group_ad → sem4r/ad_group_ad/fixtures}/get_text_ad-req.xml +0 -0
  122. data/spec/{fixtures/services/ad_group_ad → sem4r/ad_group_ad/fixtures}/get_text_ad-res.xml +0 -0
  123. data/spec/{fixtures/services/ad_group_ad → sem4r/ad_group_ad/fixtures}/mutate_add_mobile_ad-req.xml +0 -0
  124. data/spec/{fixtures/services/ad_group_ad → sem4r/ad_group_ad/fixtures}/mutate_add_mobile_ad-res.xml +0 -0
  125. data/spec/{fixtures/services/ad_group_ad → sem4r/ad_group_ad/fixtures}/mutate_add_text_ad-req.xml +0 -0
  126. data/spec/{fixtures/services/ad_group_ad → sem4r/ad_group_ad/fixtures}/mutate_add_text_ad-res.xml +0 -0
  127. data/spec/{fixtures/services/ad_group_ad → sem4r/ad_group_ad/fixtures}/mutate_add_two_criterions-req.xml +0 -0
  128. data/spec/{fixtures/services/ad_group_ad → sem4r/ad_group_ad/fixtures}/mutate_add_two_criterions-res.xml +0 -0
  129. data/spec/sem4r/ad_group_criterion/ad_group_criterion_bids_spec.rb +5 -4
  130. data/spec/sem4r/ad_group_criterion/ad_group_criterion_service_spec.rb +6 -5
  131. data/spec/sem4r/ad_group_criterion/ad_group_criterion_spec.rb +6 -5
  132. data/spec/sem4r/ad_group_criterion/criterion_spec.rb +5 -4
  133. data/spec/{fixtures/services/ad_group_criterion → sem4r/ad_group_criterion/fixtures}/get-req.xml +0 -0
  134. data/spec/{fixtures/services/ad_group_criterion → sem4r/ad_group_criterion/fixtures}/get-res.xml +0 -0
  135. data/spec/{fixtures/services/ad_group_criterion → sem4r/ad_group_criterion/fixtures}/mutate_add_criterion_keyword-req.xml +0 -0
  136. data/spec/{fixtures/services/ad_group_criterion → sem4r/ad_group_criterion/fixtures}/mutate_add_criterion_keyword-res.xml +0 -0
  137. data/spec/{fixtures/services/ad_group_criterion → sem4r/ad_group_criterion/fixtures}/mutate_add_criterion_placement-req.xml +0 -0
  138. data/spec/{fixtures/services/ad_group_criterion → sem4r/ad_group_criterion/fixtures}/mutate_add_criterion_placement-res.xml +0 -0
  139. data/spec/{fixtures/services/ad_group_criterion → sem4r/ad_group_criterion/fixtures}/mutate_add_negative_keyword-req.xml +0 -0
  140. data/spec/{fixtures/services/ad_group_criterion → sem4r/ad_group_criterion/fixtures}/mutate_add_negative_keyword-res.xml +0 -0
  141. data/spec/sem4r/ad_param/ad_param_service_spec.rb +6 -5
  142. data/spec/sem4r/ad_param/ad_param_spec.rb +3 -2
  143. data/spec/{fixtures/services/ad_param → sem4r/ad_param/fixtures}/mutate_set-req.xml +0 -0
  144. data/spec/{fixtures/services/ad_param → sem4r/ad_param/fixtures}/mutate_set-res.xml +0 -0
  145. data/spec/sem4r/adwords_spec.rb +1 -1
  146. data/spec/sem4r/bulk_mutate_job/bulk_mutate_job_service_spec.rb +6 -5
  147. data/spec/sem4r/bulk_mutate_job/bulk_mutate_job_spec.rb +4 -3
  148. data/spec/{fixtures/services/bulk_mutate_job → sem4r/bulk_mutate_job/fixtures}/get-req.xml +0 -0
  149. data/spec/{fixtures/services/bulk_mutate_job → sem4r/bulk_mutate_job/fixtures}/get-res.xml +0 -0
  150. data/spec/{fixtures/services/bulk_mutate_job → sem4r/bulk_mutate_job/fixtures}/mutate-req.xml +0 -0
  151. data/spec/{fixtures/services/bulk_mutate_job → sem4r/bulk_mutate_job/fixtures}/mutate-res.xml +0 -0
  152. data/spec/sem4r/bulk_mutate_job/job_operation_spec.rb +3 -2
  153. data/spec/sem4r/campaign/campaign_service_spec.rb +8 -7
  154. data/spec/sem4r/campaign/campaign_spec.rb +3 -2
  155. data/spec/{fixtures/services/campaign → sem4r/campaign/fixtures}/get-req.xml +0 -0
  156. data/spec/{fixtures/services/campaign → sem4r/campaign/fixtures}/get-res.xml +0 -0
  157. data/spec/{fixtures/services/campaign → sem4r/campaign/fixtures}/mutate_add-req.xml +0 -0
  158. data/spec/{fixtures/services/campaign → sem4r/campaign/fixtures}/mutate_add-res.xml +0 -0
  159. data/spec/sem4r/cli/cli_spec.rb +2 -3
  160. data/spec/sem4r/credentials_spec.rb +1 -1
  161. data/spec/sem4r/info/account_info_extension_spec.rb +51 -0
  162. data/spec/sem4r/info/fixtures/get_unit_count-req.xml +34 -0
  163. data/spec/sem4r/info/fixtures/get_unit_count-res.xml +27 -0
  164. data/spec/sem4r/nokogiri_parsing_spec.rb +105 -0
  165. data/spec/{fixtures/services/report_definition → sem4r/report_definition/fixtures}/mutate_add-req.xml +0 -0
  166. data/spec/{fixtures/services/report_definition → sem4r/report_definition/fixtures}/mutate_add-req_orig.xml +0 -0
  167. data/spec/sem4r/report_definition/report_definition_service_spec.rb +5 -3
  168. data/spec/sem4r/report_definition/report_definition_spec.rb +6 -3
  169. data/spec/sem4r/rexml_parsing_spec.rb +22 -22
  170. data/spec/sem4r/services/service_spec.rb +2 -1
  171. data/spec/sem4r/services/soap_call_spec.rb +6 -5
  172. data/spec/sem4r/services/soap_message_v13_spec.rb +5 -11
  173. data/spec/{fixtures/services/targeting_idea → sem4r/targeting_idea/fixtures}/get-req-all-options.xml +0 -0
  174. data/spec/{fixtures/services/targeting_idea → sem4r/targeting_idea/fixtures}/get-req.xml +9 -11
  175. data/spec/sem4r/targeting_idea/fixtures/get-res.xml +2276 -0
  176. data/spec/sem4r/targeting_idea/targeting_idea_selector_spec.rb +30 -11
  177. data/spec/sem4r/targeting_idea/targeting_idea_service_spec.rb +4 -3
  178. data/spec/sem4r/targeting_idea/targeting_idea_spec.rb +5 -4
  179. data/spec/sem4r/v13_account/account_account_extension_spec.rb +47 -0
  180. data/spec/sem4r/v13_account/account_service_spec.rb +6 -5
  181. data/spec/sem4r/v13_account/billing_address_spec.rb +40 -0
  182. data/spec/{fixtures/services/v13_account → sem4r/v13_account/fixtures}/get_account_info-req.xml +0 -0
  183. data/spec/{fixtures/services/v13_account → sem4r/v13_account/fixtures}/get_account_info-res.xml +0 -0
  184. data/spec/{fixtures/services/v13_account → sem4r/v13_account/fixtures}/get_client_accounts-req.xml +0 -0
  185. data/spec/{fixtures/services/v13_account → sem4r/v13_account/fixtures}/get_client_accounts-res.xml +0 -0
  186. data/spec/{fixtures/services/v13_report → sem4r/v13_report/fixtures}/get_all_jobs-req.xml +0 -0
  187. data/spec/{fixtures/services/v13_report → sem4r/v13_report/fixtures}/get_all_jobs-res.xml +2 -2
  188. data/spec/{fixtures/services/v13_report → sem4r/v13_report/fixtures}/schedule_report_job-req.xml +0 -0
  189. data/spec/{fixtures/services/v13_report → sem4r/v13_report/fixtures}/schedule_report_job-res.xml +0 -0
  190. data/spec/sem4r/v13_report/report_service_spec.rb +13 -11
  191. data/spec/sem4r/v13_report/report_spec.rb +4 -3
  192. data/spec/sem4r_stubs.rb +182 -0
  193. data/spec/soap_helpers/soap_attributes_spec.rb +129 -0
  194. metadata +225 -125
  195. data/spec/fixtures/services/info/get_unit_count-req.xml +0 -30
  196. data/spec/fixtures/services/info/get_unit_count-res.xml +0 -29
  197. data/spec/fixtures/services/targeting_idea/get-res.xml +0 -3601
  198. data/spec/sem4r/soap_attributes_spec.rb +0 -116
  199. data/spec/sem4r_spec_helper.rb +0 -353
@@ -51,9 +51,9 @@ module Sem4r
51
51
 
52
52
  def self.from_element( ad_group, el )
53
53
  new(ad_group) do
54
- @id = el.elements["id"].text.strip.to_i
55
- text el.elements["text"].text.strip
56
- match el.elements["matchType"].text.strip
54
+ @id = el.at_xpath("id").text.strip.to_i
55
+ text el.at_xpath("text").text.strip
56
+ match el.at_xpath("matchType").text.strip
57
57
  end
58
58
  end
59
59
 
@@ -41,8 +41,8 @@ module Sem4r
41
41
 
42
42
  def self.from_element( ad_group, el )
43
43
  new(ad_group) do
44
- @id = el.elements["id"].text.strip.to_i
45
- url el.elements["url"].text.strip
44
+ @id = el.at_xpath("id").text.strip.to_i
45
+ url el.at_xpath("url").text.strip
46
46
  end
47
47
  end
48
48
 
@@ -72,13 +72,13 @@ module Sem4r
72
72
  end
73
73
 
74
74
  def self.from_element(ad_group, el)
75
- criterion_id = el.elements["criterionId"].text.strip.to_i
75
+ criterion_id = el.at_xpath("criterionId").text.strip.to_i
76
76
  criterion = ad_group.find_criterion(criterion_id)
77
77
  new(ad_group, criterion) do
78
78
  # ad_param don't have id so use @saved to indicate if readed from xml
79
79
  @saved = true
80
- index el.elements["paramIndex"].text.strip.to_i
81
- text el.elements["insertionText"].text.strip
80
+ index el.at_xpath("paramIndex").text.strip.to_i
81
+ text el.at_xpath("insertionText").text.strip
82
82
  end
83
83
  end
84
84
 
@@ -29,15 +29,15 @@ module Sem4r
29
29
  def initialize(connector)
30
30
  @connector = connector
31
31
 
32
- @service_namespace = "https://adwords.google.com/api/adwords/cm/v201003"
32
+ @service_namespace = "https://adwords.google.com/api/adwords/cm/v201008"
33
33
  @header_namespace = @service_namespace
34
34
 
35
- @sandbox_service_url = "https://adwords-sandbox.google.com/api/adwords/cm/v201003/AdParamService"
36
- @production_service_url = "https://adwords.google.com/api/adwords/cm/v201003/AdParamService"
35
+ @sandbox_service_url = "https://adwords-sandbox.google.com/api/adwords/cm/v201008/AdParamService"
36
+ @production_service_url = "https://adwords.google.com/api/adwords/cm/v201008/AdParamService"
37
37
  end
38
38
 
39
- soap_call_v2009 :all, :mutate => false
40
- soap_call_v2009 :mutate
39
+ soap_call_v2010 :all, :mutate => false
40
+ soap_call_v2010 :mutate
41
41
 
42
42
  private
43
43
 
data/lib/sem4r/adwords.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  # -------------------------------------------------------------------
2
3
  # Copyright (c) 2009-2010 Sem4r sem4ruby@gmail.com
3
4
  #
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  module Sem4r
2
3
  class ApiCounters
3
4
  def initialize
data/lib/sem4r/base.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  # -------------------------------------------------------------------
2
3
  # Copyright (c) 2009-2010 Sem4r sem4ruby@gmail.com
3
4
  #
@@ -94,8 +94,8 @@ module Sem4r
94
94
 
95
95
  def self.from_element(el)
96
96
  new do
97
- @id = el.elements["id"].text.strip.to_i
98
- status el.elements["status"].text
97
+ @id = el.at_xpath("id").text.strip.to_i
98
+ status el.at_xpath("status").text
99
99
  end
100
100
  end
101
101
 
@@ -0,0 +1,59 @@
1
+ # -------------------------------------------------------------------------
2
+ # Copyright (c) 2009-2010 Sem4r sem4ruby@gmail.com
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #
23
+ # -------------------------------------------------------------------------
24
+
25
+ module Sem4r
26
+
27
+ module BulkMutateJobAccountExtension
28
+ ############################################################################
29
+ # Bulk Jobs
30
+
31
+ def p_jobs
32
+ selector = BulkMutateJobSelector.new
33
+ soap_message = service.bulk_mutate_job.all(credentials, selector)
34
+ add_counters( soap_message.counters )
35
+ els = soap_message.response.xpath("//getResponse/rval")
36
+ jobs = els.map do |el|
37
+ BulkMutateJob.from_element(el)
38
+ end
39
+
40
+ puts "#{jobs.length} bulk mutate jobs"
41
+ jobs.each do |job|
42
+ puts job.to_s
43
+ end
44
+ self
45
+ end
46
+
47
+ def job_mutate(bulk_mutate_job)
48
+ soap_message = service.bulk_mutate_job.mutate(credentials, bulk_mutate_job)
49
+ add_counters( soap_message.counters )
50
+ el = soap_message.response.at_xpath("//rval")
51
+ BulkMutateJob.from_element(el)
52
+ end
53
+ end
54
+
55
+ class Account
56
+ include BulkMutateJobAccountExtension
57
+ end
58
+
59
+ end
@@ -29,15 +29,15 @@ module Sem4r
29
29
  def initialize(connector)
30
30
  @connector = connector
31
31
 
32
- @service_namespace = "https://adwords.google.com/api/adwords/cm/v201003"
32
+ @service_namespace = "https://adwords.google.com/api/adwords/cm/v201008"
33
33
  @header_namespace = @service_namespace
34
34
 
35
- @sandbox_service_url = "https://adwords-sandbox.google.com/api/adwords/job/v201003/BulkMutateJobService"
36
- @production_service_url = "https://adwords.google.com/api/adwords/job/v201003/BulkMutateJobService"
35
+ @sandbox_service_url = "https://adwords-sandbox.google.com/api/adwords/job/v201008/BulkMutateJobService"
36
+ @production_service_url = "https://adwords.google.com/api/adwords/job/v201008/BulkMutateJobService"
37
37
  end
38
38
 
39
- soap_call_v2009 :all, :mutate => false
40
- soap_call_v2009 :mutate
39
+ soap_call_v2010 :all, :mutate => false
40
+ soap_call_v2010 :mutate
41
41
 
42
42
  private
43
43
 
@@ -91,12 +91,12 @@ module Sem4r
91
91
 
92
92
  def self.from_element(account, el)
93
93
  new(account) do
94
- @id = el.elements["id"].text.strip.to_i
95
- name el.elements["name"].text.strip
96
- status el.elements['status'].text.strip # ACTIVE, PAUSED, DELETED
97
- serving_status el.elements['servingStatus']
98
- start_date el.elements['startDate']
99
- end_date el.elements['endDate']
94
+ @id = el.at_xpath("id").text.strip.to_i
95
+ name el.at_xpath("name").text.strip
96
+ status el.at_xpath('status').text.strip # ACTIVE, PAUSED, DELETED
97
+ serving_status el.at_xpath('servingStatus')
98
+ start_date el.at_xpath('startDate')
99
+ end_date el.at_xpath('endDate')
100
100
  end
101
101
  end
102
102
 
@@ -108,8 +108,8 @@ module Sem4r
108
108
  unless @id
109
109
  soap_message = service.campaign.create(credentials, to_xml)
110
110
  add_counters( soap_message.counters )
111
- rval = REXML::XPath.first( soap_message.response, "//mutateResponse/rval")
112
- id = REXML::XPath.match( rval, "value/id" ).first
111
+ rval = soap_message.response.at_xpath("//mutateResponse/rval")
112
+ id = rval.xpath("value/id").first
113
113
  @id = id.text.strip.to_i
114
114
  end
115
115
  self
@@ -180,8 +180,8 @@ module Sem4r
180
180
  def _ad_groups
181
181
  soap_message = service.ad_group.all(credentials, @id)
182
182
  add_counters( soap_message.counters )
183
- rval = REXML::XPath.first( soap_message.response, "//getResponse/rval")
184
- els = REXML::XPath.match( rval, "entries")
183
+ rval = soap_message.response.xpath("//getResponse/rval").first
184
+ els = rval.xpath( "entries")
185
185
  @ad_groups = els.map do |el|
186
186
  AdGroup.from_element(self, el)
187
187
  end
@@ -0,0 +1,87 @@
1
+ # -------------------------------------------------------------------------
2
+ # Copyright (c) 2009-2010 Sem4r sem4ruby@gmail.com
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #
23
+ # -------------------------------------------------------------------------
24
+
25
+ module Sem4r
26
+
27
+ module AccountCampaignExtension
28
+ ############################################################################
29
+ # Campaign - Service Campaign
30
+
31
+ # TODO: accettare un parametro opzionale campaign(name=nil,&block)
32
+ # la campagna che verra' creata ha il nome gia' settato
33
+ # se esiste gia' una campagna con quel nome allora fara' da contesto
34
+ # e non verra' creata
35
+ def campaign(name = nil, &block)
36
+ campaign = Campaign.new(self, name, &block)
37
+ campaign.save
38
+ @campaigns ||= []
39
+ @campaigns.push(campaign)
40
+ campaign
41
+ end
42
+
43
+ alias create_campaign campaign
44
+
45
+ def campaigns(refresh = false, opts = {}) # conditions = nil
46
+ if refresh.respond_to?(:keys)
47
+ opts = refresh
48
+ refresh = false
49
+ end
50
+ _campaigns unless @campaigns and !refresh
51
+ @campaigns
52
+ # return @campaigns unless conditions
53
+ # @campaigns.find_all {|c| c.name =~ conditions}
54
+ end
55
+
56
+ def p_campaigns(refresh = false, opts = {}) # conditions = nil
57
+ if refresh.respond_to?(:keys)
58
+ opts = refresh
59
+ refresh = false
60
+ end
61
+
62
+ cs = campaigns(refresh, opts)
63
+ puts "#{cs.length} campaigns"
64
+ campaigns(refresh).each do |campaign|
65
+ puts campaign.to_s
66
+ end
67
+ self
68
+ end
69
+
70
+ private
71
+
72
+ def _campaigns
73
+ soap_message = service.campaign.all(credentials)
74
+ add_counters( soap_message.counters )
75
+ rval = soap_message.response.at_xpath("//getResponse/rval")
76
+ els = rval.xpath("entries")
77
+ @campaigns = els.map do |el|
78
+ Campaign.from_element(self, el)
79
+ end
80
+ end
81
+ end
82
+
83
+ class Account
84
+ include AccountCampaignExtension
85
+ end
86
+
87
+ end
@@ -28,16 +28,16 @@ module Sem4r
28
28
 
29
29
  def initialize(connector)
30
30
  @connector = connector
31
- @service_namespace = "https://adwords.google.com/api/adwords/cm/v201003"
31
+ @service_namespace = "https://adwords.google.com/api/adwords/cm/v201008"
32
32
  @header_namespace = @service_namespace
33
33
 
34
- @sandbox_service_url = "https://adwords-sandbox.google.com/api/adwords/cm/v201003/CampaignService"
34
+ @sandbox_service_url = "https://adwords-sandbox.google.com/api/adwords/cm/v201008/CampaignService"
35
35
  end
36
36
 
37
- soap_call_v2009 :all, :mutate => false
38
- soap_call_v2009 :create
39
- soap_call_v2009 :delete
40
-
37
+ soap_call_v2010 :all, :mutate => false
38
+ soap_call_v2010 :create
39
+ soap_call_v2010 :delete
40
+
41
41
  private
42
42
 
43
43
  def _all(statuses = [Campaign::ACTIVE, Campaign::PAUSED])
@@ -1,25 +1,25 @@
1
- ## -------------------------------------------------------------------
2
- ## Copyright (c) 2009-2010 Sem4r sem4ruby@gmail.com
3
- ##
4
- ## Permission is hereby granted, free of charge, to any person obtaining
5
- ## a copy of this software and associated documentation files (the
6
- ## "Software"), to deal in the Software without restriction, including
7
- ## without limitation the rights to use, copy, modify, merge, publish,
8
- ## distribute, sublicense, and/or sell copies of the Software, and to
9
- ## permit persons to whom the Software is furnished to do so, subject to
10
- ## the following conditions:
11
- ##
12
- ## The above copyright notice and this permission notice shall be
13
- ## included in all copies or substantial portions of the Software.
14
- ##
15
- ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
- ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
- ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
- ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
- ## LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
- ## OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
- ## WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
- ## -------------------------------------------------------------------
1
+ # -------------------------------------------------------------------
2
+ # Copyright (c) 2009-2010 Sem4r sem4ruby@gmail.com
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ # -------------------------------------------------------------------
23
23
 
24
24
  module Sem4r
25
25
  class CampaignTargetService
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  # -------------------------------------------------------------------------
2
3
  # Copyright (c) 2009-2010 Sem4r sem4ruby@gmail.com
3
4
  #
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  # -------------------------------------------------------------------------
2
3
  # Copyright (c) 2009-2010 Sem4r sem4ruby@gmail.com
3
4
  #
@@ -66,6 +67,10 @@ module Sem4r
66
67
  end
67
68
  end
68
69
 
70
+ if @options.ask_password
71
+ puts "ask_password"
72
+ end
73
+
69
74
  !@options.exit
70
75
  end
71
76
 
@@ -162,9 +167,11 @@ module Sem4r
162
167
  end
163
168
 
164
169
  # password
165
- opt_parser.on("--password PASSWORD",
166
- "password of adwords account") do |password|
167
- options.password = password
170
+ opt_parser.on("--password [PASSWORD]",
171
+ "password of adwords account",
172
+ "If password is not given it's asked from the tty") do |password|
173
+ options.ask_password = !password
174
+ options.password = password if password
168
175
  end
169
176
 
170
177
  # developer token
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  module Sem4r
2
3
  # From http://gist.github.com/72234
3
4
  #
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  # -------------------------------------------------------------------
2
3
  # Copyright (c) 2009-2010 Sem4r sem4ruby@gmail.com
3
4
  #
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  # -------------------------------------------------------------------------
2
3
  # Copyright (c) 2009-2010 Sem4r sem4ruby@gmail.com
3
4
  #
@@ -78,4 +79,4 @@ module Sem4r
78
79
  end
79
80
 
80
81
  end
81
- end
82
+ end
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  # -------------------------------------------------------------------------
2
3
  # Copyright (c) 2009-2010 Sem4r sem4ruby@gmail.com
3
4
  #
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  # -------------------------------------------------------------------------
2
3
  # Copyright (c) 2009-2010 Sem4r sem4ruby@gmail.com
3
4
  #
@@ -24,22 +25,8 @@
24
25
 
25
26
  module Sem4r
26
27
 
27
- CliListClient = CliCommand.define_command("clients", "list clients account") do |account|
28
- puts account.adwords.to_s
29
- puts account.to_s
30
- account.p_client_accounts
31
- account.adwords.p_counters
32
- true
33
- end
34
-
35
- CliListReport = CliCommand.define_command("reports", "list reports") do |account|
36
- report(account.reports, :id, :name, :status)
37
- account.adwords.p_counters
38
- true
39
- end
40
-
41
28
  CliInfo = CliCommand.define_command("info", "account info") do |account|
42
- account.p_info
29
+ account.p_info
43
30
  items = (Account::UsageTypes - [Account::METHOD_COST]).map do |usage_type|
44
31
  n = account.year_unit_cost(usage_type)
45
32
  # puts "#{usage_type} -> #{n}"
@@ -50,11 +37,4 @@ module Sem4r
50
37
  true
51
38
  end
52
39
 
53
- CliCampaign = CliCommand.define_command("campaigns", "list campaigns") do |account|
54
- puts "listing campaings in #{account}"
55
- report( account.campaigns, :id, :name, :status )
56
- account.adwords.p_counters
57
- true
58
- end
59
-
60
- end
40
+ end
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  # -------------------------------------------------------------------------
2
3
  # Copyright (c) 2009-2010 Sem4r sem4ruby@gmail.com
3
4
  #
@@ -0,0 +1,35 @@
1
+ # -*- coding: utf-8 -*-
2
+ # -------------------------------------------------------------------------
3
+ # Copyright (c) 2009-2010 Sem4r sem4ruby@gmail.com
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining
6
+ # a copy of this software and associated documentation files (the
7
+ # "Software"), to deal in the Software without restriction, including
8
+ # without limitation the rights to use, copy, modify, merge, publish,
9
+ # distribute, sublicense, and/or sell copies of the Software, and to
10
+ # permit persons to whom the Software is furnished to do so, subject to
11
+ # the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be
14
+ # included in all copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+ #
24
+ # -------------------------------------------------------------------------
25
+
26
+ module Sem4r
27
+
28
+ CliListCampaign = CliCommand.define_command("campaigns", "list campaigns") do |account|
29
+ puts "listing campaings in #{account}"
30
+ report( account.campaigns, :id, :name, :status )
31
+ account.adwords.p_counters
32
+ true
33
+ end
34
+
35
+ end
@@ -0,0 +1,36 @@
1
+ # -*- coding: utf-8 -*-
2
+ # -------------------------------------------------------------------------
3
+ # Copyright (c) 2009-2010 Sem4r sem4ruby@gmail.com
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining
6
+ # a copy of this software and associated documentation files (the
7
+ # "Software"), to deal in the Software without restriction, including
8
+ # without limitation the rights to use, copy, modify, merge, publish,
9
+ # distribute, sublicense, and/or sell copies of the Software, and to
10
+ # permit persons to whom the Software is furnished to do so, subject to
11
+ # the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be
14
+ # included in all copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+ #
24
+ # -------------------------------------------------------------------------
25
+
26
+ module Sem4r
27
+
28
+ CliListClient = CliCommand.define_command("clients", "list clients account") do |account|
29
+ puts account.adwords.to_s
30
+ puts account.to_s
31
+ account.p_client_accounts
32
+ account.adwords.p_counters
33
+ true
34
+ end
35
+
36
+ end
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  # -------------------------------------------------------------------------
2
3
  # Copyright (c) 2009-2010 Sem4r sem4ruby@gmail.com
3
4
  #
@@ -0,0 +1,34 @@
1
+ # -*- coding: utf-8 -*-
2
+ # -------------------------------------------------------------------------
3
+ # Copyright (c) 2009-2010 Sem4r sem4ruby@gmail.com
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining
6
+ # a copy of this software and associated documentation files (the
7
+ # "Software"), to deal in the Software without restriction, including
8
+ # without limitation the rights to use, copy, modify, merge, publish,
9
+ # distribute, sublicense, and/or sell copies of the Software, and to
10
+ # permit persons to whom the Software is furnished to do so, subject to
11
+ # the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be
14
+ # included in all copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+ #
24
+ # -------------------------------------------------------------------------
25
+
26
+ module Sem4r
27
+
28
+ CliListReport = CliCommand.define_command("reports", "list reports") do |account|
29
+ report(account.reports, :id, :name, :status)
30
+ account.adwords.p_counters
31
+ true
32
+ end
33
+
34
+ end