acts_as_video_fu 1.3

Sign up to get free protection for your applications and to get access to all the features.
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008 [name of plugin creator]
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.textile ADDED
@@ -0,0 +1,41 @@
1
+ h2. ActsAsVideoFu
2
+
3
+ A Rails plugin that easily allows you to show video streams on your site.
4
+ Currently, YouTube and Vimeo streams are supported.
5
+
6
+ <pre>
7
+ Note that #video_url is expected to be in these formats:
8
+
9
+ YouTube: http://www.youtube.com/watch?v=gEILFf2XSrM
10
+ Vimeo: http://www.vimeo.com/726135
11
+ </pre>
12
+
13
+
14
+ h3. Installation
15
+
16
+ # Install the gem
17
+ <pre>sudo gem install mdarby-acts_as_video_fu</pre>
18
+
19
+ # Require the gem in your config/environment.rb file
20
+ <pre>config.gem 'mdarby-acts_as_video_fu', :lib => 'acts_as_video_fu'</pre>
21
+
22
+
23
+ h3. Example
24
+
25
+ # Generate a resource that includes the title:string and video_url:string attributes
26
+ <pre>./script/generate scaffold Video title:string video_url:string</pre>
27
+
28
+ # Add 'acts_as_video_fu' to your model
29
+ <pre>
30
+ class Video < ActiveRecord::Base
31
+ acts_as_video_fu
32
+ end
33
+ </pre>
34
+
35
+ # Show the video's thumbnail in any view you might like
36
+ <pre><%= image_tag thumbnail_url(video) %></pre>
37
+
38
+ # Add the 'display_video' helper to show the full-sized video in any view you might like
39
+ <pre><%= display_video(@video) %></pre>
40
+
41
+ Copyright (c) 2008 Matt Darby, released under the MIT license
data/Rakefile ADDED
@@ -0,0 +1,22 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/rdoctask'
4
+
5
+ desc 'Default: run unit tests.'
6
+ task :default => :test
7
+
8
+ desc 'Test the acts_as_video_fu plugin.'
9
+ Rake::TestTask.new(:test) do |t|
10
+ t.libs << 'lib'
11
+ t.pattern = 'test/**/*_test.rb'
12
+ t.verbose = true
13
+ end
14
+
15
+ desc 'Generate documentation for the acts_as_video_fu plugin.'
16
+ Rake::RDocTask.new(:rdoc) do |rdoc|
17
+ rdoc.rdoc_dir = 'rdoc'
18
+ rdoc.title = 'ActsAsVideoFu'
19
+ rdoc.options << '--line-numbers' << '--inline-source'
20
+ rdoc.rdoc_files.include('README')
21
+ rdoc.rdoc_files.include('lib/**/*.rb')
22
+ end
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require File.dirname(__FILE__) + "/rails/init"
data/install.rb ADDED
@@ -0,0 +1 @@
1
+ # Install hook code here
@@ -0,0 +1,55 @@
1
+ module Mdarby
2
+ module Acts #:nodoc:
3
+ module Acts_as_video_fu #:nodoc:
4
+
5
+ VIMEO_RE = /^http:\/\/(www\.vimeo|vimeo)\.com\/[0-9]*$/
6
+ YOUTUBE_RE = /^http:\/\/(www\.youtube|youtube)\.com\/watch\?v=[^&]*(&.*){0,}$/
7
+
8
+ def self.included(base)
9
+ base.extend ClassMethods
10
+ end
11
+
12
+ module ClassMethods
13
+ def acts_as_video_fu
14
+ include Mdarby::Acts::Acts_as_video_fu::InstanceMethods
15
+ extend Mdarby::Acts::Acts_as_video_fu::SingletonMethods
16
+
17
+ before_save :validate
18
+ end
19
+ end
20
+
21
+ module SingletonMethods
22
+ end
23
+
24
+ module InstanceMethods
25
+
26
+ def type
27
+ return YouTube if youtube?
28
+ return Vimeo if vimeo?
29
+ return false
30
+ end
31
+
32
+ def youtube?
33
+ YOUTUBE_RE =~ video_url
34
+ end
35
+
36
+ def vimeo?
37
+ VIMEO_RE =~ video_url
38
+ end
39
+
40
+
41
+ private
42
+
43
+ def validate
44
+ raise "#{self.class.to_s}#video_url doesn't exist!" unless respond_to?(:video_url)
45
+
46
+ unless video_url.blank?
47
+ errors.add_to_base("Video URL has whitespace") if video_url.strip!
48
+ errors.add_to_base("Video URL is not recognized") unless type
49
+ end
50
+ end
51
+
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,22 @@
1
+ module Mdarby
2
+ module Acts #:nodoc:
3
+ module Acts_as_video_fu_helper
4
+
5
+ def display_video(obj)
6
+ video_klass(obj).embed_html
7
+ end
8
+
9
+ def thumbnail_url(obj)
10
+ video_klass(obj).thumbnail_url
11
+ end
12
+
13
+
14
+ private
15
+
16
+ def video_klass(obj)
17
+ obj.type.new(obj)
18
+ end
19
+
20
+ end
21
+ end
22
+ end
data/lib/vimeo.rb ADDED
@@ -0,0 +1,28 @@
1
+ class VimeoError < StandardError; end
2
+
3
+ class Vimeo
4
+ include HTTParty
5
+ format :json
6
+ base_uri 'vimeo.com'
7
+ default_params :output => 'json'
8
+
9
+ def initialize(obj)
10
+ @clip_id = obj.video_url.split('/').last
11
+ @response = self.class.get('/api/oembed.json', :query => {:url => "http://vimeo.com/#{@clip_id}"})
12
+
13
+ raise blank_error(obj) if @response.blank?
14
+ end
15
+
16
+ def blank_error(obj)
17
+ raise VimeoError, "Vimeo returned a blank response for this video: #{obj.video_url}"
18
+ end
19
+
20
+ def thumbnail_url
21
+ @response["thumbnail_url"]
22
+ end
23
+
24
+ def embed_html
25
+ @response["html"]
26
+ end
27
+
28
+ end
data/lib/you_tube.rb ADDED
@@ -0,0 +1,27 @@
1
+ class YouTube
2
+ include HTTParty
3
+ format :xml
4
+ base_uri 'gdata.youtube.com'
5
+ default_params :output => 'xml'
6
+
7
+ def initialize(obj)
8
+ @clip_id = obj.video_url.split('?v=').last
9
+ @embed_url = "http://www.youtube.com/v/#{@clip_id}&hl=en&fs=1"
10
+ @response = self.class.get("/feeds/api/videos/#{@clip_id}")
11
+ end
12
+
13
+ def thumbnail_url
14
+ @response["entry"]["media:group"]["media:thumbnail"][0]["url"]
15
+ end
16
+
17
+ def embed_html
18
+ <<-END
19
+ <object width="425" height="344">
20
+ <param name="movie" value="#{@embed_url}" />
21
+ <param name="allowFullScreen" value="true" />
22
+ <embed src="#{@embed_url}" type="application/x-shockwave-flash" allowfullscreen="true" width="425" height="344" />
23
+ </object>
24
+ END
25
+ end
26
+
27
+ end
data/rails/init.rb ADDED
@@ -0,0 +1,8 @@
1
+ require 'httparty'
2
+ require 'acts_as_video_fu'
3
+ require 'acts_as_video_fu_helper'
4
+
5
+ ActiveRecord::Base.send(:include, Mdarby::Acts::Acts_as_video_fu)
6
+ ActionView::Base.send(:include, Mdarby::Acts::Acts_as_video_fu_helper)
7
+
8
+ RAILS_DEFAULT_LOGGER.debug "** [acts_as_video_fu] loaded"
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :acts_as_video_fu do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,8 @@
1
+ require 'test/unit'
2
+
3
+ class ActsAsVideoFuTest < Test::Unit::TestCase
4
+ # Replace this with your real tests.
5
+ def test_this_plugin
6
+ flunk
7
+ end
8
+ end
data/uninstall.rb ADDED
@@ -0,0 +1 @@
1
+ # Uninstall hook code here
metadata ADDED
@@ -0,0 +1,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: acts_as_video_fu
3
+ version: !ruby/object:Gem::Version
4
+ version: "1.3"
5
+ platform: ruby
6
+ authors:
7
+ - Matt Darby
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-03-15 00:00:00 -04:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: httparty
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 0.3.1
24
+ version:
25
+ description: Rails plugin that easily allows you to show video streams on your site.
26
+ email: matt@matt-darby.com
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files: []
32
+
33
+ files:
34
+ - init.rb
35
+ - install.rb
36
+ - lib/acts_as_video_fu.rb
37
+ - lib/acts_as_video_fu_helper.rb
38
+ - lib/vimeo.rb
39
+ - lib/you_tube.rb
40
+ - MIT-LICENSE
41
+ - rails/init.rb
42
+ - Rakefile
43
+ - README.textile
44
+ - tasks/acts_as_video_fu_tasks.rake
45
+ - test/acts_as_video_fu_test.rb
46
+ - uninstall.rb
47
+ has_rdoc: true
48
+ homepage: http://github.com/mdarby/acts_as_video_fu/tree/master
49
+ licenses: []
50
+
51
+ post_install_message:
52
+ rdoc_options: []
53
+
54
+ require_paths:
55
+ - lib
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: "0"
61
+ version:
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: "0"
67
+ version:
68
+ requirements: []
69
+
70
+ rubyforge_project:
71
+ rubygems_version: 1.3.5
72
+ signing_key:
73
+ specification_version: 3
74
+ summary: Rails plugin that easily allows you to show video streams on your site.
75
+ test_files: []
76
+