Last active
August 29, 2015 14:10
-
-
Save BRMatt/8e3cca6a942aca0fc489 to your computer and use it in GitHub Desktop.
Revisions
-
BRMatt revised this gist
Dec 2, 2014 . 1 changed file with 3 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -8,6 +8,9 @@ redirect_to client.auth_code.authorize_url # Member has been sent to Memberful by above redirect, then Memberful has sent the user back to the # callback action below: # I'd recommend playing around with this call and using obviously wrong values for params[:code] # e.g. "foobar" so that you can get an idea of how the OAuth2 gem will fail if it can't fetch # a valid token from Memberful. -
BRMatt created this gist
Dec 2, 2014 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,26 @@ require 'oauth2' client = OAuth2::Client.new( 'client_id', 'client_secret', :site => 'https://workshop.memberful.com', :authorize_url => '/oauth' ) redirect_to client.auth_code.authorize_url # I'd recommend playing around with this call and using obviously wrong values for params[:code] # e.g. "foobar" so that you can get an idea of how the OAuth2 gem will fail if it can't fetch # a valid token from Memberful. token = client.auth_code.get_token(params[:code]) # Get the member's account info. This will be the info described here # https://memberful.com/help/integrate/advanced/sign-members-in/ account_info = token.get('/account.json') member_info = account_info[:member] # http://api.rubyonrails.org/classes/ActiveRecord/Relation.html#method-i-find_or_create_by member = User.find_or_create_by( :id => member[:id], :name => member[:full_name], # .... )