sem4r 0.1.1

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 (187) hide show
  1. data/LICENSE +22 -0
  2. data/README.rdoc +74 -0
  3. data/Rakefile +126 -0
  4. data/VERSION.yml +5 -0
  5. data/bin/sem +34 -0
  6. data/config/sem4r.example.yml +51 -0
  7. data/examples_blog/2009-11-29-hello-world.rb +12 -0
  8. data/examples_blog/2009-12-12-create-campaign.rb +29 -0
  9. data/examples_blog/2010-02-06-constants-scope.rb +8 -0
  10. data/examples_blog/2010-02-07-ad-parameters.rb +47 -0
  11. data/examples_sem4r/01_get_account.rb +37 -0
  12. data/examples_sem4r/02_get_info.rb +32 -0
  13. data/examples_sem4r/03_list_ad.rb +47 -0
  14. data/examples_sem4r/04_list_keywords.rb +54 -0
  15. data/examples_sem4r/05_request_report.rb +51 -0
  16. data/examples_sem4r/05_request_report_2010.rb +40 -0
  17. data/examples_sem4r/06_create_campaigns.rb +86 -0
  18. data/examples_sem4r/07_create_campaigns_block.rb +99 -0
  19. data/examples_sem4r/07_create_campaigns_simple.rb +65 -0
  20. data/examples_sem4r/08_ad_params.rb +70 -0
  21. data/examples_sem4r/09_targeting_idea.rb +59 -0
  22. data/examples_sem4r/10_get_location.rb +28 -0
  23. data/examples_sem4r/11_submit_bulk_job.rb +82 -0
  24. data/examples_sem4r/12_list_bulk_job.rb +29 -0
  25. data/examples_sem4r/30_prune_empty_adgroup.rb +50 -0
  26. data/examples_sem4r/31_empty_accounts.rb +40 -0
  27. data/examples_sem4r/example_helper.rb +115 -0
  28. data/lib/sem4r/account.rb +349 -0
  29. data/lib/sem4r/ad_extension_override/ad_extension_override_service.rb +30 -0
  30. data/lib/sem4r/ad_group/ad_group.rb +340 -0
  31. data/lib/sem4r/ad_group/ad_group_bids.rb +170 -0
  32. data/lib/sem4r/ad_group/ad_group_service.rb +75 -0
  33. data/lib/sem4r/ad_group/mobile_ad_image.rb +33 -0
  34. data/lib/sem4r/ad_group_ad/ad_group_ad.rb +98 -0
  35. data/lib/sem4r/ad_group_ad/ad_group_ad_operations.rb +38 -0
  36. data/lib/sem4r/ad_group_ad/ad_group_ad_service.rb +56 -0
  37. data/lib/sem4r/ad_group_ad/ad_group_mobile_ad.rb +137 -0
  38. data/lib/sem4r/ad_group_ad/ad_group_text_ad.rb +98 -0
  39. data/lib/sem4r/ad_group_criterion/ad_group_criterion.rb +144 -0
  40. data/lib/sem4r/ad_group_criterion/ad_group_criterion_bids.rb +115 -0
  41. data/lib/sem4r/ad_group_criterion/ad_group_criterion_operations.rb +35 -0
  42. data/lib/sem4r/ad_group_criterion/ad_group_criterion_service.rb +58 -0
  43. data/lib/sem4r/ad_group_criterion/criterion.rb +67 -0
  44. data/lib/sem4r/ad_group_criterion/criterion_keyword.rb +80 -0
  45. data/lib/sem4r/ad_group_criterion/criterion_placement.rb +66 -0
  46. data/lib/sem4r/ad_param/ad_param.rb +96 -0
  47. data/lib/sem4r/ad_param/ad_param_operation.rb +34 -0
  48. data/lib/sem4r/ad_param/ad_param_service.rb +59 -0
  49. data/lib/sem4r/adwords.rb +242 -0
  50. data/lib/sem4r/api_counters.rb +7 -0
  51. data/lib/sem4r/base.rb +43 -0
  52. data/lib/sem4r/bulk_mutate_job/bulk_mutate_job.rb +108 -0
  53. data/lib/sem4r/bulk_mutate_job/bulk_mutate_job_selector.rb +56 -0
  54. data/lib/sem4r/bulk_mutate_job/bulk_mutate_job_service.rb +57 -0
  55. data/lib/sem4r/bulk_mutate_job/job_operations.rb +35 -0
  56. data/lib/sem4r/campaign/campaign.rb +193 -0
  57. data/lib/sem4r/campaign/campaign_service.rb +91 -0
  58. data/lib/sem4r/campaign_criterion/campaign_criterion_service.rb +30 -0
  59. data/lib/sem4r/campaign_target/campaign_target_service.rb +30 -0
  60. data/lib/sem4r/cli/cli_command.rb +101 -0
  61. data/lib/sem4r/cli/cli_commands.rb +60 -0
  62. data/lib/sem4r/cli/cli_common_args.rb +293 -0
  63. data/lib/sem4r/cli/cli_download_report.rb +81 -0
  64. data/lib/sem4r/cli/cli_helpers.rb +57 -0
  65. data/lib/sem4r/cli/cli_ideas.rb +100 -0
  66. data/lib/sem4r/cli/cli_list_ads.rb +74 -0
  67. data/lib/sem4r/cli/cli_list_keywords.rb +76 -0
  68. data/lib/sem4r/cli/cli_request_report.rb +104 -0
  69. data/lib/sem4r/cli/cli_sem.rb +64 -0
  70. data/lib/sem4r/common/operation.rb +78 -0
  71. data/lib/sem4r/credentials.rb +86 -0
  72. data/lib/sem4r/extensions.rb +62 -0
  73. data/lib/sem4r/geo_location/geo_location_service.rb +59 -0
  74. data/lib/sem4r/info/info_service.rb +115 -0
  75. data/lib/sem4r/report_definition/report_definition.rb +104 -0
  76. data/lib/sem4r/report_definition/report_definition_operation.rb +34 -0
  77. data/lib/sem4r/report_definition/report_definition_selector.rb +31 -0
  78. data/lib/sem4r/report_definition/report_definition_service.rb +55 -0
  79. data/lib/sem4r/sem4r_error.rb +28 -0
  80. data/lib/sem4r/services/service.rb +74 -0
  81. data/lib/sem4r/services/soap_call.rb +100 -0
  82. data/lib/sem4r/services/soap_connector.rb +284 -0
  83. data/lib/sem4r/services/soap_error.rb +38 -0
  84. data/lib/sem4r/services/soap_message_v13.rb +129 -0
  85. data/lib/sem4r/services/soap_message_v2009.rb +170 -0
  86. data/lib/sem4r/soap_attributes.rb +141 -0
  87. data/lib/sem4r/targeting_idea/targeting_idea.rb +158 -0
  88. data/lib/sem4r/targeting_idea/targeting_idea_selector.rb +200 -0
  89. data/lib/sem4r/targeting_idea/targeting_idea_service.rb +51 -0
  90. data/lib/sem4r/v13_account/account_service.rb +54 -0
  91. data/lib/sem4r/v13_account/billing_address.rb +67 -0
  92. data/lib/sem4r/v13_report/report.rb +185 -0
  93. data/lib/sem4r/v13_report/report_job.rb +51 -0
  94. data/lib/sem4r/v13_report/report_service.rb +89 -0
  95. data/lib/sem4r/v13_traffic_estimator/traffic_estimator_service.rb +30 -0
  96. data/lib/sem4r.rb +142 -0
  97. data/lib/sem4r_cli.rb +40 -0
  98. data/sem4r.gemspec +247 -0
  99. data/spec/aggregates_spec_helper.rb +59 -0
  100. data/spec/fixtures/sem4r.example.yml +26 -0
  101. data/spec/fixtures/services/ad_group/get-first-req.xml +28 -0
  102. data/spec/fixtures/services/ad_group/get-first-res.xml +91 -0
  103. data/spec/fixtures/services/ad_group/get-manual-cpm-bids-req.xml +106 -0
  104. data/spec/fixtures/services/ad_group/get-manual-cpm-bids-res.xml +75 -0
  105. data/spec/fixtures/services/ad_group/mutate_add-req.xml +52 -0
  106. data/spec/fixtures/services/ad_group/mutate_add-res.xml +33 -0
  107. data/spec/fixtures/services/ad_group_ad/get_mobile_ad-req.xml +28 -0
  108. data/spec/fixtures/services/ad_group_ad/get_mobile_ad-res.xml +194 -0
  109. data/spec/fixtures/services/ad_group_ad/get_text_ad-req.xml +29 -0
  110. data/spec/fixtures/services/ad_group_ad/get_text_ad-res.xml +55 -0
  111. data/spec/fixtures/services/ad_group_ad/mutate_add_mobile_ad-req.xml +50 -0
  112. data/spec/fixtures/services/ad_group_ad/mutate_add_mobile_ad-res.xml +42 -0
  113. data/spec/fixtures/services/ad_group_ad/mutate_add_text_ad-req.xml +37 -0
  114. data/spec/fixtures/services/ad_group_ad/mutate_add_text_ad-res.xml +32 -0
  115. data/spec/fixtures/services/ad_group_ad/mutate_add_two_criterions-req.xml +83 -0
  116. data/spec/fixtures/services/ad_group_ad/mutate_add_two_criterions-res.xml +95 -0
  117. data/spec/fixtures/services/ad_group_criterion/get-req.xml +28 -0
  118. data/spec/fixtures/services/ad_group_criterion/get-res.xml +242 -0
  119. data/spec/fixtures/services/ad_group_criterion/mutate_add_criterion_keyword-req.xml +48 -0
  120. data/spec/fixtures/services/ad_group_criterion/mutate_add_criterion_keyword-res.xml +47 -0
  121. data/spec/fixtures/services/ad_group_criterion/mutate_add_criterion_placement-req.xml +35 -0
  122. data/spec/fixtures/services/ad_group_criterion/mutate_add_criterion_placement-res.xml +32 -0
  123. data/spec/fixtures/services/ad_group_criterion/mutate_add_negative_keyword-req.xml +37 -0
  124. data/spec/fixtures/services/ad_group_criterion/mutate_add_negative_keyword-res.xml +51 -0
  125. data/spec/fixtures/services/ad_param/mutate_set-req.xml +43 -0
  126. data/spec/fixtures/services/ad_param/mutate_set-res.xml +29 -0
  127. data/spec/fixtures/services/bulk_mutate_job/get-req.xml +36 -0
  128. data/spec/fixtures/services/bulk_mutate_job/get-res.xml +54 -0
  129. data/spec/fixtures/services/bulk_mutate_job/mutate-req.xml +69 -0
  130. data/spec/fixtures/services/bulk_mutate_job/mutate-res.xml +48 -0
  131. data/spec/fixtures/services/campaign/get-req.xml +37 -0
  132. data/spec/fixtures/services/campaign/get-res.xml +1986 -0
  133. data/spec/fixtures/services/campaign/mutate_add-req.xml +37 -0
  134. data/spec/fixtures/services/campaign/mutate_add-res.xml +42 -0
  135. data/spec/fixtures/services/error.xml +28 -0
  136. data/spec/fixtures/services/info/get_unit_count-req.xml +30 -0
  137. data/spec/fixtures/services/info/get_unit_count-res.xml +29 -0
  138. data/spec/fixtures/services/report_definition/mutate_add-req.xml +24 -0
  139. data/spec/fixtures/services/report_definition/mutate_add-req_orig.xml +45 -0
  140. data/spec/fixtures/services/targeting_idea/get-req-all-options.xml +57 -0
  141. data/spec/fixtures/services/targeting_idea/get-req.xml +60 -0
  142. data/spec/fixtures/services/targeting_idea/get-res.xml +3601 -0
  143. data/spec/fixtures/services/v13_account/get_account_info-req.xml +23 -0
  144. data/spec/fixtures/services/v13_account/get_account_info-res.xml +54 -0
  145. data/spec/fixtures/services/v13_account/get_client_accounts-req.xml +22 -0
  146. data/spec/fixtures/services/v13_account/get_client_accounts-res.xml +37 -0
  147. data/spec/fixtures/services/v13_report/get_all_jobs-req.xml +21 -0
  148. data/spec/fixtures/services/v13_report/get_all_jobs-res.xml +109 -0
  149. data/spec/fixtures/services/v13_report/schedule_report_job-req.xml +56 -0
  150. data/spec/fixtures/services/v13_report/schedule_report_job-res.xml +24 -0
  151. data/spec/sem4r/account_spec.rb +86 -0
  152. data/spec/sem4r/ad_group/ad_group_bids_spec.rb +67 -0
  153. data/spec/sem4r/ad_group/ad_group_service_spec.rb +66 -0
  154. data/spec/sem4r/ad_group/ad_group_spec.rb +212 -0
  155. data/spec/sem4r/ad_group_ad/ad_group_ad_operation_spec.rb +88 -0
  156. data/spec/sem4r/ad_group_ad/ad_group_ad_service_spec.rb +55 -0
  157. data/spec/sem4r/ad_group_ad/ad_group_ad_spec.rb +173 -0
  158. data/spec/sem4r/ad_group_criterion/ad_group_criterion_bids_spec.rb +60 -0
  159. data/spec/sem4r/ad_group_criterion/ad_group_criterion_service_spec.rb +55 -0
  160. data/spec/sem4r/ad_group_criterion/ad_group_criterion_spec.rb +103 -0
  161. data/spec/sem4r/ad_group_criterion/criterion_spec.rb +85 -0
  162. data/spec/sem4r/ad_param/ad_param_service_spec.rb +55 -0
  163. data/spec/sem4r/ad_param/ad_param_spec.rb +59 -0
  164. data/spec/sem4r/adwords_spec.rb +110 -0
  165. data/spec/sem4r/bulk_mutate_job/bulk_mutate_job_service_spec.rb +63 -0
  166. data/spec/sem4r/bulk_mutate_job/bulk_mutate_job_spec.rb +69 -0
  167. data/spec/sem4r/bulk_mutate_job/job_operation_spec.rb +48 -0
  168. data/spec/sem4r/campaign/campaign_service_spec.rb +66 -0
  169. data/spec/sem4r/campaign/campaign_spec.rb +105 -0
  170. data/spec/sem4r/cli/cli_spec.rb +71 -0
  171. data/spec/sem4r/credentials_spec.rb +65 -0
  172. data/spec/sem4r/report_definition/report_definition_service_spec.rb +44 -0
  173. data/spec/sem4r/report_definition/report_definition_spec.rb +105 -0
  174. data/spec/sem4r/rexml_parsing_spec.rb +103 -0
  175. data/spec/sem4r/services/service_spec.rb +36 -0
  176. data/spec/sem4r/services/soap_call_spec.rb +115 -0
  177. data/spec/sem4r/services/soap_message_v13_spec.rb +54 -0
  178. data/spec/sem4r/soap_attributes_spec.rb +116 -0
  179. data/spec/sem4r/targeting_idea/targeting_idea_selector_spec.rb +120 -0
  180. data/spec/sem4r/targeting_idea/targeting_idea_service_spec.rb +44 -0
  181. data/spec/sem4r/targeting_idea/targeting_idea_spec.rb +53 -0
  182. data/spec/sem4r/v13_account/account_service_spec.rb +60 -0
  183. data/spec/sem4r/v13_report/report_service_spec.rb +104 -0
  184. data/spec/sem4r/v13_report/report_spec.rb +79 -0
  185. data/spec/sem4r_spec_helper.rb +353 -0
  186. data/spec/spec_helper.rb +12 -0
  187. metadata +375 -0
@@ -0,0 +1,115 @@
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
+ require 'rubygems'
25
+
26
+ begin
27
+ require 'sem4r'
28
+ rescue LoadError
29
+ cwd = File.expand_path( File.join( File.dirname(__FILE__), "..", "lib" ) )
30
+ $:.unshift(cwd) unless $:.include?(cwd)
31
+ require 'sem4r'
32
+ end
33
+ include Sem4r
34
+
35
+ def tmp_dirname
36
+ d = File.join( File.dirname(__FILE__), "..", "tmp" )
37
+ return d if File.directory?(d)
38
+
39
+ if RUBY_PLATFORM.include?("linux")
40
+ d = "/tmp"
41
+ return d if File.directory?(d)
42
+ else
43
+ d = "c:\\temp"
44
+ return d if File.directory?(d)
45
+ end
46
+ return "."
47
+ end
48
+
49
+ def example_soap_dump_options(example_file)
50
+ return nil unless File.directory?(tmp_dirname)
51
+ basename = File.basename(example_file).sub(/\.rb$/, '')
52
+ log_directory = File.join( File.join(tmp_dirname), basename)
53
+ log_directory = File.expand_path(log_directory)
54
+ unless File.directory?(log_directory)
55
+ Dir.mkdir(log_directory)
56
+ end
57
+ puts "dump soap messages in '#{log_directory}'"
58
+ { :directory => log_directory, :format => true }
59
+ end
60
+
61
+ def example_logger(example_file)
62
+ return nil unless File.directory?(tmp_dirname)
63
+ filename = File.join( tmp_dirname, File.basename(example_file).sub(/\.rb$/, ".log") )
64
+ file = File.open( filename, "w" )
65
+ file.sync = true
66
+ logger = Logger.new(file)
67
+ logger.formatter = proc { |severity, datetime, progname, msg|
68
+ "#{datetime.strftime("%H:%M:%S")}: #{msg}\n"
69
+ }
70
+ logger
71
+ end
72
+
73
+
74
+ def run_example(file)
75
+ if !block_given?
76
+ puts "block required!"
77
+ exit
78
+ end
79
+ puts "---------------------------------------------------------------------"
80
+ puts "Running #{File.basename(file)}"
81
+ puts "---------------------------------------------------------------------"
82
+
83
+ begin
84
+ #
85
+ # config stuff
86
+ #
87
+
88
+ # config = {
89
+ # :email => "",
90
+ # :password => "",
91
+ # :developer_token => ""
92
+ # }
93
+ # adwords = Adwords.sandbox(config)
94
+
95
+ adwords = Adwords.sandbox # search credentials into ~/.sem4r file
96
+ adwords.dump_soap_options( example_soap_dump_options(file) )
97
+ adwords.logger = Logger.new(STDOUT)
98
+ # adwords.logger = example_logger(file)
99
+
100
+ #
101
+ # example body
102
+ #
103
+
104
+ yield(adwords)
105
+
106
+ adwords.p_counters
107
+
108
+ rescue Sem4rError
109
+ puts "I am so sorry! Something went wrong! (exception #{$!.to_s})"
110
+ end
111
+
112
+ puts "---------------------------------------------------------------------"
113
+
114
+ end
115
+
@@ -0,0 +1,349 @@
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
+ module Sem4r
25
+
26
+ class Account < Base
27
+
28
+ def initialize( adwords, credentials )
29
+ super( adwords, credentials )
30
+ @campaigns = nil
31
+ @reports = nil
32
+ @report_definitions = nil
33
+ end
34
+
35
+ def to_s
36
+ credentials.to_s
37
+ end
38
+
39
+ def client_email
40
+ credentials.client_email
41
+ end
42
+
43
+ ############################################################################
44
+ # Info Service
45
+
46
+ # FREE_USAGE_API_UNITS_PER_MONTH
47
+ # Retrieves the number of free API units that can be used by the developer
48
+ # token being used to make the call for this month.
49
+ # Specify only the apiUsageType parameter.
50
+ #
51
+ # TOTAL_USAGE_API_UNITS_PER_MONTH
52
+ # Retrieves the total number of API units for this entire month that can
53
+ # be used by the developer token being used to make this call. Includes
54
+ # both free and paid API units.
55
+ # Specify only the apiUsageType parameter.
56
+ #
57
+ # OPERATION_COUNT
58
+ # Retrieves the number of operations recorded for the developer token
59
+ # being used to make this call over the given date range.
60
+ # The given dates
61
+ # are inclusive; to get the operation count for a single day, supply it as
62
+ # both the start and end date.
63
+ # Specify the apiUsageType and dateRange parameters.
64
+ #
65
+ # UNIT_COUNT
66
+ # Retrieves the number of API units recorded for the developer token being
67
+ # used to make this call.
68
+ # o Specify the apiUsageType and dateRange parameters to retrieve
69
+ # the units recorded over the given date range.
70
+ # o Specify the apiUsageType, serviceName, methodName, operator,
71
+ # dateRange to retrieve the units recorded over the given date
72
+ # range for a specified method.
73
+ #
74
+ # UNIT_COUNT_FOR_CLIENTS
75
+ # Retrieves the number of API units recorded for a subset of clients over
76
+ # the given date range for the developer token being used to make this
77
+ # call.
78
+ # The given dates are inclusive; to get the unit count for a single
79
+ # day, supply it as both the start and end date.
80
+ # Specify the apiUsageType, dateRange and clientEmails parameters.
81
+ #
82
+ # METHOD_COST
83
+ # Retrieves the cost, in API units per operation, of the given method on
84
+ # a specific date for the developer token being used to make this call.
85
+ #
86
+ # Methods default to a cost of 1. Specify the apiUsageType, dateRange
87
+ # (start date and end date should be the same), serviceName, methodName,
88
+ # operator parameters.
89
+
90
+ enum :UsageTypes, [
91
+ :FREE_USAGE_API_UNITS_PER_MONTH,
92
+ :UNIT_COUNT,
93
+ :TOTAL_USAGE_API_UNITS_PER_MONTH,
94
+ :OPERATION_COUNT,
95
+ :UNIT_COUNT_FOR_CLIENTS,
96
+ :METHOD_COST]
97
+
98
+ def year_unit_cost(usage_type)
99
+ raise "usage type '#{usage_type}' not permitted" unless UsageTypes.include?(usage_type)
100
+ soap_message = service.info.unit_cost(@credentials, usage_type)
101
+ add_counters( soap_message.counters )
102
+ cost = REXML::XPath.first( soap_message.response, "//getResponse/rval/cost")
103
+ cost.text.to_i
104
+ end
105
+
106
+ ############################################################################
107
+ # Targeting Idea
108
+
109
+ def targeting_idea(&block)
110
+ selector = TargetingIdeaSelector.new(&block)
111
+ soap_message = service.targeting_idea.get(@credentials, selector.to_xml)
112
+ add_counters( soap_message.counters )
113
+ rval = REXML::XPath.first( soap_message.response, "//getResponse/rval")
114
+ els = REXML::XPath.match( rval, "entries")
115
+ els.map do |el|
116
+ TargetingIdea.from_element( el )
117
+ end
118
+ end
119
+
120
+ def p_targeting_idea(&block)
121
+ targeting_ideas = targeting_idea(&block)
122
+ targeting_ideas.each{ |idea| puts idea }
123
+ end
124
+
125
+ ############################################################################
126
+ # Bulk Jobs
127
+
128
+ def p_jobs
129
+ selector = BulkMutateJobSelector.new
130
+ soap_message = service.bulk_mutate_job.all(credentials, selector)
131
+ add_counters( soap_message.counters )
132
+ els = REXML::XPath.match( soap_message.response, "//getResponse/rval")
133
+ jobs = els.map do |el|
134
+ BulkMutateJob.from_element(el)
135
+ end
136
+
137
+ puts "#{jobs.length} bulk mutate jobs"
138
+ jobs.each do |job|
139
+ puts job.to_s
140
+ end
141
+ self
142
+ end
143
+
144
+ def job_mutate(bulk_mutate_job)
145
+ soap_message = service.bulk_mutate_job.mutate(credentials, bulk_mutate_job)
146
+ add_counters( soap_message.counters )
147
+ el = REXML::XPath.first( soap_message.response, "//rval")
148
+ BulkMutateJob.from_element(el)
149
+ end
150
+
151
+ ############################################################################
152
+ # Geo Location
153
+
154
+ def geo_location
155
+ soap_message = service.geo_location.get(@credentials, "")
156
+ add_counters( soap_message.counters )
157
+ # cost = REXML::XPath.first( soap_message.response, "//getResponse/rval/cost")
158
+ # cost.text.to_i
159
+ end
160
+
161
+ ############################################################################
162
+ # Reports - Service Report
163
+
164
+ def report(&block)
165
+ Report.new(self, &block)
166
+ end
167
+
168
+ def p_reports(refresh = false)
169
+ reports(refresh).each do |report|
170
+ puts report.to_s
171
+ end
172
+ end
173
+
174
+ def reports(refresh = false)
175
+ _reports unless @reports and !refresh
176
+ @reports
177
+ end
178
+
179
+ private
180
+
181
+ def _reports
182
+ soap_message = service.report.all(credentials)
183
+ add_counters( soap_message.counters )
184
+ els = REXML::XPath.match( soap_message.response, "//getAllJobsResponse/getAllJobsReturn")
185
+ @reports = els.map do |el|
186
+ Report.from_element(self, el)
187
+ end
188
+ end
189
+
190
+ public
191
+
192
+ ############################################################################
193
+ # Report Definitions - Service Report Definition
194
+
195
+ def report_definition(&block)
196
+ ReportDefinition.new(self, &block)
197
+ end
198
+
199
+ def p_report_definitions(refresh = false)
200
+ report_definitions(refresh).each do |report_definition|
201
+ puts report_definition.to_s
202
+ end
203
+ end
204
+
205
+ def report_definitions(refresh = false)
206
+ _report_definitions unless @report_definitions and !refresh
207
+ @report_definitions
208
+ end
209
+
210
+ private
211
+
212
+ def _report_definitions
213
+ soap_message = service.report_definition.get(credentials, ReportDefinitionSelector.new.to_xml)
214
+ add_counters( soap_message.counters )
215
+ els = REXML::XPath.match( soap_message.response, "//getAllJobsResponse/getAllJobsReturn")
216
+ @report_definitions = els.map do |el|
217
+ ReportDefinition.from_element(self, el)
218
+ end
219
+ end
220
+
221
+ public
222
+
223
+ ############################################################################
224
+ # Info Account - Service Account
225
+
226
+ def p_info
227
+ _info unless @currency_code
228
+ puts "currency_code: #{@currency_code}"
229
+ puts "customer_id: #{@customer_id}"
230
+ puts @billing_address
231
+ end
232
+
233
+ def currency_code
234
+ _info unless @currency_code
235
+ @currency_code
236
+ end
237
+
238
+ def customer_id
239
+ _info unless @customer_id
240
+ @customer_id
241
+ end
242
+
243
+ private
244
+
245
+ def _info
246
+ soap_message = service.account.account_info(credentials)
247
+ add_counters( soap_message.counters )
248
+ el = REXML::XPath.first( soap_message.response, "//getAccountInfoResponse/getAccountInfoReturn")
249
+ @currency_code = el.elements['currencyCode'].text.strip
250
+ @customer_id = el.elements['customerId'].text.strip
251
+ @billing_address = BillingAddress.from_element( el.elements['billingAddress'] )
252
+ end
253
+
254
+ public
255
+
256
+ ############################################################################
257
+ # Account - Service Account
258
+
259
+ def client_accounts(refresh = false)
260
+ _client_accounts unless @accounts and !refresh
261
+ @accounts
262
+ end
263
+
264
+ def p_client_accounts(refresh = false)
265
+ cs = client_accounts(refresh)
266
+ # puts "#{cs.length} client accounts"
267
+ cs.each do |account|
268
+ puts account.to_s
269
+ end
270
+ self
271
+ end
272
+
273
+ alias clients client_accounts
274
+ alias p_clients p_client_accounts
275
+
276
+ private
277
+
278
+ def _client_accounts
279
+ soap_message = service.account.client_accounts(credentials)
280
+ add_counters( soap_message.counters )
281
+ els = REXML::XPath.match( soap_message.response, "//getClientAccountsReturn")
282
+ @accounts = els.map do |el|
283
+ client_email = el.text
284
+ Account.new( adwords, Credentials.new(@credentials, client_email) )
285
+ end
286
+ end
287
+
288
+ public
289
+
290
+ ############################################################################
291
+ # Campaign - Service Campaign
292
+
293
+ # TODO: accettare un parametro opzionale campaign(name=nil,&block)
294
+ # la campagna che verra' creata ha il nome gia' settato
295
+ # se esiste gia' una campagna con quel nome allora fara' da contesto
296
+ # e non verra' creata
297
+ def campaign(name = nil, &block)
298
+ campaign = Campaign.new(self, name, &block)
299
+ campaign.save
300
+ @campaigns ||= []
301
+ @campaigns.push(campaign)
302
+ campaign
303
+ end
304
+
305
+ alias create_campaign campaign
306
+
307
+ def campaigns(refresh = false, opts = {}) # conditions = nil
308
+ if refresh.respond_to?(:keys)
309
+ opts = refresh
310
+ refresh = false
311
+ end
312
+ _campaigns unless @campaigns and !refresh
313
+ @campaigns
314
+ # return @campaigns unless conditions
315
+ # @campaigns.find_all {|c| c.name =~ conditions}
316
+ end
317
+
318
+ def p_campaigns(refresh = false, opts = {}) # conditions = nil
319
+ if refresh.respond_to?(:keys)
320
+ opts = refresh
321
+ refresh = false
322
+ end
323
+
324
+ cs = campaigns(refresh, opts)
325
+ puts "#{cs.length} campaigns"
326
+ campaigns(refresh).each do |campaign|
327
+ puts campaign.to_s
328
+ end
329
+ self
330
+ end
331
+
332
+ private
333
+
334
+ def _campaigns
335
+ soap_message = service.campaign.all(credentials)
336
+ add_counters( soap_message.counters )
337
+ rval = REXML::XPath.first( soap_message.response, "//getResponse/rval")
338
+ els = REXML::XPath.match( rval, "entries")
339
+ @campaigns = els.map do |el|
340
+ Campaign.from_element(self, el)
341
+ end
342
+ end
343
+
344
+ public
345
+
346
+ ###########################################################################
347
+
348
+ end
349
+ end
@@ -0,0 +1,30 @@
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
+ module Sem4r
25
+ class AdExtensionOverrideService
26
+ def initialize
27
+
28
+ end
29
+ end
30
+ end