Skip to content

Commit

Permalink
Tumblr's API sometimes returns an array, sometimes not
Browse files Browse the repository at this point in the history
  • Loading branch information
jamiew committed Apr 14, 2011
1 parent 93c9ecf commit ef02aff
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions oa-oauth/lib/omniauth/strategies/tumblr.rb
Expand Up @@ -24,7 +24,6 @@ def initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &bl
end

def auth_hash
user = user_hash['tumblr']['tumblelog'][0]
OmniAuth::Utils.deep_merge(super, {
'uid' => user['name'],
'user_info' => user_info,
Expand All @@ -33,7 +32,6 @@ def auth_hash
end

def user_info
user = user_hash['tumblr']['tumblelog'][0]
{
'nickname' => user['name'],
'name' => user['title'],
Expand All @@ -44,6 +42,15 @@ def user_info
}
end

def user
tumblelogs = user_hash['tumblr']['tumblelog']
if tumblelogs.kind_of?(Array)
@user ||= tumblelogs[0]
else
@user ||= tumblelogs
end
end

def user_hash
url = "http://www.tumblr.com/api/authenticate"
@user_hash ||= Hash.from_xml(@access_token.get(url).body)
Expand Down

0 comments on commit ef02aff

Please sign in to comment.