social_current 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/social_current.rb +1 -1
- data/lib/social_current/service.rb +4 -4
- data/lib/social_current/version.rb +1 -1
- metadata +1 -1
data/lib/social_current.rb
CHANGED
@@ -5,8 +5,8 @@ module SocialCurrent
|
|
5
5
|
end
|
6
6
|
|
7
7
|
def fetch(remote, local)
|
8
|
-
@contents = if cache_valid?(local)
|
9
|
-
JSON.parse(
|
8
|
+
@contents = if cache_valid?("#{Dir.tmpdir}/#{local}")
|
9
|
+
JSON.parse(File.read("#{Dir.tmpdir}/#{local}"))
|
10
10
|
else
|
11
11
|
write_cache(local, JSON.parse(self.class.get(remote).body))
|
12
12
|
end
|
@@ -15,14 +15,14 @@ module SocialCurrent
|
|
15
15
|
private
|
16
16
|
|
17
17
|
def write_cache(local, contents)
|
18
|
-
|
18
|
+
File.open("#{Dir.tmpdir}/#{local}", "w") do |f|
|
19
19
|
f.write(contents.to_json)
|
20
20
|
end
|
21
21
|
contents
|
22
22
|
end
|
23
23
|
|
24
24
|
def cache_valid?(cache)
|
25
|
-
|
25
|
+
File.exists?(cache) && File.new(cache).mtime > Time.now - 3000
|
26
26
|
end
|
27
27
|
end
|
28
28
|
end
|