aweplug 1.0.0.a21 → 1.0.0.a22

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,29 +1,3 @@
1
- # Aweplug
1
+ == aweplug
2
2
 
3
- TODO: Write a gem description
4
-
5
- ## Installation
6
-
7
- Add this line to your application's Gemfile:
8
-
9
- gem 'aweplug'
10
-
11
- And then execute:
12
-
13
- $ bundle
14
-
15
- Or install it yourself as:
16
-
17
- $ gem install aweplug
18
-
19
- ## Usage
20
-
21
- TODO: Write usage instructions here
22
-
23
- ## Contributing
24
-
25
- 1. Fork it
26
- 2. Create your feature branch (`git checkout -b my-new-feature`)
27
- 3. Commit your changes (`git commit -am 'Add some feature'`)
28
- 4. Push to the branch (`git push origin my-new-feature`)
29
- 5. Create new Pull Request
3
+ A set of Awestruct extensions aimed at creating OSS project websites.
@@ -15,14 +15,14 @@ module Aweplug
15
15
  # Returns the html snippet
16
16
  #
17
17
  def vimeo(url)
18
- video = Video.new(url, access_token, site)
18
+ video = get_video(url)
19
19
  #out = %Q[<div class="embedded-media">] +
20
20
  %Q[<h4>#{video.title}</h4><div class="flex-video widescreen vimeo">] +
21
21
  %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>] +
22
22
  %Q[</div>]
23
23
  #video.cast.each do |c|
24
24
  #out += %Q[<div class="follow-links">] +
25
- #%Q[<span class="title">Follow #{first_name(c.realname)}</span>] +
25
+ #%Q[<span class="title">Follow #{first_name(c.display_name)}</span>] +
26
26
  ## TODO add in follow links
27
27
  #%Q[<a><i class="icon-rss"></i></a>] +
28
28
  #%Q[<a><i class="icon-facebook"></i></a>] +
@@ -39,16 +39,16 @@ module Aweplug
39
39
  #
40
40
  # Returns the html snippet.
41
41
  def vimeo_thumb(url)
42
- video = Video.new(url, access_token, site)
43
- out = %Q{<a href="#{site.base_url}/video/vimeo/#{video.id}">} +
42
+ video = get_video(url)
43
+ out = %Q{<a href="#{video.detail_url}">} +
44
44
  %Q{<img src="#{video.thumb_url}" />} +
45
45
  %Q{</a>} +
46
46
  %Q{<span class="label material-duration">#{video.duration}</span>} +
47
47
  # TODO Add this in once the DCP supports manually adding tags
48
48
  # %Q{<span class="label material-level-beginner">Beginner<span>} +
49
- %Q{<h4><a href="#{video.thumb_url}">#{video.title}</a></h4>} +
49
+ %Q{<h4><a href="#{video.detail_url}">#{video.title}</a></h4>} +
50
50
  # TODO Wire in link to profile URL
51
- %Q{<p class="author">Author: <a href="#">#{video.author.realname}</a></p>} +
51
+ %Q{<p class="author">Author: <a href="#">#{video.author.display_name}</a></p>} +
52
52
  %Q{<p class="material-datestamp">Added #{video.upload_date}</p>} +
53
53
  # TODO wire in ratings
54
54
  #%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>} +
@@ -56,6 +56,24 @@ module Aweplug
56
56
  out
57
57
  end
58
58
 
59
+ # Internal: Retrieves the video object
60
+ #
61
+ # url: the Vimeo URL to retrieve the video from
62
+ def get_video(url)
63
+ if site.video_cache.nil?
64
+ site.send('video_cache=', {})
65
+ end
66
+ if site.video_cache.key?(url)
67
+ site.video_cache[url]
68
+ else
69
+ video = Video.new(url, access_token, site)
70
+ site.video_cache[url] = video
71
+ video
72
+ end
73
+ end
74
+
75
+
76
+
59
77
  # Internal: Extracts a firstname from a full name
60
78
  #
61
79
  # full_name - the full name, e.g. Pete Muir
@@ -78,6 +96,15 @@ module Aweplug
78
96
  fetch_info
79
97
  fetch_cast
80
98
  fetch_thumb_url
99
+ #log
100
+ end
101
+
102
+ def log
103
+ File.open("_tmp/vimeo_fetch.log", 'a') { |f| f.write(
104
+ "------------------------------------\n" +
105
+ "Id: #{@id}\n" +
106
+ "Cast: #{@cast}\n" +
107
+ "Author: #{author}\n") }
81
108
  end
82
109
 
83
110
  def id
@@ -93,9 +120,16 @@ module Aweplug
93
120
  Time.at(t).utc.strftime("%T")
94
121
  end
95
122
 
123
+ def modified_date
124
+ pretty_date(@video["modified_date"])
125
+ end
126
+
96
127
  def upload_date
97
- d = @video["upload_date"]
98
- DateTime.parse(d).strftime("%F %T")
128
+ pretty_date(@video["upload_date"])
129
+ end
130
+
131
+ def detail_url
132
+ "#{@site.base_url}/video/vimeo/#{id}"
99
133
  end
100
134
 
101
135
  def description
@@ -112,30 +146,20 @@ module Aweplug
112
146
  out += s
113
147
  end
114
148
  end
149
+ # Deal with the case that the description has no sentence end in it
150
+ out = out.empty? ? d : out
115
151
  end
116
- out || ''
152
+ out
117
153
  end
118
154
 
119
155
  def author
120
- if @cast[0]
121
- @cast[0]
122
- else
123
- @cast = OpenStruct.new({"realname" => "Unknown"})
124
- end
156
+ @author
125
157
  end
126
158
 
127
159
  def cast
128
160
  @cast || ''
129
161
  end
130
162
 
131
- def modified_date
132
- if @video["upload_date"]
133
- DateTime.parse(@video["upload_date"]).strftime("%F %T")
134
- else
135
- "UNKOWN DATE"
136
- end
137
- end
138
-
139
163
  def tags
140
164
  if @video['tags'].is_a? Hash
141
165
  @video['tags']['tag'].inject([]) do |result, element|
@@ -190,6 +214,7 @@ module Aweplug
190
214
  end
191
215
  end
192
216
  end
217
+ @author = @cast[0] ? @cast[0] : OpenStruct.new({"display_name" => "Unknown"})
193
218
  end
194
219
 
195
220
  # Internal: Execute a method against the Vimeo API
@@ -204,6 +229,27 @@ module Aweplug
204
229
  access_token.get(query).body
205
230
  end
206
231
  end
232
+
233
+ def pretty_date(date_str)
234
+ date = DateTime.parse(date_str)
235
+ a = (Time.now-date.to_time).to_i
236
+
237
+ case a
238
+ when 0 then 'just now'
239
+ when 1 then 'a second ago'
240
+ when 2..59 then a.to_s+' seconds ago'
241
+ when 60..119 then 'a minute ago' #120 = 2 minutes
242
+ when 120..3540 then (a/60).to_i.to_s+' minutes ago'
243
+ when 3541..7100 then 'an hour ago' # 3600 = 1 hour
244
+ when 7101..82800 then ((a+99)/3600).to_i.to_s+' hours ago'
245
+ when 82801..172000 then 'a day ago' # 86400 = 1 day
246
+ when 172001..518400 then ((a+800)/(60*60*24)).to_i.to_s+' days ago'
247
+ when 518400..1036800 then 'a week ago'
248
+ when 1036800..4147200 then ((a+180000)/(60*60*24*7)).to_i.to_s+' weeks ago'
249
+ else date.strftime("%F")
250
+ end
251
+ end
252
+
207
253
  end
208
254
 
209
255
  # Internal: Obtains an OAuth::AcccessToken for the Vimeo API, using the
@@ -1,4 +1,4 @@
1
1
  module Aweplug
2
- VERSION='1.0.0.a21'
2
+ VERSION='1.0.0.a22'
3
3
  end
4
4
 
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.a21
4
+ version: 1.0.0.a22
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-03-13 00:00:00.000000000 Z
12
+ date: 2014-03-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: octokit
@@ -191,7 +191,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
191
191
  version: '0'
192
192
  segments:
193
193
  - 0
194
- hash: 2565258213881195966
194
+ hash: 930035991948049599
195
195
  required_rubygems_version: !ruby/object:Gem::Requirement
196
196
  none: false
197
197
  requirements: