Class: Fera::App

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

Instance Method Summary collapse

Constructor Details

#initialize(client_id, client_secret, options = {}) ⇒ App

Returns a new instance of App.



3
4
5
6
7
8
9
10
# File 'lib/fera/app.rb', line 3

def initialize(client_id, client_secret, options = {})
  @client_id = client_id
  @client_secret = client_secret
  @options = options

  @app_url = options[:app_url] || 'https://app.fera.ai'
  @api_url = options[:api_url] || 'https://api.fera.ai'
end

Instance Method Details

#decode_jwt(jwt) ⇒ Object



26
27
28
29
30
# File 'lib/fera/app.rb', line 26

def decode_jwt(jwt)
  JWT.decode(jwt, @client_secret, true).try(:first).to_h.with_indifferent_access
rescue StandardError
  nil
end

#encode_jwt(payload) ⇒ Object



32
33
34
# File 'lib/fera/app.rb', line 32

def encode_jwt(payload)
  JWT.encode(payload, @client_secret)
end

#revoke_token!(auth_token) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/fera/app.rb', line 12

def revoke_token!(auth_token)
  previous_site = Base.site

  Base.site = @app_url

  body = { client_id: @client_id, client_secret: @client_secret, token: auth_token }

  result = Base.connection.post("#{ @app_url }/oauth/revoke", body.to_json)

  Base.site = previous_site

  result
end