zaikio-client-helpers 0.2.4 → 0.4.0

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: d00d304ca27fb927748ae92d163e44c1254a6a9b6c7cd2616fdc32e8cd08dc38
4
- data.tar.gz: cbbe9e8df3357f9e1bfdb7defc4e14d20808add68608138d60684e2af78b2e08
3
+ metadata.gz: d266642334866842da555510bf6da0a789a31a23a02ba39d33e72115d22752ef
4
+ data.tar.gz: 80db7cb3b8f18f4631382cef21bf60e7181a5a5c4e7a8538c9e30298353bf6c5
5
5
  SHA512:
6
- metadata.gz: 24eebf4cafa1afd04326db5f23b2d8518e2c1633607e5d8c54bcdf768b576ac5e7b3a266ac495c85ab73e6f167dfca7b545d41d802f3fd6777e8df417af35590
7
- data.tar.gz: 51c4e0d201584c3d0701bffb3942a219d2d40312f946f4b75b11e43ccf00acc06369553b8ee6bdef182766f07137b38e52ef6520e4319c8e33ee55f44d008753
6
+ metadata.gz: 9e125c503402d5b156be59ab0af6a0739db65588996a194c539b00a06578ee771db6e6d46caa2ba36390c1a56cfbdb694b2a4d3a438089160b23a6b1be9b310f
7
+ data.tar.gz: 7ba458d96f9f1fc0f5fa9030c39b5d06fe1d30352075e54cc79bd60631917606ae78157ec6aec788dbec20cdb4a9010f25ed721a749924d02fda565f2d3e0cc5
data/CHANGELOG.md CHANGED
@@ -1,4 +1,12 @@
1
- ## [Unreleased]
1
+ ## [0.4.0] - 2023-02-09
2
+
3
+ - Add a default read timeout for Faraday connection of 5 seconds, and open timeout of 1 second.
4
+
5
+ ## [0.3.0] - 2022-08-15
6
+
7
+ - 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
8
+ - Add `Zaikio::Client::Helpers::Configuration` as an abstract configuration class
9
+ - Add `Zaikio::Client.create_connection`
2
10
 
3
11
  ## [0.2.4] - 2022-03-29
4
12
 
@@ -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
@@ -3,7 +3,7 @@
3
3
  module Zaikio
4
4
  module Client
5
5
  module Helpers
6
- VERSION = "0.2.4"
6
+ VERSION = "0.4.0"
7
7
  end
8
8
  end
9
9
  end
@@ -0,0 +1,33 @@
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.options.read_timeout = 5
22
+ c.options.open_timeout = 1
23
+ c.request :json
24
+ c.response :logger, configuration&.logger, headers: false
25
+ c.use Zaikio::Client::Helpers::Pagination::FaradayMiddleware
26
+ c.use Zaikio::Client::Helpers::JSONParser
27
+ c.use Zaikio::Client::Helpers::AuthorizationMiddleware
28
+ c.adapter Faraday.default_adapter
29
+ end
30
+ end
31
+ end
32
+ end
33
+ 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/model"
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.2.4
4
+ version: 0.4.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-03-29 00:00:00.000000000 Z
11
+ date: 2023-02-09 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