enviso 0.1.5 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 868fa4f07cd6d42b1a22917a7e45982f0e569c31ef96f497e6239a9982270429
4
- data.tar.gz: 14ce3150ee9ce8b0d0c5b6fa7d500bb2e5e1e5b33d81a9920de7270c0ae1fe59
3
+ metadata.gz: 1d618e4e3a0373f44ce7ecbcd8a87fbb8509d35c995ae700f4fff130385807ff
4
+ data.tar.gz: 32fe913b71cbd584100f07148899f2c5c61b5d72c528ff21a76efd6b843784ce
5
5
  SHA512:
6
- metadata.gz: ba681cca43b4abab40b191118e9b105d0517c83bd843255f525cd18b9b37c5be05ebc41f0762c5ede5680ed2c3eeb9002edde46bdc13ac46130d770b687296bb
7
- data.tar.gz: 491c5d20966bbcf2fda9b90905dbb98e1073bc609f345e6dc8b7636255c81b12925f61fcfa4553166872dda258c48da2ea010be6027f0d09dbc9e2c5cac60720
6
+ metadata.gz: d09dd98ef9da9931bfc19efc4ada6475a2582e6cfac1c9effffec77e67837f3516cf094f801425ae7bf5ef92f64df86e8780f16c4b67ca9896b1f2c0349203bb
7
+ data.tar.gz: 0f67c3bf869a9ec5ad29a535801c643ba1c2a6282a5476981d3cfb16e257ed2e8fc51deaa87e5c3a8ba2273111b57444e3e9401ba3df7fb0ac6a3455cabf8c66
@@ -1,7 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- enviso (0.1.2)
4
+ enviso (0.1.5)
5
+ jwt
5
6
  openssl
6
7
  rest-client
7
8
 
@@ -14,6 +15,7 @@ GEM
14
15
  http-accept (1.7.0)
15
16
  http-cookie (1.0.3)
16
17
  domain_name (~> 0.5)
18
+ jwt (2.2.1)
17
19
  mime-types (3.3)
18
20
  mime-types-data (~> 3.2015)
19
21
  mime-types-data (3.2019.1009)
@@ -36,6 +36,7 @@ Gem::Specification.new do |spec|
36
36
  spec.require_paths = ["lib"]
37
37
 
38
38
  spec.add_dependency "rest-client"
39
+ spec.add_dependency "jwt"
39
40
  # spec.add_dependency "digest"
40
41
  spec.add_dependency "openssl"
41
42
 
@@ -13,10 +13,9 @@ module Enviso::API
13
13
  url = "#{Enviso::Config.api_link}v#{Enviso::Config.api_version}/#{endpoint}"
14
14
  begin
15
15
 
16
- if token.nil?
17
- unless endpoint.include?("apis")
18
- Enviso::Authentication.get_new_token
19
- end
16
+ # Get a new API token is the current one has expired.
17
+ unless Enviso::Authentication.has_valid_api_key || endpoint.include?("apis")
18
+ Enviso::Authentication.get_new_token
20
19
  end
21
20
 
22
21
  if Enviso::Config.verbose
@@ -2,6 +2,7 @@ module Enviso::Authentication
2
2
  require 'digest'
3
3
  require 'base64'
4
4
  require 'openssl'
5
+ require 'jwt'
5
6
 
6
7
  # The communication layer implements all the methods available in the Enviso API
7
8
  class << self
@@ -88,6 +89,18 @@ module Enviso::Authentication
88
89
  end
89
90
  end
90
91
 
92
+ # Parses the current API key and checks if the 'exp' attribute
93
+ # represents a date in the future.
94
+ def has_valid_api_key
95
+ return self.auth_token != nil && api_key_valid_until > Time.now
96
+ end
97
+
98
+ def api_key_valid_until
99
+ decoded_token = JWT.decode self.auth_token, nil, false
100
+ Time.at(decoded_token.first["exp"])
101
+ end
102
+
91
103
  end
104
+
92
105
  init!
93
106
  end
@@ -1,3 +1,3 @@
1
1
  module Enviso
2
- VERSION = "0.1.5"
2
+ VERSION = "0.1.7"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: enviso
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henk Meijer
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-12-11 00:00:00.000000000 Z
11
+ date: 2019-12-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: jwt
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: openssl
29
43
  requirement: !ruby/object:Gem::Requirement