Class: SocialCurrent::Service
- Inherits:
-
Object
- Object
- SocialCurrent::Service
- Defined in:
- lib/social_current/service.rb
Direct Known Subclasses
Instance Method Summary collapse
- #fetch(remote, local) ⇒ Object
-
#initialize(user) ⇒ Service
constructor
A new instance of Service.
Constructor Details
#initialize(user) ⇒ Service
Returns a new instance of Service.
3 4 5 |
# File 'lib/social_current/service.rb', line 3 def initialize(user) @user = user end |
Instance Method Details
#fetch(remote, local) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/social_current/service.rb', line 7 def fetch(remote, local) if cache_valid?("#{Dir.tmpdir}/#{local}") JSON.parse(File.read("#{Dir.tmpdir}/#{local}")) else response = self.class.get(remote) if response.header.code == "404" [] else write_cache(local, JSON.parse(response.body)) JSON.parse(response.body) end end end |