Module: Songkick::OAuth2::Model

Defined in:
lib/songkick/oauth2/model.rb,
lib/songkick/oauth2/model/client.rb,
lib/songkick/oauth2/model/hashing.rb,
lib/songkick/oauth2/model/helpers.rb,
lib/songkick/oauth2/model/client_owner.rb,
lib/songkick/oauth2/model/authorization.rb,
lib/songkick/oauth2/model/resource_owner.rb

Defined Under Namespace

Modules: ClientOwner, Hashing, Helpers, ResourceOwner Classes: Authorization, Client

Constant Summary collapse

Schema =
Songkick::OAuth2::Schema
DUPLICATE_RECORD_ERRORS =
[
  /^Mysql::Error:\s+Duplicate\s+entry\b/,
  /^PG::Error:\s+ERROR:\s+duplicate\s+key\b/,
  /\bConstraintException\b/
]

Class Method Summary collapse

Class Method Details

.duplicate_record_error?(error) ⇒ Boolean

ActiveRecord::RecordNotUnique was introduced in Rails 3.0 so referring to it while running earlier versions will raise an error. The above error strings should match PostgreSQL, MySQL and SQLite errors on Rails 2. If you’re running a different adapter, add a suitable regex to the list:

Songkick::OAuth2::Model::DUPLICATE_RECORD_ERRORS << /DB2 found a dup/

Returns:

  • (Boolean)


29
30
31
32
# File 'lib/songkick/oauth2/model.rb', line 29

def self.duplicate_record_error?(error)
  error.class.name == 'ActiveRecord::RecordNotUnique' or
  DUPLICATE_RECORD_ERRORS.any? { |re| re =~ error.message }
end

.find_access_token(access_token) ⇒ Object



34
35
36
37
# File 'lib/songkick/oauth2/model.rb', line 34

def self.find_access_token(access_token)
  return nil if access_token.nil?
  Authorization.find_by_access_token_hash(Songkick::OAuth2.hashify(access_token))
end