conred 0.4.3 → 0.5.0
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 +4 -4
- data/README.md +5 -10
- data/conred.gemspec +4 -7
- data/lib/conred.rb +0 -1
- data/lib/conred/version.rb +1 -1
- data/lib/conred/video.rb +18 -23
- data/lib/views/video/video_iframe.html.erb +2 -0
- data/spec/conred_spec/video_spec.rb +27 -23
- metadata +8 -50
- data/lib/views/video/video_iframe.html.haml +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 52df766ea4e04c86a1a128f258afcfd1a98c0cdd
|
4
|
+
data.tar.gz: 2477890c39c4ff06dff211e80fc23fa055dc0bf4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8450ca6de41b5981dd4fb478f7c70eb7a0c40d785f77e45b35af18563e8431ed86b024e18e6906ab672cf9ed7e1d5c8bb169b0f2c7d0480ce66cdb9f3b341d0f
|
7
|
+
data.tar.gz: af014e2a85ea64dde0e96dc8e88a0a13cb9cb1c44ce6f04e5335d51755b0baea1a2a513ac7d4dcd9763839a5a2184d5f46462492e32745a1371f4ed00ab68f8f
|
data/README.md
CHANGED
@@ -3,10 +3,7 @@
|
|
3
3
|
|
4
4
|
# Conred
|
5
5
|
|
6
|
-
|
7
|
-
embedding from url, user input displaying, formatting, trimming stripping,
|
8
|
-
external url protocol adding and all that nasty stuff that we write in our apps.
|
9
|
-
These are the cases where Conred saves the day.
|
6
|
+
Easily and safely embed YouTube and Vimeo videos in your applications.
|
10
7
|
|
11
8
|
## Installation
|
12
9
|
|
@@ -24,14 +21,12 @@ Or install it yourself as:
|
|
24
21
|
|
25
22
|
## Usage
|
26
23
|
|
27
|
-
### Iframe generator for Youtube and Vimeo videos:
|
28
|
-
|
29
24
|
```ruby
|
30
25
|
c = Conred::Video.new(
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
26
|
+
video_url: "http://www.youtube.com/watch?v=tNtW9pGFPTA&feature=plcp",
|
27
|
+
width: 285,
|
28
|
+
height: 185,
|
29
|
+
error_message: "Video url is invalid"
|
35
30
|
)
|
36
31
|
```
|
37
32
|
|
data/conred.gemspec
CHANGED
@@ -4,15 +4,12 @@ require File.expand_path('../lib/conred/version', __FILE__)
|
|
4
4
|
Gem::Specification.new do |gem|
|
5
5
|
gem.authors = ["Janis Miezitis"]
|
6
6
|
gem.email = ["janjiss@gmail.com"]
|
7
|
-
gem.description = %q{
|
8
|
-
gem.summary = %q{
|
7
|
+
gem.description = %q{Safely and easily embed videos}
|
8
|
+
gem.summary = %q{Safely and easily embed YouTube and Vimeo videos}
|
9
9
|
gem.homepage = "http://github.com/janjiss/conred"
|
10
10
|
|
11
|
-
gem.
|
12
|
-
gem.
|
13
|
-
gem.add_dependency "actionpack", '>= 3.0'
|
14
|
-
gem.add_development_dependency "rspec", '>= 2.0'
|
15
|
-
gem.add_development_dependency "rake", '>= 10.1'
|
11
|
+
gem.add_development_dependency "rspec", '~> 2.0'
|
12
|
+
gem.add_development_dependency "rake", '~> 10.1'
|
16
13
|
|
17
14
|
gem.files = `git ls-files`.split($\)
|
18
15
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
data/lib/conred.rb
CHANGED
data/lib/conred/version.rb
CHANGED
data/lib/conred/video.rb
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
require "conred/version"
|
2
|
-
require "action_view"
|
3
2
|
require "net/http"
|
4
|
-
require "
|
3
|
+
require "erb"
|
4
|
+
|
5
5
|
module Conred
|
6
6
|
module Video
|
7
|
-
def initialize(
|
8
|
-
@width
|
9
|
-
@height
|
10
|
-
@error_message =
|
11
|
-
@video_id
|
7
|
+
def initialize(options = {})
|
8
|
+
@width = options.fetch(:width, 670)
|
9
|
+
@height = options.fetch(:height, 450)
|
10
|
+
@error_message = options.fetch(:error_message, "Invalid video url")
|
11
|
+
@video_id = get_video_id_from(options[:video_url])
|
12
12
|
end
|
13
13
|
|
14
|
-
def self.new
|
14
|
+
def self.new(arguments)
|
15
15
|
if Youtube.url_format_is_valid? arguments[:video_url]
|
16
16
|
Youtube.new arguments
|
17
17
|
elsif Video::Vimeo.url_format_is_valid? arguments[:video_url]
|
@@ -30,27 +30,22 @@ module Conred
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def code
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
)
|
33
|
+
view_path = File.join(
|
34
|
+
File.dirname(__FILE__),
|
35
|
+
"../views/video/video_iframe.html.erb"
|
36
|
+
)
|
37
|
+
template = ERB.new(File.read(view_path))
|
38
|
+
template.result(binding)
|
38
39
|
end
|
39
40
|
|
40
41
|
def exist?
|
41
|
-
response =
|
42
|
-
response.
|
42
|
+
response = Net::HTTP.get_response(URI("http:#{api_uri}"))
|
43
|
+
response.is_a?(Net::HTTPSuccess)
|
43
44
|
end
|
44
45
|
|
45
|
-
|
46
|
+
attr_reader :height, :width, :video_id, :error_message
|
46
47
|
|
47
|
-
|
48
|
-
path = File.join(
|
49
|
-
File.dirname(__FILE__),
|
50
|
-
"../views/video/video_iframe".split("/")
|
51
|
-
)
|
52
|
-
Haml::Engine.new(File.read("#{path}.html.haml")).render(Object.new, locals)
|
53
|
-
end
|
48
|
+
private
|
54
49
|
|
55
50
|
class Youtube
|
56
51
|
include Video
|
@@ -20,65 +20,69 @@ describe Conred do
|
|
20
20
|
}
|
21
21
|
|
22
22
|
it "should match youtube video" do
|
23
|
-
short_youtube_url.
|
24
|
-
https_youtube_url.
|
25
|
-
short_youtube_url_with_www.
|
26
|
-
long_youtube_url_with_features.
|
27
|
-
short_youtube_url_without_http_and_www.
|
23
|
+
expect(short_youtube_url).to be_youtube_video
|
24
|
+
expect(https_youtube_url).to be_youtube_video
|
25
|
+
expect(short_youtube_url_with_www).to be_youtube_video
|
26
|
+
expect(long_youtube_url_with_features).to be_youtube_video
|
27
|
+
expect(short_youtube_url_without_http_and_www).to be_youtube_video
|
28
28
|
end
|
29
29
|
|
30
30
|
it "should check for corner cases" do
|
31
|
-
evil_vimeo.
|
32
|
-
evil_vimeo.
|
31
|
+
expect(evil_vimeo).to_not be_youtube_video
|
32
|
+
expect(evil_vimeo).to_not be_vimeo_video
|
33
33
|
end
|
34
34
|
|
35
35
|
it "should match vimeo video" do
|
36
|
-
vimeo_url.
|
37
|
-
vimeo_without_http.
|
38
|
-
https_vimeo_url.
|
39
|
-
vimeo_url.
|
36
|
+
expect(vimeo_url).to_not be_youtube_video
|
37
|
+
expect(vimeo_without_http).to be_vimeo_video
|
38
|
+
expect(https_vimeo_url).to be_vimeo_video
|
39
|
+
expect(vimeo_url).to be_vimeo_video
|
40
40
|
end
|
41
41
|
|
42
42
|
describe "youtube embed code" do
|
43
43
|
subject {Conred::Video.new(:video_url=>"http://www.youtube.com/watch?v=Lrj5Kxdzouc", :width=>450,:height=> 300).code }
|
44
|
-
it
|
45
|
-
|
46
|
-
|
44
|
+
it "matches to correct html" do
|
45
|
+
expect(subject).to match(/Lrj5Kxdzouc/)
|
46
|
+
expect(subject).to match(/width="450"/)
|
47
|
+
expect(subject).to match(/height="300"/)
|
48
|
+
end
|
47
49
|
end
|
48
50
|
|
49
51
|
describe "vimeo embed code" do
|
50
52
|
subject { Conred::Video.new(:video_url=>"http://vimeo.com/49556689", :width=>450, :height=>300).code }
|
51
|
-
it
|
52
|
-
|
53
|
-
|
53
|
+
it "matches to correct html" do
|
54
|
+
expect(subject).to match(/49556689/)
|
55
|
+
expect(subject).to match(/width="450"/)
|
56
|
+
expect(subject).to match(/height="300"/)
|
57
|
+
end
|
54
58
|
end
|
55
59
|
|
56
60
|
it "should render error message when url is invalid" do
|
57
|
-
error_video.code.
|
61
|
+
expect(error_video.code).to eq("Some mistake in url")
|
58
62
|
end
|
59
63
|
|
60
64
|
it "should return correct embed code when passing arguments in url" do
|
61
|
-
Conred::Video.new(:video_url=>"http://www.youtube.com/watch?NR=1&feature=endscreen&v=Lrj5Kxdzouc",:width=> 450,:height=> 300).code.
|
65
|
+
expect(Conred::Video.new(:video_url=>"http://www.youtube.com/watch?NR=1&feature=endscreen&v=Lrj5Kxdzouc",:width=> 450,:height=> 300).code).to match(/Lrj5Kxdzouc/)
|
62
66
|
end
|
63
67
|
|
64
68
|
describe "check if a video exist" do
|
65
69
|
it "should return false if request 404" do
|
66
70
|
non_existing_video = Conred::Video.new(:video_url=>"http://www.youtube.com/watch?v=Lrj5Kxdzoux")
|
67
|
-
non_existing_video.exist
|
71
|
+
expect(non_existing_video.exist?).to eq(false)
|
68
72
|
end
|
69
73
|
|
70
74
|
it "should make a request to the proper uri" do
|
71
75
|
non_existing_video = Conred::Video.new(:video_url=>"http://www.youtube.com/watch?v=Lrj5Kxdzoux")
|
72
|
-
non_existing_video.api_uri.
|
76
|
+
expect(non_existing_video.api_uri).to eq("//gdata.youtube.com/feeds/api/videos/Lrj5Kxdzoux")
|
73
77
|
end
|
74
78
|
|
75
79
|
it "should be true if response is 200" do
|
76
80
|
existing_video = Conred::Video.new(:video_url=>"http://www.youtube.com/watch?v=Lrj5Kxdzouc")
|
77
|
-
existing_video.exist
|
81
|
+
expect(existing_video.exist?).to eq(true)
|
78
82
|
end
|
79
83
|
|
80
84
|
it "should be false if uri isn't recognized" do
|
81
|
-
error_video.exist
|
85
|
+
expect(error_video.exist?).to eq(false)
|
82
86
|
end
|
83
87
|
end
|
84
88
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: conred
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Janis Miezitis
|
@@ -10,77 +10,35 @@ bindir: bin
|
|
10
10
|
cert_chain: []
|
11
11
|
date: 2014-04-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: haml
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - ">="
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '3.0'
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - ">="
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '3.0'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: typhoeus
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ">="
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0.6'
|
34
|
-
type: :runtime
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - ">="
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0.6'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: actionpack
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - ">="
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '3.0'
|
48
|
-
type: :runtime
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - ">="
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '3.0'
|
55
13
|
- !ruby/object:Gem::Dependency
|
56
14
|
name: rspec
|
57
15
|
requirement: !ruby/object:Gem::Requirement
|
58
16
|
requirements:
|
59
|
-
- - "
|
17
|
+
- - "~>"
|
60
18
|
- !ruby/object:Gem::Version
|
61
19
|
version: '2.0'
|
62
20
|
type: :development
|
63
21
|
prerelease: false
|
64
22
|
version_requirements: !ruby/object:Gem::Requirement
|
65
23
|
requirements:
|
66
|
-
- - "
|
24
|
+
- - "~>"
|
67
25
|
- !ruby/object:Gem::Version
|
68
26
|
version: '2.0'
|
69
27
|
- !ruby/object:Gem::Dependency
|
70
28
|
name: rake
|
71
29
|
requirement: !ruby/object:Gem::Requirement
|
72
30
|
requirements:
|
73
|
-
- - "
|
31
|
+
- - "~>"
|
74
32
|
- !ruby/object:Gem::Version
|
75
33
|
version: '10.1'
|
76
34
|
type: :development
|
77
35
|
prerelease: false
|
78
36
|
version_requirements: !ruby/object:Gem::Requirement
|
79
37
|
requirements:
|
80
|
-
- - "
|
38
|
+
- - "~>"
|
81
39
|
- !ruby/object:Gem::Version
|
82
40
|
version: '10.1'
|
83
|
-
description:
|
41
|
+
description: Safely and easily embed videos
|
84
42
|
email:
|
85
43
|
- janjiss@gmail.com
|
86
44
|
executables: []
|
@@ -96,7 +54,7 @@ files:
|
|
96
54
|
- lib/conred.rb
|
97
55
|
- lib/conred/version.rb
|
98
56
|
- lib/conred/video.rb
|
99
|
-
- lib/views/video/video_iframe.html.
|
57
|
+
- lib/views/video/video_iframe.html.erb
|
100
58
|
- spec/conred_spec.rb
|
101
59
|
- spec/conred_spec/video_spec.rb
|
102
60
|
homepage: http://github.com/janjiss/conred
|
@@ -121,7 +79,7 @@ rubyforge_project:
|
|
121
79
|
rubygems_version: 2.2.0
|
122
80
|
signing_key:
|
123
81
|
specification_version: 4
|
124
|
-
summary:
|
82
|
+
summary: Safely and easily embed YouTube and Vimeo videos
|
125
83
|
test_files:
|
126
84
|
- spec/conred_spec.rb
|
127
85
|
- spec/conred_spec/video_spec.rb
|
@@ -1 +0,0 @@
|
|
1
|
-
%iframe{:allowFullScreen => "", :frameborder => "0", :height => height, :mozallowfullscreen => "", :src => "#{video_link}", :webkitAllowFullScreen => "", :width => width}
|