refinerycms-vimeo-videos 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -1,8 +1,67 @@
1
1
  Refinerycms-Vimeo-Videos
2
2
  ========================
3
3
 
4
- This gem makes it easy for refinerycms sites to add vimeo videos to models.
4
+ This gem makes it easy for refinerycms sites to add vimeo videos to models. It is still in a very experimental phase of development, but already used in production. Use only if you are sure about what the code does.
5
5
 
6
- Usage
7
- -----
6
+ Setup and Authorization
7
+ -----------------------
8
8
 
9
+ Add the gem to your Gemfile and bundle install it
10
+
11
+ gem 'refinerycms-vimeo-videos'
12
+
13
+ Run the generator and migrate your database
14
+
15
+ rails generate refinerycms_vimeo_videos
16
+ rake db:migrate
17
+
18
+ Create an api-application for your vimeo account under http://vimeo.com/api/applications with a callback url of
19
+
20
+ http://yourapp.com/admin/vimeo_videos/callback
21
+
22
+ Copy/paste the consumer\_key and consumer\_secret of your vimeo api-application to the related Refinery Settings (:vimeo\_consumer\_key and :vimeo\_consumer\_secret). Then access the following url:
23
+
24
+ http://yourapp.com/admin/vimeo_videos/authorization
25
+
26
+ After this, your app should be setup to use your vimeo account.
27
+
28
+ Adding a vimeo video
29
+ --------------------
30
+
31
+ Add a field to the table:
32
+
33
+ add_column :projects, :test_video_id, :string
34
+
35
+ Call _vimeo\_video_ in your model with the corresponding field as attribute:
36
+
37
+ vimeo_video :test_video
38
+
39
+ In your _form.html.erb insert this:
40
+
41
+ <div class='field'>
42
+ <%= f.label "Test Video" -%>
43
+ <%= render :partial => "/shared/admin/vimeo_picker", :locals => {
44
+ :f => f,
45
+ :field => :test_video_id,
46
+ :vimeo_video => @project.test_video
47
+ } %>
48
+ </div>
49
+
50
+ Now embed the video (with a width of 750px):
51
+
52
+ <%= @project.test_video.embed '750' -%>
53
+
54
+ Invalidating Caches
55
+ -------------------
56
+
57
+ If you need to invalidate the whole cache, simply call delete\_all on VimeoEmbedCache and VimeoMetaCache.
58
+
59
+ In case you want to just pull in changes, you can do:
60
+
61
+ VimeoEmbedCache.update_cache
62
+ VimeoMetaCache.update_cache
63
+
64
+ TODO
65
+ ----
66
+
67
+ Alot!
@@ -25,7 +25,8 @@ module Admin
25
25
  else
26
26
 
27
27
  # not ready to authorize
28
- raise ArgumentError, 'Not ready to authorize. Type in consumer_key and consumer_secret.'
28
+ flash.alert = "You are not ready to authorize. Type in consumer_key and consumer_secret."
29
+ redirect_to "/admin"
29
30
 
30
31
  end
31
32
  end
@@ -20,9 +20,9 @@ class VimeoEmbedCache < ActiveRecord::Base
20
20
  static = configuration.delete("static") if configuration.has_key?("static")
21
21
  if static
22
22
  geometry =~ FIXED_GEOMETRY ?
23
- static_embed_code(vid, geometry) : raise(ArgumentError, "Must use fixed geometry string for static embeds (e.g. 100x240)")
23
+ static_embed_code(vid, geometry).html_safe : raise(ArgumentError, "Must use fixed geometry string for static embeds (e.g. 100x240)")
24
24
  else
25
- find_or_create_by_vid_and_configuration(vid, :configuration => YAML.dump(configuration))
25
+ find_or_create_by_vid_and_configuration(vid, :configuration => YAML.dump(configuration)).code.html_safe
26
26
  end
27
27
  end
28
28
 
@@ -13,7 +13,7 @@ class VimeoMetaCache < ActiveRecord::Base
13
13
  validates_presence_of :vid
14
14
 
15
15
  def embed geometry, options = {}
16
- VimeoEmbedCache.embed(self.vid, geometry, options).code
16
+ VimeoEmbedCache.embed(self.vid, geometry, options)
17
17
  end
18
18
 
19
19
  def url
@@ -30,12 +30,13 @@ class VimeoMetaCache < ActiveRecord::Base
30
30
  def cache force = false, images = false
31
31
  if !self.title? or !self.image_id? or !self.description? or force
32
32
 
33
- video = Vimeo::Advanced::Video.new(
33
+ video_info_request = Vimeo::Advanced::Video.new(
34
34
  account[:consumer_key],
35
35
  account[:consumer_secret],
36
36
  :token => account[:token],
37
37
  :secret => account[:secret])
38
- video_info = video.get_info(self.vid)["video"].first
38
+
39
+ video_info = video_info_request.get_info(self.vid)["video"].first
39
40
 
40
41
  # By default omitt image if we already have one.
41
42
  # If we force an update, we need to specifically force images as well by
@@ -44,7 +45,7 @@ class VimeoMetaCache < ActiveRecord::Base
44
45
  if images or !image_id?
45
46
  # Save fetched image url
46
47
  vimeo_thumb_url = video_info["thumbnails"]["thumbnail"].last["_content"]
47
- self.create_image(:image => URLTempfile.new(vimeo_thumb_url))
48
+ self.create_image(:image => RefinerycmsVimeoVideos::URLTempfile.new(vimeo_thumb_url))
48
49
  end
49
50
 
50
51
  # Save fetched title
@@ -2,7 +2,7 @@ class CreateVimeoEmbedCache < ActiveRecord::Migration
2
2
 
3
3
  def self.up
4
4
  create_table :vimeo_embed_cache do |t|
5
- t.integer :vid
5
+ t.string :vid
6
6
  t.string :code
7
7
  t.text :configuration
8
8
  t.timestamps
@@ -0,0 +1,18 @@
1
+ require 'factory_girl'
2
+
3
+ Factory.define :user do |u|
4
+ u.sequence(:username) { |n| "person#{n}" }
5
+ u.sequence(:email) { |n| "person#{n}@cucumber.com" }
6
+ u.password "greenandjuicy"
7
+ u.password_confirmation "greenandjuicy"
8
+ end
9
+
10
+ Factory.define :refinery_user, :parent => :user do |u|
11
+ u.roles { [ Role[:refinery] ] }
12
+
13
+ u.after_create do |user|
14
+ Refinery::Plugins.registered.each_with_index do |plugin, index|
15
+ user.plugins.create(:name => plugin.name, :position => index)
16
+ end
17
+ end
18
+ end
@@ -2,6 +2,8 @@ require 'refinerycms-base'
2
2
  require 'vimeo'
3
3
 
4
4
  require 'refinerycms_vimeo_videos/account'
5
+ require 'refinerycms_vimeo_videos/active_record_extension'
6
+ require 'refinerycms_vimeo_videos/url_tempfile'
5
7
 
6
8
  module Refinery
7
9
  module VimeoVideos
@@ -0,0 +1,38 @@
1
+ module RefinerycmsVimeoVideos
2
+ module ActiveRecordExtension
3
+
4
+ def self.included(base)
5
+ base.extend(ClassMethods)
6
+ end
7
+
8
+ module ClassMethods
9
+
10
+ def vimeo_video field
11
+ class_eval <<-EOV
12
+
13
+ def #{field}
14
+ if self.new_record?
15
+ self.#{field}_id
16
+ else
17
+ self.#{field}_id? ? VimeoMetaCache.find_or_create_by_vid(self.#{field}_id) : nil
18
+ end
19
+ end
20
+
21
+ before_save :cache_vimeo_meta_for_#{field}
22
+
23
+ def cache_vimeo_meta_for_#{field}
24
+ if self.#{field}_id? and self.#{field}_id_changed?
25
+ VimeoMetaCache.find_or_create_by_vid(self.#{field}_id)
26
+ end
27
+ end
28
+ protected :cache_vimeo_meta_for_#{field}
29
+
30
+ EOV
31
+ end
32
+
33
+ end
34
+
35
+ end
36
+ end
37
+
38
+ ActiveRecord::Base.class_eval { include RefinerycmsVimeoVideos::ActiveRecordExtension }
@@ -0,0 +1,19 @@
1
+ module RefinerycmsVimeoVideos
2
+ class URLTempfile < Tempfile
3
+
4
+ def initialize(url)
5
+ @url = URI.parse(url)
6
+
7
+ begin
8
+ super('url', Dir.tmpdir, :encoding => 'ascii-8bit')
9
+
10
+ Net::HTTP.start(@url.host) do |http|
11
+ resp = http.get(@url.path)
12
+ self.write resp.body
13
+ end
14
+ ensure
15
+ end
16
+ end
17
+
18
+ end
19
+ end
@@ -1,3 +1,3 @@
1
1
  module RefinerycmsVimeoVideos
2
- VERSION = "0.1.6"
2
+ VERSION = "0.1.7"
3
3
  end
@@ -4,7 +4,7 @@ require "refinerycms_vimeo_videos/version"
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = %q{refinerycms-vimeo-videos}
7
- s.version = %q{0.1.6}
7
+ s.version = %q{0.1.7}
8
8
  s.description = 'Ruby on Rails Vimeo Videos engine for Refinery CMS'
9
9
  s.date = %q{2011-04-25}
10
10
  s.summary = 'Vimeo Videos engine for Refinery CMS'
@@ -66,6 +66,7 @@ Gem::Specification.new do |s|
66
66
  'features/step_definitions',
67
67
  'features/step_definitions/vimeo_video_steps.rb',
68
68
  'features/support',
69
+ 'features/support/factories.rb',
69
70
  'features/support/paths.rb',
70
71
  'lib',
71
72
  'lib/generators',
@@ -73,6 +74,8 @@ Gem::Specification.new do |s|
73
74
  'lib/refinerycms-vimeo-videos.rb',
74
75
  'lib/refinerycms_vimeo_videos',
75
76
  'lib/refinerycms_vimeo_videos/account.rb',
77
+ 'lib/refinerycms_vimeo_videos/active_record_extension.rb',
78
+ 'lib/refinerycms_vimeo_videos/url_tempfile.rb',
76
79
  'lib/refinerycms_vimeo_videos/version.rb',
77
80
  'lib/tasks',
78
81
  'lib/tasks/vimeo_videos.rake',
@@ -190,7 +193,7 @@ Gem::Specification.new do |s|
190
193
  'spec/fixtures/advanced/video_embed/get_presets.json',
191
194
  'spec/fixtures/advanced/video_embed/set_preset.json',
192
195
  'spec/fixtures/oembed',
193
- 'spec/fixtures/oembed/oembed.json',
196
+ 'spec/fixtures/oembed/oembed.json.erb',
194
197
  'spec/fixtures/simple',
195
198
  'spec/fixtures/simple/activity',
196
199
  'spec/fixtures/simple/activity/contacts_did.json',
@@ -223,9 +226,12 @@ Gem::Specification.new do |s|
223
226
  'spec/fixtures/simple/video',
224
227
  'spec/fixtures/simple/video/info.json',
225
228
  'spec/models',
229
+ 'spec/models/active_record_extension_spec.rb',
226
230
  'spec/models/vimeo_embed_cache_spec.rb',
227
231
  'spec/models/vimeo_meta_cache_spec.rb',
228
232
  'spec/models/vimeo_video_spec.rb',
233
+ 'spec/samples',
234
+ 'spec/samples/taj.jpg',
229
235
  'spec/vimeo_helper.rb'
230
236
  ]
231
237
  end
@@ -0,0 +1,56 @@
1
+ require 'spec_helper'
2
+ require 'factory_girl'
3
+ Dir[File.expand_path('../../../../features/support/factories.rb', __FILE__)].each {|f| require f}
4
+ require File.expand_path '../../../vimeo_helper', __FILE__
5
+
6
+ include Devise::TestHelpers
7
+
8
+ describe Admin::VimeoAccountController do
9
+
10
+ def reset(options = {})
11
+ FakeWeb.clean_registry
12
+ RefinerySetting.delete_all
13
+ login_user
14
+ end
15
+
16
+ def login_user
17
+ @request.env["devise.mapping"] = Devise.mappings[:user]
18
+ user = Factory.create(:refinery_user)
19
+ sign_in user
20
+ end
21
+
22
+ before(:each) do
23
+ reset
24
+ end
25
+
26
+ it "should not ask for authorization if not ready" do
27
+ get :authorization
28
+
29
+ response.should be_redirect
30
+ flash[:alert].should_not == nil
31
+ end
32
+
33
+ it "should redirect if ready to authorize" do
34
+ RefinerySetting.set(:vimeo_consumer_key, '0fdb4f200cc52ae06cd3dfa74e680feb')
35
+ RefinerySetting.set(:vimeo_consumer_secret, 'e6cdebf36a8cdd6b')
36
+
37
+ stub_custom_get("/oauth/request_token", "advanced/auth/request_token.txt")
38
+
39
+ get :authorization
40
+
41
+ response.should redirect_to('http://vimeo.com/oauth/authorize?permission=delete&oauth_token=12345')
42
+ end
43
+
44
+ it "should redirect to /admin if already authorized" do
45
+ RefinerySetting.set(:vimeo_consumer_key, '0fdb4f200cc52ae06cd3dfa74e680feb')
46
+ RefinerySetting.set(:vimeo_consumer_secret, 'e6cdebf36a8cdd6b')
47
+ RefinerySetting.set(:vimeo_token, '0ea53d3415ce2c60625ddc649730e1b9')
48
+ RefinerySetting.set(:vimeo_secret, '97ce681f949aadb4e56e764b897a6e4463df0a7b')
49
+
50
+ get :authorization
51
+
52
+ response.should redirect_to('/admin')
53
+ flash[:notice].should_not == nil
54
+ end
55
+
56
+ end
@@ -1,246 +1,175 @@
1
1
  {
2
- "generated_in":"0.2644",
2
+ "generated_in":"0.2381",
3
3
  "stat":"ok",
4
- "video":{
5
- "embed_privacy":"anywhere",
6
- "id":"6788487",
7
- "is_hd":"1",
8
- "is_transcoding":"0",
9
- "privacy":"anybody",
10
- "title":"Riding High",
11
- "caption":"13thWitness\u2122 x NYC Bridge Rollers...\n\nhttp:\/\/twitter.com\/13thwitness",
12
- "upload_date":"2009-09-27 22:35:02",
13
- "number_of_likes":"33",
14
- "number_of_plays":"2420",
15
- "number_of_comments":"18",
16
- "width":"640",
17
- "height":"352",
18
- "duration":"181",
19
- "owner":{
20
- "display_name":"13thWitness\u2122",
21
- "id":"580098",
22
- "is_plus":"1",
23
- "is_staff":"0",
24
- "profileurl":"http:\/\/vimeo.com\/the13thwitness",
25
- "realname":"13thWitness\u2122",
26
- "username":"the13thwitness",
27
- "videosurl":"http:\/\/vimeo.com\/the13thwitness\/videos",
28
- "portraits":{
29
- "portrait":[
30
- {
31
- "height":"30",
32
- "width":"30",
33
- "_content":"http:\/\/images.vimeo.com\/91\/61\/45\/91614528\/91614528_30.jpg"
4
+ "video":[
5
+ {
6
+ "embed_privacy":"anywhere",
7
+ "id":"26366794",
8
+ "is_hd":"0",
9
+ "is_like":"0",
10
+ "is_transcoding":"",
11
+ "is_watchlater":"0",
12
+ "license":"0",
13
+ "privacy":"anybody",
14
+ "title":"Riding High",
15
+ "description":"Riding High description",
16
+ "upload_date":"2010-11-15 17:59:15",
17
+ "modified_date":"2011-04-18 16:32:10",
18
+ "number_of_likes":"1",
19
+ "number_of_plays":"50",
20
+ "number_of_comments":"0",
21
+ "width":"640",
22
+ "height":"360",
23
+ "duration":"214",
24
+ "owner":{
25
+ "display_name":"Perfect Film Prd | Baldvin K\u00e1ri",
26
+ "id":"3067177",
27
+ "is_plus":"0",
28
+ "is_staff":"0",
29
+ "profileurl":"http:\/\/vimeo.com\/perfectfilms",
30
+ "realname":"Perfect Film Prd | Baldvin K\u00e1ri",
31
+ "username":"perfectfilms",
32
+ "videosurl":"http:\/\/vimeo.com\/perfectfilms\/videos",
33
+ "portraits":{
34
+ "portrait":[
35
+ {
36
+ "height":"30",
37
+ "width":"30",
38
+ "_content":"http:\/\/b.vimeocdn.com\/ps\/136\/901\/1369017_30.jpg"
39
+ },
40
+ {
41
+ "height":"75",
42
+ "width":"75",
43
+ "_content":"http:\/\/b.vimeocdn.com\/ps\/136\/901\/1369017_75.jpg"
44
+ },
45
+ {
46
+ "height":"100",
47
+ "width":"100",
48
+ "_content":"http:\/\/b.vimeocdn.com\/ps\/136\/901\/1369017_100.jpg"
49
+ },
50
+ {
51
+ "height":"300",
52
+ "width":"300",
53
+ "_content":"http:\/\/b.vimeocdn.com\/ps\/136\/901\/1369017_300.jpg"
54
+ }
55
+ ]
56
+ }
57
+ },
58
+ "tags":{
59
+ "tag":[
60
+ {
61
+ "author":"3067177",
62
+ "id":"39388789",
63
+ "normalized":"shortfilm",
64
+ "url":"http:\/\/vimeo.com\/tag:shortfilm",
65
+ "_content":"short film"
34
66
  },
35
67
  {
36
- "height":"75",
37
- "width":"75",
38
- "_content":"http:\/\/images.vimeo.com\/91\/61\/45\/91614528\/91614528_75.jpg"
68
+ "author":"3067177",
69
+ "id":"39388792",
70
+ "normalized":"columbia",
71
+ "url":"http:\/\/vimeo.com\/tag:columbia",
72
+ "_content":"columbia"
73
+ },
74
+ {
75
+ "author":"3067177",
76
+ "id":"39388793",
77
+ "normalized":"baldvinkari",
78
+ "url":"http:\/\/vimeo.com\/tag:baldvinkari",
79
+ "_content":"baldvin kari"
80
+ },
81
+ {
82
+ "author":"3067177",
83
+ "id":"39388794",
84
+ "normalized":"hairdo",
85
+ "url":"http:\/\/vimeo.com\/tag:hairdo",
86
+ "_content":"hairdo"
87
+ },
88
+ {
89
+ "author":"3067177",
90
+ "id":"39388795",
91
+ "normalized":"hairstyle",
92
+ "url":"http:\/\/vimeo.com\/tag:hairstyle",
93
+ "_content":"hairstyle"
94
+ },
95
+ {
96
+ "author":"3067177",
97
+ "id":"39388796",
98
+ "normalized":"eighties",
99
+ "url":"http:\/\/vimeo.com\/tag:eighties",
100
+ "_content":"eighties"
101
+ },
102
+ {
103
+ "author":"3067177",
104
+ "id":"39388797",
105
+ "normalized":"80s",
106
+ "url":"http:\/\/vimeo.com\/tag:80s",
107
+ "_content":"80s"
108
+ },
109
+ {
110
+ "author":"3067177",
111
+ "id":"39388798",
112
+ "normalized":"comedy",
113
+ "url":"http:\/\/vimeo.com\/tag:comedy",
114
+ "_content":"comedy"
115
+ }
116
+ ]
117
+ },
118
+ "cast":{
119
+ "member":[
120
+ {
121
+ "display_name":"Perfect Film Prd | Baldvin K\u00e1ri",
122
+ "id":"3067177",
123
+ "role":"Production Company | Director\/Co-Writer",
124
+ "username":"perfectfilms"
39
125
  },
40
126
  {
41
- "height":"100",
127
+ "display_name":"Blendwerk",
128
+ "id":"1139721",
129
+ "role":"Cinematography (Viktor Schaider)",
130
+ "username":"user1139721"
131
+ },
132
+ {
133
+ "display_name":"Christoph Kuschnig",
134
+ "id":"1591276",
135
+ "role":"Gaffer",
136
+ "username":"christophkuschnig"
137
+ },
138
+ {
139
+ "display_name":"Erlingur Thoroddsen",
140
+ "id":"2642258",
141
+ "role":"Sound recordist",
142
+ "username":"user2642258"
143
+ }
144
+ ]
145
+ },
146
+ "urls":{
147
+ "url":[
148
+ {
149
+ "type":"video",
150
+ "_content":"http:\/\/vimeo.com\/16866796"
151
+ }
152
+ ]
153
+ },
154
+ "thumbnails":{
155
+ "thumbnail":[
156
+ {
157
+ "height":"75",
42
158
  "width":"100",
43
- "_content":"http:\/\/images.vimeo.com\/91\/61\/45\/91614528\/91614528_100.jpg"
159
+ "_content":"http:\/\/b.vimeocdn.com\/ts\/104\/602\/104602144_100.jpg"
160
+ },
161
+ {
162
+ "height":"150",
163
+ "width":"200",
164
+ "_content":"http:\/\/b.vimeocdn.com\/ts\/104\/602\/104602144_200.jpg"
44
165
  },
45
166
  {
46
- "height":"300",
47
- "width":"300",
48
- "_content":"http:\/\/images.vimeo.com\/91\/61\/45\/91614528\/91614528_300.jpg"
167
+ "height":"360",
168
+ "width":"640",
169
+ "_content":"http:\/\/b.vimeocdn.com\/ts\/104\/602\/104602144_640.jpg"
49
170
  }
50
171
  ]
51
172
  }
52
- },
53
- "tags":{
54
- "tag":[
55
- {
56
- "author":"580098",
57
- "id":"16600131",
58
- "normalized":"fixedgear",
59
- "url":"http:\/\/vimeo.com\/tag:fixedgear",
60
- "_content":"fixed gear"
61
- },
62
- {
63
- "author":"580098",
64
- "id":"16600141",
65
- "normalized":"bicycle",
66
- "url":"http:\/\/vimeo.com\/tag:bicycle",
67
- "_content":"bicycle"
68
- },
69
- {
70
- "author":"580098",
71
- "id":"16600144",
72
- "normalized":"clyclist",
73
- "url":"http:\/\/vimeo.com\/tag:clyclist",
74
- "_content":"clyclist"
75
- },
76
- {
77
- "author":"580098",
78
- "id":"16600155",
79
- "normalized":"newyorkcity",
80
- "url":"http:\/\/vimeo.com\/tag:newyorkcity",
81
- "_content":"new york city"
82
- },
83
- {
84
- "author":"580098",
85
- "id":"16600159",
86
- "normalized":"nycbridgerollers",
87
- "url":"http:\/\/vimeo.com\/tag:nycbridgerollers",
88
- "_content":"nyc bridge rollers"
89
- },
90
- {
91
- "author":"580098",
92
- "id":"16600165",
93
- "normalized":"13thwitness",
94
- "url":"http:\/\/vimeo.com\/tag:13thwitness",
95
- "_content":"13thWitness"
96
- },
97
- {
98
- "author":"580098",
99
- "id":"16600169",
100
- "normalized":"elsaeso",
101
- "url":"http:\/\/vimeo.com\/tag:elsaeso",
102
- "_content":"el saeso"
103
- },
104
- {
105
- "author":"580098",
106
- "id":"16600174",
107
- "normalized":"kai",
108
- "url":"http:\/\/vimeo.com\/tag:kai",
109
- "_content":"kai"
110
- },
111
- {
112
- "author":"580098",
113
- "id":"16600178",
114
- "normalized":"mikehernandez",
115
- "url":"http:\/\/vimeo.com\/tag:mikehernandez",
116
- "_content":"mike hernandez"
117
- },
118
- {
119
- "author":"580098",
120
- "id":"16600194",
121
- "normalized":"jack",
122
- "url":"http:\/\/vimeo.com\/tag:jack",
123
- "_content":"jack"
124
- },
125
- {
126
- "author":"580098",
127
- "id":"16600212",
128
- "normalized":"mitch",
129
- "url":"http:\/\/vimeo.com\/tag:mitch",
130
- "_content":"mitch"
131
- },
132
- {
133
- "author":"580098",
134
- "id":"16600239",
135
- "normalized":"brooklyn",
136
- "url":"http:\/\/vimeo.com\/tag:brooklyn",
137
- "_content":"brooklyn"
138
- },
139
- {
140
- "author":"580098",
141
- "id":"16600253",
142
- "normalized":"queens",
143
- "url":"http:\/\/vimeo.com\/tag:queens",
144
- "_content":"queens"
145
- },
146
- {
147
- "author":"580098",
148
- "id":"16600260",
149
- "normalized":"manhattan",
150
- "url":"http:\/\/vimeo.com\/tag:manhattan",
151
- "_content":"manhattan"
152
- },
153
- {
154
- "author":"580098",
155
- "id":"16600262",
156
- "normalized":"bike",
157
- "url":"http:\/\/vimeo.com\/tag:bike",
158
- "_content":"bike"
159
- },
160
- {
161
- "author":"580098",
162
- "id":"16600264",
163
- "normalized":"gear",
164
- "url":"http:\/\/vimeo.com\/tag:gear",
165
- "_content":"gear"
166
- },
167
- {
168
- "author":"580098",
169
- "id":"16600290",
170
- "normalized":"faze-o",
171
- "url":"http:\/\/vimeo.com\/tag:faze-o",
172
- "_content":"faze-o"
173
- },
174
- {
175
- "author":"580098",
176
- "id":"16600291",
177
- "normalized":"ridinghigh",
178
- "url":"http:\/\/vimeo.com\/tag:ridinghigh",
179
- "_content":"riding high"
180
- },
181
- {
182
- "author":"580098",
183
- "id":"16600378",
184
- "normalized":"cruising",
185
- "url":"http:\/\/vimeo.com\/tag:cruising",
186
- "_content":"cruising"
187
- },
188
- {
189
- "author":"580098",
190
- "id":"16600396",
191
- "normalized":"riding",
192
- "url":"http:\/\/vimeo.com\/tag:riding",
193
- "_content":"riding"
194
- }
195
- ]
196
- },
197
- "cast":{
198
- "member":{
199
- "display_name":"13thWitness\u2122",
200
- "id":"580098",
201
- "role":"",
202
- "username":"the13thwitness"
203
- }
204
- },
205
- "urls":{
206
- "url":[
207
- {
208
- "type":"video",
209
- "_content":"http:\/\/vimeo.com\/6788487"
210
- },
211
- {
212
- "type":"group",
213
- "_content":"http:\/\/vimeo.com\/groups\/HDXS\/videos\/6788487"
214
- },
215
- {
216
- "type":"group",
217
- "_content":"http:\/\/vimeo.com\/groups\/11906\/videos\/6788487"
218
- }
219
- ]
220
- },
221
- "thumbnails":{
222
- "thumbnail":[
223
- {
224
- "height":"75",
225
- "width":"100",
226
- "_content":"http:\/\/ts.vimeo.com.s3.amazonaws.com\/269\/983\/26998387_100.jpg"
227
- },
228
- {
229
- "height":"150",
230
- "width":"200",
231
- "_content":"http:\/\/ts.vimeo.com.s3.amazonaws.com\/269\/983\/26998387_200.jpg"
232
- },
233
- {
234
- "height":"360",
235
- "width":"640",
236
- "_content":"http:\/\/ts.vimeo.com.s3.amazonaws.com\/269\/983\/26998387_640.jpg"
237
- },
238
- {
239
- "height":"720",
240
- "width":"1280",
241
- "_content":"http:\/\/bitcast.vimeo.com\/vimeo\/thumbnails\/defaults\/default.300x400.jpg"
242
- }
243
- ]
244
173
  }
245
- }
174
+ ]
246
175
  }
@@ -0,0 +1,5 @@
1
+ {
2
+ "oembed":{
3
+ "html":"Hello embedded world <%= @vars.to_s -%>"
4
+ }
5
+ }
@@ -0,0 +1,58 @@
1
+ require 'spec_helper'
2
+ require File.expand_path '../../vimeo_helper', __FILE__
3
+
4
+ class Project < ActiveRecord::Base
5
+ vimeo_video :video
6
+ end
7
+
8
+ class CreateModels < ActiveRecord::Migration
9
+ def self.up
10
+ create_table :projects do |t|
11
+ t.string :video_id
12
+ end
13
+ end
14
+
15
+ def self.down
16
+ end
17
+ end
18
+
19
+ ActiveRecord::Base.connection.drop_table("projects") if ActiveRecord::Base.connection.tables.include?("projects")
20
+ ActiveRecord::Migration.verbose = false
21
+ CreateModels.up
22
+
23
+ describe "RefinerycmsVimeoVideos ActiveRecord extension" do
24
+
25
+ before(:each) do
26
+ RefinerySetting.set(:vimeo_consumer_key, '12345')
27
+ RefinerySetting.set(:vimeo_consumer_secret, 'secret')
28
+ RefinerySetting.set(:vimeo_token, 'token')
29
+ RefinerySetting.set(:vimeo_secret, 'secret')
30
+ end
31
+
32
+ it "should return nil if new record" do
33
+ project = Project.new
34
+ project.video.should == nil
35
+ end
36
+
37
+ it "should return value if new record and vimeo id assigned" do
38
+ project = Project.new
39
+ project.video_id = "12345"
40
+ project.video.should == "12345"
41
+ end
42
+
43
+ it "should not let video be assigned directly" do
44
+ project = Project.new
45
+ lambda { project.video = "100" }.should raise_error NoMethodError
46
+ end
47
+
48
+ it "should return vimeo meta cache if vimeo id assigned and not new_record?" do
49
+ stub_post("?video_id=123498432&api_key=12345&format=json&method=vimeo.videos.getInfo&api_sig=0f1a7df7325961a0cf352da6264e913f", "advanced/video/get_info.json")
50
+ FakeWeb.register_uri(:get, "http://b.vimeocdn.com/ts/104/602/104602144_640.jpg", :body => "", :content_type => "image/jpeg")
51
+
52
+ project = Project.create!(:video_id => "123498432")
53
+
54
+ project.video.class.should == VimeoMetaCache
55
+ project.video.title.should == "Riding High"
56
+ end
57
+
58
+ end
@@ -27,7 +27,7 @@ describe VimeoEmbedCache do
27
27
  end
28
28
 
29
29
  it "should allow static embedding only if width and height given" do
30
- VimeoEmbedCache.embed(@valid_attributes[:vid], @valid_attributes[:geometry], :static => true).should_not == @vimeo_embed_cache.code
30
+ VimeoEmbedCache.embed(@valid_attributes[:vid], @valid_attributes[:geometry], :static => true).should_not == @vimeo_embed_cache
31
31
  lambda { VimeoEmbedCache.embed(@valid_attributes[:vid], '100', :static => true) }.should raise_error ArgumentError
32
32
  end
33
33
 
@@ -35,16 +35,24 @@ describe VimeoEmbedCache do
35
35
 
36
36
  context "caching" do
37
37
 
38
- it "fetches embedding if it has no cache for parameters" do
38
+ it "should fetch embed code if it has no cache for parameters" do
39
39
  stub_vimeo_embed_uri '400x200'
40
40
  VimeoEmbedCache.embed(@valid_attributes[:vid], '400x200').should_not == @vimeo_embed_cache
41
- VimeoEmbedCache.embed(@valid_attributes[:vid], '400x200').code == "Hello oembed world!"
41
+ VimeoEmbedCache.embed(@valid_attributes[:vid], '400x200') == "Hello oembed world 400x200"
42
42
  end
43
43
 
44
44
  it "should fetch video from cache" do
45
45
  VimeoEmbedCache.embed(@valid_attributes[:vid], @valid_attributes[:geometry]).should == @vimeo_embed_cache
46
46
  end
47
47
 
48
+ it "should override cache on update_cache" do
49
+ vec = VimeoEmbedCache.find_by_vid(123456)
50
+ vec.code = "Hello"
51
+ vec.save
52
+ vec.update_cache
53
+ vec.code.should_not == "Hello"
54
+ end
55
+
48
56
  end
49
57
 
50
58
  context "geometry" do
@@ -5,7 +5,7 @@ describe VimeoMetaCache do
5
5
  def reset_vimeo_meta_cache(options = {})
6
6
  @valid_attributes = {
7
7
  :id => 1,
8
- :title => "RSpec is great for testing too"
8
+ :vid => "123498432"
9
9
  }
10
10
 
11
11
  @vimeo_meta_cache.destroy! if @vimeo_meta_cache
@@ -13,11 +13,28 @@ describe VimeoMetaCache do
13
13
  end
14
14
 
15
15
  before(:each) do
16
+ stub_post("?video_id=123498432&api_key=12345&format=json&method=vimeo.videos.getInfo&api_sig=0f1a7df7325961a0cf352da6264e913f", "advanced/video/get_info.json")
17
+ FakeWeb.register_uri(:get, "http://b.vimeocdn.com/ts/104/602/104602144_640.jpg", :body => "", :content_type => "image/jpeg")
16
18
  reset_vimeo_meta_cache
17
19
  end
20
+
21
+ context "caching" do
22
+
23
+ it "should cache title and description" do
24
+ @vimeo_meta_cache.title.should == "Riding High"
25
+ @vimeo_meta_cache.description.should == "<p>Riding High description</p>"
26
+ end
27
+
28
+ end
18
29
 
19
- context "validations" do
30
+ context "update_cache" do
20
31
 
32
+ it "should update title and description if force = true" do
33
+ vmc = VimeoMetaCache.create!(@valid_attributes.merge(:title => "Riding Low", :description => "Low Rider"))
34
+ vmc.update_cache
35
+ vmc.title.should == "Riding High"
36
+ vmc.description.should == "<p>Riding High description</p>"
37
+ end
21
38
 
22
39
  end
23
40
 
@@ -18,7 +18,6 @@ describe VimeoVideo do
18
18
 
19
19
  context "validations" do
20
20
 
21
-
22
21
  end
23
22
 
24
23
  end
Binary file
data/spec/vimeo_helper.rb CHANGED
@@ -1,4 +1,6 @@
1
1
  require 'fakeweb'
2
+ require 'erb'
3
+ require 'ostruct'
2
4
 
3
5
  FakeWeb.allow_net_connect = false
4
6
 
@@ -11,6 +13,14 @@ def fixture_file(filename)
11
13
  File.read(file_path)
12
14
  end
13
15
 
16
+ def erb_fixture_file(filename, vars)
17
+ return '' if filename == ''
18
+
19
+ av = ActionView::Base.new(File.expand_path(File.dirname(__FILE__) + '/fixtures/'))
20
+ av.assign({:vars => vars})
21
+ av.render(:template => filename)
22
+ end
23
+
14
24
  def vimeo_base_url(url = "/")
15
25
  "http://vimeo.com#{url}"
16
26
  end
@@ -47,8 +57,10 @@ end
47
57
  def stub_vimeo_embed_uri(geometry)
48
58
  geometry_hash = VimeoEmbedCache.geometry_hash(geometry)
49
59
 
60
+ vars = OpenStruct.new :geometry => geometry
61
+
50
62
  FakeWeb.register_uri( :get,
51
63
  "http://vimeo.com/api/oembed.xml?url=http%3A%2F%2Fvimeo.com%2F123456&#{geometry_hash.to_query}",
52
- :body => fixture_file("oembed/oembed.json"),
64
+ :body => erb_fixture_file("oembed/oembed.json.erb", geometry),
53
65
  :content_type => 'application/json' )
54
66
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: refinerycms-vimeo-videos
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.6
5
+ version: 0.1.7
6
6
  platform: ruby
7
7
  authors:
8
8
  - Marian Andre
@@ -83,10 +83,13 @@ files:
83
83
  - db/seeds/vimeo_videos.rb
84
84
  - features/manage_vimeo_videos.feature
85
85
  - features/step_definitions/vimeo_video_steps.rb
86
+ - features/support/factories.rb
86
87
  - features/support/paths.rb
87
88
  - lib/generators/refinerycms_vimeo_videos_generator.rb
88
89
  - lib/refinerycms-vimeo-videos.rb
89
90
  - lib/refinerycms_vimeo_videos/account.rb
91
+ - lib/refinerycms_vimeo_videos/active_record_extension.rb
92
+ - lib/refinerycms_vimeo_videos/url_tempfile.rb
90
93
  - lib/refinerycms_vimeo_videos/version.rb
91
94
  - lib/tasks/vimeo_videos.rake
92
95
  - public/javascripts/refinery/vimeo_videos.js
@@ -179,7 +182,7 @@ files:
179
182
  - spec/fixtures/advanced/video/set_title.json
180
183
  - spec/fixtures/advanced/video_embed/get_presets.json
181
184
  - spec/fixtures/advanced/video_embed/set_preset.json
182
- - spec/fixtures/oembed/oembed.json
185
+ - spec/fixtures/oembed/oembed.json.erb
183
186
  - spec/fixtures/simple/activity/contacts_did.json
184
187
  - spec/fixtures/simple/activity/everyone_did.json
185
188
  - spec/fixtures/simple/activity/happened_to_contacts.json
@@ -204,9 +207,11 @@ files:
204
207
  - spec/fixtures/simple/user/subscriptions.json
205
208
  - spec/fixtures/simple/user/videos.json
206
209
  - spec/fixtures/simple/video/info.json
210
+ - spec/models/active_record_extension_spec.rb
207
211
  - spec/models/vimeo_embed_cache_spec.rb
208
212
  - spec/models/vimeo_meta_cache_spec.rb
209
213
  - spec/models/vimeo_video_spec.rb
214
+ - spec/samples/taj.jpg
210
215
  - spec/vimeo_helper.rb
211
216
  has_rdoc: true
212
217
  homepage: http://bitflut.com
@@ -1,5 +0,0 @@
1
- {
2
- "oembed":{
3
- "html":"Hello embedded world!"
4
- }
5
- }