unit_ruby_sdk 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +3 -0
  3. data/Gemfile +0 -10
  4. data/README.md +73 -1
  5. data/lib/unit/api_resources/account_resource.rb +125 -0
  6. data/lib/unit/api_resources/application_resource.rb +9 -9
  7. data/lib/unit/api_resources/base_resource.rb +3 -11
  8. data/lib/unit/api_resources/customer_resource.rb +12 -11
  9. data/lib/unit/errors/unit_error.rb +7 -13
  10. data/lib/unit/errors/unit_error_payload.rb +15 -2
  11. data/lib/unit/models/account/account.rb +157 -0
  12. data/lib/unit/models/account/deposit/account_owners_request.rb +29 -0
  13. data/lib/unit/models/account/deposit/balance_history_request.rb +39 -0
  14. data/lib/unit/models/account/deposit/close_deposit_account_request.rb +36 -0
  15. data/lib/unit/models/account/deposit/create_deposit_account_request.rb +39 -0
  16. data/lib/unit/models/account/deposit/freeze_account_request.rb +36 -0
  17. data/lib/unit/models/account/deposit/list_account_params.rb +48 -0
  18. data/lib/unit/models/account/deposit/patch_deposit_account_request.rb +36 -0
  19. data/lib/unit/models/application/application.rb +127 -0
  20. data/lib/unit/models/application/create_business_application_request.rb +7 -7
  21. data/lib/unit/models/application/create_individual_application_request.rb +14 -14
  22. data/lib/unit/models/application/list_application_params.rb +3 -3
  23. data/lib/unit/models/application/patch_application_request.rb +3 -3
  24. data/lib/unit/models/application/upload_document_request.rb +1 -1
  25. data/lib/unit/models/customer/add_authorized_users_request.rb +3 -3
  26. data/lib/unit/models/customer/archive_customer_request.rb +3 -4
  27. data/lib/unit/models/customer/customer.rb +96 -0
  28. data/lib/unit/models/customer/list_customer_params.rb +9 -11
  29. data/lib/unit/models/customer/patch_business_customer_request.rb +8 -8
  30. data/lib/unit/models/customer/patch_individual_customer_request.rb +9 -10
  31. data/lib/unit/models/customer/remove_authorized_users_request.rb +3 -3
  32. data/lib/unit/models/unit_response.rb +7 -1
  33. data/lib/unit/types/authorized_user.rb +1 -1
  34. data/lib/unit/types/relationship.rb +4 -5
  35. data/lib/unit/types/relationship_array.rb +14 -12
  36. data/lib/unit/utils/http_helper.rb +56 -0
  37. data/lib/unit/version.rb +1 -1
  38. data/lib/unit_ruby_sdk.rb +15 -21
  39. metadata +60 -7
  40. data/Gemfile.lock +0 -133
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1c537218faa351239ef177faffa0c2b9de8d40eebf52eb3608b55e76dc89746a
4
- data.tar.gz: aee02b9bca0da9370d687d5e374e1210198f7224e4834e585d32998fb3a74582
3
+ metadata.gz: a46692704b238a1ee794e61279bd26e2362d46758df062c6798654e420d07c9b
4
+ data.tar.gz: 15d22512500136bbcab8a1a8cd6053fa87c6caa3faf1aec7d42d90b9bc8a5242
5
5
  SHA512:
6
- metadata.gz: 30b0e0991cb6d0e291c0d6af7b4a8448ee293e06d06b1e7f2dac9b39b189807879eff0f048f788c41fc49045cd593dd319ee74e7c42fc7ec884c1495a3f45f8c
7
- data.tar.gz: 0fbae70cf0069a97e19ab5bbf5284fe802f9355879e30f15484e63b13b67a56f5e141dfde7c2ed0f4b17298b4b618498e8f594239897c0e7ea3bc0b530981dbb
6
+ metadata.gz: d679b613f4d3d262f5a70523a1031a0fa7ab7ca07ce55530bd1bd2b8e8fe0f622f109e082db4df6b2ca0fb964e5ce0f96996975d21f7420c241ea436ed3d6589
7
+ data.tar.gz: 81bde72e0dc915f97f247edc4f96e41143a628d6f068d1e239edc27bdbd15b2f012ce78db3dbcd988fa28f223463bf8803191cf1a7379cb9026efe82b6546556
data/.rubocop.yml CHANGED
@@ -30,5 +30,8 @@ Layout/LineLength:
30
30
  Style/ClassVars:
31
31
  Enabled: false
32
32
 
33
+ Lint/UnderscorePrefixedVariableName:
34
+ Enabled: false
35
+
33
36
  Metrics/BlockLength:
34
37
  Enabled: false
data/Gemfile CHANGED
@@ -4,13 +4,3 @@ source "https://rubygems.org"
4
4
 
5
5
  # Specify your gem's dependencies in unit-ruby-sdk.gemspec
6
6
  gemspec
7
-
8
- gem "rake", "~> 13.0"
9
-
10
- gem "rubocop", "~> 1.21"
11
-
12
- gem "httparty", "~0.20.0"
13
-
14
- gem "ruby-debug-ide"
15
-
16
- gem "factory_bot_rails", "~> 6.2.0"
data/README.md CHANGED
@@ -1 +1,73 @@
1
- # unit-ruby-sdk
1
+ # unit_ruby_sdk
2
+
3
+ This gem provides a ruby wrapper for [Unit's API](https://docs.unit.co/#introduction).
4
+
5
+ ## Documentation
6
+
7
+ See [Unit's Docs](https://docs.unit.co)
8
+
9
+ ## Installation
10
+
11
+ ```bash
12
+ gem install unit_ruby_sdk
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ ### Creating a Business Application
18
+
19
+ ```ruby
20
+ require 'unit_ruby_sdk'
21
+
22
+ Unit.config(api_url: ENV['API_URL'], token: ENV['TOKEN'])
23
+
24
+ full_name = Unit::Types::FullName.new('John', 'Doe')
25
+ date_of_birth = '1980-08-10'
26
+ address = Unit::Types::Address.new('123 Main St', 'San Francisco', 'CA', '94205', 'US')
27
+ phone = Unit::Types::Phone.new('380', '555123222')
28
+ email = 'jone.doe@unit-finance.com'
29
+ ssn = '123456789'
30
+ beneficial_owner = Unit::Types::BeneficialOwner.new(full_name, date_of_birth, address, phone, email, ssn)
31
+
32
+ response = Unit::Application.create_business_application(
33
+ name: "Acme Inc.",
34
+ address: address,
35
+ phone: phone,
36
+ state_of_incorporation: "CA",
37
+ ein: '123456789',
38
+ industry: "Retail",
39
+ contact: Unit::Types::BusinessContact.new(full_name, email, phone),
40
+ officer: Unit::Types::Officer.new(full_name, date_of_birth, address, phone, email, ssn),
41
+ beneficial_owners: [beneficial_owner, beneficial_owner],
42
+ entity_type: 'LLC'
43
+ )
44
+
45
+ application = response.data
46
+
47
+ puts application.id
48
+ ```
49
+
50
+ ### Fetching a Customer
51
+
52
+ ```ruby
53
+ require 'unit_ruby_sdk'
54
+
55
+ Unit.config(api_url: ENV['API_URL'], token: ENV['TOKEN'])
56
+
57
+ customer = Unit::Customer.list_customers.first
58
+ puts customer.id
59
+ ```
60
+
61
+ ### Logging Errors
62
+
63
+ ```ruby
64
+ require 'unit_ruby_sdk'
65
+
66
+ Unit.config(api_url: ENV['API_URL'], token: "missing token")
67
+
68
+ # response is a Unit::UnitError
69
+ response = Unit::Application.get_application('123')
70
+
71
+ # Prints "Bearer token is missing"
72
+ response.errors.each{|error| puts error.title}
73
+ ```
@@ -0,0 +1,125 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "./base_resource"
4
+ require_relative "../utils/http_helper"
5
+ require "json"
6
+
7
+ # class for creating request for accounts to Unit API and parsing responses
8
+ # @see https://docs.unit.co/#accounts
9
+ module Unit
10
+ module Resource
11
+ class AccountResource < Unit::Resource::BaseResource
12
+ class << self
13
+ # Create a new account by calling Unit's API
14
+ # @param request [CreateDepositAccountRequest] request
15
+ # @return [UnitResponse, UnitError]
16
+ def create_account(request)
17
+ payload = request.to_json_api
18
+ response = HttpHelper.post("#{api_url}/accounts", body: payload, headers: headers)
19
+ response_handler(response)
20
+ end
21
+
22
+ # Close an account by calling Unit's API
23
+ # @param request [CloseDepositAccountRequest] request
24
+ # @return [UnitResponse, UnitError]
25
+ def close_account(request)
26
+ payload = request.to_json_api
27
+ response = HttpHelper.post("#{api_url}/accounts/#{request.account_id}/close", body: payload, headers: headers)
28
+ response_handler(response)
29
+ end
30
+
31
+ # Reopen an account by calling Unit's API
32
+ # @param account_id [String]
33
+ # @param reason [String]
34
+ # @return [UnitResponse, UnitError]
35
+ def reopen_account(account_id)
36
+ response = HttpHelper.post("#{api_url}/accounts/#{account_id}/reopen", headers: headers)
37
+ response_handler(response)
38
+ end
39
+
40
+ # Freeze an account by calling Unit's API
41
+ # @param request [FreezeAccountRequest]
42
+ # @return [UnitResponse, UnitError]
43
+ def freeze_account(request)
44
+ payload = request.to_json_api
45
+ response = HttpHelper.post("#{api_url}/accounts/#{request.account_id}/freeze", body: payload, headers: headers)
46
+ response_handler(response)
47
+ end
48
+
49
+ # Unfreeze an account by calling Unit's API
50
+ # @param account_id [String]
51
+ # @return [UnitResponse, UnitError]
52
+ def unfreeze_account(account_id)
53
+ response = HttpHelper.post("#{api_url}/accounts/#{account_id}/unfreeze", headers: headers)
54
+ response_handler(response)
55
+ end
56
+
57
+ # Get account by calling Unit's API
58
+ # @param account_id [String]
59
+ # @return [UnitResponse, UnitError]
60
+ def get_account(account_id)
61
+ response = HttpHelper.get("#{api_url}/accounts/#{account_id}", headers: headers)
62
+ response_handler(response)
63
+ end
64
+
65
+ # List accounts by calling Unit's API
66
+ # @param params [ListAccountParams] - optional
67
+ # @return [UnitResponse, UnitError]
68
+ def list_accounts(params = nil)
69
+ response = HttpHelper.get("#{api_url}/accounts", params: params.to_hash, headers: headers)
70
+ response_handler(response)
71
+ end
72
+
73
+ # Update account by calling Unit's API
74
+ # @param request [PatchDepositAccountRequest]
75
+ def update_account(request)
76
+ payload = request.to_json_api
77
+ response = HttpHelper.patch("#{api_url}/accounts/#{request.account_id}", body: payload, headers: headers)
78
+ response_handler(response)
79
+ end
80
+
81
+ # Limit account by calling Unit's API
82
+ # @param account_id [String]
83
+ # @return [UnitResponse, UnitError]
84
+ def limits(account_id)
85
+ response = HttpHelper.get("#{api_url}/accounts/#{account_id}/limits", headers: headers)
86
+ response_handler(response)
87
+ end
88
+
89
+ # Get deposit products by calling Unit's API
90
+ # @param account_id [String]
91
+ # @return [UnitResponse, UnitError]
92
+ def get_deposit_products(account_id)
93
+ response = HttpHelper.get("#{api_url}/accounts/#{account_id}/deposit-products", headers: headers)
94
+ response_handler(response)
95
+ end
96
+
97
+ # Get account balance history by calling Unit's API
98
+ # @param params [BalanceHistoryRequest]
99
+ # @return [UnitResponse, UnitError]
100
+ def get_account_balance_history(params)
101
+ response = HttpHelper.get("#{api_url}/account-end-of-day", params: params.to_hash.to_json, headers: headers)
102
+ response_handler(response)
103
+ end
104
+
105
+ # Add account owners by calling Unit's API
106
+ # @param request [AccountOwnersRequest]
107
+ # @return [UnitResponse, UnitError]
108
+ def add_owners(request)
109
+ payload = request.to_json_api
110
+ response = HttpHelper.post("#{api_url}/accounts/#{request.account_id}/relationships/customers", body: payload, headers: headers)
111
+ response_handler(response)
112
+ end
113
+
114
+ # Remove account owners by calling Unit's API
115
+ # @param request [AccountOwnersRequest]
116
+ # @return [UnitResponse, UnitError]
117
+ def remove_owners(request)
118
+ payload = request.to_json_api
119
+ response = HttpHelper.delete("#{api_url}/accounts/#{request.account_id}/relationships/customers", body: payload, headers: headers)
120
+ response_handler(response)
121
+ end
122
+ end
123
+ end
124
+ end
125
+ end
@@ -1,10 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "httparty"
4
3
  require_relative "./base_resource"
4
+ require_relative "../utils/http_helper"
5
5
  require "json"
6
6
  # class for creating requests for applications to Unit API and parsing responses
7
- # See: https://docs.unit.co/applications
7
+ # @see https://docs.unit.co/applications
8
8
  module Unit
9
9
  module Resource
10
10
  class ApplicationResource < Unit::Resource::BaseResource
@@ -14,23 +14,23 @@ module Unit
14
14
  # @return [UnitResponse, UnitError]
15
15
  def create_application(request)
16
16
  payload = request.to_json_api
17
- response = HTTParty.post("#{api_url}/applications", body: payload, headers: headers)
17
+ response = HttpHelper.post("#{api_url}/applications", body: payload, headers: headers)
18
18
  response_handler(response)
19
19
  end
20
20
 
21
21
  # Get an application by calling Unit's API
22
- # @param [Integer] application_id
22
+ # @param [String] application_id
23
23
  # @return [UnitResponse, UnitError]
24
24
  def get_application(application_id)
25
- response = HTTParty.get("#{api_url}/applications/#{application_id}", headers: headers)
25
+ response = HttpHelper.get("#{api_url}/applications/#{application_id}", headers: headers)
26
26
  response_handler(response)
27
27
  end
28
28
 
29
- # Get an applications by calling Unit's API
29
+ # List applications by calling Unit's API
30
30
  # @param [ListApplicationParams] params
31
31
  # @return [UnitResponse, UnitError]
32
32
  def list_applications(params = nil)
33
- response = HTTParty.get("#{api_url}/applications", body: params&.to_hash&.to_json, headers: headers)
33
+ response = HttpHelper.get("#{api_url}/applications", params: params&.to_hash, headers: headers)
34
34
  response_handler(response)
35
35
  end
36
36
 
@@ -50,7 +50,7 @@ module Unit
50
50
  headers["Content-Type"] = "image/jpeg" if request.file_type == "jpeg"
51
51
  headers["Content-Type"] = "image/png" if request.file_type == "png"
52
52
 
53
- response = HTTParty.put(url, body: request.file, headers: headers)
53
+ response = HttpHelper.put(url, body: request.file, headers: headers)
54
54
 
55
55
  response_handler(response)
56
56
  end
@@ -60,7 +60,7 @@ module Unit
60
60
  # @return [UnitResponse, UnitError]
61
61
  def update(request)
62
62
  payload = request.to_json_api
63
- response = HTTParty.patch("#{api_url}/applications/#{request.application_id}", body: payload, headers: headers)
63
+ response = HttpHelper.patch("#{api_url}/applications/#{request.application_id}", body: payload, headers: headers)
64
64
  response_handler(response)
65
65
  end
66
66
  end
@@ -1,22 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "httparty"
4
-
5
3
  module Unit
6
4
  module Resource
7
5
  class BaseResource
8
6
  class << self
9
7
  # Check the response code and return a UnitResponse or UnitError
10
- # @param [HTTParty::Response] response
8
+ # @param [HTTP::Response] response
11
9
  def response_handler(response)
12
- included = response["included"].nil? ? nil : response["included"]
13
- meta = response["meta"].nil? ? nil : response["meta"]
14
- case response.code
15
- when 200...300
16
- Unit::UnitResponse.new(response["data"], included, meta)
17
- else
18
- Unit::UnitError.from_json_api(response)
19
- end
10
+ handler = response.code.to_i.between?(200, 299) ? Unit::UnitResponse : Unit::UnitError
11
+ handler.from_json_api(response)
20
12
  end
21
13
 
22
14
  protected
@@ -1,13 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "httparty"
4
-
5
3
  require_relative "../api_resources/base_resource"
6
4
  require_relative "../models/unit_response"
7
5
  require_relative "../errors/unit_error"
6
+ require_relative "../utils/http_helper"
8
7
 
9
8
  # class for creating requests for customers to Unit API and parsing responses
10
- # See: https://docs.unit.co/customers/
9
+ # @see https://docs.unit.co/customers/
11
10
  module Unit
12
11
  module Resource
13
12
  class CustomerResource < Unit::Resource::BaseResource
@@ -17,7 +16,7 @@ module Unit
17
16
  # @return [UnitResponse, UnitError]
18
17
  def update(request)
19
18
  payload = request.to_json_api
20
- response = HTTParty.patch("#{api_url}/customers/#{request.customer_id}", body: payload, headers: headers)
19
+ response = HttpHelper.patch("#{api_url}/customers/#{request.customer_id}", body: payload, headers: headers)
21
20
  response_handler(response)
22
21
  end
23
22
 
@@ -25,7 +24,7 @@ module Unit
25
24
  # @param [String] customer_id
26
25
  # @return [UnitResponse, UnitError]
27
26
  def get(customer_id)
28
- response = HTTParty.get("#{api_url}/customers/#{customer_id}", headers: headers)
27
+ response = HttpHelper.get("#{api_url}/customers/#{customer_id}", headers: headers)
29
28
  response_handler(response)
30
29
  end
31
30
 
@@ -33,7 +32,7 @@ module Unit
33
32
  # @param [ListCustomerParams] params
34
33
  # @return [UnitResponse, UnitError]
35
34
  def list(params = nil)
36
- response = HTTParty.get("#{api_url}/customers", body: params&.to_hash&.to_json, headers: headers)
35
+ response = HttpHelper.get("#{api_url}/customers", params: params&.to_hash, headers: headers)
37
36
  response_handler(response)
38
37
  end
39
38
 
@@ -42,7 +41,7 @@ module Unit
42
41
  # @return [UnitResponse, UnitError]
43
42
  def archive(request)
44
43
  payload = request.to_json_api
45
- response = HTTParty.post("#{api_url}/customers/#{request.customer_id}/archive", body: payload, headers: headers)
44
+ response = HttpHelper.post("#{api_url}/customers/#{request.customer_id}/archive", body: payload, headers: headers)
46
45
  response_handler(response)
47
46
  end
48
47
 
@@ -51,9 +50,11 @@ module Unit
51
50
  # @return [UnitResponse, UnitError]
52
51
  def add_authorized_users(request)
53
52
  payload = request.to_json_api
54
- response = HTTParty.post("#{api_url}/customers/#{request.customer_id}/authorized-users",
55
- body: payload,
56
- headers: headers)
53
+ response = HttpHelper.post(
54
+ "#{api_url}/customers/#{request.customer_id}/authorized-users",
55
+ body: payload,
56
+ headers: headers
57
+ )
57
58
  response_handler(response)
58
59
  end
59
60
 
@@ -62,7 +63,7 @@ module Unit
62
63
  # @return [UnitResponse, UnitError]
63
64
  def remove_authorized_users(request)
64
65
  payload = request.to_json_api
65
- response = HTTParty.delete("#{api_url}/customers/#{request.customer_id}/authorized-users", body: payload, headers: headers)
66
+ response = HttpHelper.delete("#{api_url}/customers/#{request.customer_id}/authorized-users", body: payload, headers: headers)
66
67
  response_handler(response)
67
68
  end
68
69
  end
@@ -5,25 +5,19 @@ require_relative "unit_error_payload"
5
5
  # Represents an Error returned from Unit's API
6
6
  module Unit
7
7
  class UnitError
8
+ attr_reader :errors
9
+
8
10
  # Create a new UnitError
9
11
  # @param [Array<UnitErrorPayload>] errors
10
12
  def initialize(errors)
11
13
  @errors = errors
12
14
  end
13
15
 
14
- class << self
15
- # Creates a new UnitError from given response.
16
- # @param [Hash] response The response returned from Unit's API
17
- # @return [UnitError] a new UnitError populated with values taken from the response
18
- def from_json_api(response)
19
- errors = response["errors"]
20
-
21
- errors&.map do |error|
22
- UnitErrorPayload.new(error["title"], error["status"],
23
- error["detail"], error["details"], error["source"], error["code"])
24
- end
25
- UnitError.new(errors)
26
- end
16
+ # Creates a new UnitError from given response.
17
+ # @param [HTTP::Response] response The response returned from Unit's API
18
+ # @return [UnitError] a new UnitError populated with values taken from the response
19
+ def self.from_json_api(response)
20
+ new((response.body["errors"] || []).map { |error| UnitErrorPayload.from_json_api(error) })
27
21
  end
28
22
  end
29
23
  end
@@ -11,8 +11,7 @@ module Unit
11
11
  # @param source [Hash] The source of the error
12
12
  # @param code [String] A Unit-specific code, uniquely identifying the error type
13
13
  # Check out documentation link for more details: https://docs.unit.co/about-jsonapi/#intro-errors
14
- def initialize(title, status, detail, details = nil,
15
- source = nil, code = nil)
14
+ def initialize(title, status, detail, details = nil, source = nil, code = nil)
16
15
  @title = title
17
16
  @status = status
18
17
  @detail = detail
@@ -20,5 +19,19 @@ module Unit
20
19
  @source = source
21
20
  @code = code
22
21
  end
22
+
23
+ # Creates a new UnitErrorPayload from given response error.
24
+ # @param [Hash] error One of the errors returned in a response from Unit's API
25
+ # @return [UnitErrorPayload] a new UnitErrorPayload populated with values taken from the response error
26
+ def self.from_json_api(error)
27
+ new(
28
+ error["title"],
29
+ error["status"],
30
+ error["detail"],
31
+ error["details"],
32
+ error["source"],
33
+ error["code"]
34
+ )
35
+ end
23
36
  end
24
37
  end
@@ -0,0 +1,157 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Unit
4
+ module Account
5
+ module Deposit
6
+ ACCOUNT_LIST_LIMIT = 100
7
+ ACCOUNT_LIST_OFFSET = 0
8
+ BALANCE_HISTORY_LIMIT = 100
9
+ BALANCE_HISTORY_OFFSET = 0
10
+ autoload :CreateDepositAccountRequest, "unit/models/account/deposit/create_deposit_account_request"
11
+ autoload :CloseDepositAccountRequest, "unit/models/account/deposit/close_deposit_account_request"
12
+ autoload :AccountOwnersRequest, "unit/models/account/deposit/account_owners_request"
13
+ autoload :BalanceHistoryRequest, "unit/models/account/deposit/balance_history_request"
14
+ autoload :FreezeAccountRequest, "unit/models/account/deposit/freeze_account_request"
15
+ autoload :ListAccountParams, "unit/models/account/deposit/list_account_params"
16
+ autoload :PatchDepositAccountRequest, "unit/models/account/deposit/patch_deposit_account_request"
17
+
18
+ class << self
19
+ # Create a deposit account
20
+ # @see https://docs.unit.co/deposit-accounts#create-deposit-account
21
+ # @param deposit_product [String]
22
+ # @param tags [Hash]- optional
23
+ # @param idempotency_key [String] - optional
24
+ # @param relationships [Relationships, RelationshipArray] - optional
25
+ # @return [UnitResponse, UnitError]
26
+ def create_deposit_account(deposit_product:, tags: nil, relationships: nil, idempotency_key: nil)
27
+ request = CreateDepositAccountRequest.new(deposit_product, tags, relationships, idempotency_key)
28
+ Unit::Resource::AccountResource.create_account(request)
29
+ end
30
+
31
+ # Close deposit account
32
+ # @see https://docs.unit.co/deposit-accounts#close-account
33
+ # @param account_id [String]
34
+ # @param reason [String]
35
+ # @param fraud_reason [String] - optional
36
+ # @return [UnitResponse, UnitError]
37
+ def close_deposit_account(account_id:, reason:)
38
+ request = CloseDepositAccountRequest.new(account_id, reason)
39
+ Unit::Resource::AccountResource.close_account(request)
40
+ end
41
+
42
+ # Reopen deposit account
43
+ # @see https://docs.unit.co/deposit-accounts#reopen-account
44
+ # @param account_id [String]
45
+ # @param reason [String]
46
+ def reopen_account(account_id:)
47
+ Unit::Resource::AccountResource.reopen_account(account_id)
48
+ end
49
+
50
+ # Get a deposit account by id
51
+ # @see https://docs.unit.co/deposit-accounts#get-specific-deposit-account
52
+ # @param account_id [String]
53
+ def get_deposit_account(account_id:)
54
+ Unit::Resource::AccountResource.get_account(account_id)
55
+ end
56
+
57
+ # Freeze deposit account
58
+ # @see https://docs.unit.co/deposit-accounts#freeze-account
59
+ # @param account_id [String]
60
+ # @param reason [String]
61
+ # @param reason_text [String] - optional
62
+ # @return [UnitResponse, UnitError]
63
+ def freeze_account(account_id:, reason:, reason_text: nil)
64
+ request = FreezeAccountRequest.new(account_id, reason, reason_text)
65
+ Unit::Resource::AccountResource.freeze_account(request)
66
+ end
67
+
68
+ # Unfreeze deposit account
69
+ # @see https://docs.unit.co/deposit-accounts#freeze-account
70
+ # @param account_id [String]
71
+ # @return [UnitResponse, UnitError]
72
+ def unfreeze_account(account_id:)
73
+ Unit::Resource::AccountResource.unfreeze_account(account_id)
74
+ end
75
+
76
+ # Listing deposit accounts
77
+ # @see https://docs.unit.co/deposit-accounts#list-deposit-accounts
78
+ # @param limit [Integer] - optional
79
+ # @param offset [Integer] - optional
80
+ # @param customer_id [String] - optional
81
+ # @param tags [Hash] - optional
82
+ # @param status [String] - optional
83
+ # @param from_balance [Integer] - optional
84
+ # @param to_balance [Integer] - optional
85
+ # @param include [String] - optional
86
+ # @return [UnitResponse, UnitError]
87
+ def list_deposit_accounts(limit: ACCOUNT_LIST_LIMIT, offset: ACCOUNT_LIST_OFFSET, customer_id: nil, tags: nil,
88
+ status: nil, from_balance: nil, to_balance: nil, include: nil)
89
+ request = ListAccountParams.new(limit, offset, customer_id, tags, status, from_balance, to_balance, include)
90
+ Unit::Resource::AccountResource.list_accounts(request)
91
+ end
92
+
93
+ # Update a deposit account
94
+ # @see https://docs.unit.co/deposit-accounts#update-accounts
95
+ # @param account_id [String]
96
+ # @param tags [Hash] - optional
97
+ # @param deposit_product [String] - optional
98
+ # @return [UnitResponse, UnitError]
99
+ def update_deposit_account(account_id:, tags: nil, deposit_product: nil)
100
+ request = PatchDepositAccountRequest.new(account_id, tags, deposit_product)
101
+ Unit::Resource::AccountResource.update_account(request)
102
+ end
103
+
104
+ # Limit a deposit account
105
+ # @see https://docs.unit.co/deposit-accounts#account-limits
106
+ # @param account_id [String]
107
+ # @return [UnitResponse, UnitError]
108
+ def limits(account_id:)
109
+ Unit::Resource::AccountResource.limits(account_id)
110
+ end
111
+
112
+ # Get deposit products
113
+ # @see https://docs.unit.co/deposit-accounts#account-deposit-products
114
+ # @param account_id [String]
115
+ # @return [UnitResponse, UnitError]
116
+ def get_deposit_products(account_id:)
117
+ Unit::Resource::AccountResource.get_deposit_products(account_id)
118
+ end
119
+
120
+ # Get account balance history by calling Unit's API
121
+ # @see https://docs.unit.co/deposit-accounts#get-account-balance-history
122
+ # @param limit [Integer] - optional
123
+ # @param offset [Integer] - optional
124
+ # @param account_id [String] - optional
125
+ # @param customer_id [String] - optional
126
+ # @param since [String] - optional
127
+ # @param _until [String] - optional
128
+ # @return [UnitResponse, UnitError]
129
+ def get_balance_history(limit = BALANCE_HISTORY_LIMIT, offset = BALANCE_HISTORY_OFFSET, account_id: nil, customer_id: nil,
130
+ since: nil, _until: nil)
131
+ request = BalanceHistoryRequest.new(limit, offset, account_id, customer_id, since, _until)
132
+ Unit::Resource::AccountResource.get_account_balance_history(request)
133
+ end
134
+
135
+ # Add account owners by calling Unit's API
136
+ # @see https://docs.unit.co/deposit-accounts#account-add-owners
137
+ # @param account_id [String]
138
+ # @param customers [Array<String>]
139
+ # @return [UnitResponse, UnitError]
140
+ def add_owners(account_id:, customers:)
141
+ request = AccountOwnersRequest.new(account_id, customers)
142
+ Unit::Resource::AccountResource.add_owners(request)
143
+ end
144
+
145
+ # Remove account owners by calling Unit's API
146
+ # @see https://docs.unit.co/deposit-accounts#account-remove-owners
147
+ # @param account_id [String]
148
+ # @param customers [Array<Customer>]
149
+ # @return [UnitResponse, UnitError]
150
+ def remove_owners(account_id:, customers:)
151
+ request = AccountOwnersRequest.new(account_id, customers)
152
+ Unit::Resource::AccountResource.remove_owners(request)
153
+ end
154
+ end
155
+ end
156
+ end
157
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Request to add or remove owners to a deposit account
4
+ # @see https://docs.unit.co/deposit-accounts#account-add-owners
5
+ # @see https://docs.unit.co/deposit-accounts#account-remove-owners
6
+ module Unit
7
+ module Account
8
+ module Deposit
9
+ class AccountOwnersRequest
10
+ attr_reader :account_id, :customers
11
+
12
+ # @param account_id [String]
13
+ # @param customers [Array<String>]
14
+ def initialize(account_id, customers)
15
+ @account_id = account_id
16
+ @customers = customers
17
+ end
18
+
19
+ def to_json_api
20
+ customers_hash = customers.map do |customer|
21
+ { "type": "customer", "id": customer }
22
+ end
23
+ result = { data: customers_hash }
24
+ result.to_json
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end