bb_statements 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ed022da729839b6b43e2486553f96b2d10acb08d873975029159178dfa94f93a
4
+ data.tar.gz: 437e58b8207f4cea3f603701ea8797663ece81ade47ebfc6444a27ac8fc35905
5
+ SHA512:
6
+ metadata.gz: '09a82c547e369ebf629f27aa7103e39ffae290d4d180b041838cf35873bc7528307e0f8b2eb550b194b9cc5c4b2bcff922b0f22e05f57970ad3ba4f53685ac16'
7
+ data.tar.gz: 5f156c2a57d13c85853d6a9505770f12cbfe32ed395e9dd96b69b1ad5c61522f9de95a1377691841e6bb2cb824a5e62e6f30e7474889da69a9e06587d03d60ea
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,13 @@
1
+ AllCops:
2
+ TargetRubyVersion: 3.2.2
3
+
4
+ Style/StringLiterals:
5
+ Enabled: true
6
+ EnforcedStyle: double_quotes
7
+
8
+ Style/StringLiteralsInInterpolation:
9
+ Enabled: true
10
+ EnforcedStyle: double_quotes
11
+
12
+ Layout/LineLength:
13
+ Max: 120
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2024-04-29
4
+
5
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at luanbritop7@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 ruby-banco-brasil
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 luanbrito7
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,81 @@
1
+ # bb_statements
2
+
3
+ BancoBrasilStatements - The Ruby gem for the the Banco do Brasil Statements API
4
+
5
+ - API version: 1.0
6
+ - Package version: 1.0.0
7
+ For more information, please visit [https://developers.bb.com.br](https://developers.bb.com.br)
8
+
9
+ ## Installation
10
+
11
+ ### Build a gem
12
+
13
+ To build the Ruby code into a gem:
14
+
15
+ ```shell
16
+ gem build bb_statements.gemspec
17
+ ```
18
+
19
+ Then either install the gem locally:
20
+
21
+ ```shell
22
+ gem install ./bb_statements-1.0.0.gem
23
+ ```
24
+ (for development, run `gem install --dev ./bb_statements-1.0.0.gem` to install the development dependencies)
25
+
26
+ or publish the gem to a gem hosting service, e.g. [RubyGems](https://rubygems.org/).
27
+
28
+ Finally add this to the Gemfile:
29
+
30
+ gem 'bb_statements', '~> 1.0.0'
31
+
32
+ ### Install from Git
33
+
34
+ If the Ruby gem is hosted at a git repository: https://github.com/GIT_USER_ID/GIT_REPO_ID, then add the following in the Gemfile:
35
+
36
+ gem 'bb_statements', :git => 'https://github.com/GIT_USER_ID/GIT_REPO_ID.git'
37
+
38
+ ### Include the Ruby code directly
39
+
40
+ Include the Ruby code directly using `-I` as follows:
41
+
42
+ ```shell
43
+ ruby -Ilib script.rb
44
+ ```
45
+
46
+ ## Getting Started
47
+
48
+ Please follow the [installation](#installation) procedure and then run the following code:
49
+
50
+ ```ruby
51
+ # Load the gem
52
+ require 'bb_statements'
53
+ # Setup authorization
54
+ BancoBrasilStatements.configure do |config|
55
+ # Configure OAuth2 access token for authorization: OAuth2-CC
56
+ config.access_token = 'YOUR ACCESS TOKEN'
57
+ end
58
+
59
+ api_instance = BancoBrasilStatements::StatementsApi.new
60
+ id = 'id_example' # String | Código identificador do pagamento.
61
+ gw_dev_app_key = 'gw_dev_app_key_example' # String | Chave de acesso do aplicativo do desenvolvedor. Esta chave é única e obtida no Portal “BB for Developers” e usada para identificar as requisições da aplicação do desenvolvedor. Example: 0021239456d80136bebf005056891bed
62
+ authorization = 'authorization_example' # String | É um “token” de acesso fornecido pelo OAuth 2.0. Example: Bearer [ACCESS_TOKEN]
63
+ opts = {
64
+ start_date: Date.yesterday,
65
+ end_date: Date.current,
66
+ page_size: 50,
67
+ page_index: 1
68
+ }
69
+
70
+ begin
71
+ # branch_office, account, opts
72
+ result = api_instance.consult_statements(1505, 1348, opts)
73
+ p result
74
+ rescue BancoBrasilStatements::ApiError => e
75
+ puts "Exception when calling StatementsApi->consult_statements: #{e}"
76
+ end
77
+ # Setup authorization
78
+ BancoBrasilStatements.configure do |config|
79
+ # Configure OAuth2 access token for authorization: OAuth2-CC
80
+ config.access_token = 'YOUR ACCESS TOKEN'
81
+ end
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,41 @@
1
+ # frozen_string_literal: true
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "bb_statements/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "bb_statements"
7
+ spec.version = BancoBrasilStatements::VERSION
8
+ spec.platform = Gem::Platform::RUBY
9
+ spec.authors = ["Luan", "Hent"]
10
+ spec.email = ["luanbritop7@gmail.com", "tech@hent.com.br"]
11
+
12
+ spec.summary = "A ruby wrapper for Banco do Brasil Statements"
13
+ spec.description = "This gem maps to the BB Statements API"
14
+ spec.homepage = "https://github.com/ruby-banco-brasil/bb-statement"
15
+ spec.license = "MIT"
16
+ spec.required_ruby_version = ">= 2.6.0"
17
+
18
+ spec.metadata["source_code_uri"] = "https://github.com/ruby-banco-brasil/bb-statement"
19
+
20
+ # Specify which files should be added to the gem when it is released.
21
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
+ spec.files = Dir.chdir(__dir__) do
23
+ `git ls-files -z`.split("\x0").reject do |f|
24
+ (File.expand_path(f) == __FILE__) ||
25
+ f.start_with?(*%w[bin/ test/ spec/ features/ .git appveyor Gemfile])
26
+ end
27
+ end
28
+ spec.bindir = "exe"
29
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ["lib"]
31
+
32
+ spec.add_runtime_dependency 'faraday', '~> 2.9.0'
33
+ spec.add_runtime_dependency 'json', '~> 2.6', '>= 2.1.0'
34
+ spec.add_runtime_dependency 'bb_oauth', '~> 1.0.3'
35
+ spec.add_runtime_dependency 'rails', '~> 7.1.2'
36
+
37
+ spec.add_development_dependency 'rspec', '~> 3.6', '>= 3.6.0'
38
+ spec.add_development_dependency 'byebug', '~> 11.1.3'
39
+ spec.add_development_dependency 'webmock', '~> 3.22.0'
40
+ spec.add_development_dependency 'activesupport', '~> 7.1', '>= 7.1.3.2'
41
+ end
@@ -0,0 +1,59 @@
1
+ module BancoBrasilStatements
2
+ class StatementsApi
3
+ attr_accessor :api_client, :gw_app_key
4
+
5
+ PAGE_SIZE = 50
6
+
7
+ def initialize(api_client = ApiClient.default)
8
+ @api_client = api_client
9
+ @gw_app_key = api_client.config.gw_app_key
10
+ end
11
+
12
+ # GET /conta-corrente/agencia/{agencia}/conta/{conta}
13
+ # Consulta os extratos de uma conta.
14
+ def consult_statements(branch_office, account, opts = {})
15
+ client_opts = build_client_opts(api_client: api_client,
16
+ gw_app_key: gw_app_key,
17
+ opts: opts)
18
+
19
+ # query parameters
20
+ query_params = client_opts[:query_params]
21
+ query_params[@api_client.config.app_key_name.to_sym] = gw_app_key
22
+ query_params[:dataInicioSolicitacao] = opts[:start_date].strftime('%d%m%Y').to_i unless opts[:start_date].nil?
23
+ query_params[:dataFimSolicitacao] = opts[:end_date].strftime('%d%m%Y').to_i unless opts[:end_date].nil?
24
+ query_params[:quantidadeRegistroPaginaSolicitacao] = unless opts[:page_size].nil?
25
+ opts[:page_size]
26
+ else
27
+ PAGE_SIZE
28
+ end
29
+
30
+ query_params[:numeroPaginaSolicitacao] = opts[:page_index] unless opts[:page_index].nil?
31
+
32
+ unless Rails.env.production?
33
+ branch_office = 452
34
+ account = 123873
35
+ end
36
+
37
+ api_client.call_api(:GET, "/conta-corrente/agencia/#{branch_office}/conta/#{account}", client_opts)
38
+ end
39
+
40
+ private
41
+
42
+ def build_client_opts(api_client:, gw_app_key:, opts:, return_type: 'Object', body: nil)
43
+ client_opts = {
44
+ base_path: '/extratos/v1',
45
+ body: opts[:body] || body,
46
+ form_params: opts[:form_params] || {},
47
+ return_type: opts[:return_type] || return_type,
48
+ auth_names: opts[:auth_names] || ['OAuth2-CC'],
49
+ query_params: opts[:query_params] || {},
50
+ header_params: opts[:header_params] || {}
51
+ }
52
+
53
+ # query parameters
54
+ client_opts[:query_params][api_client.config.app_key_name.to_sym] = gw_app_key
55
+
56
+ client_opts
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,107 @@
1
+ require 'date'
2
+ require 'json'
3
+ require 'logger'
4
+ require 'tempfile'
5
+ require 'faraday'
6
+ require 'uri'
7
+
8
+ module BancoBrasilStatements
9
+ class ApiClient
10
+ TOKEN_EXPIRE_TIME = 570
11
+
12
+ attr_accessor :config, :default_headers, :access_token_requested_at
13
+
14
+ # Initializes the ApiClient
15
+ # @option config [Configuration] Configuration for initializing the object, default to Configuration.default
16
+ def initialize(config = Configuration.default)
17
+ @config = config
18
+ @user_agent = "bb-statements-gem/#{VERSION}/ruby"
19
+ @default_headers = {
20
+ 'Content-Type' => 'application/json',
21
+ 'User-Agent' => @user_agent
22
+ }
23
+ @access_token_requested_at = nil
24
+ end
25
+
26
+ def self.default
27
+ @@default ||= ApiClient.new
28
+ end
29
+
30
+ def call_api(http_method, path, opts = {})
31
+ request = build_request(path, opts)
32
+ response = request.send(http_method.downcase.to_sym)
33
+
34
+ if @config.debugging
35
+ @config.logger.debug "HTTP response body ~BEGIN~\n#{response.body}\n~END~\n"
36
+ end
37
+
38
+ response.body
39
+ rescue Faraday::Error => e
40
+ fail BancoBrasilStatements::ApiError.new(e.message)
41
+ end
42
+
43
+ def build_request(path, opts = {})
44
+ base_path = opts[:base_path]
45
+ url = build_request_url(path, base_path)
46
+
47
+ header_params = @default_headers.merge(opts[:header_params] || {})
48
+ header_params['Accept-Encoding'] = 'gzip'
49
+ header_params['x-br-com-bb-ipa-mciteste'.to_sym] = '704950857' unless Rails.env.production?
50
+ query_params = opts[:query_params] || {}
51
+ form_params = opts[:form_params] || {}
52
+
53
+ update_params_for_auth! header_params
54
+
55
+ Faraday.new(url: url) do |faraday|
56
+ faraday.request :url_encoded
57
+ faraday.request :json
58
+ faraday.adapter Faraday.default_adapter
59
+
60
+ if @config.verify_ssl
61
+ faraday.ssl.verify = true
62
+ faraday.ssl.verify_mode = @config.verify_ssl_host ? OpenSSL::SSL::VERIFY_PEER : OpenSSL::SSL::VERIFY_NONE
63
+ faraday.ssl.client_cert = @config.cert_file if @config.cert_file
64
+ faraday.ssl.client_key = @config.key_file if @config.key_file
65
+ faraday.ssl.key_password = @config.ssl_key_passwd if @config.ssl_key_passwd
66
+ faraday.ssl.ca_file = @config.ssl_ca_cert if @config.ssl_ca_cert
67
+ else
68
+ faraday.ssl.verify = false
69
+ end
70
+
71
+ faraday.response :logger if @config.debugging
72
+ faraday.response :raise_error
73
+ faraday.response :json
74
+ faraday.headers = header_params
75
+ faraday.params = query_params
76
+ faraday.options.timeout = @config.timeout if @config.timeout
77
+ end
78
+ end
79
+
80
+ def build_request_url(path, base_path = nil)
81
+ # Add leading and trailing slashes to path
82
+ path = "/#{path}".gsub(/\/+/, '/')
83
+ @config.base_url(base_path || @config.base_path) + path
84
+ end
85
+
86
+ def update_params_for_auth!(header_params)
87
+ renew_token unless valid_token?
88
+
89
+ header_params['Authorization'] = "Bearer #{@config.access_token}"
90
+ end
91
+
92
+ def valid_token?
93
+ access_token_requested_at &&
94
+ (Time.zone.now - access_token_requested_at) < TOKEN_EXPIRE_TIME
95
+ end
96
+
97
+ def renew_token
98
+ api_instance = BancoBrasilClientCredentials::DefaultApi.new @config.client_credentials_api
99
+ result = api_instance.oauth_token_post('client_credentials',
100
+ @config.access_token_scopes, @config.basic_auth_token,
101
+ 'application/x-www-form-urlencoded')
102
+ self.access_token_requested_at = Time.zone.now
103
+ @config.access_token = result.access_token
104
+ result.access_token
105
+ end
106
+ end
107
+ end
@@ -0,0 +1,16 @@
1
+ module BancoBrasilStatements
2
+ class ApiError < StandardError
3
+ def initialize(message)
4
+ super message
5
+ end
6
+
7
+ # Override to_s to display a friendly error message
8
+ def to_s
9
+ message
10
+ end
11
+
12
+ def message
13
+ @message || "Error message: the server returns an error"
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,219 @@
1
+ module BancoBrasilStatements
2
+ class Configuration
3
+ # Defines url scheme
4
+ attr_accessor :scheme
5
+
6
+ # Defines url host
7
+ attr_accessor :host
8
+
9
+ # Defines url for oauth
10
+ attr_accessor :oauth_host
11
+
12
+ # Defines url base path
13
+ attr_accessor :base_path
14
+
15
+ # Defines API keys used with API Key authentications.
16
+ #
17
+ # @return [Hash] key: parameter name, value: parameter value (API key)
18
+ #
19
+ # @example parameter name is "api_key", API key is "xxx" (e.g. "api_key=xxx" in query string)
20
+ # config.api_key['api_key'] = 'xxx'
21
+ attr_accessor :api_key
22
+
23
+ # Defines API key prefixes used with API Key authentications.
24
+ #
25
+ # @return [Hash] key: parameter name, value: API key prefix
26
+ #
27
+ # @example parameter name is "Authorization", API key prefix is "Token" (e.g. "Authorization: Token xxx" in headers)
28
+ # config.api_key_prefix['api_key'] = 'Token'
29
+ attr_accessor :api_key_prefix
30
+
31
+ # Chave de acesso do aplicativo do desenvolvedor.
32
+ # Esta chave é única e obtida no Portal “BB for Developers”
33
+ # Usada para identificar as requisições da aplicação do desenvolvedor.
34
+ attr_accessor :gw_app_key
35
+
36
+ # Defines the username used with HTTP basic authentication.
37
+ #
38
+ # @return [String]
39
+ attr_accessor :username
40
+
41
+ # Defines the password used with HTTP basic authentication.
42
+ #
43
+ # @return [String]
44
+ attr_accessor :password
45
+
46
+ # Defines the access token (Bearer) used with OAuth2.
47
+ attr_accessor :access_token
48
+
49
+ # Set this to enable/disable debugging. When enabled (set to true), HTTP request/response
50
+ # details will be logged with `logger.debug` (see the `logger` attribute).
51
+ # Default to false.
52
+ #
53
+ # @return [true, false]
54
+ attr_accessor :debugging
55
+
56
+ # Defines the logger used for debugging.
57
+ # Default to `Rails.logger` (when in Rails) or logging to STDOUT.
58
+ #
59
+ # @return [#debug]
60
+ attr_accessor :logger
61
+
62
+ # Defines the temporary folder to store downloaded files
63
+ # (for API endpoints that have file response).
64
+ # Default to use `Tempfile`.
65
+ #
66
+ # @return [String]
67
+ attr_accessor :temp_folder_path
68
+
69
+ # The time limit for HTTP request in seconds.
70
+ # Default to 0 (never times out).
71
+ attr_accessor :timeout
72
+
73
+ # Set this to false to skip client side validation in the operation.
74
+ # Default to true.
75
+ # @return [true, false]
76
+ attr_accessor :client_side_validation
77
+
78
+ ### TLS/SSL setting
79
+ # Set this to false to skip verifying SSL certificate when calling API from https server.
80
+ # Default to true.
81
+ #
82
+ # @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks.
83
+ #
84
+ # @return [true, false]
85
+ attr_accessor :verify_ssl
86
+
87
+ ### TLS/SSL setting
88
+ # Set this to false to skip verifying SSL host name
89
+ # Default to true.
90
+ #
91
+ # @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks.
92
+ #
93
+ # @return [true, false]
94
+ attr_accessor :verify_ssl_host
95
+
96
+ ### TLS/SSL setting
97
+ # Set this to customize the certificate file to verify the peer.
98
+ #
99
+ # @return [String] the path to the certificate file
100
+ #
101
+ # @see The `cainfo` option of Typhoeus, `--cert` option of libcurl. Related source code:
102
+ # https://github.com/typhoeus/typhoeus/blob/master/lib/typhoeus/easy_factory.rb#L145
103
+ attr_accessor :ssl_ca_cert
104
+
105
+ ### TLS/SSL setting
106
+ # Client certificate file (for client certificate)
107
+ attr_accessor :cert_file
108
+
109
+ ### TLS/SSL setting
110
+ # Client private key file (for client certificate)
111
+ attr_accessor :key_file
112
+
113
+ ### TLS/SSL setting
114
+ # Client private key passphrase (for client certificate)
115
+ attr_accessor :ssl_key_passwd
116
+
117
+ # Set this to customize parameters encoding of array parameter with multi collectionFormat.
118
+ # Default to nil.
119
+ #
120
+ # @see The params_encoding option of Ethon. Related source code:
121
+ # https://github.com/typhoeus/ethon/blob/master/lib/ethon/easy/queryable.rb#L96
122
+ attr_accessor :params_encoding
123
+
124
+ attr_accessor :inject_format
125
+
126
+ attr_accessor :force_ending_format
127
+
128
+ attr_accessor :access_token_scopes
129
+
130
+ attr_accessor :app_key_name
131
+
132
+ def initialize
133
+ @scheme = 'https'
134
+ @app_key_name = 'gw-app-key'
135
+ @host = 'api-extratos.bb.com.br'
136
+ @oauth_host = 'oauth.bb.com.br'
137
+ @base_path = 'extratos/v1'
138
+ @api_key = {}
139
+ @api_key_prefix = {}
140
+ @timeout = nil
141
+ @client_side_validation = true
142
+ @verify_ssl = true
143
+ @verify_ssl_host = true
144
+ @params_encoding = nil
145
+ @cert_file = nil
146
+ @key_file = nil
147
+ @debugging = false
148
+ @inject_format = false
149
+ @force_ending_format = false
150
+ @logger = defined?(Jets) ? Jets.logger : Logger.new(STDOUT)
151
+ @access_token_scopes = 'extrato-info'
152
+
153
+ yield(self) if block_given?
154
+ end
155
+
156
+ def client_credentials_api
157
+ @client_credentials_api ||= BancoBrasilClientCredentials::ApiClient.new oauth_config
158
+ end
159
+
160
+ def oauth_config
161
+ oauth_config = BancoBrasilClientCredentials::Configuration.new
162
+ oauth_config.host = oauth_host
163
+ oauth_config.base_path = ''
164
+ oauth_config.logger = logger
165
+ oauth_config.debugging = debugging
166
+ oauth_config.verify_ssl = verify_ssl
167
+ oauth_config.verify_ssl_host = verify_ssl_host
168
+ oauth_config.access_token = access_token
169
+ oauth_config.username = username
170
+ oauth_config.password = password
171
+ oauth_config.ssl_ca_cert = ssl_ca_cert
172
+ oauth_config
173
+ end
174
+
175
+ # The default Configuration object.
176
+ def self.default
177
+ @@default ||= Configuration.new
178
+ end
179
+
180
+ def configure
181
+ yield(self) if block_given?
182
+ end
183
+
184
+ def scheme=(scheme)
185
+ # remove :// from scheme
186
+ @scheme = scheme.sub(/:\/\//, '')
187
+ end
188
+
189
+ def host=(host)
190
+ # remove http(s):// and anything after a slash
191
+ @host = host.sub(/https?:\/\//, '').split('/').first
192
+ end
193
+
194
+ def base_path=(base_path)
195
+ # Add leading and trailing slashes to base_path
196
+ @base_path = "/#{base_path}".gsub(/\/+/, '/')
197
+ @base_path = '' if @base_path == '/'
198
+ end
199
+
200
+ def base_url(base_path)
201
+ "#{scheme}://#{[host, base_path].join('/').gsub(/\/+/, '/')}".sub(/\/+\z/, '')
202
+ end
203
+
204
+ # Gets API key (with prefix if set).
205
+ # @param [String] param_name the parameter name of API key auth
206
+ def api_key_with_prefix(param_name)
207
+ if @api_key_prefix[param_name]
208
+ "#{@api_key_prefix[param_name]} #{@api_key[param_name]}"
209
+ else
210
+ @api_key[param_name]
211
+ end
212
+ end
213
+
214
+ # Gets Basic Auth token string
215
+ def basic_auth_token
216
+ 'Basic ' + Base64.encode64("#{username}:#{password}").delete("\r\n")
217
+ end
218
+ end
219
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BancoBrasilStatements
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bb_oauth'
4
+ require "bb_statements/version"
5
+ require 'bb_statements/api_error'
6
+ require 'bb_statements/api_client'
7
+ require 'bb_statements/configuration'
8
+ require 'bb_statements/api/statements_api'
9
+
10
+ module BancoBrasilStatements
11
+ class << self
12
+ # Customize default settings for the SDK using block.
13
+ # BancoBrasilStatements.configure do |config|
14
+ # config.username = "xxx"
15
+ # config.password = "xxx"
16
+ # end
17
+ # If no block given, return the default Configuration object.
18
+ def configure
19
+ if block_given?
20
+ yield(Configuration.default)
21
+ else
22
+ Configuration.default
23
+ end
24
+ end
25
+ end
26
+ end
metadata ADDED
@@ -0,0 +1,191 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bb_statements
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Luan
8
+ - Hent
9
+ autorequire:
10
+ bindir: exe
11
+ cert_chain: []
12
+ date: 2024-05-13 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: faraday
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: 2.9.0
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: 2.9.0
28
+ - !ruby/object:Gem::Dependency
29
+ name: json
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '2.6'
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: 2.1.0
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - "~>"
43
+ - !ruby/object:Gem::Version
44
+ version: '2.6'
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 2.1.0
48
+ - !ruby/object:Gem::Dependency
49
+ name: bb_oauth
50
+ requirement: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 1.0.3
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 1.0.3
62
+ - !ruby/object:Gem::Dependency
63
+ name: rails
64
+ requirement: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 7.1.2
69
+ type: :runtime
70
+ prerelease: false
71
+ version_requirements: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 7.1.2
76
+ - !ruby/object:Gem::Dependency
77
+ name: rspec
78
+ requirement: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.6'
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: 3.6.0
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - "~>"
91
+ - !ruby/object:Gem::Version
92
+ version: '3.6'
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: 3.6.0
96
+ - !ruby/object:Gem::Dependency
97
+ name: byebug
98
+ requirement: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: 11.1.3
103
+ type: :development
104
+ prerelease: false
105
+ version_requirements: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: 11.1.3
110
+ - !ruby/object:Gem::Dependency
111
+ name: webmock
112
+ requirement: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - "~>"
115
+ - !ruby/object:Gem::Version
116
+ version: 3.22.0
117
+ type: :development
118
+ prerelease: false
119
+ version_requirements: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - "~>"
122
+ - !ruby/object:Gem::Version
123
+ version: 3.22.0
124
+ - !ruby/object:Gem::Dependency
125
+ name: activesupport
126
+ requirement: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - "~>"
129
+ - !ruby/object:Gem::Version
130
+ version: '7.1'
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: 7.1.3.2
134
+ type: :development
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - "~>"
139
+ - !ruby/object:Gem::Version
140
+ version: '7.1'
141
+ - - ">="
142
+ - !ruby/object:Gem::Version
143
+ version: 7.1.3.2
144
+ description: This gem maps to the BB Statements API
145
+ email:
146
+ - luanbritop7@gmail.com
147
+ - tech@hent.com.br
148
+ executables: []
149
+ extensions: []
150
+ extra_rdoc_files: []
151
+ files:
152
+ - ".rspec"
153
+ - ".rubocop.yml"
154
+ - CHANGELOG.md
155
+ - CODE_OF_CONDUCT.md
156
+ - LICENSE
157
+ - LICENSE.txt
158
+ - README.md
159
+ - Rakefile
160
+ - bb_statements.gemspec
161
+ - lib/bb_statements.rb
162
+ - lib/bb_statements/api/statements_api.rb
163
+ - lib/bb_statements/api_client.rb
164
+ - lib/bb_statements/api_error.rb
165
+ - lib/bb_statements/configuration.rb
166
+ - lib/bb_statements/version.rb
167
+ homepage: https://github.com/ruby-banco-brasil/bb-statement
168
+ licenses:
169
+ - MIT
170
+ metadata:
171
+ source_code_uri: https://github.com/ruby-banco-brasil/bb-statement
172
+ post_install_message:
173
+ rdoc_options: []
174
+ require_paths:
175
+ - lib
176
+ required_ruby_version: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: 2.6.0
181
+ required_rubygems_version: !ruby/object:Gem::Requirement
182
+ requirements:
183
+ - - ">="
184
+ - !ruby/object:Gem::Version
185
+ version: '0'
186
+ requirements: []
187
+ rubygems_version: 3.3.7
188
+ signing_key:
189
+ specification_version: 4
190
+ summary: A ruby wrapper for Banco do Brasil Statements
191
+ test_files: []