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 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 hav Textile, but it is not good for all cases),
5
- external url protocol adding. And here Conred saves the day.
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
 
@@ -1,3 +1,3 @@
1
1
  module Conred
2
- VERSION = "0.2.5"
2
+ VERSION = "0.2.6"
3
3
  end
@@ -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
- if @video_url[/vimeo\.com\/([0-9]*)/]
33
- @vimeo_id = $1
34
- end
35
- vimeo_file = "../views/video/vimeo_iframe"
36
- render(vimeo_file, :vimeo_id => @vimeo_id, :height => @height, :width => @width).html_safe
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
- if @video_url[/youtu\.be\/([^\?]*)/]
41
- @youtube_id = $1
42
- else
43
- @video_url[/(v=([A-Za-z0-9_-]*))/]
44
- @youtube_id = $2
45
- end
46
- youtube_file = "../views/video/youtube_iframe"
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.5
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-07 00:00:00.000000000 Z
12
+ date: 2013-01-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec