francois-ad_gear_client 0.2.0 → 0.3.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.
data/.gitignore CHANGED
@@ -3,3 +3,4 @@
3
3
  coverage
4
4
  pkg
5
5
  doc
6
+ *.log
data/README.rdoc CHANGED
@@ -6,10 +6,48 @@ AdGear::Client is a client for accessing AdGear's RESTian web service.
6
6
 
7
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
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
+
9
45
  == Dependencies
10
46
 
11
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.
12
48
 
49
+ This gem also requires the francois-rest-client gem, for file upload support.
50
+
13
51
  == Copyright
14
52
 
15
53
  Copyright (c) 2009 François Beausoleil.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.3.1
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{ad_gear_client}
5
- s.version = "0.2.0"
5
+ s.version = "0.3.1"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
- s.authors = ["François Beausoleil"]
9
- s.date = %q{2009-09-02}
8
+ s.authors = ["Fran\303\247ois Beausoleil"]
9
+ s.date = %q{2009-09-15}
10
10
  s.email = %q{francois@teksol.info}
11
11
  s.extra_rdoc_files = [
12
12
  "LICENSE",
@@ -35,9 +35,9 @@ Gem::Specification.new do |s|
35
35
  "lib/ad_gear/ad_unit_variable.rb",
36
36
  "lib/ad_gear/advertiser.rb",
37
37
  "lib/ad_gear/base.rb",
38
- "lib/ad_gear/campaign.rb",
39
38
  "lib/ad_gear/click.rb",
40
39
  "lib/ad_gear/config.rb",
40
+ "lib/ad_gear/core_ext.rb",
41
41
  "lib/ad_gear/file.rb",
42
42
  "lib/ad_gear/format.rb",
43
43
  "lib/ad_gear/has_many_array.rb",
@@ -45,13 +45,13 @@ Gem::Specification.new do |s|
45
45
  "lib/ad_gear/placement_membership.rb",
46
46
  "lib/ad_gear/placement_rule.rb",
47
47
  "lib/ad_gear/publisher.rb",
48
- "lib/ad_gear/publisher_placement.rb",
49
48
  "lib/ad_gear/site.rb",
50
49
  "lib/ad_gear/template.rb",
51
50
  "lib/ad_gear/upload.rb",
52
51
  "lib/ad_gear/variable.rb",
52
+ "lib/ad_gear/web_campaign.rb",
53
+ "lib/ad_gear/web_placement.rb",
53
54
  "lib/ad_gear/xml_format.rb",
54
- "lib/core_ext.rb",
55
55
  "test/ad_gear/ad_spot_test.rb",
56
56
  "test/ad_gear/config_test.rb",
57
57
  "test/ad_gear/placement_rule_test.rb",
@@ -61,12 +61,11 @@ Gem::Specification.new do |s|
61
61
  "test/fixtures/access-denied-no-auth.txt",
62
62
  "test/test_helper.rb"
63
63
  ]
64
- s.has_rdoc = true
65
64
  s.homepage = %q{http://github.com/francois/ad_gear_client}
66
65
  s.rdoc_options = ["--charset=UTF-8"]
67
66
  s.require_paths = ["lib"]
68
67
  s.rubyforge_project = %q{ad_gear_client}
69
- s.rubygems_version = %q{1.3.1}
68
+ s.rubygems_version = %q{1.3.5}
70
69
  s.summary = %q{A Ruby client for accessing AdGear http://bloomdigital.com/}
71
70
  s.test_files = [
72
71
  "test/ad_gear/ad_spot_test.rb",
@@ -84,7 +83,7 @@ Gem::Specification.new do |s|
84
83
 
85
84
  if s.respond_to? :specification_version then
86
85
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
87
- s.specification_version = 2
86
+ s.specification_version = 3
88
87
 
89
88
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
90
89
  s.add_development_dependency(%q<lsegal-yard>, [">= 0.2.3"])
@@ -1,23 +1,28 @@
1
1
  require "prelude"
2
2
 
3
3
  begin
4
+ log "Getting publishers"
4
5
  publishers = AdGear::Publisher.find(:all)
5
6
  publisher = publishers.detect(&:active?)
6
7
  assert_not_nil publisher, "Missing a Publisher"
7
8
 
9
+ log "Getting formats"
8
10
  formats = AdGear::Format.find(:all)
9
11
  format = formats.first
10
12
  assert_not_nil format, "Missing a Format"
11
13
 
12
- campaigns = AdGear::Campaign.find(:all)
14
+ log "Getting WebCampaigns"
15
+ campaigns = AdGear::WebCampaign.find(:all)
13
16
  campaign = campaigns.first
14
17
  assert_not_nil campaign, "Missing a Campaign"
15
18
 
19
+ log "Getting AdUnits"
16
20
  ad_units = AdGear::AdUnit.find(:all)
17
21
  active_ad_units = ad_units.select(&:active?)
18
22
  assert active_ad_units.any?, "No active AdUnits available"
19
23
 
20
- placement = AdGear::PublisherPlacement.new(
24
+ log "Instantiating a rotating publisher placement"
25
+ placement = AdGear::WebPlacement.new(
21
26
  :campaign => campaign,
22
27
  :format => format,
23
28
  :selection_mechanism => "rotated",
@@ -29,9 +34,11 @@ begin
29
34
  :placement_memberships => [
30
35
  AdGear::PlacementMembership.new(:selection_attribute => "1", :ad_unit => active_ad_units[0]),
31
36
  AdGear::PlacementMembership.new(:selection_attribute => "2", :ad_unit => active_ad_units[1])])
37
+ log "Saving the placement"
32
38
  placement.save
33
39
 
34
- placement = AdGear::PublisherPlacement.new(
40
+ log "Instantiating a weighted publisher placment"
41
+ placement = AdGear::WebPlacement.new(
35
42
  :campaign => campaign,
36
43
  :format => format,
37
44
  :selection_mechanism => "weighted",
@@ -43,6 +50,7 @@ begin
43
50
  :placement_memberships => [
44
51
  AdGear::PlacementMembership.new(:selection_attribute => "30", :ad_unit => active_ad_units[0]),
45
52
  AdGear::PlacementMembership.new(:selection_attribute => "70", :ad_unit => active_ad_units[1])])
53
+ log "Saving the placement"
46
54
  placement.save
47
55
  rescue ActiveResource::BadRequest => e
48
56
  p ActiveResource::Formats[:xml].decode(e.response.body)
data/examples/prelude.rb CHANGED
@@ -15,4 +15,13 @@ end
15
15
  require "test/unit/assertions"
16
16
  include Test::Unit::Assertions
17
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
+
18
27
  AdGear.config = AdGear::Config.new("ad_gear.yml", "development")
@@ -1,39 +1,36 @@
1
1
  require "prelude"
2
2
 
3
3
  begin
4
+ log "Getting formats"
4
5
  formats = AdGear::Format.find(:all)
5
- p formats
6
6
 
7
+ log "Getting sites"
7
8
  sites = AdGear::Site.find(:all)
8
- p sites
9
9
 
10
+ log "Instantiating new Site"
10
11
  site = AdGear::Site.new(:name => "XLsuite", :url => "http://xlsuite.com/", :ad_spots => [{:format_id => formats.first.id, :name => "sidebar top"}])
11
- site.ad_spots << AdGear::AdSpot.new(:format_id => formats.first.id, :name => "homepage banner")
12
-
13
- p site.new?
14
- p site.save
15
- p site.new?
16
- p "Saved"
17
12
 
18
- pp site.embed_code
19
- pp site.ad_spots
20
-
21
- p site.ad_spots.class
13
+ log "banner AdSpot"
14
+ site.ad_spots << AdGear::AdSpot.new(:format_id => formats.first.id, :name => "homepage banner")
22
15
 
16
+ log "vertical AdSpot"
23
17
  site.ad_spots << AdGear::AdSpot.new(:format_id => formats.first.id, :name => "homepage vertical")
24
18
  site.ad_spots.detect {|as| as.name == "homepage banner"}.name = "home page banner"
25
19
  assert_equal 3, site.ad_spots.length, site.to_xml
26
20
 
21
+ log "Saving new Site"
22
+ assert site.save, "Could not save site"
23
+
24
+ log "Instantiating new AdSpot outside Site"
27
25
  ad_spot = AdGear::AdSpot.new(:format_id => formats.first.id, :name => "east", :site_id => site.id)
26
+ log "Saving"
28
27
  assert ad_spot.save, "Could not save new AdSpot"
28
+
29
+ log "Reloading site"
29
30
  site = AdGear::Site.find(site.id) # TODO: Support #reload
30
31
  assert site.ad_spots.detect {|as| as.name == "east"}, "Could not find new AdSpot linked to old site"
31
32
 
32
- puts site.to_xml
33
- site.save
34
-
35
- p "After PUT"
36
- assert_equal 3, site.ad_spots.length, site.to_xml
33
+ log "Done testing"
37
34
  rescue ActiveResource::BadRequest => e
38
35
  p ActiveResource::Formats[:xml].decode(e.response.body)
39
36
  end
@@ -10,6 +10,7 @@ require "restclient"
10
10
  p RestClient.version
11
11
  RestClient.log = "stdout"
12
12
 
13
+ log "Instantiating upload"
13
14
  upload = AdGear::Upload.new(:filename => File.dirname(__FILE__) + "/ad_gear.yml")
14
15
  if upload.save then
15
16
  p "uploaded successfully"
@@ -19,10 +20,15 @@ else
19
20
  exit 1
20
21
  end
21
22
 
23
+ log "Finding correct template"
22
24
  templates = AdGear::Template.find(:all)
23
25
  template = templates.detect {|template| template.name == "Javascript"}
26
+
27
+ log "Getting formats"
24
28
  formats = AdGear::Format.find(:all)
25
- campaigns = AdGear::Campaign.find(:all)
29
+
30
+ log "Getting WebCampaigns"
31
+ campaigns = AdGear::WebCampaign.find(:all)
26
32
 
27
33
  # Use Javascript, but forget to put the payload
28
34
  ad_unit = AdGear::AdUnit.new(:campaign => campaigns.first, :name => "BMW M5", :format => formats.first, :template => template.name)
@@ -32,9 +38,12 @@ ad_unit.ad_unit_clicks << AdGear::AdUnitClick.new(:name => "clickTAG", :ur
32
38
  puts "================="*8
33
39
  puts ad_unit.to_xml
34
40
  puts "================="*8
41
+
42
+ log "Attempt save, but forget to include the payload"
35
43
  assert_raise ActiveResource::BadRequest do
36
44
  ad_unit.save
37
45
  end
38
46
 
47
+ log "Save with payload"
39
48
  ad_unit.ad_unit_variables << AdGear::AdUnitVariable.new(:name => "payload", :value => "// whatever")
40
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
data/lib/ad_gear.rb CHANGED
@@ -35,13 +35,13 @@ module AdGear
35
35
  # AdGear models themselves
36
36
  autoload :Site, "ad_gear/site"
37
37
  autoload :AdSpot, "ad_gear/ad_spot"
38
- autoload :Campaign, "ad_gear/campaign"
38
+ autoload :WebCampaign, "ad_gear/web_campaign"
39
39
  autoload :Format, "ad_gear/format"
40
40
  autoload :Upload, "ad_gear/upload"
41
41
  autoload :Publisher, "ad_gear/publisher"
42
42
 
43
43
  # Placements and it's dependencies
44
- autoload :PublisherPlacement, "ad_gear/publisher_placement"
44
+ autoload :WebPlacement, "ad_gear/web_placement"
45
45
  autoload :PlacementRule, "ad_gear/placement_rule"
46
46
  autoload :PlacementMembership, "ad_gear/placement_membership"
47
47
 
@@ -90,10 +90,15 @@ module AdGear
90
90
 
91
91
  ActiveSupport::XmlMini.backend = "Nokogiri"
92
92
 
93
- require "core_ext"
93
+ # Can't require before now, because our own method is overwritten
94
+ require "ad_gear/core_ext"
94
95
  end
95
96
 
96
97
  def self.config
97
- config
98
+ @config
99
+ end
100
+
101
+ def self.logger
102
+ config.logger
98
103
  end
99
104
  end
File without changes
@@ -0,0 +1,4 @@
1
+ module AdGear
2
+ class WebCampaign < AdGear::Base
3
+ end
4
+ end
@@ -0,0 +1,26 @@
1
+ module AdGear
2
+ class WebPlacement < AdGear::Base
3
+ belongs_to :campaign, :format
4
+ has_many :placement_rules, :placement_memberships
5
+
6
+ def selection_mechanism
7
+ case value = attributes["selection_mechanism"]
8
+ when "R" ; "rotated"
9
+ when "W" ; "weighted"
10
+ else ; value
11
+ end
12
+ end
13
+
14
+ def selection_mechanism=(value)
15
+ case value
16
+ when /^r/i
17
+ attributes["selection_mechanism"] = "R"
18
+ when /^w/i
19
+ attributes["selection_mechanism"] = "W"
20
+ else
21
+ # Assign whatever we received, and hope for the best
22
+ attributes["selection_mechanism"] = value
23
+ end
24
+ end
25
+ end
26
+ end
@@ -1,6 +1,6 @@
1
1
  require "test_helper"
2
2
 
3
- class AdGear::PublisherPlacementTest < Test::Unit::TestCase
3
+ class AdGear::PlacementRuleTest < Test::Unit::TestCase
4
4
  def setup
5
5
  super
6
6
  AdGear.config = OpenStruct.new(:site => "http://test.host", :format => :xml)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: francois-ad_gear_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - "Fran\xC3\xA7ois Beausoleil"
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-09-02 00:00:00 -07:00
12
+ date: 2009-09-15 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -84,9 +84,9 @@ files:
84
84
  - lib/ad_gear/ad_unit_variable.rb
85
85
  - lib/ad_gear/advertiser.rb
86
86
  - lib/ad_gear/base.rb
87
- - lib/ad_gear/campaign.rb
88
87
  - lib/ad_gear/click.rb
89
88
  - lib/ad_gear/config.rb
89
+ - lib/ad_gear/core_ext.rb
90
90
  - lib/ad_gear/file.rb
91
91
  - lib/ad_gear/format.rb
92
92
  - lib/ad_gear/has_many_array.rb
@@ -94,13 +94,13 @@ files:
94
94
  - lib/ad_gear/placement_membership.rb
95
95
  - lib/ad_gear/placement_rule.rb
96
96
  - lib/ad_gear/publisher.rb
97
- - lib/ad_gear/publisher_placement.rb
98
97
  - lib/ad_gear/site.rb
99
98
  - lib/ad_gear/template.rb
100
99
  - lib/ad_gear/upload.rb
101
100
  - lib/ad_gear/variable.rb
101
+ - lib/ad_gear/web_campaign.rb
102
+ - lib/ad_gear/web_placement.rb
102
103
  - lib/ad_gear/xml_format.rb
103
- - lib/core_ext.rb
104
104
  - test/ad_gear/ad_spot_test.rb
105
105
  - test/ad_gear/config_test.rb
106
106
  - test/ad_gear/placement_rule_test.rb
@@ -109,8 +109,9 @@ files:
109
109
  - test/ad_gear_test.rb
110
110
  - test/fixtures/access-denied-no-auth.txt
111
111
  - test/test_helper.rb
112
- has_rdoc: true
112
+ has_rdoc: false
113
113
  homepage: http://github.com/francois/ad_gear_client
114
+ licenses:
114
115
  post_install_message:
115
116
  rdoc_options:
116
117
  - --charset=UTF-8
@@ -131,9 +132,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
131
132
  requirements: []
132
133
 
133
134
  rubyforge_project: ad_gear_client
134
- rubygems_version: 1.2.0
135
+ rubygems_version: 1.3.5
135
136
  signing_key:
136
- specification_version: 2
137
+ specification_version: 3
137
138
  summary: A Ruby client for accessing AdGear http://bloomdigital.com/
138
139
  test_files:
139
140
  - test/ad_gear/ad_spot_test.rb
@@ -1,4 +0,0 @@
1
- module AdGear
2
- class Campaign < AdGear::Base
3
- end
4
- end
@@ -1,26 +0,0 @@
1
- module AdGear
2
- class PublisherPlacement < AdGear::Base
3
- belongs_to :campaign, :format
4
- has_many :placement_rules, :placement_memberships
5
-
6
- def selection_mechanism
7
- case value = attributes["selection_mechanism"]
8
- when "R" ; "rotated"
9
- when "W" ; "weighted"
10
- else ; value
11
- end
12
- end
13
-
14
- def selection_mechanism=(value)
15
- case value
16
- when /^r/i
17
- attributes["selection_mechanism"] = "R"
18
- when /^w/i
19
- attributes["selection_mechanism"] = "W"
20
- else
21
- # Assign whatever we received, and hope for the best
22
- attributes["selection_mechanism"] = value
23
- end
24
- end
25
- end
26
- end