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.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +39 -0
  3. data/lib/unit/api_resources/api_token_resource.rb +59 -0
  4. data/lib/unit/api_resources/base_resource.rb +5 -1
  5. data/lib/unit/api_resources/card_resource.rb +104 -0
  6. data/lib/unit/api_resources/payment_resource.rb +32 -0
  7. data/lib/unit/api_resources/statement_resource.rb +46 -0
  8. data/lib/unit/api_resources/transaction_resource.rb +40 -0
  9. data/lib/unit/models/account/deposit/balance_history_request.rb +1 -1
  10. data/lib/unit/models/api_token/api_token.rb +89 -0
  11. data/lib/unit/models/api_token/customer/create_customer_token_request.rb +41 -0
  12. data/lib/unit/models/api_token/customer/create_customer_token_verification.rb +37 -0
  13. data/lib/unit/models/api_token/customer/create_token_using_jwt_request.rb +30 -0
  14. data/lib/unit/models/api_token/org/create_api_token_request.rb +40 -0
  15. data/lib/unit/models/application/list_application_params.rb +1 -1
  16. data/lib/unit/models/card/card.rb +149 -0
  17. data/lib/unit/models/card/create_business_debit_card_request.rb +68 -0
  18. data/lib/unit/models/card/create_business_virtual_debit_card_request.rb +56 -0
  19. data/lib/unit/models/card/create_individual_debit_card_request.rb +57 -0
  20. data/lib/unit/models/card/create_individual_virtual_card_request.rb +44 -0
  21. data/lib/unit/models/card/list_card_params.rb +45 -0
  22. data/lib/unit/models/card/replace_card_request.rb +31 -0
  23. data/lib/unit/models/customer/list_customer_params.rb +1 -1
  24. data/lib/unit/models/payment/create_book_payment_request.rb +49 -0
  25. data/lib/unit/models/payment/patch_book_payment_request.rb +31 -0
  26. data/lib/unit/models/payment/payment.rb +37 -0
  27. data/lib/unit/models/statement/get_bank_verification_pdf.rb +23 -0
  28. data/lib/unit/models/statement/get_html_by_id_request.rb +26 -0
  29. data/lib/unit/models/statement/get_pdf_by_id_request.rb +26 -0
  30. data/lib/unit/models/statement/list_statement_params.rb +37 -0
  31. data/lib/unit/models/statement/statement.rb +55 -0
  32. data/lib/unit/models/transaction/get_transaction_params.rb +28 -0
  33. data/lib/unit/models/transaction/list_transaction_params.rb +70 -0
  34. data/lib/unit/models/transaction/patch_tags_request.rb +33 -0
  35. data/lib/unit/models/transaction/transaction.rb +60 -0
  36. data/lib/unit/types/restricted_resource.rb +23 -0
  37. data/lib/unit/utils/http_helper.rb +10 -2
  38. data/lib/unit/version.rb +1 -1
  39. data/lib/unit_ruby_sdk.rb +11 -0
  40. metadata +32 -2
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Request to list statements
4
+ # @see https://docs.unit.co/statements#list-statements
5
+ module Unit
6
+ module Statement
7
+ class ListStatementParams
8
+ attr_reader :limit, :offset, :account_id, :customer_id, :period, :sort
9
+
10
+ # @param limit [Integer] - optional
11
+ # @param offset [Integer] - optional
12
+ # @param account_id [String] - optional
13
+ # @param customer_id [String] - optional
14
+ # @param period [String] - optional
15
+ # @param sort [String] - optional
16
+ def initialize(limit = STATEMENT_LIST_LIMIT, offset = STATEMENT_LIST_OFFSET,
17
+ account_id = nil, customer_id = nil, period = nil, sort = nil)
18
+ @limit = limit
19
+ @offset = offset
20
+ @account_id = account_id
21
+ @customer_id = customer_id
22
+ @period = period
23
+ @sort = sort
24
+ end
25
+
26
+ def to_hash
27
+ params = { "page[limit]": limit,
28
+ "page[offset]": offset,
29
+ "filter[accountId]": account_id,
30
+ "filter[customerId]": customer_id,
31
+ "filter[period]": period,
32
+ "sort": sort }
33
+ params.compact
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Unit
4
+ module Statement
5
+ STATEMENT_LIST_LIMIT = 100
6
+ STATEMENT_LIST_OFFSET = 0
7
+ autoload :ListStatementParams, "unit/models/statement/list_statement_params"
8
+ autoload :GetPdfByIdRequest, "unit/models/statement/get_pdf_by_id_request"
9
+ autoload :GetHtmlByIdRequest, "unit/models/statement/get_html_by_id_request"
10
+ autoload :GetBankVerificationPdf, "unit/models/statement/get_bank_verification_pdf"
11
+
12
+ class << self
13
+ # List statements
14
+ # @see https://docs.unit.co/statements#list-statements
15
+ # @param limit [Integer]
16
+ # @param offset [Integer]
17
+ # @param account_id [String]
18
+ # @param customer_id [String]
19
+ # @param period [String]
20
+ # @param sort [String]
21
+ def list_statements(limit: STATEMENT_LIST_LIMIT, offset: STATEMENT_LIST_OFFSET,
22
+ account_id: nil, customer_id: nil, period: nil, sort: nil)
23
+ params = ListStatementParams.new(limit, offset, account_id, customer_id, period, sort)
24
+ Unit::Resource::StatementResource.list(params)
25
+ end
26
+
27
+ # Get statement pdf by id
28
+ # @see https://docs.unit.co/statements#get-statement-pdf
29
+ # @param customer_id [String]
30
+ # @param language [String]
31
+ def get_pdf_by_id(statement_id:, customer_id:, language: nil)
32
+ request = GetPdfByIdRequest.new(statement_id, customer_id, language)
33
+ Unit::Resource::StatementResource.get_pdf_by_id(request)
34
+ end
35
+
36
+ # Get statement html by id
37
+ # @see https://docs.unit.co/statements#get-statement-html
38
+ # @param customer_id [String]
39
+ # @param language [String]
40
+ def get_html_by_id(statement_id:, customer_id:, language: nil)
41
+ request = GetHtmlByIdRequest.new(statement_id, customer_id, language)
42
+ Unit::Resource::StatementResource.get_html_by_id(request)
43
+ end
44
+
45
+ # Get a bank verification pdf
46
+ # @see https://docs.unit.co/statements#get-bank-verification-pdf
47
+ # @param account_id [String]
48
+ # @param include_proof_of_funds [Boolean]
49
+ def get_bank_verification_pdf(account_id:, include_proof_of_funds: false)
50
+ request = GetBankVerificationPdf.new(account_id, include_proof_of_funds: include_proof_of_funds)
51
+ Unit::Resource::StatementResource.get_bank_verification(request)
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Request to get a transaction
4
+ # @see https://docs.unit.co/transactions#get-specific-transaction
5
+ module Unit
6
+ module Transaction
7
+ class GetTransactionParams
8
+ attr_accessor :transaction_id, :account_id, :customer_id, :include
9
+
10
+ # @param transaction_id [String]
11
+ # @param account_id [String]
12
+ # @param customer_id [String] - optional
13
+ # @param include [Array<String>] - optional
14
+ def initialize(transaction_id, account_id, customer_id = nil, include = nil)
15
+ @transaction_id = transaction_id
16
+ @account_id = account_id
17
+ @customer_id = customer_id
18
+ @include = include
19
+ end
20
+
21
+ def to_hash
22
+ params = { "filter[customerId]": customer_id,
23
+ "include": include&.join(",") }
24
+ params.compact
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,70 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Request to list transactions
4
+ # @see https://docs.unit.co/transactions#list-transactions
5
+ module Unit
6
+ module Transaction
7
+ class ListTransactionParams
8
+ attr_reader :limit, :offset, :account_id, :customer_id, :query, :tags, :since, :_until, :card_id, :type, :from_amount, :to_amount, :direction, :exclude_fees, :sort, :include
9
+
10
+ # @param limit [Integer] - optional
11
+ # @param offset [Integer] - optional
12
+ # @param account_id [String] - optional
13
+ # @param customer_id [String] - optional
14
+ # @param query [String] - optional
15
+ # @param tags [String] - optional
16
+ # @param since [String] - optional
17
+ # @param _until [String] - optional
18
+ # @param card_id [String] - optional
19
+ # @param type [Array<String>] - optional
20
+ # @param from_amount [Integer] - optional
21
+ # @param to_amount [Integer] - optional
22
+ # @param direction [String] - optional
23
+ # @param exclude_fees [Boolean] - optional
24
+ # @param sort [String] - optional
25
+ # @param include [Array<String>] - optional
26
+ def initialize(limit = TRANSACTION_LIST_LIMIT, offset = TRANSACTION_LIST_OFFSET, account_id = nil, customer_id = nil,
27
+ query = nil, tags = nil, since = nil, _until = nil, card_id = nil, type = nil, from_amount = nil, to_amount = nil,
28
+ direction = nil, exclude_fees = nil, sort = nil, include = nil)
29
+ @limit = limit
30
+ @offset = offset
31
+ @account_id = account_id
32
+ @customer_id = customer_id
33
+ @query = query
34
+ @tags = tags
35
+ @since = since
36
+ @_until = _until
37
+ @card_id = card_id
38
+ @type = type
39
+ @from_amount = from_amount
40
+ @to_amount = to_amount
41
+ @direction = direction
42
+ @exclude_fees = exclude_fees
43
+ @sort = sort
44
+ @include = include
45
+ end
46
+
47
+ def to_hash
48
+ params = { "page[limit]": limit,
49
+ "page[offset]": offset,
50
+ "filter[accountId]": account_id,
51
+ "filter[customerId]": customer_id,
52
+ "filter[query]": query,
53
+ "filter[tags]": tags,
54
+ "filter[since]": since,
55
+ "filter[until]": _until,
56
+ "filter[cardId]": card_id,
57
+ "filter[fromAmount]": from_amount,
58
+ "filter[toAmount]": to_amount,
59
+ "filter[direction]": direction,
60
+ "excludeFees": exclude_fees,
61
+ "sort": sort,
62
+ "include": include&.join(",") }
63
+ type&.each_with_index&.map do |val, index|
64
+ params.merge!({ "filter[type][#{index}]": val })
65
+ end
66
+ params.compact
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Request to update a transaction's tags
4
+ # @see https://docs.unit.co/transactions#update-transaction-tags
5
+ module Unit
6
+ module Transaction
7
+ class PatchTagsRequest
8
+ attr_accessor :account_id, :transaction_id, :tags
9
+
10
+ # @param account_id [String]
11
+ # @param transaction_id [String]
12
+ # @param tags [Hash] - optional
13
+ def initialize(account_id, transaction_id, tags = nil)
14
+ @account_id = account_id
15
+ @transaction_id = transaction_id
16
+ @tags = tags
17
+ end
18
+
19
+ def to_json_api
20
+ payload = {
21
+ "data": {
22
+ "type": "transaction",
23
+ "attributes": {
24
+ "tags": tags
25
+ }
26
+ }
27
+ }
28
+ payload[:data][:attributes].compact!
29
+ payload.to_json
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Unit
4
+ module Transaction
5
+ TRANSACTION_LIST_LIMIT = 100
6
+ TRANSACTION_LIST_OFFSET = 0
7
+ autoload :GetTransactionParams, "unit/models/transaction/get_transaction_params"
8
+ autoload :ListTransactionParams, "unit/models/transaction/list_transaction_params"
9
+ autoload :PatchTagsRequest, "unit/models/transaction/patch_tags_request"
10
+
11
+ class << self
12
+ # Get a transaction by id
13
+ # @see https://docs.unit.co/transactions#get-specific-transaction
14
+ # @param transaction_id [String]
15
+ # @param account_id [String]
16
+ # @param customer_id [String] - optional
17
+ # @param include [Array<String>] - optional
18
+ def get_transaction(transaction_id:, account_id:, customer_id: nil, include: nil)
19
+ params = GetTransactionParams.new(transaction_id, account_id, customer_id, include)
20
+ Unit::Resource::TransactionResource.get_transaction(params)
21
+ end
22
+
23
+ # List transactions
24
+ # @see https://docs.unit.co/transactions#list-transactions
25
+ # @param limit [Integer] - optional
26
+ # @param offset [Integer] - optional
27
+ # @param account_id [String] - optional
28
+ # @param query [String] - optional
29
+ # @param tags [String] - optional
30
+ # @param since [String] - optional
31
+ # @param _until [String] - optional
32
+ # @param card_id [String] - optional
33
+ # @param type [Array<String>] - optional
34
+ # @param from_amount [Integer] - optional
35
+ # @param to_amount [Integer] - optional
36
+ # @param direction [String] - optional
37
+ # @param exclude_fees [Boolean] - optional
38
+ # @param sort [String] - optional
39
+ # @param include [Array<String>] - optional
40
+ def list_transactions(limit: nil, offset: nil, account_id: nil, customer_id: nil,
41
+ query: nil, tags: nil, since: nil, _until: nil, card_id: nil, type: nil, from_amount: nil, to_amount: nil,
42
+ direction: nil, exclude_fees: nil, sort: nil, include: nil)
43
+ params = ListTransactionParams.new(limit, offset, account_id, customer_id, query, tags, since,
44
+ _until, card_id, type, from_amount, to_amount,
45
+ direction, exclude_fees, sort, include)
46
+ Unit::Resource::TransactionResource.list_transactions(params)
47
+ end
48
+
49
+ # Update transaction tags
50
+ # @see https://docs.unit.co/transactions#update-transaction-tags
51
+ # @param account_id [String]
52
+ # @param transaction_id [String]
53
+ # @param tags [Hash]
54
+ def update_transaction(account_id:, transaction_id:, tags: nil)
55
+ request = PatchTagsRequest.new(account_id, transaction_id, tags)
56
+ Unit::Resource::TransactionResource.update_tags(request)
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "json"
4
+ module Unit
5
+ module Types
6
+ class RestrictedResource
7
+ attr_reader :ids, :type
8
+
9
+ def initialize(ids, type)
10
+ @ids = ids
11
+ @type = type
12
+ end
13
+
14
+ def to_json_api
15
+ result = []
16
+ @ids.each do |id|
17
+ result << { type: type, id: id }
18
+ end
19
+ result
20
+ end
21
+ end
22
+ end
23
+ end
@@ -21,7 +21,7 @@ module HttpHelper
21
21
  make_request(Net::HTTP::Patch, url, headers, body: body)
22
22
  end
23
23
 
24
- def self.delete(url, body:, headers:)
24
+ def self.delete(url, headers:, body: nil)
25
25
  make_request(Net::HTTP::Delete, url, headers, body: body)
26
26
  end
27
27
 
@@ -35,11 +35,19 @@ module HttpHelper
35
35
  request = net_http.new uri, headers
36
36
  request.body = body unless body.nil?
37
37
  response = http.request request
38
- response.body = JSON.parse(response.body)
38
+ response.body = response_check(response)
39
39
  response
40
40
  end
41
41
  end
42
42
 
43
+ def self.response_check(response)
44
+ if response.body.include?("html") || response.body.include?("PDF")
45
+ response.body
46
+ else
47
+ JSON.parse(response.body)
48
+ end
49
+ end
50
+
43
51
  def self.encode(value, key = nil)
44
52
  case value
45
53
  when Hash then value.map { |k, v| encode(v, append_key(key, k)) }.join("&")
data/lib/unit/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Unit
4
- VERSION = "0.1.3"
4
+ VERSION = "0.1.5"
5
5
  end
data/lib/unit_ruby_sdk.rb CHANGED
@@ -6,11 +6,21 @@ module Unit
6
6
  autoload :Application, "unit/models/application/application"
7
7
  autoload :Customer, "unit/models/customer/customer"
8
8
  autoload :Account, "unit/models/account/account"
9
+ autoload :ApiToken, "unit/models/api_token/api_token"
10
+ autoload :Payment, "unit/models/payment/payment"
11
+ autoload :Transaction, "unit/models/transaction/transaction"
12
+ autoload :Card, "unit/models/card/card"
13
+ autoload :Statement, "unit/models/statement/statement"
9
14
 
10
15
  module Resource
11
16
  autoload :ApplicationResource, "unit/api_resources/application_resource"
12
17
  autoload :CustomerResource, "unit/api_resources/customer_resource"
13
18
  autoload :AccountResource, "unit/api_resources/account_resource"
19
+ autoload :ApiTokenResource, "unit/api_resources/api_token_resource"
20
+ autoload :PaymentResource, "unit/api_resources/payment_resource"
21
+ autoload :TransactionResource, "unit/api_resources/transaction_resource"
22
+ autoload :CardResource, "unit/api_resources/card_resource"
23
+ autoload :StatementResource, "unit/api_resources/statement_resource"
14
24
  end
15
25
 
16
26
  module Types
@@ -26,6 +36,7 @@ module Unit
26
36
  autoload :PowerOfAttorneyAgent, "unit/types/power_of_attorney_agent"
27
37
  autoload :Relationship, "unit/types/relationship"
28
38
  autoload :RelationshipArray, "unit/types/relationship_array"
39
+ autoload :RestrictedResource, "unit/types/restricted_resource"
29
40
  end
30
41
 
31
42
  autoload :UnitErrorPayload, "unit/errors/unit_error_payload"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unit_ruby_sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Unit
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-12-20 00:00:00.000000000 Z
11
+ date: 2023-01-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: factory_bot_rails
@@ -95,9 +95,14 @@ files:
95
95
  - README.md
96
96
  - Rakefile
97
97
  - lib/unit/api_resources/account_resource.rb
98
+ - lib/unit/api_resources/api_token_resource.rb
98
99
  - lib/unit/api_resources/application_resource.rb
99
100
  - lib/unit/api_resources/base_resource.rb
101
+ - lib/unit/api_resources/card_resource.rb
100
102
  - lib/unit/api_resources/customer_resource.rb
103
+ - lib/unit/api_resources/payment_resource.rb
104
+ - lib/unit/api_resources/statement_resource.rb
105
+ - lib/unit/api_resources/transaction_resource.rb
101
106
  - lib/unit/errors/unit_error.rb
102
107
  - lib/unit/errors/unit_error_payload.rb
103
108
  - lib/unit/models/account/account.rb
@@ -108,12 +113,24 @@ files:
108
113
  - lib/unit/models/account/deposit/freeze_account_request.rb
109
114
  - lib/unit/models/account/deposit/list_account_params.rb
110
115
  - lib/unit/models/account/deposit/patch_deposit_account_request.rb
116
+ - lib/unit/models/api_token/api_token.rb
117
+ - lib/unit/models/api_token/customer/create_customer_token_request.rb
118
+ - lib/unit/models/api_token/customer/create_customer_token_verification.rb
119
+ - lib/unit/models/api_token/customer/create_token_using_jwt_request.rb
120
+ - lib/unit/models/api_token/org/create_api_token_request.rb
111
121
  - lib/unit/models/application/application.rb
112
122
  - lib/unit/models/application/create_business_application_request.rb
113
123
  - lib/unit/models/application/create_individual_application_request.rb
114
124
  - lib/unit/models/application/list_application_params.rb
115
125
  - lib/unit/models/application/patch_application_request.rb
116
126
  - lib/unit/models/application/upload_document_request.rb
127
+ - lib/unit/models/card/card.rb
128
+ - lib/unit/models/card/create_business_debit_card_request.rb
129
+ - lib/unit/models/card/create_business_virtual_debit_card_request.rb
130
+ - lib/unit/models/card/create_individual_debit_card_request.rb
131
+ - lib/unit/models/card/create_individual_virtual_card_request.rb
132
+ - lib/unit/models/card/list_card_params.rb
133
+ - lib/unit/models/card/replace_card_request.rb
117
134
  - lib/unit/models/customer/add_authorized_users_request.rb
118
135
  - lib/unit/models/customer/archive_customer_request.rb
119
136
  - lib/unit/models/customer/customer.rb
@@ -121,6 +138,18 @@ files:
121
138
  - lib/unit/models/customer/patch_business_customer_request.rb
122
139
  - lib/unit/models/customer/patch_individual_customer_request.rb
123
140
  - lib/unit/models/customer/remove_authorized_users_request.rb
141
+ - lib/unit/models/payment/create_book_payment_request.rb
142
+ - lib/unit/models/payment/patch_book_payment_request.rb
143
+ - lib/unit/models/payment/payment.rb
144
+ - lib/unit/models/statement/get_bank_verification_pdf.rb
145
+ - lib/unit/models/statement/get_html_by_id_request.rb
146
+ - lib/unit/models/statement/get_pdf_by_id_request.rb
147
+ - lib/unit/models/statement/list_statement_params.rb
148
+ - lib/unit/models/statement/statement.rb
149
+ - lib/unit/models/transaction/get_transaction_params.rb
150
+ - lib/unit/models/transaction/list_transaction_params.rb
151
+ - lib/unit/models/transaction/patch_tags_request.rb
152
+ - lib/unit/models/transaction/transaction.rb
124
153
  - lib/unit/models/unit_resource.rb
125
154
  - lib/unit/models/unit_response.rb
126
155
  - lib/unit/types/address.rb
@@ -135,6 +164,7 @@ files:
135
164
  - lib/unit/types/power_of_attorney_agent.rb
136
165
  - lib/unit/types/relationship.rb
137
166
  - lib/unit/types/relationship_array.rb
167
+ - lib/unit/types/restricted_resource.rb
138
168
  - lib/unit/utils/http_helper.rb
139
169
  - lib/unit/version.rb
140
170
  - lib/unit_ruby_sdk.rb