bunq-client 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/bunq/bunq.rb +1 -16
- data/lib/bunq/resource.rb +29 -4
- data/lib/bunq/signature.rb +7 -3
- data/lib/bunq/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 22487972e1aebeb56b45b8781968b99da449bc9a
|
4
|
+
data.tar.gz: 2f1b2e7500ae78bf18a066d45b751e38cf56fbc8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 00f65e325aa9b546c8f1124c6debf626b07d21a546be70f8af5f901bcb8d74bcdff85b067775ed17c2dd103502d422499201904d5f2fc1673780a363f42546e4
|
7
|
+
data.tar.gz: 29544093b45a56c096c45599263fcd29fccfd124a5e2a52515bc4d3eb8434ed0b59f5bba687d1f45ff63f88c68cae2768f8c727057a1ecc66f56df2f1503fb86
|
data/lib/bunq/bunq.rb
CHANGED
@@ -1,19 +1,4 @@
|
|
1
1
|
require 'rest-client'
|
2
2
|
require_relative './client'
|
3
3
|
require_relative './signature'
|
4
|
-
require_relative 'paginated'
|
5
|
-
|
6
|
-
RestClient.add_before_execution_proc do |req, params|
|
7
|
-
next unless params[:url].include?('bunq.com')
|
8
|
-
req['X-Bunq-Client-Request-Id'] = params[:headers][:'X-Bunq-Client-Request-Id'] = SecureRandom.uuid
|
9
|
-
|
10
|
-
# can't sign the creation of an installation
|
11
|
-
# see https://doc.bunq.com/api/1/call/installation/method/post
|
12
|
-
next if params[:url].end_with?('/installation') && req.method == 'POST'
|
13
|
-
req['X-Bunq-Client-Signature'] = Bunq.signature.create(
|
14
|
-
params[:method].upcase,
|
15
|
-
req.path,
|
16
|
-
params[:headers],
|
17
|
-
params[:payload]
|
18
|
-
)
|
19
|
-
end
|
4
|
+
require_relative './paginated'
|
data/lib/bunq/resource.rb
CHANGED
@@ -6,6 +6,7 @@ require 'json'
|
|
6
6
|
module Bunq
|
7
7
|
class Resource
|
8
8
|
attr_reader :resource
|
9
|
+
NO_PARAMS = {}
|
9
10
|
|
10
11
|
def initialize(client, path)
|
11
12
|
@client = client
|
@@ -24,25 +25,28 @@ module Bunq
|
|
24
25
|
end
|
25
26
|
|
26
27
|
def get(params = {}, &block)
|
27
|
-
@resource.get(params: params) do |response, request, result|
|
28
|
+
@resource.get({params: params}.merge(bunq_request_headers('GET', params))) do |response, request, result|
|
28
29
|
verify_and_handle_response(response, request, result, &block)
|
29
30
|
end
|
30
31
|
end
|
31
32
|
|
33
|
+
|
32
34
|
def post(payload, skip_verify = false, &block)
|
35
|
+
json = JSON.generate(payload)
|
33
36
|
if skip_verify
|
34
|
-
@resource.post(
|
37
|
+
@resource.post(json, bunq_request_headers('POST', NO_PARAMS, json)) do |response, request, result|
|
35
38
|
handle_response(response, request, result, &block)
|
36
39
|
end
|
37
40
|
else
|
38
|
-
@resource.post(
|
41
|
+
@resource.post(json, bunq_request_headers('POST', NO_PARAMS, json)) do |response, request, result|
|
39
42
|
verify_and_handle_response(response, request, result, &block)
|
40
43
|
end
|
41
44
|
end
|
42
45
|
end
|
43
46
|
|
44
47
|
def put(payload, &block)
|
45
|
-
|
48
|
+
json = JSON.generate(payload)
|
49
|
+
@resource.put(json, bunq_request_headers('PUT', NO_PARAMS, json)) do |response, request, result|
|
46
50
|
verify_and_handle_response(response, request, result, &block)
|
47
51
|
end
|
48
52
|
end
|
@@ -63,6 +67,27 @@ module Bunq
|
|
63
67
|
|
64
68
|
attr_reader :client
|
65
69
|
|
70
|
+
def bunq_request_headers(verb, params, payload = nil)
|
71
|
+
request_id_header = {'X-Bunq-Client-Request-Id' => SecureRandom.uuid}
|
72
|
+
|
73
|
+
return request_id_header if @path.end_with?('/installation') && verb == 'POST'
|
74
|
+
request_id_header.merge('X-Bunq-Client-Signature' => sign_request(verb, params, request_id_header, payload))
|
75
|
+
end
|
76
|
+
|
77
|
+
def sign_request(verb, params, request_id_header, payload = nil)
|
78
|
+
Bunq.signature.create(
|
79
|
+
verb,
|
80
|
+
encode_params(@path, params),
|
81
|
+
@resource.headers.merge(request_id_header),
|
82
|
+
payload
|
83
|
+
)
|
84
|
+
end
|
85
|
+
|
86
|
+
def encode_params(path, params)
|
87
|
+
return path if params.empty?
|
88
|
+
"#{path}?#{URI.escape(params.collect { |k, v| "#{k}=#{v}" }.join('&'))}"
|
89
|
+
end
|
90
|
+
|
66
91
|
def verify_and_handle_response(response, request, result, &block)
|
67
92
|
Bunq.signature.verify!(response) unless client.configuration.disable_response_signature_verification
|
68
93
|
handle_response(response, request, result, &block)
|
data/lib/bunq/signature.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
require_relative 'unexpected_response'
|
2
2
|
|
3
3
|
module Bunq
|
4
|
-
|
5
4
|
class Signature
|
6
5
|
# headers in raw_headers hash in rest client are all lower case
|
7
6
|
BUNQ_HEADER_PREFIX = 'X-Bunq-'.downcase
|
@@ -19,7 +18,11 @@ module Bunq
|
|
19
18
|
end
|
20
19
|
|
21
20
|
def create(verb, path, headers, body)
|
22
|
-
signature = private_key.sign(
|
21
|
+
signature = private_key.sign(
|
22
|
+
digest,
|
23
|
+
signable_input(verb, path, headers.select { |header_name, _| signable_header?(header_name) }, body)
|
24
|
+
)
|
25
|
+
|
23
26
|
Base64.strict_encode64(signature)
|
24
27
|
end
|
25
28
|
|
@@ -43,9 +46,10 @@ module Bunq
|
|
43
46
|
end
|
44
47
|
|
45
48
|
def signable_input(verb, path, headers, body)
|
49
|
+
sortable_headers = Hash[headers.collect{ |k,v| [k.to_s, v] }]
|
46
50
|
head = [
|
47
51
|
[verb, path].join(' '),
|
48
|
-
|
52
|
+
sortable_headers.sort.to_h.map { |k,v| "#{k}: #{v}" }.join("\n")
|
49
53
|
].join("\n")
|
50
54
|
"#{head}\n\n#{body}"
|
51
55
|
end
|
data/lib/bunq/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bunq-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lars Vonk
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: exe
|
12
12
|
cert_chain: []
|
13
|
-
date: 2017-
|
13
|
+
date: 2017-05-19 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rest-client
|