Class: Crocker::Validator

Inherits:
Object
  • Object
show all
Defined in:
lib/crocker.rb

Class Method Summary collapse

Class Method Details

.id_and_password_present?(params) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/crocker.rb', line 21

def self.id_and_password_present?(params)
  params[:user_id] && params[:user_password]
end

.validate(params) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/crocker.rb', line 9

def self.validate(params)
  return unless id_and_password_present?(params)
  uri       = URI.parse(params.delete(:api_url)||API_URL) rescue ''
  signature = Digest::MD5.hexdigest([params.delete(:user_password), params.delete(:secret)||API_SECRET].join) rescue ''
  uri.query = URI.encode_www_form({
                                    :userid    => params.delete(:user_id),
                                    :signature => signature
                                  }) rescue nil
  response = JSON.parse(Net::HTTP.get_response(uri).body.downcase) rescue {}
  response['success'] == true ? response['token'].downcase : nil      
end