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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 196c56c7c25333964e67affce921dec15f8927e3eaa1c45aacd2d5d93e41daef
4
- data.tar.gz: cb6db6d911d09b424e5e1dd1f6b1b380b6c408b4cf884205d935bc9011fa1803
3
+ metadata.gz: 21758426458c2332ba6c8417b6c537aa9b7f5f6858d71a0978af801463c638f6
4
+ data.tar.gz: fd206f19dc7884755a5a5d75ba4b8c6c42a8a7ad21c7e22053eed2925d106269
5
5
  SHA512:
6
- metadata.gz: d5fc93e4431a5f382b563bd2067bdaaa2dd264eb09544134ba3036ed6048b3774b061b198ff1b31546cdd9fceedb33a6a61c4befb70b3d503689ec40f84507ad
7
- data.tar.gz: ad888940994f62359763454a95348b0bdccc2b2efc5cac28871ff8002b64ca7b7453ef1dd3d2fddfb3adf026a6aac3bc1411d73b4e28183171b219c852aa3f23
6
+ metadata.gz: 8ed84be6352fb6a4ba845dee14947636130c4cfd826003d4322462c1846be1a03c10b8b1474a873fa452b13dfb15e4a4460848caa1293ce223412231cc0a3d5d
7
+ data.tar.gz: 3a63645fc47e5e982be2399147464dfc7a77b6fadef0a7c6fc9d412fcde4769f1c787ab1b104a1d9274462ca309e2151c560f9de5a8461bc99e20514de26b72b
data/CHANGELOG.md CHANGED
@@ -5,4 +5,10 @@
5
5
  - Initial release
6
6
  - only the most basic api for statements v3
7
7
  - pagination
8
- - authentication
8
+ - authentication
9
+
10
+ ## [0.1.1] - 2025-03-17
11
+
12
+ - hot fix
13
+ - configuration for client params
14
+ - base64 dependency added
@@ -13,28 +13,36 @@ module UkrsibAPI
13
13
 
14
14
  attr_reader :client_params, :private_key, :tokens
15
15
 
16
- # This method sets up authentication using either `client_params` (for new authentication) or existing `tokens`
17
- #
18
- # @param private_key [String] The RSA private key in PEM format.
19
- # @param client_params [Hash, nil] OAuth2 client parameters for authentication.
20
- # This includes `client_id`, `client_secret`.
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 with client_params (fresh authentication)
30
- # auth = Authenticator.new(private_key:, client_params: { client_id: "abc", client_secret: "xyz" })
28
+ # @example Initialize using stored config
29
+ # auth = Authentication.new
31
30
  #
32
- # @example Initialize with tokens (existing authentication)
33
- # auth = Authenticator.new(private_key:, client_params:, tokens: { access_token: "token123", refresh_token: "token456" }, expires_at: Time.now + 3600)
34
- def initialize(private_key:, client_params:, tokens: nil)
35
- @private_key = OpenSSL::PKey::RSA.new(private_key) # Load RSA private key
36
- @client_params = client_params&.slice(:client_id, :client_secret) if client_params
37
- @tokens = tokens&.slice(:access_token, :refresh_token, :expires_at) if tokens
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"
@@ -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:, adapter: Faraday.default_adapter, stubs: nil)
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::Models
4
- # best practices
5
- module Types
6
- include Dry.Types()
3
+ module UkrsibAPI
4
+ module Models
5
+ # best practices
6
+ module Types
7
+ include Dry.Types()
7
8
 
8
- UnixTimestampWithMilliseconds = Types::Coercible::Integer.constructor do |value|
9
- # Convert Unix timestamp (milliseconds) to Time object
10
- ::Time.at(value / 1000).utc if value
11
- end
12
- CoercibleDecimal = Types::Nominal::Decimal.constructor do |value|
13
- case value
14
- when Float
15
- BigDecimal(value.to_s, 2) # Convert float to string first
16
- else
17
- begin
18
- BigDecimal(value)
19
- rescue StandardError
20
- nil
21
- end # Fallback for other cases
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module UkrsibAPI
4
- VERSION = "0.0.1"
4
+ VERSION = "0.0.2"
5
5
  end
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
- def self.logger
37
- @@logger ||= defined?(Rails) ? Rails.logger : Logger.new($stdout, progname: "UkrsibAPI") # rubocop:disable Style/ClassVars
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.1
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-17 00:00:00.000000000 Z
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