conred 0.2.5 → 0.2.6
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +2 -2
- data/lib/conred/version.rb +1 -1
- data/lib/conred/video.rb +36 -14
- data/spec/conred_spec/video_spec.rb +15 -1
- metadata +2 -2
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# Conred
|
2
2
|
|
3
3
|
In every project we have common things like video
|
4
|
-
embeding from url, body formating (Of course we
|
5
|
-
external url protocol adding.
|
4
|
+
embeding from url, body formating (Of course we have Textile, but it is not good for all cases),
|
5
|
+
external url protocol adding. These are the cases where Conred saves the day.
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
data/lib/conred/version.rb
CHANGED
data/lib/conred/video.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require "conred/version"
|
2
2
|
require "action_view"
|
3
|
+
require "net/http"
|
3
4
|
module Conred
|
4
5
|
class Video
|
5
6
|
def initialize(video_url, width = 670, height = 450, error_message = "Video url you have provided is invalid")
|
@@ -29,22 +30,23 @@ module Conred
|
|
29
30
|
|
30
31
|
|
31
32
|
def video_from_vimeo_url
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
33
|
+
vimeo_partial = "../views/video/vimeo_iframe"
|
34
|
+
render(
|
35
|
+
vimeo_partial,
|
36
|
+
:vimeo_id => video_id,
|
37
|
+
:height => @height,
|
38
|
+
:width => @width
|
39
|
+
).html_safe
|
37
40
|
end
|
38
41
|
|
39
42
|
def video_from_youtube_url
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
render(youtube_file, :youtube_id => @youtube_id, :height => @height, :width => @width).html_safe
|
43
|
+
youtube_partial = "../views/video/youtube_iframe"
|
44
|
+
render(
|
45
|
+
youtube_partial,
|
46
|
+
:youtube_id => video_id,
|
47
|
+
:height => @height,
|
48
|
+
:width => @width
|
49
|
+
).html_safe
|
48
50
|
end
|
49
51
|
|
50
52
|
def render(path_to_partial, locals = {})
|
@@ -55,5 +57,25 @@ module Conred
|
|
55
57
|
Haml::Engine.new(File.read("#{path}.html.haml")).render(Object.new, locals)
|
56
58
|
end
|
57
59
|
|
60
|
+
def video_id
|
61
|
+
if @video_url[/vimeo\.com\/([0-9]*)/]
|
62
|
+
video_id = $1
|
63
|
+
elsif @video_url[/youtu\.be\/([^\?]*)/]
|
64
|
+
video_id = $1
|
65
|
+
else
|
66
|
+
@video_url[/(v=([A-Za-z0-9_-]*))/]
|
67
|
+
video_id = $2
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def exist?
|
72
|
+
if youtube_video?
|
73
|
+
response = Net::HTTP.get_response(URI("http://gdata.youtube.com/feeds/api/videos/#{video_id}"))
|
74
|
+
else
|
75
|
+
response = Net::HTTP.get_response(URI("http://vimeo.com/api/v2/video/#{video_id}.json"))
|
76
|
+
end
|
77
|
+
response.is_a?(Net::HTTPSuccess)
|
78
|
+
end
|
79
|
+
|
58
80
|
end
|
59
|
-
end
|
81
|
+
end
|
@@ -40,5 +40,19 @@ describe Conred do
|
|
40
40
|
Conred::Video.new("http://vimeo.com/49556689", 450, 300).code.should match(/height='300'/)
|
41
41
|
Conred::Video.new("http://google.com/12311233", 450, 300, "Some mistake in url").code.should == "Some mistake in url"
|
42
42
|
end
|
43
|
+
|
44
|
+
describe "check if a video exist" do
|
45
|
+
it "should return false if request 404" do
|
46
|
+
non_existing_video = Conred::Video.new("http://www.youtube.com/watch?v=Lrj5Kxdzoux")
|
47
|
+
Net::HTTP.stub(:get_response=>Net::HTTPNotFound.new(true, 404, "Not Found"))
|
48
|
+
non_existing_video.exist?.should be_false
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should be true if response is 200" do
|
52
|
+
existing_video = Conred::Video.new("http://www.youtube.com/watch?v=Lrj5Kxdzouc")
|
53
|
+
Net::HTTP.stub(:get_response=>Net::HTTPOK.new(true,200,"OK"))
|
54
|
+
existing_video.exist?.should be_true
|
55
|
+
end
|
56
|
+
end
|
43
57
|
end
|
44
|
-
end
|
58
|
+
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.2.
|
4
|
+
version: 0.2.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-01-
|
12
|
+
date: 2013-01-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|