mdarby-acts_as_video_fu 1.0

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/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=[^&]*$/
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
+ klass(obj).embed_html
7
+ end
8
+
9
+ def thumbnail_url(obj)
10
+ klass(obj).thumbnail_url
11
+ end
12
+
13
+
14
+ private
15
+
16
+ def klass(obj)
17
+ obj.type.new(obj)
18
+ end
19
+
20
+ end
21
+ end
22
+ end
data/lib/vimeo.rb ADDED
@@ -0,0 +1,20 @@
1
+ class Vimeo
2
+ include HTTParty
3
+ format :json
4
+ base_uri 'vimeo.com'
5
+ default_params :output => 'json'
6
+
7
+ def initialize(obj)
8
+ @clip_id = obj.video_url.split('/').last
9
+ @response = self.class.get('/api/oembed.json', :query => {:url => "http://vimeo.com/#{@clip_id}"})
10
+ end
11
+
12
+ def thumbnail_url
13
+ @response["thumbnail_url"]
14
+ end
15
+
16
+ def embed_html
17
+ @response["html"]
18
+ end
19
+
20
+ 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"]["group"]["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,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mdarby-acts_as_video_fu
3
+ version: !ruby/object:Gem::Version
4
+ version: "1.0"
5
+ platform: ruby
6
+ authors:
7
+ - Matt Darby
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-12-14 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: httparty
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 0.2.2
23
+ version:
24
+ description: Rails plugin that easily allows you to show video streams on your site.
25
+ email: matt@matt-darby.com
26
+ executables: []
27
+
28
+ extensions: []
29
+
30
+ extra_rdoc_files: []
31
+
32
+ files:
33
+ - init.rb
34
+ - install.rb
35
+ - lib/acts_as_video_fu.rb
36
+ - lib/acts_as_video_fu_helper.rb
37
+ - lib/vimeo.rb
38
+ - lib/you_tube.rb
39
+ - MIT-LICENSE
40
+ - rails/init.rb
41
+ - Rakefile
42
+ - README
43
+ - tasks/acts_as_video_fu_tasks.rake
44
+ - test/acts_as_video_fu_test.rb
45
+ - uninstall.rb
46
+ has_rdoc: false
47
+ homepage: http://github.com/mdarby/acts_as_video_fu/tree/master
48
+ post_install_message:
49
+ rdoc_options: []
50
+
51
+ require_paths:
52
+ - lib
53
+ required_ruby_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: "0"
58
+ version:
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: "0"
64
+ version:
65
+ requirements: []
66
+
67
+ rubyforge_project:
68
+ rubygems_version: 1.2.0
69
+ signing_key:
70
+ specification_version: 2
71
+ summary: Rails plugin that easily allows you to show video streams on your site.
72
+ test_files: []
73
+