rail-locator-api 1.0.27 → 1.0.29
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fd0edd76666a0e2c989d8a946760cfb7f25e033fb465ab098a16de9954ee29ba
|
4
|
+
data.tar.gz: 4b76a953264943d3a1984d5114bbcd25b4fc53c9765f3a9a4d3d9d3015759ec8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '0344942f521b8bdc3fa68223ccea4de9ab64a6d60042687ea6f5d7df37f70e3fb4f1e064c4affc8917104013e73fc0aefc954d578bf249ec63c0e56cba534be2'
|
7
|
+
data.tar.gz: 00c9c402006d0d42ea99ec8d2e7b4af4f165701bf85426a3e3888686e662137be01bf6b1ed69425ad264c521742d0979145881a3ac4bc814a2976b380e5dc9ea
|
@@ -2,7 +2,8 @@ require 'rail-locator-api'
|
|
2
2
|
|
3
3
|
RailLocatorApi.setup do |config|
|
4
4
|
if File.exist?('config/rail_locator_api.yml')
|
5
|
-
processed = YAML.load_file('config/rail_locator_api.yml')[Rails.env]
|
5
|
+
#processed = YAML.load_file('config/rail_locator_api.yml')[Rails.env]
|
6
|
+
processed = YAML.load('config/rail_locator_api.yml', aliases: true)[Rails.env]
|
6
7
|
|
7
8
|
processed.each do |k, v|
|
8
9
|
config::register k.underscore.to_sym, v
|
@@ -9,10 +9,44 @@ module RailLocatorApi
|
|
9
9
|
validate_api_key
|
10
10
|
begin
|
11
11
|
if is_multipart?(body)
|
12
|
+
if self.api_auth_method == :base64
|
13
|
+
headers['Authorization'] = "Basic " + Base64::encode64("#{self.api_user_email}:#{self.api_user_password}")
|
14
|
+
end
|
15
|
+
if [:keycloak].include?(self.api_auth_method)
|
16
|
+
unless RailLocatorApi::Request.token_alive?(RailLocatorApi::Request.access_token)
|
17
|
+
if RailLocatorApi::Request.token_alive?(RailLocatorApi::Request.refresh_token)
|
18
|
+
response = RailLocatorApi.refresh_access_token
|
19
|
+
RailLocatorApi::Request.access_token = response.try(:dig, "access_token")
|
20
|
+
RailLocatorApi::Request.refresh_token = response.try(:dig, "refresh_token")
|
21
|
+
else
|
22
|
+
error_params = { title: "UNAUTHORIZED", status_code: 401 }
|
23
|
+
error = RailLocatorApiError.new("Token is unavailable", error_params)
|
24
|
+
raise error
|
25
|
+
end
|
26
|
+
end
|
27
|
+
headers['Authorization'] = "Bearer #{RailLocatorApi::Request.access_token}"
|
28
|
+
end
|
29
|
+
if [:api_key].include?(self.api_auth_method)
|
30
|
+
request.headers['X-Api-Key'] = "#{RailLocatorApi::Request.api_key}"
|
31
|
+
if self.api_user_id.present?
|
32
|
+
request.headers['X-User-Id'] = self.api_user_id.to_s
|
33
|
+
end
|
34
|
+
end
|
35
|
+
headers['User-Agent'] = "RailLocatorApi/#{RailLocatorApi::VERSION} Ruby gem"
|
36
|
+
headers['Accept-Language'] = RailLocatorApi::Request.language.to_s
|
37
|
+
if @request_builder.without_ratelimit
|
38
|
+
headers['X-Is-Request-Without-RateLimit'] = "true"
|
39
|
+
end
|
40
|
+
if @request_builder.is_allow_access_to_coordinates
|
41
|
+
headers['X-Is-Allow-Access-To-Coordinates'] = "true"
|
42
|
+
end
|
12
43
|
url = URI("#{self.api_url}#{format.present? ? ".#{format}": ""}")
|
13
44
|
http = Net::HTTP.new(url.host, url.port);
|
14
|
-
request = Net::HTTP::Post.new(url)
|
45
|
+
request = Net::HTTP::Post.new(url, headers)
|
15
46
|
request.set_form body.to_params, 'multipart/form-data'
|
47
|
+
if @request_builder.debug
|
48
|
+
p request
|
49
|
+
end
|
16
50
|
http.request(request)
|
17
51
|
else
|
18
52
|
response = self.rest_client(format).post do |request|
|