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: babfe587c20865aeae89c7c943ebd2d208e68f429cbf9c7569e5e2871861fb4e
4
- data.tar.gz: b83d16401ca1e9c6b33960140ccf2615bdfaf35d488a4d5126abb770d4dbca1a
3
+ metadata.gz: d18546901c758dce0fc595b7d1ce59febf00d9aeaa86bc4084c9a1767fe2e1f3
4
+ data.tar.gz: 2683cb32179168de613e0ef342c1a0745d9e7f49beb0aeb5fa56ae9b3a0a1ab4
5
5
  SHA512:
6
- metadata.gz: 94d9326f0692e05f0be5b397fc90601a163d316a74f9747d4f969f7785105bd0d1473356e05fbe9ca3138e32842a31d733c13d41664092a5959518f8e418cf6c
7
- data.tar.gz: 9a25f2432b0f3f21af73cea537e9efb876994e9c4bc5460417ae6230c87361fca5a945cd40d971293d5e6a24f10efb22ec41ba8300bd185e9bbaf35d6bddc4b1
6
+ metadata.gz: 6a763649c45434762b1f8264529dd8360bb183c5cd5060333aba0f0775eeced2585d658737d3cfbe6ef2d3571cda9d52d0b737491a8049ee05674ecc5243094c
7
+ data.tar.gz: 81ae9ff0a809267981ea47cb0b1ad1ee15f7c6fe2c2b78b79aa745691832e91fea2ea468fe2b8e0fcff740b3bf337c6e5a84bbb3458a05dfe7572de0d96678ba
@@ -1,6 +1,6 @@
1
1
  defaults: &defaults
2
2
  HOST: 'https://lk.sblogistica.ru'
3
- API_TOKEN_URL: 'https://lk.sblogistica.ru/auth/oauth/token?system=LDAP'
3
+ API_TOKEN_URL: 'https://lk.sblogistica.ru/auth/oauth/token'
4
4
  API_GRANT_TYPE: 'request-body'
5
5
  API_KEY: '***'
6
6
  API_USERNAME: '***'
@@ -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
- request.headers['X-Api-Key'] = Sblogistica::Request.api_key
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
@@ -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, :symbolize_keys, :debug, :logger, :test
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
@@ -1,3 +1,3 @@
1
1
  module Sblogistica
2
- VERSION = "0.0.8"
2
+ VERSION = "0.0.10"
3
3
  end
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=#{Sblogistica.api_grant_type}&client_id=#{Sblogistica.api_client_id}&client_secret=#{Sblogistica.api_client_secret}&username=#{Sblogistica.api_username}&password=#{Sblogistica.api_password}"
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sblogistica
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pavel Osetrov