privat_bank_business_api 0.2.1

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.
Files changed (102) hide show
  1. checksums.yaml +7 -0
  2. data/.devcontainer/Dockerfile +17 -0
  3. data/.devcontainer/devcontainer.json +33 -0
  4. data/.devcontainer/post-create.sh +8 -0
  5. data/.rspec +3 -0
  6. data/.rubocop.yml +9 -0
  7. data/.vscode/settings.json +6 -0
  8. data/CHANGELOG.md +12 -0
  9. data/CODE_OF_CONDUCT.md +132 -0
  10. data/LICENSE.txt +21 -0
  11. data/README.md +123 -0
  12. data/Rakefile +12 -0
  13. data/lib/pb_api/base_transformer.rb +19 -0
  14. data/lib/pb_api/client.rb +41 -0
  15. data/lib/pb_api/models/balance.rb +79 -0
  16. data/lib/pb_api/models/base_struct.rb +30 -0
  17. data/lib/pb_api/models/transaction.rb +114 -0
  18. data/lib/pb_api/pagination_helper.rb +73 -0
  19. data/lib/pb_api/resource.rb +97 -0
  20. data/lib/pb_api/resources/balance_resource.rb +40 -0
  21. data/lib/pb_api/resources/transaction_resource.rb +105 -0
  22. data/lib/pb_api/transformers/balance_transformer.rb +35 -0
  23. data/lib/pb_api/transformers/transaction_transformer.rb +46 -0
  24. data/lib/pb_api/types.rb +8 -0
  25. data/lib/pb_api/version.rb +5 -0
  26. data/lib/pb_api.rb +34 -0
  27. data/sig/privat_bank_buisness_api.rbs +4 -0
  28. data/sorbet/config +4 -0
  29. data/sorbet/rbi/annotations/.gitattributes +1 -0
  30. data/sorbet/rbi/annotations/faraday.rbi +17 -0
  31. data/sorbet/rbi/annotations/rainbow.rbi +269 -0
  32. data/sorbet/rbi/gems/.gitattributes +1 -0
  33. data/sorbet/rbi/gems/ast@2.4.2.rbi +585 -0
  34. data/sorbet/rbi/gems/benchmark@0.4.0.rbi +618 -0
  35. data/sorbet/rbi/gems/bigdecimal@3.1.9.rbi +9 -0
  36. data/sorbet/rbi/gems/concurrent-ruby@1.3.5.rbi +9 -0
  37. data/sorbet/rbi/gems/date@3.4.1.rbi +75 -0
  38. data/sorbet/rbi/gems/diff-lcs@1.6.0.rbi +1134 -0
  39. data/sorbet/rbi/gems/dry-core@1.1.0.rbi +9 -0
  40. data/sorbet/rbi/gems/dry-inflector@1.2.0.rbi +9 -0
  41. data/sorbet/rbi/gems/dry-logic@1.6.0.rbi +9 -0
  42. data/sorbet/rbi/gems/dry-struct@1.7.1.rbi +925 -0
  43. data/sorbet/rbi/gems/dry-transformer@1.0.1.rbi +1512 -0
  44. data/sorbet/rbi/gems/dry-types@1.8.2.rbi +9 -0
  45. data/sorbet/rbi/gems/erubi@1.13.1.rbi +155 -0
  46. data/sorbet/rbi/gems/faraday-em_http@1.0.0.rbi +9 -0
  47. data/sorbet/rbi/gems/faraday-em_synchrony@1.0.0.rbi +9 -0
  48. data/sorbet/rbi/gems/faraday-excon@1.1.0.rbi +9 -0
  49. data/sorbet/rbi/gems/faraday-httpclient@1.0.1.rbi +9 -0
  50. data/sorbet/rbi/gems/faraday-multipart@1.1.0.rbi +9 -0
  51. data/sorbet/rbi/gems/faraday-net_http@1.0.2.rbi +9 -0
  52. data/sorbet/rbi/gems/faraday-net_http_persistent@1.2.0.rbi +9 -0
  53. data/sorbet/rbi/gems/faraday-patron@1.0.0.rbi +9 -0
  54. data/sorbet/rbi/gems/faraday-rack@1.0.0.rbi +9 -0
  55. data/sorbet/rbi/gems/faraday-retry@1.0.3.rbi +9 -0
  56. data/sorbet/rbi/gems/faraday@1.10.4.rbi +9 -0
  57. data/sorbet/rbi/gems/faraday_middleware@1.2.1.rbi +9 -0
  58. data/sorbet/rbi/gems/i18n@1.14.7.rbi +2208 -0
  59. data/sorbet/rbi/gems/ice_nine@0.11.2.rbi +9 -0
  60. data/sorbet/rbi/gems/io-console@0.8.0.rbi +9 -0
  61. data/sorbet/rbi/gems/json@2.10.1.rbi +2120 -0
  62. data/sorbet/rbi/gems/language_server-protocol@3.17.0.4.rbi +9 -0
  63. data/sorbet/rbi/gems/lint_roller@1.1.0.rbi +86 -0
  64. data/sorbet/rbi/gems/logger@1.6.6.rbi +940 -0
  65. data/sorbet/rbi/gems/money@6.19.0.rbi +2260 -0
  66. data/sorbet/rbi/gems/multipart-post@2.4.1.rbi +9 -0
  67. data/sorbet/rbi/gems/netrc@0.11.0.rbi +159 -0
  68. data/sorbet/rbi/gems/parallel@1.26.3.rbi +291 -0
  69. data/sorbet/rbi/gems/parser@3.3.7.1.rbi +5525 -0
  70. data/sorbet/rbi/gems/pp@0.6.2.rbi +368 -0
  71. data/sorbet/rbi/gems/prettyprint@0.2.0.rbi +477 -0
  72. data/sorbet/rbi/gems/prism@1.3.0.rbi +41403 -0
  73. data/sorbet/rbi/gems/psych@5.2.3.rbi +2435 -0
  74. data/sorbet/rbi/gems/racc@1.8.1.rbi +164 -0
  75. data/sorbet/rbi/gems/rainbow@3.1.1.rbi +403 -0
  76. data/sorbet/rbi/gems/rake@13.2.1.rbi +3028 -0
  77. data/sorbet/rbi/gems/rbi@0.2.4.rbi +4542 -0
  78. data/sorbet/rbi/gems/rdoc@6.12.0.rbi +12758 -0
  79. data/sorbet/rbi/gems/regexp_parser@2.10.0.rbi +3795 -0
  80. data/sorbet/rbi/gems/reline@0.6.0.rbi +2451 -0
  81. data/sorbet/rbi/gems/rspec-core@3.13.3.rbi +10986 -0
  82. data/sorbet/rbi/gems/rspec-expectations@3.13.3.rbi +8183 -0
  83. data/sorbet/rbi/gems/rspec-mocks@3.13.2.rbi +5341 -0
  84. data/sorbet/rbi/gems/rspec-support@3.13.2.rbi +1630 -0
  85. data/sorbet/rbi/gems/rspec@3.13.0.rbi +83 -0
  86. data/sorbet/rbi/gems/rubocop-ast@1.38.0.rbi +7654 -0
  87. data/sorbet/rbi/gems/rubocop@1.72.2.rbi +61026 -0
  88. data/sorbet/rbi/gems/ruby-progressbar@1.13.0.rbi +1318 -0
  89. data/sorbet/rbi/gems/ruby2_keywords@0.0.5.rbi +9 -0
  90. data/sorbet/rbi/gems/spoom@1.5.4.rbi +5026 -0
  91. data/sorbet/rbi/gems/stringio@3.1.5.rbi +9 -0
  92. data/sorbet/rbi/gems/tapioca@0.16.11.rbi +3656 -0
  93. data/sorbet/rbi/gems/thor@1.3.2.rbi +4378 -0
  94. data/sorbet/rbi/gems/unicode-display_width@3.1.4.rbi +132 -0
  95. data/sorbet/rbi/gems/unicode-emoji@4.0.4.rbi +251 -0
  96. data/sorbet/rbi/gems/yard-sorbet@0.9.0.rbi +435 -0
  97. data/sorbet/rbi/gems/yard@0.9.37.rbi +18379 -0
  98. data/sorbet/rbi/gems/zeitwerk@2.7.2.rbi +9 -0
  99. data/sorbet/rbi/todo.rbi +17 -0
  100. data/sorbet/tapioca/config.yml +13 -0
  101. data/sorbet/tapioca/require.rb +8 -0
  102. metadata +231 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 99e919189c20bcfbc270bbbbcc3e094c09839538f4fddb38d74eb4b2fc9372d0
4
+ data.tar.gz: 7ee9d4349b91691ea022d005e4fc0568a12ec9ec884e953879d43b7af7177abf
5
+ SHA512:
6
+ metadata.gz: 4f2cc235f7e3d12452456258f491fc999b66d58f84ce9857322c69bc4b4eb73b6f4d481dab22cfa540fad5c33d7da17639ad37877b17a4988c6bceab77ff45d4
7
+ data.tar.gz: 906805e69987a99b94f3e2318c6352d1a8758a6d5d7bccdea5c96d83dac18fec0be3e86ec3c6d36ecaacf14fa7311ac7601d30c25233b6c468e66ee5a15fe9c4
@@ -0,0 +1,17 @@
1
+ # Use the base image from the devcontainer.json file
2
+ FROM mcr.microsoft.com/devcontainers/ruby:1-3.3-bullseye
3
+
4
+ # watchman latest release version. Could be done auto, but that needs a script. See https://github.com/facebook/watchman/issues/982
5
+ ARG WM_VERSION=v2024.04.15.00
6
+
7
+ # install watchman
8
+ RUN wget https://github.com/facebook/watchman/releases/download/$WM_VERSION/watchman-$WM_VERSION-linux.zip && \
9
+ unzip watchman-$WM_VERSION-linux.zip && \
10
+ cd watchman-$WM_VERSION-linux && \
11
+ mkdir -p /usr/local/{bin,lib} /usr/local/var/run/watchman && \
12
+ cp bin/* /usr/local/bin && \
13
+ cp lib/* /usr/local/lib && \
14
+ chmod 755 /usr/local/bin/watchman && \
15
+ chmod 2777 /usr/local/var/run/watchman && \
16
+ cd .. && \
17
+ rm -fr watchman-$WM_VERSION-linux.zip watchman-$WM_VERSION-linux
@@ -0,0 +1,33 @@
1
+ // For format details, see https://aka.ms/devcontainer.json. For config options, see the
2
+ // README at: https://github.com/devcontainers/templates/tree/main/src/ruby
3
+ {
4
+ "name": "Ruby",
5
+ // Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
6
+ "build": {
7
+ "dockerfile": "Dockerfile"
8
+ },
9
+ // Features to add to the dev container. More info: https://containers.dev/features.
10
+ // "features": {},
11
+ // Use 'forwardPorts' to make a list of ports inside the container available locally.
12
+ // "forwardPorts": [],
13
+ // Use 'postCreateCommand' to run commands after the container is created.
14
+ "postCreateCommand": "sh .devcontainer/post-create.sh",
15
+ // Configure tool-specific properties.
16
+ "customizations": {
17
+ // Configure properties specific to VS Code.
18
+ "vscode": {
19
+ // Add the IDs of extensions you want installed when the container is created.
20
+ "extensions": [
21
+ "streetsidesoftware.code-spell-checker",
22
+ "Shopify.ruby-extensions-pack",
23
+ "connorshea.vscode-ruby-test-adapter",
24
+ "eamodio.gitlens",
25
+ "Gruntfuggly.todo-tree",
26
+ "ninoseki.vscode-mogami",
27
+ "bierner.markdown-mermaid"
28
+ ]
29
+ }
30
+ },
31
+ // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
32
+ // "remoteUser": "root"
33
+ }
@@ -0,0 +1,8 @@
1
+ if [ -f Gemfile ]; then
2
+ bundle install
3
+ fi
4
+
5
+ if [ -f .ruby-lsp/Gemfile ]; then
6
+ cd .ruby-lsp
7
+ bundle install
8
+ fi
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,9 @@
1
+ AllCops:
2
+ TargetRubyVersion: 3.1
3
+ NewCops: enable
4
+
5
+ Style/StringLiterals:
6
+ EnforcedStyle: double_quotes
7
+
8
+ Style/StringLiteralsInInterpolation:
9
+ EnforcedStyle: double_quotes
@@ -0,0 +1,6 @@
1
+ {
2
+ "cSpell.words": [
3
+ "privat"
4
+ ],
5
+ "rubyLsp.rubyExecutablePath": "/usr/local/bin/ruby" // adjust path as needed
6
+ }
data/CHANGELOG.md ADDED
@@ -0,0 +1,12 @@
1
+ ## [Released]
2
+
3
+ ## [0.1.0] - 2025-02-24
4
+
5
+ - Initial release
6
+ - only the most basic api, for balance, no pagination.
7
+
8
+ ## [0.2.0] - 2025-03-02
9
+
10
+ - Added resource transactions.
11
+ - Added pagination support with lazy enumerable.
12
+ - added tests.
@@ -0,0 +1,132 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our
6
+ community a harassment-free experience for everyone, regardless of age, body
7
+ size, visible or invisible disability, ethnicity, sex characteristics, gender
8
+ identity and expression, level of experience, education, socio-economic status,
9
+ nationality, personal appearance, race, caste, color, religion, or sexual
10
+ identity and orientation.
11
+
12
+ We pledge to act and interact in ways that contribute to an open, welcoming,
13
+ diverse, inclusive, and healthy community.
14
+
15
+ ## Our Standards
16
+
17
+ Examples of behavior that contributes to a positive environment for our
18
+ community include:
19
+
20
+ * Demonstrating empathy and kindness toward other people
21
+ * Being respectful of differing opinions, viewpoints, and experiences
22
+ * Giving and gracefully accepting constructive feedback
23
+ * Accepting responsibility and apologizing to those affected by our mistakes,
24
+ and learning from the experience
25
+ * Focusing on what is best not just for us as individuals, but for the overall
26
+ community
27
+
28
+ Examples of unacceptable behavior include:
29
+
30
+ * The use of sexualized language or imagery, and sexual attention or advances of
31
+ any kind
32
+ * Trolling, insulting or derogatory comments, and personal or political attacks
33
+ * Public or private harassment
34
+ * Publishing others' private information, such as a physical or email address,
35
+ without their explicit permission
36
+ * Other conduct which could reasonably be considered inappropriate in a
37
+ professional setting
38
+
39
+ ## Enforcement Responsibilities
40
+
41
+ Community leaders are responsible for clarifying and enforcing our standards of
42
+ acceptable behavior and will take appropriate and fair corrective action in
43
+ response to any behavior that they deem inappropriate, threatening, offensive,
44
+ or harmful.
45
+
46
+ Community leaders have the right and responsibility to remove, edit, or reject
47
+ comments, commits, code, wiki edits, issues, and other contributions that are
48
+ not aligned to this Code of Conduct, and will communicate reasons for moderation
49
+ decisions when appropriate.
50
+
51
+ ## Scope
52
+
53
+ This Code of Conduct applies within all community spaces, and also applies when
54
+ an individual is officially representing the community in public spaces.
55
+ Examples of representing our community include using an official email address,
56
+ posting via an official social media account, or acting as an appointed
57
+ representative at an online or offline event.
58
+
59
+ ## Enforcement
60
+
61
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
62
+ reported to the community leaders responsible for enforcement at
63
+ [INSERT CONTACT METHOD].
64
+ All complaints will be reviewed and investigated promptly and fairly.
65
+
66
+ All community leaders are obligated to respect the privacy and security of the
67
+ reporter of any incident.
68
+
69
+ ## Enforcement Guidelines
70
+
71
+ Community leaders will follow these Community Impact Guidelines in determining
72
+ the consequences for any action they deem in violation of this Code of Conduct:
73
+
74
+ ### 1. Correction
75
+
76
+ **Community Impact**: Use of inappropriate language or other behavior deemed
77
+ unprofessional or unwelcome in the community.
78
+
79
+ **Consequence**: A private, written warning from community leaders, providing
80
+ clarity around the nature of the violation and an explanation of why the
81
+ behavior was inappropriate. A public apology may be requested.
82
+
83
+ ### 2. Warning
84
+
85
+ **Community Impact**: A violation through a single incident or series of
86
+ actions.
87
+
88
+ **Consequence**: A warning with consequences for continued behavior. No
89
+ interaction with the people involved, including unsolicited interaction with
90
+ those enforcing the Code of Conduct, for a specified period of time. This
91
+ includes avoiding interactions in community spaces as well as external channels
92
+ like social media. Violating these terms may lead to a temporary or permanent
93
+ ban.
94
+
95
+ ### 3. Temporary Ban
96
+
97
+ **Community Impact**: A serious violation of community standards, including
98
+ sustained inappropriate behavior.
99
+
100
+ **Consequence**: A temporary ban from any sort of interaction or public
101
+ communication with the community for a specified period of time. No public or
102
+ private interaction with the people involved, including unsolicited interaction
103
+ with those enforcing the Code of Conduct, is allowed during this period.
104
+ Violating these terms may lead to a permanent ban.
105
+
106
+ ### 4. Permanent Ban
107
+
108
+ **Community Impact**: Demonstrating a pattern of violation of community
109
+ standards, including sustained inappropriate behavior, harassment of an
110
+ individual, or aggression toward or disparagement of classes of individuals.
111
+
112
+ **Consequence**: A permanent ban from any sort of public interaction within the
113
+ community.
114
+
115
+ ## Attribution
116
+
117
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118
+ version 2.1, available at
119
+ [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
120
+
121
+ Community Impact Guidelines were inspired by
122
+ [Mozilla's code of conduct enforcement ladder][Mozilla CoC].
123
+
124
+ For answers to common questions about this code of conduct, see the FAQ at
125
+ [https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
126
+ [https://www.contributor-covenant.org/translations][translations].
127
+
128
+ [homepage]: https://www.contributor-covenant.org
129
+ [v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
130
+ [Mozilla CoC]: https://github.com/mozilla/diversity
131
+ [FAQ]: https://www.contributor-covenant.org/faq
132
+ [translations]: https://www.contributor-covenant.org/translations
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 merof
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,123 @@
1
+ # PrivatBankBusinessApi
2
+
3
+ This gem is an API wrapper for the PrivatBank Business API. It is currently a work in progress. For more details, see the [changelog](CHANGELOG.md).
4
+
5
+ API documentation can be found [here](https://docs.google.com/document/d/e/2PACX-1vTtKvGa3P4E-lDqLg3bHRF6Wi9S7GIjSMFEFxII5qQZBGxuTXs25hQNiUU1hMZQhOyx6BNvIZ1bVKSr/pub).
6
+
7
+ This project uses `dry-transformers` and `dry-schema` to provide proper names for API fields. See the model files in the `/models` directory and the mapping from the original fields in the `/transformers` directory. For example, see the [balance transformer](lib/pb_api/transformers/balance_transformer.rb) and [balance model](lib/pb_api/models/balance.rb).
8
+
9
+ ## Money Field Mappings
10
+
11
+ Certain fields in the API responses can be handled as Money using the Money gem. These fields are available in various formats depending on the context. Below are some examples:
12
+
13
+ ### Balances
14
+ - **Standard Fields:**
15
+ - `balance_in` and `balance_in_uah`
16
+ - `balance_out` and `balance_out_uah`
17
+ - `turnover_debt` and `turnover_debt_uah`
18
+ - `turnover_cred` and `turnover_cred_uah`
19
+ - **Money Gem Fields:**
20
+ The same fields may also appear with an additional `_money` suffix (e.g., `balance_in_money`), providing a Money-formatted version.
21
+
22
+ ### Transactions
23
+ - **Standard Amount Fields:**
24
+ - `money_amount_uah`
25
+ - `money_amount`
26
+ - **Money Gem Fields:**
27
+ - `amount_uah_money`
28
+ - `amount_money`
29
+
30
+ ## Installation
31
+
32
+ Follow the installation instructions provided in the main guide to add and use the gem in your application.
33
+
34
+ Install the gem and add to the application's Gemfile by executing:
35
+
36
+ ```bash
37
+ bundle add privat_bank_business_api
38
+ ```
39
+
40
+ If bundler is not being used to manage dependencies, install the gem by executing:
41
+
42
+ ```bash
43
+ gem install privat_bank_business_api
44
+ ```
45
+
46
+ ## Usage
47
+
48
+ To use the API, you need to initialize the client with your API token. Here is a basic example of how to list balances:
49
+
50
+ ```ruby
51
+ require "pb_api"
52
+ require "date"
53
+
54
+ # Initialize the client with your API token
55
+ client = PbAPI::Client.new(api_token: "your_api_token_here")
56
+
57
+ # Define the date range for the balance query
58
+ today = Date.today
59
+ last_month = today.prev_month
60
+
61
+ # Fetch the list of balances
62
+ balances = client.balance.list(start_date: last_month)
63
+
64
+ # Print the account and balance information
65
+ balances.each do |balance|
66
+ puts "Account: #{balance.account}"
67
+ puts "Balance: #{balance.balance_in_money.format}"
68
+ end
69
+ ```
70
+
71
+ ## Feature: Lazy Loading Pagination
72
+
73
+ All API methods internally use lazy loading to handle paginated results. By leveraging Ruby's Enumerator, the gem fetches data on-demand
74
+
75
+ ## Logging
76
+
77
+ PbAPI's has configurable logging logging is configured in [pb_api.rb](./lib/pb_api.rb). The logger uses Rails.logger if available, otherwise defaults to a standard Ruby Logger writing to STDOUT with a custom formatter that includes abbreviated severity, a timestamp with microseconds, and process details.
78
+
79
+ ## Development
80
+
81
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
82
+
83
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
84
+
85
+ ### Development Environment
86
+
87
+ This project includes a development container configuration. To use it, you need to have Visual Studio Code and the Remote - Containers extension installed. You can open the project in a dev container by clicking the badge below:
88
+
89
+ [![Open in Dev Containers](https://img.shields.io/static/v1?label=Dev%20Containers&message=Open&color=blue&logo=visualstudiocode)](https://vscode.dev/redirect?url=vscode://ms-vscode-remote.remote-containers/cloneInVolume?url=https://github.com/merof-code/privat_bank_business_api)
90
+
91
+
92
+
93
+ ### Using bin/console
94
+
95
+
96
+ To use the API from the interactive console (`bin/console`), you need to add your own API key. Create a file named `environment.rb` in the root directory and add your API key there. You can use the provided `environment.sample.rb` as a template by renaming it to `environment.rb` and replacing the placeholder with your actual API key.
97
+
98
+ ```ruby
99
+ # environment.rb
100
+ ENV['API_TOKEN'] = 'your_api_key_here'
101
+ ```
102
+
103
+ Once inside the console, you can use the `@client` object to interact with the API. For example, to list balances:
104
+
105
+ ```ruby
106
+ balances = @client.balance.list(@today)
107
+ balances.each do |balance|
108
+ puts balance.account
109
+ puts balance.balance_in_money.format
110
+ end
111
+ ```
112
+
113
+ ## Contributing
114
+
115
+ Bug reports and pull requests are welcome on GitHub at https://github.com/merof-code/privat_bank_business_api. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/merof-code/privat_bank_business_api/blob/master/CODE_OF_CONDUCT.md).
116
+
117
+ ## License
118
+
119
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
120
+
121
+ ## Code of Conduct
122
+
123
+ Everyone interacting in the PrivatBankBusinessApi project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/merof-code/privat_bank_business_api/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PbAPI
4
+ # transformer methods here
5
+ class BaseTransformer < Dry::Transformer::Pipe
6
+ import Dry::Transformer::HashTransformations
7
+ import Dry::Transformer::ArrayTransformations
8
+
9
+ # Build a transformation pipeline given a mapping
10
+ def self.build_pipeline(mapping)
11
+ define! do
12
+ map_array do
13
+ rename_keys(mapping)
14
+ symbolize_keys
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PbAPI
4
+ # main entry point for the gem
5
+ # see #balances. #transactions
6
+ class Client
7
+ BASE_URL = "https://acp.privatbank.ua/api/"
8
+ attr_reader :api_token, :adapter
9
+
10
+ def initialize(api_token:, adapter: Faraday.default_adapter, stubs: nil)
11
+ @api_token = api_token
12
+ @adapter = adapter
13
+
14
+ # Test stubs for requests
15
+ @stubs = stubs
16
+ end
17
+
18
+ def connection
19
+ @connection ||= Faraday.new(BASE_URL) do |b|
20
+ b.headers["token"] = @api_token
21
+ b.headers["Content-Type"] = "application/json;charset=utf8"
22
+ b.ssl.verify = true
23
+ b.response :json
24
+ b.response :logger, PbAPI.logger, { headers: false, bodies: false }
25
+ b.adapter @adapter, @stubs
26
+ end
27
+ end
28
+
29
+ # Returns a new instance of PbAPI::Resources::BalanceResource for handling balance-related API operations.
30
+ # @return [PbAPI::Resources::BalanceResource] The balance resource client.
31
+ def balances
32
+ PbAPI::Resources::BalanceResource.new(self)
33
+ end
34
+
35
+ # Returns a new instance of PbAPI::Resources::TransactionResource for handling transaction-related API operations.
36
+ # @return [PbAPI::Resources::TransactionResource] The transaction resource client.
37
+ def transactions
38
+ PbAPI::Resources::TransactionResource.new(self)
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,79 @@
1
+ # frozen_string_literal: true
2
+ # typed: true
3
+
4
+ module PbAPI
5
+ module Models
6
+ # balance model, see api docs for more info (readme)
7
+ class Balance < BaseStruct
8
+ attribute :account, Types::String
9
+ attribute :currency, Types::String
10
+ attribute :counterparty_branch, Types::String
11
+ attribute :account_branch, Types::String
12
+ attribute :account_name, Types::String
13
+ attribute :state, Types::String
14
+ attribute :account_type, Types::String
15
+ attribute :location, Types::String
16
+
17
+ # Decimal (monetary) attributes: using coercible decimals to convert string values
18
+ attribute :balance_in, Types::Coercible::Decimal
19
+ attribute :balance_in_uah, Types::Coercible::Decimal
20
+ attribute :balance_out, Types::Coercible::Decimal
21
+ attribute :balance_out_uah, Types::Coercible::Decimal
22
+ attribute :turnover_debt, Types::Coercible::Decimal
23
+ attribute :turnover_debt_uah, Types::Coercible::Decimal
24
+ attribute :turnover_cred, Types::Coercible::Decimal
25
+ attribute :turnover_cred_uah, Types::Coercible::Decimal
26
+
27
+ # DateTime attributes: using Params coercion for strings formatted as dates
28
+ attribute :last_operation_date_time, Types::Params::DateTime
29
+ attribute :open_account_reg_date_time, Types::Params::DateTime
30
+ attribute :open_account_sys_date_time, Types::Params::DateTime
31
+ attribute :close_account_date_time, Types::Params::DateTime
32
+
33
+ # Boolean attribute
34
+ attribute :final_balance, Types::Bool
35
+
36
+ # @!method balance_in_money
37
+ # @return [Money] Returns a Money object for balance_in using the model's currency.
38
+ #
39
+ # @!method balance_in_uah_money
40
+ # @return [Money] Returns a Money object for balance_in_uah using "UAH" as currency.
41
+ #
42
+ # @!method balance_out_money
43
+ # @return [Money] Returns a Money object for balance_out using the model's currency.
44
+ #
45
+ # @!method balance_out_uah_money
46
+ # @return [Money] Returns a Money object for balance_out_uah using "UAH" as currency.
47
+ #
48
+ # @!method turnover_debt_money
49
+ # @return [Money] Returns a Money object for turnover_debt using the model's currency.
50
+ #
51
+ # @!method turnover_debt_uah_money
52
+ # @return [Money] Returns a Money object for turnover_debt_uah using "UAH" as currency.
53
+ #
54
+ # @!method turnover_cred_money
55
+ # @return [Money] Returns a Money object for turnover_cred using the model's currency.
56
+ #
57
+ # @!method turnover_cred_uah_money
58
+ # @return [Money] Returns a Money object for turnover_cred_uah using "UAH" as currency.
59
+
60
+ # List of monetary attribute names.
61
+ MONEY_FIELDS = %i[
62
+ balance_in balance_in_uah
63
+ balance_out balance_out_uah
64
+ turnover_debt turnover_debt_uah
65
+ turnover_cred turnover_cred_uah
66
+ ].freeze
67
+
68
+ # For each monetary field, define a method that returns a Money object.
69
+ MONEY_FIELDS.each do |field|
70
+ define_method("#{field}_money") do
71
+ # Choose the currency based on the field name: if it ends with _uah, use "UAH",
72
+ # otherwise use the model's currency.
73
+ currency_to_use = field.to_s.end_with?("_uah") ? "UAH" : currency
74
+ Money.from_amount(public_send(field), currency_to_use)
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PbAPI
4
+ module Models
5
+ # BaseStruct is a parent class for all models that require a transformer.
6
+ # It dynamically infers the transformer class based on the name of the child class.
7
+ #
8
+ # Example:
9
+ # class Balance < BaseStruct; end
10
+ # Balance.transformer # Returns PbAPI::Transformers::BalanceTransformer.new
11
+ #
12
+ # class Transaction < BaseStruct; end
13
+ # Transaction.transformer # Returns PbAPI::Transformers::TransactionTransformer.new
14
+ #
15
+ # This ensures that all subclasses of BaseStruct automatically have a transformer method
16
+ # without needing to redefine it in each subclass.
17
+ class BaseStruct < Dry::Struct
18
+ # Returns an instance of the transformer class inferred from the child class name.
19
+ # Example:
20
+ # class Balance < BaseStruct; end
21
+ # Balance.transformer # Returns PbAPI::Transformers::BalanceTransformer.new
22
+ def self.transformer
23
+ short_name = name.split("::").last
24
+ transformer_class_name = "#{short_name}Transformer"
25
+ transformer_class = PbAPI::Transformers.const_get(transformer_class_name)
26
+ transformer_class.new
27
+ end
28
+ end
29
+ end
30
+ end