aweplug 1.0.0.a18 → 1.0.0.a19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -70,10 +70,14 @@ module Aweplug
70
70
  #
71
71
  # Returns nothing.
72
72
  def execute site
73
+ if site.cache.nil?
74
+ site.send('cache=', Aweplug::Cache::YamlFileCache.new)
75
+ end
73
76
  searchisko = Aweplug::Helpers::Searchisko.new({:base_url => site.dcp_base_url,
74
77
  :authenticate => true,
75
78
  :searchisko_username => ENV['dcp_user'],
76
79
  :searchisko_password => ENV['dcp_password'],
80
+ :cache => site.cache,
77
81
  :logger => site.profile == 'developement'})
78
82
  Find.find @directory do |path|
79
83
  Find.prune if File.directory?(path) && !@recurse_subdirectories
@@ -55,12 +55,16 @@ module Aweplug
55
55
  #
56
56
  # Returns nothing.
57
57
  def execute site
58
+ if site.cache.nil?
59
+ site.send('cache=', Aweplug::Cache::YamlFileCache.new)
60
+ end
58
61
  # Not sure if it's better to do this once per class,
59
62
  # once per site, or once per invocation
60
63
  searchisko = Aweplug::Helpers::Searchisko.new({:base_url => site.dcp_base_url,
61
64
  :authenticate => true,
62
65
  :searchisko_username => ENV['dcp_user'],
63
66
  :searchisko_password => ENV['dcp_password'],
67
+ :cache => site.cache,
64
68
  :logger => site.profile == 'developement'})
65
69
  Dir["#{@repo}/**/README.md"].each do |file|
66
70
  next if @excludes.include?(File.dirname(file))
@@ -16,6 +16,7 @@ module Aweplug
16
16
  # :logging - Boolean to log responses
17
17
  # :raise_error - Boolean flag if 404 and 500 should raise exceptions
18
18
  # :adapter - faraday adapter to use, defaults to :net_http
19
+ # :cache - Instance of a cache to use
19
20
  #
20
21
  # Returns a new instance of Searchisko.
21
22
  def initialize opts={}
@@ -29,7 +30,7 @@ module Aweplug
29
30
  end
30
31
  builder.response :logger if opts[:logging]
31
32
  builder.response :raise_error if opts[:raise_error]
32
- builder.use FaradayMiddleware::Caching, Aweplug::Cache::YamlFileCache.new, {}
33
+ builder.use FaradayMiddleware::Caching, opts[:cache], {}
33
34
  #builder.response :json, :content_type => /\bjson$/
34
35
  builder.adapter opts[:adapter] || :net_http
35
36
  end
@@ -1,4 +1,6 @@
1
1
  require 'oauth'
2
+ require 'aweplug/cache/yaml_file_cache'
3
+ require 'pry'
2
4
 
3
5
  module Aweplug
4
6
  module Helpers
@@ -65,9 +67,14 @@ module Aweplug
65
67
  # Internal: Data object to hold and parse values from the Vimeo API.
66
68
  class Video
67
69
  include Aweplug::Helpers::Vimeo
70
+
68
71
  def initialize(url, access_token, site)
69
72
  @id = url.match(/^.*\/(\d*)$/)[1]
70
73
  @site = site
74
+ if site.cache.nil?
75
+ site.send('cache=', Aweplug::Cache::YamlFileCache.new)
76
+ end
77
+ @cache = site.cache
71
78
  @access_token = access_token
72
79
  fetch_info
73
80
  fetch_cast
@@ -83,7 +90,7 @@ module Aweplug
83
90
  end
84
91
 
85
92
  def duration
86
- t = @video["duration"].to_i
93
+ t = Integer @video["duration"]
87
94
  Time.at(t).utc.strftime("%T")
88
95
  end
89
96
 
@@ -145,12 +152,17 @@ module Aweplug
145
152
  @thumb["_content"] || ''
146
153
  end
147
154
 
148
- def fetch_info
149
- body = exec_method "vimeo.videos.getInfo", @id
150
- if body
151
- @video = JSON.parse(body)["video"][0]
155
+ def fetch_info
156
+ if @cache.read(@id).nil?
157
+ body = exec_method "vimeo.videos.getInfo", @id
158
+ if body
159
+ @video = JSON.parse(body)["video"][0]
160
+ @cache.write(@id, body)
161
+ else
162
+ @video = {"title" => "Unable to fetch video info from vimeo"}
163
+ end
152
164
  else
153
- @video = {"title" => "Unable to fetch video info from vimeo"}
165
+ @video = JSON.parse(@cache.read(@id))['video'][0]
154
166
  end
155
167
  end
156
168
 
@@ -165,21 +177,21 @@ module Aweplug
165
177
  def fetch_cast
166
178
  @cast = []
167
179
  if @video['cast']
168
- cast = @video["cast"]
169
- if cast['total'] != '1'
180
+ cast = @video['cast']
181
+ if cast['member'].is_a? Hash
182
+ if cast['member']['username'] != 'jbossdeveloper'
183
+ @cast << OpenStruct.new(cast['member'])
184
+ end
185
+ else
170
186
  cast["member"].each do |c|
171
187
  o = OpenStruct.new(c)
172
188
  if o.username != "jbossdeveloper"
173
189
  @cast << o
174
190
  end
175
- end
176
- else
177
- if cast['member']['username'] != 'jbossdeveloper'
178
- @cast << OpenStruct.new(cast['member'])
179
191
  end
180
192
  end
181
- end
182
- end
193
+ end
194
+ end
183
195
 
184
196
  # Internal: Execute a method against the Vimeo API
185
197
  #
@@ -1,4 +1,4 @@
1
1
  module Aweplug
2
- VERSION='1.0.0.a18'
2
+ VERSION='1.0.0.a19'
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.a18
4
+ version: 1.0.0.a19
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-10 00:00:00.000000000 Z
12
+ date: 2014-03-11 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: 2401597976548953007
194
+ hash: 846519133645315994
195
195
  required_rubygems_version: !ruby/object:Gem::Requirement
196
196
  none: false
197
197
  requirements: