rail-locator-api 1.0.26 → 1.0.28
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: 2d749526a2d09bb688c6de24159ca68aa6d0545f47577a7f390a53e85c979ad2
|
4
|
+
data.tar.gz: 9de1cdedec614f65f4182b140fde5bcc2c73c79113af0406b8bbdb7ee828ceee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eb986e91e3cb09f20d9675886a2ee81b1191e8cd883ed1c9e3311c0e8f97469f58e4a527c3b85cb9729b602ea156dca712252fe4d4ddb4862c1c43d4f4b196a5
|
7
|
+
data.tar.gz: 774accf2563eb53a36008a2b1aa0ad946ebae505928f67ce35f22e41954042becac3eb3729a47a481d87e5e77886d8be88505bfc68b47dec9bc1e316f3e651b1
|
@@ -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,45 @@ 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)
|
46
|
+
request['foo'] = bar
|
15
47
|
request.set_form body.to_params, 'multipart/form-data'
|
48
|
+
if @request_builder.debug
|
49
|
+
p request
|
50
|
+
end
|
16
51
|
http.request(request)
|
17
52
|
else
|
18
53
|
response = self.rest_client(format).post do |request|
|
@@ -363,7 +398,12 @@ end
|
|
363
398
|
class Object
|
364
399
|
def to_params(key)
|
365
400
|
if self.is_a? ActionDispatch::Http::UploadedFile
|
366
|
-
[key.to_param, File.open(self.path)
|
401
|
+
[key.to_param, File.open(self.path),
|
402
|
+
{
|
403
|
+
:filename => self.original_filename,
|
404
|
+
:content_type => self.content_type
|
405
|
+
}
|
406
|
+
]
|
367
407
|
elsif %w[File Tempfile StringIO].include?(self.class.name)
|
368
408
|
self
|
369
409
|
else
|