sem4r 0.1.1 → 0.1.2
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.
- data/Gemfile +11 -0
- data/Gemfile.lock +36 -0
- data/README.rdoc +30 -0
- data/Rakefile +15 -12
- data/VERSION.yml +1 -1
- data/examples_blog/2009-11-29-hello-world.rb +0 -1
- data/examples_sem4r/01_get_account.rb +1 -1
- data/examples_sem4r/02_get_info.rb +6 -2
- data/examples_sem4r/03_list_ad.rb +1 -1
- data/examples_sem4r/04_list_keywords.rb +1 -1
- data/examples_sem4r/05_request_report.rb +1 -2
- data/examples_sem4r/05_request_report_2010.rb +19 -4
- data/examples_sem4r/06_create_campaigns.rb +1 -1
- data/examples_sem4r/07_create_campaigns_block.rb +1 -1
- data/examples_sem4r/07_create_campaigns_simple.rb +1 -1
- data/examples_sem4r/08_ad_params.rb +1 -1
- data/examples_sem4r/09_targeting_idea.rb +1 -1
- data/examples_sem4r/10_get_location.rb +1 -1
- data/examples_sem4r/11_submit_bulk_job.rb +1 -1
- data/examples_sem4r/12_list_bulk_job.rb +1 -1
- data/examples_sem4r/30_prune_empty_adgroup.rb +1 -1
- data/examples_sem4r/31_empty_accounts.rb +1 -1
- data/examples_sem4r/example_helper.rb +5 -10
- data/lib/sem4r/account.rb +3 -306
- data/lib/sem4r/ad_group/ad_group.rb +16 -14
- data/lib/sem4r/ad_group/ad_group_bids.rb +11 -10
- data/lib/sem4r/ad_group/ad_group_service.rb +5 -5
- data/lib/sem4r/ad_group_ad/ad_group_ad.rb +1 -1
- data/lib/sem4r/ad_group_ad/ad_group_ad_service.rb +5 -5
- data/lib/sem4r/ad_group_ad/ad_group_mobile_ad.rb +9 -9
- data/lib/sem4r/ad_group_ad/ad_group_text_ad.rb +9 -9
- data/lib/sem4r/ad_group_criterion/ad_group_criterion.rb +6 -6
- data/lib/sem4r/ad_group_criterion/ad_group_criterion_bids.rb +5 -6
- data/lib/sem4r/ad_group_criterion/ad_group_criterion_operations.rb +0 -1
- data/lib/sem4r/ad_group_criterion/ad_group_criterion_service.rb +4 -4
- data/lib/sem4r/ad_group_criterion/criterion.rb +3 -3
- data/lib/sem4r/ad_group_criterion/criterion_keyword.rb +3 -3
- data/lib/sem4r/ad_group_criterion/criterion_placement.rb +2 -2
- data/lib/sem4r/ad_param/ad_param.rb +3 -3
- data/lib/sem4r/ad_param/ad_param_service.rb +5 -5
- data/lib/sem4r/adwords.rb +1 -0
- data/lib/sem4r/api_counters.rb +1 -0
- data/lib/sem4r/base.rb +1 -0
- data/lib/sem4r/bulk_mutate_job/bulk_mutate_job.rb +2 -2
- data/lib/sem4r/bulk_mutate_job/bulk_mutate_job_account_extension.rb +59 -0
- data/lib/sem4r/bulk_mutate_job/bulk_mutate_job_service.rb +5 -5
- data/lib/sem4r/campaign/campaign.rb +10 -10
- data/lib/sem4r/campaign/campaign_account_extension.rb +87 -0
- data/lib/sem4r/campaign/campaign_service.rb +6 -6
- data/lib/sem4r/campaign_target/campaign_target_service.rb +22 -22
- data/lib/sem4r/cli/cli_command.rb +1 -0
- data/lib/sem4r/cli/cli_common_args.rb +10 -3
- data/lib/sem4r/cli/cli_helpers.rb +1 -0
- data/lib/sem4r/cli/cli_sem.rb +1 -0
- data/lib/sem4r/cli/{cli_download_report.rb → commands/cli_download_report.rb} +2 -1
- data/lib/sem4r/cli/{cli_ideas.rb → commands/cli_ideas.rb} +1 -0
- data/lib/sem4r/cli/{cli_commands.rb → commands/cli_info.rb} +3 -23
- data/lib/sem4r/cli/{cli_list_ads.rb → commands/cli_list_ads.rb} +1 -0
- data/lib/sem4r/cli/commands/cli_list_campaign.rb +35 -0
- data/lib/sem4r/cli/commands/cli_list_client.rb +36 -0
- data/lib/sem4r/cli/{cli_list_keywords.rb → commands/cli_list_keywords.rb} +1 -0
- data/lib/sem4r/cli/commands/cli_list_report.rb +34 -0
- data/lib/sem4r/cli/commands/cli_repdef.rb +109 -0
- data/lib/sem4r/cli/commands/cli_report.rb +78 -0
- data/lib/sem4r/cli/{cli_request_report.rb → commands/cli_request_report.rb} +1 -0
- data/lib/sem4r/credentials.rb +1 -0
- data/lib/sem4r/extensions.rb +22 -1
- data/lib/sem4r/geo_location/geo_location_account_extension.rb +43 -0
- data/lib/sem4r/geo_location/geo_location_service.rb +4 -4
- data/lib/sem4r/info/info_account_extension.rb +48 -0
- data/lib/sem4r/info/info_selector.rb +108 -0
- data/lib/sem4r/info/info_service.rb +11 -66
- data/lib/sem4r/{common/operation.rb → operation.rb} +3 -1
- data/lib/sem4r/report_definition/report_definition.rb +75 -15
- data/lib/sem4r/report_definition/report_definition_account_extension.rb +79 -0
- data/lib/sem4r/report_definition/report_definition_operation.rb +3 -1
- data/lib/sem4r/report_definition/report_definition_service.rb +7 -7
- data/lib/sem4r/report_definition/report_field.rb +57 -0
- data/lib/sem4r/sem4r_error.rb +1 -0
- data/lib/sem4r/services/http_connector.rb +93 -0
- data/lib/sem4r/services/service.rb +1 -1
- data/lib/sem4r/services/soap_call.rb +27 -5
- data/lib/sem4r/services/soap_connector.rb +2 -147
- data/lib/sem4r/services/soap_dumper.rb +105 -0
- data/lib/sem4r/services/soap_message_v13.rb +15 -9
- data/lib/sem4r/services/{soap_message_v2009.rb → soap_message_v2010.rb} +26 -12
- data/lib/sem4r/targeting_idea/targeting_idea.rb +16 -11
- data/lib/sem4r/targeting_idea/targeting_idea_account_extension.rb +52 -0
- data/lib/sem4r/targeting_idea/targeting_idea_selector.rb +36 -10
- data/lib/sem4r/targeting_idea/targeting_idea_service.rb +5 -5
- data/lib/sem4r/v13_account/account_account_extension.rb +103 -0
- data/lib/sem4r/v13_account/billing_address.rb +10 -21
- data/lib/sem4r/v13_report/report.rb +8 -8
- data/lib/sem4r/v13_report/report_account_extension.rb +63 -0
- data/lib/sem4r/v13_report/report_job.rb +1 -1
- data/lib/sem4r.rb +27 -6
- data/lib/sem4r_cli.rb +4 -6
- data/lib/{sem4r → soap_helpers}/soap_attributes.rb +105 -13
- data/sem4r.gemspec +229 -190
- data/spec/{aggregates_spec_helper.rb → aggregates_rspec_helper.rb} +0 -0
- data/spec/build_fixtures.rb +84 -0
- data/spec/rspec_hash.rb +66 -0
- data/spec/{spec_helper.rb → rspec_helper.rb} +4 -2
- data/spec/rspec_matchers.rb +102 -0
- data/spec/rspec_sem4r_helper.rb +88 -0
- data/spec/sem4r/account_spec.rb +3 -4
- data/spec/sem4r/ad_group/ad_group_bids_spec.rb +4 -3
- data/spec/sem4r/ad_group/ad_group_service_spec.rb +8 -7
- data/spec/sem4r/ad_group/ad_group_spec.rb +5 -4
- data/spec/{fixtures/services/ad_group → sem4r/ad_group/fixtures}/get-first-req.xml +0 -0
- data/spec/{fixtures/services/ad_group → sem4r/ad_group/fixtures}/get-first-res.xml +0 -0
- data/spec/{fixtures/services/ad_group → sem4r/ad_group/fixtures}/get-manual-cpm-bids-req.xml +0 -0
- data/spec/{fixtures/services/ad_group → sem4r/ad_group/fixtures}/get-manual-cpm-bids-res.xml +0 -0
- data/spec/{fixtures/services/ad_group → sem4r/ad_group/fixtures}/mutate_add-req.xml +0 -0
- data/spec/{fixtures/services/ad_group → sem4r/ad_group/fixtures}/mutate_add-res.xml +0 -0
- data/spec/sem4r/ad_group_ad/ad_group_ad_operation_spec.rb +3 -3
- data/spec/sem4r/ad_group_ad/ad_group_ad_service_spec.rb +6 -5
- data/spec/sem4r/ad_group_ad/ad_group_ad_spec.rb +6 -5
- data/spec/{fixtures/services/ad_group_ad → sem4r/ad_group_ad/fixtures}/get_mobile_ad-req.xml +0 -0
- data/spec/{fixtures/services/ad_group_ad → sem4r/ad_group_ad/fixtures}/get_mobile_ad-res.xml +0 -0
- data/spec/{fixtures/services/ad_group_ad → sem4r/ad_group_ad/fixtures}/get_text_ad-req.xml +0 -0
- data/spec/{fixtures/services/ad_group_ad → sem4r/ad_group_ad/fixtures}/get_text_ad-res.xml +0 -0
- data/spec/{fixtures/services/ad_group_ad → sem4r/ad_group_ad/fixtures}/mutate_add_mobile_ad-req.xml +0 -0
- data/spec/{fixtures/services/ad_group_ad → sem4r/ad_group_ad/fixtures}/mutate_add_mobile_ad-res.xml +0 -0
- data/spec/{fixtures/services/ad_group_ad → sem4r/ad_group_ad/fixtures}/mutate_add_text_ad-req.xml +0 -0
- data/spec/{fixtures/services/ad_group_ad → sem4r/ad_group_ad/fixtures}/mutate_add_text_ad-res.xml +0 -0
- data/spec/{fixtures/services/ad_group_ad → sem4r/ad_group_ad/fixtures}/mutate_add_two_criterions-req.xml +0 -0
- data/spec/{fixtures/services/ad_group_ad → sem4r/ad_group_ad/fixtures}/mutate_add_two_criterions-res.xml +0 -0
- data/spec/sem4r/ad_group_criterion/ad_group_criterion_bids_spec.rb +5 -4
- data/spec/sem4r/ad_group_criterion/ad_group_criterion_service_spec.rb +6 -5
- data/spec/sem4r/ad_group_criterion/ad_group_criterion_spec.rb +6 -5
- data/spec/sem4r/ad_group_criterion/criterion_spec.rb +5 -4
- data/spec/{fixtures/services/ad_group_criterion → sem4r/ad_group_criterion/fixtures}/get-req.xml +0 -0
- data/spec/{fixtures/services/ad_group_criterion → sem4r/ad_group_criterion/fixtures}/get-res.xml +0 -0
- data/spec/{fixtures/services/ad_group_criterion → sem4r/ad_group_criterion/fixtures}/mutate_add_criterion_keyword-req.xml +0 -0
- data/spec/{fixtures/services/ad_group_criterion → sem4r/ad_group_criterion/fixtures}/mutate_add_criterion_keyword-res.xml +0 -0
- data/spec/{fixtures/services/ad_group_criterion → sem4r/ad_group_criterion/fixtures}/mutate_add_criterion_placement-req.xml +0 -0
- data/spec/{fixtures/services/ad_group_criterion → sem4r/ad_group_criterion/fixtures}/mutate_add_criterion_placement-res.xml +0 -0
- data/spec/{fixtures/services/ad_group_criterion → sem4r/ad_group_criterion/fixtures}/mutate_add_negative_keyword-req.xml +0 -0
- data/spec/{fixtures/services/ad_group_criterion → sem4r/ad_group_criterion/fixtures}/mutate_add_negative_keyword-res.xml +0 -0
- data/spec/sem4r/ad_param/ad_param_service_spec.rb +6 -5
- data/spec/sem4r/ad_param/ad_param_spec.rb +3 -2
- data/spec/{fixtures/services/ad_param → sem4r/ad_param/fixtures}/mutate_set-req.xml +0 -0
- data/spec/{fixtures/services/ad_param → sem4r/ad_param/fixtures}/mutate_set-res.xml +0 -0
- data/spec/sem4r/adwords_spec.rb +1 -1
- data/spec/sem4r/bulk_mutate_job/bulk_mutate_job_service_spec.rb +6 -5
- data/spec/sem4r/bulk_mutate_job/bulk_mutate_job_spec.rb +4 -3
- data/spec/{fixtures/services/bulk_mutate_job → sem4r/bulk_mutate_job/fixtures}/get-req.xml +0 -0
- data/spec/{fixtures/services/bulk_mutate_job → sem4r/bulk_mutate_job/fixtures}/get-res.xml +0 -0
- data/spec/{fixtures/services/bulk_mutate_job → sem4r/bulk_mutate_job/fixtures}/mutate-req.xml +0 -0
- data/spec/{fixtures/services/bulk_mutate_job → sem4r/bulk_mutate_job/fixtures}/mutate-res.xml +0 -0
- data/spec/sem4r/bulk_mutate_job/job_operation_spec.rb +3 -2
- data/spec/sem4r/campaign/campaign_service_spec.rb +8 -7
- data/spec/sem4r/campaign/campaign_spec.rb +3 -2
- data/spec/{fixtures/services/campaign → sem4r/campaign/fixtures}/get-req.xml +0 -0
- data/spec/{fixtures/services/campaign → sem4r/campaign/fixtures}/get-res.xml +0 -0
- data/spec/{fixtures/services/campaign → sem4r/campaign/fixtures}/mutate_add-req.xml +0 -0
- data/spec/{fixtures/services/campaign → sem4r/campaign/fixtures}/mutate_add-res.xml +0 -0
- data/spec/sem4r/cli/cli_spec.rb +2 -3
- data/spec/sem4r/credentials_spec.rb +1 -1
- data/spec/sem4r/info/account_info_extension_spec.rb +51 -0
- data/spec/sem4r/info/fixtures/get_unit_count-req.xml +34 -0
- data/spec/sem4r/info/fixtures/get_unit_count-res.xml +27 -0
- data/spec/sem4r/nokogiri_parsing_spec.rb +105 -0
- data/spec/{fixtures/services/report_definition → sem4r/report_definition/fixtures}/mutate_add-req.xml +0 -0
- data/spec/{fixtures/services/report_definition → sem4r/report_definition/fixtures}/mutate_add-req_orig.xml +0 -0
- data/spec/sem4r/report_definition/report_definition_service_spec.rb +5 -3
- data/spec/sem4r/report_definition/report_definition_spec.rb +6 -3
- data/spec/sem4r/rexml_parsing_spec.rb +22 -22
- data/spec/sem4r/services/service_spec.rb +2 -1
- data/spec/sem4r/services/soap_call_spec.rb +6 -5
- data/spec/sem4r/services/soap_message_v13_spec.rb +5 -11
- data/spec/{fixtures/services/targeting_idea → sem4r/targeting_idea/fixtures}/get-req-all-options.xml +0 -0
- data/spec/{fixtures/services/targeting_idea → sem4r/targeting_idea/fixtures}/get-req.xml +9 -11
- data/spec/sem4r/targeting_idea/fixtures/get-res.xml +2276 -0
- data/spec/sem4r/targeting_idea/targeting_idea_selector_spec.rb +30 -11
- data/spec/sem4r/targeting_idea/targeting_idea_service_spec.rb +4 -3
- data/spec/sem4r/targeting_idea/targeting_idea_spec.rb +5 -4
- data/spec/sem4r/v13_account/account_account_extension_spec.rb +47 -0
- data/spec/sem4r/v13_account/account_service_spec.rb +6 -5
- data/spec/sem4r/v13_account/billing_address_spec.rb +40 -0
- data/spec/{fixtures/services/v13_account → sem4r/v13_account/fixtures}/get_account_info-req.xml +0 -0
- data/spec/{fixtures/services/v13_account → sem4r/v13_account/fixtures}/get_account_info-res.xml +0 -0
- data/spec/{fixtures/services/v13_account → sem4r/v13_account/fixtures}/get_client_accounts-req.xml +0 -0
- data/spec/{fixtures/services/v13_account → sem4r/v13_account/fixtures}/get_client_accounts-res.xml +0 -0
- data/spec/{fixtures/services/v13_report → sem4r/v13_report/fixtures}/get_all_jobs-req.xml +0 -0
- data/spec/{fixtures/services/v13_report → sem4r/v13_report/fixtures}/get_all_jobs-res.xml +2 -2
- data/spec/{fixtures/services/v13_report → sem4r/v13_report/fixtures}/schedule_report_job-req.xml +0 -0
- data/spec/{fixtures/services/v13_report → sem4r/v13_report/fixtures}/schedule_report_job-res.xml +0 -0
- data/spec/sem4r/v13_report/report_service_spec.rb +13 -11
- data/spec/sem4r/v13_report/report_spec.rb +4 -3
- data/spec/sem4r_stubs.rb +182 -0
- data/spec/soap_helpers/soap_attributes_spec.rb +129 -0
- metadata +225 -125
- data/spec/fixtures/services/info/get_unit_count-req.xml +0 -30
- data/spec/fixtures/services/info/get_unit_count-res.xml +0 -29
- data/spec/fixtures/services/targeting_idea/get-res.xml +0 -3601
- data/spec/sem4r/soap_attributes_spec.rb +0 -116
- data/spec/sem4r_spec_helper.rb +0 -353
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
# -------------------------------------------------------------------------
|
|
2
|
-
# Copyright (c) 2009-2010 Sem4r sem4ruby@gmail.com
|
|
3
|
-
#
|
|
4
|
-
# Permission is hereby granted, free of charge, to any person obtaining
|
|
5
|
-
# a copy of this software and associated documentation files (the
|
|
6
|
-
# "Software"), to deal in the Software without restriction, including
|
|
7
|
-
# without limitation the rights to use, copy, modify, merge, publish,
|
|
8
|
-
# distribute, sublicense, and/or sell copies of the Software, and to
|
|
9
|
-
# permit persons to whom the Software is furnished to do so, subject to
|
|
10
|
-
# the following conditions:
|
|
11
|
-
#
|
|
12
|
-
# The above copyright notice and this permission notice shall be
|
|
13
|
-
# included in all copies or substantial portions of the Software.
|
|
14
|
-
#
|
|
15
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
16
|
-
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
17
|
-
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
18
|
-
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
19
|
-
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
20
|
-
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
21
|
-
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
22
|
-
#
|
|
23
|
-
# -------------------------------------------------------------------------
|
|
24
|
-
|
|
25
|
-
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
|
26
|
-
|
|
27
|
-
describe SoapAttributes do
|
|
28
|
-
|
|
29
|
-
class TSoapAttributes
|
|
30
|
-
include Sem4r::SoapAttributes
|
|
31
|
-
|
|
32
|
-
enum :Types, [:Daily, :Monthly, :Weekly, :Yearly]
|
|
33
|
-
enum :Columns, [:Id, :Campaign, :Keyword]
|
|
34
|
-
|
|
35
|
-
g_accessor :name
|
|
36
|
-
g_accessor :type, {:values_in => :Types}
|
|
37
|
-
g_accessor :day, {:if_type => "Daily"}
|
|
38
|
-
g_accessor :month, {:if_type => "Monthly"}
|
|
39
|
-
g_accessor :myflag, {:default => false}
|
|
40
|
-
|
|
41
|
-
g_set_accessor :column
|
|
42
|
-
g_set_accessor :c_column, {:values_in => :Columns}
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
describe "g_accessor" do
|
|
47
|
-
it "g_accessor should define constants from enum array" do
|
|
48
|
-
TSoapAttributes::Daily.should eql("Daily")
|
|
49
|
-
TSoapAttributes::Types.should include("Daily")
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
it "g_accessor without constraints" do
|
|
53
|
-
t = TSoapAttributes.new
|
|
54
|
-
|
|
55
|
-
t.name = "Pippo"
|
|
56
|
-
t.name.should == "Pippo"
|
|
57
|
-
|
|
58
|
-
t.name "Pluto"
|
|
59
|
-
t.name.should == "Pluto"
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
it "g_accessor with constraints on value" do
|
|
63
|
-
t = TSoapAttributes.new
|
|
64
|
-
|
|
65
|
-
t.type = "Daily"
|
|
66
|
-
t.type.should == "Daily"
|
|
67
|
-
|
|
68
|
-
lambda { t.type "Dailyy" }.should raise_error
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
it "g_accessor with contraint on type" do
|
|
72
|
-
t = TSoapAttributes.new
|
|
73
|
-
|
|
74
|
-
t.type = "Daily"
|
|
75
|
-
t.day = "2009-10-10"
|
|
76
|
-
t.day.should == "2009-10-10"
|
|
77
|
-
|
|
78
|
-
lambda { t.month "November" }.should raise_error
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
it "g_accessor with default value" do
|
|
82
|
-
t = TSoapAttributes.new
|
|
83
|
-
|
|
84
|
-
t.type.should == nil
|
|
85
|
-
t.myflag.should == false
|
|
86
|
-
t.myflag = true
|
|
87
|
-
t.myflag.should == true
|
|
88
|
-
end
|
|
89
|
-
end
|
|
90
|
-
|
|
91
|
-
describe "g_set_accessor" do
|
|
92
|
-
it "g_set_accessor without contraints" do
|
|
93
|
-
t = TSoapAttributes.new
|
|
94
|
-
|
|
95
|
-
t.column = "Id"
|
|
96
|
-
t.column "Campaign"
|
|
97
|
-
t.columns.should include("Id")
|
|
98
|
-
t.columns.should include("Campaign")
|
|
99
|
-
t.columns.should_not include("Pluto")
|
|
100
|
-
|
|
101
|
-
t.should have(2).columns
|
|
102
|
-
t.column = "Id"
|
|
103
|
-
t.should have(2).columns
|
|
104
|
-
end
|
|
105
|
-
|
|
106
|
-
it "g_set_accessor with values constraints" do
|
|
107
|
-
t = TSoapAttributes.new
|
|
108
|
-
|
|
109
|
-
t.c_column = "Id"
|
|
110
|
-
t.c_columns.should include("Id")
|
|
111
|
-
|
|
112
|
-
lambda { t.c_column = "Pluto" }.should raise_error
|
|
113
|
-
end
|
|
114
|
-
end
|
|
115
|
-
|
|
116
|
-
end
|
data/spec/sem4r_spec_helper.rb
DELETED
|
@@ -1,353 +0,0 @@
|
|
|
1
|
-
# -------------------------------------------------------------------------
|
|
2
|
-
# Copyright (c) 2009-2010 Sem4r sem4ruby@gmail.com
|
|
3
|
-
#
|
|
4
|
-
# Permission is hereby granted, free of charge, to any person obtaining
|
|
5
|
-
# a copy of this software and associated documentation files (the
|
|
6
|
-
# "Software"), to deal in the Software without restriction, including
|
|
7
|
-
# without limitation the rights to use, copy, modify, merge, publish,
|
|
8
|
-
# distribute, sublicense, and/or sell copies of the Software, and to
|
|
9
|
-
# permit persons to whom the Software is furnished to do so, subject to
|
|
10
|
-
# the following conditions:
|
|
11
|
-
#
|
|
12
|
-
# The above copyright notice and this permission notice shall be
|
|
13
|
-
# included in all copies or substantial portions of the Software.
|
|
14
|
-
#
|
|
15
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
16
|
-
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
17
|
-
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
18
|
-
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
19
|
-
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
20
|
-
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
21
|
-
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
22
|
-
#
|
|
23
|
-
# -------------------------------------------------------------------------
|
|
24
|
-
|
|
25
|
-
# comparing xml is always a b-i-a-t-c-h in any testing environment. here is a
|
|
26
|
-
# little snippet for ruby that, i think, it a good first pass at making it
|
|
27
|
-
# easier. comment with your improvements please!
|
|
28
|
-
#
|
|
29
|
-
# http://drawohara.com/post/89110816/ruby-comparing-xml
|
|
30
|
-
require 'rexml/document'
|
|
31
|
-
require 'differ'
|
|
32
|
-
require 'differ/string'
|
|
33
|
-
|
|
34
|
-
def pretty_xml(xml)
|
|
35
|
-
normalized = Class.new(REXML::Formatters::Pretty) do
|
|
36
|
-
def write_text(node, output)
|
|
37
|
-
super(node.to_s.strip, output)
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
normalized.new(0,false).write(xml, xml_pretty='')
|
|
41
|
-
xml_pretty
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
Spec::Matchers.define :xml_equivalent do |expected_xml|
|
|
45
|
-
match do |xml|
|
|
46
|
-
if expected_xml.class == String
|
|
47
|
-
# erase namespaces i.e. <ns1:tag> -> <tag>
|
|
48
|
-
expected_xml = expected_xml.gsub(/(ns\d:|xsi:|s:|^\n)/, "").strip
|
|
49
|
-
expected_xml = REXML::Document.new(expected_xml)
|
|
50
|
-
end
|
|
51
|
-
expected_normalized = pretty_xml(expected_xml)
|
|
52
|
-
# erase namespaces i.e. <ns1:tag> -> <tag>
|
|
53
|
-
expected_normalized = expected_normalized.gsub(/(ns\d:|xsi:|s:|^\n| {2,})/, "").strip
|
|
54
|
-
|
|
55
|
-
if xml.class == String
|
|
56
|
-
xml = xml.gsub(/(ns\d:|xsi:|s:|^\n)/, "").strip
|
|
57
|
-
begin
|
|
58
|
-
xml = REXML::Document.new(xml)
|
|
59
|
-
rescue RuntimeError
|
|
60
|
-
puts "----------------------------------"
|
|
61
|
-
puts xml
|
|
62
|
-
puts "----------------------------------"
|
|
63
|
-
raise
|
|
64
|
-
end
|
|
65
|
-
end
|
|
66
|
-
xml_normalized = pretty_xml(xml)
|
|
67
|
-
xml_normalized = xml_normalized.gsub(/(ns\d:|xsi:|s:|^\n)/, "").strip
|
|
68
|
-
|
|
69
|
-
if xml_normalized != expected_normalized
|
|
70
|
-
puts "----differ start"
|
|
71
|
-
|
|
72
|
-
puts xml_normalized
|
|
73
|
-
|
|
74
|
-
puts "---"
|
|
75
|
-
puts expected_normalized
|
|
76
|
-
puts "---"
|
|
77
|
-
diff = Differ.diff_by_line(xml_normalized, expected_normalized)
|
|
78
|
-
puts diff.format_as(:ascii)
|
|
79
|
-
puts "----differ end"
|
|
80
|
-
false
|
|
81
|
-
else
|
|
82
|
-
true
|
|
83
|
-
end
|
|
84
|
-
end
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
Spec::Matchers.define :xml_contains do |expected_xml|
|
|
88
|
-
match do |xml|
|
|
89
|
-
if expected_xml.class == String
|
|
90
|
-
# erase namespaces i.e. <ns1:tag> -> <tag>
|
|
91
|
-
expected_xml = expected_xml.gsub(/(ns\d:|xsi:|s:|^\n)/, "").strip
|
|
92
|
-
expected_xml = REXML::Document.new(expected_xml)
|
|
93
|
-
end
|
|
94
|
-
expected_normalized = pretty_xml(expected_xml)
|
|
95
|
-
# erase namespaces i.e. <ns1:tag> -> <tag>
|
|
96
|
-
expected_normalized = expected_normalized.gsub(/(ns\d:|xsi:|s:|^\n)/, "").strip
|
|
97
|
-
|
|
98
|
-
if xml.class == String
|
|
99
|
-
xml = xml.gsub(/(ns\d:|xsi:|s:|^\n)/, "").strip
|
|
100
|
-
begin
|
|
101
|
-
xml = REXML::Document.new(xml)
|
|
102
|
-
rescue RuntimeError
|
|
103
|
-
puts "----------------------------------"
|
|
104
|
-
puts xml
|
|
105
|
-
puts "----------------------------------"
|
|
106
|
-
raise
|
|
107
|
-
end
|
|
108
|
-
end
|
|
109
|
-
xml_normalized = pretty_xml(xml)
|
|
110
|
-
xml_normalized = xml_normalized.gsub(/(ns\d:|xsi:|s:|^\n)/, "").strip
|
|
111
|
-
|
|
112
|
-
unless xml_normalized.match(expected_normalized)
|
|
113
|
-
false
|
|
114
|
-
else
|
|
115
|
-
true
|
|
116
|
-
end
|
|
117
|
-
end
|
|
118
|
-
end
|
|
119
|
-
|
|
120
|
-
module Sem4rSpecHelper
|
|
121
|
-
|
|
122
|
-
require "stringio"
|
|
123
|
-
def with_stdout_captured
|
|
124
|
-
old_stdout = $stdout
|
|
125
|
-
out = StringIO.new
|
|
126
|
-
$stdout = out
|
|
127
|
-
begin
|
|
128
|
-
yield
|
|
129
|
-
ensure
|
|
130
|
-
$stdout = old_stdout
|
|
131
|
-
end
|
|
132
|
-
out.string
|
|
133
|
-
end
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
##
|
|
137
|
-
# rSpec Hash additions.
|
|
138
|
-
#
|
|
139
|
-
# From
|
|
140
|
-
# * http://wincent.com/knowledge-base/Fixtures_considered_harmful%3F
|
|
141
|
-
# * Neil Rahilly
|
|
142
|
-
|
|
143
|
-
class Hash
|
|
144
|
-
|
|
145
|
-
##
|
|
146
|
-
# Filter keys out of a Hash.
|
|
147
|
-
#
|
|
148
|
-
# { :a => 1, :b => 2, :c => 3 }.except(:a)
|
|
149
|
-
# => { :b => 2, :c => 3 }
|
|
150
|
-
|
|
151
|
-
def except(*keys)
|
|
152
|
-
self.reject { |k,v| keys.include?(k || k.to_sym) }
|
|
153
|
-
end
|
|
154
|
-
|
|
155
|
-
##
|
|
156
|
-
# Override some keys.
|
|
157
|
-
#
|
|
158
|
-
# { :a => 1, :b => 2, :c => 3 }.with(:a => 4)
|
|
159
|
-
# => { :a => 4, :b => 2, :c => 3 }
|
|
160
|
-
|
|
161
|
-
def with(overrides = {})
|
|
162
|
-
self.merge overrides
|
|
163
|
-
end
|
|
164
|
-
|
|
165
|
-
##
|
|
166
|
-
# Returns a Hash with only the pairs identified by +keys+.
|
|
167
|
-
#
|
|
168
|
-
# { :a => 1, :b => 2, :c => 3 }.only(:a)
|
|
169
|
-
# => { :a => 1 }
|
|
170
|
-
|
|
171
|
-
def only(*keys)
|
|
172
|
-
self.reject { |k,v| !keys.include?(k || k.to_sym) }
|
|
173
|
-
end
|
|
174
|
-
|
|
175
|
-
end
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
#############################################################################
|
|
179
|
-
|
|
180
|
-
def read_xml_file(*args)
|
|
181
|
-
xml_filepath = File.join(File.dirname(__FILE__), "fixtures", *args)
|
|
182
|
-
unless File.exist?(xml_filepath)
|
|
183
|
-
raise "file #{xml_filepath} not exists"
|
|
184
|
-
end
|
|
185
|
-
File.open(xml_filepath).read
|
|
186
|
-
end
|
|
187
|
-
|
|
188
|
-
def read_model(xpath, *args, &blk)
|
|
189
|
-
contents = read_xml_file(*args)
|
|
190
|
-
response_xml_wns = contents.gsub(/n(s?)\d:/, "")
|
|
191
|
-
xml_document = REXML::Document.new(response_xml_wns)
|
|
192
|
-
if xpath && blk
|
|
193
|
-
el = REXML::XPath.each(xml_document, xpath) do |node|
|
|
194
|
-
yield node
|
|
195
|
-
end
|
|
196
|
-
elsif xpath
|
|
197
|
-
el = REXML::XPath.first(xml_document, xpath)
|
|
198
|
-
else
|
|
199
|
-
el = xml_document.root.elements.to_a.first
|
|
200
|
-
end
|
|
201
|
-
if el.nil?
|
|
202
|
-
raise "xml element not found '#{xpath}'"
|
|
203
|
-
end
|
|
204
|
-
el
|
|
205
|
-
end
|
|
206
|
-
|
|
207
|
-
def read_xml_document(*args)
|
|
208
|
-
contents = read_xml_file(*args)
|
|
209
|
-
response_xml_wns = contents.gsub(/ns\d:/, "")
|
|
210
|
-
REXML::Document.new(response_xml_wns)
|
|
211
|
-
end
|
|
212
|
-
|
|
213
|
-
#############################################################################
|
|
214
|
-
|
|
215
|
-
def stub_service_account(service)
|
|
216
|
-
xml_document = read_xml_document("services", "v13_account", "get_account_info-res.xml")
|
|
217
|
-
soap_message = stub("soap_message", :response => xml_document, :counters => nil)
|
|
218
|
-
account_service = stub("account_service", :account_info => soap_message)
|
|
219
|
-
service.stub(:account).and_return(account_service)
|
|
220
|
-
end
|
|
221
|
-
|
|
222
|
-
def stub_service_info(service)
|
|
223
|
-
xml_document = read_xml_document("services", "info", "get_unit_count-res.xml")
|
|
224
|
-
soap_message = stub("soap_message", :response => xml_document, :counters => nil)
|
|
225
|
-
account_service = stub("account_service", :unit_cost => soap_message)
|
|
226
|
-
service.stub(:info).and_return(account_service)
|
|
227
|
-
end
|
|
228
|
-
|
|
229
|
-
def stub_service_campaign(service)
|
|
230
|
-
xml_document = read_xml_document("services", "campaign", "mutate_add-res.xml")
|
|
231
|
-
soap_message_create = stub("soap_message", :response => xml_document, :counters => nil)
|
|
232
|
-
|
|
233
|
-
xml_document = read_xml_document("services", "campaign", "get-res.xml")
|
|
234
|
-
soap_message_all = stub("soap_message", :response => xml_document, :counters => nil)
|
|
235
|
-
|
|
236
|
-
campaign_service = stub("campaign_service", :create => soap_message_create, :all => soap_message_all)
|
|
237
|
-
service.stub(:campaign).and_return(campaign_service)
|
|
238
|
-
end
|
|
239
|
-
|
|
240
|
-
def stub_service_ad_group(service)
|
|
241
|
-
xml_document = read_xml_document("services", "ad_group", "mutate_add-res.xml")
|
|
242
|
-
soap_message = stub("soap_message", :response => xml_document, :counters => nil)
|
|
243
|
-
ad_group_service = stub("adgroup_service", :create => soap_message)
|
|
244
|
-
service.stub(:ad_group).and_return(ad_group_service)
|
|
245
|
-
end
|
|
246
|
-
|
|
247
|
-
def stub_service_ad_group_ad(service)
|
|
248
|
-
xml_document = read_xml_document("services", "ad_group_ad", "mutate_add_text_ad-res.xml")
|
|
249
|
-
soap_message = stub("soap_message", :response => xml_document, :counters => nil)
|
|
250
|
-
ad_group_ad_service = stub("ad_group_ad_service", :mutate => soap_message)
|
|
251
|
-
service.stub(:ad_group_ad).and_return(ad_group_ad_service)
|
|
252
|
-
end
|
|
253
|
-
|
|
254
|
-
def stub_service_ad_group_criterion(service)
|
|
255
|
-
xml_document = read_xml_document("services", "ad_group_criterion", "mutate_add_criterion_keyword-res.xml")
|
|
256
|
-
soap_message = stub("soap_message", :response => xml_document, :counters => nil)
|
|
257
|
-
ad_group_criterion_service = stub("ad_group_criterion_service", :mutate => soap_message)
|
|
258
|
-
service.stub(:ad_group_criterion).and_return(ad_group_criterion_service)
|
|
259
|
-
end
|
|
260
|
-
|
|
261
|
-
def stub_service_ad_param(service)
|
|
262
|
-
# xml_document = read_xml_document("services", "ad_group_criterion_service", "mutate_add_criterion_keyword-res.xml")
|
|
263
|
-
soap_message = stub("soap_message", :response => nil, :counters => nil)
|
|
264
|
-
ad_param_service = stub("ad_param_service", :mutate => soap_message)
|
|
265
|
-
service.stub(:ad_param).and_return(ad_param_service)
|
|
266
|
-
end
|
|
267
|
-
|
|
268
|
-
def stub_service_report(service)
|
|
269
|
-
all_xml_document = read_xml_document("services", "v13_report", "get_all_jobs-res.xml")
|
|
270
|
-
all_soap_message = stub("soap_message", :response => all_xml_document, :counters => nil)
|
|
271
|
-
set_soap_message = stub("soap_message", :response => nil, :counters => nil)
|
|
272
|
-
report_service = stub("report_service",
|
|
273
|
-
:set => set_soap_message,
|
|
274
|
-
:all => all_soap_message)
|
|
275
|
-
|
|
276
|
-
service.stub(:report).and_return(report_service)
|
|
277
|
-
end
|
|
278
|
-
|
|
279
|
-
def stub_service_report_definition(service)
|
|
280
|
-
report_definition_service = stub("report_definition_service")
|
|
281
|
-
service.stub(:report_definition).and_return(report_definition_service)
|
|
282
|
-
end
|
|
283
|
-
|
|
284
|
-
#############################################################################
|
|
285
|
-
|
|
286
|
-
def stub_services
|
|
287
|
-
double("services")
|
|
288
|
-
end
|
|
289
|
-
|
|
290
|
-
def stub_adwords(services = nil)
|
|
291
|
-
stub("adwords",
|
|
292
|
-
:service => services ||= stub_services,
|
|
293
|
-
:add_counters => nil)
|
|
294
|
-
end
|
|
295
|
-
|
|
296
|
-
def stub_credentials
|
|
297
|
-
stub("credentials",
|
|
298
|
-
:sandbox? => true,
|
|
299
|
-
:email => "example@gmail.com",
|
|
300
|
-
:password => "secret",
|
|
301
|
-
:client_email => nil,
|
|
302
|
-
:useragent => "sem4r",
|
|
303
|
-
:developer_token => "dev_token",
|
|
304
|
-
:authentication_token => "1234567890",
|
|
305
|
-
:mutable? => false
|
|
306
|
-
)
|
|
307
|
-
end
|
|
308
|
-
|
|
309
|
-
def stub_account(services = nil)
|
|
310
|
-
adwords = stub_adwords(services)
|
|
311
|
-
credentials = stub_credentials
|
|
312
|
-
campaign = stub("account",
|
|
313
|
-
:adwords => adwords,
|
|
314
|
-
:credentials => credentials,
|
|
315
|
-
:id => 1000)
|
|
316
|
-
campaign
|
|
317
|
-
end
|
|
318
|
-
|
|
319
|
-
def stub_campaign(services = nil)
|
|
320
|
-
adwords = stub_adwords(services)
|
|
321
|
-
credentials = stub_credentials
|
|
322
|
-
|
|
323
|
-
campaign = stub("campaign",
|
|
324
|
-
:adwords => adwords,
|
|
325
|
-
:credentials => credentials,
|
|
326
|
-
:inside_initialize? => false,
|
|
327
|
-
:id => 1000)
|
|
328
|
-
campaign
|
|
329
|
-
end
|
|
330
|
-
|
|
331
|
-
def stub_adgroup(services = nil, id = 1000)
|
|
332
|
-
adwords = stub_adwords(services)
|
|
333
|
-
credentials = stub_credentials
|
|
334
|
-
stub("adgroup",
|
|
335
|
-
:adwords => adwords,
|
|
336
|
-
:credentials => credentials,
|
|
337
|
-
:inside_initialize? => false,
|
|
338
|
-
:id => id)
|
|
339
|
-
end
|
|
340
|
-
|
|
341
|
-
def stub_criterion(services = nil)
|
|
342
|
-
adwords = stub_adwords(services)
|
|
343
|
-
credentials = stub_credentials
|
|
344
|
-
|
|
345
|
-
stub("criterion",
|
|
346
|
-
:adwords => adwords,
|
|
347
|
-
:credentials => credentials,
|
|
348
|
-
:inside_initialize? => false,
|
|
349
|
-
:id => 1000,
|
|
350
|
-
:ad_group => stub_adgroup(services))
|
|
351
|
-
end
|
|
352
|
-
end
|
|
353
|
-
|