Skip to content

Commit

Permalink
provide basic caching strategy for User Fetcher
Browse files Browse the repository at this point in the history
  • Loading branch information
farnoy committed Jan 21, 2012
1 parent aa25859 commit db28755
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions lib/github-api-client/fetchers/user.rb
Expand Up @@ -3,13 +3,21 @@ module Fetchers
module User
def self.get(login)
attributes = {}
Browser.start do |http|
request = Net::HTTP::Get.new "/users/#{login}"
attributes = Fetchers.parse(http.request(request).body)
model = Models::User.find_by_login(login)
unless model
Browser.start do |http|
request = Net::HTTP::Get.new "/users/#{login}"
attributes = Fetchers.parse(http.request(request).body)
end
else
# optional, but whatever
attributes = Resources::User.valid_attributes(model.attributes)
end
Resources::User.new.tap do |user|
user = Resources::User.new.tap do |user|
user.attributes = user.class.valid_attributes(attributes)
end
model ||= Models::User.create(user.attributes)
return model
end

def self.association_repositories(user)
Expand Down

0 comments on commit db28755

Please sign in to comment.