unit_ruby_sdk 0.1.3 → 0.1.5
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/README.md +39 -0
- data/lib/unit/api_resources/api_token_resource.rb +59 -0
- data/lib/unit/api_resources/base_resource.rb +5 -1
- data/lib/unit/api_resources/card_resource.rb +104 -0
- data/lib/unit/api_resources/payment_resource.rb +32 -0
- data/lib/unit/api_resources/statement_resource.rb +46 -0
- data/lib/unit/api_resources/transaction_resource.rb +40 -0
- data/lib/unit/models/account/deposit/balance_history_request.rb +1 -1
- 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/list_application_params.rb +1 -1
- data/lib/unit/models/card/card.rb +149 -0
- data/lib/unit/models/card/create_business_debit_card_request.rb +68 -0
- data/lib/unit/models/card/create_business_virtual_debit_card_request.rb +56 -0
- data/lib/unit/models/card/create_individual_debit_card_request.rb +57 -0
- data/lib/unit/models/card/create_individual_virtual_card_request.rb +44 -0
- data/lib/unit/models/card/list_card_params.rb +45 -0
- data/lib/unit/models/card/replace_card_request.rb +31 -0
- data/lib/unit/models/customer/list_customer_params.rb +1 -1
- 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/statement/get_bank_verification_pdf.rb +23 -0
- data/lib/unit/models/statement/get_html_by_id_request.rb +26 -0
- data/lib/unit/models/statement/get_pdf_by_id_request.rb +26 -0
- data/lib/unit/models/statement/list_statement_params.rb +37 -0
- data/lib/unit/models/statement/statement.rb +55 -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/types/restricted_resource.rb +23 -0
- data/lib/unit/utils/http_helper.rb +10 -2
- data/lib/unit/version.rb +1 -1
- data/lib/unit_ruby_sdk.rb +11 -0
- metadata +32 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 00b359a8630b7687c710525b86d5faec0f30dc7771ed820538a12f18e3423d9d
|
4
|
+
data.tar.gz: 6ed3a97d6962f88810a0801e0f7f98a2e5cd8a850fb870b945bb06bc91229af4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cdc7b4d814b87313a2163176589d3c871f6986a9c39eb327a59596ef5ad7531645fe324703e105a0758a5d871da2a9d5cdc8ea30912a2a5983a77ff6d85949d0
|
7
|
+
data.tar.gz: 54884fbeb721faa5a5a8b2b78b91059a3b93af504f70d313e4b87963e33e6944c998d31c52412a61e2da198964bf9030872d39c22fab6db871f42a954c2681e3
|
data/README.md
CHANGED
@@ -14,6 +14,8 @@ gem install unit_ruby_sdk
|
|
14
14
|
|
15
15
|
## Usage
|
16
16
|
|
17
|
+
Bellow are a few exapmles of the Ruby SDK application. For full documentation of the Unit API please refer to the full documentation at https://docs.unit.co/
|
18
|
+
|
17
19
|
### Creating a Business Application
|
18
20
|
|
19
21
|
```ruby
|
@@ -58,6 +60,43 @@ customer = Unit::Customer.list_customers.first
|
|
58
60
|
puts customer.id
|
59
61
|
```
|
60
62
|
|
63
|
+
###
|
64
|
+
### Creating a Payment
|
65
|
+
|
66
|
+
```ruby
|
67
|
+
require 'unit_ruby_sdk'
|
68
|
+
|
69
|
+
response = Unit::Payment.create_book_payment(
|
70
|
+
amount: 10000,
|
71
|
+
description: 'Payment for order #123',
|
72
|
+
relationships: { account: Unit::Types::Relationship.new("depositAccount", "12345").to_hash,
|
73
|
+
counterpartyAccount: Unit::Types::Relationship.new("depositAccount", "36221").to_hash }
|
74
|
+
)
|
75
|
+
payment = response.data
|
76
|
+
puts payment.id
|
77
|
+
```
|
78
|
+
|
79
|
+
### Get a transaction by id
|
80
|
+
|
81
|
+
```ruby
|
82
|
+
response = Unit::Transaction.get_transaction(transaction_id: '12345', account_id: '72345')
|
83
|
+
transaction = response.data
|
84
|
+
puts transaction.id
|
85
|
+
```
|
86
|
+
|
87
|
+
### Creating an individual debit card
|
88
|
+
```ruby
|
89
|
+
response = Unit::Card.create_individual_debit_card(
|
90
|
+
account_id: '1234',
|
91
|
+
type: "depositAccount",
|
92
|
+
shipping_address: address,
|
93
|
+
design: "default",
|
94
|
+
additional_embossed_text: "Second Cardholder"
|
95
|
+
)
|
96
|
+
card = response.data
|
97
|
+
puts card.id
|
98
|
+
```
|
99
|
+
|
61
100
|
### Logging Errors
|
62
101
|
|
63
102
|
```ruby
|
@@ -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
|
@@ -11,6 +11,10 @@ module Unit
|
|
11
11
|
handler.from_json_api(response)
|
12
12
|
end
|
13
13
|
|
14
|
+
def file_response_handler(response)
|
15
|
+
response.code.to_i.between?(200, 299) ? response.body : Unit::UnitError
|
16
|
+
end
|
17
|
+
|
14
18
|
protected
|
15
19
|
|
16
20
|
def api_url
|
@@ -25,7 +29,7 @@ module Unit
|
|
25
29
|
{
|
26
30
|
"Content-Type" => "application/vnd.api+json",
|
27
31
|
"Authorization" => "Bearer #{Unit.config[:token]}",
|
28
|
-
"
|
32
|
+
"X-UNIT-SDK" => "unit-ruby-sdk@v#{Unit::VERSION}"
|
29
33
|
}
|
30
34
|
end
|
31
35
|
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "./base_resource"
|
4
|
+
require_relative "../utils/http_helper"
|
5
|
+
require "json"
|
6
|
+
# class for creating requests for cards to Unit API and parsing responses
|
7
|
+
# @see https://docs.unit.co/cards
|
8
|
+
module Unit
|
9
|
+
module Resource
|
10
|
+
class CardResource < Unit::Resource::BaseResource
|
11
|
+
class << self
|
12
|
+
# Create a new card by calling Unit's API
|
13
|
+
# @param [CreateIndividualDebitCardRequest, CreateIndividualVirtualCardRequest] request
|
14
|
+
# @return [UnitResponse, UnitError]
|
15
|
+
def create_card(request)
|
16
|
+
payload = request.to_json_api
|
17
|
+
response = HttpHelper.post("#{api_url}/cards", body: payload, headers: headers)
|
18
|
+
response_handler(response)
|
19
|
+
end
|
20
|
+
|
21
|
+
# Get pin status by calling Unit's API
|
22
|
+
# @param card_id [String]
|
23
|
+
# @return [UnitResponse, UnitError]
|
24
|
+
def get_pin_status(card_id)
|
25
|
+
response = HttpHelper.get("#{api_url}/cards/#{card_id}/secure-data/pin/status", headers: headers)
|
26
|
+
response_handler(response)
|
27
|
+
end
|
28
|
+
|
29
|
+
# Report a card as a stolen by calling Unit's API
|
30
|
+
# @param card_id [String]
|
31
|
+
# @return [UnitResponse, UnitError]
|
32
|
+
def report_stolen(card_id)
|
33
|
+
response = HttpHelper.post("#{api_url}/cards/#{card_id}/report-stolen", headers: headers)
|
34
|
+
response_handler(response)
|
35
|
+
end
|
36
|
+
|
37
|
+
# Report a card as a lost by calling Unit's API
|
38
|
+
# @param card_id [String]
|
39
|
+
# @return [UnitResponse, UnitError]
|
40
|
+
def report_lost(card_id)
|
41
|
+
response = HttpHelper.post("#{api_url}/cards/#{card_id}/report-lost", headers: headers)
|
42
|
+
response_handler(response)
|
43
|
+
end
|
44
|
+
|
45
|
+
# Close a card by calling Unit's API
|
46
|
+
# @param card_id [String]
|
47
|
+
# @return [UnitResponse, UnitError]
|
48
|
+
def close_card(card_id)
|
49
|
+
response = HttpHelper.post("#{api_url}/cards/#{card_id}/close", headers: headers)
|
50
|
+
response_handler(response)
|
51
|
+
end
|
52
|
+
|
53
|
+
# Freeze a card by calling Unit's API
|
54
|
+
# @param card_id [String]
|
55
|
+
# @return [UnitResponse, UnitError]
|
56
|
+
def freeze_card(card_id)
|
57
|
+
response = HttpHelper.post("#{api_url}/cards/#{card_id}/freeze", headers: headers)
|
58
|
+
response_handler(response)
|
59
|
+
end
|
60
|
+
|
61
|
+
# Unfreeze a card by calling Unit's API
|
62
|
+
# @param card_id [String]
|
63
|
+
# @return [UnitResponse, UnitError]
|
64
|
+
def unfreeze_card(card_id)
|
65
|
+
response = HttpHelper.post("#{api_url}/cards/#{card_id}/unfreeze", headers: headers)
|
66
|
+
response_handler(response)
|
67
|
+
end
|
68
|
+
|
69
|
+
# Replace a card by calling Unit's API
|
70
|
+
# @param request [ReplaceCardRequest]
|
71
|
+
# @return [UnitResponse, UnitError]
|
72
|
+
def replace_card(request)
|
73
|
+
payload = request.to_json_api
|
74
|
+
response = HttpHelper.post("#{api_url}/cards/#{request.card_id}/replace", body: payload, headers: headers)
|
75
|
+
response_handler(response)
|
76
|
+
end
|
77
|
+
|
78
|
+
# Get a card by id by calling Unit's API
|
79
|
+
# @param card_id [String]
|
80
|
+
# @return [UnitResponse, UnitError]
|
81
|
+
def get_card(card_id)
|
82
|
+
response = HttpHelper.get("#{api_url}/cards/#{card_id}", headers: headers)
|
83
|
+
response_handler(response)
|
84
|
+
end
|
85
|
+
|
86
|
+
# List cards by calling Unit's API
|
87
|
+
# @param params [ListCardParams]
|
88
|
+
# @return [UnitResponse, UnitError]
|
89
|
+
def list_cards(params = nil)
|
90
|
+
response = HttpHelper.get("#{api_url}/cards", params: params&.to_hash, headers: headers)
|
91
|
+
response_handler(response)
|
92
|
+
end
|
93
|
+
|
94
|
+
# Get card limits by calling Unit's API
|
95
|
+
# @param card_id [String]
|
96
|
+
# @return [UnitResponse, UnitError]
|
97
|
+
def limits(card_id)
|
98
|
+
response = HttpHelper.get("#{api_url}/cards/#{card_id}/limits", headers: headers)
|
99
|
+
response_handler(response)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
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,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "./base_resource"
|
4
|
+
require_relative "../utils/http_helper"
|
5
|
+
require "json"
|
6
|
+
# class for creating requests for statements to Unit API and parsing responses
|
7
|
+
# @see https://docs.unit.co/cards
|
8
|
+
module Unit
|
9
|
+
module Resource
|
10
|
+
class StatementResource < Unit::Resource::BaseResource
|
11
|
+
class << self
|
12
|
+
# Get statements by calling Unit's API
|
13
|
+
# @param params [ListStatementParams]
|
14
|
+
# @return [UnitResponse, UnitError]
|
15
|
+
def list(params = nil)
|
16
|
+
response = HttpHelper.get("#{api_url}/statements", params: params&.to_hash, headers: headers)
|
17
|
+
response_handler(response)
|
18
|
+
end
|
19
|
+
|
20
|
+
# Get a html statement by id by calling Unit's API
|
21
|
+
# @param params [GetHtmlByIdRequest]
|
22
|
+
# @return [UnitResponse, UnitError]
|
23
|
+
def get_html_by_id(request)
|
24
|
+
response = HttpHelper.get("#{api_url}/statements/#{request.statement_id}/html", params: request.to_hash, headers: headers)
|
25
|
+
file_response_handler(response)
|
26
|
+
end
|
27
|
+
|
28
|
+
# Get a pdf statement by id by calling Unit's API
|
29
|
+
# @param request [GetPdfByIdRequest]
|
30
|
+
# @return [UnitResponse, UnitError]
|
31
|
+
def get_pdf_by_id(request)
|
32
|
+
response = HttpHelper.get("#{api_url}/statements/#{request.statement_id}/pdf", params: request.to_hash, headers: headers)
|
33
|
+
file_response_handler(response)
|
34
|
+
end
|
35
|
+
|
36
|
+
# Get bank verification by calling Unit's API
|
37
|
+
# @param request [GetBankVerificationRequest]
|
38
|
+
# @return [UnitResponse, UnitError]
|
39
|
+
def get_bank_verification(request)
|
40
|
+
response = HttpHelper.get("#{api_url}/statements/#{request.account_id}/bank/pdf", params: request&.to_hash, headers: headers)
|
41
|
+
file_response_handler(response)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
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
|
@@ -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 [Array<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.join(" "),
|
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
|