sem4r 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (175) hide show
  1. data/Gemfile +13 -2
  2. data/Gemfile.lock +13 -7
  3. data/README.rdoc +44 -7
  4. data/Rakefile +2 -122
  5. data/VERSION.yml +1 -1
  6. data/bin/sem +1 -0
  7. data/examples_sem4r/01_get_account.rb +1 -0
  8. data/examples_sem4r/02_get_info.rb +1 -0
  9. data/examples_sem4r/03_list_ad.rb +1 -0
  10. data/examples_sem4r/04_list_keywords.rb +1 -0
  11. data/examples_sem4r/05_request_report.rb +25 -14
  12. data/examples_sem4r/{05_request_report_2010.rb → 06_request_report_definition.rb} +2 -4
  13. data/examples_sem4r/{06_create_campaigns.rb → 07_create_campaigns.rb} +1 -0
  14. data/examples_sem4r/{07_create_campaigns_block.rb → 08_create_campaigns_block.rb} +1 -0
  15. data/examples_sem4r/{07_create_campaigns_simple.rb → 09_create_campaigns_simple.rb} +1 -0
  16. data/examples_sem4r/{08_ad_params.rb → 10_ad_params.rb} +1 -0
  17. data/examples_sem4r/{09_targeting_idea.rb → 11_targeting_idea.rb} +1 -0
  18. data/examples_sem4r/{10_get_location.rb → 12_get_location.rb} +1 -0
  19. data/examples_sem4r/{11_submit_bulk_job.rb → 13_submit_bulk_job.rb} +1 -1
  20. data/examples_sem4r/{12_list_bulk_job.rb → 14_list_bulk_job.rb} +3 -0
  21. data/examples_sem4r/30_prune_empty_adgroup.rb +1 -0
  22. data/examples_sem4r/31_empty_accounts.rb +1 -0
  23. data/examples_sem4r/example_helper.rb +2 -1
  24. data/lib/sem4r/ad_group/ad_group.rb +22 -7
  25. data/lib/sem4r/ad_group/ad_group_bids.rb +1 -1
  26. data/lib/sem4r/ad_group/ad_group_service.rb +12 -5
  27. data/lib/sem4r/ad_group_ad/ad_group_ad.rb +1 -0
  28. data/lib/sem4r/ad_group_ad/ad_group_ad_operations.rb +1 -0
  29. data/lib/sem4r/ad_group_ad/ad_group_ad_service.rb +14 -9
  30. data/lib/sem4r/ad_group_ad/ad_group_mobile_ad.rb +16 -25
  31. data/lib/sem4r/ad_group_ad/ad_group_text_ad.rb +18 -14
  32. data/lib/sem4r/ad_group_criterion/ad_group_criterion.rb +27 -19
  33. data/lib/sem4r/ad_group_criterion/ad_group_criterion_bids.rb +2 -1
  34. data/lib/sem4r/ad_group_criterion/ad_group_criterion_operations.rb +1 -0
  35. data/lib/sem4r/ad_group_criterion/ad_group_criterion_service.rb +9 -4
  36. data/lib/sem4r/ad_group_criterion/criterion.rb +1 -0
  37. data/lib/sem4r/ad_group_criterion/criterion_keyword.rb +1 -0
  38. data/lib/sem4r/ad_group_criterion/criterion_placement.rb +1 -0
  39. data/lib/sem4r/ad_param/ad_param.rb +24 -8
  40. data/lib/sem4r/ad_param/ad_param_service.rb +8 -5
  41. data/lib/sem4r/adwords.rb +232 -76
  42. data/lib/sem4r/base.rb +1 -1
  43. data/lib/sem4r/bulk_mutate_job/bulk_mutate_job.rb +41 -35
  44. data/lib/sem4r/bulk_mutate_job/bulk_mutate_job_account_extension.rb +49 -15
  45. data/lib/sem4r/bulk_mutate_job/bulk_mutate_job_selector.rb +29 -20
  46. data/lib/sem4r/bulk_mutate_job/bulk_mutate_job_service.rb +13 -14
  47. data/lib/sem4r/bulk_mutate_job/job_operations.rb +1 -1
  48. data/lib/sem4r/campaign/campaign.rb +1 -0
  49. data/lib/sem4r/campaign/campaign_account_extension.rb +2 -1
  50. data/lib/sem4r/campaign/campaign_service.rb +9 -5
  51. data/lib/sem4r/credentials.rb +11 -5
  52. data/lib/sem4r/geo_location/address.rb +56 -0
  53. data/lib/sem4r/geo_location/geo_location_account_extension.rb +27 -6
  54. data/lib/sem4r/geo_location/geo_location_selector.rb +57 -0
  55. data/lib/sem4r/geo_location/geo_location_service.rb +9 -16
  56. data/lib/sem4r/info/info_account_extension.rb +3 -2
  57. data/lib/sem4r/info/info_selector.rb +2 -1
  58. data/lib/sem4r/info/info_service.rb +10 -3
  59. data/lib/sem4r/operation.rb +39 -20
  60. data/lib/sem4r/report_definition/report_definition.rb +37 -19
  61. data/lib/sem4r/report_definition/report_definition_account_extension.rb +66 -16
  62. data/lib/sem4r/report_definition/report_definition_operation.rb +2 -2
  63. data/lib/sem4r/report_definition/report_definition_selector.rb +1 -1
  64. data/lib/sem4r/report_definition/report_definition_service.rb +11 -7
  65. data/lib/sem4r/report_definition/report_field.rb +3 -2
  66. data/lib/sem4r/sem4r_templates.rb +77 -0
  67. data/lib/sem4r/{services/service.rb → service.rb} +23 -23
  68. data/lib/sem4r/targeting_idea/targeting_idea.rb +4 -4
  69. data/lib/sem4r/targeting_idea/targeting_idea_account_extension.rb +1 -1
  70. data/lib/sem4r/targeting_idea/targeting_idea_selector.rb +6 -6
  71. data/lib/sem4r/targeting_idea/targeting_idea_service.rb +7 -5
  72. data/lib/sem4r/v13_account/account_account_extension.rb +7 -10
  73. data/lib/sem4r/v13_account/account_service.rb +10 -4
  74. data/lib/sem4r/v13_account/billing_address.rb +2 -2
  75. data/lib/sem4r/v13_report/report_service.rb +11 -9
  76. data/lib/sem4r.rb +46 -31
  77. data/lib/{sem4r/cli → sem4r_cli}/cli_helpers.rb +3 -2
  78. data/lib/{sem4r/cli/cli_command.rb → sem4r_cli/cli_mini_framework.rb} +77 -32
  79. data/lib/{sem4r/cli/cli_common_args.rb → sem4r_cli/cli_sem.rb} +177 -157
  80. data/lib/{sem4r/cli/commands/cli_list_ads.rb → sem4r_cli/commands/cli_ads.rb} +7 -9
  81. data/lib/sem4r_cli/commands/cli_campaign.rb +69 -0
  82. data/lib/{sem4r/cli/commands/cli_list_client.rb → sem4r_cli/commands/cli_clients.rb} +2 -2
  83. data/lib/{sem4r/cli → sem4r_cli}/commands/cli_ideas.rb +35 -27
  84. data/lib/{sem4r/cli → sem4r_cli}/commands/cli_info.rb +3 -4
  85. data/lib/{sem4r/cli/commands/cli_repdef.rb → sem4r_cli/commands/cli_job.rb} +57 -55
  86. data/lib/{sem4r/cli/commands/cli_list_keywords.rb → sem4r_cli/commands/cli_keywords.rb} +14 -13
  87. data/lib/sem4r_cli/commands/cli_profile.rb +138 -0
  88. data/lib/{sem4r/cli/commands/cli_report.rb → sem4r_cli/commands/cli_repdef.rb} +67 -20
  89. data/lib/{sem4r/cli/commands/cli_request_report.rb → sem4r_cli/commands/cli_report.rb} +82 -19
  90. data/lib/sem4r_cli.rb +5 -7
  91. data/lib/sem4r_soap/http_connector.rb +206 -0
  92. data/lib/{soap_helpers → sem4r_soap}/soap_attributes.rb +8 -3
  93. data/lib/{sem4r/services → sem4r_soap}/soap_dumper.rb +36 -20
  94. data/lib/{sem4r/services → sem4r_soap}/soap_error.rb +5 -2
  95. data/lib/sem4r_soap/soap_response.rb +75 -0
  96. data/lib/sem4r_soap/soap_service.rb +137 -0
  97. data/lib/{sem4r/cli/cli_sem.rb → sem4r_soap/soap_service_v13.rb} +27 -28
  98. data/lib/sem4r_soap/soap_service_v2010.rb +80 -0
  99. data/lib/sem4r_soap.rb +17 -0
  100. data/sem4r.gemspec +93 -58
  101. data/spec/build_fixtures.rb +49 -42
  102. data/spec/fixtures/password.example.yml +3 -0
  103. data/spec/fixtures/sem4r.example.yml +6 -0
  104. data/spec/fixtures/{services/error.xml → soap_error.xml} +0 -0
  105. data/spec/fixtures/soap_error2.xml +29 -0
  106. data/spec/helpers/dump_interceptor.rb +90 -0
  107. data/spec/helpers/fixtures_bulk_mutate_job.rb +48 -0
  108. data/spec/helpers/fixtures_geo_location.rb +45 -0
  109. data/{lib/sem4r/campaign_criterion/campaign_criterion_service.rb → spec/helpers/fixtures_info.rb} +10 -6
  110. data/spec/helpers/fixtures_report_definition.rb +65 -0
  111. data/spec/{rspec_hash.rb → helpers/rspec_hash.rb} +1 -0
  112. data/spec/{rspec_matchers.rb → helpers/rspec_matchers.rb} +46 -19
  113. data/spec/{rspec_sem4r_helper.rb → helpers/rspec_sem4r_helper.rb} +19 -16
  114. data/spec/{sem4r_stubs.rb → helpers/sem4r_stubs.rb} +5 -4
  115. data/spec/rspec_helper.rb +4 -4
  116. data/spec/sem4r/account_spec.rb +2 -3
  117. data/spec/sem4r/ad_group/ad_group_service_spec.rb +1 -1
  118. data/spec/sem4r/ad_group/ad_group_spec.rb +1 -1
  119. data/spec/sem4r/ad_group_ad/ad_group_ad_operation_spec.rb +3 -3
  120. data/spec/sem4r/adwords_spec.rb +62 -39
  121. data/{lib/sem4r/cli/commands/cli_list_campaign.rb → spec/sem4r/bulk_mutate_job/bulk_mutate_job_selector_spec.rb} +14 -11
  122. data/spec/sem4r/bulk_mutate_job/bulk_mutate_job_service_spec.rb +2 -3
  123. data/spec/sem4r/bulk_mutate_job/bulk_mutate_job_spec.rb +23 -17
  124. data/spec/sem4r/bulk_mutate_job/fixtures/get-list_job-req.xml +35 -0
  125. data/spec/sem4r/bulk_mutate_job/fixtures/get-list_job-res.xml +417 -0
  126. data/spec/sem4r/bulk_mutate_job/fixtures/mutate-add_job-req.xml +106 -0
  127. data/spec/sem4r/bulk_mutate_job/fixtures/mutate-add_job-res.xml +48 -0
  128. data/spec/sem4r/bulk_mutate_job/job_operation_spec.rb +5 -7
  129. data/spec/sem4r/campaign/campaign_service_spec.rb +2 -2
  130. data/spec/sem4r/credentials_spec.rb +10 -8
  131. data/spec/sem4r/geo_location/address_spec.rb +62 -0
  132. data/spec/sem4r/geo_location/fixtures/get-req.xml +42 -0
  133. data/spec/sem4r/geo_location/fixtures/get-res.xml +60 -0
  134. data/spec/sem4r/info/fixtures/get-req.xml +34 -0
  135. data/spec/sem4r/info/fixtures/get-res.xml +27 -0
  136. data/spec/sem4r/nokogiri_parsing_spec.rb +1 -0
  137. data/spec/sem4r/operation_spec.rb +72 -0
  138. data/spec/sem4r/report_definition/fixtures/get-list-repdef-req.xml +22 -0
  139. data/spec/sem4r/report_definition/fixtures/get-list-repdef-res.xml +73 -0
  140. data/spec/sem4r/report_definition/fixtures/getReportFields-req.xml +24 -0
  141. data/spec/sem4r/report_definition/fixtures/getReportFields-res.xml +1199 -0
  142. data/spec/sem4r/report_definition/fixtures/mutate-add-report-req.xml +63 -0
  143. data/spec/sem4r/report_definition/fixtures/mutate-add-report-res.xml +68 -0
  144. data/spec/sem4r/report_definition/report_definition_service_spec.rb +5 -5
  145. data/spec/sem4r/report_definition/report_definition_spec.rb +28 -43
  146. data/{lib/sem4r/cli/commands/cli_list_report.rb → spec/sem4r/report_definition/report_field_spec.rb} +12 -10
  147. data/spec/sem4r/rexml_parsing_spec.rb +1 -0
  148. data/spec/sem4r/{services/service_spec.rb → service_spec.rb} +1 -1
  149. data/spec/sem4r/targeting_idea/targeting_idea_selector_spec.rb +1 -1
  150. data/spec/sem4r/targeting_idea/targeting_idea_service_spec.rb +1 -1
  151. data/spec/sem4r/targeting_idea/targeting_idea_spec.rb +1 -1
  152. data/spec/sem4r/v13_account/account_service_spec.rb +2 -2
  153. data/spec/sem4r/v13_report/report_service_spec.rb +2 -2
  154. data/spec/{sem4r/cli → sem4r_cli}/cli_spec.rb +22 -27
  155. data/spec/{soap_helpers → sem4r_soap}/soap_attributes_spec.rb +3 -3
  156. data/spec/{sem4r/services/soap_message_v13_spec.rb → sem4r_soap/soap_response_spec.rb} +10 -15
  157. data/spec/{sem4r/services/soap_call_spec.rb → sem4r_soap/soap_service_spec.rb} +35 -54
  158. data/tasks/jeweler.rake +66 -0
  159. data/tasks/rspec.rake +21 -0
  160. data/tasks/sem4r.rake +25 -0
  161. data/tasks/yard.rake +31 -0
  162. metadata +173 -76
  163. data/lib/sem4r/ad_extension_override/ad_extension_override_service.rb +0 -30
  164. data/lib/sem4r/api_counters.rb +0 -8
  165. data/lib/sem4r/campaign_target/campaign_target_service.rb +0 -30
  166. data/lib/sem4r/cli/commands/cli_download_report.rb +0 -82
  167. data/lib/sem4r/services/http_connector.rb +0 -93
  168. data/lib/sem4r/services/soap_call.rb +0 -122
  169. data/lib/sem4r/services/soap_connector.rb +0 -139
  170. data/lib/sem4r/services/soap_message_v13.rb +0 -135
  171. data/lib/sem4r/services/soap_message_v2010.rb +0 -184
  172. data/lib/sem4r/v13_traffic_estimator/traffic_estimator_service.rb +0 -30
  173. data/spec/aggregates_rspec_helper.rb +0 -59
  174. data/spec/sem4r/report_definition/fixtures/mutate_add-req.xml +0 -24
  175. data/spec/sem4r/report_definition/fixtures/mutate_add-req_orig.xml +0 -45
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  # -------------------------------------------------------------------------
2
3
  # Copyright (c) 2009-2010 Sem4r sem4ruby@gmail.com
3
4
  #
@@ -19,41 +20,90 @@
19
20
  # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
21
  # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
22
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
- #
23
23
  # -------------------------------------------------------------------------
24
24
 
25
25
  module Sem4r
26
-
27
- module ReportDefinitionAccountExtension
28
26
 
29
- def report_definition_delete(report_definition_id)
30
- report_definition = ReportDefinition.new(self)
31
- report_definition.instance_eval { @id = report_definition_id }
32
- op = ReportDefinitionOperation.new
33
- op.remove(report_definition)
34
- soap_message = service.report_definition.mutate(credentials, op.to_xml("operations"))
35
- add_counters( soap_message.counters )
36
- end
27
+ module ReportDefinitionAccountExtension
37
28
 
38
- def report_fields
39
- soap_message = service.report_definition.report_fields(credentials)
40
- add_counters( soap_message.counters )
29
+ #
30
+ # Query the list of field for a report type
31
+ # @param [ReportDefinition::ReportTypes] a value of
32
+ #
33
+ def report_fields(report_type)
34
+ soap_message = service.report_definition.report_fields(credentials, report_type)
35
+ add_counters(soap_message.counters)
41
36
  els = soap_message.response.xpath("//getReportFieldsResponse/rval")
42
37
  els.map do |el|
43
38
  ReportField.from_element(el)
44
39
  end
45
40
  end
46
41
 
42
+ #
43
+ # Delete a report definition
44
+ #
45
+ # @param[ReportDefinition, Number]
46
+ #
47
+ def report_definition_delete(repdef_or_id)
48
+ if repdef_or_id.class == ReportDefinition
49
+ report_definition = repdef_or_id
50
+ else
51
+ report_definition = ReportDefinition.new(self)
52
+ report_definition.instance_eval { @id = repdef_or_id }
53
+ end
54
+
55
+ op = ReportDefinitionOperation.remove(report_definition)
56
+ soap_message = service.report_definition.mutate(credentials, op.to_xml)
57
+ add_counters(soap_message.counters)
58
+
59
+ unless @report_definitions
60
+ @report_definition.delete_if { |repdef| repdef == report_definition.id }
61
+ end
62
+ report_definition.instance_eval { @id = -1 } # repdef status invalid/deleted
63
+ self
64
+ end
65
+
66
+ #
67
+ # Delete all report definition
68
+ #
69
+ def report_definition_delete_all
70
+ report_definitions.each do |repdef|
71
+ repdef.delete
72
+ end
73
+ end
74
+
75
+ #
76
+ # Create a new report definition
77
+ # @yield report definition DSL
78
+ # @return [ReportDefinition] in unsaved state
79
+ #
80
+ # @example
81
+ # account.report_definition do
82
+ # name "MyReport"
83
+ # ...
84
+ # end
85
+ #
47
86
  def report_definition(&block)
48
87
  ReportDefinition.new(self, &block)
49
88
  end
50
89
 
90
+ #
91
+ # Prints on stdout the list of report definition contained into account
92
+ # @param [bool] true if the list must be refreshed
93
+ # @return self
94
+ #
51
95
  def p_report_definitions(refresh = false)
52
96
  report_definitions(refresh).each do |report_definition|
53
97
  puts report_definition.to_s
54
98
  end
99
+ self
55
100
  end
56
101
 
102
+ #
103
+ # Returns an array of ReportDefinition
104
+ # @param [bool] true if the list must be refreshed
105
+ # @return [Array of ReportDefinition]
106
+ #
57
107
  def report_definitions(refresh = false)
58
108
  _report_definitions unless @report_definitions and !refresh
59
109
  @report_definitions
@@ -63,8 +113,8 @@ module Sem4r
63
113
 
64
114
  def _report_definitions
65
115
  soap_message = service.report_definition.get(credentials, ReportDefinitionSelector.new.to_xml)
66
- add_counters( soap_message.counters )
67
- els = soap_message.response.xpath("//entries")
116
+ add_counters(soap_message.counters)
117
+ els = soap_message.response.xpath("//entries")
68
118
  @report_definitions = els.map do |el|
69
119
  ReportDefinition.from_element(self, el)
70
120
  end
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  # -------------------------------------------------------------------------
2
3
  # Copyright (c) 2009-2010 Sem4r sem4ruby@gmail.com
3
4
  #
@@ -19,14 +20,13 @@
19
20
  # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
21
  # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
22
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
- #
23
23
  # -------------------------------------------------------------------------
24
24
 
25
25
  module Sem4r
26
26
  class ReportDefinitionOperation < Operation
27
27
  def initialize(&block)
28
28
  @operation_type = "n1:ReportDefinitionOperation"
29
- @namespace = 'xmlns:n1="https://adwords.google.com/api/adwords/cm/v201008"'
29
+ @attrs = {'xmlns:n1'=>"https://adwords.google.com/api/adwords/cm/v201008"}
30
30
  if block_given?
31
31
  block.arity < 1 ? instance_eval(&block) : block.call(self)
32
32
  end
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  # -------------------------------------------------------------------------
2
3
  # Copyright (c) 2009-2010 Sem4r sem4ruby@gmail.com
3
4
  #
@@ -19,7 +20,6 @@
19
20
  # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
21
  # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
22
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
- #
23
23
  # -------------------------------------------------------------------------
24
24
 
25
25
  module Sem4r
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  # -------------------------------------------------------------------
2
3
  # Copyright (c) 2009-2010 Sem4r sem4ruby@gmail.com
3
4
  #
@@ -23,19 +24,22 @@
23
24
 
24
25
  module Sem4r
25
26
 
26
- class ReportDefinitionService
27
- include SoapCall
27
+ #
28
+ # @private
29
+ #
30
+ class ReportDefinitionService < Sem4rSoap::SoapServiceV2010
28
31
 
29
32
  def initialize(connector)
30
33
  @connector = connector
31
34
  @header_namespace = "https://adwords.google.com/api/adwords/cm/v201008"
32
35
 
33
36
  @sandbox_service_url = "https://adwords-sandbox.google.com/api/adwords/cm/v201008/ReportDefinitionService"
37
+ init(@header_namespace, @service_namespace)
34
38
  end
35
39
 
36
- soap_call_v2010 :get, :mutate => false
37
- soap_call_v2010 :report_fields, :mutate => false
38
- soap_call_v2010 :mutate
40
+ soap_call :get, :mutate => false
41
+ soap_call :report_fields, :mutate => false
42
+ soap_call :mutate
39
43
 
40
44
  private
41
45
 
@@ -43,8 +47,8 @@ module Sem4r
43
47
  "<get>#{xml}</get>"
44
48
  end
45
49
 
46
- def _report_fields
47
- "<getReportFields><reportType>URL_PERFORMANCE_REPORT</reportType></getReportFields>"
50
+ def _report_fields(report_type)
51
+ "<getReportFields><reportType>#{report_type}</reportType></getReportFields>"
48
52
  end
49
53
 
50
54
  def _mutate(xml)
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  # -------------------------------------------------------------------
2
3
  # Copyright (c) 2009-2010 Sem4r sem4ruby@gmail.com
3
4
  #
@@ -24,7 +25,7 @@
24
25
  module Sem4r
25
26
 
26
27
  class ReportField
27
- include SoapAttributes
28
+ include Sem4rSoap::SoapAttributes
28
29
 
29
30
  attrs =[
30
31
  :field_name,
@@ -50,7 +51,7 @@ module Sem4r
50
51
  end
51
52
 
52
53
  def to_s
53
- "#{@field_name} #{@field_type} #{@address_line2} #{@city}"
54
+ "#{@field_name} #{@field_type}"
54
55
  end
55
56
 
56
57
  end
@@ -0,0 +1,77 @@
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
+ module Sem4r
26
+
27
+ # @private
28
+ #
29
+ # create an example mutate job useful for test, example, etc
30
+ #
31
+ def template_campaign_and_ad_group(account)
32
+ client_account = account.client_accounts.first
33
+
34
+ campaign = Campaign.create(client_account) do
35
+ name "campaign #{Time.now.strftime('%m%d-%H%M%S')}"
36
+ end
37
+
38
+ ad_group = campaign.ad_group do
39
+ name "adgroup #{Time.now.strftime('%m%d-%H%M%S')}"
40
+ end
41
+
42
+ puts "created campaign '#{campaign.name}' with id '#{campaign.id}'"
43
+ puts "created adgroup '#{ad_group.name}' with id '#{ad_group.id}'"
44
+ [campaign, ad_group]
45
+ end
46
+
47
+ # @private
48
+ #
49
+ # create an example mutate job useful for test, example, etc
50
+ #
51
+ def template_bulk_mutate_job(campaign, adgroup)
52
+ # TextAd
53
+ text_ad1 = AdGroupTextAd.new(adgroup)
54
+ text_ad1.headline = "Cruise to Mars Sector 1"
55
+ text_ad1.description1 = "Visit the Red Planet in style."
56
+ text_ad1.description2 = "Low-gravity fun for everyone!"
57
+ text_ad1.url = "http://www.example.com"
58
+ text_ad1.display_url = "www.example.com"
59
+
60
+ # TextAd
61
+ text_ad2 = AdGroupTextAd.new(adgroup)
62
+ text_ad2.headline = "Cruise to Mars Sector 2"
63
+ text_ad2.description1 = "Visit the Red Planet in style."
64
+ text_ad2.description2 = "Low-gravity fun for everyone!"
65
+ text_ad2.url = "http://www.example.com"
66
+ text_ad2.display_url = "www.example.com"
67
+
68
+
69
+ bulk_mutate_job = BulkMutateJob.new
70
+ bulk_mutate_job.campaign_id = campaign.id
71
+ bulk_mutate_job.add_operation AdGroupAdOperation.add text_ad1
72
+ bulk_mutate_job.add_operation AdGroupAdOperation.add text_ad2
73
+
74
+ bulk_mutate_job
75
+ end
76
+
77
+ end
@@ -22,53 +22,53 @@
22
22
  # -------------------------------------------------------------------
23
23
 
24
24
  module Sem4r
25
- class Service
26
25
 
27
- def initialize(connector)
28
- @connector = connector
29
- end
26
+ class Service #:nodoc: all
27
+
28
+ def initialize(connector)
29
+ @connector = connector
30
+ end
30
31
 
31
- ###########################################################################
32
- # services v13
32
+ ###########################################################################
33
+ # services v13
33
34
 
34
- %w{ account report traffic_estimator }.each do |service|
35
- klass_name = service.split('_').map{|p| p.capitalize}.join('')
36
- str=<<-EOFR
35
+ %w{ account report }.each do |service|
36
+ klass_name = service.split('_').map{|p| p.capitalize}.join('')
37
+ str=<<-EOFR
37
38
  require 'sem4r/v13_#{service}/#{service}_service'
38
39
  def #{service}
39
40
  return @#{service}_service if @#{service}_service
40
41
  @#{service}_service = #{klass_name}Service.new(@connector)
41
42
  end
42
- EOFR
43
- eval str
44
- end
43
+ EOFR
44
+ eval str
45
+ end
45
46
 
46
- ###########################################################################
47
- # services v2010xx
47
+ ###########################################################################
48
+ # services v2010xx
48
49
 
49
- %w{ ad_extension_override
50
+ %w{
50
51
  ad_group
51
52
  ad_group_ad
52
53
  ad_param
53
54
  ad_group_criterion
54
55
  campaign
55
- campaign_criterion
56
- campaign_target
57
56
  geo_location
58
57
  info
59
58
  targeting_idea
60
59
  bulk_mutate_job
61
60
  report_definition }.each do |service|
62
- klass_name = service.split('_').map{|p| p.capitalize}.join('')
63
- str=<<-EOFR
61
+ klass_name = service.split('_').map{|p| p.capitalize}.join('')
62
+ str=<<-EOFR
64
63
  require 'sem4r/#{service}/#{service}_service'
65
64
  def #{service}
66
65
  return @#{service}_service if @#{service}_service
67
66
  @#{service}_service = #{klass_name}Service.new(@connector)
68
67
  end
69
- EOFR
70
- eval str
68
+ EOFR
69
+ eval str
70
+ end
71
+
71
72
  end
72
73
 
73
- end
74
- end
74
+ end # module Sem4r
@@ -26,7 +26,7 @@ module Sem4r
26
26
 
27
27
 
28
28
  class TargetingIdea
29
- include SoapAttributes
29
+ include Sem4rSoap::SoapAttributes
30
30
 
31
31
  enum :AttributeTypes, [
32
32
  :AdFormatSpecListAttribute,
@@ -83,7 +83,7 @@ module Sem4r
83
83
  end
84
84
 
85
85
  class TKeywordAttribute
86
- include SoapAttributes
86
+ include Sem4rSoap::SoapAttributes
87
87
 
88
88
  g_accessor :text
89
89
  g_accessor :match_type
@@ -108,7 +108,7 @@ module Sem4r
108
108
  end
109
109
 
110
110
  class TMonthlySearchVolumeAttribute
111
- include SoapAttributes
111
+ include Sem4rSoap::SoapAttributes
112
112
 
113
113
  g_accessor :text
114
114
  g_accessor :values
@@ -139,7 +139,7 @@ module Sem4r
139
139
  end
140
140
 
141
141
  class TIdeaTypeAttribute
142
- include SoapAttributes
142
+ include Sem4rSoap::SoapAttributes
143
143
 
144
144
  g_accessor :value
145
145
 
@@ -30,7 +30,7 @@ module Sem4r
30
30
 
31
31
  def targeting_idea(&block)
32
32
  selector = TargetingIdeaSelector.new(&block)
33
- soap_message = service.targeting_idea.get(@credentials, selector.to_xml)
33
+ soap_message = service.targeting_idea.get(credentials, selector.to_xml)
34
34
  add_counters( soap_message.counters )
35
35
  rval = soap_message.response.at_xpath("//getResponse/rval")
36
36
  els = rval.xpath("entries")
@@ -25,7 +25,7 @@
25
25
  module Sem4r
26
26
 
27
27
  class RelatedToKeywordSearchParameter
28
- include SoapAttributes
28
+ include Sem4rSoap::SoapAttributes
29
29
 
30
30
  g_set_accessor :text
31
31
  g_accessor :match_type
@@ -51,7 +51,7 @@ module Sem4r
51
51
  end
52
52
 
53
53
  class ExcludedKeywordSearchParameter
54
- include SoapAttributes
54
+ include Sem4rSoap::SoapAttributes
55
55
 
56
56
  g_accessor :text
57
57
  g_accessor :match_type
@@ -76,7 +76,7 @@ module Sem4r
76
76
  end
77
77
 
78
78
  class KeywordMatchTypeSearchParameter
79
- include SoapAttributes
79
+ include Sem4rSoap::SoapAttributes
80
80
 
81
81
  g_set_accessor :match_type
82
82
 
@@ -97,7 +97,7 @@ module Sem4r
97
97
  end
98
98
 
99
99
  class CountryTargetSearchParameter
100
- include SoapAttributes
100
+ include Sem4rSoap::SoapAttributes
101
101
 
102
102
  g_set_accessor :country_code
103
103
 
@@ -120,7 +120,7 @@ module Sem4r
120
120
  end
121
121
 
122
122
  class NgramGroupsSearchParameter
123
- include SoapAttributes
123
+ include Sem4rSoap::SoapAttributes
124
124
 
125
125
  g_set_accessor :ngram
126
126
 
@@ -141,7 +141,7 @@ module Sem4r
141
141
  end
142
142
 
143
143
  class TargetingIdeaSelector
144
- include SoapAttributes
144
+ include Sem4rSoap::SoapAttributes
145
145
 
146
146
  enum :IdeaTypes, [:KEYWORD, :PLACEMENT]
147
147
  enum :RequestTypes, [:IDEAS, :STATS]
@@ -22,8 +22,11 @@
22
22
  # -------------------------------------------------------------------
23
23
 
24
24
  module Sem4r
25
- class TargetingIdeaService
26
- include SoapCall
25
+
26
+ #
27
+ # @private
28
+ #
29
+ class TargetingIdeaService < Sem4rSoap::SoapServiceV2010 #:nodoc: all
27
30
 
28
31
  def initialize(connector)
29
32
  @connector = connector
@@ -33,11 +36,10 @@ module Sem4r
33
36
 
34
37
  @sandbox_service_url = "https://adwords-sandbox.google.com/api/adwords/o/v201008/TargetingIdeaService"
35
38
  @production_service_url = "https://adwords.google.com/api/adwords/o/v201008/TargetingIdeaService"
39
+ init(@header_namespace, @service_namespace)
36
40
  end
37
41
 
38
- soap_call_v2010 :get, :mutate => false
39
-
40
- ################
42
+ soap_call :get, :mutate => false
41
43
 
42
44
  private
43
45
 
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  # -------------------------------------------------------------------------
2
3
  # Copyright (c) 2009-2010 Sem4r sem4ruby@gmail.com
3
4
  #
@@ -19,19 +20,20 @@
19
20
  # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
21
  # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
22
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
- #
23
23
  # -------------------------------------------------------------------------
24
24
 
25
25
  module Sem4r
26
26
 
27
27
  module AccountAccountExtension
28
+
28
29
  ############################################################################
29
- # Info Account - Service Account
30
+ # Info
30
31
 
31
32
  def p_info
32
33
  _info unless @currency_code
33
34
  puts "currency_code: #{@currency_code}"
34
35
  puts "customer_id: #{@customer_id}"
36
+ puts "email: #{@credentials.client_email}" if @credentials.client_email
35
37
  puts @billing_address
36
38
  end
37
39
 
@@ -59,7 +61,7 @@ module Sem4r
59
61
  public
60
62
 
61
63
  ############################################################################
62
- # Account - Service Account
64
+ # Client
63
65
 
64
66
  def client_accounts(refresh = false)
65
67
  _client_accounts unless @accounts and !refresh
@@ -67,9 +69,8 @@ module Sem4r
67
69
  end
68
70
 
69
71
  def p_client_accounts(refresh = false)
70
- cs = client_accounts(refresh)
71
- # puts "#{cs.length} client accounts"
72
- cs.each do |account|
72
+ client_accounts(refresh)
73
+ @accounts.each do |account|
73
74
  puts account.to_s
74
75
  end
75
76
  self
@@ -90,10 +91,6 @@ module Sem4r
90
91
  end
91
92
  end
92
93
 
93
- public
94
-
95
- ###########################################################################
96
-
97
94
  end
98
95
 
99
96
  class Account
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  # -------------------------------------------------------------------
2
3
  # Copyright (c) 2009-2010 Sem4r sem4ruby@gmail.com
3
4
  #
@@ -22,17 +23,22 @@
22
23
  # -------------------------------------------------------------------
23
24
 
24
25
  module Sem4r
25
- class AccountService
26
- include SoapCall
26
+
27
+ #
28
+ # @private
29
+ #
30
+ class AccountService < Sem4rSoap::SoapServiceV13
27
31
 
28
32
  def initialize(connector)
33
+ super()
29
34
  @connector = connector
30
35
  @sandbox_service_url = "https://sandbox.google.com/api/adwords/v13/AccountService"
31
36
  @production_service_url = "https://adwords.google.com/api/adwords/v13/AccountService"
37
+ # init(@header_namespace, @service_namespace)
32
38
  end
33
39
 
34
- soap_call_v13 :account_info, :mutate => false
35
- soap_call_v13 :client_accounts, :mutate => false
40
+ soap_call :account_info, :mutate => false
41
+ soap_call :client_accounts, :mutate => false
36
42
 
37
43
  private
38
44
 
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  # -------------------------------------------------------------------------
2
3
  # Copyright (c) 2009-2010 Sem4r sem4ruby@gmail.com
3
4
  #
@@ -19,12 +20,11 @@
19
20
  # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
21
  # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
22
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
- #
23
23
  # -------------------------------------------------------------------------
24
24
 
25
25
  module Sem4r
26
26
  class BillingAddress
27
- include SoapAttributes
27
+ include Sem4rSoap::SoapAttributes
28
28
 
29
29
  g_accessor :company_name
30
30
  g_accessor :address_line1
@@ -22,25 +22,27 @@
22
22
  # -------------------------------------------------------------------
23
23
 
24
24
  module Sem4r
25
- class ReportService
26
25
 
27
- include SoapCall
26
+ #
27
+ # @private
28
+ #
29
+ class ReportService < Sem4rSoap::SoapServiceV13
28
30
 
29
31
  def initialize(connector)
32
+ super()
30
33
  @connector = connector
31
34
  @namespace = "https://adwords.google.com/api/adwords/v13"
32
35
 
33
36
  @sandbox_service_url = "https://sandbox.google.com/api/adwords/v13/ReportService"
34
37
  @production_service_url = "https://adwords.google.com/api/adwords/v13/ReportService"
38
+ # init(@header_namespace, @service_namespace)
35
39
  end
36
40
 
37
- soap_call_v13 :all, :mutate => false
38
- soap_call_v13 :validate, :mutate => false
39
- soap_call_v13 :schedule, :mutate => false
40
- soap_call_v13 :status, :mutate => false
41
- soap_call_v13 :url, :mutate => false
42
-
43
- ################
41
+ soap_call :all, :mutate => false
42
+ soap_call :validate, :mutate => false
43
+ soap_call :schedule, :mutate => false
44
+ soap_call :status, :mutate => false
45
+ soap_call :url, :mutate => false
44
46
 
45
47
  def download(url, path_name)
46
48
  @connector.download(url, path_name)