sblogistica 0.0.8 → 0.0.10
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: d18546901c758dce0fc595b7d1ce59febf00d9aeaa86bc4084c9a1767fe2e1f3
|
4
|
+
data.tar.gz: 2683cb32179168de613e0ef342c1a0745d9e7f49beb0aeb5fa56ae9b3a0a1ab4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6a763649c45434762b1f8264529dd8360bb183c5cd5060333aba0f0775eeced2585d658737d3cfbe6ef2d3571cda9d52d0b737491a8049ee05674ecc5243094c
|
7
|
+
data.tar.gz: 81ae9ff0a809267981ea47cb0b1ad1ee15f7c6fe2c2b78b79aa745691832e91fea2ea468fe2b8e0fcff740b3bf337c6e5a84bbb3458a05dfe7572de0d96678ba
|
@@ -140,7 +140,17 @@ module Sblogistica
|
|
140
140
|
def configure_request(request: nil, params: nil, headers: nil, body: nil)
|
141
141
|
if request
|
142
142
|
request.params.merge!(params) if params
|
143
|
-
|
143
|
+
case @request_builder.path_parts.try(:first)
|
144
|
+
when "ext"
|
145
|
+
request.headers['X-Api-Key'] = Sblogistica::Request.api_key
|
146
|
+
when "sbl-tariff"
|
147
|
+
request.headers['authorization'] = "Bearer #{Sblogistica::generate_access_token}"
|
148
|
+
when "admin", "internal"
|
149
|
+
request.headers['authorization'] = "Bearer #{Sblogistica::generate_access_token(system: "ADMIN_PANEL")}"
|
150
|
+
when "api"
|
151
|
+
request.headers['authorization'] = "Bearer #{Sblogistica::generate_access_token(system: "LK")}"
|
152
|
+
end
|
153
|
+
|
144
154
|
request.headers['Content-Type'] = 'application/json'
|
145
155
|
request.headers['User-Agent'] = "Sblogistica/#{Sblogistica::VERSION} Ruby gem"
|
146
156
|
request.headers.merge!(headers) if headers
|
data/lib/sblogistica/request.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
module Sblogistica
|
2
2
|
class Request
|
3
|
-
attr_accessor :api_key, :api_endpoint, :timeout, :open_timeout, :proxy, :ssl_options, :faraday_adapter,
|
3
|
+
attr_accessor :api_key, :api_endpoint, :timeout, :open_timeout, :proxy, :ssl_options, :faraday_adapter,
|
4
|
+
:symbolize_keys, :debug, :logger, :test, :path_parts
|
4
5
|
|
5
6
|
DEFAULT_TIMEOUT = 60
|
6
7
|
DEFAULT_OPEN_TIMEOUT = 60
|
data/lib/sblogistica/version.rb
CHANGED
data/lib/sblogistica.rb
CHANGED
@@ -9,9 +9,10 @@ require 'sblogistica/response'
|
|
9
9
|
module Sblogistica
|
10
10
|
class << self
|
11
11
|
|
12
|
-
def generate_access_token
|
12
|
+
def generate_access_token(system: 'LDAP')
|
13
13
|
client = Faraday.new(Sblogistica.api_token_url, proxy: Sblogistica::Request.proxy,
|
14
14
|
ssl: Sblogistica::Request.ssl_options) do |faraday|
|
15
|
+
faraday.basic_auth(Sblogistica.api_client_id, Sblogistica.api_client_secret)
|
15
16
|
faraday.response :raise_error
|
16
17
|
faraday.adapter Faraday.default_adapter
|
17
18
|
if Sblogistica::Request.debug
|
@@ -19,11 +20,12 @@ module Sblogistica
|
|
19
20
|
end
|
20
21
|
end
|
21
22
|
response = client.post do |request|
|
23
|
+
request.params.merge!({system: system})
|
22
24
|
request.headers['Content-Type'] = 'application/x-www-form-urlencoded'
|
23
25
|
request.headers['User-Agent'] = "Sblogistica/#{Sblogistica::VERSION} Ruby gem"
|
24
|
-
request.body = "grant_type
|
26
|
+
request.body = "grant_type=password&username=#{Sblogistica.api_username}&password=#{Sblogistica.api_password}"
|
25
27
|
end
|
26
|
-
JSON.parse(response.body)
|
28
|
+
JSON.parse(response.body).try(:dig, "access_token")
|
27
29
|
end
|
28
30
|
|
29
31
|
def setup
|