Created
November 29, 2010 19:55
-
-
Save oscardelben/720494 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def oauth | |
OAuth::Consumer.new( | |
consumer_key, | |
consumer_secret, | |
{ | |
:site => 'https://api.login.yahoo.com', | |
:scheme => :query_string, | |
:http_method => :get, | |
:request_token_path => '/oauth/v2/get_request_token', | |
:access_token_path => '/oauth/v2/get_token', | |
:authorize_path => '/oauth/v2/request_auth', | |
}) | |
end | |
def oauth_api | |
OAuth::Consumer.new( | |
consumer_key, | |
consumer_secret, | |
{ | |
:site => 'http://social.yahooapis.com', | |
:scheme => :header, | |
:realm => 'yahooapis.com', | |
:http_method => :get, | |
:request_token_path => '/oauth/v2/get_request_token', | |
:access_token_path => '/oauth/v2/get_token', | |
:authorize_path => '/oauth/v2/request_auth' | |
}) | |
end | |
### To authorize (note that oauth is the method above: | |
@request_token = oauth.get_request_token( | |
{ :oauth_callback => "http://example.com/callback" } ) | |
session['yahoo_rtoken'] = @request_token.token | |
session['yahoo_stoken'] = @request_token.secret | |
redirect_to @request_token.authorize_url | |
# callback | |
@request_token = OAuth::RequestToken.new( oauth, session['yahoo_rtoken'], session['yahoo_stoken'] ) | |
@access_token = @request_token.get_access_token({ :oauth_verifier => params[:oauth_verifier] }) | |
@access_token.consumer = oauth_api | |
session['yahoo_atoken'] = nil | |
session['yahoo_stoken'] = nil | |
## Example once you are authorized: | |
@access_token = OAuth::AccessToken.new( oauth_api, current_user.yahoo_atoken, current_user.yahoo_stoken ) | |
guid_response = @access_token.get('/v1/me/guid') | |
guid = XMLObject.new(guid_response.body).value | |
response = @access_token.get("/v1/user/#{guid}/contacts?count=max") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment