sem4r 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (187) hide show
  1. data/LICENSE +22 -0
  2. data/README.rdoc +74 -0
  3. data/Rakefile +126 -0
  4. data/VERSION.yml +5 -0
  5. data/bin/sem +34 -0
  6. data/config/sem4r.example.yml +51 -0
  7. data/examples_blog/2009-11-29-hello-world.rb +12 -0
  8. data/examples_blog/2009-12-12-create-campaign.rb +29 -0
  9. data/examples_blog/2010-02-06-constants-scope.rb +8 -0
  10. data/examples_blog/2010-02-07-ad-parameters.rb +47 -0
  11. data/examples_sem4r/01_get_account.rb +37 -0
  12. data/examples_sem4r/02_get_info.rb +32 -0
  13. data/examples_sem4r/03_list_ad.rb +47 -0
  14. data/examples_sem4r/04_list_keywords.rb +54 -0
  15. data/examples_sem4r/05_request_report.rb +51 -0
  16. data/examples_sem4r/05_request_report_2010.rb +40 -0
  17. data/examples_sem4r/06_create_campaigns.rb +86 -0
  18. data/examples_sem4r/07_create_campaigns_block.rb +99 -0
  19. data/examples_sem4r/07_create_campaigns_simple.rb +65 -0
  20. data/examples_sem4r/08_ad_params.rb +70 -0
  21. data/examples_sem4r/09_targeting_idea.rb +59 -0
  22. data/examples_sem4r/10_get_location.rb +28 -0
  23. data/examples_sem4r/11_submit_bulk_job.rb +82 -0
  24. data/examples_sem4r/12_list_bulk_job.rb +29 -0
  25. data/examples_sem4r/30_prune_empty_adgroup.rb +50 -0
  26. data/examples_sem4r/31_empty_accounts.rb +40 -0
  27. data/examples_sem4r/example_helper.rb +115 -0
  28. data/lib/sem4r/account.rb +349 -0
  29. data/lib/sem4r/ad_extension_override/ad_extension_override_service.rb +30 -0
  30. data/lib/sem4r/ad_group/ad_group.rb +340 -0
  31. data/lib/sem4r/ad_group/ad_group_bids.rb +170 -0
  32. data/lib/sem4r/ad_group/ad_group_service.rb +75 -0
  33. data/lib/sem4r/ad_group/mobile_ad_image.rb +33 -0
  34. data/lib/sem4r/ad_group_ad/ad_group_ad.rb +98 -0
  35. data/lib/sem4r/ad_group_ad/ad_group_ad_operations.rb +38 -0
  36. data/lib/sem4r/ad_group_ad/ad_group_ad_service.rb +56 -0
  37. data/lib/sem4r/ad_group_ad/ad_group_mobile_ad.rb +137 -0
  38. data/lib/sem4r/ad_group_ad/ad_group_text_ad.rb +98 -0
  39. data/lib/sem4r/ad_group_criterion/ad_group_criterion.rb +144 -0
  40. data/lib/sem4r/ad_group_criterion/ad_group_criterion_bids.rb +115 -0
  41. data/lib/sem4r/ad_group_criterion/ad_group_criterion_operations.rb +35 -0
  42. data/lib/sem4r/ad_group_criterion/ad_group_criterion_service.rb +58 -0
  43. data/lib/sem4r/ad_group_criterion/criterion.rb +67 -0
  44. data/lib/sem4r/ad_group_criterion/criterion_keyword.rb +80 -0
  45. data/lib/sem4r/ad_group_criterion/criterion_placement.rb +66 -0
  46. data/lib/sem4r/ad_param/ad_param.rb +96 -0
  47. data/lib/sem4r/ad_param/ad_param_operation.rb +34 -0
  48. data/lib/sem4r/ad_param/ad_param_service.rb +59 -0
  49. data/lib/sem4r/adwords.rb +242 -0
  50. data/lib/sem4r/api_counters.rb +7 -0
  51. data/lib/sem4r/base.rb +43 -0
  52. data/lib/sem4r/bulk_mutate_job/bulk_mutate_job.rb +108 -0
  53. data/lib/sem4r/bulk_mutate_job/bulk_mutate_job_selector.rb +56 -0
  54. data/lib/sem4r/bulk_mutate_job/bulk_mutate_job_service.rb +57 -0
  55. data/lib/sem4r/bulk_mutate_job/job_operations.rb +35 -0
  56. data/lib/sem4r/campaign/campaign.rb +193 -0
  57. data/lib/sem4r/campaign/campaign_service.rb +91 -0
  58. data/lib/sem4r/campaign_criterion/campaign_criterion_service.rb +30 -0
  59. data/lib/sem4r/campaign_target/campaign_target_service.rb +30 -0
  60. data/lib/sem4r/cli/cli_command.rb +101 -0
  61. data/lib/sem4r/cli/cli_commands.rb +60 -0
  62. data/lib/sem4r/cli/cli_common_args.rb +293 -0
  63. data/lib/sem4r/cli/cli_download_report.rb +81 -0
  64. data/lib/sem4r/cli/cli_helpers.rb +57 -0
  65. data/lib/sem4r/cli/cli_ideas.rb +100 -0
  66. data/lib/sem4r/cli/cli_list_ads.rb +74 -0
  67. data/lib/sem4r/cli/cli_list_keywords.rb +76 -0
  68. data/lib/sem4r/cli/cli_request_report.rb +104 -0
  69. data/lib/sem4r/cli/cli_sem.rb +64 -0
  70. data/lib/sem4r/common/operation.rb +78 -0
  71. data/lib/sem4r/credentials.rb +86 -0
  72. data/lib/sem4r/extensions.rb +62 -0
  73. data/lib/sem4r/geo_location/geo_location_service.rb +59 -0
  74. data/lib/sem4r/info/info_service.rb +115 -0
  75. data/lib/sem4r/report_definition/report_definition.rb +104 -0
  76. data/lib/sem4r/report_definition/report_definition_operation.rb +34 -0
  77. data/lib/sem4r/report_definition/report_definition_selector.rb +31 -0
  78. data/lib/sem4r/report_definition/report_definition_service.rb +55 -0
  79. data/lib/sem4r/sem4r_error.rb +28 -0
  80. data/lib/sem4r/services/service.rb +74 -0
  81. data/lib/sem4r/services/soap_call.rb +100 -0
  82. data/lib/sem4r/services/soap_connector.rb +284 -0
  83. data/lib/sem4r/services/soap_error.rb +38 -0
  84. data/lib/sem4r/services/soap_message_v13.rb +129 -0
  85. data/lib/sem4r/services/soap_message_v2009.rb +170 -0
  86. data/lib/sem4r/soap_attributes.rb +141 -0
  87. data/lib/sem4r/targeting_idea/targeting_idea.rb +158 -0
  88. data/lib/sem4r/targeting_idea/targeting_idea_selector.rb +200 -0
  89. data/lib/sem4r/targeting_idea/targeting_idea_service.rb +51 -0
  90. data/lib/sem4r/v13_account/account_service.rb +54 -0
  91. data/lib/sem4r/v13_account/billing_address.rb +67 -0
  92. data/lib/sem4r/v13_report/report.rb +185 -0
  93. data/lib/sem4r/v13_report/report_job.rb +51 -0
  94. data/lib/sem4r/v13_report/report_service.rb +89 -0
  95. data/lib/sem4r/v13_traffic_estimator/traffic_estimator_service.rb +30 -0
  96. data/lib/sem4r.rb +142 -0
  97. data/lib/sem4r_cli.rb +40 -0
  98. data/sem4r.gemspec +247 -0
  99. data/spec/aggregates_spec_helper.rb +59 -0
  100. data/spec/fixtures/sem4r.example.yml +26 -0
  101. data/spec/fixtures/services/ad_group/get-first-req.xml +28 -0
  102. data/spec/fixtures/services/ad_group/get-first-res.xml +91 -0
  103. data/spec/fixtures/services/ad_group/get-manual-cpm-bids-req.xml +106 -0
  104. data/spec/fixtures/services/ad_group/get-manual-cpm-bids-res.xml +75 -0
  105. data/spec/fixtures/services/ad_group/mutate_add-req.xml +52 -0
  106. data/spec/fixtures/services/ad_group/mutate_add-res.xml +33 -0
  107. data/spec/fixtures/services/ad_group_ad/get_mobile_ad-req.xml +28 -0
  108. data/spec/fixtures/services/ad_group_ad/get_mobile_ad-res.xml +194 -0
  109. data/spec/fixtures/services/ad_group_ad/get_text_ad-req.xml +29 -0
  110. data/spec/fixtures/services/ad_group_ad/get_text_ad-res.xml +55 -0
  111. data/spec/fixtures/services/ad_group_ad/mutate_add_mobile_ad-req.xml +50 -0
  112. data/spec/fixtures/services/ad_group_ad/mutate_add_mobile_ad-res.xml +42 -0
  113. data/spec/fixtures/services/ad_group_ad/mutate_add_text_ad-req.xml +37 -0
  114. data/spec/fixtures/services/ad_group_ad/mutate_add_text_ad-res.xml +32 -0
  115. data/spec/fixtures/services/ad_group_ad/mutate_add_two_criterions-req.xml +83 -0
  116. data/spec/fixtures/services/ad_group_ad/mutate_add_two_criterions-res.xml +95 -0
  117. data/spec/fixtures/services/ad_group_criterion/get-req.xml +28 -0
  118. data/spec/fixtures/services/ad_group_criterion/get-res.xml +242 -0
  119. data/spec/fixtures/services/ad_group_criterion/mutate_add_criterion_keyword-req.xml +48 -0
  120. data/spec/fixtures/services/ad_group_criterion/mutate_add_criterion_keyword-res.xml +47 -0
  121. data/spec/fixtures/services/ad_group_criterion/mutate_add_criterion_placement-req.xml +35 -0
  122. data/spec/fixtures/services/ad_group_criterion/mutate_add_criterion_placement-res.xml +32 -0
  123. data/spec/fixtures/services/ad_group_criterion/mutate_add_negative_keyword-req.xml +37 -0
  124. data/spec/fixtures/services/ad_group_criterion/mutate_add_negative_keyword-res.xml +51 -0
  125. data/spec/fixtures/services/ad_param/mutate_set-req.xml +43 -0
  126. data/spec/fixtures/services/ad_param/mutate_set-res.xml +29 -0
  127. data/spec/fixtures/services/bulk_mutate_job/get-req.xml +36 -0
  128. data/spec/fixtures/services/bulk_mutate_job/get-res.xml +54 -0
  129. data/spec/fixtures/services/bulk_mutate_job/mutate-req.xml +69 -0
  130. data/spec/fixtures/services/bulk_mutate_job/mutate-res.xml +48 -0
  131. data/spec/fixtures/services/campaign/get-req.xml +37 -0
  132. data/spec/fixtures/services/campaign/get-res.xml +1986 -0
  133. data/spec/fixtures/services/campaign/mutate_add-req.xml +37 -0
  134. data/spec/fixtures/services/campaign/mutate_add-res.xml +42 -0
  135. data/spec/fixtures/services/error.xml +28 -0
  136. data/spec/fixtures/services/info/get_unit_count-req.xml +30 -0
  137. data/spec/fixtures/services/info/get_unit_count-res.xml +29 -0
  138. data/spec/fixtures/services/report_definition/mutate_add-req.xml +24 -0
  139. data/spec/fixtures/services/report_definition/mutate_add-req_orig.xml +45 -0
  140. data/spec/fixtures/services/targeting_idea/get-req-all-options.xml +57 -0
  141. data/spec/fixtures/services/targeting_idea/get-req.xml +60 -0
  142. data/spec/fixtures/services/targeting_idea/get-res.xml +3601 -0
  143. data/spec/fixtures/services/v13_account/get_account_info-req.xml +23 -0
  144. data/spec/fixtures/services/v13_account/get_account_info-res.xml +54 -0
  145. data/spec/fixtures/services/v13_account/get_client_accounts-req.xml +22 -0
  146. data/spec/fixtures/services/v13_account/get_client_accounts-res.xml +37 -0
  147. data/spec/fixtures/services/v13_report/get_all_jobs-req.xml +21 -0
  148. data/spec/fixtures/services/v13_report/get_all_jobs-res.xml +109 -0
  149. data/spec/fixtures/services/v13_report/schedule_report_job-req.xml +56 -0
  150. data/spec/fixtures/services/v13_report/schedule_report_job-res.xml +24 -0
  151. data/spec/sem4r/account_spec.rb +86 -0
  152. data/spec/sem4r/ad_group/ad_group_bids_spec.rb +67 -0
  153. data/spec/sem4r/ad_group/ad_group_service_spec.rb +66 -0
  154. data/spec/sem4r/ad_group/ad_group_spec.rb +212 -0
  155. data/spec/sem4r/ad_group_ad/ad_group_ad_operation_spec.rb +88 -0
  156. data/spec/sem4r/ad_group_ad/ad_group_ad_service_spec.rb +55 -0
  157. data/spec/sem4r/ad_group_ad/ad_group_ad_spec.rb +173 -0
  158. data/spec/sem4r/ad_group_criterion/ad_group_criterion_bids_spec.rb +60 -0
  159. data/spec/sem4r/ad_group_criterion/ad_group_criterion_service_spec.rb +55 -0
  160. data/spec/sem4r/ad_group_criterion/ad_group_criterion_spec.rb +103 -0
  161. data/spec/sem4r/ad_group_criterion/criterion_spec.rb +85 -0
  162. data/spec/sem4r/ad_param/ad_param_service_spec.rb +55 -0
  163. data/spec/sem4r/ad_param/ad_param_spec.rb +59 -0
  164. data/spec/sem4r/adwords_spec.rb +110 -0
  165. data/spec/sem4r/bulk_mutate_job/bulk_mutate_job_service_spec.rb +63 -0
  166. data/spec/sem4r/bulk_mutate_job/bulk_mutate_job_spec.rb +69 -0
  167. data/spec/sem4r/bulk_mutate_job/job_operation_spec.rb +48 -0
  168. data/spec/sem4r/campaign/campaign_service_spec.rb +66 -0
  169. data/spec/sem4r/campaign/campaign_spec.rb +105 -0
  170. data/spec/sem4r/cli/cli_spec.rb +71 -0
  171. data/spec/sem4r/credentials_spec.rb +65 -0
  172. data/spec/sem4r/report_definition/report_definition_service_spec.rb +44 -0
  173. data/spec/sem4r/report_definition/report_definition_spec.rb +105 -0
  174. data/spec/sem4r/rexml_parsing_spec.rb +103 -0
  175. data/spec/sem4r/services/service_spec.rb +36 -0
  176. data/spec/sem4r/services/soap_call_spec.rb +115 -0
  177. data/spec/sem4r/services/soap_message_v13_spec.rb +54 -0
  178. data/spec/sem4r/soap_attributes_spec.rb +116 -0
  179. data/spec/sem4r/targeting_idea/targeting_idea_selector_spec.rb +120 -0
  180. data/spec/sem4r/targeting_idea/targeting_idea_service_spec.rb +44 -0
  181. data/spec/sem4r/targeting_idea/targeting_idea_spec.rb +53 -0
  182. data/spec/sem4r/v13_account/account_service_spec.rb +60 -0
  183. data/spec/sem4r/v13_report/report_service_spec.rb +104 -0
  184. data/spec/sem4r/v13_report/report_spec.rb +79 -0
  185. data/spec/sem4r_spec_helper.rb +353 -0
  186. data/spec/spec_helper.rb +12 -0
  187. metadata +375 -0
@@ -0,0 +1,103 @@
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
+
28
+ describe AdGroupCriterion do
29
+
30
+ include Sem4rSpecHelper
31
+
32
+ before do
33
+ services = stub("services")
34
+ stub_service_ad_group_criterion(services)
35
+ @ad_group = stub_adgroup(services)
36
+ @criterion = stub_criterion(services)
37
+ @bids = stub("bids")
38
+ end
39
+
40
+ describe BiddableAdGroupCriterion do
41
+
42
+ it "should be build with accessor (not a block)" do
43
+ biddable_criterion = BiddableAdGroupCriterion.new(@ad_group)
44
+ biddable_criterion.criterion @criterion
45
+ biddable_criterion.bids @bids
46
+ biddable_criterion.criterion.should eql @criterion
47
+ biddable_criterion.bids.should eql @bids
48
+ end
49
+
50
+ it "should produce xml (input for google)" do
51
+ keyword = CriterionKeyword.new(@ad_group) do
52
+ text "sem4r adwords api"
53
+ match "BROAD"
54
+ end
55
+ bids = ManualCPCAdGroupCriterionBids.new
56
+ bids.max_cpc 10000000
57
+
58
+ biddable_criterion = BiddableAdGroupCriterion.new(@ad_group)
59
+ biddable_criterion.criterion keyword
60
+ biddable_criterion.bids bids
61
+
62
+ xml_expected = read_model("//operand", "services", "ad_group_criterion", "mutate_add_criterion_keyword-req.xml")
63
+ biddable_criterion.to_xml("operand").should xml_equivalent(xml_expected)
64
+ end
65
+
66
+ it "should parse xml (produced by google)" do
67
+ el = read_model("//entries", "services", "ad_group_criterion", "get-res.xml")
68
+ biddable_criterion = BiddableAdGroupCriterion.from_element(@ad_group, el)
69
+ biddable_criterion.bids.should be_instance_of(ManualCPCAdGroupCriterionBids)
70
+ biddable_criterion.criterion.should be_instance_of(CriterionKeyword)
71
+ end
72
+
73
+ end
74
+
75
+ describe NegativeAdGroupCriterion do
76
+
77
+ it "should be build with accessors (not a block)" do
78
+ biddable_criterion = NegativeAdGroupCriterion.new(@ad_group)
79
+ biddable_criterion.criterion @criterion
80
+ biddable_criterion.criterion.should eql @criterion
81
+ end
82
+
83
+ it "should produce xml (input for google)" do
84
+ keyword = CriterionKeyword.new(@ad_group) do
85
+ text "sem4r adwords api"
86
+ match "BROAD"
87
+ end
88
+ biddable_criterion = NegativeAdGroupCriterion.new(@ad_group)
89
+ biddable_criterion.criterion keyword
90
+ xml_expected = read_model("//operand", "services", "ad_group_criterion", "mutate_add_negative_keyword-req.xml")
91
+ biddable_criterion.to_xml("operand").should xml_equivalent(xml_expected)
92
+ end
93
+
94
+ it "should parse xml (produced by google)" do
95
+ el = read_model("//value", "services", "ad_group_criterion", "mutate_add_negative_keyword-res.xml")
96
+ negative = AdGroupCriterion.from_element(@ad_group, el)
97
+ negative.criterion.text.should == "java api library"
98
+ negative.criterion.match.should == "BROAD"
99
+ end
100
+
101
+ end
102
+
103
+ end
@@ -0,0 +1,85 @@
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
+
28
+ describe Criterion do
29
+ include Sem4rSpecHelper
30
+
31
+ before do
32
+ services = stub("services")
33
+ stub_service_ad_group_criterion(services)
34
+ @ad_group = stub_adgroup(services)
35
+ end
36
+
37
+ describe CriterionKeyword do
38
+
39
+ it "should accept a block" do
40
+ keyword = CriterionKeyword.new(@ad_group) do
41
+ text "pippo"
42
+ match "BROAD"
43
+ end
44
+ keyword.text.should == "pippo"
45
+ keyword.match.should == "BROAD"
46
+ end
47
+
48
+ it "should produce xml (input for google)" do
49
+ keyword = CriterionKeyword.new(@ad_group) do
50
+ text "sem4r adwords api"
51
+ match "BROAD"
52
+ end
53
+ xml_expected = read_model("//criterion", "services", "ad_group_criterion", "mutate_add_criterion_keyword-req.xml")
54
+ keyword.to_xml("criterion").should xml_equivalent(xml_expected)
55
+ end
56
+
57
+ it "should parse xml (produced by google)" do
58
+ el = read_model("//entries/criterion", "services", "ad_group_criterion", "get-res.xml")
59
+ keyword = CriterionKeyword.from_element(@ad_group, el)
60
+ keyword.id.should == 11536082
61
+ keyword.text.should == "pippo"
62
+ keyword.match.should == "BROAD"
63
+ end
64
+
65
+ end
66
+
67
+ describe CriterionPlacement do
68
+
69
+ it "should accept a block" do
70
+ keyword = CriterionPlacement.new(@ad_group) do
71
+ url "http://github.com"
72
+ end
73
+ keyword.url.should == "http://github.com"
74
+ end
75
+
76
+ it "should parse xml (produced by google)" do
77
+ el = read_model("//criterion", "services", "ad_group_criterion", "mutate_add_criterion_placement-res.xml")
78
+ placement = CriterionPlacement.from_element(@ad_group, el)
79
+ placement.id.should == 11536085
80
+ placement.url.should == "github.com"
81
+ end
82
+
83
+ end
84
+
85
+ end
@@ -0,0 +1,55 @@
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 AdParamService 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", "ad_param", "mutate_set-res.xml")
36
+ connector = mock("connector")
37
+ connector.should_receive(:send).and_return(response_xml)
38
+ service = AdParamService.new(connector)
39
+ soap_message = service.all( @credentials, "ad_group_id" )
40
+ els = REXML::XPath.match( soap_message.response, "//mutateResponse")
41
+ els.should_not be_empty
42
+ end
43
+
44
+ it "should define 'set'" do
45
+ @credentials.should_receive(:mutable?).and_return(true)
46
+ response_xml = read_xml_file("services", "ad_param", "mutate_set-res.xml")
47
+ connector = mock("connector")
48
+ connector.should_receive(:send).and_return(response_xml)
49
+ service = AdParamService.new(connector)
50
+ soap_message = service.mutate( @credentials, "xml" )
51
+ els = REXML::XPath.match( soap_message.response, "//mutateResponse")
52
+ els.should_not be_empty
53
+ end
54
+
55
+ end
@@ -0,0 +1,59 @@
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 AdParam do
28
+
29
+ include Sem4rSpecHelper
30
+
31
+ before(:each) do
32
+ services = stub("services")
33
+ stub_service_ad_param(services)
34
+ # stub_service_ad_group_criterion(services)
35
+ # stub_service_ad_group_ad(services)
36
+ @adgroup = stub_adgroup(services)
37
+ @criterion = stub_criterion(services)
38
+ end
39
+
40
+ it "should accepts a block" do
41
+ ad_param = AdParam.new(@adgroup, @criterion) do
42
+ index 1
43
+ text "testo"
44
+ end
45
+ ad_param.index.should == 1
46
+ ad_param.text.should == "testo"
47
+ end
48
+
49
+ it "should parse xml" do
50
+ @adgroup.should_receive(:find_criterion).with(100).and_return(@criterion)
51
+ el = read_model("//rval", "services", "ad_param", "mutate_set-res.xml")
52
+ ad_param = AdParam.from_element(@adgroup, el)
53
+ ad_param.index.should == 1
54
+ ad_param.text.should == "$99.99"
55
+ end
56
+
57
+ end
58
+
59
+
@@ -0,0 +1,110 @@
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 Adwords do
28
+
29
+ before(:each) do
30
+ @test_config_filename = File.expand_path(File.dirname(__FILE__) + "/../fixtures/sem4r.example.yml")
31
+
32
+ @environment = "sandbox"
33
+ @email = "pippo"
34
+ @password = "password"
35
+ @developer_token = "developer_token"
36
+
37
+ @options = {
38
+ :environment => @environment,
39
+ :email => @email,
40
+ :password => @password,
41
+ :developer_token => @developer_token,
42
+ }
43
+ end
44
+
45
+ it "should take an hash as configuration" do
46
+ adwords = Adwords.new( @options )
47
+ adwords.should_not_receive(:load_config)
48
+ credentials = adwords.account.credentials
49
+
50
+ adwords.profile.should == "anonymous_" + @environment
51
+ credentials.environment.should == @environment
52
+ credentials.email.should == @email
53
+ credentials.password.should == @password
54
+ credentials.developer_token.should == @developer_token
55
+ credentials.should_not be_mutable
56
+ end
57
+
58
+ it "should be mutable" do
59
+ @options[:mutable] = true
60
+ adwords = Adwords.new( @options )
61
+ adwords.should_not_receive(:load_config)
62
+ credentials = adwords.account.credentials
63
+ credentials.should be_mutable
64
+ end
65
+
66
+ it "should set the right environment (sandbox)" do
67
+ @options.delete(:environment)
68
+
69
+ adwords = Adwords.sandbox( @options )
70
+ credentials = adwords.account.credentials
71
+ credentials.environment.should == "sandbox"
72
+ credentials.email.should == @email
73
+ end
74
+
75
+ it "should set the right environment (production)" do
76
+ @options.delete(:environment)
77
+ adwords = Adwords.production( @options )
78
+ credentials = adwords.account.credentials
79
+ credentials.environment.should == "production"
80
+ credentials.email.should == @email
81
+ end
82
+
83
+ it "should raise an exception when profile is sandbox and env is production" do
84
+ @options[:environment] = "prodution"
85
+ lambda { adwords = Adwords.sandbox( @options ) }.should raise_error(RuntimeError)
86
+
87
+ @options[:environment] = "sandbox"
88
+ lambda { adwords = Adwords.production( @options ) }.should raise_error(RuntimeError)
89
+ end
90
+
91
+ it "should read config file (profile file)" do
92
+ adwords = Adwords.new( "sandbox", {:config_file => @test_config_filename} )
93
+ credentials = adwords.account.credentials
94
+ credentials.environment.should == "sandbox"
95
+ credentials.developer_token.should == "example@gmail.com++EUR"
96
+
97
+ adwords = Adwords.new( "production1", {:config_file => @test_config_filename} )
98
+ credentials = adwords.account.credentials
99
+ credentials.environment.should == "production"
100
+ credentials.developer_token.should == "productiondevelopertoken"
101
+ end
102
+
103
+
104
+ it "should list profiles" do
105
+ values = Adwords.profiles(@test_config_filename)
106
+ values.should have(4).profiles
107
+ end
108
+
109
+ end
110
+
@@ -0,0 +1,63 @@
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 BulkMutateJobService 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", "bulk_mutate_job", "get-res.xml")
36
+ connector = mock("connector")
37
+ connector.should_receive(:send).and_return(response_xml)
38
+ service = BulkMutateJobService.new(connector)
39
+
40
+ operation = mock("operation")
41
+ operation.stub(:to_xml).and_return("xml")
42
+
43
+ soap_message = service.all( @credentials, operation )
44
+ els = REXML::XPath.match( soap_message.response, "//getResponse")
45
+ els.should_not be_empty
46
+ end
47
+
48
+ it "should define 'mutate'" do
49
+ @credentials.should_receive(:mutable?).and_return(true)
50
+ response_xml = read_xml_file("services", "bulk_mutate_job", "mutate-res.xml")
51
+ connector = mock("connector")
52
+ connector.should_receive(:send).and_return(response_xml)
53
+ service = BulkMutateJobService.new(connector)
54
+
55
+ operation = mock("operation")
56
+ operation.stub(:to_xml).and_return("xml")
57
+
58
+ soap_message = service.mutate( @credentials, operation )
59
+ els = REXML::XPath.match( soap_message.response, "//mutateResponse")
60
+ els.should_not be_empty
61
+ end
62
+
63
+ end
@@ -0,0 +1,69 @@
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 BulkMutateJob do
28
+ include Sem4rSpecHelper, AggregatesSpecHelper
29
+
30
+ before do
31
+ @adgroup = mock("adgroup").as_null_object
32
+ end
33
+
34
+ it "should accept type accessor" do
35
+ # @adgroup.should_receive(:id).and_return(10)
36
+
37
+ text_ad = AdGroupTextAd.new(@adgroup)
38
+ text_ad.headline = "headline"
39
+ text_ad.description1 = "description1"
40
+ text_ad.description2 = "description2"
41
+
42
+ ad_operation = AdGroupAdOperation.new
43
+ ad_operation.add text_ad
44
+
45
+ job = BulkMutateJob.new
46
+ job.campaign_id = 100
47
+ job.add_operation ad_operation
48
+
49
+ job.should have(1).operations
50
+ end
51
+
52
+ it "should parse xml" do
53
+ el = read_model("//rval", "services", "bulk_mutate_job", "get-res.xml")
54
+ job = BulkMutateJob.from_element(el)
55
+ job.id.should == 56889
56
+ job.status.should == "PENDING"
57
+ end
58
+
59
+ it "should have a representation in xml" do
60
+ @adgroup.stub(:id).and_return(3060284754)
61
+ @campaign = stub("campaign")
62
+ @campaign.stub(:id).and_return(100)
63
+ job = create_bulk_mutate_job(@campaign, @adgroup)
64
+
65
+ expected = read_model("//operand", "services", "bulk_mutate_job", "mutate-req.xml")
66
+ job.to_xml('operand').should xml_equivalent(expected)
67
+ end
68
+ end
69
+
@@ -0,0 +1,48 @@
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 JobOperation do
28
+ include Sem4rSpecHelper, AggregatesSpecHelper
29
+
30
+
31
+ it "should produce xml" do
32
+ @campaign = mock("campaign").as_null_object
33
+ @campaign.stub(:id).and_return(100)
34
+
35
+ @adgroup = mock("adgroup").as_null_object
36
+ @adgroup.stub(:id).and_return(3060284754)
37
+
38
+ bulk_mutate_job = create_bulk_mutate_job(@campaign, @adgroup)
39
+ bulk_mutate_job.should_not be_empty
40
+
41
+ job_operation = JobOperation.new
42
+ job_operation.add(bulk_mutate_job)
43
+
44
+ expected_xml = read_model("//operation", "services", "bulk_mutate_job", "mutate-req.xml")
45
+ job_operation.to_xml('operation').should xml_equivalent(expected_xml)
46
+ end
47
+
48
+ end
@@ -0,0 +1,66 @@
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 CampaignService 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", "campaign", "get-res.xml")
36
+ connector = mock("connector")
37
+ connector.should_receive(:send).and_return(response_xml)
38
+ service = CampaignService.new(connector)
39
+ soap_message = service.all( @credentials )
40
+ els = REXML::XPath.match( soap_message.response, "//getResponse")
41
+ els.should_not be_empty
42
+ end
43
+
44
+ it "should define 'create'" do
45
+ @credentials.should_receive(:mutable?).and_return(true)
46
+ response_xml = read_xml_file("services", "campaign", "mutate_add-res.xml")
47
+ connector = mock("connector")
48
+ connector.should_receive(:send).and_return(response_xml)
49
+ service = CampaignService.new(connector)
50
+ soap_message = service.create( @credentials, "xml" )
51
+ els = REXML::XPath.match( soap_message.response, "//mutateResponse")
52
+ els.should_not be_empty
53
+ end
54
+
55
+ it "should define 'delete'" do
56
+ @credentials.should_receive(:mutable?).and_return(true)
57
+ response_xml = read_xml_file("services", "campaign", "mutate_add-res.xml")
58
+ connector = mock("connector")
59
+ connector.should_receive(:send).and_return(response_xml)
60
+ service = CampaignService.new(connector)
61
+ soap_message = service.delete( @credentials, "xml" )
62
+ els = REXML::XPath.match( soap_message.response, "//mutateResponse")
63
+ els.should_not be_empty
64
+ end
65
+
66
+ end