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.
Files changed (49) hide show
  1. data/.gitignore +6 -0
  2. data/LICENSE +21 -0
  3. data/README.rdoc +55 -0
  4. data/Rakefile +132 -0
  5. data/VERSION +1 -0
  6. data/ad_gear_client.gemspec +114 -0
  7. data/examples/.gitignore +1 -0
  8. data/examples/ad_gear.yml.sample +8 -0
  9. data/examples/create_campaign.rb +23 -0
  10. data/examples/create_placement.rb +57 -0
  11. data/examples/prelude.rb +27 -0
  12. data/examples/read_write_site.rb +36 -0
  13. data/examples/upload_file_to_ad_unit.rb +49 -0
  14. data/lib/ad_gear/ad_spot.rb +7 -0
  15. data/lib/ad_gear/ad_spot_membership.rb +5 -0
  16. data/lib/ad_gear/ad_unit.rb +17 -0
  17. data/lib/ad_gear/ad_unit_click.rb +5 -0
  18. data/lib/ad_gear/ad_unit_file.rb +6 -0
  19. data/lib/ad_gear/ad_unit_interaction.rb +5 -0
  20. data/lib/ad_gear/ad_unit_variable.rb +5 -0
  21. data/lib/ad_gear/advertiser.rb +4 -0
  22. data/lib/ad_gear/base.rb +169 -0
  23. data/lib/ad_gear/click.rb +4 -0
  24. data/lib/ad_gear/config.rb +143 -0
  25. data/lib/ad_gear/core_ext.rb +18 -0
  26. data/lib/ad_gear/file.rb +4 -0
  27. data/lib/ad_gear/format.rb +4 -0
  28. data/lib/ad_gear/has_many_array.rb +84 -0
  29. data/lib/ad_gear/interaction.rb +4 -0
  30. data/lib/ad_gear/placement_membership.rb +5 -0
  31. data/lib/ad_gear/placement_rule.rb +5 -0
  32. data/lib/ad_gear/publisher.rb +7 -0
  33. data/lib/ad_gear/site.rb +6 -0
  34. data/lib/ad_gear/template.rb +4 -0
  35. data/lib/ad_gear/upload.rb +46 -0
  36. data/lib/ad_gear/variable.rb +4 -0
  37. data/lib/ad_gear/web_campaign.rb +6 -0
  38. data/lib/ad_gear/web_placement.rb +26 -0
  39. data/lib/ad_gear/xml_format.rb +35 -0
  40. data/lib/ad_gear.rb +108 -0
  41. data/test/ad_gear/ad_spot_test.rb +43 -0
  42. data/test/ad_gear/config_test.rb +114 -0
  43. data/test/ad_gear/placement_rule_test.rb +22 -0
  44. data/test/ad_gear/site_test.rb +69 -0
  45. data/test/ad_gear/upload_test.rb +58 -0
  46. data/test/ad_gear_test.rb +23 -0
  47. data/test/fixtures/access-denied-no-auth.txt +13 -0
  48. data/test/test_helper.rb +33 -0
  49. metadata +163 -0
data/.gitignore ADDED
@@ -0,0 +1,6 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ pkg
5
+ doc
6
+ *.log
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ Copyright (c) 2009 François Beausoleil
2
+ Copyright (c) 2009 Bloom Digital Platforms
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.
data/README.rdoc ADDED
@@ -0,0 +1,55 @@
1
+ = ad_gear_client
2
+
3
+ This gem is Ruby 1.8.6, Ruby 1.8.7, Ruby 1.9 and JRuby 1.3 compatible.
4
+
5
+ AdGear::Client is a client for accessing AdGear's RESTian web service.
6
+
7
+ AdGear is a product of Bloom Digital Platforms, a Montreal-based company founded in 2008. Through the AdGear family of products Bloom provides advertising management solutions to publishers, ad networks and platform developers looking to monetize their audiences.
8
+
9
+ == Getting Started
10
+
11
+ Create a config file, such as config/ad_gear.yml
12
+
13
+ # Sample ad_gear.yml configuration file. This file uses the same environment specifications as Rails, but they are actually optional
14
+ development: &defaults
15
+ site: http://adgear.local/api
16
+ user: francois
17
+ password: 94457f97dd3aa153c05257104e59a90f41a8110184cdefc8e52e4e295e48a782
18
+ use_basic_authentication: false
19
+ use_digest_authentication: true
20
+
21
+ # This is RestClient's logger support
22
+ logger: STDERR
23
+
24
+ test:
25
+ <<: *defaults
26
+
27
+ production:
28
+ <<: *defaults
29
+ site: http://admin.adgear.com/api
30
+ user: francois
31
+ password: 0
32
+ logger: log/ad_gear.log
33
+
34
+ Then, load the configuration:
35
+
36
+ require "ad_gear"
37
+
38
+ AdGear.config = AdGear::Config.new("path/to/ad_gear.yml", RAILS_ENV) # or whatever ENV you need
39
+
40
+ # You can start using the client here
41
+ formats = AdGear::Format.find(:all)
42
+
43
+ The environment is actually optional. If you do not specify it, the +site+, +user+, +password+ and other keys must exist at the root level of the file. If you specify a key, and the YAML file does not have that key at the root, an +AdGear::Config::MissingEnvironmentSpecification+ will be raised (fail early).
44
+
45
+ == Dependencies
46
+
47
+ AdGear::Client works best with the ActiveResource branch made by François Beausoleil, at http://github.com/francois/rails. This branch of ActiveResource supports Digest authentication. AdGear::Client will work wihout that branch, but without Digest authentication.
48
+
49
+ This gem also requires the francois-rest-client gem, for file upload support.
50
+
51
+ == Copyright
52
+
53
+ Copyright (c) 2009 François Beausoleil.
54
+ Copyright (c) 2009 Bloom Digital Platforms
55
+ See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,132 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'rake'
5
+
6
+ begin
7
+ require 'jeweler'
8
+ Jeweler::Tasks.new do |gem|
9
+ gem.name = "ad_gear_client"
10
+ gem.summary = %Q{A Ruby client for accessing AdGear http://bloomdigital.com/}
11
+ gem.email = "francois@teksol.info"
12
+ gem.homepage = "http://github.com/francois/ad_gear_client"
13
+ gem.authors = ["François Beausoleil"]
14
+ gem.rubyforge_project = "ad_gear_client"
15
+
16
+ gem.files.exclude ".document"
17
+
18
+ gem.add_development_dependency "lsegal-yard", ">= 0.2.3"
19
+ gem.add_development_dependency "mocha", ">= 0.9.5"
20
+
21
+ gem.add_dependency "activeresource", "> 2.0"
22
+ gem.add_dependency "francois-rest-client", "~> 1"
23
+ gem.add_dependency "nokogiri"
24
+ end
25
+
26
+ Jeweler::GemcutterTasks.new
27
+ rescue LoadError
28
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
29
+ end
30
+
31
+ require 'rake/testtask'
32
+ Rake::TestTask.new(:test) do |test|
33
+ test.libs << 'lib' << 'test'
34
+ test.libs << "vendor/activesupport/lib" if File.directory?("vendor/activesupport/lib")
35
+ test.libs << "vendor/activemodel/lib" if File.directory?("vendor/activemodel/lib")
36
+ test.libs << "vendor/activeresource/lib" if File.directory?("vendor/activeresource/lib")
37
+
38
+ test.pattern = 'test/**/*_test.rb'
39
+ test.verbose = true
40
+ end
41
+
42
+ begin
43
+ require 'rcov/rcovtask'
44
+ Rcov::RcovTask.new do |test|
45
+ test.libs << 'test'
46
+ test.pattern = 'test/**/*_test.rb'
47
+ test.verbose = true
48
+ end
49
+ rescue LoadError
50
+ task :rcov do
51
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
52
+ end
53
+ end
54
+
55
+
56
+ task :default => :test
57
+
58
+ module AdGear
59
+ if File.exist?("VERSION")
60
+ Version = File.read("VERSION")
61
+ else
62
+ Version = ""
63
+ end
64
+ end
65
+
66
+ begin
67
+ require "yard"
68
+ YARD::Rake::YardocTask.new(:doc) do |t|
69
+ t.options = ["--title", "AdGear::Client #{AdGear::Version}", "--readme", "README.rdoc"]
70
+ end
71
+
72
+ namespace :doc do
73
+ desc "Blow away all generated documentation"
74
+ task :clean do
75
+ rm_rf "doc"
76
+ end
77
+ end
78
+
79
+ task :doc => "doc:clean"
80
+ rescue LoadError
81
+ STDERR.puts "YARD is not available. In order to generate the best possible documentation, install YARD: sudo gem install yard"
82
+
83
+ require 'rake/rdoctask'
84
+ Rake::RDocTask.new(:doc) do |rdoc|
85
+ rdoc.rdoc_dir = "doc"
86
+ rdoc.title = "AdGear::Client #{AdGear::Version}"
87
+
88
+ rdoc.rdoc_files.include('README*')
89
+ rdoc.rdoc_files.include('lib/**/*.rb')
90
+ end
91
+ end
92
+
93
+ desc "Runs tests under all supported multiruby versions"
94
+ task :multi do
95
+ tests = FileList["test/**/*_test.rb"].map do |file|
96
+ 'require "%s"' % file
97
+ end.join("; ")
98
+ sh %{ multiruby -w -Ilib:test -e 'require "rubygems"; require "test/unit"; #{tests}' }
99
+ end
100
+
101
+ namespace :test do
102
+ desc "Do a live test against http://adgear.local/"
103
+ task :live do
104
+ base_url = ENV["BASE_URL"] || "http://adgear.local/api/services"
105
+ $:.unshift "lib"
106
+ require "ad_gear"
107
+
108
+ begin
109
+ client = AdGear::Client.new("francois", "94457f97dd3aa153c05257104e59a90f41a8110184cdefc8e52e4e295e48a782", :base_url => base_url, :logger => Logger.new(STDOUT))
110
+ p client.sites
111
+ rescue
112
+ puts $!
113
+ puts $!.backtrace
114
+ end
115
+ end
116
+ end
117
+
118
+ task :shell do
119
+ require "pp"
120
+ FileList["vendor/*/lib"].each do |path|
121
+ $LOAD_PATH.unshift path
122
+ end
123
+ $LOAD_PATH.unshift "lib"
124
+
125
+ require "ad_gear"
126
+ AdGear.config = AdGear::Config.new("examples/ad_gear.yml", "development")
127
+
128
+ require "irb"
129
+ ARGV.clear
130
+ include AdGear
131
+ IRB.start
132
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.3.8
@@ -0,0 +1,114 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{ad_gear_client}
8
+ s.version = "0.3.8"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Fran\303\247ois Beausoleil"]
12
+ s.date = %q{2009-11-13}
13
+ s.email = %q{francois@teksol.info}
14
+ s.extra_rdoc_files = [
15
+ "LICENSE",
16
+ "README.rdoc"
17
+ ]
18
+ s.files = [
19
+ ".gitignore",
20
+ "LICENSE",
21
+ "README.rdoc",
22
+ "Rakefile",
23
+ "VERSION",
24
+ "ad_gear_client.gemspec",
25
+ "examples/.gitignore",
26
+ "examples/ad_gear.yml.sample",
27
+ "examples/create_campaign.rb",
28
+ "examples/create_placement.rb",
29
+ "examples/prelude.rb",
30
+ "examples/read_write_site.rb",
31
+ "examples/upload_file_to_ad_unit.rb",
32
+ "lib/ad_gear.rb",
33
+ "lib/ad_gear/ad_spot.rb",
34
+ "lib/ad_gear/ad_spot_membership.rb",
35
+ "lib/ad_gear/ad_unit.rb",
36
+ "lib/ad_gear/ad_unit_click.rb",
37
+ "lib/ad_gear/ad_unit_file.rb",
38
+ "lib/ad_gear/ad_unit_interaction.rb",
39
+ "lib/ad_gear/ad_unit_variable.rb",
40
+ "lib/ad_gear/advertiser.rb",
41
+ "lib/ad_gear/base.rb",
42
+ "lib/ad_gear/click.rb",
43
+ "lib/ad_gear/config.rb",
44
+ "lib/ad_gear/core_ext.rb",
45
+ "lib/ad_gear/file.rb",
46
+ "lib/ad_gear/format.rb",
47
+ "lib/ad_gear/has_many_array.rb",
48
+ "lib/ad_gear/interaction.rb",
49
+ "lib/ad_gear/placement_membership.rb",
50
+ "lib/ad_gear/placement_rule.rb",
51
+ "lib/ad_gear/publisher.rb",
52
+ "lib/ad_gear/site.rb",
53
+ "lib/ad_gear/template.rb",
54
+ "lib/ad_gear/upload.rb",
55
+ "lib/ad_gear/variable.rb",
56
+ "lib/ad_gear/web_campaign.rb",
57
+ "lib/ad_gear/web_placement.rb",
58
+ "lib/ad_gear/xml_format.rb",
59
+ "test/ad_gear/ad_spot_test.rb",
60
+ "test/ad_gear/config_test.rb",
61
+ "test/ad_gear/placement_rule_test.rb",
62
+ "test/ad_gear/site_test.rb",
63
+ "test/ad_gear/upload_test.rb",
64
+ "test/ad_gear_test.rb",
65
+ "test/fixtures/access-denied-no-auth.txt",
66
+ "test/test_helper.rb"
67
+ ]
68
+ s.homepage = %q{http://github.com/francois/ad_gear_client}
69
+ s.rdoc_options = ["--charset=UTF-8"]
70
+ s.require_paths = ["lib"]
71
+ s.rubyforge_project = %q{ad_gear_client}
72
+ s.rubygems_version = %q{1.3.5}
73
+ s.summary = %q{A Ruby client for accessing AdGear http://bloomdigital.com/}
74
+ s.test_files = [
75
+ "test/ad_gear/ad_spot_test.rb",
76
+ "test/ad_gear/config_test.rb",
77
+ "test/ad_gear/placement_rule_test.rb",
78
+ "test/ad_gear/site_test.rb",
79
+ "test/ad_gear/upload_test.rb",
80
+ "test/ad_gear_test.rb",
81
+ "test/test_helper.rb",
82
+ "examples/create_campaign.rb",
83
+ "examples/create_placement.rb",
84
+ "examples/prelude.rb",
85
+ "examples/read_write_site.rb",
86
+ "examples/upload_file_to_ad_unit.rb"
87
+ ]
88
+
89
+ if s.respond_to? :specification_version then
90
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
91
+ s.specification_version = 3
92
+
93
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
94
+ s.add_development_dependency(%q<lsegal-yard>, [">= 0.2.3"])
95
+ s.add_development_dependency(%q<mocha>, [">= 0.9.5"])
96
+ s.add_runtime_dependency(%q<activeresource>, ["> 2.0"])
97
+ s.add_runtime_dependency(%q<francois-rest-client>, ["~> 1"])
98
+ s.add_runtime_dependency(%q<nokogiri>, [">= 0"])
99
+ else
100
+ s.add_dependency(%q<lsegal-yard>, [">= 0.2.3"])
101
+ s.add_dependency(%q<mocha>, [">= 0.9.5"])
102
+ s.add_dependency(%q<activeresource>, ["> 2.0"])
103
+ s.add_dependency(%q<francois-rest-client>, ["~> 1"])
104
+ s.add_dependency(%q<nokogiri>, [">= 0"])
105
+ end
106
+ else
107
+ s.add_dependency(%q<lsegal-yard>, [">= 0.2.3"])
108
+ s.add_dependency(%q<mocha>, [">= 0.9.5"])
109
+ s.add_dependency(%q<activeresource>, ["> 2.0"])
110
+ s.add_dependency(%q<francois-rest-client>, ["~> 1"])
111
+ s.add_dependency(%q<nokogiri>, [">= 0"])
112
+ end
113
+ end
114
+
@@ -0,0 +1 @@
1
+ ad_gear.yml
@@ -0,0 +1,8 @@
1
+ ---
2
+ development:
3
+ site: http://adgear.local/api
4
+ user: francois
5
+ password: 94457f97dd3aa153c05257104e59a90f41a8110184cdefc8e52e4e295e48a782
6
+ use_basic_authentication: false
7
+ use_digest_authentication: true
8
+ logger: STDERR
@@ -0,0 +1,23 @@
1
+ require "prelude"
2
+
3
+ begin
4
+ log "Searching for an existing advertiser"
5
+
6
+ advertiser = AdGear::Advertiser.find(:first)
7
+ if advertiser.nil? then
8
+ log "Creating a new advertiser since none existed"
9
+ advertiser = AdGear::Advertiser.new(:name => "Coca-Cola")
10
+ advertiser.save
11
+ end
12
+
13
+ log "Creating campaign"
14
+ wc = AdGear::WebCampaign.new(:name => "Coca-Cola is Rich",
15
+ :default_start_at => 10.days.from_now,
16
+ :default_end_at => 30.days.from_now,
17
+ :advertiser => advertiser)
18
+ wc.save
19
+
20
+ log "Done testing"
21
+ rescue ActiveResource::BadRequest => e
22
+ p ActiveResource::Formats[:xml].decode(e.response.body)
23
+ end
@@ -0,0 +1,57 @@
1
+ require "prelude"
2
+
3
+ begin
4
+ log "Getting publishers"
5
+ publishers = AdGear::Publisher.find(:all)
6
+ publisher = publishers.detect(&:active?)
7
+ assert_not_nil publisher, "Missing a Publisher"
8
+
9
+ log "Getting formats"
10
+ formats = AdGear::Format.find(:all)
11
+ format = formats.first
12
+ assert_not_nil format, "Missing a Format"
13
+
14
+ log "Getting WebCampaigns"
15
+ campaigns = AdGear::WebCampaign.find(:all)
16
+ campaign = campaigns.first
17
+ assert_not_nil campaign, "Missing a Campaign"
18
+
19
+ log "Getting AdUnits"
20
+ ad_units = AdGear::AdUnit.find(:all)
21
+ active_ad_units = ad_units.select(&:active?)
22
+ assert active_ad_units.any?, "No active AdUnits available"
23
+
24
+ log "Instantiating a rotating publisher placement"
25
+ placement = AdGear::WebPlacement.new(
26
+ :campaign => campaign,
27
+ :format => format,
28
+ :selection_mechanism => "rotated",
29
+ :name => "Snow Leopard for a week",
30
+ :start_at => 3.days.from_now,
31
+ :end_at => 7.days.from_now,
32
+ :placement_rules => [
33
+ AdGear::PlacementRule.new(:kind => "PlacementInclusion", :bookable => publisher)],
34
+ :placement_memberships => [
35
+ AdGear::PlacementMembership.new(:selection_attribute => "1", :ad_unit => active_ad_units[0]),
36
+ AdGear::PlacementMembership.new(:selection_attribute => "2", :ad_unit => active_ad_units[1])])
37
+ log "Saving the placement"
38
+ placement.save
39
+
40
+ log "Instantiating a weighted publisher placment"
41
+ placement = AdGear::WebPlacement.new(
42
+ :campaign => campaign,
43
+ :format => format,
44
+ :selection_mechanism => "weighted",
45
+ :name => "BMW M5",
46
+ :start_at => 3.days.from_now,
47
+ :end_at => 7.days.from_now,
48
+ :placement_rules => [
49
+ AdGear::PlacementRule.new(:kind => "PlacementInclusion", :bookable => publisher)],
50
+ :placement_memberships => [
51
+ AdGear::PlacementMembership.new(:selection_attribute => "30", :ad_unit => active_ad_units[0]),
52
+ AdGear::PlacementMembership.new(:selection_attribute => "70", :ad_unit => active_ad_units[1])])
53
+ log "Saving the placement"
54
+ placement.save
55
+ rescue ActiveResource::BadRequest => e
56
+ p ActiveResource::Formats[:xml].decode(e.response.body)
57
+ end
@@ -0,0 +1,27 @@
1
+ $:.unshift "../lib"
2
+ %w(activesupport activemodel activeresource rest-client).each do |lib|
3
+ $:.unshift "../vendor/#{lib}/lib" if File.directory?("../vendor/#{lib}/lib")
4
+ end
5
+
6
+ require "ad_gear"
7
+ require "pp"
8
+
9
+ begin
10
+ require "ruby-debug"
11
+ rescue LoadError
12
+ # Ignored under 1.9, JRuby
13
+ end
14
+
15
+ require "test/unit/assertions"
16
+ include Test::Unit::Assertions
17
+
18
+ def log(msg)
19
+ AdGear.logger.info msg.to_yaml
20
+ if msg.kind_of?(String) then
21
+ puts msg
22
+ else
23
+ pp msg
24
+ end
25
+ end
26
+
27
+ AdGear.config = AdGear::Config.new("ad_gear.yml", "development")
@@ -0,0 +1,36 @@
1
+ require "prelude"
2
+
3
+ begin
4
+ log "Getting formats"
5
+ formats = AdGear::Format.find(:all)
6
+
7
+ log "Getting sites"
8
+ sites = AdGear::Site.find(:all)
9
+
10
+ log "Instantiating new Site"
11
+ site = AdGear::Site.new(:name => "XLsuite", :url => "http://xlsuite.com/", :ad_spots => [{:format_id => formats.first.id, :name => "sidebar top"}])
12
+
13
+ log "banner AdSpot"
14
+ site.ad_spots << AdGear::AdSpot.new(:format_id => formats.first.id, :name => "homepage banner")
15
+
16
+ log "vertical AdSpot"
17
+ site.ad_spots << AdGear::AdSpot.new(:format_id => formats.first.id, :name => "homepage vertical")
18
+ site.ad_spots.detect {|as| as.name == "homepage banner"}.name = "home page banner"
19
+ assert_equal 3, site.ad_spots.length, site.to_xml
20
+
21
+ log "Saving new Site"
22
+ assert site.save, "Could not save site"
23
+
24
+ log "Instantiating new AdSpot outside Site"
25
+ ad_spot = AdGear::AdSpot.new(:format_id => formats.first.id, :name => "east", :site_id => site.id)
26
+ log "Saving"
27
+ assert ad_spot.save, "Could not save new AdSpot"
28
+
29
+ log "Reloading site"
30
+ site = AdGear::Site.find(site.id) # TODO: Support #reload
31
+ assert site.ad_spots.detect {|as| as.name == "east"}, "Could not find new AdSpot linked to old site"
32
+
33
+ log "Done testing"
34
+ rescue ActiveResource::BadRequest => e
35
+ p ActiveResource::Formats[:xml].decode(e.response.body)
36
+ end
@@ -0,0 +1,49 @@
1
+ require "prelude"
2
+
3
+ begin
4
+ gem "francois-rest-client", ">= 1.1.5"
5
+ rescue RuntimeError => e
6
+ p e
7
+ end
8
+
9
+ require "restclient"
10
+ p RestClient.version
11
+ RestClient.log = "stdout"
12
+
13
+ log "Instantiating upload"
14
+ upload = AdGear::Upload.new(:filename => File.dirname(__FILE__) + "/ad_gear.yml")
15
+ if upload.save then
16
+ p "uploaded successfully"
17
+ p upload.id
18
+ else
19
+ p upload.errors
20
+ exit 1
21
+ end
22
+
23
+ log "Finding correct template"
24
+ templates = AdGear::Template.find(:all)
25
+ template = templates.detect {|template| template.name == "Javascript"}
26
+
27
+ log "Getting formats"
28
+ formats = AdGear::Format.find(:all)
29
+
30
+ log "Getting WebCampaigns"
31
+ campaigns = AdGear::WebCampaign.find(:all)
32
+
33
+ # Use Javascript, but forget to put the payload
34
+ ad_unit = AdGear::AdUnit.new(:campaign => campaigns.first, :name => "BMW M5", :format => formats.first, :template => template.name)
35
+ ad_unit.ad_unit_files << AdGear::AdUnitFile.new(:name => "image", :upload => upload)
36
+ ad_unit.ad_unit_interactions << AdGear::AdUnitInteraction.new(:name => "something")
37
+ ad_unit.ad_unit_clicks << AdGear::AdUnitClick.new(:name => "clickTAG", :url => "http://somewhere.com/")
38
+ puts "================="*8
39
+ puts ad_unit.to_xml
40
+ puts "================="*8
41
+
42
+ log "Attempt save, but forget to include the payload"
43
+ assert_raise ActiveResource::BadRequest do
44
+ ad_unit.save
45
+ end
46
+
47
+ log "Save with payload"
48
+ ad_unit.ad_unit_variables << AdGear::AdUnitVariable.new(:name => "payload", :value => "// whatever")
49
+ assert ad_unit.save, "What? Now I'm providing the system-required variable, why am I still erroring out?\n" + ad_unit.errors.to_yaml
@@ -0,0 +1,7 @@
1
+ module AdGear
2
+ class AdSpot < AdGear::Base
3
+ ignorable_attributes :embed_code
4
+ belongs_to :format
5
+ has_many :ad_spot_memberships
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ module AdGear
2
+ class AdSpotMembership < AdGear::Base
3
+ belongs_to :ad_spot, :placement
4
+ end
5
+ end
@@ -0,0 +1,17 @@
1
+ module AdGear
2
+ class AdUnit < AdGear::Base
3
+ has_many :ad_unit_files, :ad_unit_clicks, :ad_unit_interactions, :ad_unit_variables
4
+ has_many :placement_memberships
5
+ ignorable_attributes :placements
6
+ belongs_to :web_campaign, :as => :campaign
7
+ belongs_to :format
8
+
9
+ def active?
10
+ state == "active"
11
+ end
12
+
13
+ def deleted?
14
+ state == "deleted"
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,5 @@
1
+ module AdGear
2
+ class AdUnitClick < AdGear::Base
3
+ belongs_to :ad_unit
4
+ end
5
+ end
@@ -0,0 +1,6 @@
1
+ module AdGear
2
+ class AdUnitFile < AdGear::Base
3
+ belongs_to :upload
4
+ belongs_to :ad_unit
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ module AdGear
2
+ class AdUnitInteraction < AdGear::Base
3
+ belongs_to :ad_unit
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module AdGear
2
+ class AdUnitVariable < AdGear::Base
3
+ belongs_to :ad_unit
4
+ end
5
+ end
@@ -0,0 +1,4 @@
1
+ module AdGear
2
+ class Advertiser < AdGear::Base
3
+ end
4
+ end