rb42-videos 1.0.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 8f348137ad540ee0a117c9dd429b730f5428d5c4274415656daeda41d402f22d
4
+ data.tar.gz: 6de82443a73eb4053c28b2a9a216b5133a0ee27ccaacbf9f34a624daea640d8b
5
+ SHA512:
6
+ metadata.gz: 730392a23c087a30531da32efec0b16d0146bf0e0531677bb90566365739c4e9bacf2341eb478772bf49a24eb6f707c525965e3493c746462112d7cb95e88be4
7
+ data.tar.gz: bb491dc7769c0374784356efd3dd0995edcdb6d8dadae7e2f80cef70a7623d0ed2b018aaaf4e1995e0c1db875a0b2ed66f44934d6f5317db4702d65327c98c39
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ .rspec_status
10
+ *.gem
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.5.0
5
+ before_install: gem install bundler -v 1.16.0
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source "https://rubygems.org"
2
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,111 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ rb42-videos (1.0.0)
5
+ actionview (~> 5)
6
+ httparty (~> 0.16)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ actionview (5.1.5)
12
+ activesupport (= 5.1.5)
13
+ builder (~> 3.1)
14
+ erubi (~> 1.4)
15
+ rails-dom-testing (~> 2.0)
16
+ rails-html-sanitizer (~> 1.0, >= 1.0.3)
17
+ activesupport (5.1.5)
18
+ concurrent-ruby (~> 1.0, >= 1.0.2)
19
+ i18n (~> 0.7)
20
+ minitest (~> 5.1)
21
+ tzinfo (~> 1.1)
22
+ builder (3.2.3)
23
+ coderay (1.1.2)
24
+ concurrent-ruby (1.0.5)
25
+ crass (1.0.3)
26
+ diff-lcs (1.3)
27
+ erubi (1.7.0)
28
+ ffi (1.9.23)
29
+ formatador (0.2.5)
30
+ guard (2.14.2)
31
+ formatador (>= 0.2.4)
32
+ listen (>= 2.7, < 4.0)
33
+ lumberjack (>= 1.0.12, < 2.0)
34
+ nenv (~> 0.1)
35
+ notiffany (~> 0.0)
36
+ pry (>= 0.9.12)
37
+ shellany (~> 0.0)
38
+ thor (>= 0.18.1)
39
+ guard-compat (1.2.1)
40
+ guard-rspec (4.7.3)
41
+ guard (~> 2.1)
42
+ guard-compat (~> 1.1)
43
+ rspec (>= 2.99.0, < 4.0)
44
+ html_validation (1.1.5)
45
+ httparty (0.16.0)
46
+ multi_xml (>= 0.5.2)
47
+ i18n (0.9.5)
48
+ concurrent-ruby (~> 1.0)
49
+ listen (3.1.5)
50
+ rb-fsevent (~> 0.9, >= 0.9.4)
51
+ rb-inotify (~> 0.9, >= 0.9.7)
52
+ ruby_dep (~> 1.2)
53
+ loofah (2.2.0)
54
+ crass (~> 1.0.2)
55
+ nokogiri (>= 1.5.9)
56
+ lumberjack (1.0.12)
57
+ method_source (0.9.0)
58
+ mini_portile2 (2.3.0)
59
+ minitest (5.11.3)
60
+ multi_xml (0.6.0)
61
+ nenv (0.3.0)
62
+ nokogiri (1.8.2)
63
+ mini_portile2 (~> 2.3.0)
64
+ notiffany (0.1.1)
65
+ nenv (~> 0.1)
66
+ shellany (~> 0.0)
67
+ pry (0.11.3)
68
+ coderay (~> 1.1.0)
69
+ method_source (~> 0.9.0)
70
+ rails-dom-testing (2.0.3)
71
+ activesupport (>= 4.2.0)
72
+ nokogiri (>= 1.6)
73
+ rails-html-sanitizer (1.0.3)
74
+ loofah (~> 2.0)
75
+ rake (10.5.0)
76
+ rb-fsevent (0.10.3)
77
+ rb-inotify (0.9.10)
78
+ ffi (>= 0.5.0, < 2)
79
+ rspec (3.7.0)
80
+ rspec-core (~> 3.7.0)
81
+ rspec-expectations (~> 3.7.0)
82
+ rspec-mocks (~> 3.7.0)
83
+ rspec-core (3.7.1)
84
+ rspec-support (~> 3.7.0)
85
+ rspec-expectations (3.7.0)
86
+ diff-lcs (>= 1.2.0, < 2.0)
87
+ rspec-support (~> 3.7.0)
88
+ rspec-mocks (3.7.0)
89
+ diff-lcs (>= 1.2.0, < 2.0)
90
+ rspec-support (~> 3.7.0)
91
+ rspec-support (3.7.1)
92
+ ruby_dep (1.5.0)
93
+ shellany (0.0.1)
94
+ thor (0.20.0)
95
+ thread_safe (0.3.6)
96
+ tzinfo (1.2.5)
97
+ thread_safe (~> 0.1)
98
+
99
+ PLATFORMS
100
+ ruby
101
+
102
+ DEPENDENCIES
103
+ bundler (~> 1.16)
104
+ guard-rspec (~> 4.7)
105
+ html_validation (~> 1.1)
106
+ rake (~> 10.0)
107
+ rb42-videos!
108
+ rspec (~> 3.0)
109
+
110
+ BUNDLED WITH
111
+ 1.16.0
data/Guardfile ADDED
@@ -0,0 +1,70 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ ## Uncomment and set this to only include directories you want to watch
5
+ # directories %w(app lib config test spec features) \
6
+ # .select{|d| Dir.exists?(d) ? d : UI.warning("Directory #{d} does not exist")}
7
+
8
+ ## Note: if you are using the `directories` clause above and you are not
9
+ ## watching the project directory ('.'), then you will want to move
10
+ ## the Guardfile to a watched dir and symlink it back, e.g.
11
+ #
12
+ # $ mkdir config
13
+ # $ mv Guardfile config/
14
+ # $ ln -s config/Guardfile .
15
+ #
16
+ # and, you'll have to watch "config/Guardfile" instead of "Guardfile"
17
+
18
+ # Note: The cmd option is now required due to the increasing number of ways
19
+ # rspec may be run, below are examples of the most common uses.
20
+ # * bundler: 'bundle exec rspec'
21
+ # * bundler binstubs: 'bin/rspec'
22
+ # * spring: 'bin/rspec' (This will use spring if running and you have
23
+ # installed the spring binstubs per the docs)
24
+ # * zeus: 'zeus rspec' (requires the server to be started separately)
25
+ # * 'just' rspec: 'rspec'
26
+
27
+ guard :rspec, cmd: "bundle exec rspec" do
28
+ require "guard/rspec/dsl"
29
+ dsl = Guard::RSpec::Dsl.new(self)
30
+
31
+ # Feel free to open issues for suggestions and improvements
32
+
33
+ # RSpec files
34
+ rspec = dsl.rspec
35
+ watch(rspec.spec_helper) { rspec.spec_dir }
36
+ watch(rspec.spec_support) { rspec.spec_dir }
37
+ watch(rspec.spec_files)
38
+
39
+ # Ruby files
40
+ ruby = dsl.ruby
41
+ dsl.watch_spec_files_for(ruby.lib_files)
42
+
43
+ # Rails files
44
+ rails = dsl.rails(view_extensions: %w(erb haml slim))
45
+ dsl.watch_spec_files_for(rails.app_files)
46
+ dsl.watch_spec_files_for(rails.views)
47
+
48
+ watch(rails.controllers) do |m|
49
+ [
50
+ rspec.spec.call("routing/#{m[1]}_routing"),
51
+ rspec.spec.call("controllers/#{m[1]}_controller"),
52
+ rspec.spec.call("acceptance/#{m[1]}")
53
+ ]
54
+ end
55
+
56
+ # Rails config changes
57
+ watch(rails.spec_helper) { rspec.spec_dir }
58
+ watch(rails.routes) { "#{rspec.spec_dir}/routing" }
59
+ watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" }
60
+
61
+ # Capybara features specs
62
+ watch(rails.view_dirs) { |m| rspec.spec.call("features/#{m[1]}") }
63
+ watch(rails.layouts) { |m| rspec.spec.call("features/#{m[1]}") }
64
+
65
+ # Turnip features and steps
66
+ watch(%r{^spec/acceptance/(.+)\.feature$})
67
+ watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) do |m|
68
+ Dir[File.join("**/#{m[1]}.feature")][0] || "spec/acceptance"
69
+ end
70
+ end
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
7
+
8
+ task :console do
9
+ sh 'bin/console'
10
+ end
data/bin/console ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "videos"
5
+
6
+ require "pry"
7
+ Pry.start
8
+
9
+ require "irb"
10
+ IRB.start(__FILE__)
data/lib/videos.rb ADDED
@@ -0,0 +1,19 @@
1
+ require "videos/version"
2
+ require "videos/uri"
3
+ require "videos/video"
4
+ require "videos/youtube"
5
+ require "videos/youtube"
6
+ require "videos/vimeo"
7
+
8
+ module Videos
9
+ PROVIDERS = {
10
+ 'youtube' => Videos::YouTube,
11
+ 'vimeo' => Videos::Vimeo,
12
+ 'video' => Videos::Video
13
+ }
14
+
15
+ def self.factory(uri_string,options={})
16
+ uri = Videos::URI.new(uri_string)
17
+ PROVIDERS[uri.provider].new(uri,options)
18
+ end
19
+ end
data/lib/videos/uri.rb ADDED
@@ -0,0 +1,45 @@
1
+ require 'uri'
2
+ require 'cgi'
3
+ require 'httparty'
4
+
5
+ class Videos::URI
6
+ PROVIDERS_BY_HOST = {
7
+ 'www.youtube.com' => 'youtube',
8
+ 'youtu.be' => 'youtube',
9
+ 'vimeo.com' => 'vimeo'
10
+ }
11
+
12
+ def initialize(uri)
13
+ @uri = uri
14
+ end
15
+
16
+ def obj
17
+ URI.parse(@uri)
18
+ end
19
+
20
+ def provider
21
+ PROVIDERS_BY_HOST.has_key?(obj.host) ? PROVIDERS_BY_HOST[obj.host] : 'video'
22
+ end
23
+
24
+ def query
25
+ CGI::parse(obj.query).to_h if obj.query
26
+ end
27
+
28
+ def content_type
29
+ @content_type ||= get_content_type
30
+ end
31
+
32
+ def to_s
33
+ obj.to_s
34
+ end
35
+
36
+ private
37
+
38
+ def get_content_type
39
+ begin
40
+ resp = HTTParty.head(@uri, follow_redirects: true)
41
+ resp.headers['content-type'].split(';')[0]
42
+ rescue
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,3 @@
1
+ module Videos
2
+ VERSION = "1.0.1"
3
+ end
@@ -0,0 +1,38 @@
1
+ require 'action_view'
2
+
3
+ class Videos::Video
4
+ include ActionView::Helpers::TagHelper
5
+ include ActionView::Helpers::TextHelper
6
+ include ActionView::Context
7
+ attr_reader :uri
8
+ attr_accessor :options
9
+
10
+ DEFAULTS = {
11
+ width: 640,
12
+ height: 360
13
+ }
14
+ def initialize(uri,options={})
15
+ @uri = uri
16
+ @options = DEFAULTS.merge(options)
17
+ end
18
+
19
+ def embed_code
20
+ content_tag(:video) do
21
+ concat(tag(:source, src: @uri.to_s, type: @uri.content_type))
22
+ concat(content_tag(:span, sorry_message, class: 'sorry'))
23
+ end
24
+ end
25
+ alias_method :to_html, :embed_code
26
+
27
+ def sorry_message
28
+ "I'm sorry; your browser doesn't support HTML5 video."
29
+ end
30
+
31
+ def width
32
+ @options[:width]
33
+ end
34
+
35
+ def height
36
+ @options[:height]
37
+ end
38
+ end
@@ -0,0 +1,27 @@
1
+ class Videos::Vimeo < Videos::Video
2
+ VIMEO_DEFAULTS = {
3
+ allowfullscreen: true
4
+ }
5
+
6
+ def initialize(uri,options={})
7
+ options = VIMEO_DEFAULTS.merge(options)
8
+ super(uri,options)
9
+ end
10
+
11
+ def embed_code
12
+ content_tag(:iframe, '', src: src, width: width, height: height, allowfullscreen: allowfullscreen)
13
+ end
14
+ alias_method :to_html, :embed_code
15
+
16
+ def allowfullscreen
17
+ @options[:allowfullscreen]
18
+ end
19
+
20
+ def src
21
+ "https://player.vimeo.com/video/#{id}"
22
+ end
23
+
24
+ def id
25
+ @uri.to_s.match(/https?:\/\/(?:[\w]+\.)*vimeo\.com(?:[\/\w]*\/?)?\/(?<id>[0-9]+)[^\s]*/)[:id]
26
+ end
27
+ end
@@ -0,0 +1,22 @@
1
+ class Videos::YouTube < Videos::Video
2
+ def embed_code
3
+ content_tag(:iframe, '', type: 'text/html', width: width, height: height, src: src)
4
+ end
5
+ alias_method :to_html, :embed_code
6
+
7
+ def id
8
+ id = ''
9
+ url = @uri.to_s.gsub(/(>|<)/i,'').split(/(vi\/|v=|\/v\/|youtu\.be\/|\/embed\/)/)
10
+ if url[2] != nil
11
+ id = url[2].split(/[^0-9a-z_\-]/i)
12
+ id = id[0];
13
+ else
14
+ id = url;
15
+ end
16
+ id
17
+ end
18
+
19
+ def src
20
+ "https://www.youtube.com/embed/#{id}"
21
+ end
22
+ end
data/license ADDED
@@ -0,0 +1,13 @@
1
+ Copyright 2018 Ryan Burnette
2
+
3
+ Permission to use, copy, modify, and/or distribute this software for any
4
+ purpose with or without fee is hereby granted, provided that the above
5
+ copyright notice and this permission notice appear in all copies.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
8
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
9
+ FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
10
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
11
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
12
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
13
+ PERFORMANCE OF THIS SOFTWARE.
data/readme.md ADDED
@@ -0,0 +1,23 @@
1
+ # Videos
2
+
3
+ Videos is an API for going from a URL to video embed code.
4
+
5
+ Right now only the basics are implemented.
6
+
7
+ YouTube, Vimeo and `<video>` tags are supported.
8
+
9
+ ## Usage
10
+
11
+ ```ruby
12
+ # Gemfile
13
+ gem 'rb42-videos', '~> 1.0'
14
+ # or
15
+ gem 'videos', '~> 1.0', git: 'https://github.com/ryanburnette/videos.git'
16
+ ```
17
+
18
+ ```
19
+ require 'videos'
20
+ v = Videos.factory('https://youtu.be/abc123')
21
+ v.id
22
+ v.to_html
23
+ ```
data/videos.gemspec ADDED
@@ -0,0 +1,31 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "videos/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "rb42-videos"
7
+ spec.version = Videos::VERSION
8
+ spec.authors = ["Ryan Burnette"]
9
+ spec.email = ["ryan.burnette@gmail.com"]
10
+
11
+ spec.summary = "Videos is an API for going from a URL to video embed code."
12
+ spec.description = "Videos is an API for going from a URL to video embed code."
13
+ spec.homepage = "https://github.com/ryanburnette/videos"
14
+ spec.license = "ISC"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.16"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "rspec", "~> 3.0"
26
+ spec.add_development_dependency "guard-rspec", "~> 4.7"
27
+ spec.add_development_dependency "html_validation", "~> 1.1"
28
+
29
+ spec.add_dependency "httparty", "~> 0.16"
30
+ spec.add_dependency "actionview", "~> 5"
31
+ end
metadata ADDED
@@ -0,0 +1,159 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rb42-videos
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Ryan Burnette
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-03-05 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.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
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: :development
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: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: guard-rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '4.7'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '4.7'
69
+ - !ruby/object:Gem::Dependency
70
+ name: html_validation
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.1'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.1'
83
+ - !ruby/object:Gem::Dependency
84
+ name: httparty
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.16'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.16'
97
+ - !ruby/object:Gem::Dependency
98
+ name: actionview
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '5'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '5'
111
+ description: Videos is an API for going from a URL to video embed code.
112
+ email:
113
+ - ryan.burnette@gmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - ".rspec"
120
+ - ".travis.yml"
121
+ - Gemfile
122
+ - Gemfile.lock
123
+ - Guardfile
124
+ - Rakefile
125
+ - bin/console
126
+ - lib/videos.rb
127
+ - lib/videos/uri.rb
128
+ - lib/videos/version.rb
129
+ - lib/videos/video.rb
130
+ - lib/videos/vimeo.rb
131
+ - lib/videos/youtube.rb
132
+ - license
133
+ - readme.md
134
+ - videos.gemspec
135
+ homepage: https://github.com/ryanburnette/videos
136
+ licenses:
137
+ - ISC
138
+ metadata: {}
139
+ post_install_message:
140
+ rdoc_options: []
141
+ require_paths:
142
+ - lib
143
+ required_ruby_version: !ruby/object:Gem::Requirement
144
+ requirements:
145
+ - - ">="
146
+ - !ruby/object:Gem::Version
147
+ version: '0'
148
+ required_rubygems_version: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ requirements: []
154
+ rubyforge_project:
155
+ rubygems_version: 2.7.4
156
+ signing_key:
157
+ specification_version: 4
158
+ summary: Videos is an API for going from a URL to video embed code.
159
+ test_files: []