unit_ruby_sdk 0.1.2 → 0.1.4
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.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -0
- data/Gemfile +0 -10
- data/README.md +97 -1
- data/lib/unit/api_resources/account_resource.rb +125 -0
- data/lib/unit/api_resources/api_token_resource.rb +59 -0
- data/lib/unit/api_resources/application_resource.rb +9 -9
- data/lib/unit/api_resources/base_resource.rb +3 -11
- data/lib/unit/api_resources/customer_resource.rb +12 -11
- data/lib/unit/api_resources/payment_resource.rb +32 -0
- data/lib/unit/api_resources/transaction_resource.rb +40 -0
- data/lib/unit/errors/unit_error.rb +7 -13
- data/lib/unit/errors/unit_error_payload.rb +15 -2
- data/lib/unit/models/account/account.rb +157 -0
- data/lib/unit/models/account/deposit/account_owners_request.rb +29 -0
- data/lib/unit/models/account/deposit/balance_history_request.rb +39 -0
- data/lib/unit/models/account/deposit/close_deposit_account_request.rb +36 -0
- data/lib/unit/models/account/deposit/create_deposit_account_request.rb +39 -0
- data/lib/unit/models/account/deposit/freeze_account_request.rb +36 -0
- data/lib/unit/models/account/deposit/list_account_params.rb +48 -0
- data/lib/unit/models/account/deposit/patch_deposit_account_request.rb +36 -0
- data/lib/unit/models/api_token/api_token.rb +89 -0
- data/lib/unit/models/api_token/customer/create_customer_token_request.rb +41 -0
- data/lib/unit/models/api_token/customer/create_customer_token_verification.rb +37 -0
- data/lib/unit/models/api_token/customer/create_token_using_jwt_request.rb +30 -0
- data/lib/unit/models/api_token/org/create_api_token_request.rb +40 -0
- data/lib/unit/models/application/application.rb +127 -0
- data/lib/unit/models/application/create_business_application_request.rb +7 -7
- data/lib/unit/models/application/create_individual_application_request.rb +14 -14
- data/lib/unit/models/application/list_application_params.rb +4 -4
- data/lib/unit/models/application/patch_application_request.rb +3 -3
- data/lib/unit/models/application/upload_document_request.rb +1 -1
- data/lib/unit/models/customer/add_authorized_users_request.rb +3 -3
- data/lib/unit/models/customer/archive_customer_request.rb +3 -4
- data/lib/unit/models/customer/customer.rb +96 -0
- data/lib/unit/models/customer/list_customer_params.rb +10 -12
- data/lib/unit/models/customer/patch_business_customer_request.rb +8 -8
- data/lib/unit/models/customer/patch_individual_customer_request.rb +9 -10
- data/lib/unit/models/customer/remove_authorized_users_request.rb +3 -3
- data/lib/unit/models/payment/create_book_payment_request.rb +49 -0
- data/lib/unit/models/payment/patch_book_payment_request.rb +31 -0
- data/lib/unit/models/payment/payment.rb +37 -0
- data/lib/unit/models/transaction/get_transaction_params.rb +28 -0
- data/lib/unit/models/transaction/list_transaction_params.rb +70 -0
- data/lib/unit/models/transaction/patch_tags_request.rb +33 -0
- data/lib/unit/models/transaction/transaction.rb +60 -0
- data/lib/unit/models/unit_response.rb +7 -1
- data/lib/unit/types/authorized_user.rb +1 -1
- data/lib/unit/types/relationship.rb +4 -5
- data/lib/unit/types/relationship_array.rb +14 -12
- data/lib/unit/types/restricted_resource.rb +23 -0
- data/lib/unit/utils/http_helper.rb +56 -0
- data/lib/unit/version.rb +1 -1
- data/lib/unit_ruby_sdk.rb +22 -21
- metadata +76 -7
- data/Gemfile.lock +0 -133
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 14fc2502ef67bd580d1fb1d8ed06af33d22d99161bce1fa79ea98ac7acc9dad6
|
4
|
+
data.tar.gz: c0df3342ca09be9cb8f3ded2ff6717f188620716b0a8118b7850a19143b0ab4e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1270a0a50b9e23a8608716098ea341708a18233d290e124416aed5be9a564a28e4c4d7b4f1c59a8224e74ae54746dc51c3908bdf1bb790df79dc810ba173602f
|
7
|
+
data.tar.gz: 5f4fac2c94ec93621ca4541ebc9c80a1bc0f2c0590f8503a1133d7b4fe437b783c0488ea42665f771d212c7959ac91837229f7917eec148ea7246e272a78a066
|
data/.rubocop.yml
CHANGED
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,97 @@
|
|
1
|
-
#
|
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
|
+
###
|
62
|
+
### Creating a Payment
|
63
|
+
|
64
|
+
```ruby
|
65
|
+
require 'unit_ruby_sdk'
|
66
|
+
|
67
|
+
response = Unit::Payment.create_book_payment(
|
68
|
+
amount: 10000,
|
69
|
+
description: 'Payment for order #123',
|
70
|
+
relationships: { account: Unit::Types::Relationship.new("depositAccount", "12345").to_hash,
|
71
|
+
counterpartyAccount: Unit::Types::Relationship.new("depositAccount", "36221").to_hash }
|
72
|
+
)
|
73
|
+
payment = response.data
|
74
|
+
puts payment.id
|
75
|
+
```
|
76
|
+
|
77
|
+
### Get a transaction by id
|
78
|
+
|
79
|
+
```ruby
|
80
|
+
response = Unit::Transaction.get_transaction(transaction_id: '12345', account_id: '72345')
|
81
|
+
transaction = response.data
|
82
|
+
puts transaction.id
|
83
|
+
```
|
84
|
+
|
85
|
+
### Logging Errors
|
86
|
+
|
87
|
+
```ruby
|
88
|
+
require 'unit_ruby_sdk'
|
89
|
+
|
90
|
+
Unit.config(api_url: ENV['API_URL'], token: "missing token")
|
91
|
+
|
92
|
+
# response is a Unit::UnitError
|
93
|
+
response = Unit::Application.get_application('123')
|
94
|
+
|
95
|
+
# Prints "Bearer token is missing"
|
96
|
+
response.errors.each{|error| puts error.title}
|
97
|
+
```
|
@@ -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
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "./base_resource"
|
4
|
+
require_relative "../utils/http_helper"
|
5
|
+
|
6
|
+
# class for creating new API tokens' requests
|
7
|
+
# @see https://docs.unit.co/org-api-tokens
|
8
|
+
# @see https://docs.unit.co/customer-api-tokens
|
9
|
+
module Unit
|
10
|
+
module Resource
|
11
|
+
class ApiTokenResource < Unit::Resource::BaseResource
|
12
|
+
class << self
|
13
|
+
# Create a new Org API api_token by calling Unit's API
|
14
|
+
# @param request [CreateApiTokenRequest]
|
15
|
+
# @return [UnitResponse, UnitError]
|
16
|
+
def create_org_api_token(request)
|
17
|
+
payload = request.to_json_api
|
18
|
+
response = HttpHelper.post("#{api_url}/users/#{request.user_id}/api-tokens", body: payload, headers: headers)
|
19
|
+
response_handler(response)
|
20
|
+
end
|
21
|
+
|
22
|
+
# Get Org API tokens by calling Unit's API
|
23
|
+
# @param user_id [String]
|
24
|
+
# @return [UnitResponse, UnitError]
|
25
|
+
def list_org_tokens(user_id)
|
26
|
+
response = HttpHelper.get("#{api_url}/users/#{user_id}/api-tokens", headers: headers)
|
27
|
+
response_handler(response)
|
28
|
+
end
|
29
|
+
|
30
|
+
# Revoke Org API api_token by calling Unit's API
|
31
|
+
# @param user_id [String]
|
32
|
+
# @param token_id [String]
|
33
|
+
# @return [UnitResponse, UnitError]
|
34
|
+
def revoke_org_token(user_id, token_id)
|
35
|
+
response = HttpHelper.delete("#{api_url}/users/#{user_id}/api-tokens/#{token_id}", headers: headers)
|
36
|
+
response_handler(response)
|
37
|
+
end
|
38
|
+
|
39
|
+
# Create customer token by calling Unit's API
|
40
|
+
# @param [CreateCustomerTokenRequest, CreateCustomerTokenUsingJwtRequest] request
|
41
|
+
# @return [UnitResponse, UnitError]
|
42
|
+
def create_customer_token(request)
|
43
|
+
payload = request.to_json_api
|
44
|
+
response = HttpHelper.post("#{api_url}/customers/#{request.customer_id}/token", headers: headers, body: payload)
|
45
|
+
response_handler(response)
|
46
|
+
end
|
47
|
+
|
48
|
+
# Create customer token verification by calling Unit's API
|
49
|
+
# @param [CreateCustomerTokenVerification] request
|
50
|
+
# @return [UnitResponse, UnitError]
|
51
|
+
def create_token_verification(request)
|
52
|
+
payload = request.to_json_api
|
53
|
+
response = HttpHelper.post("#{api_url}/customers/#{request.customer_id}/token/verification", body: payload, headers: headers)
|
54
|
+
response_handler(response)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
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
|
-
#
|
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 =
|
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 [
|
22
|
+
# @param [String] application_id
|
23
23
|
# @return [UnitResponse, UnitError]
|
24
24
|
def get_application(application_id)
|
25
|
-
response =
|
25
|
+
response = HttpHelper.get("#{api_url}/applications/#{application_id}", headers: headers)
|
26
26
|
response_handler(response)
|
27
27
|
end
|
28
28
|
|
29
|
-
#
|
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 =
|
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 =
|
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 =
|
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 [
|
8
|
+
# @param [HTTP::Response] response
|
11
9
|
def response_handler(response)
|
12
|
-
|
13
|
-
|
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
|
-
#
|
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 =
|
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 =
|
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 =
|
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 =
|
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 =
|
55
|
-
|
56
|
-
|
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 =
|
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
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "./base_resource"
|
4
|
+
require_relative "../utils/http_helper"
|
5
|
+
|
6
|
+
# class for creating requests for book payments to Unit API and parsing responses
|
7
|
+
# @see https://docs.unit.co/book-payments#book-payments
|
8
|
+
module Unit
|
9
|
+
module Resource
|
10
|
+
class PaymentResource < Unit::Resource::BaseResource
|
11
|
+
class << self
|
12
|
+
# Create a new book payment by calling Unit's API
|
13
|
+
# @param request [CreatePaymentRequest]
|
14
|
+
# @return [UnitResponse, UnitError]
|
15
|
+
def create_payment(request)
|
16
|
+
payload = request.to_json_api
|
17
|
+
response = HttpHelper.post("#{api_url}/payments", body: payload, headers: headers)
|
18
|
+
response_handler(response)
|
19
|
+
end
|
20
|
+
|
21
|
+
# Update a book payment by calling Unit's API
|
22
|
+
# @param request [PatchBookPaymentRequest]
|
23
|
+
# @return [UnitResponse, UnitError]
|
24
|
+
def update_payment(request)
|
25
|
+
payload = request.to_json_api
|
26
|
+
response = HttpHelper.patch("#{api_url}/payments/#{request.payment_id}", body: payload, headers: headers)
|
27
|
+
response_handler(response)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,40 @@
|
|
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 requests for transactions to Unit API and parsing responses
|
8
|
+
# @see https://docs.unit.co/transactions
|
9
|
+
module Unit
|
10
|
+
module Resource
|
11
|
+
class TransactionResource < Unit::Resource::BaseResource
|
12
|
+
class << self
|
13
|
+
# Get a transaction by id by calling Unit's API
|
14
|
+
# @param params [GetTransactionParams]
|
15
|
+
# @return [UnitResponse, UnitError]
|
16
|
+
def get_transaction(params)
|
17
|
+
response = HttpHelper.get("#{api_url}/accounts/#{params.account_id}/transactions/#{params.transaction_id}", params: params.to_hash, headers: headers)
|
18
|
+
response_handler(response)
|
19
|
+
end
|
20
|
+
|
21
|
+
# Get transactions by calling Unit's API
|
22
|
+
# @param params [ListTransactionParams]
|
23
|
+
# @return [UnitResponse, UnitError]
|
24
|
+
def list_transactions(params = nil)
|
25
|
+
response = HttpHelper.get("#{api_url}/transactions", params: params.to_hash, headers: headers)
|
26
|
+
response_handler(response)
|
27
|
+
end
|
28
|
+
|
29
|
+
# Update a transaction by calling Unit's API
|
30
|
+
# @param request [PatchTagsRequest]
|
31
|
+
# @return [UnitResponse, UnitError]
|
32
|
+
def update_tags(request)
|
33
|
+
payload = request.to_json_api
|
34
|
+
response = HttpHelper.patch("#{api_url}/accounts/#{request.account_id}/transactions/#{request.transaction_id}", body: payload, headers: headers)
|
35
|
+
response_handler(response)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
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
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
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
|