bunq_rb 0.0.19 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0c43ca1a50fa32378a07889a18dccf3f5eabd3c5
4
- data.tar.gz: fb31685b9cddd56bea513de904c725d4d5247640
3
+ metadata.gz: adeb4222d853387f782b2a0419dcd2e2bc8d9be6
4
+ data.tar.gz: 485b94b9039508f7437116240d142eadc04515a2
5
5
  SHA512:
6
- metadata.gz: 81f305ad8641ff6ca4a027b17bd2b6b94ae07f0943ccdea3636ca3a26c01747c4de4c2664ed96052c36765d32ed8bed0b2c43aac9e98807a1bf838c0308f9841
7
- data.tar.gz: 422ffd3a7f62cad2bc65a10db31bd1f1d43501b798be99aa7286fa7b3478059fdeb2a763562636bd9cb8beaa5ed209e917db9b3be885728d54b4363468fc7f00
6
+ metadata.gz: f0402358accffc3c200357cc337fe192f7ca8ef99d76a5c116a2c9e09c8f40484a5e84810ea80d48519a5b3ba6c72dc3e6d7326964fc7331d4b1dc58f93622c7
7
+ data.tar.gz: 92036e5a55c9494636433ced9b8e86585130c0139f6d552809a9e1fd85c369e5b1ffa92e6e89ea115543f3ce10feff521456084655e7a15664f524d1e31e32f2
data/README.md CHANGED
@@ -265,7 +265,17 @@ TODO
265
265
 
266
266
  ##### LIST
267
267
 
268
- TODO
268
+ ```ruby
269
+ user_id = 1913
270
+ monetary_account_id = 1933
271
+ bunq_me_tabs = BunqRb::BunqMeTab.all(user_id, monetary_account_id)
272
+
273
+ # OR
274
+
275
+ user = BunqRb::User.find(1913)
276
+ monetary_accounts = user.monetary_accounts
277
+ bunq_me_tabs = monetary_accounts.first.bunq_me_tabs
278
+ ```
269
279
 
270
280
  ### DRAFT PAYMENTS
271
281
 
data/bunq_rb.gemspec CHANGED
@@ -32,4 +32,5 @@ Gem::Specification.new do |spec|
32
32
 
33
33
  spec.add_dependency "spyke"
34
34
  spec.add_dependency "money"
35
+ spec.add_dependency "addressable"
35
36
  end
data/lib/bunq_rb.rb CHANGED
@@ -1,6 +1,8 @@
1
1
  require "active_support/all"
2
2
  require "money"
3
+ require "addressable"
3
4
 
5
+ require_relative "bunq_rb/logger"
4
6
  require_relative "bunq_rb/version"
5
7
  require_relative "bunq_rb/configuration"
6
8
  require_relative "bunq_rb/client"
@@ -1,4 +1,3 @@
1
- require "addressable/uri"
2
1
  require "securerandom"
3
2
  require "faraday"
4
3
  require "faraday_middleware"
@@ -17,32 +16,47 @@ module BunqRb
17
16
  calls.each do |call|
18
17
  case call
19
18
  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
19
+ implements_get
25
20
  when :list
26
- define_singleton_method(:all) do
27
- page_size = BunqRb.configuration.page_size
28
- response = Client.send_method(:get, "#{uri}?count=#{page_size}")
29
- response.map { |resp| new(resp.values.first) }
30
- end
31
- when :post
32
- define_singleton_method(:create) do |*args|
33
- response = Client.send_method(:post, uri, args)
34
- new(response[0]["Id"])
35
- end
36
- when :put
37
- define_singleton_method(:update) do |*args|
38
- response = Client.send_method(:post, uri, args)
39
- new(response[0]["Id"])
40
- end
21
+ implements_list
41
22
  else
42
23
  puts "ERROR for: #{call}"
43
24
  end
44
25
  end
45
26
  end
27
+
28
+ private
29
+
30
+ def implements_get
31
+ define_singleton_method(:find) do |*args|
32
+ id = args.pop
33
+ full_uri = [url(*args), id].join("/")
34
+ response = Client.send_method(:get, full_uri)
35
+ new(response[0].values.first)
36
+ end
37
+ end
38
+
39
+ def implements_list
40
+ define_singleton_method(:all) do |*args|
41
+ Enumerator.new do |yielder|
42
+ older_url = counted_url(args)
43
+ loop do
44
+ results = Client.raw_send_method(:get, older_url)
45
+ json = JSON.parse(results.body)
46
+ json["Response"].map { |item| yielder << new(item.values.first) }
47
+ raise StopIteration if json["Pagination"].nil? || json["Pagination"]["older_url"].nil?
48
+ older_url = json["Pagination"]["older_url"]
49
+ end
50
+ end.lazy
51
+ end
52
+ end
53
+
54
+ def counted_url(args)
55
+ page_size = BunqRb.configuration.page_size
56
+ arged_url = Addressable::Template.new("#{url(*args)}{?query*}")
57
+ params = page_size == 10 ? {} : { count: page_size }
58
+ arged_url.expand(query: params).to_s
59
+ end
46
60
  end
47
61
  end
48
62
  end
@@ -63,10 +77,16 @@ module BunqRb
63
77
  end
64
78
 
65
79
  def self.send_method(method, url, payload = {})
80
+ BunqRb.logger.debug "#{method.upcase} #{url}"
66
81
  faraday_response = connection.send(method, url, payload)
67
82
  json_response = JSON.parse(faraday_response.body)
68
83
  raise json_response["Error"].first["error_description"] if json_response.key?("Error")
69
84
  json_response["Response"]
70
85
  end
86
+
87
+ def self.raw_send_method(method, url, payload = {})
88
+ BunqRb.logger.debug "#{method.upcase} #{url}"
89
+ connection.send(method, url, payload)
90
+ end
71
91
  end
72
92
  end
@@ -0,0 +1,9 @@
1
+ module BunqRb
2
+ def self.logger
3
+ @@logger ||= defined?(Rails) ? Rails.logger : Logger.new(STDOUT)
4
+ end
5
+
6
+ def self.logger=(logger)
7
+ @@logger = logger
8
+ end
9
+ end
@@ -1,7 +1,9 @@
1
1
  module BunqRb
2
2
  # AttachmentPublic
3
3
  class AttachmentPublic
4
- URI = "/v1/attachment-public".freeze
4
+ include BunqRb::Shared
5
+
6
+ implements :get
5
7
 
6
8
  attr_reader :uuid
7
9
 
@@ -10,14 +12,12 @@ module BunqRb
10
12
  end
11
13
 
12
14
  def self.create(hash = {})
13
- response = Client.send_method(:post, URI, hash)
15
+ response = Client.send_method(:post, url, hash)
14
16
  new(response[0]["Uuid"])
15
17
  end
16
18
 
17
- def self.find(id)
18
- uri = [URI, id].join("/")
19
- response = Client.send_method(:get, uri)
20
- new(response[0]["AttachmentPublic"])
19
+ def self.url
20
+ "/v1/attachment-public"
21
21
  end
22
22
  end
23
23
  end
@@ -1,7 +1,9 @@
1
1
  module BunqRb
2
2
  # Avatar
3
3
  class Avatar
4
- URI = "/v1/avatar".freeze
4
+ include BunqRb::Shared
5
+
6
+ implements :get
5
7
 
6
8
  attr_reader :uuid
7
9
 
@@ -9,15 +11,13 @@ module BunqRb
9
11
  @uuid = hsh["uuid"]
10
12
  end
11
13
 
12
- def self.create(hash = {})
13
- response = Client.send_method(:post, URI, hash)
14
- new(response[0]["Uuid"])
14
+ def self.url
15
+ "/v1/avatar"
15
16
  end
16
17
 
17
- def self.find(id)
18
- uri = [URI, id].join("/")
19
- response = Client.send_method(:get, uri)
20
- new(response[0]["Avatar"])
18
+ def self.create(hash = {})
19
+ response = Client.send_method(:post, url, hash)
20
+ new(response[0]["Uuid"])
21
21
  end
22
22
  end
23
23
  end
@@ -0,0 +1,21 @@
1
+ module BunqRb
2
+ # Avatar
3
+ class BunqMeTab
4
+ include BunqRb::Shared
5
+
6
+ implements :list
7
+
8
+ attr_reader :id, :created, :updated, :status
9
+
10
+ def initialize(hsh = {})
11
+ @id = hsh["id"]
12
+ @status = hsh["status"]
13
+ @created = Time.parse(hsh["created"])
14
+ @updated = Time.parse(hsh["updated"])
15
+ end
16
+
17
+ def self.url(user_id, monetary_account_id)
18
+ "/v1/user/#{user_id}/monetary-account/#{monetary_account_id}/bunqme-tab"
19
+ end
20
+ end
21
+ end
@@ -3,26 +3,16 @@ module BunqRb
3
3
  class Card
4
4
  include BunqRb::Shared
5
5
 
6
+ implements :list, :get
7
+
6
8
  attr_reader :id
7
9
 
8
10
  def initialize(hsh = {})
9
11
  @id = hsh["id"]
10
12
  end
11
13
 
12
- def self.all(user_id)
13
- page_size = BunqRb.configuration.page_size
14
- response = Client.send_method(:get, "#{url(user_id)}?count=#{page_size}")
15
- response.map { |resp| new(resp["CardDebit"]) }
16
- end
17
-
18
14
  def self.url(user_id)
19
15
  "/v1/user/#{user_id}/card"
20
16
  end
21
-
22
- def self.find(user_id, id)
23
- uri = [url(user_id), id].join("/")
24
- response = Client.send_method(:get, uri)
25
- new(response[0]["CardDebit"])
26
- end
27
17
  end
28
18
  end
@@ -3,7 +3,7 @@ module BunqRb
3
3
  class CashRegister
4
4
  include BunqRb::Shared
5
5
 
6
- implements :put, :list
6
+ implements :list, :get
7
7
 
8
8
  attr_reader :id, :name, :status
9
9
 
@@ -13,20 +13,13 @@ module BunqRb
13
13
  @status = hsh["status"]
14
14
  end
15
15
 
16
- def self.find(id, user_id, monetary_account_id)
17
- url = uri(user_id, monetary_account_id)
18
- full_path = [url, id].join("/")
19
- response = Client.send_method(:get, full_path)
20
- new(response[0]["CashRegister"])
21
- end
22
-
23
16
  def self.create(hsh = {}, user_id, monetary_account_id)
24
- url = uri(user_id, monetary_account_id)
25
- response = Client.send_method(:post, url, hsh)
17
+ uri = url(user_id, monetary_account_id)
18
+ response = Client.send_method(:post, uri, hsh)
26
19
  response[0]["Id"]
27
20
  end
28
21
 
29
- def self.uri(user_id, monetary_account_id)
22
+ def self.url(user_id, monetary_account_id)
30
23
  "/v1/user/#{user_id}/monetary-account/#{monetary_account_id}/cash-register"
31
24
  end
32
25
  end
@@ -3,7 +3,7 @@ module BunqRb
3
3
  class Device
4
4
  include BunqRb::Shared
5
5
 
6
- implements :get, :list
6
+ implements :list
7
7
 
8
8
  attr_reader :id
9
9
 
@@ -11,7 +11,7 @@ module BunqRb
11
11
  @id = hsh["id"]
12
12
  end
13
13
 
14
- def self.uri
14
+ def self.url
15
15
  "/v1/device"
16
16
  end
17
17
  end
@@ -11,12 +11,12 @@ module BunqRb
11
11
  @id = hsh["id"]
12
12
  end
13
13
 
14
- def self.uri
14
+ def self.url
15
15
  "/v1/device-server"
16
16
  end
17
17
 
18
18
  def self.create(hash = {})
19
- response = Client.send_method(:post, uri, hash)
19
+ response = Client.send_method(:post, url, hash)
20
20
  new(response[0]["Id"])
21
21
  end
22
22
  end
@@ -17,11 +17,11 @@ module BunqRb
17
17
  end
18
18
 
19
19
  def self.create(hash = {})
20
- response = Client.send_method(:post, uri, hash)
20
+ response = Client.send_method(:post, url, hash)
21
21
  [new(response[0]["Id"]), response[1]["Token"], response[2]["ServerPublicKey"]]
22
22
  end
23
23
 
24
- def self.uri
24
+ def self.url
25
25
  "/v1/installation"
26
26
  end
27
27
  end
@@ -1,9 +1,14 @@
1
1
  module BunqRb
2
- # MonetaryAccount
3
- class MonetaryAccount
2
+ # MonetaryAccountBank
3
+ class MonetaryAccountBank
4
+ include BunqRb::Shared
5
+
6
+ implements :list
7
+
4
8
  attr_reader :id, :currency, :description
5
9
 
6
10
  def initialize(hsh = {})
11
+ # puts hsh
7
12
  @id = hsh["id"]
8
13
  @user_id = hsh["user_id"]
9
14
  @currency = hsh["currency"]
@@ -11,16 +16,15 @@ module BunqRb
11
16
  end
12
17
 
13
18
  def self.url(user_id)
14
- "/v1/user/#{user_id}/monetary-account"
15
- end
16
-
17
- def self.all(user_id)
18
- response = Client.send_method(:get, url(user_id))
19
- response.map { |resp| new(resp["MonetaryAccountBank"]) }
19
+ "/v1/user/#{user_id}/monetary-account-bank"
20
20
  end
21
21
 
22
22
  def payments
23
23
  BunqRb::Payment.all(@user_id, @id)
24
24
  end
25
+
26
+ def bunq_me_tabs
27
+ BunqRb::BunqMeTab.all(@user_id, @id)
28
+ end
25
29
  end
26
30
  end
@@ -1,6 +1,10 @@
1
1
  module BunqRb
2
2
  # Payment
3
3
  class Payment
4
+ include BunqRb::Shared
5
+
6
+ implements :list
7
+
4
8
  attr_reader :id, :created, :updated, :description, :amount
5
9
 
6
10
  def initialize(hsh = {})
@@ -14,11 +18,5 @@ module BunqRb
14
18
  def self.url(user_id, monetary_account_id)
15
19
  "/v1/user/#{user_id}/monetary-account/#{monetary_account_id}/payment"
16
20
  end
17
-
18
- def self.all(user_id, monetary_account_id)
19
- page_size = BunqRb.configuration.page_size
20
- response = Client.send_method(:get, "#{url(user_id, monetary_account_id)}?count=#{page_size}")
21
- response.map { |resp| new(resp["Payment"]) }
22
- end
23
21
  end
24
22
  end
@@ -1,6 +1,10 @@
1
1
  module BunqRb
2
2
  # PermittedIp
3
3
  class PermittedIp
4
+ include BunqRb::Shared
5
+
6
+ implements :get, :list
7
+
4
8
  attr_reader :ip, :status, :id
5
9
 
6
10
  def initialize(hsh = {})
@@ -9,32 +13,19 @@ module BunqRb
9
13
  @status = hsh["status"]
10
14
  end
11
15
 
12
- def self.uri(user_id, credential_password_id)
16
+ def self.url(user_id, credential_password_id)
13
17
  "/v1/user/#{user_id}/credential-password-ip/#{credential_password_id}/ip"
14
18
  end
15
19
 
16
20
  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)
21
+ uri = url(user_id, credential_password_id)
22
+ response = Client.send_method(:post, uri, hsh)
19
23
  response[0]["Id"]
20
24
  end
21
25
 
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
26
  def update(hsh = {}, user_id, credential_password_id)
36
- url = self.class.uri(user_id, credential_password_id)
37
- full_path = [url, id].join("/")
27
+ uri = self.class.url(user_id, credential_password_id)
28
+ full_path = [uri, id].join("/")
38
29
  response = Client.send_method(:put, full_path, hsh)
39
30
  response[0]["Id"]
40
31
  end
@@ -1,6 +1,10 @@
1
1
  module BunqRb
2
2
  # RequestInquiry
3
3
  class RequestInquiry
4
+ include BunqRb::Shared
5
+
6
+ implements :get
7
+
4
8
  attr_reader :id, :status
5
9
 
6
10
  def initialize(hsh = {})
@@ -8,13 +12,8 @@ module BunqRb
8
12
  @status = hsh["status"]
9
13
  end
10
14
 
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"])
15
+ def self.url(user_id, monetary_account_id)
16
+ "/v1/user/#{user_id}/monetary-account/#{monetary_account_id}/request-inquiry"
18
17
  end
19
18
 
20
19
  def self.create(hash = {})
@@ -12,12 +12,12 @@ module BunqRb
12
12
  @display_name = hsh["display_name"]
13
13
  end
14
14
 
15
- def self.uri
15
+ def self.url
16
16
  "/v1/user"
17
17
  end
18
18
 
19
19
  def monetary_accounts
20
- BunqRb::MonetaryAccount.all(@id)
20
+ BunqRb::MonetaryAccountBank.all(@id)
21
21
  end
22
22
 
23
23
  def cards
@@ -1,3 +1,3 @@
1
1
  module BunqRb
2
- VERSION = "0.0.19".freeze
2
+ VERSION = "0.1.0".freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bunq_rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.19
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dunya Kirkali
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2018-03-21 00:00:00.000000000 Z
12
+ date: 2018-03-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: spyke
@@ -39,6 +39,20 @@ dependencies:
39
39
  - - ">="
40
40
  - !ruby/object:Gem::Version
41
41
  version: '0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: addressable
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :runtime
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
42
56
  description: Bunq API Client
43
57
  email:
44
58
  - dunyakirkali@gmail.com
@@ -64,16 +78,18 @@ files:
64
78
  - lib/bunq_rb/client/headers.rb
65
79
  - lib/bunq_rb/client/sign_request.rb
66
80
  - lib/bunq_rb/configuration.rb
81
+ - lib/bunq_rb/logger.rb
67
82
  - lib/bunq_rb/objects/attachment_monetary_account.rb
68
83
  - lib/bunq_rb/objects/attachment_public.rb
69
84
  - lib/bunq_rb/objects/avatar.rb
85
+ - lib/bunq_rb/objects/bunq_me_tab.rb
70
86
  - lib/bunq_rb/objects/card.rb
71
87
  - lib/bunq_rb/objects/cash_register.rb
72
88
  - lib/bunq_rb/objects/device.rb
73
89
  - lib/bunq_rb/objects/device_server.rb
74
90
  - lib/bunq_rb/objects/installation.rb
75
91
  - lib/bunq_rb/objects/installation_server_public_key.rb
76
- - lib/bunq_rb/objects/monetary_account.rb
92
+ - lib/bunq_rb/objects/monetary_account_bank.rb
77
93
  - lib/bunq_rb/objects/payment.rb
78
94
  - lib/bunq_rb/objects/permitted_ip.rb
79
95
  - lib/bunq_rb/objects/request_inquiry.rb