Sha256: 6b47743856cea86a823b557975217a86f34791c1f7bbb65fc9819235551b647f

Contents?: true

Size: 911 Bytes

Versions: 3

Compression:

Stored size: 911 Bytes

Contents

module RestPack::User::Service::Models
  class Authentication < ActiveRecord::Base
    self.table_name = :restpack_authentications

    attr_accessible :application_id, :oauth, :provider, :uid, :user_id, :omniauth
    serialize :oauth, JSON

    validates_presence_of :application_id, :omniauth, :provider, :uid, :user_id
    validates :provider, :length => { :maximum => 128 }
    validates :uid, :length => { :maximum => 1024 }

    belongs_to :user

    def self.from_omniauth(application_id, omniauth)
      Authentication.new(
        application_id: application_id,
        provider: omniauth['provider'],
        uid: omniauth['uid'],
        omniauth: omniauth
      )
    end

    def self.get_by_omniauth(application_id, omniauth)
      Authentication.where(
        application_id: application_id,
        provider: omniauth['provider'],
        uid: omniauth['uid']
      ).first
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
restpack_user_service-0.0.4 lib/restpack_user_service/models/authentication.rb
restpack_user_service-0.0.3 lib/restpack_user_service/models/authentication.rb
restpack_user_service-0.0.2 lib/restpack_user_service/models/authentication.rb