aweplug 1.0.0.a15 → 1.0.0.a16
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/aweplug/helpers/vimeo.rb +167 -80
- data/lib/aweplug/version.rb +1 -1
- metadata +3 -3
@@ -14,24 +14,47 @@ module Aweplug
|
|
14
14
|
# Returns the html snippet
|
15
15
|
#
|
16
16
|
def vimeo(url)
|
17
|
-
|
18
|
-
title = video_title(id)
|
17
|
+
video = Video.new(url, access_token, site)
|
19
18
|
out = %Q[<div class="embedded-media">] +
|
20
|
-
|
21
|
-
|
22
|
-
cast
|
23
|
-
cast.each do |c|
|
19
|
+
%Q[<h4>#{video.title}</h4>] +
|
20
|
+
%Q[<iframe src="//player.vimeo.com/video/#{video.id}\?title=0&byline=0&portrait=0&badge=0&color=2664A2" width="500" height="313" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen}></iframe>]
|
21
|
+
video.cast.each do |c|
|
24
22
|
out += %Q[<div class="follow-links">] +
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
23
|
+
%Q[<span class="title">Follow #{first_name(c.realname)}</span>] +
|
24
|
+
# TODO add in follow links
|
25
|
+
%Q[<a><i class="icon-rss"></i></a>] +
|
26
|
+
%Q[<a><i class="icon-facebook"></i></a>] +
|
27
|
+
%Q[<a><i class="icon-twitter"></i></a>] +
|
28
|
+
%Q[<a><i class="icon-linkedin"></i></a>] +
|
29
|
+
%Q[</div>]
|
31
30
|
end
|
32
31
|
out + %Q[</div>]
|
33
32
|
end
|
34
33
|
|
34
|
+
# Public: Embeds a vimeo video thumbnail into a web page. Retrieves the title
|
35
|
+
# and video cast from vimeo using the authenticated API.
|
36
|
+
#
|
37
|
+
# url - the URL of the vimeo page for the video to display
|
38
|
+
#
|
39
|
+
# Returns the html snippet.
|
40
|
+
def vimeo_thumb(url)
|
41
|
+
video = Video.new(url, access_token, site)
|
42
|
+
out = %Q{<a href="#{site.base_url}/video/vimeo/#{video.id}">} +
|
43
|
+
%Q{<img src="#{video.thumb_url}" />} +
|
44
|
+
%Q{</a>} +
|
45
|
+
%Q{<span class="label material-duration">#{video.duration}</span>} +
|
46
|
+
# TODO Add this in once the DCP supports manually adding tags
|
47
|
+
# %Q{<span class="label material-level-beginner">Beginner<span>} +
|
48
|
+
%Q{<h4><a href="#{video.thumb_url}">#{video.title}</a></h4>} +
|
49
|
+
# TODO Wire in link to profile URL
|
50
|
+
%Q{<p class="author">Author: <a href="#">#{video.author.realname}</a></p>} +
|
51
|
+
%Q{<p class="material-datestamp">Added #{video.upload_date}</p>} +
|
52
|
+
# TODO wire in ratings
|
53
|
+
#%Q{<p class="rating">Video<i class="fa fa-star"></i><i class="fa fa-star"></i><i class="fa fa-star"></i><i class="fa fa-star-half-empty"></i><i class="fa fa-star-empty"></i></p>} +
|
54
|
+
%Q{<div class="body"><p>#{video.description}</p></div>}
|
55
|
+
out
|
56
|
+
end
|
57
|
+
|
35
58
|
# Internal: Extracts a firstname from a full name
|
36
59
|
#
|
37
60
|
# full_name - the full name, e.g. Pete Muir
|
@@ -39,87 +62,151 @@ module Aweplug
|
|
39
62
|
full_name.split[0]
|
40
63
|
end
|
41
64
|
|
42
|
-
# Internal:
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
65
|
+
# Internal: Data object to hold and parse values from the Vimeo API.
|
66
|
+
class Video
|
67
|
+
def initialize(url, access_token, site)
|
68
|
+
@id = url.match(/^.*\/(\d*)$/)[1]
|
69
|
+
@site = site
|
70
|
+
@access_token = access_token
|
71
|
+
fetch_info
|
72
|
+
fetch_cast
|
73
|
+
fetch_thumb_url
|
74
|
+
end
|
48
75
|
|
49
|
-
|
50
|
-
|
51
|
-
# video_id - the id of the video to fetch the title for
|
52
|
-
def video_title(video_id)
|
53
|
-
body = exec_method "vimeo.videos.getInfo", video_id
|
54
|
-
if body
|
55
|
-
JSON.parse(body)["video"][0]["title"]
|
56
|
-
else
|
57
|
-
"Unable to fetch video info from vimeo"
|
76
|
+
def id
|
77
|
+
@id
|
58
78
|
end
|
59
|
-
end
|
60
79
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
80
|
+
def title
|
81
|
+
@video["title"]
|
82
|
+
end
|
83
|
+
|
84
|
+
def duration
|
85
|
+
t = @video["duration"].to_i
|
86
|
+
Time.at(t).utc.strftime("%T")
|
87
|
+
end
|
88
|
+
|
89
|
+
def upload_date
|
90
|
+
d = @video["upload_date"]
|
91
|
+
DateTime.parse(d).strftime("%F %T")
|
92
|
+
end
|
93
|
+
|
94
|
+
def description
|
95
|
+
d = @video["description"]
|
96
|
+
out = ""
|
97
|
+
if d
|
98
|
+
i = 0
|
99
|
+
max_length = 150
|
100
|
+
d.scan(/[^\.!?]+[\.!?]/).map(&:strip).each do |s|
|
101
|
+
i += s.length
|
102
|
+
if i > max_length
|
103
|
+
break
|
104
|
+
else
|
105
|
+
out += s
|
106
|
+
end
|
107
|
+
end
|
70
108
|
end
|
109
|
+
out
|
71
110
|
end
|
72
|
-
cast
|
73
|
-
end
|
74
111
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
def exec_method(method, video_id)
|
82
|
-
if access_token
|
83
|
-
query = "http://vimeo.com/api/rest/v2?method=#{method}&video_id=#{video_id}&format=json"
|
84
|
-
access_token.get(query).body
|
112
|
+
def author
|
113
|
+
if @cast[0]
|
114
|
+
@cast[0]
|
115
|
+
else
|
116
|
+
@cast = Openstruct.new({"realname" => "Unknown"})
|
117
|
+
end
|
85
118
|
end
|
86
|
-
end
|
87
119
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
if
|
99
|
-
|
100
|
-
|
120
|
+
def cast
|
121
|
+
@cast
|
122
|
+
end
|
123
|
+
|
124
|
+
def thumb_url
|
125
|
+
@thumb["_content"]
|
126
|
+
end
|
127
|
+
|
128
|
+
def fetch_info
|
129
|
+
body = exec_method "vimeo.videos.getInfo", @id
|
130
|
+
if body
|
131
|
+
@video = JSON.parse(body)["video"][0]
|
132
|
+
else
|
133
|
+
@video = {"title" => "Unable to fetch video info from vimeo"}
|
101
134
|
end
|
102
|
-
|
103
|
-
|
104
|
-
|
135
|
+
end
|
136
|
+
|
137
|
+
def fetch_thumb_url
|
138
|
+
body = exec_method "vimeo.videos.getThumbnailUrls", @id
|
139
|
+
if body
|
140
|
+
@thumb = JSON.parse(body)["thumbnails"]["thumbnail"][1]
|
141
|
+
else
|
142
|
+
@thumb = {"_content" => ""}
|
105
143
|
end
|
106
|
-
|
107
|
-
|
108
|
-
|
144
|
+
end
|
145
|
+
|
146
|
+
def fetch_cast
|
147
|
+
body = exec_method "vimeo.videos.getCast", @id
|
148
|
+
@cast = []
|
149
|
+
if body
|
150
|
+
JSON.parse(body)["cast"]["member"].each do |c|
|
151
|
+
o = OpenStruct.new(c)
|
152
|
+
if o.username != "jbossdeveloper"
|
153
|
+
@cast << o
|
154
|
+
end
|
155
|
+
end
|
109
156
|
end
|
110
|
-
|
111
|
-
|
112
|
-
|
157
|
+
end
|
158
|
+
|
159
|
+
# Internal: Execute a method against the Vimeo API
|
160
|
+
#
|
161
|
+
# method - the API method to execute
|
162
|
+
# video_id - the id of the video to execute the method for
|
163
|
+
#
|
164
|
+
# Returns JSON retreived from the Vimeo API
|
165
|
+
def exec_method(method, video_id)
|
166
|
+
if access_token
|
167
|
+
query = "http://vimeo.com/api/rest/v2?method=#{method}&video_id=#{video_id}&format=json"
|
168
|
+
access_token.get(query).body
|
113
169
|
end
|
114
|
-
|
115
|
-
|
116
|
-
|
170
|
+
end
|
171
|
+
|
172
|
+
# Internal: Obtains an OAuth::AcccessToken for the Vimeo API, using the
|
173
|
+
# vimeo_client_id and vimeo_access_token defined in site/config.yml and
|
174
|
+
# vimeo_client_secret and vimeo_access_token_secret defined in environment
|
175
|
+
# variables
|
176
|
+
#
|
177
|
+
# site - Awestruct Site instance
|
178
|
+
#
|
179
|
+
# Returns an OAuth::AccessToken for the Vimeo API
|
180
|
+
def access_token
|
181
|
+
if @access_token
|
182
|
+
@access_token
|
183
|
+
else
|
184
|
+
if not ENV['vimeo_client_secret']
|
185
|
+
puts 'Cannot fetch video info from vimeo, vimeo_client_secret is missing from environment variables'
|
186
|
+
return
|
187
|
+
end
|
188
|
+
if not @site.vimeo_client_id
|
189
|
+
puts 'Cannot fetch video info vimeo, vimeo_client_id is missing from _config/site.yml'
|
190
|
+
return
|
191
|
+
end
|
192
|
+
if not ENV['vimeo_access_token_secret']
|
193
|
+
puts 'Cannot fetch video info from vimeo, vimeo_access_token_secret is missing from environment variables'
|
194
|
+
return
|
195
|
+
end
|
196
|
+
if not @site.vimeo_access_token
|
197
|
+
puts 'Cannot fetch video info from vimeo, vimeo_access_token is missing from _config/site.yml'
|
198
|
+
return
|
199
|
+
end
|
200
|
+
consumer = OAuth::Consumer.new(@site.vimeo_client_id, ENV['vimeo_client_secret'],
|
201
|
+
{ :site => "https://vimeo.com",
|
202
|
+
:scheme => :header
|
117
203
|
})
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
204
|
+
# now create the access token object from passed values
|
205
|
+
token_hash = { :oauth_token => @site.vimeo_access_token,
|
206
|
+
:oauth_token_secret => ENV['vimeo_access_token_secret']
|
207
|
+
}
|
208
|
+
OAuth::AccessToken.from_hash(consumer, token_hash )
|
209
|
+
end
|
123
210
|
end
|
124
211
|
end
|
125
212
|
end
|
data/lib/aweplug/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aweplug
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0.
|
4
|
+
version: 1.0.0.a16
|
5
5
|
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-02-
|
12
|
+
date: 2014-02-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: octokit
|
@@ -190,7 +190,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
190
190
|
version: '0'
|
191
191
|
segments:
|
192
192
|
- 0
|
193
|
-
hash:
|
193
|
+
hash: -3016901967987087946
|
194
194
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
195
195
|
none: false
|
196
196
|
requirements:
|