vast_analyzer 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 95231bcd4f18f2c61528dc8a3f8e37e52e8d41a7
4
+ data.tar.gz: 640ae6723ab95abda094640b611f7815559b2395
5
+ SHA512:
6
+ metadata.gz: 5689492655bd3f8a3031e18b6d606b427e9a18310a2911aeeb1f73687e49a86039252a27ddbaa0d2f9667530f315f07b8502774e12869dc970b764495873a318
7
+ data.tar.gz: 33cb4786e59ab981a441a235b881dff108f2b0895b2a17486f480174dc3879c54688b47491521d1eb297a51890175300def5da11f7a95639a7029b2021c34717
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ .DS_Store
11
+ .byebug_history
data/.gitmodules ADDED
File without changes
data/.rubocop.yml ADDED
@@ -0,0 +1,17 @@
1
+ inherit_from:
2
+ - style/ruby/style.yml
3
+
4
+ Rails:
5
+ Enabled: false
6
+
7
+ AllCops:
8
+ TargetRubyVersion: 2.3
9
+
10
+ Documentation:
11
+ Enabled: false
12
+
13
+ Style/RaiseArgs:
14
+ EnforcedStyle: compact
15
+
16
+ ClassLength:
17
+ Max: 150
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.3.0
data/.travis.yml ADDED
@@ -0,0 +1 @@
1
+ language: ruby
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+ source 'https://rubygems.org'
3
+
4
+ # Specify your gem's dependencies in vast_analyzer.gemspec
5
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Marina Chirchikova
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,51 @@
1
+ ## Installation
2
+
3
+ Add this line to your application's Gemfile:
4
+
5
+ ```ruby
6
+ gem 'vast_analyzer'
7
+ ```
8
+
9
+ And then execute:
10
+
11
+ $ bundle
12
+
13
+ Or install it yourself as:
14
+
15
+ $ gem install vast_analyzer
16
+
17
+ ## Usage
18
+
19
+ Simply pass your xml vast url to the parser object to instantiate a parser linked to that vast:
20
+
21
+ ```ruby
22
+ result = VastAnalyzer::parse('https://www.vastexample.xml')
23
+ ```
24
+
25
+ You can then check attributes of the result:
26
+
27
+ ```ruby
28
+ result.vpaid_status
29
+ => 'flash_js_vpaid'
30
+
31
+ result.skippable?
32
+ => false
33
+ ```
34
+
35
+ Vpaid status will return one of four options: 'flash_js_vpaid', 'flash_vpaid', 'js_vpaid', 'neither'
36
+
37
+ ## Development
38
+
39
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
40
+
41
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
42
+
43
+ ## Contributing
44
+
45
+ Bug reports and pull requests are welcome on GitHub at https://github.com/marina101/vast-analyzer.
46
+
47
+
48
+ ## License
49
+
50
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
51
+
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+ require 'bundler/gem_tasks'
3
+ require 'rake/testtask'
4
+
5
+ Rake::TestTask.new(:test) do |t|
6
+ t.libs << 'test'
7
+ t.libs << 'lib'
8
+ t.test_files = FileList['test/**/*_test.rb']
9
+ end
10
+
11
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'vast_analyzer'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,105 @@
1
+ # frozen_string_literal: true
2
+ require 'vast_analyzer/version'
3
+ require 'vast_analyzer/errors'
4
+ require 'nokogiri'
5
+ require 'net/http'
6
+ require 'addressable/uri'
7
+
8
+ module VastAnalyzer
9
+
10
+ def self.parse(url, max_redirects: 5)
11
+ ParserResult.new(url)
12
+ end
13
+
14
+ class ParserResult
15
+ attr_reader :vast, :vast_version
16
+
17
+ def initialize(url, max_redirects: 5)
18
+ open_xml(url)
19
+ vast_root = @vast&.xpath('//VAST')
20
+ raise NotVastError.new("Not vast, url: #{url}") unless vast_root&.any?
21
+ unwrap(max_redirects) unless @vast.xpath('//VASTAdTagURI').empty?
22
+ @vast_version = vast_root.attr('version').value
23
+ end
24
+
25
+ def vpaid_status
26
+ if include_flash_vpaid? && include_js?
27
+ 'flash_js_vpaid'
28
+ elsif include_flash_vpaid?
29
+ 'flash_vpaid'
30
+ elsif include_js?
31
+ 'js_vpaid'
32
+ else
33
+ 'neither'
34
+ end
35
+ end
36
+
37
+ def skippable?
38
+ @skippable ||=
39
+ case @vast_version
40
+ when '2.0', '2.0.1'
41
+ !!@vast.xpath('//Tracking')&.any? { |track| track.attr('event') == 'skip' }
42
+ when '3.0'
43
+ !!@vast.xpath('//Linear').attr('skipoffset')
44
+ end
45
+ end
46
+
47
+ def mediafiles
48
+ @mediafiles ||= @vast.xpath('//MediaFile')&.map do |node|
49
+ h = node.to_h
50
+ h['url'] = node.content
51
+ h
52
+ end
53
+ end
54
+
55
+ private
56
+
57
+ def open_xml(url, limit: 2)
58
+ raise ArgumentError.new('Too many HTTP redirects') if limit == 0
59
+ uri = Addressable::URI.parse(url)
60
+ response = Net::HTTP.get_response(uri)
61
+ case response
62
+ when Net::HTTPSuccess
63
+ @vast = Nokogiri::XML(response.body){ |config| config.noblanks }
64
+ when Net::HTTPRedirection
65
+ open_xml(response['location'], :limit => limit - 1)
66
+ else
67
+ raise ErrorOpeningUrl.new("Net/http error, #{response.code}, #{response.message}"\
68
+ "url: #{url}")
69
+ end
70
+ rescue Timeout::Error
71
+ raise UrlTimeoutError.new('Timeout error')
72
+ rescue StandardError => e
73
+ raise ErrorOpeningUrl.new("Error opening url, #{e.message}")
74
+ end
75
+
76
+ def unwrap(max_redirects)
77
+ max_redirects.times do
78
+ return if @vast.xpath('//VASTAdTagURI').empty?
79
+ begin
80
+ url = @vast.xpath('//VASTAdTagURI')[0].content
81
+ open_xml(url)
82
+ rescue
83
+ raise WrapperRedirectError.new('Error with opening the wrapper url')
84
+ end
85
+ end
86
+ raise WrapperDepthError.new('Error: Wrapper depth exceeds five redirects')
87
+ end
88
+
89
+ def include_flash_vpaid?
90
+ @include_flash ||= mediafiles.any? do |mediafile|
91
+ is_vpaid_api = mediafile['apiFramework'] == 'VPAID'
92
+ uses_flash = ['application/x-shockwave-flash', 'video/x-flv']
93
+ .include?(mediafile['type'])
94
+ is_vpaid_api && uses_flash
95
+ end
96
+ end
97
+
98
+ def include_js?
99
+ @include_js ||= mediafiles.any? do |mediafile|
100
+ ['application/x-javascript', 'application/javascript'].include?(mediafile['type'])
101
+ end
102
+ end
103
+ end
104
+ private_constant :ParserResult
105
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+ module VastAnalyzer
3
+ class Error < StandardError; end
4
+ class ErrorOpeningUrl < Error; end
5
+ class WrapperRedirectError < Error; end
6
+ class NotVastError < Error; end
7
+ class WrapperDepthError < Error; end
8
+ class UrlTimeoutError < Error; end
9
+ class ErrorWithHttp < Error; end
10
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+ module VastAnalyzer
3
+ VERSION = '1.0.2'
4
+ end
@@ -0,0 +1,43 @@
1
+ # coding: utf-8
2
+ # frozen_string_literal: true
3
+ lib = File.expand_path('../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'vast_analyzer/version'
6
+
7
+ Gem::Specification.new 'vast_analyzer', '1.0.4' do |spec|
8
+ spec.name = 'vast_analyzer'
9
+ spec.version = '1.0.4'
10
+ spec.authors = ['Marina Chirchikova']
11
+
12
+ spec.summary = 'A VAST analyzer that autodetects VPAID, flash, and js in VAST media files'
13
+ spec.homepage = 'https://github.com/marina101/vast-analyzer'
14
+ spec.license = 'MIT'
15
+
16
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
18
+ if spec.respond_to?(:metadata)
19
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
20
+ else
21
+ raise 'RubyGems 2.0 or newer is required to protect against ' \
22
+ 'public gem pushes.'
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
26
+ f.match(%r{^(test|spec|features)/})
27
+ end
28
+ spec.bindir = 'exe'
29
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ['lib']
31
+
32
+ spec.required_ruby_version = '>= 2.3.0'
33
+ spec.add_runtime_dependency 'bundler', '~> 1.13'
34
+ spec.add_runtime_dependency 'rake', '~> 10.0'
35
+ spec.add_development_dependency 'minitest', '~> 5.0'
36
+ spec.add_runtime_dependency 'nokogiri', '>= 1.8.1'
37
+ spec.add_development_dependency 'rubocop', '0.39.0'
38
+ spec.add_development_dependency 'vcr'
39
+ spec.add_development_dependency 'webmock'
40
+ spec.add_development_dependency 'minitest-vcr'
41
+ spec.add_development_dependency 'byebug'
42
+ spec.add_runtime_dependency 'addressable'
43
+ end
metadata ADDED
@@ -0,0 +1,199 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vast_analyzer
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.4
5
+ platform: ruby
6
+ authors:
7
+ - Marina Chirchikova
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-11-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.13'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.13'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: nokogiri
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: 1.8.1
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: 1.8.1
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '='
74
+ - !ruby/object:Gem::Version
75
+ version: 0.39.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '='
81
+ - !ruby/object:Gem::Version
82
+ version: 0.39.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: vcr
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: webmock
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: minitest-vcr
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: byebug
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: addressable
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ description:
154
+ email:
155
+ executables: []
156
+ extensions: []
157
+ extra_rdoc_files: []
158
+ files:
159
+ - ".gitignore"
160
+ - ".gitmodules"
161
+ - ".rubocop.yml"
162
+ - ".ruby-version"
163
+ - ".travis.yml"
164
+ - Gemfile
165
+ - LICENSE.txt
166
+ - README.md
167
+ - Rakefile
168
+ - bin/console
169
+ - bin/setup
170
+ - lib/vast_analyzer.rb
171
+ - lib/vast_analyzer/errors.rb
172
+ - lib/vast_analyzer/version.rb
173
+ - vast_analyzer.gemspec
174
+ homepage: https://github.com/marina101/vast-analyzer
175
+ licenses:
176
+ - MIT
177
+ metadata:
178
+ allowed_push_host: https://rubygems.org
179
+ post_install_message:
180
+ rdoc_options: []
181
+ require_paths:
182
+ - lib
183
+ required_ruby_version: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ">="
186
+ - !ruby/object:Gem::Version
187
+ version: 2.3.0
188
+ required_rubygems_version: !ruby/object:Gem::Requirement
189
+ requirements:
190
+ - - ">="
191
+ - !ruby/object:Gem::Version
192
+ version: '0'
193
+ requirements: []
194
+ rubyforge_project:
195
+ rubygems_version: 2.5.1
196
+ signing_key:
197
+ specification_version: 4
198
+ summary: A VAST analyzer that autodetects VPAID, flash, and js in VAST media files
199
+ test_files: []