sem4r 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
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,54 @@
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 SoapMessageV13 do
28
+
29
+ include Sem4rSpecHelper
30
+
31
+ before(:all) do
32
+ @credentials = mock("credentials")
33
+ # @credentials.should_receive(:sandbox?).and_return(true)
34
+ @credentials.should_receive(:email).and_return("example@gmail.com")
35
+ @credentials.should_receive(:password).and_return("secret")
36
+ @credentials.should_receive(:client_email).and_return(nil)
37
+ @credentials.should_receive(:useragent).and_return("sem4r")
38
+ @credentials.should_receive(:developer_token).and_return("dev_token")
39
+ end
40
+
41
+ it "should update counters" do
42
+ response_xml = read_xml_file("services", "v13_report", "get_all_jobs-res.xml")
43
+ connector = mock("connector")
44
+ connector.should_receive(:send).and_return(response_xml)
45
+
46
+ message_v13 = SoapMessageV13.new(connector, @credentials)
47
+ message_v13.body = ""
48
+ message_v13.send("service_url", "soap_action")
49
+
50
+ message_v13.counters.should_not be_empty
51
+ message_v13.counters.should == { :response_time => 177, :operations => 4, :units => 4 }
52
+ end
53
+
54
+ end
@@ -0,0 +1,116 @@
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
@@ -0,0 +1,120 @@
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 TargetingIdeaSelector do
28
+ include Sem4rSpecHelper, AggregatesSpecHelper
29
+
30
+ it "should produce xml (input for google)" do
31
+ idea_selector = TargetingIdeaSelector.new do
32
+ idea_type "KEYWORD"
33
+ request_type "IDEAS"
34
+
35
+ excluded_keyword_search_parameter do
36
+ text 'media player'
37
+ match_type 'EXACT'
38
+ end
39
+
40
+ keyword_match_type_search_parameter do
41
+ match_type 'BROAD'
42
+ match_type 'EXACT'
43
+ end
44
+
45
+ related_to_keyword_search_parameter do
46
+ text 'dvd player'
47
+ match_type 'EXACT'
48
+ end
49
+
50
+ country_target_search_parameter do
51
+ country_code 'US'
52
+ end
53
+ end
54
+
55
+ xml_expected = read_model("//s:selector", "services", "targeting_idea", "get-req.xml")
56
+ idea_selector.to_xml.should xml_equivalent(xml_expected)
57
+ end
58
+
59
+ it "should produce xml (input for google) with optional parameters" do
60
+ idea_selector = TargetingIdeaSelector.new do
61
+ idea_type "KEYWORD"
62
+ request_type "IDEAS"
63
+ requested_attributes [:keyword, :targeted_monthly_searches]
64
+ start_index 201
65
+ number_results 200
66
+
67
+ related_to_keyword_search_parameter do
68
+ text 'dvd player'
69
+ match_type 'EXACT'
70
+ end
71
+ end
72
+ read_model("//s:requestedAttributeTypes", "services", "targeting_idea", "get-req-all-options.xml") do |attribute_type|
73
+ idea_selector.to_xml.should xml_contains(attribute_type)
74
+ end
75
+ end
76
+
77
+ describe RelatedToKeywordSearchParameter do
78
+ it "should produce xml (input for google)" do
79
+ sp = RelatedToKeywordSearchParameter.new do
80
+ text "dvd player"
81
+ match_type "EXACT"
82
+ end
83
+ xml_expected = read_model("//s:searchParameters[@xsi:type='s:RelatedToKeywordSearchParameter']", "services", "targeting_idea", "get-req.xml")
84
+ sp.to_xml.should xml_equivalent(xml_expected)
85
+ end
86
+ end
87
+
88
+ describe ExcludedKeywordSearchParameter do
89
+ it "should produce xml (input for google)" do
90
+ sp = ExcludedKeywordSearchParameter.new do
91
+ text "media player"
92
+ match_type "EXACT"
93
+ end
94
+ xml_expected = read_model("//s:searchParameters[@xsi:type='s:ExcludedKeywordSearchParameter']", "services", "targeting_idea", "get-req.xml")
95
+ sp.to_xml.should xml_equivalent(xml_expected)
96
+ end
97
+ end
98
+
99
+ describe KeywordMatchTypeSearchParameter do
100
+ it "should produce xml (input for google)" do
101
+ sp = KeywordMatchTypeSearchParameter.new do
102
+ match_type 'BROAD'
103
+ match_type "EXACT"
104
+ end
105
+ xml_expected = read_model("//s:searchParameters[@xsi:type='s:KeywordMatchTypeSearchParameter']", "services", "targeting_idea", "get-req.xml")
106
+ sp.to_xml.should xml_equivalent(xml_expected)
107
+ end
108
+ end
109
+
110
+ describe CountryTargetSearchParameter do
111
+ it "should produce xml (input for google)" do
112
+ sp = CountryTargetSearchParameter.new do
113
+ country_code 'US'
114
+ end
115
+ xml_expected = read_model("//s:searchParameters[@xsi:type='s:CountryTargetSearchParameter']", "services", "targeting_idea", "get-req.xml")
116
+ sp.to_xml.should xml_equivalent(xml_expected)
117
+ end
118
+ end
119
+
120
+ end
@@ -0,0 +1,44 @@
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 TargetingIdeaService do
28
+ include Sem4rSpecHelper
29
+
30
+ before do
31
+ @credentials = stub_credentials
32
+ end
33
+
34
+ it "should define 'get'" do
35
+ response_xml = read_xml_file("services", "targeting_idea", "get-res.xml")
36
+ connector = mock("connector")
37
+ connector.should_receive(:send).and_return(response_xml)
38
+ service = TargetingIdeaService.new(connector)
39
+ soap_message = service.get( @credentials, "xml" )
40
+ els = REXML::XPath.match( soap_message.response, "//getResponse")
41
+ els.should_not be_empty
42
+ end
43
+
44
+ end
@@ -0,0 +1,53 @@
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 TargetingIdea do
28
+ include Sem4rSpecHelper, AggregatesSpecHelper
29
+
30
+ it "should parse xml (produced by google)" do
31
+ el = read_model("//entries", "services", "targeting_idea", "get-res.xml")
32
+ idea = TargetingIdea.from_element(el)
33
+ idea.should have(2).attributes
34
+ end
35
+
36
+ describe TKeywordAttribute do
37
+ it "should parse xml (produced by google)" do
38
+ el = read_model("//value", "services", "targeting_idea", "get-res.xml")
39
+ attr = TKeywordAttribute.from_element(el)
40
+ attr.text.should == "sample keyword"
41
+ attr.match_type.should == "EXACT"
42
+ end
43
+ end
44
+
45
+ describe TIdeaTypeAttribute do
46
+ it "should parse xml (produced by google)" do
47
+ el = read_model("//value[@type='IdeaTypeAttribute']", "services", "targeting_idea", "get-res.xml")
48
+ attr = TIdeaTypeAttribute.from_element(el)
49
+ attr.value.should == "KEYWORD"
50
+ end
51
+ end
52
+
53
+ end
@@ -0,0 +1,60 @@
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 AccountService do
28
+ include Sem4rSpecHelper
29
+
30
+ before do
31
+ @credentials = stub_credentials
32
+ end
33
+
34
+ it "should define 'account_info'" do
35
+ response_xml = read_xml_file("services", "v13_account", "get_account_info-res.xml")
36
+
37
+ connector = mock("connector")
38
+ connector.should_receive(:send).and_return(response_xml)
39
+
40
+ service = AccountService.new(connector)
41
+ soap_message = service.account_info( @credentials )
42
+
43
+ els = REXML::XPath.match( soap_message.response, "//getAccountInfoResponse")
44
+ els.should_not be_empty
45
+ end
46
+
47
+ it "should define 'client_accounts'" do
48
+ response_xml = read_xml_file("services", "v13_account", "get_client_accounts-res.xml")
49
+
50
+ connector = mock("connector")
51
+ connector.should_receive(:send).and_return(response_xml)
52
+
53
+ service = AccountService.new(connector)
54
+ soap_message = service.client_accounts( @credentials )
55
+
56
+ els = REXML::XPath.match( soap_message.response, "//getClientAccountsResponse")
57
+ els.should_not be_empty
58
+ end
59
+
60
+ end
@@ -0,0 +1,104 @@
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 ReportService do
28
+ include Sem4rSpecHelper
29
+
30
+ before do
31
+ @credentials = stub_credentials
32
+ end
33
+
34
+ it "should define 'all'" do
35
+ response_xml = read_xml_file("services", "v13_report", "get_all_jobs-res.xml")
36
+
37
+ connector = mock("connector")
38
+ connector.should_receive(:send).and_return(response_xml)
39
+
40
+ report_service = ReportService.new(connector)
41
+ soap_message = report_service.all( @credentials )
42
+
43
+ els = REXML::XPath.match( soap_message.response, "//getAllJobsResponse/getAllJobsReturn")
44
+ els.should_not be_empty
45
+ els.should have(4).elements
46
+ end
47
+
48
+ it "should define 'validate'" do
49
+ response_xml = read_xml_file("services", "v13_report", "get_all_jobs-res.xml")
50
+
51
+ connector = mock("connector")
52
+ connector.should_receive(:send).and_return(response_xml)
53
+
54
+ report_service = ReportService.new(connector)
55
+ soap_message = report_service.validate( @credentials, "xml" )
56
+
57
+ els = REXML::XPath.match( soap_message.response, "//getAllJobsResponse/getAllJobsReturn")
58
+ els.should_not be_empty
59
+ els.should have(4).elements
60
+ end
61
+
62
+ it "should define 'schedule'" do
63
+ response_xml = read_xml_file("services", "v13_report", "get_all_jobs-res.xml")
64
+
65
+ connector = mock("connector")
66
+ connector.should_receive(:send).and_return(response_xml)
67
+
68
+ report_service = ReportService.new(connector)
69
+ soap_message = report_service.schedule( @credentials, "xml" )
70
+
71
+ els = REXML::XPath.match( soap_message.response, "//getAllJobsResponse/getAllJobsReturn")
72
+ els.should_not be_empty
73
+ els.should have(4).elements
74
+ end
75
+
76
+ it "should define 'status'" do
77
+ response_xml = read_xml_file("services", "v13_report", "get_all_jobs-res.xml")
78
+
79
+ connector = mock("connector")
80
+ connector.should_receive(:send).and_return(response_xml)
81
+
82
+ report_service = ReportService.new(connector)
83
+ soap_message = report_service.status( @credentials, "job_id" )
84
+
85
+ els = REXML::XPath.match( soap_message.response, "//getAllJobsResponse/getAllJobsReturn")
86
+ els.should_not be_empty
87
+ els.should have(4).elements
88
+ end
89
+
90
+ it "should define 'url'" do
91
+ response_xml = read_xml_file("services", "v13_report", "get_all_jobs-res.xml")
92
+
93
+ connector = mock("connector")
94
+ connector.should_receive(:send).and_return(response_xml)
95
+
96
+ report_service = ReportService.new(connector)
97
+ soap_message = report_service.url( @credentials, "job_id" )
98
+
99
+ els = REXML::XPath.match( soap_message.response, "//getAllJobsResponse/getAllJobsReturn")
100
+ els.should_not be_empty
101
+ els.should have(4).elements
102
+ end
103
+
104
+ end
@@ -0,0 +1,79 @@
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 Report do
28
+ include Sem4rSpecHelper
29
+
30
+ before do
31
+ services = stub("services")
32
+ stub_service_report(services)
33
+ @account = stub_account(services)
34
+ end
35
+
36
+ it "create should be accept a block" do
37
+ report = Report.new(@account) do
38
+ name "Test Report"
39
+ type "Structure"
40
+ start_day "2009-01-01"
41
+ end_day "2009-01-31"
42
+ aggregation "Keyword"
43
+ column "Campaign"
44
+ column "AdGroup"
45
+ column "Keyword"
46
+ column "KeywordTypeDisplay"
47
+ end
48
+ report.id.should == nil
49
+ report.name.should == "Test Report"
50
+ report.type.should == "Structure"
51
+ end
52
+
53
+ it "should parse xml (produced by google)" do
54
+ el = read_model("//getAllJobsReturn", "services", "v13_report", "get_all_jobs-res.xml")
55
+ report = Report.from_element(@account, el)
56
+ report.id.should == 11
57
+ report.name.should == "report [11]"
58
+ report.start_day == "2010-02-19-08:00"
59
+ report.status == "Pending"
60
+ end
61
+
62
+ it "should build xml (input for google)" do
63
+ report = Report.new(@account) do
64
+ name "Test Report"
65
+ type "Structure"
66
+ start_day "2009-01-01"
67
+ end_day "2009-01-31"
68
+ aggregation "Keyword"
69
+ column "Campaign"
70
+ column "AdGroup"
71
+ column "Keyword"
72
+ column "KeywordTypeDisplay"
73
+ end
74
+
75
+ expected = read_model("//job", "services", "v13_report", "schedule_report_job-req.xml")
76
+ report.to_xml.should xml_equivalent(expected)
77
+ end
78
+
79
+ end