Class: Etna::Clients::BaseClient
- Inherits:
-
Object
- Object
- Etna::Clients::BaseClient
- Defined in:
- lib/etna/clients/base_client.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#ignore_ssl ⇒ Object
readonly
Returns the value of attribute ignore_ssl.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
Instance Method Summary collapse
-
#initialize(host:, token:, ignore_ssl: false, logger: nil) ⇒ BaseClient
constructor
A new instance of BaseClient.
- #token_expired? ⇒ Boolean
- #token_will_expire?(offset = 3000) ⇒ Boolean
Constructor Details
#initialize(host:, token:, ignore_ssl: false, logger: nil) ⇒ BaseClient
Returns a new instance of BaseClient.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/etna/clients/base_client.rb', line 9 def initialize(host:, token:, ignore_ssl: false, logger: nil) raise "#{self.class.name} client configuration is missing host." unless host @token = token raise "Your token is expired." if token && token_expired? @etna_client = ::Etna::Client.new( host, token, routes_available: false, ignore_ssl: ignore_ssl, logger: logger) @host = host @ignore_ssl = ignore_ssl end |
Instance Attribute Details
#host ⇒ Object (readonly)
Returns the value of attribute host.
8 9 10 |
# File 'lib/etna/clients/base_client.rb', line 8 def host @host end |
#ignore_ssl ⇒ Object (readonly)
Returns the value of attribute ignore_ssl.
8 9 10 |
# File 'lib/etna/clients/base_client.rb', line 8 def ignore_ssl @ignore_ssl end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
8 9 10 |
# File 'lib/etna/clients/base_client.rb', line 8 def token @token end |
Instance Method Details
#token_expired? ⇒ Boolean
25 26 27 28 |
# File 'lib/etna/clients/base_client.rb', line 25 def token_expired? # Has the token already expired? token_will_expire?(0) end |
#token_will_expire?(offset = 3000) ⇒ Boolean
30 31 32 33 34 35 36 37 |
# File 'lib/etna/clients/base_client.rb', line 30 def token_will_expire?(offset=3000) # offset in seconds # Will the user's token expire in the given amount of time? payload = JSON.parse(Base64.urlsafe_decode64(token.split('.')[1])) epoch_seconds = payload["exp"] expiration = DateTime.strptime(epoch_seconds.to_s, "%s") expiration <= DateTime.now.new_offset + offset end |