Module: Peel

Defined in:
lib/peel.rb,
lib/peel/api.rb,
lib/peel/version.rb,
lib/peel/api_include.rb

Defined Under Namespace

Modules: ApiInclude Classes: API

Constant Summary collapse

VERSION =
"0.0.1"

Class Method Summary collapse

Class Method Details

.authenticate_with_token(token) ⇒ Object


5
6
7
8
9
10
11
12
# File 'lib/peel.rb', line 5

def self.authenticate_with_token(token)
  begin
    payload = decode_payload(token)
  rescue
    return false
  end
  find_user_by_email(payload['email'])
end

.decode_payload(jwt_token) ⇒ Object


23
24
25
26
# File 'lib/peel.rb', line 23

def self.decode_payload(jwt_token)
  secret = ENV['PEEL_SECRET']
  JWT.decode(jwt_token, secret)[0]
end

.encode_payload(payload) ⇒ Object


18
19
20
21
# File 'lib/peel.rb', line 18

def self.encode_payload(payload)
  validate_secret_presence
  JWT.encode(payload, ENV['PEEL_SECRET'])
end

.find_user_by_email(email) ⇒ Object


14
15
16
# File 'lib/peel.rb', line 14

def self.find_user_by_email(email)
  User.find_by_email(email)
end

.validate_secret_presenceObject


28
29
30
# File 'lib/peel.rb', line 28

def self.validate_secret_presence
  fail 'You must set ENV["PEEL_SECRET"]' unless ENV['PEEL_SECRET']
end