rail-locator-api 0.0.24 → 0.0.27
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rail-locator-api/api_request.rb +6 -2
- data/lib/rail-locator-api/request.rb +10 -8
- data/lib/rail-locator-api/version.rb +1 -1
- data/lib/rail-locator-api.rb +15 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5fa9621f90e61d080230517327f571b5946b528dd17e4f0cf69478aa0a62aade
|
4
|
+
data.tar.gz: d7ad5a17ab908af7e6d4554d5d542edfdaed0cf38ebb3a38d3f29ddfbe002117
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e50ff5cc52c6f1327b5270a2abd3c8a6aec6baf122804e1e58ce6709de059be470ae2037030e3e3b52f6afcc99719865a51f837de47963469bfb58ad73384591
|
7
|
+
data.tar.gz: 4bba788b46c1acbfbf57b922be11f57fbedb8352dd438c088b951fc824b60ca54853cebc7f2a227f83d9109454a53d566b864ef134c3c25feaf17daae083d9a3
|
@@ -5,7 +5,7 @@ module RailLocatorApi
|
|
5
5
|
@request_builder = builder
|
6
6
|
end
|
7
7
|
|
8
|
-
def post(params: nil, headers: nil, suffix: nil, body: {}
|
8
|
+
def post(params: nil, headers: nil, suffix: nil, body: {})
|
9
9
|
validate_api_key
|
10
10
|
begin
|
11
11
|
response = self.rest_client(suffix).post do |request|
|
@@ -17,7 +17,7 @@ module RailLocatorApi
|
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
-
def get(params: nil, headers: nil, body: {}
|
20
|
+
def get(params: nil, headers: nil, body: {})
|
21
21
|
validate_api_key
|
22
22
|
|
23
23
|
begin
|
@@ -38,6 +38,10 @@ module RailLocatorApi
|
|
38
38
|
@request_builder.access_token
|
39
39
|
end
|
40
40
|
|
41
|
+
def refresh_token
|
42
|
+
@request_builder.refresh_token
|
43
|
+
end
|
44
|
+
|
41
45
|
def api_key
|
42
46
|
@request_builder.api_key
|
43
47
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module RailLocatorApi
|
2
2
|
class Request
|
3
|
-
attr_accessor :access_token, :api_key, :api_user_email, :api_user_password, :api_auth_method, :api_endpoint,
|
3
|
+
attr_accessor :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, :logger, :test
|
5
5
|
|
6
6
|
AUTH_METHODS = [:keycloak, :api_key, :base64]
|
@@ -8,7 +8,7 @@ module RailLocatorApi
|
|
8
8
|
DEFAULT_TIMEOUT = 60
|
9
9
|
DEFAULT_OPEN_TIMEOUT = 60
|
10
10
|
|
11
|
-
def initialize(access_token: nil, api_key: nil, api_user_email: nil, api_user_password: nil,
|
11
|
+
def initialize(access_token: nil, refresh_token: nil, api_key: nil, api_user_email: nil, api_user_password: nil,
|
12
12
|
api_endpoint: nil, api_auth_method: nil, timeout: nil, open_timeout: nil, proxy: nil, ssl_options: nil,
|
13
13
|
faraday_adapter: nil, symbolize_keys: false, debug: false, logger: nil, test: false)
|
14
14
|
|
@@ -19,10 +19,12 @@ module RailLocatorApi
|
|
19
19
|
|
20
20
|
@access_token = access_token || self.class.access_token || RailLocatorApi.generate_access_token.try(:dig, "access_token")
|
21
21
|
@access_token = @access_token.strip if @access_token
|
22
|
-
@access_token = RailLocatorApi::generate_access_token if @access_token.nil?
|
22
|
+
@access_token = RailLocatorApi::generate_access_token.try(:dig, "access_token") if @access_token.nil?
|
23
|
+
@refresh_token = refresh_token || self.class.refresh_token
|
24
|
+
@refresh_token = @refresh_token.strip if @refresh_token
|
23
25
|
|
24
|
-
@api_user_email = api_user_email ||
|
25
|
-
@api_user_password = api_user_password ||
|
26
|
+
@api_user_email = api_user_email || ENV['API_USER_EMAIL'] || ""
|
27
|
+
@api_user_password = api_user_password || ENV['API_USER_PASSWORD'] || ""
|
26
28
|
@api_endpoint = api_endpoint || self.class.api_endpoint
|
27
29
|
@api_endpoint = RailLocatorApi::api_endpoint if @api_endpoint.nil?
|
28
30
|
@api_auth_method = api_auth_method || DEFAULT_AUTH_METHOD
|
@@ -91,12 +93,12 @@ module RailLocatorApi
|
|
91
93
|
end
|
92
94
|
|
93
95
|
class << self
|
94
|
-
attr_accessor :access_token, :api_key, :api_user_email, :api_user_password, :api_auth_method, :timeout, :open_timeout,
|
96
|
+
attr_accessor :access_token, :refresh_token, :api_key, :api_user_email, :api_user_password, :api_auth_method, :timeout, :open_timeout,
|
95
97
|
:api_endpoint, :proxy, :ssl_options, :faraday_adapter, :symbolize_keys, :debug, :logger, :test
|
96
98
|
|
97
99
|
def method_missing(sym, *args, &block)
|
98
|
-
new(access_token: self.access_token,
|
99
|
-
api_user_password: self.api_user_email,
|
100
|
+
new(access_token: self.access_token, refresh_token: self.refresh_token, api_key: self.api_key,
|
101
|
+
api_user_email: self.api_user_email, api_user_password: self.api_user_email,
|
100
102
|
api_auth_method: self.api_auth_method, api_endpoint: self.api_endpoint,
|
101
103
|
timeout: self.timeout, open_timeout: self.open_timeout, faraday_adapter: self.faraday_adapter,
|
102
104
|
symbolize_keys: self.symbolize_keys, debug: self.debug, proxy: self.proxy, ssl_options: self.ssl_options, logger: self.logger,
|
data/lib/rail-locator-api.rb
CHANGED
@@ -14,7 +14,21 @@ module RailLocatorApi
|
|
14
14
|
else
|
15
15
|
payload = "grant_type=#{RailLocatorApi.keycloak_grant_type}&client_id=#{RailLocatorApi.keycloak_client_id}&code=#{RailLocatorApi::Request.api_key}&redirect_uri=#{RailLocatorApi.keycloak_redirect_uri}"
|
16
16
|
end
|
17
|
+
connection = Faraday.new(RailLocatorApi.keycloak_token_url, proxy: nil,
|
18
|
+
ssl: { version: "TLSv1_2" }) do |faraday|
|
19
|
+
faraday.adapter Faraday.default_adapter
|
20
|
+
faraday.response :logger, ::Logger.new(STDOUT), bodies: true
|
21
|
+
end
|
22
|
+
|
23
|
+
response = connection.post RailLocatorApi.keycloak_token_url, payload do |request|
|
24
|
+
request.headers['accept'] = 'application/json'
|
25
|
+
end
|
26
|
+
|
27
|
+
JSON.parse(response.body)
|
28
|
+
end
|
17
29
|
|
30
|
+
def refresh_access_token
|
31
|
+
payload = "grant_type=refresh_token&client_id=#{RailLocatorApi.keycloak_client_id}&refresh_token=#{RailLocatorApi::Request.access_token}&redirect_uri=#{RailLocatorApi.keycloak_redirect_uri}"
|
18
32
|
connection = Faraday.new(RailLocatorApi.keycloak_token_url, proxy: nil,
|
19
33
|
ssl: { version: "TLSv1_2" }) do |faraday|
|
20
34
|
faraday.adapter Faraday.default_adapter
|
@@ -25,7 +39,7 @@ module RailLocatorApi
|
|
25
39
|
request.headers['accept'] = 'application/json'
|
26
40
|
end
|
27
41
|
|
28
|
-
JSON.parse(response.body)
|
42
|
+
JSON.parse(response.body)
|
29
43
|
end
|
30
44
|
|
31
45
|
def setup
|