ukrsib_api 0.0.1 → 0.0.2
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 +4 -4
- data/CHANGELOG.md +7 -1
- data/lib/ukrsib_api/authentication.rb +26 -18
- data/lib/ukrsib_api/client.rb +2 -3
- data/lib/ukrsib_api/models/types.rb +20 -18
- data/lib/ukrsib_api/version.rb +1 -1
- data/lib/ukrsib_api.rb +10 -3
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 21758426458c2332ba6c8417b6c537aa9b7f5f6858d71a0978af801463c638f6
|
4
|
+
data.tar.gz: fd206f19dc7884755a5a5d75ba4b8c6c42a8a7ad21c7e22053eed2925d106269
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8ed84be6352fb6a4ba845dee14947636130c4cfd826003d4322462c1846be1a03c10b8b1474a873fa452b13dfb15e4a4460848caa1293ce223412231cc0a3d5d
|
7
|
+
data.tar.gz: 3a63645fc47e5e982be2399147464dfc7a77b6fadef0a7c6fc9d412fcde4769f1c787ab1b104a1d9274462ca309e2151c560f9de5a8461bc99e20514de26b72b
|
data/CHANGELOG.md
CHANGED
@@ -13,28 +13,36 @@ module UkrsibAPI
|
|
13
13
|
|
14
14
|
attr_reader :client_params, :private_key, :tokens
|
15
15
|
|
16
|
-
#
|
17
|
-
#
|
18
|
-
# @param private_key [String]
|
19
|
-
# @param client_params [Hash, nil] OAuth2
|
20
|
-
#
|
21
|
-
# @param tokens [Hash, nil] Optional. A hash containing previously acquired authentication tokens.
|
22
|
-
# Typically includes:
|
23
|
-
# - `:access_token` [String] The access token for API requests.
|
24
|
-
# - `:refresh_token` [String] The refresh token for obtaining a new access token.
|
25
|
-
# - `:expires_at` [Time] The refresh token for obtaining a new access token.
|
16
|
+
# Initializes authentication using provided credentials or defaults from config.
|
17
|
+
#
|
18
|
+
# @param private_key [String, nil] RSA private key in PEM format. Falls back to `UkrsibAPI.private_key`.
|
19
|
+
# @param client_params [Hash, nil] OAuth2 credentials (`client_id`, `client_secret`). Defaults to `UkrsibAPI` config.
|
20
|
+
# @param tokens [Hash, nil] Previously acquired tokens (`access_token`, `refresh_token`, `expires_at`).
|
26
21
|
#
|
27
22
|
# @raise [OpenSSL::PKey::RSAError] If the private key is invalid.
|
23
|
+
# @raise [ArgumentError] If tokens are provided without `expires_at`.
|
24
|
+
#
|
25
|
+
# @example Initialize with explicit credentials
|
26
|
+
# auth = Authentication.new(private_key: my_key, client_params: { client_id: "abc", client_secret: "xyz" })
|
28
27
|
#
|
29
|
-
# @example Initialize
|
30
|
-
# auth =
|
28
|
+
# @example Initialize using stored config
|
29
|
+
# auth = Authentication.new
|
31
30
|
#
|
32
|
-
# @example Initialize with tokens
|
33
|
-
# auth =
|
34
|
-
def initialize(private_key
|
35
|
-
@private_key = OpenSSL::PKey::RSA.new(private_key
|
36
|
-
@client_params =
|
37
|
-
|
31
|
+
# @example Initialize with tokens
|
32
|
+
# auth = Authentication.new(tokens: { access_token: "token123", refresh_token: "token456", expires_at: Time.now + 3600 })
|
33
|
+
def initialize(private_key: nil, client_params: nil, tokens: nil)
|
34
|
+
@private_key = OpenSSL::PKey::RSA.new(private_key || UkrsibAPI.private_key)
|
35
|
+
@client_params = {
|
36
|
+
client_id: client_params&.dig(:client_id) || UkrsibAPI.client_id,
|
37
|
+
client_secret: client_params&.dig(:client_secret) || UkrsibAPI.client_secret
|
38
|
+
}.compact
|
39
|
+
|
40
|
+
unless tokens
|
41
|
+
UkrsibAPI.logger.warn "No tokens provided, authenticate first, or pass UkrsibAPI::Authentication with existing tokens to UkrsibAPI::Client"
|
42
|
+
return
|
43
|
+
end
|
44
|
+
|
45
|
+
@tokens = tokens&.slice(:access_token, :refresh_token, :expires_at)
|
38
46
|
return unless @tokens && !@tokens[:expires_at]
|
39
47
|
|
40
48
|
raise ArgumentError, "Missing :expires_at in tokens, it should be a Time object, e.g. Time.now + expires_in"
|
data/lib/ukrsib_api/client.rb
CHANGED
@@ -7,12 +7,11 @@ module UkrsibAPI
|
|
7
7
|
BASE_URL = "https://business.ukrsibbank.com/morpheus/"
|
8
8
|
attr_reader :access_token, :adapter, :stubs, :auth
|
9
9
|
|
10
|
-
|
11
10
|
# Expects UkrsibAPI::Authentication tp be already authorized
|
12
11
|
# see documentation for UkrsibAPI::Authentication
|
13
12
|
# @param authentication [UkrsibAPI::Authentication] authentication object
|
14
|
-
def initialize(authentication
|
15
|
-
@auth = authentication
|
13
|
+
def initialize(authentication: nil, adapter: Faraday.default_adapter, stubs: nil)
|
14
|
+
@auth = authentication || UkrsibAPI::Authentication.new
|
16
15
|
@adapter = adapter
|
17
16
|
@stubs = stubs
|
18
17
|
end
|
@@ -1,24 +1,26 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
module UkrsibAPI
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
module UkrsibAPI
|
4
|
+
module Models
|
5
|
+
# best practices
|
6
|
+
module Types
|
7
|
+
include Dry.Types()
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
9
|
+
UnixTimestampWithMilliseconds = Types::Coercible::Integer.constructor do |value|
|
10
|
+
# Convert Unix timestamp (milliseconds) to Time object
|
11
|
+
::Time.at(value / 1000).utc if value
|
12
|
+
end
|
13
|
+
CoercibleDecimal = Types::Nominal::Decimal.constructor do |value|
|
14
|
+
case value
|
15
|
+
when Float
|
16
|
+
BigDecimal(value.to_s, 2) # Convert float to string first
|
17
|
+
else
|
18
|
+
begin
|
19
|
+
BigDecimal(value)
|
20
|
+
rescue StandardError
|
21
|
+
nil
|
22
|
+
end # Fallback for other cases
|
23
|
+
end
|
22
24
|
end
|
23
25
|
end
|
24
26
|
end
|
data/lib/ukrsib_api/version.rb
CHANGED
data/lib/ukrsib_api.rb
CHANGED
@@ -28,12 +28,19 @@ require_relative "ukrsib_api/transformers/statement_party_details_transformer"
|
|
28
28
|
require_relative "ukrsib_api/models/statement_party_details"
|
29
29
|
require_relative "ukrsib_api/models/statement_v3"
|
30
30
|
|
31
|
-
# Main entry point for the gem, use client = UkrsibAPI::Client.new(api_token: "token") to start using the API.
|
32
31
|
module UkrsibAPI
|
33
32
|
class Error < StandardError; end
|
34
33
|
class NotAuthorizedError < Error; end
|
35
34
|
|
36
|
-
|
37
|
-
|
35
|
+
class << self
|
36
|
+
attr_accessor :client_id, :client_secret, :private_key
|
37
|
+
|
38
|
+
def configure
|
39
|
+
yield self
|
40
|
+
end
|
41
|
+
|
42
|
+
def logger
|
43
|
+
@@logger ||= defined?(Rails) ? Rails.logger : Logger.new($stdout, progname: "UkrsibAPI") # rubocop:disable Style/ClassVars
|
44
|
+
end
|
38
45
|
end
|
39
46
|
end
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ukrsib_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- merof
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-03-
|
11
|
+
date: 2025-03-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: base64
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: dry-struct
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|