nubank_sdk 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/FUNDING.yml +1 -0
- data/.github/workflows/gem-push.yml +2 -2
- data/.github/workflows/quality-inspector.yml +41 -0
- data/.rubocop.yml +0 -3
- data/.travis.yml +1 -1
- data/.vscode/settings.json +2 -1
- data/Gemfile +3 -1
- data/Gemfile.lock +38 -20
- data/README.md +72 -22
- data/Rakefile +13 -8
- data/bin/console +4 -3
- data/lib/graphql/account/feed.gql +44 -0
- data/lib/nubank_sdk/account.rb +24 -1
- data/lib/nubank_sdk/api_routes.rb +8 -3
- data/lib/nubank_sdk/auth.rb +22 -24
- data/lib/nubank_sdk/certificate.rb +16 -1
- data/lib/nubank_sdk/client.rb +11 -0
- data/lib/nubank_sdk/credit.rb +18 -0
- data/lib/nubank_sdk/user.rb +9 -4
- data/lib/nubank_sdk/utils.rb +18 -0
- data/lib/nubank_sdk/version.rb +3 -1
- data/lib/nubank_sdk.rb +11 -8
- data/nubank_sdk.gemspec +26 -20
- metadata +61 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 053f6750d8819dc5c05fa23831829106314f7002357d65083f45a234a28233f0
|
4
|
+
data.tar.gz: 827596b59873ca86d556323dda076f710ee9dc19494bba206ee53cd748fa62ff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bf061fa7d6423a5c356418a5e9b2a823fa4492766e5b6bb92503bca7118cd323ce220a1042863b715a4af2297547c0539f44de35e95dd4ee1e814accbd8935df
|
7
|
+
data.tar.gz: e103553e8c83693f918437f7d4ac7ae5d9121af6f88c71b759c1b0ef9878b0be84c81a9775b770b60b64bbabd9d59be52dca2a985a225fa51829594ab3ac249f
|
data/.github/FUNDING.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
github: [Viserion77]
|
@@ -0,0 +1,41 @@
|
|
1
|
+
name: Quality Inspector
|
2
|
+
on:
|
3
|
+
push:
|
4
|
+
branches: [ "develop" ]
|
5
|
+
pull_request:
|
6
|
+
branches: [ "develop" ]
|
7
|
+
jobs:
|
8
|
+
Rspec:
|
9
|
+
runs-on: ubuntu-latest
|
10
|
+
strategy:
|
11
|
+
matrix:
|
12
|
+
ruby-version: ['3.0']
|
13
|
+
|
14
|
+
steps:
|
15
|
+
- uses: actions/checkout@v3
|
16
|
+
- name: Set up Ruby
|
17
|
+
uses: ruby/setup-ruby@ee2113536afb7f793eed4ce60e8d3b26db912da4 # v1.127.0
|
18
|
+
with:
|
19
|
+
ruby-version: ${{ matrix.ruby-version }}
|
20
|
+
bundler-cache: true
|
21
|
+
- name: Run tests
|
22
|
+
run: bundle exec rspec
|
23
|
+
- uses: joshmfrankel/simplecov-check-action@main
|
24
|
+
with:
|
25
|
+
github_token: ${{ secrets.GITHUB_TOKEN }}
|
26
|
+
|
27
|
+
Rubocop:
|
28
|
+
runs-on: ubuntu-latest
|
29
|
+
strategy:
|
30
|
+
matrix:
|
31
|
+
ruby-version: ['3.0']
|
32
|
+
|
33
|
+
steps:
|
34
|
+
- uses: actions/checkout@v3
|
35
|
+
- name: Set up Ruby
|
36
|
+
uses: ruby/setup-ruby@ee2113536afb7f793eed4ce60e8d3b26db912da4 # v1.127.0
|
37
|
+
with:
|
38
|
+
ruby-version: ${{ matrix.ruby-version }}
|
39
|
+
bundler-cache: true
|
40
|
+
- name: Run rubocop
|
41
|
+
run: bundle exec rubocop --format=g
|
data/.rubocop.yml
CHANGED
data/.travis.yml
CHANGED
data/.vscode/settings.json
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
nubank_sdk (0.
|
4
|
+
nubank_sdk (0.7.0)
|
5
5
|
faraday (~> 2.7.1)
|
6
6
|
json (~> 2.3)
|
7
7
|
|
@@ -16,23 +16,25 @@ GEM
|
|
16
16
|
ast (2.4.2)
|
17
17
|
concurrent-ruby (1.1.10)
|
18
18
|
diff-lcs (1.5.0)
|
19
|
+
docile (1.4.0)
|
19
20
|
factory_bot (4.8.2)
|
20
21
|
activesupport (>= 3.0.0)
|
21
|
-
faraday (2.7.
|
22
|
+
faraday (2.7.2)
|
22
23
|
faraday-net_http (>= 2.0, < 3.1)
|
23
24
|
ruby2_keywords (>= 0.0.4)
|
24
25
|
faraday-net_http (3.0.2)
|
26
|
+
gem-release (2.2.2)
|
25
27
|
i18n (1.12.0)
|
26
28
|
concurrent-ruby (~> 1.0)
|
27
|
-
jaro_winkler (1.5.4)
|
28
29
|
json (2.6.2)
|
29
30
|
minitest (5.15.0)
|
30
|
-
parallel (1.
|
31
|
-
parser (3.1.
|
31
|
+
parallel (1.22.1)
|
32
|
+
parser (3.1.3.0)
|
32
33
|
ast (~> 2.4.1)
|
33
|
-
powerpack (0.1.3)
|
34
34
|
rainbow (3.1.1)
|
35
|
-
rake (
|
35
|
+
rake (13.0.6)
|
36
|
+
regexp_parser (2.6.1)
|
37
|
+
rexml (3.2.5)
|
36
38
|
rspec (3.11.0)
|
37
39
|
rspec-core (~> 3.11.0)
|
38
40
|
rspec-expectations (~> 3.11.0)
|
@@ -46,22 +48,35 @@ GEM
|
|
46
48
|
diff-lcs (>= 1.2.0, < 2.0)
|
47
49
|
rspec-support (~> 3.11.0)
|
48
50
|
rspec-support (3.11.1)
|
49
|
-
rubocop (
|
50
|
-
|
51
|
+
rubocop (1.41.0)
|
52
|
+
json (~> 2.3)
|
51
53
|
parallel (~> 1.10)
|
52
|
-
parser (>= 2.
|
53
|
-
powerpack (~> 0.1)
|
54
|
+
parser (>= 3.1.2.1)
|
54
55
|
rainbow (>= 2.2.2, < 4.0)
|
56
|
+
regexp_parser (>= 1.8, < 3.0)
|
57
|
+
rexml (>= 3.2.5, < 4.0)
|
58
|
+
rubocop-ast (>= 1.23.0, < 2.0)
|
55
59
|
ruby-progressbar (~> 1.7)
|
56
|
-
unicode-display_width (
|
57
|
-
rubocop-
|
58
|
-
|
60
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
61
|
+
rubocop-ast (1.24.0)
|
62
|
+
parser (>= 3.1.1.0)
|
63
|
+
rubocop-rspec (2.16.0)
|
64
|
+
rubocop (~> 1.33)
|
59
65
|
ruby-progressbar (1.11.0)
|
60
66
|
ruby2_keywords (0.0.5)
|
67
|
+
simplecov (0.21.2)
|
68
|
+
docile (~> 1.1)
|
69
|
+
simplecov-html (~> 0.11)
|
70
|
+
simplecov_json_formatter (~> 0.1)
|
71
|
+
simplecov-html (0.12.3)
|
72
|
+
simplecov-json (0.2.3)
|
73
|
+
json
|
74
|
+
simplecov
|
75
|
+
simplecov_json_formatter (0.1.4)
|
61
76
|
thread_safe (0.3.6)
|
62
77
|
tzinfo (1.2.10)
|
63
78
|
thread_safe (~> 0.1)
|
64
|
-
unicode-display_width (
|
79
|
+
unicode-display_width (2.3.0)
|
65
80
|
webrick (1.7.0)
|
66
81
|
yard (0.9.28)
|
67
82
|
webrick (~> 1.7.0)
|
@@ -70,14 +85,17 @@ PLATFORMS
|
|
70
85
|
ruby
|
71
86
|
|
72
87
|
DEPENDENCIES
|
73
|
-
bundler (~>
|
88
|
+
bundler (~> 2.3.26)
|
74
89
|
factory_bot (~> 4.8.2)
|
90
|
+
gem-release (~> 2.2.2)
|
75
91
|
nubank_sdk!
|
76
|
-
rake (~>
|
92
|
+
rake (~> 13.0)
|
77
93
|
rspec (~> 3.0)
|
78
|
-
rubocop (~>
|
79
|
-
rubocop-rspec (~>
|
94
|
+
rubocop (~> 1.41.0)
|
95
|
+
rubocop-rspec (~> 2.16.0)
|
96
|
+
simplecov (~> 0.21.2)
|
97
|
+
simplecov-json (~> 0.2.3)
|
80
98
|
yard (~> 0.9.12)
|
81
99
|
|
82
100
|
BUNDLED WITH
|
83
|
-
|
101
|
+
2.3.26
|
data/README.md
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
|
1
|
+
# NubankSdk
|
2
2
|
|
3
|
-
|
3
|
+
[![Version](https://img.shields.io/gem/v/nubank_sdk?color=%23701516&logo=ruby&logoColor=%23701516&style=for-the-badge)](https://rubygems.org/gems/nubank_sdk)
|
4
|
+
[![Downloads](https://img.shields.io/gem/dt/nubank_sdk?color=%23701516&logo=ruby&logoColor=%23701516&style=for-the-badge)](https://rubygems.org/gems/nubank_sdk)
|
5
|
+
[![Quality Inspector](https://github.com/Viserion77/nubank_sdk/actions/workflows/quality-inspector.yml/badge.svg?branch=develop&&event=push)](https://github.com/Viserion77/nubank_sdk/actions/workflows/quality-inspector.yml?branch=develop)
|
4
6
|
|
5
7
|
A gem to make it ease to monitorize your Nubank account.
|
6
8
|
|
7
|
-
<!-- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/nubank_sdk`. To experiment with that code, run `bin/console` for an interactive prompt. -->
|
8
|
-
|
9
9
|
## Installation
|
10
10
|
|
11
11
|
Add this line to your application's Gemfile:
|
@@ -16,11 +16,15 @@ gem 'nubank_sdk'
|
|
16
16
|
|
17
17
|
And then execute:
|
18
18
|
|
19
|
-
|
19
|
+
```shell
|
20
|
+
bundle
|
21
|
+
```
|
20
22
|
|
21
23
|
Or install it yourself as:
|
22
24
|
|
23
|
-
|
25
|
+
```shell
|
26
|
+
gem install nubank_sdk
|
27
|
+
```
|
24
28
|
|
25
29
|
## Usage
|
26
30
|
|
@@ -28,13 +32,11 @@ Or install it yourself as:
|
|
28
32
|
require 'nubank_sdk'
|
29
33
|
|
30
34
|
# instance a nubank account object
|
31
|
-
user = NubankSdk::User.new
|
35
|
+
user = NubankSdk::User.new cpf: '12345678909'
|
32
36
|
password = 'dracarys'
|
33
37
|
```
|
34
38
|
|
35
|
-
> First time?
|
36
|
-
>
|
37
|
-
> authenticate the account
|
39
|
+
> First time? authenticate the account!
|
38
40
|
>
|
39
41
|
> ```ruby
|
40
42
|
> # request an email code
|
@@ -46,27 +48,75 @@ password = 'dracarys'
|
|
46
48
|
> user.auth.exchange_certs(email_code, password)
|
47
49
|
> ```
|
48
50
|
>
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
>
|
55
|
-
> ```ruby
|
56
|
-
> user.auth.authenticate_with_certificate(password)
|
57
|
-
> ```
|
51
|
+
|
52
|
+
Has a certificate? generate a access token :D
|
53
|
+
```ruby
|
54
|
+
user.auth.authenticate_with_certificate(password)
|
55
|
+
```
|
58
56
|
|
59
57
|
get the account balance
|
60
58
|
|
61
59
|
```ruby
|
62
|
-
user.account.balance # => 77.0
|
60
|
+
account_balance = user.account.balance # => 77.0
|
63
61
|
```
|
64
62
|
|
65
63
|
## Development
|
66
64
|
|
67
|
-
|
65
|
+
> <details>
|
66
|
+
>
|
67
|
+
> <summary>Prerequisites</summary>
|
68
|
+
>
|
69
|
+
> - Ruby 2.7.2
|
70
|
+
> - Bundler
|
71
|
+
> - git
|
72
|
+
>
|
73
|
+
> Clone the repository:
|
74
|
+
> ```shell
|
75
|
+
> git clone https://github.com/viserion77/nubank_sdk.git
|
76
|
+
> ```
|
77
|
+
>
|
78
|
+
> Install the dependencies:
|
79
|
+
> ```shell
|
80
|
+
> bundle install
|
81
|
+
> ```
|
82
|
+
>
|
83
|
+
> </details>
|
84
|
+
|
85
|
+
- Create a new branch for your feature or bugfix
|
86
|
+
- Commit your changes, and push your branch to GitHub
|
87
|
+
- Open a Pull Request to the `develop` branch
|
88
|
+
- Write a description for your PR, and how to test it!
|
89
|
+
- Wait for the CI to run the tests and check the code quality
|
90
|
+
- If everything is ok, your PR will be merged
|
91
|
+
|
92
|
+
## Deployment
|
68
93
|
|
69
|
-
|
94
|
+
> <details>
|
95
|
+
>
|
96
|
+
> <summary>Prerequisites</summary>
|
97
|
+
>
|
98
|
+
> - Ruby 2.7.2
|
99
|
+
> - Bundler
|
100
|
+
> - git
|
101
|
+
>
|
102
|
+
> Clone the repository:
|
103
|
+
> ```shell
|
104
|
+
> git clone https://github.com/viserion77/nubank_sdk.git
|
105
|
+
> ```
|
106
|
+
>
|
107
|
+
> Install the dependencies:
|
108
|
+
> ```shell
|
109
|
+
> bundle install
|
110
|
+
> ```
|
111
|
+
>
|
112
|
+
> </details>
|
113
|
+
|
114
|
+
- Create a new branch from `develop` for bumping the version
|
115
|
+
- run `bundle exec rake start_new_release` to bump the version and a new tag
|
116
|
+
- Open a Pull Request to the `main` branch
|
117
|
+
- If everything is ok, your PR will be merged
|
118
|
+
- After the merge, the CI will publish the new version to rubygems.org
|
119
|
+
- If all goes well, you need release the new tag to GitHub. ([tags](https://github.com/Viserion77/nubank_sdk/tags))
|
70
120
|
|
71
121
|
## Contributing
|
72
122
|
|
data/Rakefile
CHANGED
@@ -1,26 +1,31 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'bundler/gem_tasks'
|
4
|
+
require 'rspec/core/rake_task'
|
3
5
|
|
4
6
|
RSpec::Core::RakeTask.new(:spec)
|
5
7
|
Bundler::GemHelper.install_tasks
|
6
8
|
|
7
|
-
task :
|
9
|
+
task default: :spec
|
8
10
|
|
9
11
|
task :start_new_release do
|
10
12
|
bump = ENV['BUMP'] || 'patch'
|
11
13
|
|
12
|
-
sh 'gem install gem-release'
|
13
14
|
sh "gem bump --version #{bump}"
|
14
|
-
|
15
|
+
|
15
16
|
sh 'bundle'
|
16
17
|
Rake::Task[:build].invoke
|
17
|
-
|
18
|
+
|
18
19
|
sh 'git add .'
|
19
|
-
sh "git commit -m \"build(version): :bookmark: bump #{bump}\""
|
20
|
+
sh "git commit -m \"build(version): :bookmark: bump #{bump}\""
|
20
21
|
sh 'git push'
|
21
22
|
|
23
|
+
Rake::Task[:generate_git_tag].invoke
|
24
|
+
end
|
25
|
+
|
26
|
+
task :generate_git_tag do
|
22
27
|
version = NubankSdk::VERSION
|
23
28
|
version_tag = "v#{version}"
|
24
29
|
sh "git tag -a #{version_tag} -m \"Version #{version}\""
|
25
30
|
sh 'git push --tags'
|
26
|
-
end
|
31
|
+
end
|
data/bin/console
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
|
-
require
|
4
|
-
require
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'nubank_sdk'
|
5
6
|
|
6
7
|
# You can add fixtures and/or initialization code here to make experimenting
|
7
8
|
# with your gem easier. You can also use a different console, if you like.
|
@@ -10,5 +11,5 @@ require "nubank_sdk"
|
|
10
11
|
# require "pry"
|
11
12
|
# Pry.start
|
12
13
|
|
13
|
-
require
|
14
|
+
require 'irb'
|
14
15
|
IRB.start(__FILE__)
|
@@ -0,0 +1,44 @@
|
|
1
|
+
{
|
2
|
+
viewer {
|
3
|
+
savingsAccount {
|
4
|
+
id
|
5
|
+
feed {
|
6
|
+
id
|
7
|
+
__typename
|
8
|
+
title
|
9
|
+
detail
|
10
|
+
postDate
|
11
|
+
... on TransferInEvent {
|
12
|
+
amount
|
13
|
+
originAccount {
|
14
|
+
name
|
15
|
+
}
|
16
|
+
}
|
17
|
+
... on TransferOutEvent {
|
18
|
+
amount
|
19
|
+
destinationAccount {
|
20
|
+
name
|
21
|
+
}
|
22
|
+
}
|
23
|
+
... on TransferOutReversalEvent {
|
24
|
+
amount
|
25
|
+
}
|
26
|
+
... on BillPaymentEvent {
|
27
|
+
amount
|
28
|
+
}
|
29
|
+
... on DebitPurchaseEvent {
|
30
|
+
amount
|
31
|
+
}
|
32
|
+
... on BarcodePaymentEvent {
|
33
|
+
amount
|
34
|
+
}
|
35
|
+
... on DebitWithdrawalFeeEvent {
|
36
|
+
amount
|
37
|
+
}
|
38
|
+
... on DebitWithdrawalEvent {
|
39
|
+
amount
|
40
|
+
}
|
41
|
+
}
|
42
|
+
}
|
43
|
+
}
|
44
|
+
}
|
data/lib/nubank_sdk/account.rb
CHANGED
@@ -1,4 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module NubankSdk
|
4
|
+
#
|
5
|
+
# Returns the account statement
|
6
|
+
#
|
2
7
|
class Account
|
3
8
|
#
|
4
9
|
# Returns the account statement
|
@@ -24,8 +29,26 @@ module NubankSdk
|
|
24
29
|
}
|
25
30
|
)
|
26
31
|
|
27
|
-
data =
|
32
|
+
data = Client.get_body(response)
|
28
33
|
data[:data][:viewer][:savingsAccount][:currentSavingsBalance][:netAmount]
|
29
34
|
end
|
35
|
+
|
36
|
+
#
|
37
|
+
# Returns the account feed
|
38
|
+
#
|
39
|
+
# @return [Array<Hash>]
|
40
|
+
def feed
|
41
|
+
query_url = @api_routes.entrypoint(path: :ssl, entrypoint: :query)
|
42
|
+
|
43
|
+
response = @connection.post(
|
44
|
+
query_url, {
|
45
|
+
'variables': {},
|
46
|
+
'query': Utils.read_graphql_query('account', 'feed')
|
47
|
+
}
|
48
|
+
)
|
49
|
+
|
50
|
+
data = Client.get_body(response)
|
51
|
+
data[:data][:viewer][:savingsAccount][:feed]
|
52
|
+
end
|
30
53
|
end
|
31
54
|
end
|
@@ -1,9 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'faraday'
|
2
4
|
require 'json'
|
3
5
|
|
4
6
|
module NubankSdk
|
7
|
+
#
|
8
|
+
# Controller for the ApiRoutes class
|
9
|
+
#
|
5
10
|
class ApiRoutes
|
6
|
-
DISCOVERY_URI = 'https://prod-s0-webapp-proxy.nubank.com.br'
|
11
|
+
DISCOVERY_URI = 'https://prod-s0-webapp-proxy.nubank.com.br'
|
7
12
|
PROXY_PATHS = {
|
8
13
|
default: '/api/discovery',
|
9
14
|
app: '/api/app/discovery',
|
@@ -28,7 +33,7 @@ module NubankSdk
|
|
28
33
|
# @param [Symbol] type, :splitted or :full
|
29
34
|
#
|
30
35
|
# @return [String, Array]
|
31
|
-
def entrypoint(path: :default,
|
36
|
+
def entrypoint(entrypoint:, path: :default, type: :full)
|
32
37
|
discovery(path) if @url_discovery_map[path].nil?
|
33
38
|
|
34
39
|
url = @url_discovery_map[path][entrypoint]
|
@@ -47,7 +52,7 @@ module NubankSdk
|
|
47
52
|
# @param [String] url
|
48
53
|
#
|
49
54
|
# @return [Hash]
|
50
|
-
def add_entrypoint(path: :default
|
55
|
+
def add_entrypoint(entrypoint:, url:, path: :default)
|
51
56
|
path_map = @url_discovery_map[path] || {}
|
52
57
|
path_map[entrypoint] = url
|
53
58
|
|
data/lib/nubank_sdk/auth.rb
CHANGED
@@ -1,6 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'securerandom'
|
2
4
|
|
3
5
|
module NubankSdk
|
6
|
+
#
|
7
|
+
# Auth method to connect with the nubank api
|
8
|
+
#
|
4
9
|
class Auth
|
5
10
|
attr_reader :refresh_token, :refresh_before, :access_token
|
6
11
|
|
@@ -14,7 +19,7 @@ module NubankSdk
|
|
14
19
|
def initialize(cpf:, device_id: nil, api_routes: nil, connection_adapter: nil)
|
15
20
|
@cpf = cpf
|
16
21
|
@device_id = device_id || generate_device_id
|
17
|
-
@api_routes = api_routes ||
|
22
|
+
@api_routes = api_routes || ApiRoutes.new
|
18
23
|
|
19
24
|
@connection_adapter = connection_adapter
|
20
25
|
end
|
@@ -24,7 +29,7 @@ module NubankSdk
|
|
24
29
|
#
|
25
30
|
# @return [NubankSdk::Certificate] the certificate instance
|
26
31
|
def certificate
|
27
|
-
@certificate ||=
|
32
|
+
@certificate ||= Certificate.new(@cpf)
|
28
33
|
end
|
29
34
|
|
30
35
|
#
|
@@ -39,9 +44,8 @@ module NubankSdk
|
|
39
44
|
|
40
45
|
response_hash = Client.get_body(response)
|
41
46
|
|
42
|
-
@refresh_token = response_hash
|
43
|
-
|
44
|
-
@access_token = response_hash[:access_token]
|
47
|
+
@refresh_token, @refresh_before, @access_token = response_hash.values_at(:refresh_token, :refresh_before,
|
48
|
+
:access_token)
|
45
49
|
|
46
50
|
update_api_routes(response_hash[:_links])
|
47
51
|
end
|
@@ -66,11 +70,9 @@ module NubankSdk
|
|
66
70
|
#
|
67
71
|
# @return [File] the certificate file
|
68
72
|
def exchange_certs(email_code, password)
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
})
|
73
|
-
)
|
73
|
+
new_payload = payload(password)
|
74
|
+
.merge({ code: email_code, 'encrypted-code': @encrypted_code })
|
75
|
+
response = default_connection.post(@gen_certificate_path, new_payload)
|
74
76
|
|
75
77
|
response_data = Client.get_body(response)
|
76
78
|
certificate.process_decoded(key, response_data[:certificate])
|
@@ -89,12 +91,12 @@ module NubankSdk
|
|
89
91
|
parsed = {}
|
90
92
|
|
91
93
|
chunks.each do |chunk|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
94
|
+
key, value = chunk.split('=')
|
95
|
+
key = key.strip.gsub(' ', '_').gsub('-', '_').to_sym
|
96
|
+
value = value.gsub('"', '')
|
97
|
+
parsed[key] = value
|
96
98
|
end
|
97
|
-
|
99
|
+
|
98
100
|
parsed
|
99
101
|
end
|
100
102
|
|
@@ -110,7 +112,7 @@ module NubankSdk
|
|
110
112
|
password: password,
|
111
113
|
public_key: key.public_key.to_pem,
|
112
114
|
device_id: @device_id,
|
113
|
-
model: "NubankSdk Client (
|
115
|
+
model: "NubankSdk Client (#{@device_id})"
|
114
116
|
}
|
115
117
|
end
|
116
118
|
|
@@ -145,16 +147,12 @@ module NubankSdk
|
|
145
147
|
#
|
146
148
|
# @return [NubankSdk::ApiRoutes] the api routes with the new links
|
147
149
|
def update_api_routes(links)
|
148
|
-
feed_url_keys = [:events, :magnitude]
|
149
|
-
bills_url_keys = [:bills_summary]
|
150
|
-
customer_url_keys = [:customer]
|
151
|
-
account_url_keys = [:account]
|
152
150
|
@api_routes.add_entrypoint(path: :ssl, entrypoint: :revoke_token, url: links[:revoke_token][:href])
|
153
151
|
@api_routes.add_entrypoint(path: :ssl, entrypoint: :query, url: links[:ghostflame][:href])
|
154
|
-
@api_routes.add_entrypoint(path: :ssl, entrypoint: :feed, url: find_url(
|
155
|
-
@api_routes.add_entrypoint(path: :ssl, entrypoint: :bills, url: find_url(
|
156
|
-
@api_routes.add_entrypoint(path: :ssl, entrypoint: :customer, url: find_url(
|
157
|
-
@api_routes.add_entrypoint(path: :ssl, entrypoint: :account, url: find_url(
|
152
|
+
@api_routes.add_entrypoint(path: :ssl, entrypoint: :feed, url: find_url(%i[events magnitude], links))
|
153
|
+
@api_routes.add_entrypoint(path: :ssl, entrypoint: :bills, url: find_url([:bills_summary], links))
|
154
|
+
@api_routes.add_entrypoint(path: :ssl, entrypoint: :customer, url: find_url([:customer], links))
|
155
|
+
@api_routes.add_entrypoint(path: :ssl, entrypoint: :account, url: find_url([:account], links))
|
158
156
|
@api_routes
|
159
157
|
end
|
160
158
|
|
@@ -1,8 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'openssl'
|
2
4
|
|
3
5
|
module NubankSdk
|
6
|
+
#
|
7
|
+
# Controller of certifications
|
8
|
+
#
|
4
9
|
class Certificate
|
5
|
-
FILES_PATH = './certificates/'
|
10
|
+
FILES_PATH = './certificates/'
|
6
11
|
|
7
12
|
#
|
8
13
|
# Controller of certifications
|
@@ -51,11 +56,21 @@ module NubankSdk
|
|
51
56
|
#
|
52
57
|
# @return [File]
|
53
58
|
def save(p12)
|
59
|
+
create_folder
|
60
|
+
|
54
61
|
File.open("#{FILES_PATH}#{@cpf}.p12", 'wb') do |file|
|
55
62
|
file.write p12.to_der
|
56
63
|
end
|
57
64
|
end
|
58
65
|
|
66
|
+
# @!visibility private
|
67
|
+
# Create certificates folder
|
68
|
+
#
|
69
|
+
# @return [File]
|
70
|
+
def create_folder
|
71
|
+
Dir.mkdir(FILES_PATH) unless Dir.exist?(FILES_PATH)
|
72
|
+
end
|
73
|
+
|
59
74
|
# @!visibility private
|
60
75
|
# crypt key and certificate to pkcs12
|
61
76
|
#
|
data/lib/nubank_sdk/client.rb
CHANGED
@@ -1,7 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'faraday'
|
2
4
|
require 'json'
|
3
5
|
|
4
6
|
module NubankSdk
|
7
|
+
#
|
8
|
+
# Wrapper for Faraday::Connection
|
9
|
+
#
|
5
10
|
module Client
|
6
11
|
#
|
7
12
|
# Parse the response body symbolizing keys
|
@@ -13,6 +18,9 @@ module NubankSdk
|
|
13
18
|
JSON.parse(response.body, symbolize_names: true)
|
14
19
|
end
|
15
20
|
|
21
|
+
#
|
22
|
+
# create a new connection with the given url in Faraday
|
23
|
+
#
|
16
24
|
class HTTP
|
17
25
|
#
|
18
26
|
# create a new connection with the given url in Faraday
|
@@ -51,6 +59,9 @@ module NubankSdk
|
|
51
59
|
end
|
52
60
|
end
|
53
61
|
|
62
|
+
#
|
63
|
+
# Create a new instance of Faraday::Connection with client certificate
|
64
|
+
#
|
54
65
|
class HTTPS
|
55
66
|
attr_accessor :headers
|
56
67
|
|
data/lib/nubank_sdk/credit.rb
CHANGED
@@ -1,4 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module NubankSdk
|
4
|
+
#
|
5
|
+
# Returns the credit statement
|
6
|
+
#
|
2
7
|
class Credit
|
3
8
|
#
|
4
9
|
# Returns the credit statement
|
@@ -22,5 +27,18 @@ module NubankSdk
|
|
22
27
|
|
23
28
|
response_hash[:account][:balances]
|
24
29
|
end
|
30
|
+
|
31
|
+
#
|
32
|
+
# Returns the credit feed
|
33
|
+
#
|
34
|
+
# @return [Array<Hash>] the credit feed
|
35
|
+
def feed
|
36
|
+
feed_url = @api_routes.entrypoint(path: :ssl, entrypoint: :feed)
|
37
|
+
|
38
|
+
response = @connection.get(feed_url)
|
39
|
+
|
40
|
+
data = Client.get_body(response)
|
41
|
+
data[:events]
|
42
|
+
end
|
25
43
|
end
|
26
44
|
end
|
data/lib/nubank_sdk/user.rb
CHANGED
@@ -1,4 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module NubankSdk
|
4
|
+
#
|
5
|
+
# Controller of user actions in nubank
|
6
|
+
#
|
2
7
|
class User
|
3
8
|
#
|
4
9
|
# Controller of user actions in nubank
|
@@ -15,7 +20,7 @@ module NubankSdk
|
|
15
20
|
#
|
16
21
|
# @return [NubankSdk::Auth]
|
17
22
|
def auth
|
18
|
-
@auth ||=
|
23
|
+
@auth ||= Auth.new(
|
19
24
|
cpf: @cpf,
|
20
25
|
api_routes: api_routes,
|
21
26
|
connection_adapter: @connection_adapter
|
@@ -27,7 +32,7 @@ module NubankSdk
|
|
27
32
|
#
|
28
33
|
# @return [NubankSdk::Account]
|
29
34
|
def account
|
30
|
-
@account ||=
|
35
|
+
@account ||= Account.new(connection: connection, api_routes: api_routes)
|
31
36
|
end
|
32
37
|
|
33
38
|
#
|
@@ -35,7 +40,7 @@ module NubankSdk
|
|
35
40
|
#
|
36
41
|
# @return [NubankSdk::Credit]
|
37
42
|
def credit
|
38
|
-
@credit ||=
|
43
|
+
@credit ||= Credit.new(connection: connection, api_routes: api_routes)
|
39
44
|
end
|
40
45
|
|
41
46
|
#
|
@@ -43,7 +48,7 @@ module NubankSdk
|
|
43
48
|
#
|
44
49
|
# @return [NubankSdk::ApiRoutes]
|
45
50
|
def api_routes
|
46
|
-
@api_routes ||=
|
51
|
+
@api_routes ||= ApiRoutes.new
|
47
52
|
end
|
48
53
|
|
49
54
|
private
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module NubankSdk
|
4
|
+
#
|
5
|
+
# Utils
|
6
|
+
module Utils
|
7
|
+
#
|
8
|
+
# read graphQL query from file in ../graphql/{path}/{query}.gql
|
9
|
+
#
|
10
|
+
# @param [String] path - path to the query account, credit
|
11
|
+
# @param [String] query - query name
|
12
|
+
#
|
13
|
+
# @return [String]
|
14
|
+
def self.read_graphql_query(path, query)
|
15
|
+
File.read(File.join('.', 'lib', 'graphql', path, "#{query}.gql"))
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/nubank_sdk/version.rb
CHANGED
data/lib/nubank_sdk.rb
CHANGED
@@ -1,11 +1,14 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'nubank_sdk/account'
|
4
|
+
require 'nubank_sdk/api_routes'
|
5
|
+
require 'nubank_sdk/auth'
|
6
|
+
require 'nubank_sdk/certificate'
|
7
|
+
require 'nubank_sdk/credit'
|
8
|
+
require 'nubank_sdk/client'
|
9
|
+
require 'nubank_sdk/user'
|
10
|
+
require 'nubank_sdk/version'
|
11
|
+
require 'nubank_sdk/utils'
|
9
12
|
|
10
13
|
module NubankSdk
|
11
14
|
class Error < StandardError; end
|
data/nubank_sdk.gemspec
CHANGED
@@ -1,34 +1,40 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
2
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
-
require
|
5
|
+
require 'nubank_sdk/version'
|
4
6
|
|
5
7
|
Gem::Specification.new do |spec|
|
6
|
-
spec.name =
|
8
|
+
spec.name = 'nubank_sdk'
|
7
9
|
spec.version = NubankSdk::VERSION
|
8
|
-
spec.authors = [
|
9
|
-
spec.email = [
|
10
|
+
spec.authors = ['Viserion77']
|
11
|
+
spec.email = ['jeferson.a.oficial@gmail.com']
|
10
12
|
|
11
|
-
spec.summary =
|
12
|
-
spec.description =
|
13
|
-
spec.homepage =
|
13
|
+
spec.summary = 'A gem to make it ease to monitorize your Nubank account.'
|
14
|
+
spec.description = 'Monitorize balances, recent transactions, credit limit etc...'
|
15
|
+
spec.homepage = 'https://github.com/Viserion77/nubank_sdk'
|
16
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 2.7.0')
|
14
17
|
|
15
18
|
# Specify which files should be added to the gem when it is released.
|
16
19
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
17
|
-
spec.files
|
20
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
18
21
|
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
19
22
|
end
|
20
|
-
spec.bindir =
|
23
|
+
spec.bindir = 'exe'
|
21
24
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
-
spec.require_paths = [
|
25
|
+
spec.require_paths = ['lib']
|
23
26
|
|
24
|
-
spec.add_development_dependency
|
25
|
-
spec.add_development_dependency
|
26
|
-
spec.add_development_dependency
|
27
|
-
spec.add_development_dependency
|
28
|
-
spec.add_development_dependency
|
29
|
-
spec.add_development_dependency
|
30
|
-
spec.add_development_dependency
|
27
|
+
spec.add_development_dependency 'bundler', '~> 2.3.26'
|
28
|
+
spec.add_development_dependency 'factory_bot', '~> 4.8.2'
|
29
|
+
spec.add_development_dependency 'gem-release', '~> 2.2.2'
|
30
|
+
spec.add_development_dependency 'rake', '~> 13.0'
|
31
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
32
|
+
spec.add_development_dependency 'rubocop', '~> 1.41.0'
|
33
|
+
spec.add_development_dependency 'rubocop-rspec', '~> 2.16.0'
|
34
|
+
spec.add_development_dependency 'simplecov', '~> 0.21.2'
|
35
|
+
spec.add_development_dependency 'simplecov-json', '~> 0.2.3'
|
36
|
+
spec.add_development_dependency 'yard', '~> 0.9.12'
|
31
37
|
|
32
|
-
spec.add_dependency
|
33
|
-
spec.add_dependency
|
38
|
+
spec.add_dependency 'faraday', '~> 2.7.1'
|
39
|
+
spec.add_dependency 'json', '~> 2.3'
|
34
40
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nubank_sdk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Viserion77
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-01-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -16,28 +16,56 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 2.3.26
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 2.3.26
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: factory_bot
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 4.8.2
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 4.8.2
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: gem-release
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 2.2.2
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 2.2.2
|
27
55
|
- !ruby/object:Gem::Dependency
|
28
56
|
name: rake
|
29
57
|
requirement: !ruby/object:Gem::Requirement
|
30
58
|
requirements:
|
31
59
|
- - "~>"
|
32
60
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
61
|
+
version: '13.0'
|
34
62
|
type: :development
|
35
63
|
prerelease: false
|
36
64
|
version_requirements: !ruby/object:Gem::Requirement
|
37
65
|
requirements:
|
38
66
|
- - "~>"
|
39
67
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
68
|
+
version: '13.0'
|
41
69
|
- !ruby/object:Gem::Dependency
|
42
70
|
name: rspec
|
43
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -58,42 +86,56 @@ dependencies:
|
|
58
86
|
requirements:
|
59
87
|
- - "~>"
|
60
88
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
89
|
+
version: 1.41.0
|
62
90
|
type: :development
|
63
91
|
prerelease: false
|
64
92
|
version_requirements: !ruby/object:Gem::Requirement
|
65
93
|
requirements:
|
66
94
|
- - "~>"
|
67
95
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
96
|
+
version: 1.41.0
|
69
97
|
- !ruby/object:Gem::Dependency
|
70
98
|
name: rubocop-rspec
|
71
99
|
requirement: !ruby/object:Gem::Requirement
|
72
100
|
requirements:
|
73
101
|
- - "~>"
|
74
102
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
103
|
+
version: 2.16.0
|
76
104
|
type: :development
|
77
105
|
prerelease: false
|
78
106
|
version_requirements: !ruby/object:Gem::Requirement
|
79
107
|
requirements:
|
80
108
|
- - "~>"
|
81
109
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
110
|
+
version: 2.16.0
|
83
111
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
112
|
+
name: simplecov
|
85
113
|
requirement: !ruby/object:Gem::Requirement
|
86
114
|
requirements:
|
87
115
|
- - "~>"
|
88
116
|
- !ruby/object:Gem::Version
|
89
|
-
version:
|
117
|
+
version: 0.21.2
|
90
118
|
type: :development
|
91
119
|
prerelease: false
|
92
120
|
version_requirements: !ruby/object:Gem::Requirement
|
93
121
|
requirements:
|
94
122
|
- - "~>"
|
95
123
|
- !ruby/object:Gem::Version
|
96
|
-
version:
|
124
|
+
version: 0.21.2
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: simplecov-json
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 0.2.3
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: 0.2.3
|
97
139
|
- !ruby/object:Gem::Dependency
|
98
140
|
name: yard
|
99
141
|
requirement: !ruby/object:Gem::Requirement
|
@@ -143,7 +185,9 @@ executables: []
|
|
143
185
|
extensions: []
|
144
186
|
extra_rdoc_files: []
|
145
187
|
files:
|
188
|
+
- ".github/FUNDING.yml"
|
146
189
|
- ".github/workflows/gem-push.yml"
|
190
|
+
- ".github/workflows/quality-inspector.yml"
|
147
191
|
- ".gitignore"
|
148
192
|
- ".rspec"
|
149
193
|
- ".rubocop.yml"
|
@@ -157,6 +201,7 @@ files:
|
|
157
201
|
- bin/console
|
158
202
|
- bin/setup
|
159
203
|
- certificates/.gitkeep
|
204
|
+
- lib/graphql/account/feed.gql
|
160
205
|
- lib/nubank_sdk.rb
|
161
206
|
- lib/nubank_sdk/account.rb
|
162
207
|
- lib/nubank_sdk/api_routes.rb
|
@@ -165,6 +210,7 @@ files:
|
|
165
210
|
- lib/nubank_sdk/client.rb
|
166
211
|
- lib/nubank_sdk/credit.rb
|
167
212
|
- lib/nubank_sdk/user.rb
|
213
|
+
- lib/nubank_sdk/utils.rb
|
168
214
|
- lib/nubank_sdk/version.rb
|
169
215
|
- nubank_sdk.gemspec
|
170
216
|
homepage: https://github.com/Viserion77/nubank_sdk
|
@@ -178,14 +224,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
178
224
|
requirements:
|
179
225
|
- - ">="
|
180
226
|
- !ruby/object:Gem::Version
|
181
|
-
version:
|
227
|
+
version: 2.7.0
|
182
228
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
183
229
|
requirements:
|
184
230
|
- - ">="
|
185
231
|
- !ruby/object:Gem::Version
|
186
232
|
version: '0'
|
187
233
|
requirements: []
|
188
|
-
rubygems_version: 3.
|
234
|
+
rubygems_version: 3.3.26
|
189
235
|
signing_key:
|
190
236
|
specification_version: 4
|
191
237
|
summary: A gem to make it ease to monitorize your Nubank account.
|