zaikio-client-helpers 0.2.4 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/lib/zaikio/client/helpers/authorization_middleware.rb +27 -0
- data/lib/zaikio/client/helpers/configuration.rb +38 -0
- data/lib/zaikio/client/helpers/version.rb +1 -1
- data/lib/zaikio/client.rb +31 -0
- data/lib/zaikio-client-helpers.rb +1 -3
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a7c1175b44ca6b5ce9c35a6c24e3c2c546da668af38553303510b6e3ebb549f5
|
4
|
+
data.tar.gz: 57f77bce22039beedee0f51da1ff1655dc3e602de987d3d13ce594337e5f37c0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1eeb54b3661b5aa9d7730fa2751e1632273a63011cf3259f7db5df8228bd9b1208951b692332a54bf449750f1bde6ef8ea23f97d3927c896f96042a628e7d508
|
7
|
+
data.tar.gz: a22972654c7b0a53f5844a7005d3afb08345cfab355d5493ff58c99fb2e28030f54854bc8bdb32aec118723470df0cd58d98ba101feaf1e04ff16f6295eceb3b
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [0.3.0] - 2022-08-15
|
4
|
+
|
5
|
+
- Add `Zaikio::Client::Helpers::AuthorizationMiddleware` and `Zaikio::Client.with_token` to pass down bearer token to multiple clients (e.g. hub + procurement) at the same time
|
6
|
+
- Add `Zaikio::Client::Helpers::Configuration` as an abstract configuration class
|
7
|
+
- Add `Zaikio::Client.create_connection`
|
8
|
+
|
3
9
|
## [0.2.4] - 2022-03-29
|
4
10
|
|
5
11
|
- Add support for Faraday 2.x
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require "faraday"
|
2
|
+
|
3
|
+
module Zaikio
|
4
|
+
module Client
|
5
|
+
module Helpers
|
6
|
+
class AuthorizationMiddleware < Faraday::Middleware
|
7
|
+
def self.token
|
8
|
+
Thread.current[:zaikio_client_access_token]
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.token=(value)
|
12
|
+
Thread.current[:zaikio_client_access_token] = value
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.reset_token
|
16
|
+
Thread.current[:zaikio_client_access_token] = nil
|
17
|
+
end
|
18
|
+
|
19
|
+
def call(request_env)
|
20
|
+
request_env[:request_headers]["Authorization"] = "Bearer #{self.class.token}" if self.class.token
|
21
|
+
|
22
|
+
@app.call(request_env)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require "logger"
|
2
|
+
|
3
|
+
module Zaikio
|
4
|
+
module Client
|
5
|
+
module Helpers
|
6
|
+
class Configuration
|
7
|
+
attr_accessor :host
|
8
|
+
attr_reader :environment
|
9
|
+
attr_writer :logger
|
10
|
+
|
11
|
+
def self.hosts
|
12
|
+
raise NotImplementedError
|
13
|
+
end
|
14
|
+
|
15
|
+
def initialize
|
16
|
+
self.environment = :sandbox
|
17
|
+
end
|
18
|
+
|
19
|
+
def logger
|
20
|
+
@logger ||= Logger.new($stdout)
|
21
|
+
end
|
22
|
+
|
23
|
+
def environment=(env)
|
24
|
+
@environment = env.to_sym
|
25
|
+
@host = host_for(environment)
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def host_for(environment)
|
31
|
+
self.class.hosts.fetch(environment) do
|
32
|
+
raise "Invalid Zaikio::Client environment '#{environment}'"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require "zaikio/client/model"
|
2
|
+
require "zaikio/client/helpers/json_parser"
|
3
|
+
require "zaikio/client/helpers/pagination"
|
4
|
+
require "zaikio/client/helpers/configuration"
|
5
|
+
require "zaikio/client/helpers/authorization_middleware"
|
6
|
+
|
7
|
+
module Zaikio
|
8
|
+
module Client
|
9
|
+
class << self
|
10
|
+
def with_token(token)
|
11
|
+
original_token = Helpers::AuthorizationMiddleware.token
|
12
|
+
Helpers::AuthorizationMiddleware.token = token
|
13
|
+
yield
|
14
|
+
ensure
|
15
|
+
Helpers::AuthorizationMiddleware.token = original_token
|
16
|
+
end
|
17
|
+
|
18
|
+
def create_connection(configuration)
|
19
|
+
Faraday.new(url: configuration.host,
|
20
|
+
ssl: { verify: configuration.environment != :test }) do |c|
|
21
|
+
c.request :json
|
22
|
+
c.response :logger, configuration&.logger, headers: false
|
23
|
+
c.use Zaikio::Client::Helpers::Pagination::FaradayMiddleware
|
24
|
+
c.use Zaikio::Client::Helpers::JSONParser
|
25
|
+
c.use Zaikio::Client::Helpers::AuthorizationMiddleware
|
26
|
+
c.adapter Faraday.default_adapter
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -3,6 +3,4 @@
|
|
3
3
|
require_relative "zaikio/client/helpers/version"
|
4
4
|
|
5
5
|
require_relative "zaikio/error"
|
6
|
-
require_relative "zaikio/client
|
7
|
-
require_relative "zaikio/client/helpers/json_parser"
|
8
|
-
require_relative "zaikio/client/helpers/pagination"
|
6
|
+
require_relative "zaikio/client"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zaikio-client-helpers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Zaikio GMBH
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-08-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -98,6 +98,9 @@ files:
|
|
98
98
|
- README.md
|
99
99
|
- Rakefile
|
100
100
|
- lib/zaikio-client-helpers.rb
|
101
|
+
- lib/zaikio/client.rb
|
102
|
+
- lib/zaikio/client/helpers/authorization_middleware.rb
|
103
|
+
- lib/zaikio/client/helpers/configuration.rb
|
101
104
|
- lib/zaikio/client/helpers/json_parser.rb
|
102
105
|
- lib/zaikio/client/helpers/pagination.rb
|
103
106
|
- lib/zaikio/client/helpers/version.rb
|