rail-locator-api 1.0.27 → 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: 95859025aced9cb868cdc35eebeb6d871e82c465e70d85636528f6b061af48ba
4
- data.tar.gz: '0961aab8bb120e0c09345d421d883161050a3e84bc0cda4d69ad86c9aa232745'
3
+ metadata.gz: 2d749526a2d09bb688c6de24159ca68aa6d0545f47577a7f390a53e85c979ad2
4
+ data.tar.gz: 9de1cdedec614f65f4182b140fde5bcc2c73c79113af0406b8bbdb7ee828ceee
5
5
  SHA512:
6
- metadata.gz: d97cedfa807962dcdc104d6b1a95582245281646118533693e87c517e6bc596b36760683e7d93ce4b6c5011ea8148629b49e2ed849db1d079136908decff6940
7
- data.tar.gz: e38ffc250727630f4ce67253c259d23a315b90283eb42eefcfa4821d2970b7db28c1345115d1d88212309027a2e205c1209e64286d7c93c0eb3c2424f69f883b
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|
@@ -1,3 +1,3 @@
1
1
  module RailLocatorApi
2
- VERSION = "1.0.27"
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.27
4
+ version: 1.0.28
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pavel Osetrov