public
Last active

yahoo api with oauth-plugin

  • Download Gist
YahooToken.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
class YahooToken < ConsumerToken
 
YAHOO_SETTINGS={
:site => "https://api.login.yahoo.com",
:request_token_path => "/oauth/v2/get_request_token",
:access_token_path => "/oauth/v2/get_token",
:authorize_path=> "/oauth/v2/request_auth"
}
 
def self.consumer
@consumer||=OAuth::Consumer.new credentials[:key],credentials[:secret],YAHOO_SETTINGS
end
 
# refresh expired token
def refresh!
old_one = self
request_token = OAuth::RequestToken.new(YahooToken.consumer, self.token, self.secret)
 
options={}
options[:oauth_session_handle]=self.session_handle
 
access_token = request_token.get_access_token options
new_one = YahooToken.find_or_create_from_access_token self.user, access_token
new_one.session_handle=access_token.params[:oauth_session_handle]
new_one.save!
 
if new_one
old_one.delete
return new_one
end
 
return nil
end
 
def myapi
# api_url = .... Yahoo api url
request_token = OAuth::RequestToken.new(YahooToken.consumer, self.token, self.secret)
 
options={}
options[:oauth_session_handle]=self.session_handle
 
access_token = request_token.get_access_token options
response=access_token.get(api_url, { 'Accept'=>'application/json' })
return MultiJson.decode(response.body)
end
 
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.