ad_gear_client 0.3.8
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/.gitignore +6 -0
- data/LICENSE +21 -0
- data/README.rdoc +55 -0
- data/Rakefile +132 -0
- data/VERSION +1 -0
- data/ad_gear_client.gemspec +114 -0
- data/examples/.gitignore +1 -0
- data/examples/ad_gear.yml.sample +8 -0
- data/examples/create_campaign.rb +23 -0
- data/examples/create_placement.rb +57 -0
- data/examples/prelude.rb +27 -0
- data/examples/read_write_site.rb +36 -0
- data/examples/upload_file_to_ad_unit.rb +49 -0
- data/lib/ad_gear/ad_spot.rb +7 -0
- data/lib/ad_gear/ad_spot_membership.rb +5 -0
- data/lib/ad_gear/ad_unit.rb +17 -0
- data/lib/ad_gear/ad_unit_click.rb +5 -0
- data/lib/ad_gear/ad_unit_file.rb +6 -0
- data/lib/ad_gear/ad_unit_interaction.rb +5 -0
- data/lib/ad_gear/ad_unit_variable.rb +5 -0
- data/lib/ad_gear/advertiser.rb +4 -0
- data/lib/ad_gear/base.rb +169 -0
- data/lib/ad_gear/click.rb +4 -0
- data/lib/ad_gear/config.rb +143 -0
- data/lib/ad_gear/core_ext.rb +18 -0
- data/lib/ad_gear/file.rb +4 -0
- data/lib/ad_gear/format.rb +4 -0
- data/lib/ad_gear/has_many_array.rb +84 -0
- data/lib/ad_gear/interaction.rb +4 -0
- data/lib/ad_gear/placement_membership.rb +5 -0
- data/lib/ad_gear/placement_rule.rb +5 -0
- data/lib/ad_gear/publisher.rb +7 -0
- data/lib/ad_gear/site.rb +6 -0
- data/lib/ad_gear/template.rb +4 -0
- data/lib/ad_gear/upload.rb +46 -0
- data/lib/ad_gear/variable.rb +4 -0
- data/lib/ad_gear/web_campaign.rb +6 -0
- data/lib/ad_gear/web_placement.rb +26 -0
- data/lib/ad_gear/xml_format.rb +35 -0
- data/lib/ad_gear.rb +108 -0
- data/test/ad_gear/ad_spot_test.rb +43 -0
- data/test/ad_gear/config_test.rb +114 -0
- data/test/ad_gear/placement_rule_test.rb +22 -0
- data/test/ad_gear/site_test.rb +69 -0
- data/test/ad_gear/upload_test.rb +58 -0
- data/test/ad_gear_test.rb +23 -0
- data/test/fixtures/access-denied-no-auth.txt +13 -0
- data/test/test_helper.rb +33 -0
- metadata +163 -0
data/lib/ad_gear.rb
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2009 François Beausoleil
|
3
|
+
# Copyright (c) 2009 Bloom Digital Platforms
|
4
|
+
#
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
# a copy of this software and associated documentation files (the
|
7
|
+
# "Software"), to deal in the Software without restriction, including
|
8
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
# the following conditions:
|
12
|
+
#
|
13
|
+
# The above copyright notice and this permission notice shall be
|
14
|
+
# included in all copies or substantial portions of the Software.
|
15
|
+
#
|
16
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
23
|
+
#++
|
24
|
+
|
25
|
+
require "active_support"
|
26
|
+
require "active_resource"
|
27
|
+
require "bigdecimal"
|
28
|
+
require "logger"
|
29
|
+
|
30
|
+
warn "You are using the plain jane version of ActiveResource. You could use Digest authentication if you used http://github.com/francois/rails/tree/ar_digest" unless ActiveResource::Base.respond_to?(:use_basic_authentication)
|
31
|
+
|
32
|
+
module AdGear
|
33
|
+
# AdGear's models superclass
|
34
|
+
autoload :Base, "ad_gear/base"
|
35
|
+
|
36
|
+
# AdGear models themselves
|
37
|
+
autoload :Advertiser, "ad_gear/advertiser"
|
38
|
+
autoload :Site, "ad_gear/site"
|
39
|
+
autoload :AdSpot, "ad_gear/ad_spot"
|
40
|
+
autoload :AdSpotMembership, "ad_gear/ad_spot_membership"
|
41
|
+
autoload :WebCampaign, "ad_gear/web_campaign"
|
42
|
+
autoload :Format, "ad_gear/format"
|
43
|
+
autoload :Upload, "ad_gear/upload"
|
44
|
+
autoload :Publisher, "ad_gear/publisher"
|
45
|
+
|
46
|
+
# Placements and it's dependencies
|
47
|
+
autoload :WebPlacement, "ad_gear/web_placement"
|
48
|
+
autoload :PlacementRule, "ad_gear/placement_rule"
|
49
|
+
autoload :PlacementMembership, "ad_gear/placement_membership"
|
50
|
+
|
51
|
+
# AdUnits and it's child models
|
52
|
+
autoload :AdUnit, "ad_gear/ad_unit"
|
53
|
+
autoload :AdUnitFile, "ad_gear/ad_unit_file"
|
54
|
+
autoload :AdUnitInteraction, "ad_gear/ad_unit_interaction"
|
55
|
+
autoload :AdUnitClick, "ad_gear/ad_unit_click"
|
56
|
+
autoload :AdUnitVariable, "ad_gear/ad_unit_variable"
|
57
|
+
|
58
|
+
# Templates and their dependencies, to know what child models are required
|
59
|
+
autoload :Template, "ad_gear/template"
|
60
|
+
autoload :File, "ad_gear/file"
|
61
|
+
autoload :Variable, "ad_gear/variable"
|
62
|
+
autoload :Click, "ad_gear/click"
|
63
|
+
autoload :Interaction, "ad_gear/interaction"
|
64
|
+
|
65
|
+
# Miscellaneous stuff
|
66
|
+
autoload :Config, "ad_gear/config"
|
67
|
+
autoload :XmlFormat, "ad_gear/xml_format"
|
68
|
+
autoload :HasManyArray, "ad_gear/has_many_array"
|
69
|
+
|
70
|
+
class UnsupportedOperation < RuntimeError; end
|
71
|
+
|
72
|
+
# Configures AdGear's ActiveResource models.
|
73
|
+
#
|
74
|
+
# NOTE: AdGear's client expects and uses Nokogiri instead of REXML.
|
75
|
+
# See http://rubyglasses.blogspot.com/2009/07/40-speedup-using-nokogiri.html#instructions
|
76
|
+
def self.config=(config)
|
77
|
+
@config = config
|
78
|
+
|
79
|
+
AdGear::Base.logger = config.logger
|
80
|
+
|
81
|
+
AdGear::Base.site = config.site
|
82
|
+
AdGear::Base.user = config.user
|
83
|
+
AdGear::Base.password = config.password
|
84
|
+
AdGear::Base.format = config.format
|
85
|
+
|
86
|
+
if AdGear::Base.respond_to?(:use_basic_authentication=)
|
87
|
+
AdGear::Base.use_basic_authentication = config.use_basic_authentication
|
88
|
+
end
|
89
|
+
|
90
|
+
if AdGear::Base.respond_to?(:use_digest_authentication=)
|
91
|
+
AdGear::Base.use_digest_authentication = config.use_digest_authentication
|
92
|
+
end
|
93
|
+
|
94
|
+
# TODO: Programatically determine if we can use Nokogiri
|
95
|
+
ActiveSupport::XmlMini.backend = "Nokogiri"
|
96
|
+
|
97
|
+
# Can't require before now, because our own method is overwritten
|
98
|
+
require "ad_gear/core_ext"
|
99
|
+
end
|
100
|
+
|
101
|
+
def self.config
|
102
|
+
@config
|
103
|
+
end
|
104
|
+
|
105
|
+
def self.logger
|
106
|
+
config.logger
|
107
|
+
end
|
108
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
require "ostruct"
|
3
|
+
|
4
|
+
class AdGear::AdSpotTest < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
super
|
7
|
+
AdGear.config = OpenStruct.new(:site => "http://test.host", :format => :xml)
|
8
|
+
end
|
9
|
+
|
10
|
+
def teardown
|
11
|
+
AdGear::Base.site = nil
|
12
|
+
super
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_embed_code_should_not_be_encoded
|
16
|
+
spot = AdGear::AdSpot.new(:id => 84, :name => "XLsuite", :format_id => 42, :embed_code => "some code")
|
17
|
+
|
18
|
+
doc = Nokogiri::XML(spot.encode)
|
19
|
+
xpath doc, "/ad-spot/embed-code" do |ns|
|
20
|
+
assert ns.empty?, doc
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_setting_format_sets_format_id_internally
|
25
|
+
format = stub("AdGear::Format", :id => 231)
|
26
|
+
|
27
|
+
spot = AdGear::AdSpot.new
|
28
|
+
spot.format = format
|
29
|
+
assert_equal 231, spot.attributes["format_id"], spot.attributes
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_instantiating_with_format_sets_format_id_internally
|
33
|
+
format = stub("AdGear::Format", :id => 231)
|
34
|
+
spot = AdGear::AdSpot.new(:format => format)
|
35
|
+
assert_equal 231, spot.attributes["format_id"], spot.attributes
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_setting_format_to_nil_sets_format_id_to_nil
|
39
|
+
spot = AdGear::AdSpot.new
|
40
|
+
spot.format = nil
|
41
|
+
assert_nil spot.attributes["format_id"]
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,114 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
require "tempfile"
|
3
|
+
require "stringio"
|
4
|
+
|
5
|
+
class AdGear::ConfigTest < Test::Unit::TestCase
|
6
|
+
should "read a file on disk when given a path" do
|
7
|
+
econf = {"site" => "http://whatever.com/", "user" => "francois", "password" => "many"}
|
8
|
+
Tempfile.open("config") do |io|
|
9
|
+
io.write econf.to_yaml
|
10
|
+
io.close
|
11
|
+
|
12
|
+
aconf = AdGear::Config.new(io.path)
|
13
|
+
assert_equal econf, aconf.to_hash
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
should "pass a file's content through ERB before evaluating configuration" do
|
18
|
+
conf = {"user" => "<%= :whoami %>"}
|
19
|
+
econf = {"user" => "whoami"}
|
20
|
+
Tempfile.open("config") do |io|
|
21
|
+
io.write conf.to_yaml
|
22
|
+
io.close
|
23
|
+
|
24
|
+
aconf = AdGear::Config.new(io.path)
|
25
|
+
assert_equal econf, aconf.to_hash
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
should "read a stream" do
|
30
|
+
econf = {"site" => "http://whatever.com/", "user" => "francois", "password" => "many"}
|
31
|
+
Tempfile.open("config") do |io|
|
32
|
+
io.write econf.to_yaml
|
33
|
+
io.rewind
|
34
|
+
|
35
|
+
aconf = AdGear::Config.new(io)
|
36
|
+
assert_equal econf, aconf.to_hash
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
should "read the specified env" do
|
41
|
+
econf = {"site" => "http://whatever.com/", "user" => "francois", "password" => "many"}
|
42
|
+
env = {"development" => econf}
|
43
|
+
aconf = AdGear::Config.new(StringIO.new(env.to_yaml), "development")
|
44
|
+
assert_equal econf, aconf.to_hash
|
45
|
+
end
|
46
|
+
|
47
|
+
should "raise a MissingEnvironmentSpecification when the file is empty" do
|
48
|
+
assert_raise AdGear::Config::MissingEnvironmentSpecification do
|
49
|
+
AdGear::Config.new(StringIO.new(""), "development")
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
should "raise a MissingEnvironmentSpecification when the env doesn't exist" do
|
54
|
+
econf = {"site" => "http://whatever.com/", "user" => "francois", "password" => "many"}
|
55
|
+
env = {"development" => econf}
|
56
|
+
|
57
|
+
assert_raise AdGear::Config::MissingEnvironmentSpecification do
|
58
|
+
AdGear::Config.new(StringIO.new(env.to_yaml), "test")
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
should "instantiate a Logger for STDOUT when the logger key is 'stdout'" do
|
63
|
+
Logger.expects(:new).with(STDOUT).returns(mock("Logger"))
|
64
|
+
AdGear::Config.new(StringIO.new({"logger" => "stdout"}.to_yaml))
|
65
|
+
end
|
66
|
+
|
67
|
+
should "instantiate a Logger for STDERR when the logger key is 'stderr'" do
|
68
|
+
Logger.expects(:new).with(STDERR).returns(mock("Logger"))
|
69
|
+
AdGear::Config.new("logger" => "stderr")
|
70
|
+
end
|
71
|
+
|
72
|
+
should "instantiate a Logger for the file named 'log/adgear.log' when the key is 'log/adgear.log'" do
|
73
|
+
Logger.expects(:new).with(File.join(Dir.pwd, "log/adgear.log")).returns(mock("Logger"))
|
74
|
+
AdGear::Config.new(StringIO.new({"logger" => File.join(Dir.pwd, "log/adgear.log")}.to_yaml))
|
75
|
+
end
|
76
|
+
|
77
|
+
should "pass the config file through ERB before using the values" do
|
78
|
+
conf = AdGear::Config.new(StringIO.new({"user" => "<%= :whoami %>"}.to_yaml))
|
79
|
+
assert_equal "whoami", conf.user
|
80
|
+
end
|
81
|
+
|
82
|
+
should "warn when the path to the logger is relative" do
|
83
|
+
config = AdGear::Config.new
|
84
|
+
config.expects(:warn)
|
85
|
+
config.logger = "development.log"
|
86
|
+
end
|
87
|
+
|
88
|
+
context "Given a configured AdGear::Config" do
|
89
|
+
setup do
|
90
|
+
conf = {"site" => "http://whatever.com/", "user" => "francois", "password" => "many", "use_basic_authentication" => false, "use_digest_authentication" => true}
|
91
|
+
@config = AdGear::Config.new(conf)
|
92
|
+
end
|
93
|
+
|
94
|
+
should "return the correct site from #site" do
|
95
|
+
assert_equal "http://whatever.com/", @config.site
|
96
|
+
end
|
97
|
+
|
98
|
+
should "return the correct user from #user" do
|
99
|
+
assert_equal "francois", @config.user
|
100
|
+
end
|
101
|
+
|
102
|
+
should "return the correct password from #password" do
|
103
|
+
assert_equal "many", @config.password
|
104
|
+
end
|
105
|
+
|
106
|
+
should "return the correct use_basic_authentication from #use_basic_authentication" do
|
107
|
+
assert_equal false, @config.use_basic_authentication
|
108
|
+
end
|
109
|
+
|
110
|
+
should "return the correct use_digest_authentication from #use_digest_authentication" do
|
111
|
+
assert_equal true, @config.use_digest_authentication
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class AdGear::PlacementRuleTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
super
|
6
|
+
AdGear.config = OpenStruct.new(:site => "http://test.host", :format => :xml)
|
7
|
+
end
|
8
|
+
|
9
|
+
def teardown
|
10
|
+
AdGear::Base.site = nil
|
11
|
+
super
|
12
|
+
end
|
13
|
+
|
14
|
+
should "polymorphically assign the bookable" do
|
15
|
+
publisher = AdGear::Publisher.new
|
16
|
+
publisher.stubs(:id).returns(42)
|
17
|
+
|
18
|
+
rule = AdGear::PlacementRule.new(:bookable => publisher)
|
19
|
+
assert_equal "Publisher", rule.bookable_type
|
20
|
+
assert_equal 42, rule.bookable_id
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
require "ostruct"
|
3
|
+
|
4
|
+
class AdGear::SiteTest < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
super
|
7
|
+
AdGear.config = OpenStruct.new(:site => "http://test.host", :format => :xml)
|
8
|
+
end
|
9
|
+
|
10
|
+
def teardown
|
11
|
+
AdGear::Base.site = nil
|
12
|
+
super
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_adding_an_ad_spot_puts_it_in_the_new_collection
|
16
|
+
site = AdGear::Site.new(:name => "XLsuite", :url => "http://xlsuite.com/", :publisher_id => 1)
|
17
|
+
site.ad_spots << AdGear::AdSpot.new(:format_id => 13, :name => "sidebar top")
|
18
|
+
|
19
|
+
doc = Nokogiri::XML(site.to_xml)
|
20
|
+
xpath doc, "/site/ad-spot-attributes/new/*/name" do |ns|
|
21
|
+
assert_equal 1, ns.length, doc
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_adding_an_existing_ad_spot_puts_it_in_the_old_collection
|
26
|
+
site = AdGear::Site.new(:name => "XLsuite", :url => "http://xlsuite.com/", :publisher_id => 1)
|
27
|
+
FakeWeb.register_uri(:get, "http://test.host/ad_spots/42.xml", :body => "<ad-spot><id>42</id><name>bla</name></ad-spot>")
|
28
|
+
site.ad_spots << AdGear::AdSpot.find(42)
|
29
|
+
|
30
|
+
doc = Nokogiri::XML(site.to_xml)
|
31
|
+
xpath doc, "/site/ad-spot-attributes/n42/name" do |ns|
|
32
|
+
assert_equal 1, ns.length, doc
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_instantiating_with_ad_spots_still_generates_ad_spots_in_the_new_collection
|
37
|
+
site = AdGear::Site.new(:name => "XLsuite",
|
38
|
+
:url => "http://xlsuite.com/",
|
39
|
+
:publisher_id => 1,
|
40
|
+
:ad_spots => [{:format_id => 13, :name => "sidebar top"}])
|
41
|
+
|
42
|
+
doc = Nokogiri::XML(site.to_xml)
|
43
|
+
xpath doc, "/site/ad-spot-attributes/new/*/name" do |ns|
|
44
|
+
assert_equal 1, ns.length, doc
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_adding_a_new_ad_spot_to_existing_ad_spots_adds_to_new_collection
|
49
|
+
site = AdGear::Site.new(:name => "XLsuite",
|
50
|
+
:url => "http://xlsuite.com/",
|
51
|
+
:publisher_id => 1,
|
52
|
+
:ad_spots => [{:format_id => 13, :name => "sidebar top"}])
|
53
|
+
site.ad_spots << AdGear::AdSpot.new(:format_id => 13, :name => "homepage bottom")
|
54
|
+
|
55
|
+
doc = Nokogiri::XML(site.to_xml)
|
56
|
+
xpath doc, "/site/ad-spot-attributes/new/*/name" do |ns|
|
57
|
+
assert_equal 2, ns.length, doc
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_embed_code_should_not_be_encoded
|
62
|
+
site = AdGear::Site.new(:id => 84, :name => "XLsuite", :url => "http://xlsuite.com/", :embed_code => "some code")
|
63
|
+
|
64
|
+
doc = Nokogiri::XML(site.encode)
|
65
|
+
xpath doc, "/site/embed-code" do |ns|
|
66
|
+
assert ns.empty?, doc
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class AdGear::UploadTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
super
|
6
|
+
AdGear.config = OpenStruct.new(:site => "http://test.host/api", :format => :xml)
|
7
|
+
end
|
8
|
+
|
9
|
+
def teardown
|
10
|
+
AdGear::Base.site = nil
|
11
|
+
super
|
12
|
+
end
|
13
|
+
|
14
|
+
should "upload the data using RestClient" do
|
15
|
+
xml = Builder::XmlMarkup.new
|
16
|
+
xml.upload do
|
17
|
+
xml.id 42
|
18
|
+
end
|
19
|
+
|
20
|
+
uri = URI.parse("http://test.host/api/uploads.xml")
|
21
|
+
RestClient.expects(:post).with(uri.to_s, all_of(has_key("upload[uploaded_data]"), has_key("upload[filename]")), {}).returns(xml.target!)
|
22
|
+
upload = AdGear::Upload.new(:filename => "test/fixtures/access-denied-no-auth.txt")
|
23
|
+
upload.save
|
24
|
+
assert_equal 42, upload.id.to_i
|
25
|
+
end
|
26
|
+
|
27
|
+
should "raise an exception when calling #update_attribute" do
|
28
|
+
assert_raise(AdGear::UnsupportedOperation) do
|
29
|
+
AdGear::Upload.new.update_attribute
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
should "raise an exception when calling #update_attributes" do
|
34
|
+
assert_raise(AdGear::UnsupportedOperation) do
|
35
|
+
AdGear::Upload.new.update_attributes
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
should "retry with Digest authentication when RestClient::Unauthorized is raised" do
|
40
|
+
xml = Builder::XmlMarkup.new
|
41
|
+
xml.upload do
|
42
|
+
xml.id 42
|
43
|
+
end
|
44
|
+
|
45
|
+
uri = URI.parse("http://test.host/api/uploads.xml")
|
46
|
+
|
47
|
+
ActiveResource::Digest.stubs(:authenticate).returns("Calculated Authorization Header")
|
48
|
+
headers = {"www-authenticate" => ""}
|
49
|
+
unauthorized_response = stub("response", :[] => "Server Generated WWW-Authenticate Header")
|
50
|
+
|
51
|
+
RestClient.stubs(:post).with(anything, anything, {}).raises(RestClient::Unauthorized.new(unauthorized_response))
|
52
|
+
RestClient.expects(:post).with(anything, anything, has_key("Authorization")).returns(xml.target!)
|
53
|
+
|
54
|
+
upload = AdGear::Upload.new(:filename => "test/fixtures/access-denied-no-auth.txt")
|
55
|
+
upload.save
|
56
|
+
assert_equal 42, upload.id.to_i
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
require "ostruct"
|
3
|
+
|
4
|
+
class AdGearTest < Test::Unit::TestCase
|
5
|
+
should "configure AdGear::Base when calling #config= with config object" do
|
6
|
+
assert_nil AdGear::Base.site
|
7
|
+
|
8
|
+
AdGear.config = OpenStruct.new(:site => "http://bla.com", :user => "user", :password => "test", :format => :xml)
|
9
|
+
|
10
|
+
assert_equal "http://bla.com", AdGear::Base.site.to_s
|
11
|
+
assert_equal "user", AdGear::Base.user
|
12
|
+
assert_equal "test", AdGear::Base.password
|
13
|
+
end
|
14
|
+
|
15
|
+
should "override Array#to_xml to generate XML envelopes containing only class name" do
|
16
|
+
sites = [ AdGear::Site.new, AdGear::Site.new ]
|
17
|
+
|
18
|
+
doc = Nokogiri::XML(sites.to_xml)
|
19
|
+
xpath doc, "/sites/site" do |ns|
|
20
|
+
assert_equal 2, ns.length, doc
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
HTTP/1.1 401 Authorization Required
|
2
|
+
Date: Mon, 03 Aug 2009 20:06:42 GMT
|
3
|
+
Server: Apache/2.2.11 (Unix) mod_ssl/2.2.11 OpenSSL/0.9.7l DAV/2 Phusion_Passenger/2.2.2
|
4
|
+
X-Powered-By: Phusion Passenger (mod_rails/mod_rack) 2.2.2
|
5
|
+
WWW-Authenticate: Digest realm="AdGear API", qop="auth", algorithm=MD5, nonce="MTI0OTMzMDAwMjphN2NkNGU0YmUwZDQ5MjhhZjYzNzA4NzZiNjA4YTU0Ng==", opaque="a21e6002d2bd70e6dbeaca094ded4f93"
|
6
|
+
X-Runtime: 13
|
7
|
+
Cache-Control: no-cache
|
8
|
+
Set-Cookie: _AdGear_session=BAh7BjoPc2Vzc2lvbl9pZCIlYmE3NGNiZWIxN2ZhNmMyZDNjYWM5ZDEyMDFjMDhkZGI%3D--102443fec5480274e2163b6eb98ef2722c8f90cc; path=/; HttpOnly
|
9
|
+
Content-Length: 28
|
10
|
+
Status: 401
|
11
|
+
Content-Type: text/html; charset=utf-8
|
12
|
+
|
13
|
+
HTTP Digest: Access denied.
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
require "test/unit"
|
3
|
+
require "shoulda"
|
4
|
+
require "mocha"
|
5
|
+
require "fakeweb"
|
6
|
+
require "builder"
|
7
|
+
|
8
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
9
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
10
|
+
require "ad_gear"
|
11
|
+
|
12
|
+
begin
|
13
|
+
require "ruby-debug"
|
14
|
+
rescue LoadError
|
15
|
+
# Don't care, it's nice but not required
|
16
|
+
end
|
17
|
+
|
18
|
+
class Test::Unit::TestCase
|
19
|
+
BASE_URI = "http://api.adgear.com/services"
|
20
|
+
|
21
|
+
def setup
|
22
|
+
FakeWeb.allow_net_connect = false
|
23
|
+
end
|
24
|
+
|
25
|
+
def teardown
|
26
|
+
FakeWeb.allow_net_connect = true
|
27
|
+
end
|
28
|
+
|
29
|
+
protected
|
30
|
+
def xpath(doc, path)
|
31
|
+
yield doc.xpath(path)
|
32
|
+
end
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,163 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ad_gear_client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.8
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- "Fran\xC3\xA7ois Beausoleil"
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-11-13 00:00:00 -05:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: lsegal-yard
|
17
|
+
type: :development
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.2.3
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: mocha
|
27
|
+
type: :development
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.9.5
|
34
|
+
version:
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: activeresource
|
37
|
+
type: :runtime
|
38
|
+
version_requirement:
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">"
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: "2.0"
|
44
|
+
version:
|
45
|
+
- !ruby/object:Gem::Dependency
|
46
|
+
name: francois-rest-client
|
47
|
+
type: :runtime
|
48
|
+
version_requirement:
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: "1"
|
54
|
+
version:
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: nokogiri
|
57
|
+
type: :runtime
|
58
|
+
version_requirement:
|
59
|
+
version_requirements: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: "0"
|
64
|
+
version:
|
65
|
+
description:
|
66
|
+
email: francois@teksol.info
|
67
|
+
executables: []
|
68
|
+
|
69
|
+
extensions: []
|
70
|
+
|
71
|
+
extra_rdoc_files:
|
72
|
+
- LICENSE
|
73
|
+
- README.rdoc
|
74
|
+
files:
|
75
|
+
- .gitignore
|
76
|
+
- LICENSE
|
77
|
+
- README.rdoc
|
78
|
+
- Rakefile
|
79
|
+
- VERSION
|
80
|
+
- ad_gear_client.gemspec
|
81
|
+
- examples/.gitignore
|
82
|
+
- examples/ad_gear.yml.sample
|
83
|
+
- examples/create_campaign.rb
|
84
|
+
- examples/create_placement.rb
|
85
|
+
- examples/prelude.rb
|
86
|
+
- examples/read_write_site.rb
|
87
|
+
- examples/upload_file_to_ad_unit.rb
|
88
|
+
- lib/ad_gear.rb
|
89
|
+
- lib/ad_gear/ad_spot.rb
|
90
|
+
- lib/ad_gear/ad_spot_membership.rb
|
91
|
+
- lib/ad_gear/ad_unit.rb
|
92
|
+
- lib/ad_gear/ad_unit_click.rb
|
93
|
+
- lib/ad_gear/ad_unit_file.rb
|
94
|
+
- lib/ad_gear/ad_unit_interaction.rb
|
95
|
+
- lib/ad_gear/ad_unit_variable.rb
|
96
|
+
- lib/ad_gear/advertiser.rb
|
97
|
+
- lib/ad_gear/base.rb
|
98
|
+
- lib/ad_gear/click.rb
|
99
|
+
- lib/ad_gear/config.rb
|
100
|
+
- lib/ad_gear/core_ext.rb
|
101
|
+
- lib/ad_gear/file.rb
|
102
|
+
- lib/ad_gear/format.rb
|
103
|
+
- lib/ad_gear/has_many_array.rb
|
104
|
+
- lib/ad_gear/interaction.rb
|
105
|
+
- lib/ad_gear/placement_membership.rb
|
106
|
+
- lib/ad_gear/placement_rule.rb
|
107
|
+
- lib/ad_gear/publisher.rb
|
108
|
+
- lib/ad_gear/site.rb
|
109
|
+
- lib/ad_gear/template.rb
|
110
|
+
- lib/ad_gear/upload.rb
|
111
|
+
- lib/ad_gear/variable.rb
|
112
|
+
- lib/ad_gear/web_campaign.rb
|
113
|
+
- lib/ad_gear/web_placement.rb
|
114
|
+
- lib/ad_gear/xml_format.rb
|
115
|
+
- test/ad_gear/ad_spot_test.rb
|
116
|
+
- test/ad_gear/config_test.rb
|
117
|
+
- test/ad_gear/placement_rule_test.rb
|
118
|
+
- test/ad_gear/site_test.rb
|
119
|
+
- test/ad_gear/upload_test.rb
|
120
|
+
- test/ad_gear_test.rb
|
121
|
+
- test/fixtures/access-denied-no-auth.txt
|
122
|
+
- test/test_helper.rb
|
123
|
+
has_rdoc: true
|
124
|
+
homepage: http://github.com/francois/ad_gear_client
|
125
|
+
licenses: []
|
126
|
+
|
127
|
+
post_install_message:
|
128
|
+
rdoc_options:
|
129
|
+
- --charset=UTF-8
|
130
|
+
require_paths:
|
131
|
+
- lib
|
132
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
133
|
+
requirements:
|
134
|
+
- - ">="
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: "0"
|
137
|
+
version:
|
138
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
139
|
+
requirements:
|
140
|
+
- - ">="
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
version: "0"
|
143
|
+
version:
|
144
|
+
requirements: []
|
145
|
+
|
146
|
+
rubyforge_project: ad_gear_client
|
147
|
+
rubygems_version: 1.3.5
|
148
|
+
signing_key:
|
149
|
+
specification_version: 3
|
150
|
+
summary: A Ruby client for accessing AdGear http://bloomdigital.com/
|
151
|
+
test_files:
|
152
|
+
- test/ad_gear/ad_spot_test.rb
|
153
|
+
- test/ad_gear/config_test.rb
|
154
|
+
- test/ad_gear/placement_rule_test.rb
|
155
|
+
- test/ad_gear/site_test.rb
|
156
|
+
- test/ad_gear/upload_test.rb
|
157
|
+
- test/ad_gear_test.rb
|
158
|
+
- test/test_helper.rb
|
159
|
+
- examples/create_campaign.rb
|
160
|
+
- examples/create_placement.rb
|
161
|
+
- examples/prelude.rb
|
162
|
+
- examples/read_write_site.rb
|
163
|
+
- examples/upload_file_to_ad_unit.rb
|