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
@@ -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
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Request to get the balance history of a deposit account
|
4
|
+
# @see https://docs.unit.co/deposit-accounts#get-account-balance-history
|
5
|
+
module Unit
|
6
|
+
module Account
|
7
|
+
module Deposit
|
8
|
+
class BalanceHistoryRequest
|
9
|
+
attr_reader :limit, :offset, :account_id, :customer_id, :since, :_until
|
10
|
+
|
11
|
+
# @param limit [Integer] - optional
|
12
|
+
# @param offset [Integer] - optional
|
13
|
+
# @param account_id [String] - optional
|
14
|
+
# @param customer_id [String] - optional
|
15
|
+
# @param since [String] - optional
|
16
|
+
# @param _until [String] - optional
|
17
|
+
def initialize(limit = BALANCE_HISTORY_LIMIT, offset = BALANCE_HISTORY_OFFSET, account_id = nil, customer_id = nil,
|
18
|
+
since = nil, _until = nil)
|
19
|
+
@limit = limit
|
20
|
+
@offset = offset
|
21
|
+
@account_id = account_id
|
22
|
+
@customer_id = customer_id
|
23
|
+
@since = since
|
24
|
+
@_until = _until
|
25
|
+
end
|
26
|
+
|
27
|
+
def to_hash
|
28
|
+
params = { "page[limit]": limit,
|
29
|
+
"page[offset]": offset,
|
30
|
+
"filter[accountId]": account_id,
|
31
|
+
"filter[customerId]": customer_id,
|
32
|
+
"filter[since]": since,
|
33
|
+
"filter[until]": _until }
|
34
|
+
params.compact
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Request to close a deposit account
|
4
|
+
# @see https://docs.unit.co/deposit-accounts#close-account
|
5
|
+
module Unit
|
6
|
+
module Account
|
7
|
+
module Deposit
|
8
|
+
class CloseDepositAccountRequest
|
9
|
+
attr_reader :account_id, :reason, :fraud_reason
|
10
|
+
|
11
|
+
# @param account_id [String]
|
12
|
+
# @param reason [String]
|
13
|
+
# @param fraud_reason [String] - optional
|
14
|
+
def initialize(account_id, reason, fraud_reason = nil)
|
15
|
+
@account_id = account_id
|
16
|
+
@reason = reason
|
17
|
+
@fraud_reason = fraud_reason
|
18
|
+
end
|
19
|
+
|
20
|
+
def to_json_api
|
21
|
+
payload = {
|
22
|
+
data: {
|
23
|
+
type: "accountClose",
|
24
|
+
attributes: {
|
25
|
+
reason: reason,
|
26
|
+
fraudReason: fraud_reason
|
27
|
+
}
|
28
|
+
}
|
29
|
+
}
|
30
|
+
payload[:data][:attributes].compact!
|
31
|
+
payload.to_json
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Request to create a deposit account
|
4
|
+
# @see https://docs.unit.co/deposit-accounts#create-deposit-account
|
5
|
+
module Unit
|
6
|
+
module Account
|
7
|
+
module Deposit
|
8
|
+
class CreateDepositAccountRequest
|
9
|
+
attr_reader :deposit_product, :tags, :idempotency_key, :relationships
|
10
|
+
|
11
|
+
# @param deposit_product [String]
|
12
|
+
# @param tags [Hash]- optional
|
13
|
+
# @param idempotency_key [String] - optional
|
14
|
+
# @param relationships [Relationship, RelationshipArray] - optional
|
15
|
+
def initialize(deposit_product, tags = nil, relationships = nil, idempotency_key = nil)
|
16
|
+
@deposit_product = deposit_product
|
17
|
+
@tags = tags
|
18
|
+
@idempotency_key = idempotency_key
|
19
|
+
@relationships = relationships
|
20
|
+
end
|
21
|
+
|
22
|
+
def to_json_api
|
23
|
+
payload = {
|
24
|
+
data: {
|
25
|
+
type: "depositAccount",
|
26
|
+
attributes: {
|
27
|
+
depositProduct: deposit_product,
|
28
|
+
tags: tags
|
29
|
+
},
|
30
|
+
relationships: relationships
|
31
|
+
}
|
32
|
+
}
|
33
|
+
payload[:data][:attributes].compact!
|
34
|
+
payload.to_json
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Request to freeze a deposit account
|
4
|
+
# @see https://docs.unit.co/deposit-accounts#freeze-account
|
5
|
+
module Unit
|
6
|
+
module Account
|
7
|
+
module Deposit
|
8
|
+
class FreezeAccountRequest
|
9
|
+
attr_reader :account_id, :reason, :reason_text
|
10
|
+
|
11
|
+
# @param account_id [String]
|
12
|
+
# @param reason [String]
|
13
|
+
# @param reason_text [String] - optional
|
14
|
+
def initialize(account_id, reason, reason_text = nil)
|
15
|
+
@account_id = account_id
|
16
|
+
@reason = reason
|
17
|
+
@reason_text = reason_text
|
18
|
+
end
|
19
|
+
|
20
|
+
def to_json_api
|
21
|
+
payload = {
|
22
|
+
data: {
|
23
|
+
type: "accountFreeze",
|
24
|
+
attributes: {
|
25
|
+
reason: reason,
|
26
|
+
reasonText: reason_text
|
27
|
+
}
|
28
|
+
}
|
29
|
+
}
|
30
|
+
payload[:data][:attributes].compact!
|
31
|
+
payload.to_json
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# params for listing deposit accounts
|
4
|
+
# @see https://docs.unit.co/deposit-accounts#list-deposit-accounts
|
5
|
+
module Unit
|
6
|
+
module Account
|
7
|
+
module Deposit
|
8
|
+
class ListAccountParams
|
9
|
+
attr_reader :limit, :offset, :customer_id, :tags, :status,
|
10
|
+
:from_balance, :to_balance, :include
|
11
|
+
|
12
|
+
# @param limit [Integer] - optional
|
13
|
+
# @param offset [Integer] - optional
|
14
|
+
# @param customer_id [String] - optional
|
15
|
+
# @param tags [Hash] - optional
|
16
|
+
# @param status [Array<String>] - optional
|
17
|
+
# @param from_balance [Integer] - optional
|
18
|
+
# @param to_balance [Integer] - optional
|
19
|
+
# @param include [Array] - optional
|
20
|
+
def initialize(limit = ACCOUNT_LIST_LIMIT, offset = ACCOUNT_LIST_OFFSET, customer_id = nil, tags = nil,
|
21
|
+
status = nil, from_balance = nil, to_balance = nil, include = nil)
|
22
|
+
@limit = limit
|
23
|
+
@offset = offset
|
24
|
+
@customer_id = customer_id
|
25
|
+
@tags = tags
|
26
|
+
@status = status
|
27
|
+
@from_balance = from_balance
|
28
|
+
@to_balance = to_balance
|
29
|
+
@include = include
|
30
|
+
end
|
31
|
+
|
32
|
+
def to_hash
|
33
|
+
params = { "page[limit]": limit,
|
34
|
+
"page[offset]": offset,
|
35
|
+
"filter[customerId]": customer_id,
|
36
|
+
"filter[tags]": tags,
|
37
|
+
"filter[fromBalance]": from_balance,
|
38
|
+
"filter[toBalance]": to_balance,
|
39
|
+
"include": include&.join(",") }
|
40
|
+
status&.each_with_index&.map do |val, index|
|
41
|
+
params.merge!({ "filter[status][#{index}]": val })
|
42
|
+
end
|
43
|
+
params.compact
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Request to update a deposit account
|
4
|
+
# @see https://docs.unit.co/deposit-accounts#update-accounts
|
5
|
+
module Unit
|
6
|
+
module Account
|
7
|
+
module Deposit
|
8
|
+
class PatchDepositAccountRequest
|
9
|
+
attr_reader :account_id, :tags, :deposit_product
|
10
|
+
|
11
|
+
# @param account_id [String]
|
12
|
+
# @param tags [Hash] - optional
|
13
|
+
# @param deposit_product [String] - optional
|
14
|
+
def initialize(account_id, tags = nil, deposit_product = nil)
|
15
|
+
@account_id = account_id
|
16
|
+
@tags = tags
|
17
|
+
@deposit_product = deposit_product
|
18
|
+
end
|
19
|
+
|
20
|
+
def to_json_api
|
21
|
+
payload = {
|
22
|
+
data: {
|
23
|
+
type: "depositAccount",
|
24
|
+
attributes: {
|
25
|
+
tags: tags,
|
26
|
+
depositProduct: deposit_product
|
27
|
+
}
|
28
|
+
}
|
29
|
+
}
|
30
|
+
payload[:data][:attributes].compact!
|
31
|
+
payload.to_json
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Unit
|
4
|
+
module ApiToken
|
5
|
+
module Org
|
6
|
+
autoload :CreateApiTokenRequest, "unit/models/api_token/org/create_api_token_request"
|
7
|
+
|
8
|
+
class << self
|
9
|
+
# Create a new Org API api_token by calling Unit's API
|
10
|
+
# @see https://docs.unit.co/org-api-tokens#create-org-api-token
|
11
|
+
# @param user_id [String]
|
12
|
+
# @param description [String]
|
13
|
+
# @param scope [Array<String>]
|
14
|
+
# @param expiration [Datetime]
|
15
|
+
# @param source_ip [String] - optional
|
16
|
+
# @param resources [Array<RestrictedResource>] - optional
|
17
|
+
# @return [UnitResponse, UnitError]
|
18
|
+
def create_api_token(user_id:, description:, scope:, expiration:, source_ip: nil, resources: nil)
|
19
|
+
request = CreateApiTokenRequest.new(user_id, description, scope, expiration, source_ip, resources)
|
20
|
+
Unit::Resource::ApiTokenResource.create_org_api_token(request)
|
21
|
+
end
|
22
|
+
|
23
|
+
# Get Org API tokens by calling Unit's API
|
24
|
+
# @see https://docs.unit.co/org-api-tokens#list-org-api-tokens
|
25
|
+
# @param user_id [String]
|
26
|
+
# @return [UnitResponse, UnitError]
|
27
|
+
def list_tokens(user_id:)
|
28
|
+
Unit::Resource::ApiTokenResource.list_org_tokens(user_id)
|
29
|
+
end
|
30
|
+
|
31
|
+
# Revoke Org API api_token by calling Unit's API
|
32
|
+
# @see https://docs.unit.co/org-api-tokens#revoke-org-api-token
|
33
|
+
# @param user_id [String]
|
34
|
+
# @param token_id [String]
|
35
|
+
# @return [UnitResponse, UnitError]
|
36
|
+
def revoke_token(user_id:, token_id:)
|
37
|
+
Unit::Resource::ApiTokenResource.revoke_org_token(user_id, token_id)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
module Customer
|
43
|
+
autoload :CreateCustomerTokenRequest, "unit/models/api_token/customer/create_customer_token_request"
|
44
|
+
autoload :CreateTokenUsingJwtRequest, "unit/models/api_token/customer/create_token_using_jwt_request"
|
45
|
+
autoload :CreateCustomerTokenVerification, "unit/models/api_token/customer/create_customer_token_verification"
|
46
|
+
|
47
|
+
class << self
|
48
|
+
# Create customer token by calling Unit's API
|
49
|
+
# @see https://docs.unit.co/customer-api-tokens#customers-create-customer-bearer-token
|
50
|
+
# @param customer_id [String]
|
51
|
+
# @param scope [Array<String>]
|
52
|
+
# @param verification_token [String]
|
53
|
+
# @param verification_code [String] - optional
|
54
|
+
# @param expires_in [Integer] - optional
|
55
|
+
# @param resources [Array<RestrictedResource>] - optional
|
56
|
+
# @return [UnitResponse, UnitError]
|
57
|
+
def create_customer_token(customer_id:, scope:, verification_token:, verification_code: nil, expires_in: nil,
|
58
|
+
resources: nil)
|
59
|
+
request = CreateCustomerTokenRequest.new(customer_id, scope, verification_token, verification_code, expires_in, resources)
|
60
|
+
Unit::Resource::ApiTokenResource.create_customer_token(request)
|
61
|
+
end
|
62
|
+
|
63
|
+
# Create customer token using JWT by calling Unit's API
|
64
|
+
# @see https://docs.unit.co/customer-api-tokens#customers-create-customer-bearer-token-jwt
|
65
|
+
# @param customer_id [String]
|
66
|
+
# @param scope [Array<String>]
|
67
|
+
# @param jwt_token [String] - optional
|
68
|
+
# @return [UnitResponse, UnitError]
|
69
|
+
def create_customer_token_with_jwt(customer_id:, scope:, jwt_token: nil)
|
70
|
+
request = CreateTokenUsingJwtRequest.new(customer_id, scope, jwt_token)
|
71
|
+
Unit::Resource::ApiTokenResource.create_customer_token(request)
|
72
|
+
end
|
73
|
+
|
74
|
+
# Create customer token verification by calling Unit's API
|
75
|
+
# @see https://docs.unit.co/customer-api-tokens#customers-customer-token-verification
|
76
|
+
# @param customer_id [String]
|
77
|
+
# @param channel [String]
|
78
|
+
# @param phone [Phone] - optional
|
79
|
+
# @param app_hash [String] - optional
|
80
|
+
# @param language [String] - optional
|
81
|
+
# @return [UnitResponse, UnitError]
|
82
|
+
def create_customer_token_verification(customer_id:, channel:, phone: nil, app_hash: nil, language: nil)
|
83
|
+
request = CreateCustomerTokenVerification.new(customer_id, channel, phone, app_hash, language)
|
84
|
+
Unit::Resource::ApiTokenResource.create_token_verification(request)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Request to create a customer token
|
4
|
+
# @see https://docs.unit.co/customer-api-tokens#customers-create-customer-bearer-token
|
5
|
+
module Unit
|
6
|
+
module ApiToken
|
7
|
+
module Customer
|
8
|
+
class CreateCustomerTokenRequest
|
9
|
+
attr_reader :customer_id, :scope, :verification_token, :verification_code, :expires_in, :resources
|
10
|
+
|
11
|
+
# @param customer_id [String]
|
12
|
+
# @param scope [Array<String>]
|
13
|
+
# @param verification_token [String] - optional
|
14
|
+
# @param verification_code [String] - optional
|
15
|
+
# @param expires_in [Integer] - optional
|
16
|
+
# @param resources [Array<RestrictedResource>] - optional
|
17
|
+
def initialize(customer_id, scope, verification_token, verification_code = nil,
|
18
|
+
expires_in = nil, resources = nil)
|
19
|
+
@customer_id = customer_id
|
20
|
+
@scope = scope
|
21
|
+
@verification_token = verification_token
|
22
|
+
@verification_code = verification_code
|
23
|
+
@expires_in = expires_in
|
24
|
+
@resources = resources
|
25
|
+
end
|
26
|
+
|
27
|
+
def to_json_api
|
28
|
+
result = { data: { type: "customerToken",
|
29
|
+
attributes:
|
30
|
+
{ scope: scope&.join(" "),
|
31
|
+
verificationToken: verification_token,
|
32
|
+
verificationCode: verification_code,
|
33
|
+
expiresIn: expires_in,
|
34
|
+
resources: resources } } }
|
35
|
+
result[:data][:attributes].compact!
|
36
|
+
result.to_json
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Request to create a customer token verification
|
4
|
+
# @see https://docs.unit.co/customer-api-tokens#customers-customer-token-verification
|
5
|
+
module Unit
|
6
|
+
module ApiToken
|
7
|
+
module Customer
|
8
|
+
class CreateCustomerTokenVerification
|
9
|
+
attr_reader :customer_id, :channel, :phone, :app_hash, :language
|
10
|
+
|
11
|
+
# @param customer_id [String]
|
12
|
+
# @param channel [String]
|
13
|
+
# @param phone [Phone] - optional
|
14
|
+
# @param app_hash [String] - optional
|
15
|
+
# @param language [String] - optional
|
16
|
+
def initialize(customer_id, channel, phone = nil, app_hash = nil, language = nil)
|
17
|
+
@customer_id = customer_id
|
18
|
+
@channel = channel
|
19
|
+
@phone = phone
|
20
|
+
@app_hash = app_hash
|
21
|
+
@language = language
|
22
|
+
end
|
23
|
+
|
24
|
+
def to_json_api
|
25
|
+
result = { data: { type: "customerTokenVerification",
|
26
|
+
attributes:
|
27
|
+
{ channel: channel,
|
28
|
+
phone: phone&.represent,
|
29
|
+
appHash: app_hash,
|
30
|
+
language: language } } }
|
31
|
+
result[:data][:attributes].compact!
|
32
|
+
result.to_json
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Request to create Customer token using JWT
|
4
|
+
# @see https://docs.unit.co/customer-api-tokens#customers-create-customer-bearer-token-jwt
|
5
|
+
module Unit
|
6
|
+
module ApiToken
|
7
|
+
module Customer
|
8
|
+
class CreateTokenUsingJwtRequest
|
9
|
+
attr_reader :customer_id, :scope, :jwt_token
|
10
|
+
|
11
|
+
# @param scope [Array<String>]
|
12
|
+
# @param jwt_token [String]
|
13
|
+
def initialize(customer_id, scope, jwt_token = nil)
|
14
|
+
@customer_id = customer_id
|
15
|
+
@scope = scope
|
16
|
+
@jwt_token = jwt_token
|
17
|
+
end
|
18
|
+
|
19
|
+
def to_json_api
|
20
|
+
result = { data: { type: "customerToken",
|
21
|
+
attributes:
|
22
|
+
{ scope: scope&.join(" "),
|
23
|
+
jwtToken: jwt_token } } }
|
24
|
+
result[:data][:attributes].compact!
|
25
|
+
result.to_json
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Request to create an org API token
|
4
|
+
# @see https://docs.unit.co/org-api-tokens#create-org-api-token
|
5
|
+
module Unit
|
6
|
+
module ApiToken
|
7
|
+
module Org
|
8
|
+
class CreateApiTokenRequest
|
9
|
+
attr_reader :user_id, :description, :scope, :expiration, :source_ip, :resources
|
10
|
+
|
11
|
+
# @param user_id [String]
|
12
|
+
# @param description [String]
|
13
|
+
# @param scope [String]
|
14
|
+
# @param expiration [String]
|
15
|
+
# @param source_ip [String] - optional
|
16
|
+
# @param resources [Array<RestrictedResource>] - optional
|
17
|
+
def initialize(user_id, description, scope, expiration, source_ip = nil, resources = nil)
|
18
|
+
@user_id = user_id
|
19
|
+
@description = description
|
20
|
+
@scope = scope
|
21
|
+
@expiration = expiration
|
22
|
+
@source_ip = source_ip
|
23
|
+
@resources = resources
|
24
|
+
end
|
25
|
+
|
26
|
+
def to_json_api
|
27
|
+
result = { data: { type: "apiToken",
|
28
|
+
attributes:
|
29
|
+
{ description: description,
|
30
|
+
scope: scope,
|
31
|
+
expiration: expiration,
|
32
|
+
sourceIp: source_ip,
|
33
|
+
resources: resources } } }
|
34
|
+
result[:data][:attributes].compact!
|
35
|
+
result.to_json
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|