sem4r 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +13 -2
- data/Gemfile.lock +13 -7
- data/README.rdoc +44 -7
- data/Rakefile +2 -122
- data/VERSION.yml +1 -1
- data/bin/sem +1 -0
- data/examples_sem4r/01_get_account.rb +1 -0
- data/examples_sem4r/02_get_info.rb +1 -0
- data/examples_sem4r/03_list_ad.rb +1 -0
- data/examples_sem4r/04_list_keywords.rb +1 -0
- data/examples_sem4r/05_request_report.rb +25 -14
- data/examples_sem4r/{05_request_report_2010.rb → 06_request_report_definition.rb} +2 -4
- data/examples_sem4r/{06_create_campaigns.rb → 07_create_campaigns.rb} +1 -0
- data/examples_sem4r/{07_create_campaigns_block.rb → 08_create_campaigns_block.rb} +1 -0
- data/examples_sem4r/{07_create_campaigns_simple.rb → 09_create_campaigns_simple.rb} +1 -0
- data/examples_sem4r/{08_ad_params.rb → 10_ad_params.rb} +1 -0
- data/examples_sem4r/{09_targeting_idea.rb → 11_targeting_idea.rb} +1 -0
- data/examples_sem4r/{10_get_location.rb → 12_get_location.rb} +1 -0
- data/examples_sem4r/{11_submit_bulk_job.rb → 13_submit_bulk_job.rb} +1 -1
- data/examples_sem4r/{12_list_bulk_job.rb → 14_list_bulk_job.rb} +3 -0
- data/examples_sem4r/30_prune_empty_adgroup.rb +1 -0
- data/examples_sem4r/31_empty_accounts.rb +1 -0
- data/examples_sem4r/example_helper.rb +2 -1
- data/lib/sem4r/ad_group/ad_group.rb +22 -7
- data/lib/sem4r/ad_group/ad_group_bids.rb +1 -1
- data/lib/sem4r/ad_group/ad_group_service.rb +12 -5
- data/lib/sem4r/ad_group_ad/ad_group_ad.rb +1 -0
- data/lib/sem4r/ad_group_ad/ad_group_ad_operations.rb +1 -0
- data/lib/sem4r/ad_group_ad/ad_group_ad_service.rb +14 -9
- data/lib/sem4r/ad_group_ad/ad_group_mobile_ad.rb +16 -25
- data/lib/sem4r/ad_group_ad/ad_group_text_ad.rb +18 -14
- data/lib/sem4r/ad_group_criterion/ad_group_criterion.rb +27 -19
- data/lib/sem4r/ad_group_criterion/ad_group_criterion_bids.rb +2 -1
- data/lib/sem4r/ad_group_criterion/ad_group_criterion_operations.rb +1 -0
- data/lib/sem4r/ad_group_criterion/ad_group_criterion_service.rb +9 -4
- data/lib/sem4r/ad_group_criterion/criterion.rb +1 -0
- data/lib/sem4r/ad_group_criterion/criterion_keyword.rb +1 -0
- data/lib/sem4r/ad_group_criterion/criterion_placement.rb +1 -0
- data/lib/sem4r/ad_param/ad_param.rb +24 -8
- data/lib/sem4r/ad_param/ad_param_service.rb +8 -5
- data/lib/sem4r/adwords.rb +232 -76
- data/lib/sem4r/base.rb +1 -1
- data/lib/sem4r/bulk_mutate_job/bulk_mutate_job.rb +41 -35
- data/lib/sem4r/bulk_mutate_job/bulk_mutate_job_account_extension.rb +49 -15
- data/lib/sem4r/bulk_mutate_job/bulk_mutate_job_selector.rb +29 -20
- data/lib/sem4r/bulk_mutate_job/bulk_mutate_job_service.rb +13 -14
- data/lib/sem4r/bulk_mutate_job/job_operations.rb +1 -1
- data/lib/sem4r/campaign/campaign.rb +1 -0
- data/lib/sem4r/campaign/campaign_account_extension.rb +2 -1
- data/lib/sem4r/campaign/campaign_service.rb +9 -5
- data/lib/sem4r/credentials.rb +11 -5
- data/lib/sem4r/geo_location/address.rb +56 -0
- data/lib/sem4r/geo_location/geo_location_account_extension.rb +27 -6
- data/lib/sem4r/geo_location/geo_location_selector.rb +57 -0
- data/lib/sem4r/geo_location/geo_location_service.rb +9 -16
- data/lib/sem4r/info/info_account_extension.rb +3 -2
- data/lib/sem4r/info/info_selector.rb +2 -1
- data/lib/sem4r/info/info_service.rb +10 -3
- data/lib/sem4r/operation.rb +39 -20
- data/lib/sem4r/report_definition/report_definition.rb +37 -19
- data/lib/sem4r/report_definition/report_definition_account_extension.rb +66 -16
- data/lib/sem4r/report_definition/report_definition_operation.rb +2 -2
- data/lib/sem4r/report_definition/report_definition_selector.rb +1 -1
- data/lib/sem4r/report_definition/report_definition_service.rb +11 -7
- data/lib/sem4r/report_definition/report_field.rb +3 -2
- data/lib/sem4r/sem4r_templates.rb +77 -0
- data/lib/sem4r/{services/service.rb → service.rb} +23 -23
- data/lib/sem4r/targeting_idea/targeting_idea.rb +4 -4
- data/lib/sem4r/targeting_idea/targeting_idea_account_extension.rb +1 -1
- data/lib/sem4r/targeting_idea/targeting_idea_selector.rb +6 -6
- data/lib/sem4r/targeting_idea/targeting_idea_service.rb +7 -5
- data/lib/sem4r/v13_account/account_account_extension.rb +7 -10
- data/lib/sem4r/v13_account/account_service.rb +10 -4
- data/lib/sem4r/v13_account/billing_address.rb +2 -2
- data/lib/sem4r/v13_report/report_service.rb +11 -9
- data/lib/sem4r.rb +46 -31
- data/lib/{sem4r/cli → sem4r_cli}/cli_helpers.rb +3 -2
- data/lib/{sem4r/cli/cli_command.rb → sem4r_cli/cli_mini_framework.rb} +77 -32
- data/lib/{sem4r/cli/cli_common_args.rb → sem4r_cli/cli_sem.rb} +177 -157
- data/lib/{sem4r/cli/commands/cli_list_ads.rb → sem4r_cli/commands/cli_ads.rb} +7 -9
- data/lib/sem4r_cli/commands/cli_campaign.rb +69 -0
- data/lib/{sem4r/cli/commands/cli_list_client.rb → sem4r_cli/commands/cli_clients.rb} +2 -2
- data/lib/{sem4r/cli → sem4r_cli}/commands/cli_ideas.rb +35 -27
- data/lib/{sem4r/cli → sem4r_cli}/commands/cli_info.rb +3 -4
- data/lib/{sem4r/cli/commands/cli_repdef.rb → sem4r_cli/commands/cli_job.rb} +57 -55
- data/lib/{sem4r/cli/commands/cli_list_keywords.rb → sem4r_cli/commands/cli_keywords.rb} +14 -13
- data/lib/sem4r_cli/commands/cli_profile.rb +138 -0
- data/lib/{sem4r/cli/commands/cli_report.rb → sem4r_cli/commands/cli_repdef.rb} +67 -20
- data/lib/{sem4r/cli/commands/cli_request_report.rb → sem4r_cli/commands/cli_report.rb} +82 -19
- data/lib/sem4r_cli.rb +5 -7
- data/lib/sem4r_soap/http_connector.rb +206 -0
- data/lib/{soap_helpers → sem4r_soap}/soap_attributes.rb +8 -3
- data/lib/{sem4r/services → sem4r_soap}/soap_dumper.rb +36 -20
- data/lib/{sem4r/services → sem4r_soap}/soap_error.rb +5 -2
- data/lib/sem4r_soap/soap_response.rb +75 -0
- data/lib/sem4r_soap/soap_service.rb +137 -0
- data/lib/{sem4r/cli/cli_sem.rb → sem4r_soap/soap_service_v13.rb} +27 -28
- data/lib/sem4r_soap/soap_service_v2010.rb +80 -0
- data/lib/sem4r_soap.rb +17 -0
- data/sem4r.gemspec +93 -58
- data/spec/build_fixtures.rb +49 -42
- data/spec/fixtures/password.example.yml +3 -0
- data/spec/fixtures/sem4r.example.yml +6 -0
- data/spec/fixtures/{services/error.xml → soap_error.xml} +0 -0
- data/spec/fixtures/soap_error2.xml +29 -0
- data/spec/helpers/dump_interceptor.rb +90 -0
- data/spec/helpers/fixtures_bulk_mutate_job.rb +48 -0
- data/spec/helpers/fixtures_geo_location.rb +45 -0
- data/{lib/sem4r/campaign_criterion/campaign_criterion_service.rb → spec/helpers/fixtures_info.rb} +10 -6
- data/spec/helpers/fixtures_report_definition.rb +65 -0
- data/spec/{rspec_hash.rb → helpers/rspec_hash.rb} +1 -0
- data/spec/{rspec_matchers.rb → helpers/rspec_matchers.rb} +46 -19
- data/spec/{rspec_sem4r_helper.rb → helpers/rspec_sem4r_helper.rb} +19 -16
- data/spec/{sem4r_stubs.rb → helpers/sem4r_stubs.rb} +5 -4
- data/spec/rspec_helper.rb +4 -4
- data/spec/sem4r/account_spec.rb +2 -3
- data/spec/sem4r/ad_group/ad_group_service_spec.rb +1 -1
- data/spec/sem4r/ad_group/ad_group_spec.rb +1 -1
- data/spec/sem4r/ad_group_ad/ad_group_ad_operation_spec.rb +3 -3
- data/spec/sem4r/adwords_spec.rb +62 -39
- data/{lib/sem4r/cli/commands/cli_list_campaign.rb → spec/sem4r/bulk_mutate_job/bulk_mutate_job_selector_spec.rb} +14 -11
- data/spec/sem4r/bulk_mutate_job/bulk_mutate_job_service_spec.rb +2 -3
- data/spec/sem4r/bulk_mutate_job/bulk_mutate_job_spec.rb +23 -17
- data/spec/sem4r/bulk_mutate_job/fixtures/get-list_job-req.xml +35 -0
- data/spec/sem4r/bulk_mutate_job/fixtures/get-list_job-res.xml +417 -0
- data/spec/sem4r/bulk_mutate_job/fixtures/mutate-add_job-req.xml +106 -0
- data/spec/sem4r/bulk_mutate_job/fixtures/mutate-add_job-res.xml +48 -0
- data/spec/sem4r/bulk_mutate_job/job_operation_spec.rb +5 -7
- data/spec/sem4r/campaign/campaign_service_spec.rb +2 -2
- data/spec/sem4r/credentials_spec.rb +10 -8
- data/spec/sem4r/geo_location/address_spec.rb +62 -0
- data/spec/sem4r/geo_location/fixtures/get-req.xml +42 -0
- data/spec/sem4r/geo_location/fixtures/get-res.xml +60 -0
- data/spec/sem4r/info/fixtures/get-req.xml +34 -0
- data/spec/sem4r/info/fixtures/get-res.xml +27 -0
- data/spec/sem4r/nokogiri_parsing_spec.rb +1 -0
- data/spec/sem4r/operation_spec.rb +72 -0
- data/spec/sem4r/report_definition/fixtures/get-list-repdef-req.xml +22 -0
- data/spec/sem4r/report_definition/fixtures/get-list-repdef-res.xml +73 -0
- data/spec/sem4r/report_definition/fixtures/getReportFields-req.xml +24 -0
- data/spec/sem4r/report_definition/fixtures/getReportFields-res.xml +1199 -0
- data/spec/sem4r/report_definition/fixtures/mutate-add-report-req.xml +63 -0
- data/spec/sem4r/report_definition/fixtures/mutate-add-report-res.xml +68 -0
- data/spec/sem4r/report_definition/report_definition_service_spec.rb +5 -5
- data/spec/sem4r/report_definition/report_definition_spec.rb +28 -43
- data/{lib/sem4r/cli/commands/cli_list_report.rb → spec/sem4r/report_definition/report_field_spec.rb} +12 -10
- data/spec/sem4r/rexml_parsing_spec.rb +1 -0
- data/spec/sem4r/{services/service_spec.rb → service_spec.rb} +1 -1
- data/spec/sem4r/targeting_idea/targeting_idea_selector_spec.rb +1 -1
- data/spec/sem4r/targeting_idea/targeting_idea_service_spec.rb +1 -1
- data/spec/sem4r/targeting_idea/targeting_idea_spec.rb +1 -1
- data/spec/sem4r/v13_account/account_service_spec.rb +2 -2
- data/spec/sem4r/v13_report/report_service_spec.rb +2 -2
- data/spec/{sem4r/cli → sem4r_cli}/cli_spec.rb +22 -27
- data/spec/{soap_helpers → sem4r_soap}/soap_attributes_spec.rb +3 -3
- data/spec/{sem4r/services/soap_message_v13_spec.rb → sem4r_soap/soap_response_spec.rb} +10 -15
- data/spec/{sem4r/services/soap_call_spec.rb → sem4r_soap/soap_service_spec.rb} +35 -54
- data/tasks/jeweler.rake +66 -0
- data/tasks/rspec.rake +21 -0
- data/tasks/sem4r.rake +25 -0
- data/tasks/yard.rake +31 -0
- metadata +173 -76
- data/lib/sem4r/ad_extension_override/ad_extension_override_service.rb +0 -30
- data/lib/sem4r/api_counters.rb +0 -8
- data/lib/sem4r/campaign_target/campaign_target_service.rb +0 -30
- data/lib/sem4r/cli/commands/cli_download_report.rb +0 -82
- data/lib/sem4r/services/http_connector.rb +0 -93
- data/lib/sem4r/services/soap_call.rb +0 -122
- data/lib/sem4r/services/soap_connector.rb +0 -139
- data/lib/sem4r/services/soap_message_v13.rb +0 -135
- data/lib/sem4r/services/soap_message_v2010.rb +0 -184
- data/lib/sem4r/v13_traffic_estimator/traffic_estimator_service.rb +0 -30
- data/spec/aggregates_rspec_helper.rb +0 -59
- data/spec/sem4r/report_definition/fixtures/mutate_add-req.xml +0 -24
- 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
|
-
|
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
|
-
|
39
|
-
|
40
|
-
|
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(
|
67
|
-
els
|
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
|
-
@
|
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
|
-
|
27
|
-
|
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
|
-
|
37
|
-
|
38
|
-
|
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
|
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}
|
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
|
-
|
28
|
-
|
29
|
-
|
26
|
+
class Service #:nodoc: all
|
27
|
+
|
28
|
+
def initialize(connector)
|
29
|
+
@connector = connector
|
30
|
+
end
|
30
31
|
|
31
|
-
|
32
|
-
|
32
|
+
###########################################################################
|
33
|
+
# services v13
|
33
34
|
|
34
|
-
|
35
|
-
|
36
|
-
|
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
|
-
|
43
|
-
|
44
|
-
|
43
|
+
EOFR
|
44
|
+
eval str
|
45
|
+
end
|
45
46
|
|
46
|
-
|
47
|
-
|
47
|
+
###########################################################################
|
48
|
+
# services v2010xx
|
48
49
|
|
49
|
-
|
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
|
-
|
63
|
-
|
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
|
-
|
70
|
-
|
68
|
+
EOFR
|
69
|
+
eval str
|
70
|
+
end
|
71
|
+
|
71
72
|
end
|
72
73
|
|
73
|
-
|
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(
|
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
|
-
|
26
|
-
|
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
|
-
|
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
|
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
|
-
#
|
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
|
-
|
71
|
-
|
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
|
-
|
26
|
-
|
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
|
-
|
35
|
-
|
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
|
-
|
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
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
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)
|