refinerycms-vimeo-videos 0.1.9.rc3 → 0.2.rc2
Sign up to get free protection for your applications and to get access to all the features.
- data/.DS_Store +0 -0
- data/README.markdown +1 -1
- data/Rakefile +1 -2
- data/app/.DS_Store +0 -0
- data/{public → app/assets}/javascripts/refinery/vimeo_videos.js +0 -0
- data/{public/stylesheets/admin → app/assets/stylesheets/refinery}/vimeo_videos.css +0 -0
- data/app/controllers/.DS_Store +0 -0
- data/app/controllers/refinery/admin/vimeo_account_controller.rb +56 -0
- data/app/controllers/refinery/admin/vimeo_videos_controller.rb +87 -0
- data/app/models/refinery/vimeo_embed_cache.rb +67 -0
- data/app/models/refinery/vimeo_meta_cache.rb +66 -0
- data/app/models/refinery/vimeo_video.rb +23 -0
- data/app/views/.DS_Store +0 -0
- data/app/views/{shared → refinery}/admin/_vimeo_picker.html.erb +5 -4
- data/app/views/{admin → refinery/admin}/vimeo_videos/_error_message.html.erb +0 -0
- data/app/views/{admin → refinery/admin}/vimeo_videos/_existing_vimeo_video.html.erb +3 -1
- data/app/views/{admin → refinery/admin}/vimeo_videos/_form.html.erb +3 -3
- data/app/views/{admin → refinery/admin}/vimeo_videos/_vimeo_video.html.haml +0 -0
- data/app/views/{admin → refinery/admin}/vimeo_videos/index.js.erb +0 -0
- data/app/views/{admin → refinery/admin}/vimeo_videos/insert.html.erb +2 -2
- data/config/locales/en.yml +1 -1
- data/config/routes.rb +8 -6
- data/db/migrate/create_vimeo_embed_cache.rb +6 -2
- data/db/migrate/create_vimeo_meta_cache.rb +6 -6
- data/db/migrate/create_vimeo_videos.rb +6 -2
- data/lib/generators/vimeo_videos_generator.rb +10 -0
- data/lib/{refinerycms-vimeo-videos → refinery/vimeo-videos}/account.rb +5 -5
- data/lib/{refinerycms-vimeo-videos → refinery/vimeo-videos}/active_record.rb +2 -2
- data/lib/{refinerycms-vimeo-videos → refinery/vimeo-videos}/url_tempfile.rb +0 -0
- data/lib/{refinerycms-vimeo-videos → refinery/vimeo-videos}/version.rb +1 -1
- data/lib/refinerycms-vimeo-videos.rb +19 -12
- data/refinerycms-vimeo-videos.gemspec +4 -3
- data/spec/controllers/admin/vimeo_account_controller_spec.rb +9 -9
- data/spec/models/active_record_extension_spec.rb +4 -4
- metadata +32 -32
- data/app/controllers/admin/vimeo_account_controller.rb +0 -54
- data/app/controllers/admin/vimeo_videos_controller.rb +0 -87
- data/app/models/vimeo_embed_cache.rb +0 -67
- data/app/models/vimeo_meta_cache.rb +0 -59
- data/app/models/vimeo_video.rb +0 -21
- data/db/seeds/vimeo_videos.rb +0 -6
- data/lib/generators/refinerycms_vimeo_videos_generator.rb +0 -6
data/.DS_Store
ADDED
Binary file
|
data/README.markdown
CHANGED
@@ -40,7 +40,7 @@ In your _form.html.erb insert this:
|
|
40
40
|
|
41
41
|
<div class='field'>
|
42
42
|
<%= f.label "Test Video" -%>
|
43
|
-
<%= render :partial => "/
|
43
|
+
<%= render :partial => "/refinery/admin/vimeo_picker", :locals => {
|
44
44
|
:f => f,
|
45
45
|
:field => :test_video_id,
|
46
46
|
:vimeo_video => @project.test_video
|
data/Rakefile
CHANGED
@@ -1,2 +1 @@
|
|
1
|
-
require 'bundler'
|
2
|
-
Bundler::GemHelper.install_tasks
|
1
|
+
require 'bundler/gem_tasks'
|
data/app/.DS_Store
ADDED
Binary file
|
File without changes
|
File without changes
|
Binary file
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module ::Refinery
|
2
|
+
module Admin
|
3
|
+
class VimeoAccountController < ::Refinery::AdminController
|
4
|
+
|
5
|
+
include ::Refinery::VimeoVideos::Account
|
6
|
+
|
7
|
+
def authorization
|
8
|
+
|
9
|
+
if not authorized? and ready_to_authorize?
|
10
|
+
|
11
|
+
# begin authorization process
|
12
|
+
base = ::Vimeo::Advanced::Base.new(
|
13
|
+
account[:consumer_key],
|
14
|
+
account[:consumer_secret])
|
15
|
+
request_token = base.get_request_token
|
16
|
+
session[:oauth_secret] = request_token.secret
|
17
|
+
|
18
|
+
redirect_to base.authorize_url
|
19
|
+
|
20
|
+
elsif ready_to_authorize?
|
21
|
+
|
22
|
+
# already authorized
|
23
|
+
flash.notice = "You have already authorized your account."
|
24
|
+
redirect_to refinery_root_path
|
25
|
+
|
26
|
+
else
|
27
|
+
|
28
|
+
# not ready to authorize
|
29
|
+
flash.alert = "You are not ready to authorize. Type in consumer_key and consumer_secret."
|
30
|
+
redirect_to refinery_root_path
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def callback
|
36
|
+
|
37
|
+
# vimeo will redirect us here upon successful authorization
|
38
|
+
base = ::Vimeo::Advanced::Base.new(
|
39
|
+
account[:consumer_key],
|
40
|
+
account[:consumer_secret])
|
41
|
+
access_token = base.get_access_token(params[:oauth_token], session[:oauth_secret], params[:oauth_verifier])
|
42
|
+
::Refinery::Setting.find_by_name('vimeo_token').update_attribute(:value, access_token.token)
|
43
|
+
::Refinery::Setting.find_by_name('vimeo_secret').update_attribute(:value, access_token.secret)
|
44
|
+
flash.notice = "You successfully authorized your vimeo account for integration in your backend. You can now start using it."
|
45
|
+
redirect_to main_app.refinery_admin_root_path
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
protected
|
50
|
+
|
51
|
+
def restrict_controller
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
class VimeoAuthorizationError < StandardError; end
|
2
|
+
|
3
|
+
module ::Refinery
|
4
|
+
module Admin
|
5
|
+
class VimeoVideosController < ::Refinery::AdminController
|
6
|
+
|
7
|
+
include ::Refinery::VimeoVideos::Account
|
8
|
+
|
9
|
+
before_filter :ensure_authorized!
|
10
|
+
before_filter :init_dialog
|
11
|
+
|
12
|
+
def index
|
13
|
+
get_videos_on_vimeo_account
|
14
|
+
end
|
15
|
+
|
16
|
+
def new
|
17
|
+
@vimeo_video = VimeoVideo.new
|
18
|
+
end
|
19
|
+
|
20
|
+
def create
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
def insert
|
25
|
+
self.new if @vimeo_video.nil?
|
26
|
+
|
27
|
+
@url_override = main_app.refinery_admin_vimeo_videos_path(request.query_parameters.merge(:insert => true))
|
28
|
+
|
29
|
+
if params[:conditions].present?
|
30
|
+
extra_condition = params[:conditions].split(',')
|
31
|
+
|
32
|
+
extra_condition[1] = true if extra_condition[1] == "true"
|
33
|
+
extra_condition[1] = false if extra_condition[1] == "false"
|
34
|
+
extra_condition[1] = nil if extra_condition[1] == "nil"
|
35
|
+
paginate_vimeo_videos({extra_condition[0].to_sym => extra_condition[1]})
|
36
|
+
else
|
37
|
+
paginate_vimeo_videos
|
38
|
+
end
|
39
|
+
render :action => "insert"
|
40
|
+
end
|
41
|
+
|
42
|
+
protected
|
43
|
+
def get_videos_on_vimeo_account
|
44
|
+
video = ::Vimeo::Advanced::Video.new(
|
45
|
+
account[:consumer_key],
|
46
|
+
account[:consumer_secret],
|
47
|
+
:token => account[:token],
|
48
|
+
:secret => account[:secret])
|
49
|
+
@vimeo_videos = video.get_all(account[:username], {:full_response => true, :sort => 'upload_date'})["videos"]["video"]
|
50
|
+
end
|
51
|
+
|
52
|
+
def init_dialog
|
53
|
+
@app_dialog = params[:app_dialog].present?
|
54
|
+
@field = params[:field]
|
55
|
+
@update_vimeo_video = params[:update_vimeo_video]
|
56
|
+
@update_text = params[:update_text]
|
57
|
+
@thumbnail = params[:thumbnail]
|
58
|
+
@callback = params[:callback]
|
59
|
+
@conditions = params[:conditions]
|
60
|
+
@current_link = params[:current_link]
|
61
|
+
end
|
62
|
+
|
63
|
+
def restrict_controller
|
64
|
+
super unless action_name == 'insert'
|
65
|
+
end
|
66
|
+
|
67
|
+
def paginate_vimeo_videos
|
68
|
+
@vimeo_videos = get_videos_on_vimeo_account.paginate(:page => (@paginate_page_number ||= params[:page]), :per_page => ::Refinery::VimeoVideo.per_page(from_dialog?))
|
69
|
+
end
|
70
|
+
|
71
|
+
def ensure_authorized!
|
72
|
+
begin
|
73
|
+
|
74
|
+
raise VimeoAuthorizationError unless authorized?
|
75
|
+
|
76
|
+
rescue VimeoAuthorizationError => exception
|
77
|
+
|
78
|
+
message = 'You have not authorized your vimeo account with this application.'
|
79
|
+
render :partial => 'error_message', :locals => {
|
80
|
+
:message => message
|
81
|
+
}
|
82
|
+
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
module Refinery
|
3
|
+
class VimeoEmbedCache < ActiveRecord::Base
|
4
|
+
|
5
|
+
set_table_name "refinery_vimeo_embed_cache"
|
6
|
+
|
7
|
+
belongs_to :vimeo_video
|
8
|
+
|
9
|
+
before_save :cache
|
10
|
+
|
11
|
+
serialize :configuration, Hash
|
12
|
+
|
13
|
+
validates_presence_of :configuration
|
14
|
+
validates_presence_of :vid
|
15
|
+
|
16
|
+
def self.embed vid, geometry, configuration = {}
|
17
|
+
configuration.stringify_keys!
|
18
|
+
configuration.merge!(geometry_hash(geometry))
|
19
|
+
|
20
|
+
static = configuration.delete("static") if configuration.has_key?("static")
|
21
|
+
if static
|
22
|
+
geometry =~ FIXED_GEOMETRY ?
|
23
|
+
static_embed_code(vid, geometry).html_safe : raise(ArgumentError, "Must use fixed geometry string for static embeds (e.g. 100x240)")
|
24
|
+
else
|
25
|
+
find_or_create_by_vid_and_configuration(vid, :configuration => ::YAML.dump(configuration)).code.html_safe
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def update_cache
|
30
|
+
cache true
|
31
|
+
self.save
|
32
|
+
end
|
33
|
+
|
34
|
+
FIXED_WIDTH_GEOMETRY = /^(\d+)$/ # e.g. '300'
|
35
|
+
FIXED_HEIGHT_GEOMETRY = /^x(\d+)$/ # e.g. 'x200'
|
36
|
+
FIXED_GEOMETRY = /^(\d+)x(\d+)$/ # e.g. '300x200'
|
37
|
+
VIMEO_GEOMETRY = ::Regexp.union FIXED_GEOMETRY, FIXED_HEIGHT_GEOMETRY, FIXED_WIDTH_GEOMETRY
|
38
|
+
|
39
|
+
def self.geometry_hash geometry
|
40
|
+
case geometry
|
41
|
+
when FIXED_WIDTH_GEOMETRY
|
42
|
+
{:width => $1}
|
43
|
+
when FIXED_HEIGHT_GEOMETRY
|
44
|
+
{:height => $1}
|
45
|
+
when FIXED_GEOMETRY
|
46
|
+
{:width => $1, :height => $2}
|
47
|
+
else raise ArgumentError, "Didn't recognise the geometry string #{geometry}"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def self.static_embed_code vid, geometry
|
54
|
+
width, height = geometry.split('x')
|
55
|
+
"<iframe src=\"http://player.vimeo.com/video/#{vid}?portrait=0\" width=\"#{width}\" height=\"#{height}\" frameborder=\"0\"></iframe>"
|
56
|
+
end
|
57
|
+
|
58
|
+
def cache force = false
|
59
|
+
if self.code.blank? or force
|
60
|
+
# Escape vimeo url and request oembed code
|
61
|
+
url = ::CGI::escape("http://vimeo.com/#{self.vid}")
|
62
|
+
response = ::HTTParty.get "http://vimeo.com/api/oembed.xml?url=#{url}&#{YAML.load(self.configuration).to_query}"
|
63
|
+
self.code = response["oembed"]["html"]
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
module Refinery
|
2
|
+
class VimeoMetaCache < ActiveRecord::Base
|
3
|
+
|
4
|
+
include ::Refinery::VimeoVideos::Account
|
5
|
+
|
6
|
+
set_table_name "refinery_vimeo_meta_cache"
|
7
|
+
|
8
|
+
has_many :vimeo_embed_caches, :dependent => :destroy
|
9
|
+
|
10
|
+
belongs_to :image, :class_name => '::Refinery::Image'
|
11
|
+
|
12
|
+
before_save :cache
|
13
|
+
|
14
|
+
validates_presence_of :vid
|
15
|
+
|
16
|
+
def embed geometry, options = {}
|
17
|
+
::Refinery::VimeoEmbedCache.embed(self.vid, geometry, options)
|
18
|
+
end
|
19
|
+
|
20
|
+
def url
|
21
|
+
"http://www.vimeo.com/#{self.vid}"
|
22
|
+
end
|
23
|
+
|
24
|
+
def update_cache images = false
|
25
|
+
cache true, images
|
26
|
+
self.save
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def cache force = false, images = false
|
32
|
+
if !self.title? or !self.image_id? or !self.description? or force
|
33
|
+
|
34
|
+
video_info_request = ::Vimeo::Advanced::Video.new(
|
35
|
+
account[:consumer_key],
|
36
|
+
account[:consumer_secret],
|
37
|
+
:token => account[:token],
|
38
|
+
:secret => account[:secret])
|
39
|
+
|
40
|
+
video_info = video_info_request.get_info(self.vid)["video"].first
|
41
|
+
|
42
|
+
# By default omitt image if we already have one.
|
43
|
+
# If we force an update, we need to specifically force images as well by
|
44
|
+
# calling this method with force and images true.
|
45
|
+
|
46
|
+
if images or !image_id?
|
47
|
+
# Save fetched image url
|
48
|
+
vimeo_thumb_url = ""
|
49
|
+
(thumbs = video_info["thumbnails"]["thumbnail"]).each_with_index do |thumb, i|
|
50
|
+
vimeo_thumb_url = thumbs[thumbs.size-1-i]["_content"]
|
51
|
+
break unless vimeo_thumb_url =~ /\/defaults\//
|
52
|
+
end
|
53
|
+
|
54
|
+
self.create_image(:image => ::Refinery::VimeoVideos::URLTempfile.new(vimeo_thumb_url))
|
55
|
+
end
|
56
|
+
|
57
|
+
# Save fetched title
|
58
|
+
self.title = video_info["title"] if !self.title? or force
|
59
|
+
|
60
|
+
# Save fetched description
|
61
|
+
self.description = "<p>#{video_info['description']}</p>" if !self.description? or force
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# This model acts as a wrapper for uploaded videos only
|
2
|
+
# Everything else happens directly with the advanced vimeo api
|
3
|
+
|
4
|
+
module Refinery
|
5
|
+
class VimeoVideo < ActiveRecord::Base
|
6
|
+
|
7
|
+
# What is the max resource size a user can upload
|
8
|
+
MAX_SIZE_IN_MB = 1000
|
9
|
+
|
10
|
+
# when a dialog pops up with resources, how many resources per page should there be
|
11
|
+
PAGES_PER_DIALOG = 18
|
12
|
+
|
13
|
+
# when listing resources out in the admin area, how many resources should show per page
|
14
|
+
PAGES_PER_ADMIN_INDEX = 20
|
15
|
+
|
16
|
+
class << self
|
17
|
+
# How many resources per page should be displayed?
|
18
|
+
def per_page(dialog = false)
|
19
|
+
dialog ? PAGES_PER_DIALOG : PAGES_PER_ADMIN_INDEX
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/app/views/.DS_Store
ADDED
Binary file
|
@@ -7,8 +7,7 @@
|
|
7
7
|
thumbnail ||= 'medium'
|
8
8
|
toggle_vimeo_video_display ||= false
|
9
9
|
randomiser = rand(Time.now.yesterday.to_i * Time.now.to_i)
|
10
|
-
current_vimeo_video_link_href =
|
11
|
-
:width => 866, :height => 510)
|
10
|
+
current_vimeo_video_link_href = main_app.insert_refinery_admin_vimeo_videos_path(:dialog => true, :callback => "vimeo_video_picker_#{randomiser}_changed")
|
12
11
|
current_vimeo_video_title = t('.change', :what => description.titleize)
|
13
12
|
-%>
|
14
13
|
<div id='vimeo_video_picker_container_<%= randomiser %>'>
|
@@ -16,9 +15,11 @@
|
|
16
15
|
<%= f.hidden_field field, :class => "current_vimeo_video_id" -%>
|
17
16
|
|
18
17
|
<div class='current_vimeo_video_container'<%= " style='display: none'" if toggle_vimeo_video_display %> style="margin-top: 10px;">
|
19
|
-
<a class='current_vimeo_video_link dialog' href="<%= current_vimeo_video_link_href %>"
|
18
|
+
<a class='current_vimeo_video_link dialog' href="<%= current_vimeo_video_link_href %>"
|
19
|
+
data-dialog-width='866' data-dialog-height='510' data-dialog-title='Pick a video...'
|
20
|
+
style='border: 0px' title='<%= current_vimeo_video_title %>'>
|
20
21
|
<% unless vimeo_video.nil? -%>
|
21
|
-
<%= image_fu vimeo_video.image, ::Image.user_image_sizes[thumbnail.to_sym], :class => "brown_border",
|
22
|
+
<%= image_fu vimeo_video.image, ::Refinery::Image.user_image_sizes[thumbnail.to_sym], :class => "brown_border",
|
22
23
|
:class => "current_picked_vimeo_video" %>
|
23
24
|
<% else -%>
|
24
25
|
<img class="current_picked_vimeo_video" src="" alt="" style='display: none' />
|
File without changes
|
@@ -1,6 +1,6 @@
|
|
1
1
|
<%= form_for [:admin, @vimeo_video], :url => @url_override || @url, :html => {:multipart => true} do |f| %>
|
2
2
|
|
3
|
-
<%= render :partial => "/
|
3
|
+
<%= render :partial => "/refinery/admin/error_messages",
|
4
4
|
:locals => {
|
5
5
|
:object => @vimeo_video,
|
6
6
|
:include_object_name => false
|
@@ -22,12 +22,12 @@
|
|
22
22
|
</div>
|
23
23
|
|
24
24
|
<div class='field'>
|
25
|
-
<label><%= t('.maximum_vimeo_video_size', :megabytes => VimeoVideo::MAX_SIZE_IN_MB) %></label>
|
25
|
+
<label><%= t('.maximum_vimeo_video_size', :megabytes => ::Refinery::VimeoVideo::MAX_SIZE_IN_MB) %></label>
|
26
26
|
</div>
|
27
27
|
|
28
28
|
<input type='hidden' name='wymeditor' value='<%= params[:wymeditor] %>'>
|
29
29
|
|
30
|
-
<%= render :partial => "/
|
30
|
+
<%= render :partial => "/refinery/admin/form_actions",
|
31
31
|
:locals => {
|
32
32
|
:f => f,
|
33
33
|
:continue_editing => false,
|
File without changes
|
File without changes
|
@@ -1,5 +1,5 @@
|
|
1
1
|
<% content_for :stylesheets do %>
|
2
|
-
<%= stylesheet_link_tag "
|
2
|
+
<%= stylesheet_link_tag "refinery/vimeo_videos" %>
|
3
3
|
<% end %>
|
4
4
|
<% content_for :javascripts do %>
|
5
5
|
<%= javascript_include_tag "refinery/vimeo_videos" %>
|
@@ -37,7 +37,7 @@
|
|
37
37
|
<% end %>
|
38
38
|
<% else %>
|
39
39
|
<% flash.now[:error] = t('.no_files') %>
|
40
|
-
<%= render :partial => "/
|
40
|
+
<%= render :partial => "/refinery/admin/form_actions",
|
41
41
|
:locals => {
|
42
42
|
:f => nil,
|
43
43
|
:cancel_url => '',
|
data/config/locales/en.yml
CHANGED
data/config/routes.rb
CHANGED
@@ -1,11 +1,13 @@
|
|
1
1
|
Refinery::Application.routes.draw do
|
2
|
-
scope(:
|
3
|
-
|
4
|
-
|
2
|
+
scope(:module => 'refinery') do
|
3
|
+
scope(:module => 'admin', :path => 'refinery', :as => 'refinery_admin') do
|
4
|
+
get 'vimeo_videos/authorization', :to => 'vimeo_account#authorization'
|
5
|
+
get 'vimeo_videos/callback', :to => 'vimeo_account#callback'
|
5
6
|
|
6
|
-
|
7
|
-
|
8
|
-
|
7
|
+
resources :vimeo_videos, :except => :show do
|
8
|
+
collection do
|
9
|
+
get :insert
|
10
|
+
end
|
9
11
|
end
|
10
12
|
end
|
11
13
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
class CreateVimeoEmbedCache < ActiveRecord::Migration
|
2
2
|
|
3
3
|
def self.up
|
4
|
-
create_table
|
4
|
+
create_table Refinery::VimeoEmbedCache do |t|
|
5
5
|
t.string :vid
|
6
6
|
t.string :code
|
7
7
|
t.text :configuration
|
@@ -12,7 +12,11 @@ class CreateVimeoEmbedCache < ActiveRecord::Migration
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def self.down
|
15
|
-
|
15
|
+
[::VimeoEmbedCache].reject{|m|
|
16
|
+
!(defined?(m) and m.respond_to?(:table_name))
|
17
|
+
}.each do |model|
|
18
|
+
drop_table model.table_name
|
19
|
+
end
|
16
20
|
end
|
17
21
|
|
18
22
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
class CreateVimeoMetaCache < ActiveRecord::Migration
|
2
2
|
|
3
3
|
def self.up
|
4
|
-
create_table
|
4
|
+
create_table Refinery::VimeoMetaCache do |t|
|
5
5
|
t.string :vid, :unique => true
|
6
6
|
t.string :title
|
7
7
|
t.text :description
|
@@ -16,11 +16,11 @@ class CreateVimeoMetaCache < ActiveRecord::Migration
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def self.down
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
19
|
+
[::VimeoMetaCache].reject{|m|
|
20
|
+
!(defined?(m) and m.respond_to?(:table_name))
|
21
|
+
}.each do |model|
|
22
|
+
drop_table model.table_name
|
23
|
+
end
|
24
24
|
end
|
25
25
|
|
26
26
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
class CreateVimeoVideos < ActiveRecord::Migration
|
2
2
|
|
3
3
|
def self.up
|
4
|
-
create_table
|
4
|
+
create_table Refinery::VimeoVideo.table_name do |t|
|
5
5
|
t.string :vid, :unique => true
|
6
6
|
t.string :title
|
7
7
|
t.text :description
|
@@ -12,7 +12,11 @@ class CreateVimeoVideos < ActiveRecord::Migration
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def self.down
|
15
|
-
|
15
|
+
[::VimeoVideo].reject{|m|
|
16
|
+
!(defined?(m) and m.respond_to?(:table_name))
|
17
|
+
}.each do |model|
|
18
|
+
drop_table model.table_name
|
19
|
+
end
|
16
20
|
end
|
17
21
|
|
18
22
|
end
|
@@ -21,11 +21,11 @@ module Refinery
|
|
21
21
|
|
22
22
|
def account
|
23
23
|
@account ||= {
|
24
|
-
:username =>
|
25
|
-
:consumer_key =>
|
26
|
-
:consumer_secret =>
|
27
|
-
:token =>
|
28
|
-
:secret =>
|
24
|
+
:username => ::Refinery::Setting.find_or_set(:vimeo_username, :value => "Username"),
|
25
|
+
:consumer_key => ::Refinery::Setting.find_or_set(:vimeo_consumer_key, :value => "Consumer Key"),
|
26
|
+
:consumer_secret => ::Refinery::Setting.find_or_set(:vimeo_consumer_secret, :value => "Consumer Secret"),
|
27
|
+
:token => ::Refinery::Setting.find_or_set(:vimeo_token, :value => 'Token'),
|
28
|
+
:secret => ::Refinery::Setting.find_or_set(:vimeo_secret, :value => 'Secret')}
|
29
29
|
end
|
30
30
|
|
31
31
|
end
|
@@ -9,7 +9,7 @@ module Refinery
|
|
9
9
|
if self.new_record?
|
10
10
|
self.#{field}_id
|
11
11
|
else
|
12
|
-
self.#{field}_id? ? VimeoMetaCache.find_or_create_by_vid(self.#{field}_id) : nil
|
12
|
+
self.#{field}_id? ? ::Refinery::VimeoMetaCache.find_or_create_by_vid(self.#{field}_id) : nil
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
@@ -17,7 +17,7 @@ module Refinery
|
|
17
17
|
|
18
18
|
def cache_vimeo_meta_for_#{field}
|
19
19
|
if self.#{field}_id? and self.#{field}_id_changed?
|
20
|
-
VimeoMetaCache.find_or_create_by_vid(self.#{field}_id)
|
20
|
+
::Refinery::VimeoMetaCache.find_or_create_by_vid(self.#{field}_id)
|
21
21
|
end
|
22
22
|
end
|
23
23
|
protected :cache_vimeo_meta_for_#{field}
|
File without changes
|
@@ -1,21 +1,26 @@
|
|
1
1
|
require 'vimeo'
|
2
|
-
require '
|
2
|
+
require 'will_paginate/array'
|
3
|
+
require File.expand_path('../refinery/vimeo-videos/version', __FILE__)
|
4
|
+
require File.expand_path('../generators/vimeo_videos_generator', __FILE__)
|
3
5
|
|
4
6
|
module Refinery
|
5
7
|
module VimeoVideos
|
6
8
|
|
7
|
-
|
8
|
-
|
9
|
+
class << self
|
10
|
+
attr_accessor :root
|
11
|
+
def root
|
12
|
+
@root ||= Pathname.new(File.expand_path('../../', __FILE__))
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
autoload :URLTempfile, File.expand_path('../refinery/vimeo-videos/url_tempfile', __FILE__)
|
17
|
+
autoload :Account, File.expand_path('../refinery/vimeo-videos/account', __FILE__)
|
9
18
|
|
10
19
|
class Engine < Rails::Engine
|
11
|
-
initializer
|
12
|
-
|
13
|
-
end
|
14
|
-
|
15
|
-
config.after_initialize do
|
16
|
-
Refinery::Plugin.register do |plugin|
|
20
|
+
initializer "init plugin", :after => :set_routes_reloader do |app|
|
21
|
+
::Refinery::Plugin.register do |plugin|
|
17
22
|
plugin.pathname = root
|
18
|
-
plugin.version = Refinery::VimeoVideos::VERSION
|
23
|
+
plugin.version = ::Refinery::VimeoVideos::VERSION
|
19
24
|
plugin.name = "vimeo_videos"
|
20
25
|
plugin.hide_from_menu = true
|
21
26
|
end
|
@@ -24,10 +29,12 @@ module Refinery
|
|
24
29
|
end
|
25
30
|
end
|
26
31
|
|
27
|
-
require '
|
32
|
+
require File.expand_path('../refinery/vimeo-videos/active_record', __FILE__)
|
28
33
|
|
29
34
|
module ActiveRecord
|
30
35
|
class Base
|
31
36
|
extend ::Refinery::VimeoVideos::ActiveRecord
|
32
37
|
end
|
33
|
-
end
|
38
|
+
end
|
39
|
+
|
40
|
+
::Refinery.engines << 'vimeo_videos'
|
@@ -1,5 +1,6 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
1
2
|
$:.push File.expand_path("../lib", __FILE__)
|
2
|
-
require "
|
3
|
+
require "refinery/vimeo-videos/version"
|
3
4
|
|
4
5
|
Gem::Specification.new do |s|
|
5
6
|
s.name = %q{refinerycms-vimeo-videos}
|
@@ -14,9 +15,9 @@ Gem::Specification.new do |s|
|
|
14
15
|
s.files = `git ls-files`.split("\n")
|
15
16
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
16
17
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
17
|
-
s.require_paths = ["lib"
|
18
|
+
s.require_paths = ["lib"]
|
18
19
|
|
19
|
-
s.add_dependency 'vimeo', '~> 1.
|
20
|
+
s.add_dependency 'vimeo', '~> 1.4'
|
20
21
|
s.add_development_dependency 'fakeweb', '~> 1.2.6'
|
21
22
|
|
22
23
|
end
|
@@ -9,7 +9,7 @@ describe Admin::VimeoAccountController do
|
|
9
9
|
|
10
10
|
def reset(options = {})
|
11
11
|
FakeWeb.clean_registry
|
12
|
-
|
12
|
+
::Refinery::Setting.delete_all
|
13
13
|
login_user
|
14
14
|
end
|
15
15
|
|
@@ -31,8 +31,8 @@ describe Admin::VimeoAccountController do
|
|
31
31
|
end
|
32
32
|
|
33
33
|
it "should redirect if ready to authorize" do
|
34
|
-
|
35
|
-
|
34
|
+
::Refinery::Setting.set(:vimeo_consumer_key, '0fdb4f200cc52ae06cd3dfa74e680feb')
|
35
|
+
::Refinery::Setting.set(:vimeo_consumer_secret, 'e6cdebf36a8cdd6b')
|
36
36
|
|
37
37
|
stub_custom_get("/oauth/request_token", "advanced/auth/request_token.txt")
|
38
38
|
|
@@ -42,10 +42,10 @@ describe Admin::VimeoAccountController do
|
|
42
42
|
end
|
43
43
|
|
44
44
|
it "should redirect to /refinery if already authorized" do
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
45
|
+
::Refinery::Setting.set(:vimeo_consumer_key, '0fdb4f200cc52ae06cd3dfa74e680feb')
|
46
|
+
::Refinery::Setting.set(:vimeo_consumer_secret, 'e6cdebf36a8cdd6b')
|
47
|
+
::Refinery::Setting.set(:vimeo_token, '0ea53d3415ce2c60625ddc649730e1b9')
|
48
|
+
::Refinery::Setting.set(:vimeo_secret, '97ce681f949aadb4e56e764b897a6e4463df0a7b')
|
49
49
|
|
50
50
|
get :authorization
|
51
51
|
|
@@ -54,8 +54,8 @@ describe Admin::VimeoAccountController do
|
|
54
54
|
end
|
55
55
|
|
56
56
|
#it "should successfully authorize on callback" do
|
57
|
-
#
|
58
|
-
#
|
57
|
+
# ::Refinery::Setting.set(:vimeo_consumer_key, '0fdb4f200cc52ae06cd3dfa74e680feb')
|
58
|
+
# ::Refinery::Setting.set(:vimeo_consumer_secret, 'e6cdebf36a8cdd6b')
|
59
59
|
#
|
60
60
|
# #stub_custom_get("/oauth/access_token", "advanced/auth/access_token.txt")
|
61
61
|
#
|
@@ -23,10 +23,10 @@ CreateModels.up
|
|
23
23
|
describe "RefinerycmsVimeoVideos ActiveRecord extension" do
|
24
24
|
|
25
25
|
before(:each) do
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
26
|
+
::Refinery::Setting.set(:vimeo_consumer_key, '12345')
|
27
|
+
::Refinery::Setting.set(:vimeo_consumer_secret, 'secret')
|
28
|
+
::Refinery::Setting.set(:vimeo_token, 'token')
|
29
|
+
::Refinery::Setting.set(:vimeo_secret, 'secret')
|
30
30
|
end
|
31
31
|
|
32
32
|
it "should return nil if new record" do
|
metadata
CHANGED
@@ -1,30 +1,30 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: refinerycms-vimeo-videos
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.2.rc2
|
5
|
+
prerelease: 4
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Marian Andre
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-
|
12
|
+
date: 2011-10-05 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: vimeo
|
16
|
-
requirement: &
|
16
|
+
requirement: &70147903603280 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: 1.
|
21
|
+
version: '1.4'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70147903603280
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: fakeweb
|
27
|
-
requirement: &
|
27
|
+
requirement: &70147903602780 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,30 +32,36 @@ dependencies:
|
|
32
32
|
version: 1.2.6
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70147903602780
|
36
36
|
description: Ruby on Rails Vimeo Videos engine for Refinery CMS
|
37
37
|
email: mail@bitflut.com
|
38
38
|
executables: []
|
39
39
|
extensions: []
|
40
40
|
extra_rdoc_files: []
|
41
41
|
files:
|
42
|
+
- .DS_Store
|
42
43
|
- .gitignore
|
43
44
|
- Gemfile
|
44
45
|
- Gemfile.lock
|
45
46
|
- README.markdown
|
46
47
|
- Rakefile
|
47
|
-
- app
|
48
|
-
- app/
|
49
|
-
- app/
|
50
|
-
- app/
|
51
|
-
- app/
|
52
|
-
- app/
|
53
|
-
- app/
|
54
|
-
- app/
|
55
|
-
- app/
|
56
|
-
- app/views
|
57
|
-
- app/views/admin/
|
58
|
-
- app/views/
|
48
|
+
- app/.DS_Store
|
49
|
+
- app/assets/javascripts/refinery/vimeo_videos.js
|
50
|
+
- app/assets/stylesheets/refinery/vimeo_videos.css
|
51
|
+
- app/controllers/.DS_Store
|
52
|
+
- app/controllers/refinery/admin/vimeo_account_controller.rb
|
53
|
+
- app/controllers/refinery/admin/vimeo_videos_controller.rb
|
54
|
+
- app/models/refinery/vimeo_embed_cache.rb
|
55
|
+
- app/models/refinery/vimeo_meta_cache.rb
|
56
|
+
- app/models/refinery/vimeo_video.rb
|
57
|
+
- app/views/.DS_Store
|
58
|
+
- app/views/refinery/admin/_vimeo_picker.html.erb
|
59
|
+
- app/views/refinery/admin/vimeo_videos/_error_message.html.erb
|
60
|
+
- app/views/refinery/admin/vimeo_videos/_existing_vimeo_video.html.erb
|
61
|
+
- app/views/refinery/admin/vimeo_videos/_form.html.erb
|
62
|
+
- app/views/refinery/admin/vimeo_videos/_vimeo_video.html.haml
|
63
|
+
- app/views/refinery/admin/vimeo_videos/index.js.erb
|
64
|
+
- app/views/refinery/admin/vimeo_videos/insert.html.erb
|
59
65
|
- config/locales/de.yml
|
60
66
|
- config/locales/en.yml
|
61
67
|
- config/locales/lolcat.yml
|
@@ -65,16 +71,13 @@ files:
|
|
65
71
|
- db/migrate/create_vimeo_embed_cache.rb
|
66
72
|
- db/migrate/create_vimeo_meta_cache.rb
|
67
73
|
- db/migrate/create_vimeo_videos.rb
|
68
|
-
-
|
69
|
-
- lib/
|
74
|
+
- lib/generators/vimeo_videos_generator.rb
|
75
|
+
- lib/refinery/vimeo-videos/account.rb
|
76
|
+
- lib/refinery/vimeo-videos/active_record.rb
|
77
|
+
- lib/refinery/vimeo-videos/url_tempfile.rb
|
78
|
+
- lib/refinery/vimeo-videos/version.rb
|
70
79
|
- lib/refinerycms-vimeo-videos.rb
|
71
|
-
- lib/refinerycms-vimeo-videos/account.rb
|
72
|
-
- lib/refinerycms-vimeo-videos/active_record.rb
|
73
|
-
- lib/refinerycms-vimeo-videos/url_tempfile.rb
|
74
|
-
- lib/refinerycms-vimeo-videos/version.rb
|
75
80
|
- lib/tasks/vimeo_videos.rake
|
76
|
-
- public/javascripts/refinery/vimeo_videos.js
|
77
|
-
- public/stylesheets/admin/vimeo_videos.css
|
78
81
|
- refinerycms-vimeo-videos.gemspec
|
79
82
|
- spec/controllers/admin/vimeo_account_controller_spec.rb
|
80
83
|
- spec/fixtures/advanced/album/add_video.json
|
@@ -201,9 +204,6 @@ post_install_message:
|
|
201
204
|
rdoc_options: []
|
202
205
|
require_paths:
|
203
206
|
- lib
|
204
|
-
- config
|
205
|
-
- app
|
206
|
-
- public
|
207
207
|
required_ruby_version: !ruby/object:Gem::Requirement
|
208
208
|
none: false
|
209
209
|
requirements:
|
@@ -218,7 +218,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
218
218
|
version: 1.3.1
|
219
219
|
requirements: []
|
220
220
|
rubyforge_project:
|
221
|
-
rubygems_version: 1.
|
221
|
+
rubygems_version: 1.8.10
|
222
222
|
signing_key:
|
223
223
|
specification_version: 3
|
224
224
|
summary: Vimeo Videos engine for Refinery CMS
|
@@ -1,54 +0,0 @@
|
|
1
|
-
module Admin
|
2
|
-
class VimeoAccountController < Admin::BaseController
|
3
|
-
|
4
|
-
include ::Refinery::VimeoVideos::Account
|
5
|
-
|
6
|
-
def authorization
|
7
|
-
|
8
|
-
if not authorized? and ready_to_authorize?
|
9
|
-
|
10
|
-
# begin authorization process
|
11
|
-
base = ::Vimeo::Advanced::Base.new(
|
12
|
-
account[:consumer_key],
|
13
|
-
account[:consumer_secret])
|
14
|
-
request_token = base.get_request_token
|
15
|
-
session[:oauth_secret] = request_token.secret
|
16
|
-
|
17
|
-
redirect_to base.authorize_url
|
18
|
-
|
19
|
-
elsif ready_to_authorize?
|
20
|
-
|
21
|
-
# already authorized
|
22
|
-
flash.notice = "You have already authorized your account."
|
23
|
-
redirect_to refinery_root_path
|
24
|
-
|
25
|
-
else
|
26
|
-
|
27
|
-
# not ready to authorize
|
28
|
-
flash.alert = "You are not ready to authorize. Type in consumer_key and consumer_secret."
|
29
|
-
redirect_to refinery_root_path
|
30
|
-
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
def callback
|
35
|
-
|
36
|
-
# vimeo will redirect us here upon successful authorization
|
37
|
-
base = ::Vimeo::Advanced::Base.new(
|
38
|
-
account[:consumer_key],
|
39
|
-
account[:consumer_secret])
|
40
|
-
access_token = base.get_access_token(params[:oauth_token], session[:oauth_secret], params[:oauth_verifier])
|
41
|
-
RefinerySetting.find_by_name('vimeo_token').update_attribute(:value, access_token.token)
|
42
|
-
RefinerySetting.find_by_name('vimeo_secret').update_attribute(:value, access_token.secret)
|
43
|
-
flash.notice = "You successfully authorized your vimeo account for integration in your backend. You can now start using it."
|
44
|
-
redirect_to refinery_root_path
|
45
|
-
|
46
|
-
end
|
47
|
-
|
48
|
-
protected
|
49
|
-
|
50
|
-
def restrict_controller
|
51
|
-
end
|
52
|
-
|
53
|
-
end
|
54
|
-
end
|
@@ -1,87 +0,0 @@
|
|
1
|
-
class VimeoAuthorizationError < StandardError; end
|
2
|
-
module Admin
|
3
|
-
class VimeoVideosController < Admin::BaseController
|
4
|
-
|
5
|
-
include ::Refinery::VimeoVideos::Account
|
6
|
-
|
7
|
-
before_filter :ensure_authorized!
|
8
|
-
before_filter :init_dialog
|
9
|
-
|
10
|
-
def index
|
11
|
-
get_videos_on_vimeo_account
|
12
|
-
end
|
13
|
-
|
14
|
-
def new
|
15
|
-
@vimeo_video = VimeoVideo.new
|
16
|
-
end
|
17
|
-
|
18
|
-
def create
|
19
|
-
|
20
|
-
end
|
21
|
-
|
22
|
-
def insert
|
23
|
-
self.new if @vimeo_video.nil?
|
24
|
-
|
25
|
-
@url_override = admin_vimeo_videos_url(:dialog => from_dialog?, :insert => true)
|
26
|
-
|
27
|
-
if params[:conditions].present?
|
28
|
-
extra_condition = params[:conditions].split(',')
|
29
|
-
|
30
|
-
extra_condition[1] = true if extra_condition[1] == "true"
|
31
|
-
extra_condition[1] = false if extra_condition[1] == "false"
|
32
|
-
extra_condition[1] = nil if extra_condition[1] == "nil"
|
33
|
-
paginate_vimeo_videos({extra_condition[0].to_sym => extra_condition[1]})
|
34
|
-
else
|
35
|
-
paginate_vimeo_videos
|
36
|
-
end
|
37
|
-
render :action => "insert"
|
38
|
-
end
|
39
|
-
|
40
|
-
protected
|
41
|
-
def get_videos_on_vimeo_account
|
42
|
-
video = ::Vimeo::Advanced::Video.new(
|
43
|
-
account[:consumer_key],
|
44
|
-
account[:consumer_secret],
|
45
|
-
:token => account[:token],
|
46
|
-
:secret => account[:secret])
|
47
|
-
@vimeo_videos = video.get_all(account[:username], {:full_response => true, :sort => 'upload_date'})["videos"]["video"]
|
48
|
-
end
|
49
|
-
|
50
|
-
def init_dialog
|
51
|
-
@app_dialog = params[:app_dialog].present?
|
52
|
-
@field = params[:field]
|
53
|
-
@update_vimeo_video = params[:update_vimeo_video]
|
54
|
-
@update_text = params[:update_text]
|
55
|
-
@thumbnail = params[:thumbnail]
|
56
|
-
@callback = params[:callback]
|
57
|
-
@conditions = params[:conditions]
|
58
|
-
@current_link = params[:current_link]
|
59
|
-
end
|
60
|
-
|
61
|
-
def restrict_controller
|
62
|
-
super unless action_name == 'insert'
|
63
|
-
end
|
64
|
-
|
65
|
-
def paginate_vimeo_videos(conditions={})
|
66
|
-
@vimeo_videos = get_videos_on_vimeo_account.paginate :page => (@paginate_page_number ||= params[:page]),
|
67
|
-
:conditions => conditions,
|
68
|
-
:order => 'created_at DESC',
|
69
|
-
:per_page => VimeoVideo.per_page(from_dialog?)
|
70
|
-
end
|
71
|
-
|
72
|
-
def ensure_authorized!
|
73
|
-
begin
|
74
|
-
|
75
|
-
raise VimeoAuthorizationError unless authorized?
|
76
|
-
|
77
|
-
rescue VimeoAuthorizationError => exception
|
78
|
-
|
79
|
-
message = 'You have not authorized your vimeo account with this application.'
|
80
|
-
render :partial => 'error_message', :locals => {
|
81
|
-
:message => message
|
82
|
-
}
|
83
|
-
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
@@ -1,67 +0,0 @@
|
|
1
|
-
require 'httparty'
|
2
|
-
|
3
|
-
class VimeoEmbedCache < ActiveRecord::Base
|
4
|
-
|
5
|
-
set_table_name "vimeo_embed_cache"
|
6
|
-
|
7
|
-
belongs_to :vimeo_video
|
8
|
-
|
9
|
-
before_save :cache
|
10
|
-
|
11
|
-
serialize :configuration, Hash
|
12
|
-
|
13
|
-
validates_presence_of :configuration
|
14
|
-
validates_presence_of :vid
|
15
|
-
|
16
|
-
def self.embed vid, geometry, configuration = {}
|
17
|
-
configuration.stringify_keys!
|
18
|
-
configuration.merge!(geometry_hash(geometry))
|
19
|
-
|
20
|
-
static = configuration.delete("static") if configuration.has_key?("static")
|
21
|
-
if static
|
22
|
-
geometry =~ FIXED_GEOMETRY ?
|
23
|
-
static_embed_code(vid, geometry).html_safe : raise(ArgumentError, "Must use fixed geometry string for static embeds (e.g. 100x240)")
|
24
|
-
else
|
25
|
-
find_or_create_by_vid_and_configuration(vid, :configuration => ::YAML.dump(configuration)).code.html_safe
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def update_cache
|
30
|
-
cache true
|
31
|
-
self.save
|
32
|
-
end
|
33
|
-
|
34
|
-
FIXED_WIDTH_GEOMETRY = /^(\d+)$/ # e.g. '300'
|
35
|
-
FIXED_HEIGHT_GEOMETRY = /^x(\d+)$/ # e.g. 'x200'
|
36
|
-
FIXED_GEOMETRY = /^(\d+)x(\d+)$/ # e.g. '300x200'
|
37
|
-
VIMEO_GEOMETRY = ::Regexp.union FIXED_GEOMETRY, FIXED_HEIGHT_GEOMETRY, FIXED_WIDTH_GEOMETRY
|
38
|
-
|
39
|
-
def self.geometry_hash geometry
|
40
|
-
case geometry
|
41
|
-
when FIXED_WIDTH_GEOMETRY
|
42
|
-
{:width => $1}
|
43
|
-
when FIXED_HEIGHT_GEOMETRY
|
44
|
-
{:height => $1}
|
45
|
-
when FIXED_GEOMETRY
|
46
|
-
{:width => $1, :height => $2}
|
47
|
-
else raise ArgumentError, "Didn't recognise the geometry string #{geometry}"
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
private
|
52
|
-
|
53
|
-
def self.static_embed_code vid, geometry
|
54
|
-
width, height = geometry.split('x')
|
55
|
-
"<iframe src=\"http://player.vimeo.com/video/#{vid}?portrait=0\" width=\"#{width}\" height=\"#{height}\" frameborder=\"0\"></iframe>"
|
56
|
-
end
|
57
|
-
|
58
|
-
def cache force = false
|
59
|
-
if self.code.blank? or force
|
60
|
-
# Escape vimeo url and request oembed code
|
61
|
-
url = ::CGI::escape("http://vimeo.com/#{self.vid}")
|
62
|
-
|
63
|
-
response = ::HTTParty.get "http://vimeo.com/api/oembed.xml?url=#{url}&#{self.configuration.to_query}"
|
64
|
-
self.code = response["oembed"]["html"]
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
@@ -1,59 +0,0 @@
|
|
1
|
-
class VimeoMetaCache < ActiveRecord::Base
|
2
|
-
|
3
|
-
include ::Refinery::VimeoVideos::Account
|
4
|
-
|
5
|
-
set_table_name "vimeo_meta_cache"
|
6
|
-
|
7
|
-
has_many :vimeo_embed_caches, :dependent => :destroy
|
8
|
-
|
9
|
-
belongs_to :image, :class_name => 'Image'
|
10
|
-
|
11
|
-
before_save :cache
|
12
|
-
|
13
|
-
validates_presence_of :vid
|
14
|
-
|
15
|
-
def embed geometry, options = {}
|
16
|
-
VimeoEmbedCache.embed(self.vid, geometry, options)
|
17
|
-
end
|
18
|
-
|
19
|
-
def url
|
20
|
-
"http://www.vimeo.com/#{self.vid}"
|
21
|
-
end
|
22
|
-
|
23
|
-
def update_cache images = false
|
24
|
-
cache true, images
|
25
|
-
self.save
|
26
|
-
end
|
27
|
-
|
28
|
-
private
|
29
|
-
|
30
|
-
def cache force = false, images = false
|
31
|
-
if !self.title? or !self.image_id? or !self.description? or force
|
32
|
-
|
33
|
-
video_info_request = ::Vimeo::Advanced::Video.new(
|
34
|
-
account[:consumer_key],
|
35
|
-
account[:consumer_secret],
|
36
|
-
:token => account[:token],
|
37
|
-
:secret => account[:secret])
|
38
|
-
|
39
|
-
video_info = video_info_request.get_info(self.vid)["video"].first
|
40
|
-
|
41
|
-
# By default omitt image if we already have one.
|
42
|
-
# If we force an update, we need to specifically force images as well by
|
43
|
-
# calling this method with force and images true.
|
44
|
-
|
45
|
-
if images or !image_id?
|
46
|
-
# Save fetched image url
|
47
|
-
vimeo_thumb_url = video_info["thumbnails"]["thumbnail"].last["_content"]
|
48
|
-
self.create_image(:image => ::Refinery::VimeoVideos::URLTempfile.new(vimeo_thumb_url))
|
49
|
-
end
|
50
|
-
|
51
|
-
# Save fetched title
|
52
|
-
self.title = video_info["title"] if !self.title? or force
|
53
|
-
|
54
|
-
# Save fetched description
|
55
|
-
self.description = "<p>#{video_info['description']}</p>" if !self.description? or force
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
end
|
data/app/models/vimeo_video.rb
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
# This model acts as a wrapper for uploaded videos only
|
2
|
-
# Everything else happens directly with the advanced vimeo api
|
3
|
-
|
4
|
-
class VimeoVideo < ActiveRecord::Base
|
5
|
-
|
6
|
-
# What is the max resource size a user can upload
|
7
|
-
MAX_SIZE_IN_MB = 1000
|
8
|
-
|
9
|
-
# when a dialog pops up with resources, how many resources per page should there be
|
10
|
-
PAGES_PER_DIALOG = 18
|
11
|
-
|
12
|
-
# when listing resources out in the admin area, how many resources should show per page
|
13
|
-
PAGES_PER_ADMIN_INDEX = 20
|
14
|
-
|
15
|
-
class << self
|
16
|
-
# How many resources per page should be displayed?
|
17
|
-
def per_page(dialog = false)
|
18
|
-
dialog ? PAGES_PER_DIALOG : PAGES_PER_ADMIN_INDEX
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
data/db/seeds/vimeo_videos.rb
DELETED