rail-locator-api 0.1.16 → 0.1.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9f669bd03427eda818b445e6639fa78c663defa18a11a491144dace854ab8906
|
4
|
+
data.tar.gz: a3eaabab8cff46cbb00334454833e2bc1b53c58e8f3668b3402cd98eea868e00
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ce8f47cbc300948b32217bcc745340f952cecde7790e0c4cbd4cf0bc78aa7fcc289bc29a0988588509fbbd7b25ad0f32ac46092e4cd0a00faffa43c25ffc2abc
|
7
|
+
data.tar.gz: 1c15323aee4561cd964048188cdc1bc402275d2f6e1cd81590a1499a165b1a97358f1ea51dbc1963181d3d059877a1391ef92206e55f8c6637f81f178fc48af3
|
@@ -13,6 +13,8 @@ RailLocatorApi.setup do |config|
|
|
13
13
|
config::Request.api_user_email ||= ENV['API_USER_EMAIL']
|
14
14
|
config::Request.api_user_password ||= ENV['API_USER_PASSWORD']
|
15
15
|
|
16
|
+
config::Request.jwt_secret_code ||= ENV['JWT_SECRET_CODE']
|
17
|
+
|
16
18
|
config::Request.timeout = 60
|
17
19
|
config::Request.open_timeout = 60
|
18
20
|
config::Request.symbolize_keys = true
|
@@ -33,6 +33,9 @@ module RailLocatorApi
|
|
33
33
|
protected
|
34
34
|
|
35
35
|
# Convenience accessors
|
36
|
+
def jwt_secret_code
|
37
|
+
@request_builder.jwt_secret_code
|
38
|
+
end
|
36
39
|
|
37
40
|
def access_token
|
38
41
|
@request_builder.access_token
|
@@ -128,7 +131,6 @@ module RailLocatorApi
|
|
128
131
|
RailLocatorApi::Request.refresh_token = response.try(:dig, "refresh_token")
|
129
132
|
end
|
130
133
|
end
|
131
|
-
|
132
134
|
if self.api_auth_method == :base64
|
133
135
|
request.headers['Authorization'] = "Basic " + Base64::encode64("#{self.api_user_email}:#{self.api_user_password}")
|
134
136
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module RailLocatorApi
|
2
2
|
class Request
|
3
|
-
attr_accessor :access_token, :refresh_token, :api_key, :api_user_email, :api_user_password, :api_auth_method, :api_endpoint,
|
3
|
+
attr_accessor :jwt_secret_code, :access_token, :refresh_token, :api_key, :api_user_email, :api_user_password, :api_auth_method, :api_endpoint,
|
4
4
|
:timeout, :open_timeout, :proxy, :ssl_options, :faraday_adapter, :symbolize_keys, :debug,
|
5
5
|
:without_ratelimit, :logger, :test
|
6
6
|
|
@@ -9,7 +9,7 @@ module RailLocatorApi
|
|
9
9
|
DEFAULT_TIMEOUT = 60
|
10
10
|
DEFAULT_OPEN_TIMEOUT = 60
|
11
11
|
|
12
|
-
def initialize(access_token: nil, refresh_token: nil, api_key: nil, api_user_email: nil, api_user_password: nil,
|
12
|
+
def initialize(jwt_secret_code: nil, access_token: nil, refresh_token: nil, api_key: nil, api_user_email: nil, api_user_password: nil,
|
13
13
|
api_endpoint: nil, api_auth_method: nil, timeout: nil, open_timeout: nil, proxy: nil, ssl_options: nil,
|
14
14
|
faraday_adapter: nil, symbolize_keys: false, debug: false, without_ratelimit: false,
|
15
15
|
logger: nil, test: false)
|
@@ -22,6 +22,10 @@ module RailLocatorApi
|
|
22
22
|
@access_token = @access_token.strip if @access_token
|
23
23
|
@refresh_token = refresh_token || self.class.refresh_token
|
24
24
|
@refresh_token = @refresh_token.strip if @refresh_token
|
25
|
+
|
26
|
+
@jwt_secret_code = jwt_secret_code || self.class.jwt_secret_code
|
27
|
+
@jwt_secret_code = @jwt_secret_code.strip if @jwt_secret_code
|
28
|
+
|
25
29
|
@api_user_email = api_user_email || ENV['API_USER_EMAIL'] || ""
|
26
30
|
@api_user_password = api_user_password || ENV['API_USER_PASSWORD'] || ""
|
27
31
|
@api_endpoint = api_endpoint || self.class.api_endpoint
|
@@ -86,10 +90,10 @@ module RailLocatorApi
|
|
86
90
|
reset
|
87
91
|
end
|
88
92
|
|
89
|
-
def token_alive?(token)
|
93
|
+
def token_alive?(token, jwt_secret_code=@jwt_secret_code)
|
90
94
|
begin
|
91
95
|
return false if token.nil?
|
92
|
-
exp = JWT.decode(token,
|
96
|
+
exp = JWT.decode(token, jwt_secret_code, false).try(:first).try(:dig, "exp")
|
93
97
|
return false if exp.nil?
|
94
98
|
Time.at(exp) > Time.now + 30.second
|
95
99
|
rescue => e
|
@@ -105,12 +109,13 @@ module RailLocatorApi
|
|
105
109
|
end
|
106
110
|
|
107
111
|
class << self
|
108
|
-
attr_accessor :access_token, :refresh_token, :api_key, :api_user_email, :api_user_password, :api_auth_method,
|
112
|
+
attr_accessor :jwt_secret_code, :access_token, :refresh_token, :api_key, :api_user_email, :api_user_password, :api_auth_method,
|
109
113
|
:timeout, :open_timeout, :api_endpoint, :proxy, :ssl_options, :faraday_adapter, :symbolize_keys,
|
110
114
|
:debug, :without_ratelimit, :logger, :test
|
111
115
|
|
112
116
|
def method_missing(sym, *args, &block)
|
113
|
-
new(
|
117
|
+
new(jwt_secret_code: self.jwt_secret_code, access_token: self.access_token, refresh_token: self.refresh_token,
|
118
|
+
api_key: self.api_key,
|
114
119
|
api_user_email: self.api_user_email, api_user_password: self.api_user_email,
|
115
120
|
api_auth_method: self.api_auth_method, api_endpoint: self.api_endpoint,
|
116
121
|
timeout: self.timeout, open_timeout: self.open_timeout, faraday_adapter: self.faraday_adapter,
|