Class: Fera::App
- Inherits:
-
Object
- Object
- Fera::App
- Defined in:
- lib/fera/app.rb
Instance Method Summary collapse
- #decode_jwt(jwt) ⇒ Object
- #encode_jwt(payload) ⇒ Object
-
#initialize(client_id, client_secret, options = {}) ⇒ App
constructor
A new instance of App.
- #revoke_token!(auth_token) ⇒ Object
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, = {}) @client_id = client_id @client_secret = client_secret @options = @app_url = [:app_url] || 'https://app.fera.ai' @api_url = [: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 |