vast 0.1 → 0.2

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/lib/vast.rb CHANGED
@@ -4,19 +4,22 @@ require 'vast/inline_ad'
4
4
  require 'vast/creative'
5
5
  require 'vast/linear_creative'
6
6
  require 'vast/mediafile'
7
+ require 'vast/companion_creative'
7
8
 
8
9
  # This module wraps VAST documents, as outlined by the IAB at http://www.iab.net/media/file/VAST-2_0-FINAL.pdf
9
10
  module VAST
10
11
  VAST_VERSION = 2.0
11
12
  VAST_SCHEMA_XSD_FILE = File.expand_path(File.join(File.dirname(__FILE__), 'vast_2.0.1.xsd'))
12
13
 
14
+ class VASTError < StandardError; end
15
+
13
16
  # Raised when parsing a VAST document that does not conform to the VAST spec XSD
14
- class InvalidDocumentError < StandardError; end
17
+ class InvalidDocumentError < VASTError; end
15
18
 
16
19
  # Raised when parsing a VAST ad node that is not complete
17
- class InvalidAdError < StandardError; end
20
+ class InvalidAdError < VASTError; end
18
21
 
19
22
  # Raised when parsing a VAST creative node that is not complete
20
- class InvalidCreativeError < StandardError; end
23
+ class InvalidCreativeError < VASTError; end
21
24
 
22
25
  end
@@ -0,0 +1,74 @@
1
+ module VAST
2
+ class CompanionCreative < Creative
3
+
4
+ def id
5
+ @source_node[:id]
6
+ end
7
+
8
+ # Width in pixels of companion
9
+ def width
10
+ @source_node[:width].to_i
11
+ end
12
+
13
+ # Height in pixels of companion
14
+ def height
15
+ @source_node[:height].to_i
16
+ end
17
+
18
+ # Width in pixels of expanding companion ad when in expanded state
19
+ def expanded_width
20
+ @source_node[:expandedWidth].to_i
21
+ end
22
+
23
+ # Height in pixels of expanding companion ad when in expanded state
24
+ def expanded_height
25
+ @source_node[:expandedHeight].to_i
26
+ end
27
+
28
+ # URI to open as destination page when user clicks on the video
29
+ def click_through_url
30
+ URI.parse @source_node.at('CompanionClickThrough').content
31
+ end
32
+
33
+ # Alternate text to be displayed when companion is rendered in HTML environment.
34
+ def alt_text
35
+ node = @source_node.at('AltText')
36
+ node.nil? ? nil : node.content
37
+ end
38
+
39
+ # Type of companion resource, returned as a symbol. Either :static, :iframe, or :html.
40
+ def resource_type
41
+ if @source_node.at('StaticResource')
42
+ :static
43
+ elsif @source_node.at('IFrameResource')
44
+ :iframe
45
+ elsif @source_node.at('HTMLResource')
46
+ :html
47
+ end
48
+ end
49
+
50
+ # Returns MIME type of static creative
51
+ def creative_type
52
+ if resource_type == :static
53
+ @source_node.at('StaticResource')[:creativeType]
54
+ end
55
+ end
56
+
57
+ # Returns URI for static or iframe resource
58
+ def resource_url
59
+ case resource_type
60
+ when :static
61
+ URI.parse @source_node.at('StaticResource').content
62
+ when :iframe
63
+ URI.parse @source_node.at('IFrameResource').content
64
+ end
65
+ end
66
+
67
+ # Returns HTML text for html resource
68
+ def resource_html
69
+ if resource_type == :html
70
+ @source_node.at('HTMLResource').content
71
+ end
72
+ end
73
+ end
74
+ end
data/lib/vast/creative.rb CHANGED
@@ -55,5 +55,4 @@ module VAST
55
55
  end
56
56
 
57
57
  class NonLinearCreative < Creative; end
58
- class CompanionCreative < Creative; end
59
58
  end
@@ -0,0 +1,37 @@
1
+ require 'test_helper'
2
+
3
+ class CompanionCreativeTest < Test::Unit::TestCase
4
+
5
+ def test_should_know_attributes
6
+ document_file = example_file('document_with_one_inline_ad.xml')
7
+ document = VAST::Document.parse!(document_file)
8
+ creative = document.inline_ads.first.companion_creatives.first
9
+
10
+ assert_equal "big_box", creative.id
11
+ assert_equal 300, creative.width
12
+ assert_equal 250, creative.height
13
+ assert_equal 600, creative.expanded_width
14
+ assert_equal 500, creative.expanded_height
15
+ assert_equal "http://www.tremormedia.com", creative.click_through_url.to_s
16
+ assert_equal "Display this instead of the ad", creative.alt_text
17
+ end
18
+
19
+ def test_should_know_static_resource
20
+ document_file = example_file('document_with_one_inline_ad.xml')
21
+ document = VAST::Document.parse!(document_file)
22
+ creative_with_static_resource = document.inline_ads.first.companion_creatives.first
23
+
24
+ assert_equal :static, creative_with_static_resource.resource_type
25
+ assert_equal "image/jpeg", creative_with_static_resource.creative_type
26
+ assert_equal "http://demo.tremormedia.com/proddev/vast/Blistex1.jpg", creative_with_static_resource.resource_url.to_s
27
+ end
28
+
29
+ def test_should_know_iframe_resource
30
+ document_file = example_file('document_with_one_inline_ad.xml')
31
+ document = VAST::Document.parse!(document_file)
32
+ creative_with_iframe_resource = document.inline_ads.first.companion_creatives.last
33
+
34
+ assert_equal :iframe, creative_with_iframe_resource.resource_type
35
+ assert_equal "http://ad3.liverail.com/util/companions.php", creative_with_iframe_resource.resource_url.to_s
36
+ end
37
+ end
@@ -49,20 +49,18 @@
49
49
  </Creative>
50
50
  <Creative AdID="601364-Companion">
51
51
  <CompanionAds>
52
- <Companion width="300" height="250">
52
+ <Companion id="big_box" width="300" height="250" expandedWidth="600" expandedHeight="500">
53
53
  <StaticResource creativeType="image/jpeg">http://demo.tremormedia.com/proddev/vast/Blistex1.jpg</StaticResource>
54
54
  <TrackingEvents>
55
55
  <Tracking event="creativeView">http://myTrackingURL/firstCompanionCreativeView</Tracking>
56
-
57
56
  </TrackingEvents>
58
-
59
57
  <CompanionClickThrough>http://www.tremormedia.com</CompanionClickThrough>
58
+ <AltText>Display this instead of the ad</AltText>
60
59
  </Companion>
61
60
  <Companion width="728" height="90">
62
- <StaticResource creativeType="image/jpeg">http://demo.tremormedia.com/proddev/vast/728x90_banner1.jpg</StaticResource>
61
+ <IFrameResource><![CDATA[http://ad3.liverail.com/util/companions.php]]></IFrameResource>
63
62
  <CompanionClickThrough>http://www.tremormedia.com</CompanionClickThrough>
64
63
  </Companion>
65
-
66
64
  </CompanionAds>
67
65
  </Creative>
68
66
  <Creative AdID="601365">
metadata CHANGED
@@ -4,8 +4,8 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 1
8
- version: "0.1"
7
+ - 2
8
+ version: "0.2"
9
9
  platform: ruby
10
10
  authors:
11
11
  - Chris Dinn
@@ -43,12 +43,14 @@ files:
43
43
  - lib/vast.rb
44
44
  - lib/vast_2.0.1.xsd
45
45
  - lib/vast/ad.rb
46
+ - lib/vast/companion_creative.rb
46
47
  - lib/vast/creative.rb
47
48
  - lib/vast/document.rb
48
49
  - lib/vast/inline_ad.rb
49
50
  - lib/vast/linear_creative.rb
50
51
  - lib/vast/mediafile.rb
51
52
  - test/ad_test.rb
53
+ - test/companion_creative_test.rb
52
54
  - test/creative_test.rb
53
55
  - test/document_test.rb
54
56
  - test/inline_ad_test.rb