Skip to content

Instantly share code, notes, and snippets.

@joelongstreet
Last active January 2, 2016 12:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joelongstreet/8307544 to your computer and use it in GitHub Desktop.
Save joelongstreet/8307544 to your computer and use it in GitHub Desktop.
user.rb
require 'oauth'
class User < ActiveRecord::Base
validates :email, :email => true
validates :name, :passport_id, :presence => true
before_validation :get_passport_data, :on => :create
def get_passport_data
@consumer = OAuth::Consumer.new ENV['PASSPORT_OAUTH_KEY'],
ENV['PASSPORT_OAUTH_SECRET'],
{ :site => 'http://dev-site.vbox.local' }
@request_token = @consumer.get_request_token
@access_token = @request_token.get_access_token
@response_body = JSON.parse(@access_token.get("/rest/user/#{self.passport_id}").body)
self.name = "#{response_body['field_preferred_name']['label']} #{response_body['field_last_name']['label']}"
self.email = response_body['mail']
self.location = response_body['field_location']['label']
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment