Class: SocialCurrent::Service

Inherits:
Object
  • Object
show all
Defined in:
lib/social_current/service.rb

Direct Known Subclasses

GithubService, TwitterService

Instance Method Summary collapse

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