Permalink
Browse files

Utilize block version of gh_client in all scenarios

  • Loading branch information...
1 parent 60dc868 commit 6196609a4c4aa192075f16bf80a86dffb74b4fd2 @rwdaigle committed Nov 7, 2012
Showing with 4 additions and 5 deletions.
  1. +4 −5 app/models/gist_fetcher.rb
View
9 app/models/gist_fetcher.rb
@@ -33,18 +33,17 @@ def fetch_gists(user_id)
def fetch_gist_files(user_id, gh_gist_id)
user = User.find(user_id)
log({ns: self, fn: __method__, measure: true, gh_gist_id: gh_gist_id}, user) do
- gh = gh_client(user)
- GistFile.import(gh.gist(gh_gist_id))
+ gh_client(user) do |gh|
+ GistFile.import(gh.gist(gh_gist_id))
+ end
end
end
private
def gh_client(user)
- client = Octokit::Client.new(:login => user.gh_username, :oauth_token => user.gh_oauth_token, :auto_traversal => true)
begin
- client.user # throws exception if oauth not cool
- yield client
+ yield Octokit::Client.new(:login => user.gh_username, :oauth_token => user.gh_oauth_token, :auto_traversal => true)
rescue Octokit::Unauthorized => e
log_exception({ns: self, fn: __method__, measure: true}, user, e)
user.invalidate_auth!

0 comments on commit 6196609

Please sign in to comment.