bunq_rb 0.0.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.rubocop.yml +49 -0
- data/.travis.yml +13 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +21 -0
- data/LICENSE.txt +21 -0
- data/README.md +221 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/bunq_rb.gemspec +37 -0
- data/lib/bunq_rb/client/headers.rb +12 -0
- data/lib/bunq_rb/client/sign_request.rb +64 -0
- data/lib/bunq_rb/client.rb +77 -0
- data/lib/bunq_rb/configuration.rb +14 -0
- data/lib/bunq_rb/objects/attachment_monetary_account.rb +19 -0
- data/lib/bunq_rb/objects/device.rb +18 -0
- data/lib/bunq_rb/objects/device_server.rb +18 -0
- data/lib/bunq_rb/objects/installation.rb +28 -0
- data/lib/bunq_rb/objects/installation_server_public_key.rb +22 -0
- data/lib/bunq_rb/objects/monetary_account.rb +20 -0
- data/lib/bunq_rb/objects/permitted_ip.rb +42 -0
- data/lib/bunq_rb/objects/request_inquiry.rb +25 -0
- data/lib/bunq_rb/objects/session_server.rb +17 -0
- data/lib/bunq_rb/objects/user.rb +19 -0
- data/lib/bunq_rb/version.rb +3 -0
- data/lib/bunq_rb.rb +18 -0
- metadata +129 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: de28e0261c9d15eec3856d9644026b928dc71bcd
|
4
|
+
data.tar.gz: 628267f5c134938729ded5a9767ed1d76cbad0f1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ed3de1be7eecf54b50038aedbadd0559b643beea297f0992221910238c599769e984296690b689bd27bad67773e32fce556dcc84ceabf83959612d470a4fe288
|
7
|
+
data.tar.gz: 51839e9ae106bc722bd4c9972f57236ef50611b818a16eb0d2286de13184ff3aa93443349d864c67f34a714e5155f6238f63fc010302b2c1d22d72386da0e348
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
Documentation:
|
2
|
+
Enabled: true
|
3
|
+
|
4
|
+
AllCops:
|
5
|
+
Include:
|
6
|
+
- '**/Rakefile'
|
7
|
+
- '**/config.ru'
|
8
|
+
Exclude:
|
9
|
+
- 'db/**/*'
|
10
|
+
- 'tmp/**/*'
|
11
|
+
- 'vendor/**/*'
|
12
|
+
- 'bin/**/*'
|
13
|
+
- 'log/**/*'
|
14
|
+
|
15
|
+
Metrics/AbcSize:
|
16
|
+
Max: 15
|
17
|
+
Metrics/BlockNesting:
|
18
|
+
Max: 3
|
19
|
+
Metrics/ClassLength:
|
20
|
+
CountComments: false # count full line comments?
|
21
|
+
Max: 100
|
22
|
+
Metrics/CyclomaticComplexity:
|
23
|
+
Max: 6
|
24
|
+
Metrics/LineLength:
|
25
|
+
Max: 150
|
26
|
+
AllowURI: true
|
27
|
+
URISchemes:
|
28
|
+
- http
|
29
|
+
- https
|
30
|
+
|
31
|
+
Style/ClassAndModuleChildren:
|
32
|
+
Enabled: false
|
33
|
+
|
34
|
+
Metrics/MethodLength:
|
35
|
+
CountComments: false # count full line comments?
|
36
|
+
Max: 13
|
37
|
+
|
38
|
+
Metrics/ParameterLists:
|
39
|
+
Max: 5
|
40
|
+
CountKeywordArgs: true
|
41
|
+
|
42
|
+
Metrics/PerceivedComplexity:
|
43
|
+
Max: 7
|
44
|
+
|
45
|
+
StringLiterals:
|
46
|
+
EnforcedStyle: double_quotes
|
47
|
+
|
48
|
+
Style/ClassAndModuleChildren:
|
49
|
+
EnforcedStyle: nested
|
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at dunyakirkali@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
# Specify your gem's dependencies in bunq_rb.gemspec
|
4
|
+
gemspec
|
5
|
+
|
6
|
+
group :development, :test do
|
7
|
+
gem "bundler", "~> 1.13"
|
8
|
+
gem "rake", "~> 10.0"
|
9
|
+
end
|
10
|
+
|
11
|
+
group :development do
|
12
|
+
# development environment dependencies
|
13
|
+
gem "rubocop"
|
14
|
+
end
|
15
|
+
|
16
|
+
group :test do
|
17
|
+
# test environment dependencies
|
18
|
+
gem "rspec"
|
19
|
+
gem "simplecov"
|
20
|
+
gem "webmock"
|
21
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Dunya Kirkali
|
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,221 @@
|
|
1
|
+
[![Build Status](https://travis-ci.org/ahtung/bunq_rb.svg?branch=master)](https://travis-ci.org/ahtung/bunq_rb)
|
2
|
+
|
3
|
+
# BunqRb
|
4
|
+
|
5
|
+
- [Documentation](https://doc.bunq.com/)
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'bunq_rb'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install bunq_rb
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
First configure the gem
|
26
|
+
|
27
|
+
```
|
28
|
+
BunqRb.configure do |config|
|
29
|
+
config.api_key = ENV.fetch("API_KEY")
|
30
|
+
config.key = key # OpenSSL::PKey::RSA.new 2048
|
31
|
+
end
|
32
|
+
```
|
33
|
+
|
34
|
+
## ToDo
|
35
|
+
|
36
|
+
- Use Cases
|
37
|
+
- ~~Create Session~~
|
38
|
+
- Making a payment request
|
39
|
+
- Creating a tab payment
|
40
|
+
|
41
|
+
---
|
42
|
+
|
43
|
+
- INSTALLATION
|
44
|
+
- ~~Installation~~
|
45
|
+
- POST
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
installation, token, server_public_key = BunqRb::Installation.create(client_public_key: BunqRb.configuration.key.public_key)
|
49
|
+
```
|
50
|
+
|
51
|
+
- GET
|
52
|
+
|
53
|
+
```ruby
|
54
|
+
installation = BunqRb::Installation.find(2348)
|
55
|
+
```
|
56
|
+
|
57
|
+
- LIST
|
58
|
+
|
59
|
+
```ruby
|
60
|
+
installations = BunqRb::Installation.all
|
61
|
+
```
|
62
|
+
|
63
|
+
- ~~Installation server public key~~
|
64
|
+
|
65
|
+
- LIST
|
66
|
+
|
67
|
+
```ruby
|
68
|
+
installation = BunqRb::Installation.find(2348)
|
69
|
+
server_public_key = installation.server_public_key
|
70
|
+
```
|
71
|
+
|
72
|
+
- ~~Device~~
|
73
|
+
|
74
|
+
- GET
|
75
|
+
|
76
|
+
```ruby
|
77
|
+
device = BunqRb::Device.find(2348)
|
78
|
+
```
|
79
|
+
|
80
|
+
- LIST
|
81
|
+
|
82
|
+
```ruby
|
83
|
+
devices = BunqRb::Device.all
|
84
|
+
```
|
85
|
+
|
86
|
+
- ~~Device server~~
|
87
|
+
|
88
|
+
- GET
|
89
|
+
|
90
|
+
```ruby
|
91
|
+
device_server = BunqRb::DeviceServer.find(1913)
|
92
|
+
```
|
93
|
+
|
94
|
+
- LIST
|
95
|
+
|
96
|
+
```ruby
|
97
|
+
device_servers = BunqRb::DeviceServer.all
|
98
|
+
```
|
99
|
+
|
100
|
+
- POST
|
101
|
+
|
102
|
+
```ruby
|
103
|
+
device_server = BunqRb::DeviceServer.create(
|
104
|
+
description: "Dunya",
|
105
|
+
secret: BunqRb.configuration.api_key,
|
106
|
+
permitted_ips: []
|
107
|
+
)
|
108
|
+
```
|
109
|
+
|
110
|
+
- ~~Permitted IP~~
|
111
|
+
- GET
|
112
|
+
- LIST
|
113
|
+
- POST
|
114
|
+
- PUT
|
115
|
+
|
116
|
+
- User credential password IP
|
117
|
+
- GET
|
118
|
+
- LIST
|
119
|
+
|
120
|
+
- SESSION
|
121
|
+
- Session
|
122
|
+
- ~~SessionServer~~
|
123
|
+
|
124
|
+
- USER
|
125
|
+
- ~~User~~
|
126
|
+
- GET
|
127
|
+
|
128
|
+
```ruby
|
129
|
+
user = BunqRb::User.find(1913)
|
130
|
+
```
|
131
|
+
|
132
|
+
- LIST
|
133
|
+
|
134
|
+
```ruby
|
135
|
+
users = BunqRb::User.all
|
136
|
+
```
|
137
|
+
|
138
|
+
- User person
|
139
|
+
- User company
|
140
|
+
- Schedule user
|
141
|
+
- MONETARY ACCOUNTS
|
142
|
+
- Monetary account
|
143
|
+
- Monetary account bank
|
144
|
+
- PAYMENTS
|
145
|
+
- Payment
|
146
|
+
- Draft payment
|
147
|
+
- Payment batch
|
148
|
+
- Request inquiry
|
149
|
+
- Request inquiry batch
|
150
|
+
- Request response
|
151
|
+
- Schedule instance
|
152
|
+
- Schedule payment
|
153
|
+
- Schedule payment batch
|
154
|
+
- Schedule
|
155
|
+
- Payment chat
|
156
|
+
- Request inquiry chat
|
157
|
+
- Request response chat
|
158
|
+
- TABS
|
159
|
+
- Cash register
|
160
|
+
- Cash register qr code
|
161
|
+
- Cash register qr code content
|
162
|
+
- Tab
|
163
|
+
- Tab item
|
164
|
+
- Tab item batch
|
165
|
+
- Tab usage single
|
166
|
+
- Tab usage multiple
|
167
|
+
- Tab qr code content
|
168
|
+
- Tab result inquiry
|
169
|
+
- Tab result response
|
170
|
+
- CARDS
|
171
|
+
- Card
|
172
|
+
- Card debit
|
173
|
+
- Card name
|
174
|
+
- Master card action
|
175
|
+
- CONNECT
|
176
|
+
- Share invite bank inquiry
|
177
|
+
- Share invite bank response
|
178
|
+
- Share invite bank amount used
|
179
|
+
- Draft share invite bank
|
180
|
+
- Draft share invite bank qr code content
|
181
|
+
- CHAT
|
182
|
+
- Chat conversation
|
183
|
+
- Chat message
|
184
|
+
- Chat message attachment
|
185
|
+
- Chat message text
|
186
|
+
- INVOICES
|
187
|
+
- Invoice
|
188
|
+
- Invoice by user
|
189
|
+
- EXPORTS
|
190
|
+
- Customer statement export
|
191
|
+
- Customer statement export content
|
192
|
+
- Export annual overview
|
193
|
+
- Export annual overview content
|
194
|
+
- CALLBACKS
|
195
|
+
- Certificate pinned
|
196
|
+
- ATTACHMENTS
|
197
|
+
- Avatar
|
198
|
+
- Attachment public
|
199
|
+
- Attachment public content
|
200
|
+
- ~~Attachment monetary account~~
|
201
|
+
- Attachment tab
|
202
|
+
- Attachment tab content
|
203
|
+
- Tab attachment tab
|
204
|
+
- Tab attachment tab content
|
205
|
+
- Attachment conversation
|
206
|
+
- Attachment conversation content
|
207
|
+
|
208
|
+
## Development
|
209
|
+
|
210
|
+
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.
|
211
|
+
|
212
|
+
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 tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
213
|
+
|
214
|
+
## Contributing
|
215
|
+
|
216
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/ahtung/bunq_rb. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
217
|
+
|
218
|
+
|
219
|
+
## License
|
220
|
+
|
221
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "bunq_rb"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/bunq_rb.gemspec
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'bunq_rb/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "bunq_rb"
|
8
|
+
spec.version = BunqRb::VERSION
|
9
|
+
spec.authors = ["Dunya Kirkali"]
|
10
|
+
spec.email = ["dunyakirkali@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Bunq API Client}
|
13
|
+
spec.description = %q{Bunq API Client}
|
14
|
+
spec.homepage = "https://github.com/ahtung/bunq_rb"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
21
|
+
else
|
22
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
23
|
+
"public gem pushes."
|
24
|
+
end
|
25
|
+
|
26
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
27
|
+
f.match(%r{^(test|spec|features)/})
|
28
|
+
end
|
29
|
+
spec.bindir = "exe"
|
30
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
31
|
+
spec.require_paths = ["lib"]
|
32
|
+
|
33
|
+
spec.add_dependency "faraday"
|
34
|
+
spec.add_dependency "addressable"
|
35
|
+
spec.add_dependency "faraday_middleware"
|
36
|
+
spec.add_dependency "activesupport"
|
37
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# Headers
|
2
|
+
class Headers < Faraday::Middleware
|
3
|
+
def call(env)
|
4
|
+
env[:request_headers]["Cache-Control"] = "no-cache"
|
5
|
+
env[:request_headers]["User-Agent"] = "bunq_rb/1.00"
|
6
|
+
env[:request_headers]["X-Bunq-Language"] = "nl_NL"
|
7
|
+
env[:request_headers]["X-Bunq-Region"] = "nl_NL"
|
8
|
+
env[:request_headers]["X-Bunq-Geolocation"] = "0 0 0 0 NL"
|
9
|
+
env[:request_headers]["X-Bunq-Client-Request-Id"] = SecureRandom.uuid
|
10
|
+
@app.call(env)
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require "openssl"
|
2
|
+
require "base64"
|
3
|
+
|
4
|
+
# SignRequest
|
5
|
+
class SignRequest < Faraday::Middleware
|
6
|
+
def call(env)
|
7
|
+
@env = env
|
8
|
+
if sign?
|
9
|
+
set_client_authentication_header
|
10
|
+
set_image_header if image?
|
11
|
+
set_signature_header
|
12
|
+
end
|
13
|
+
@app.call(@env)
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def set_signature_header
|
19
|
+
@env[:request_headers]["X-Bunq-Client-Signature"] = Base64.strict_encode64(signature)
|
20
|
+
end
|
21
|
+
|
22
|
+
def set_image_header
|
23
|
+
@env[:request_headers]["X-Bunq-Attachment-Description"] = "BAZ"
|
24
|
+
@env[:request_headers]["Content-Type"] = "image/jpeg"
|
25
|
+
end
|
26
|
+
|
27
|
+
def set_client_authentication_header
|
28
|
+
@env[:request_headers]["X-Bunq-Client-Authentication"] = BunqRb.configuration.session_token
|
29
|
+
end
|
30
|
+
|
31
|
+
def signature
|
32
|
+
digest = OpenSSL::Digest::SHA256.new
|
33
|
+
BunqRb.configuration.key.sign(digest, string)
|
34
|
+
end
|
35
|
+
|
36
|
+
def string
|
37
|
+
sorted_headers = @env[:request_headers].sort.to_h.map { |k, v| "#{k}: #{v}" }
|
38
|
+
str = request_string
|
39
|
+
str << sorted_headers.join("\n") << "\n\n"
|
40
|
+
str << body
|
41
|
+
str
|
42
|
+
end
|
43
|
+
|
44
|
+
def body
|
45
|
+
if image?
|
46
|
+
@env.body.to_s
|
47
|
+
else
|
48
|
+
[:post, :put].include?(@env[:method]) ? @env.body.to_json : ""
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def image?
|
53
|
+
@env[:url].to_s.match(%r{v1\/user\/.*\/monetary-account\/.*\/attachment})
|
54
|
+
end
|
55
|
+
|
56
|
+
def request_string
|
57
|
+
uri = Addressable::URI.parse(@env[:url])
|
58
|
+
"#{@env[:method].upcase} #{uri.path}\n"
|
59
|
+
end
|
60
|
+
|
61
|
+
def sign?
|
62
|
+
@env[:method] == :post && @env[:url].to_s.match(%r{v1\/installation}) ? false : true
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require "addressable/uri"
|
2
|
+
require "securerandom"
|
3
|
+
require "faraday"
|
4
|
+
require "faraday_middleware"
|
5
|
+
|
6
|
+
require_relative "client/headers"
|
7
|
+
require_relative "client/sign_request"
|
8
|
+
|
9
|
+
module BunqRb
|
10
|
+
# Shared
|
11
|
+
# TODO: (dunyakirkali) Extract to file
|
12
|
+
module Shared
|
13
|
+
extend ActiveSupport::Concern
|
14
|
+
|
15
|
+
module ClassMethods
|
16
|
+
def implements(*calls)
|
17
|
+
calls.each do |call|
|
18
|
+
case call
|
19
|
+
when :get
|
20
|
+
define_singleton_method(:find) do |*args|
|
21
|
+
full_uri = [uri, args.first].join("/")
|
22
|
+
response = Client.send_method(:get, full_uri)
|
23
|
+
new(response[0].values.first)
|
24
|
+
end
|
25
|
+
when :list
|
26
|
+
define_singleton_method(:all) do
|
27
|
+
response = Client.send_method(:get, uri)
|
28
|
+
response.map { |resp| new(resp.values.first) }
|
29
|
+
end
|
30
|
+
when :post
|
31
|
+
define_singleton_method(:create) do |*args|
|
32
|
+
response = Client.send_method(:post, uri, args)
|
33
|
+
new(response[0]["Id"])
|
34
|
+
end
|
35
|
+
else
|
36
|
+
puts "ERROR"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
require_relative "objects/device"
|
45
|
+
require_relative "objects/device_server"
|
46
|
+
require_relative "objects/installation"
|
47
|
+
require_relative "objects/installation_server_public_key"
|
48
|
+
require_relative "objects/session_server"
|
49
|
+
require_relative "objects/user"
|
50
|
+
require_relative "objects/permitted_ip"
|
51
|
+
require_relative "objects/monetary_account"
|
52
|
+
require_relative "objects/attachment_monetary_account"
|
53
|
+
require_relative "objects/request_inquiry"
|
54
|
+
|
55
|
+
module BunqRb
|
56
|
+
# Client
|
57
|
+
class Client
|
58
|
+
BASE_URL = "https://sandbox.public.api.bunq.com".freeze
|
59
|
+
|
60
|
+
def self.connection
|
61
|
+
@connection ||= Faraday.new(url: BASE_URL) do |config|
|
62
|
+
config.use Headers
|
63
|
+
config.use SignRequest
|
64
|
+
config.request :json
|
65
|
+
config.request :multipart
|
66
|
+
config.adapter Faraday.default_adapter
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def self.send_method(method, url, payload = {})
|
71
|
+
faraday_response = connection.send(method, url, payload)
|
72
|
+
json_response = JSON.parse(faraday_response.body)
|
73
|
+
raise json_response["Error"].first["error_description"] if json_response.key?("Error")
|
74
|
+
json_response["Response"]
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module BunqRb
|
2
|
+
# AttachmentMonetaryAccount
|
3
|
+
class AttachmentMonetaryAccount
|
4
|
+
attr_reader :id
|
5
|
+
|
6
|
+
def initialize(hsh = {})
|
7
|
+
@id = hsh["id"]
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.create(image)
|
11
|
+
response = Client.send_method(:post, url(1913, 1933), image)
|
12
|
+
response.map { |resp| new(resp["MonetaryAccountBank"]) }
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.url(user_id, monetary_account_id)
|
16
|
+
"/v1/user/#{user_id}/monetary-account/#{monetary_account_id}/attachment"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module BunqRb
|
2
|
+
# DeviceServer
|
3
|
+
class DeviceServer
|
4
|
+
include BunqRb::Shared
|
5
|
+
|
6
|
+
implements :post, :get, :list
|
7
|
+
|
8
|
+
attr_reader :id
|
9
|
+
|
10
|
+
def initialize(hsh = {})
|
11
|
+
@id = hsh["id"]
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.uri
|
15
|
+
"/v1/device-server"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module BunqRb
|
2
|
+
# Installation
|
3
|
+
class Installation
|
4
|
+
include BunqRb::Shared
|
5
|
+
|
6
|
+
implements :get, :list
|
7
|
+
|
8
|
+
attr_reader :id
|
9
|
+
|
10
|
+
def initialize(hsh = {})
|
11
|
+
@id = hsh["id"]
|
12
|
+
end
|
13
|
+
|
14
|
+
def server_public_key
|
15
|
+
@server_public_key ||= BunqRb::InstallationServerPublicKey.new(installation_id: @id)
|
16
|
+
@server_public_key.all.first
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.create(hash = {})
|
20
|
+
response = Client.send_method(:post, uri, hash)
|
21
|
+
[new(response[0]["Id"]), response[1]["Token"], response[2]["ServerPublicKey"]]
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.uri
|
25
|
+
"/v1/installation"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module BunqRb
|
2
|
+
# InstallationServerPublicKey
|
3
|
+
class InstallationServerPublicKey
|
4
|
+
attr_reader :server_public_key
|
5
|
+
attr_reader :installation_id
|
6
|
+
|
7
|
+
def initialize(hsh = {})
|
8
|
+
@server_public_key = hsh["server_public_key"]
|
9
|
+
|
10
|
+
@installation_id = hsh[:installation_id]
|
11
|
+
end
|
12
|
+
|
13
|
+
def uri
|
14
|
+
"/v1/installation/#{installation_id}/server-public-key"
|
15
|
+
end
|
16
|
+
|
17
|
+
def all
|
18
|
+
response = Client.send_method(:get, uri)
|
19
|
+
response.map { |resp| self.class.new(resp["ServerPublicKey"].merge(installation_id: installation_id)) }
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module BunqRb
|
2
|
+
# MonetaryAccount
|
3
|
+
class MonetaryAccount
|
4
|
+
attr_reader :id, :currency
|
5
|
+
|
6
|
+
def initialize(hsh = {})
|
7
|
+
@id = hsh["id"]
|
8
|
+
@currency = hsh["currency"]
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.url(user_id)
|
12
|
+
"/v1/user/#{user_id}/monetary-account"
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.all
|
16
|
+
response = Client.send_method(:get, url(1913))
|
17
|
+
response.map { |resp| new(resp["MonetaryAccountBank"]) }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module BunqRb
|
2
|
+
# PermittedIp
|
3
|
+
class PermittedIp
|
4
|
+
attr_reader :ip, :status, :id
|
5
|
+
|
6
|
+
def initialize(hsh = {})
|
7
|
+
@id = hsh["id"]
|
8
|
+
@ip = hsh["ip"]
|
9
|
+
@status = hsh["status"]
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.uri(user_id, credential_password_id)
|
13
|
+
"/v1/user/#{user_id}/credential-password-ip/#{credential_password_id}/ip"
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.create(hsh = {}, user_id, credential_password_id)
|
17
|
+
url = uri(user_id, credential_password_id)
|
18
|
+
response = Client.send_method(:post, url, hsh)
|
19
|
+
response[0]["Id"]
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.all(user_id, credential_password_id)
|
23
|
+
url = uri(user_id, credential_password_id)
|
24
|
+
response = Client.send_method(:get, url)
|
25
|
+
response.map { |resp| new(resp["PermittedIp"]) }
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.find(id, user_id, credential_password_id)
|
29
|
+
url = uri(user_id, credential_password_id)
|
30
|
+
full_path = [url, id].join("/")
|
31
|
+
response = Client.send_method(:get, full_path)
|
32
|
+
new(response[0]["PermittedIp"])
|
33
|
+
end
|
34
|
+
|
35
|
+
def update(hsh = {}, user_id, credential_password_id)
|
36
|
+
url = self.class.uri(user_id, credential_password_id)
|
37
|
+
full_path = [url, id].join("/")
|
38
|
+
response = Client.send_method(:put, full_path, hsh)
|
39
|
+
response[0]["Id"]
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module BunqRb
|
2
|
+
# RequestInquiry
|
3
|
+
class RequestInquiry
|
4
|
+
attr_reader :id, :status
|
5
|
+
|
6
|
+
def initialize(hsh = {})
|
7
|
+
@id = hsh["id"]
|
8
|
+
@status = hsh["status"]
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.url(user_id, monetary_account_id, id = nil)
|
12
|
+
"/v1/user/#{user_id}/monetary-account/#{monetary_account_id}/request-inquiry/#{id}"
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.find(id)
|
16
|
+
response = Client.send_method(:get, url(1913, 1933, id))
|
17
|
+
new(response[0]["RequestInquiry"])
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.create(hash = {})
|
21
|
+
response = Client.send_method(:post, url(1913, 1933), hash)
|
22
|
+
new(response[0]["Id"])
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module BunqRb
|
2
|
+
# SessionServer
|
3
|
+
class SessionServer
|
4
|
+
URI = "/v1/session-server".freeze
|
5
|
+
|
6
|
+
attr_reader :id
|
7
|
+
|
8
|
+
def initialize(hsh = {})
|
9
|
+
@id = hsh["id"]
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.create(hash = {})
|
13
|
+
response = Client.send_method(:post, URI, hash)
|
14
|
+
[new(response[0]["Id"]), response[1]["Token"], response[1]["UserCompany"]]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module BunqRb
|
2
|
+
# Installation
|
3
|
+
class User
|
4
|
+
include BunqRb::Shared
|
5
|
+
|
6
|
+
implements :get, :list
|
7
|
+
|
8
|
+
attr_reader :id, :display_name
|
9
|
+
|
10
|
+
def initialize(hsh = {})
|
11
|
+
@id = hsh["id"]
|
12
|
+
@display_name = hsh["display_name"]
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.uri
|
16
|
+
"/v1/user"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/bunq_rb.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require "active_support/all"
|
2
|
+
|
3
|
+
require_relative "bunq_rb/version"
|
4
|
+
require_relative "bunq_rb/configuration"
|
5
|
+
require_relative "bunq_rb/client"
|
6
|
+
|
7
|
+
# BunqRb
|
8
|
+
module BunqRb
|
9
|
+
# BunqRb
|
10
|
+
class << self
|
11
|
+
attr_accessor :configuration
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.configure
|
15
|
+
self.configuration ||= Configuration.new
|
16
|
+
yield(configuration)
|
17
|
+
end
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bunq_rb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.11
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dunya Kirkali
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-03-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: faraday
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: addressable
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: faraday_middleware
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: activesupport
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Bunq API Client
|
70
|
+
email:
|
71
|
+
- dunyakirkali@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".rspec"
|
78
|
+
- ".rubocop.yml"
|
79
|
+
- ".travis.yml"
|
80
|
+
- CODE_OF_CONDUCT.md
|
81
|
+
- Gemfile
|
82
|
+
- LICENSE.txt
|
83
|
+
- README.md
|
84
|
+
- Rakefile
|
85
|
+
- bin/console
|
86
|
+
- bin/setup
|
87
|
+
- bunq_rb.gemspec
|
88
|
+
- lib/bunq_rb.rb
|
89
|
+
- lib/bunq_rb/client.rb
|
90
|
+
- lib/bunq_rb/client/headers.rb
|
91
|
+
- lib/bunq_rb/client/sign_request.rb
|
92
|
+
- lib/bunq_rb/configuration.rb
|
93
|
+
- lib/bunq_rb/objects/attachment_monetary_account.rb
|
94
|
+
- lib/bunq_rb/objects/device.rb
|
95
|
+
- lib/bunq_rb/objects/device_server.rb
|
96
|
+
- lib/bunq_rb/objects/installation.rb
|
97
|
+
- lib/bunq_rb/objects/installation_server_public_key.rb
|
98
|
+
- lib/bunq_rb/objects/monetary_account.rb
|
99
|
+
- lib/bunq_rb/objects/permitted_ip.rb
|
100
|
+
- lib/bunq_rb/objects/request_inquiry.rb
|
101
|
+
- lib/bunq_rb/objects/session_server.rb
|
102
|
+
- lib/bunq_rb/objects/user.rb
|
103
|
+
- lib/bunq_rb/version.rb
|
104
|
+
homepage: https://github.com/ahtung/bunq_rb
|
105
|
+
licenses:
|
106
|
+
- MIT
|
107
|
+
metadata:
|
108
|
+
allowed_push_host: https://rubygems.org
|
109
|
+
post_install_message:
|
110
|
+
rdoc_options: []
|
111
|
+
require_paths:
|
112
|
+
- lib
|
113
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '0'
|
123
|
+
requirements: []
|
124
|
+
rubyforge_project:
|
125
|
+
rubygems_version: 2.6.11
|
126
|
+
signing_key:
|
127
|
+
specification_version: 4
|
128
|
+
summary: Bunq API Client
|
129
|
+
test_files: []
|