acts_as_unvlogable 1.0.0 → 1.0.2

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.
@@ -1,6 +1,6 @@
1
1
  # ----------------------------------------------
2
2
  # Class for Ted Talks (www.ted.com/talks)
3
- # http://www.ted.com/index.php/talks/benjamin_wallace_on_the_price_of_happiness.html
3
+ # http://www.ted.com/talks/benjamin_wallace_on_the_price_of_happiness.html
4
4
  # ----------------------------------------------
5
5
 
6
6
 
@@ -8,20 +8,16 @@ class VgTed
8
8
 
9
9
  def initialize(url=nil, options={})
10
10
  @url = url
11
- raise unless URI::parse(url).path.split("/").include? "talks"
12
- @page = Hpricot(open(url))
13
- id = @page.to_s.split("/id/")[1].split("\"")[0]
14
- @emb = Hpricot(open("http://www.ted.com/talks/embed/id/#{id}"))
15
- @flashvars = CGI::unescapeHTML(@emb.to_s).split("param name=\"flashvars\" value=\"")[1].split("\"")[0]
16
- @args = CGI::parse(@flashvars)
11
+ raise ArgumentError.new("Unsuported url or service") unless URI::parse(url).path.split("/").include? "talks"
12
+ @page = Nokogiri::HTML(open(@url))
17
13
  end
18
14
 
19
15
  def title
20
- @page.search("//h1/span").first.inner_html.strip
16
+ @page.xpath("//meta[@property='og:title']").first["content"].strip
21
17
  end
22
18
 
23
19
  def thumbnail
24
- "#{@args['su']}"
20
+ @page.xpath("//meta[@property='og:image']").first["content"].strip
25
21
  end
26
22
 
27
23
  def duration
@@ -29,15 +25,11 @@ class VgTed
29
25
  end
30
26
 
31
27
  def embed_url
32
- "http://video.ted.com/assets/player/swf/EmbedPlayer.swf?#{@flashvars}"
28
+ @page.xpath("//link[@itemprop='embedURL']").first["href"].strip
33
29
  end
34
30
 
35
- def embed_html(width=425, height=344, options={})
36
- "<object width='#{width}' height='#{height}'><param name='movie' value='#{embed_url}'></param><param name='allowFullScreen' value='true' /><param name='wmode' value='transparent'></param><param name='bgColor' value='#ffffff'></param><embed src='#{embed_url}' pluginspace='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' wmode='transparent' bgColor='#ffffff' width='#{width}' height='#{height}' allowFullScreen='true'></embed></object>"
37
- end
38
-
39
- def flv
40
- "#{@args['vu'].to_s}"
31
+ def embed_html(width=425, height=344, options={}, params={})
32
+ "<iframe src='#{embed_url}' width='#{width}' height='#{height}' frameborder='0' scrolling='no' webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>"
41
33
  end
42
34
 
43
35
  def download_url
@@ -5,49 +5,41 @@
5
5
 
6
6
 
7
7
  class VgVimeo
8
-
8
+
9
9
  def initialize(url=nil, options={})
10
10
  # general settings
11
11
  @url = url
12
12
  @video_id = parse_url(url)
13
- res = Net::HTTP.get(URI.parse("http://vimeo.com/moogaloop/load/clip:#{@video_id}/embed?param_server=vimeo.com&param_clip_id=#{@video_id}"))
13
+ res = Net::HTTP.get(URI.parse("http://vimeo.com/api/v2/video/#{@video_id}.xml"))
14
14
  @feed = REXML::Document.new(res)
15
15
  end
16
-
16
+
17
17
  def video_id
18
18
  @video_id
19
19
  end
20
-
20
+
21
21
  def title
22
- REXML::XPath.first( @feed, "//caption" )[0].to_s
22
+ REXML::XPath.first( @feed, "//title" )[0].to_s
23
23
  end
24
-
24
+
25
25
  def thumbnail
26
- REXML::XPath.first( @feed, "//thumbnail" )[0].to_s
26
+ REXML::XPath.first( @feed, "//thumbnail_medium" )[0].to_s
27
27
  end
28
-
28
+
29
29
  def duration
30
30
  REXML::XPath.first( @feed, "//duration" )[0].to_s.to_i
31
31
  end
32
-
32
+
33
33
  def embed_url
34
- "http://vimeo.com/moogaloop.swf?clip_id=#{@video_id}&server=vimeo.com&fullscreen=1&show_title=1&show_byline=1&show_portrait=1"
35
- end
36
-
37
- def embed_html(width=425, height=344, options={})
38
- "<object width='#{width}' height='#{height}'><param name='movie' value='#{embed_url}'></param><param name='allowFullScreen' value='true'></param><param name='allowscriptaccess' value='always'></param><embed src='#{embed_url}' type='application/x-shockwave-flash' allowscriptaccess='always' allowfullscreen='true' width='#{width}' height='#{height}'></embed></object>"
34
+ "http://http://player.vimeo.com/video/#{@video_id}"
39
35
  end
40
36
 
41
- def flv
42
- request_signature = REXML::XPath.first( @feed, "//request_signature" )[0]
43
- request_signature_expires = REXML::XPath.first( @feed, "//request_signature_expires" )[0]
44
- "http://www.vimeo.com/moogaloop/play/clip:#{@video_id}/#{request_signature}/#{request_signature_expires}/"
37
+ def embed_html(width=425, height=344, options={}, params={})
38
+ "<iframe src='#{embed_url}' width='#{width}' height='#{height}' frameborder='0' webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>"
45
39
  end
46
40
 
47
41
  def download_url
48
- request_signature = REXML::XPath.first( @feed, "//request_signature" )[0]
49
- request_signature_expires = REXML::XPath.first( @feed, "//request_signature_expires" )[0]
50
- "http://www.vimeo.com/moogaloop/play/clip:#{@video_id}/#{request_signature}/#{request_signature_expires}/?q=hd"
42
+ nil
51
43
  end
52
44
 
53
45
  def service
@@ -75,4 +67,4 @@ class VgVimeo
75
67
  nil
76
68
  end
77
69
 
78
- end
70
+ end
@@ -0,0 +1,49 @@
1
+ # ----------------------------------------------
2
+ # Class for Wistia (wistia.com)
3
+ # https://home.wistia.com/medias/e4a27b971d
4
+ # ----------------------------------------------
5
+
6
+ class VgWistia
7
+ attr_reader :title, :thumbnail, :duration, :service
8
+
9
+ def initialize(url=nil, options={})
10
+ @url = url
11
+ fetch_video_details!
12
+ assign_properties!
13
+ end
14
+
15
+ def embed_url
16
+ iframe = Nokogiri::HTML(@details["html"])
17
+ iframe.xpath("//iframe").first["src"]
18
+ end
19
+
20
+ def embed_html(width=425, height=344, options={}, params={})
21
+ "<iframe src='#{embed_url}' allowtransparency='true' frameborder='0' scrolling='no' class='wistia_embed' name='wistia_embed' allowfullscreen mozallowfullscreen webkitallowfullscreen oallowfullscreen msallowfullscreen width='#{width}' height='#{height}'></iframe>"
22
+ end
23
+
24
+ private
25
+
26
+ def fetch_video_details!
27
+ begin
28
+ res = Net::HTTP.get(URI.parse(wistia_oembed_endpoint))
29
+ @details = JSON.parse(res)
30
+ rescue JSON::ParserError
31
+ raise ArgumentError.new("Unsuported url or service")
32
+ end
33
+ end
34
+
35
+ def assign_properties!
36
+ @title = @details["title"]
37
+ @thumbnail = @details["thumbnail_url"]
38
+ @duration = @details["duration"]
39
+ @service = @details["provider_name"]
40
+ end
41
+
42
+ def encoded_url
43
+ CGI::escape(@url)
44
+ end
45
+
46
+ def wistia_oembed_endpoint
47
+ "http://fast.wistia.com/oembed.json?url=#{encoded_url}"
48
+ end
49
+ end
@@ -0,0 +1,11 @@
1
+ require "acts_as_unvlogable/vg_youtube"
2
+
3
+ class VgYoutu < VgYoutube
4
+ def initialize(url=nil, options={})
5
+ url = URI(url)
6
+ url.host = 'www.youtube.com'
7
+ url.query = "#{url.query}&v=#{url.path[1..-1]}"
8
+ url.path = '/watch'
9
+ super(url.to_s, options)
10
+ end
11
+ end
@@ -1,18 +1,21 @@
1
1
  # ----------------------------------------------
2
2
  # Class for Youtube (youtube.com)
3
- # http://www.youtube.com/watch?v=25AsfkriHQc
3
+ # http://www.youtube.com/watch?v=MVa4q-YVjD8
4
4
  # ----------------------------------------------
5
5
 
6
-
7
6
  class VgYoutube
8
7
 
9
8
  def initialize(url=nil, options={})
10
9
  object = YouTubeIt::Client.new({})
11
10
  @url = url
12
11
  @video_id = @url.query_param('v')
13
- @details = object.video_by(@video_id)
14
- @details.instance_variable_set(:@noembed, false)
15
- raise if @details.blank?
12
+ begin
13
+ @details = object.video_by(@video_id)
14
+ raise if @details.blank?
15
+ @details.instance_variable_set(:@noembed, false) unless !@details.embeddable?
16
+ rescue
17
+ raise ArgumentError, "Unsuported url or service"
18
+ end
16
19
  end
17
20
 
18
21
  def title
@@ -31,25 +34,11 @@ class VgYoutube
31
34
  @details.media_content.first.url if @details.noembed == false
32
35
  end
33
36
 
34
- # options
35
- # You can read more about the youtube player options in
36
- # http://code.google.com/intl/en/apis/youtube/player_parameters.html
37
- # Use them in options (ex {:rel => 0, :color1 => '0x333333'})
38
- #
39
- def embed_html(width=425, height=344, options={})
40
- "<object width='#{width}' height='#{height}'><param name='movie' value='#{embed_url}#{options.map {|k,v| "&#{k}=#{v}"}}'></param><param name='allowFullScreen' value='true'></param><param name='allowscriptaccess' value='always'></param><embed src='#{embed_url}#{options.map {|k,v| "&#{k}=#{v}"}}' type='application/x-shockwave-flash' allowscriptaccess='always' allowfullscreen='true' width='#{width}' height='#{height}'></embed></object>" if @details.noembed == false
41
- end
42
-
43
-
44
- def flv
45
- doc = URI::parse("http://www.youtube.com/get_video_info?&video_id=#{@video_id}").read
46
- CGI::unescape(doc.split("&fmt_url_map=")[1].split("&")[0]).split("|")[1].split(",")[0]
37
+ # iframe embed — https://developers.google.com/youtube/player_parameters#Manual_IFrame_Embeds
38
+ def embed_html(width=425, height=344, options={}, params={})
39
+ "<iframe id='ytplayer' type='text/html' width='#{width}' height='#{height}' src='#{embed_url}#{options.map {|k,v| "&#{k}=#{v}"}}' frameborder='0'/>" if @details.noembed == false
47
40
  end
48
41
 
49
- def download_url
50
- flv
51
- end
52
-
53
42
  def service
54
43
  "Youtube"
55
44
  end
@@ -0,0 +1,363 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe UnvlogIt do
5
+ context "without any url" do
6
+ it {
7
+ expect { UnvlogIt.new }.to raise_error(ArgumentError, "We need a video url")
8
+ }
9
+ end
10
+
11
+ context "with an unsupported url" do
12
+ it {
13
+ expect { UnvlogIt.new("http://iwannagothere.net") }.to raise_error(ArgumentError, "Unsuported url or service")
14
+ }
15
+ end
16
+
17
+ # ----------------------------------------------------------
18
+ # Testing youtube
19
+ # ----------------------------------------------------------
20
+
21
+ context "with an existent youtube url" do
22
+ let(:videotron) { UnvlogIt.new("http://www.youtube.com/watch?v=MVa4q-YVjD8") } # => Keith Moon´s drum kit explodes
23
+
24
+ it "initialize a VgYoutube instance" do
25
+ expect(VgYoutube).to eq(videotron.instance_values['object'].class)
26
+ expect("http://www.youtube.com/watch?v=MVa4q-YVjD8").to eq(videotron.instance_values['object'].instance_values['url'])
27
+ expect("MVa4q-YVjD8").to eq(videotron.instance_values['object'].instance_values['video_id'])
28
+ expect(videotron.instance_values['object'].instance_values['details']).to_not be_nil
29
+ end
30
+
31
+ it "returns the video properties" do
32
+ check_video_attributes({:title => "Keith Moon´s drum kit explodes", :service => "Youtube"})
33
+ end
34
+ end
35
+
36
+ context "with an existent youtube url that can not be embedded" do
37
+ it {
38
+ expect { UnvlogIt.new("https://www.youtube.com/watch?v=-PZYZ6fJbr4") }.to raise_error(ArgumentError, "Embedding disabled by request")
39
+ }
40
+ end
41
+
42
+ context "with an inexistent youtube url" do
43
+ it {
44
+ expect { UnvlogIt.new("http://www.youtube.com/watch?v=inexistente") }.to raise_error(ArgumentError, "Unsuported url or service")
45
+ }
46
+ end
47
+
48
+ context "with a shortened youtube URL" do
49
+ let(:videotron) { UnvlogIt.new("http://youtu.be/4pzMBtPMUq8") } # => Keith Moon´s drum kit explodes
50
+
51
+ it "initialize a VgYoutube instance" do
52
+ expect(VgYoutu).to eq(videotron.instance_values['object'].class)
53
+ expect("http://www.youtube.com/watch?&v=4pzMBtPMUq8").to eq(videotron.instance_values['object'].instance_values['url'])
54
+ expect("4pzMBtPMUq8").to eq(videotron.instance_values['object'].instance_values['video_id'])
55
+ expect(videotron.instance_values['object'].instance_values['details']).to_not be_nil
56
+ end
57
+
58
+ it "returns the video properties" do
59
+ check_video_attributes({:title => "APM? Capítol 349 -09/04/14- (HD)", :service => "Youtube"})
60
+ end
61
+ end
62
+
63
+ # ----------------------------------------------------------
64
+ # Testing metacafe
65
+ # ----------------------------------------------------------
66
+
67
+ context "with an existent metacafe url" do
68
+ let(:videotron) { UnvlogIt.new("http://www.metacafe.com/watch/1135061/close_call_a320_caught_in_crosswinds/") } # => Close Call! A320 Caught in Crosswinds
69
+
70
+ it "initialize a VgMetacafe instance" do
71
+ expect(VgMetacafe).to eq(videotron.instance_values['object'].class)
72
+ expect("http://www.metacafe.com/watch/1135061/close_call_a320_caught_in_crosswinds/").to eq(videotron.instance_values['object'].instance_values['url'])
73
+ expect(3).to eq(videotron.instance_values['object'].instance_values['args'].size)
74
+ expect(videotron.instance_values['object'].instance_values['yt']).to be_nil
75
+ expect(videotron.instance_values['object'].instance_values['youtubed']).to be false
76
+ end
77
+
78
+ it "returns the video properties" do
79
+ check_video_attributes({:title => "Close call a320 caught in crosswinds", :service => "Metacafe"})
80
+ end
81
+ end
82
+
83
+ context "with an existent 'youtubed' metacafe url" do
84
+ let(:videotron) { UnvlogIt.new("http://www.metacafe.com/watch/yt-r07zdVLOWBA/pop_rocks_and_coke_myth/") } # => Pop Rocks and Coke Myth
85
+
86
+ it "initialize a VgMetacafe instance" do
87
+ expect(VgMetacafe).to eq(videotron.instance_values['object'].class)
88
+ expect("http://www.metacafe.com/watch/yt-r07zdVLOWBA/pop_rocks_and_coke_myth/").to eq(videotron.instance_values['object'].instance_values['url'])
89
+ expect(3).to eq(videotron.instance_values['object'].instance_values['args'].size)
90
+ expect("VgYoutube").to eq(videotron.instance_values['object'].instance_values['yt'].class.to_s)
91
+ expect(videotron.instance_values['object'].instance_values['youtubed']).to be true
92
+ end
93
+
94
+ it "returns the video properties" do
95
+ check_video_attributes({:title => "Pop Rocks and Coke Myth", :service => "Metacafe"})
96
+ end
97
+ end
98
+
99
+ # ----------------------------------------------------------
100
+ # Testing dailymotion
101
+ # ----------------------------------------------------------
102
+
103
+ context "with an existent dailymotion url" do
104
+ let(:videotron) { UnvlogIt.new("http://www.dailymotion.com/video/x7u5kn_parkour-dayyy_sport/") } # => parkour dayyy
105
+
106
+ it "initialize a VgDailymotion instance" do
107
+ expect(VgDailymotion).to eq(videotron.instance_values['object'].class)
108
+ expect("http://www.dailymotion.com/video/x7u5kn_parkour-dayyy_sport/").to eq(videotron.instance_values['object'].instance_values['url'])
109
+ expect("x7u5kn_parkour-dayyy_sport").to eq(videotron.instance_values['object'].instance_values['video_id'])
110
+ expect(videotron.instance_values['object'].instance_values['feed']).to_not be_nil
111
+ end
112
+
113
+ it "returns the video properties" do
114
+ check_video_attributes({:title => "parkour dayyy", :service => "Dailymotion"})
115
+ end
116
+ end
117
+
118
+ # ----------------------------------------------------------
119
+ # Testing collegehumor
120
+ # ----------------------------------------------------------
121
+
122
+ context "with an existent collegehumor url" do
123
+ let(:videotron) { UnvlogIt.new("http://www.collegehumor.com/video/3005349/brohemian-rhapsody/") } # => Brohemian Rhapsody
124
+
125
+ it "initialize a VgCollegehumor instance" do
126
+ expect(VgCollegehumor).to eq(videotron.instance_values['object'].class)
127
+ expect("http://www.collegehumor.com/video/3005349/brohemian-rhapsody/").to eq(videotron.instance_values['object'].instance_values['url'])
128
+ expect("3005349").to eq(videotron.instance_values['object'].instance_values['video_id'])
129
+ expect(videotron.instance_values['object'].instance_values['feed']).to_not be_nil
130
+ end
131
+
132
+ it "returns the video properties" do
133
+ check_video_attributes({:title => "Brohemian Rhapsody", :service => "CollegeHumor"})
134
+ end
135
+ end
136
+
137
+ # ----------------------------------------------------------
138
+ # Testing blip.tv
139
+ # ----------------------------------------------------------
140
+
141
+ context "with an existent blip.tv url" do
142
+ let(:videotron) { UnvlogIt.new("http://blip.tv/sarahrdtv/sarah-s-super-bowl-spread-healthy-recipe-classic-buffalo-wing-dip-6717535") } # => Sarah's Super Bowl Spread – Healthy Recipe - Classic Buffalo Wing Dip
143
+
144
+ it "initialize a VgBlip instance" do
145
+ expect(VgBlip).to eq(videotron.instance_values['object'].class)
146
+ expect("http://blip.tv/sarahrdtv/sarah-s-super-bowl-spread-healthy-recipe-classic-buffalo-wing-dip-6717535").to eq(videotron.instance_values['object'].instance_values['url'])
147
+ expect(videotron.instance_values['object'].instance_values['feed']).to_not be_nil
148
+ end
149
+
150
+ it "returns the video properties" do
151
+ check_video_attributes({:title => "Sarah's Super Bowl Spread &#8211; Healthy Recipe - Classic Buffalo Wing Dip", :service => "Blip.tv"})
152
+ end
153
+ end
154
+
155
+ # ----------------------------------------------------------
156
+ # Testing myspace.com
157
+ # ----------------------------------------------------------
158
+ context "with an existent myspace.com url" do
159
+ let(:videotron) { UnvlogIt.new("https://myspace.com/jimmykimmellive/video/mastodon-the-motherload-/109586961") } # => Mastodon - The Motherload
160
+
161
+ it "initialize a VgMyspace instance" do
162
+ expect(VgMyspace).to eq(videotron.instance_values['object'].class)
163
+ expect("https://myspace.com/jimmykimmellive/video/mastodon-the-motherload-/109586961").to eq(videotron.instance_values['object'].instance_values['url'])
164
+ expect(videotron.instance_values['object'].instance_values['page']).to_not be_nil
165
+ end
166
+
167
+ it "returns the video properties" do
168
+ check_video_attributes({:title => "Mastodon - The Motherload", :service => "Myspace"})
169
+ end
170
+ end
171
+
172
+
173
+ # ----------------------------------------------------------
174
+ # Testing 11870.com
175
+ # ----------------------------------------------------------
176
+ context "with an existent 11870.com url" do
177
+ let(:videotron) { UnvlogIt.new("http://11870.com/pro/chic-basic-born/media/b606abfe") } # => Chic & Basic Born
178
+
179
+ it "initialize a Vg11870 instance" do
180
+ expect(Vg11870).to eq(videotron.instance_values['object'].class)
181
+ expect("https://11870.com/pro/chic-basic-born/media/b606abfe").to eq(videotron.instance_values['object'].instance_values['url'])
182
+ expect(videotron.instance_values['object'].instance_values['page']).to_not be_nil
183
+ end
184
+
185
+ it "returns the video properties" do
186
+ check_video_attributes({:title => "Chic & Basic Born", :service => "11870.com"})
187
+ end
188
+ end
189
+
190
+
191
+ # ----------------------------------------------------------
192
+ # Testing dalealplay.com
193
+ # ----------------------------------------------------------
194
+ context "with an existent dalealplay.com url" do
195
+ let(:videotron) { UnvlogIt.new("http://www.dalealplay.com/informaciondecontenido.php?con=80280") } # => Camelos Semos Jonathan Tú si que vales
196
+
197
+ it "initialize a VgDalealplay instance" do
198
+ expect(VgDalealplay).to eq(videotron.instance_values['object'].class)
199
+ expect("http://www.dalealplay.com/informaciondecontenido.php?con=80280").to eq(videotron.instance_values['object'].instance_values['url'])
200
+ expect("80280").to eq(videotron.instance_values['object'].instance_values['video_id'])
201
+ expect(videotron.instance_values['object'].instance_values['page']).to_not be_nil
202
+ end
203
+
204
+ it "returns the video properties" do
205
+ check_video_attributes({:title => "Camelos.Semos. Jonathan. Tú si que vales.", :service => "dalealplay"})
206
+ end
207
+ end
208
+
209
+
210
+ # ----------------------------------------------------------
211
+ # Testing flickr.com
212
+ # ----------------------------------------------------------
213
+ context "with a flickr.com video url" do
214
+ let(:videotron) { UnvlogIt.new("http://www.flickr.com/photos/jerovital/4152225414/", {:key => "065b2eff5e604e2a408c01af1f27a982" }) }# => flipando en los columpios
215
+
216
+ it "initialize a VgFlickr instance" do
217
+ expect(VgFlickr).to eq(videotron.instance_values['object'].class)
218
+ expect("http://www.flickr.com/photos/jerovital/4152225414/").to eq(videotron.instance_values['object'].instance_values['url'])
219
+ expect("4152225414").to eq(videotron.instance_values['object'].instance_values['video_id'])
220
+ expect(videotron.instance_values['object'].instance_values['details']).to_not be_nil
221
+ end
222
+
223
+ it "returns the video properties" do
224
+ check_video_attributes({:title => "flipando en los columpios", :service => "Flickr"})
225
+ end
226
+ end
227
+
228
+
229
+ # ----------------------------------------------------------
230
+ # Testing ted talks
231
+ # ----------------------------------------------------------
232
+ context "with an existent ted talks url" do
233
+ let(:videotron) { UnvlogIt.new("http://www.ted.com/talks/benjamin_wallace_on_the_price_of_happiness") } # => Benjamin Wallace: Does happiness have a price tag?
234
+
235
+ it "initialize a VgTed instance" do
236
+ expect(VgTed).to eq(videotron.instance_values['object'].class)
237
+ expect("http://www.ted.com/talks/benjamin_wallace_on_the_price_of_happiness").to eq(videotron.instance_values['object'].instance_values['url'])
238
+ expect(videotron.instance_values['object'].instance_values['page']).to_not be_nil
239
+ end
240
+
241
+ it "returns the video properties" do
242
+ check_video_attributes({:title => "The price of happiness", :service => "Ted Talks"})
243
+ end
244
+ end
245
+
246
+ context "with a non existent ted talks url" do
247
+ it "should raise an error" do
248
+ expect{ UnvlogIt.new("http://www.ted.com/index.php/wadus.html") }.to raise_error(ArgumentError, "Unsuported url or service")
249
+ end
250
+ end
251
+
252
+
253
+ # ----------------------------------------------------------
254
+ # Testing vimeo
255
+ # ----------------------------------------------------------
256
+ context "with an existent vimeo url" do
257
+ let(:videotron) { UnvlogIt.new("http://vimeo.com/119318850") } # => Gotham City SF // A Timelapse Film
258
+
259
+ it "initialize a VgVimeo instance" do
260
+ expect(VgVimeo).to eq(videotron.instance_values['object'].class)
261
+ expect("http://vimeo.com/119318850").to eq(videotron.instance_values['object'].instance_values['url'])
262
+ expect("119318850").to eq(videotron.instance_values['object'].instance_values['video_id'])
263
+ expect(videotron.instance_values['object'].instance_values['feed']).to_not be_nil
264
+ end
265
+
266
+ it "returns the video properties" do
267
+ check_video_attributes({:title => "Gotham City SF // A Timelapse Film", :service => "Vimeo"})
268
+ end
269
+ end
270
+
271
+
272
+ # ----------------------------------------------------------
273
+ # Testing RuTube
274
+ # ----------------------------------------------------------
275
+ context "with an existent rutube url" do
276
+ let(:videotron) { UnvlogIt.new("http://rutube.ru/video/520685fa20c456e200e683f3df17b131/") } # => chipmunks!!
277
+
278
+ it "initialize a VgRutube instance" do
279
+ expect(VgRutube).to eq(videotron.instance_values['object'].class)
280
+ expect("http://rutube.ru/video/520685fa20c456e200e683f3df17b131/").to eq(videotron.instance_values['object'].instance_values['url'])
281
+ expect(videotron.instance_values['object'].instance_values['page']).to_not be_nil
282
+ end
283
+
284
+ it "returns the video properties" do
285
+ check_video_attributes({:title => "Запасливые бурундуки", :service => "Rutube"})
286
+ end
287
+ end
288
+
289
+ context "with an invalid rutube url" do
290
+ it "should raise an error" do
291
+ expect{ UnvlogIt.new("http://rutube.ru/tracks/abdcd.html?v=523423") }.to raise_error(ArgumentError, "Unsuported url or service")
292
+ end
293
+ end
294
+
295
+ # ----------------------------------------------------------
296
+ # Testing Prostopleer
297
+ # ----------------------------------------------------------
298
+ context "with an existent pleer url" do
299
+ let(:videotron) { UnvlogIt.new("http://pleer.com/tracks/3370305QRJl") } # => La mala rodriguez, Nach Scratch SFDK - Dominicana
300
+
301
+ it "initialize a VgPleer instance" do
302
+ expect(VgPleer).to eq(videotron.instance_values['object'].class)
303
+ expect("http://pleer.com/tracks/3370305QRJl").to eq(videotron.instance_values['object'].instance_values['url'])
304
+ expect("3370305QRJl").to eq(videotron.instance_values['object'].instance_values['track_id'])
305
+ expect("Pleer").to eq(videotron.service)
306
+ expect(videotron.embed_html).not_to be_nil
307
+ expect("La mala rodriguez, Nach Scratch SFDK - Dominicana").to eq(videotron.title)
308
+ end
309
+ end
310
+
311
+ context "with an invalid pleer url" do
312
+ it "should raise an error" do
313
+ expect{ UnvlogIt.new("http://prostopleer.com/trackszz/401758bI6n") }.to raise_error(ArgumentError, "Unsuported url or service")
314
+ end
315
+ end
316
+
317
+
318
+ # ----------------------------------------------------------
319
+ # Testing Wistia
320
+ # ----------------------------------------------------------
321
+ context "with an existent wistia url" do
322
+ let(:videotron) { UnvlogIt.new("https://home.wistia.com/medias/e4a27b971d") } # => Brendan - Make It Clap
323
+
324
+ it "initialize a VgWistia instance" do
325
+ expect(VgWistia).to eq(videotron.instance_values['object'].class)
326
+ expect("https://home.wistia.com/medias/e4a27b971d").to eq(videotron.instance_values['object'].instance_values['url'])
327
+ end
328
+
329
+ it "returns the video properties" do
330
+ check_video_attributes({
331
+ :title => "Brendan - Make It Clap",
332
+ :service => "Wistia, Inc.",
333
+ :duration => 16.43,
334
+ :thumbnail => "https://embed-ssl.wistia.com/deliveries/2d2c14e15face1e0cc7aac98ebd5b6f040b950b5.jpg?image_crop_resized=640x360"
335
+ })
336
+ end
337
+ end
338
+
339
+ context "with a non existent wistia url" do
340
+ it "should raise an error" do
341
+ expect{ UnvlogIt.new("https://gadabouting.wistia.com/medias/inexistent") }.to raise_error(ArgumentError, "Unsuported url or service")
342
+ end
343
+ end
344
+
345
+ protected
346
+
347
+ def check_video_attributes(options={})
348
+ expect(options[:title]).to eq(videotron.title) unless (options.blank? || options[:title].blank?)
349
+ expect(options[:service]).to eq(videotron.service) unless (options.blank? || options[:service].blank?)
350
+ expect(videotron.thumbnail).not_to be_nil
351
+ if options.blank? || options[:noembed].blank?
352
+ expect(videotron.embed_url).not_to be_nil
353
+ expect(videotron.embed_html).not_to be_nil
354
+ elsif options[:noembed]
355
+ expect(videotron.embed_url).to be_nil
356
+ expect(videotron.embed_html).to be_nil
357
+ expect(videotron.video_details[:embed_url]).to be_nil
358
+ expect(videotron.video_details[:embed_html]).to be_nil
359
+ end
360
+ expect(videotron.flv).to be_nil
361
+ expect(Hash).to eq(videotron.video_details.class)
362
+ end
363
+ end