rail-locator-api 1.0.26 → 1.0.28

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: 119ca579b29cc950cd89a82d0a0234b309b0ef48e93f979c058798b270881ebf
4
- data.tar.gz: d0c54d0d2d476cbf1163d256a80fc6381ecdcc7f738acc32995a976c4215876a
3
+ metadata.gz: 2d749526a2d09bb688c6de24159ca68aa6d0545f47577a7f390a53e85c979ad2
4
+ data.tar.gz: 9de1cdedec614f65f4182b140fde5bcc2c73c79113af0406b8bbdb7ee828ceee
5
5
  SHA512:
6
- metadata.gz: 2da38a334259b719763e03408a72a5f6df491ff3bd9742e81a993583225295d41a7de1d969a9263c0996a67a9208b6dab99552d7a9a612b5a544514e8cd01f73
7
- data.tar.gz: d7e52a45bcffaeebb0c6a65f4f8f6c897ce4158c4157e266ba9ae7eb7c94e7258438e22fc090e663aa398c1d575b817964fd8dc5fba4bacee770f8b4da039f8a
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
@@ -1,3 +1,3 @@
1
1
  module RailLocatorApi
2
- VERSION = "1.0.26"
2
+ VERSION = "1.0.28"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rail-locator-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.26
4
+ version: 1.0.28
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pavel Osetrov