unit_ruby_sdk 0.1.5 → 1.0.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 00b359a8630b7687c710525b86d5faec0f30dc7771ed820538a12f18e3423d9d
4
- data.tar.gz: 6ed3a97d6962f88810a0801e0f7f98a2e5cd8a850fb870b945bb06bc91229af4
3
+ metadata.gz: ebccfab4c5a1935e6155ab1778b6c8beb123e7a4171b14ea6fcb2617d84d9da0
4
+ data.tar.gz: 195fe66d952a385323e750b19abca9940843645252771462efbefc75dc3a1e68
5
5
  SHA512:
6
- metadata.gz: cdc7b4d814b87313a2163176589d3c871f6986a9c39eb327a59596ef5ad7531645fe324703e105a0758a5d871da2a9d5cdc8ea30912a2a5983a77ff6d85949d0
7
- data.tar.gz: 54884fbeb721faa5a5a8b2b78b91059a3b93af504f70d313e4b87963e33e6944c998d31c52412a61e2da198964bf9030872d39c22fab6db871f42a954c2681e3
6
+ metadata.gz: 92662a6367cb982b8fe77577b729e28139a9da4b78da5518ea99e32c064fbfede80106477569380a2b68c4816e1e2e4641b4911d38f63cd608ca8f9abb8c9dc4
7
+ data.tar.gz: a80e9f7bb02d93e24adafa4c0f1d792ad7fa9ee9bcf64a421c5d06a45366e90ed5a909fa68271ccd026c287ef2ecf4167cddf436563a6738d66a0042688602b7
data/README.md CHANGED
@@ -47,6 +47,19 @@ response = Unit::Application.create_business_application(
47
47
  application = response.data
48
48
 
49
49
  puts application.id
50
+
51
+ file = File.open("./spec/test.pdf", "rb")
52
+ contents = file.read
53
+ file.close
54
+
55
+ upload_document_request = Unit::Application.upload_document(
56
+ application_id: "836683",
57
+ document_id: "125214",
58
+ file: contents,
59
+ file_type: Unit::Types::DocumentFileType::PDF,
60
+ is_back_side: true)
61
+
62
+ puts upload_document_request.data.id
50
63
  ```
51
64
 
52
65
  ### Fetching a Customer
@@ -67,10 +80,10 @@ puts customer.id
67
80
  require 'unit_ruby_sdk'
68
81
 
69
82
  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 }
83
+ amount: 1000,
84
+ description: "test payment",
85
+ account_id: "27573",
86
+ counterparty_account_id: "36981"
74
87
  )
75
88
  payment = response.data
76
89
  puts payment.id
@@ -97,6 +110,17 @@ card = response.data
97
110
  puts card.id
98
111
  ```
99
112
 
113
+ ### Creating a check deposit
114
+ ```ruby
115
+ response = Unit::CheckDeposit.create_deposit(
116
+ account_id: account_id,
117
+ amount: 50_000,
118
+ description: "test check deposit"
119
+ )
120
+ deposit = response.data
121
+ puts deposit.id
122
+ ```
123
+
100
124
  ### Logging Errors
101
125
 
102
126
  ```ruby
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "./base_resource"
4
+ require_relative "../utils/http_helper"
5
+ require "json"
6
+
7
+ module Unit
8
+ module Resource
9
+ class AtmLocationResource < Unit::Resource::BaseResource
10
+ class << self
11
+ # Get a list of ATM locations by calling Unit's API
12
+ # @param params [ListByCoordinatesParams, ListByAddressParams, ListByPostalCodeParams] The parameters to use to get a list of ATM locations
13
+ # @return [Unit::Response] The response from Unit's API
14
+ def list(params = nil)
15
+ response = HttpHelper.get("#{api_url}/atm-locations", params: params.to_hash, headers: headers)
16
+ response_handler(response)
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,81 @@
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 check deposits to Unit API and parsing responses
7
+ # @see https://docs.unit.co/check-deposits
8
+ module Unit
9
+ module Resource
10
+ class CheckDepositResource < Unit::Resource::BaseResource
11
+ class << self
12
+ # Create a check deposit by calling Unit's API
13
+ # @param request [CreateCheckDepositRequest]
14
+ # @return [UnitResponse, UnitError]
15
+ def create_deposit(request)
16
+ payload = request.to_json_api
17
+ response = HttpHelper.post("#{api_url}/check-deposits", body: payload, headers: headers)
18
+ response_handler(response)
19
+ end
20
+
21
+ # Get a check deposit by id by calling Unit's API
22
+ # @param params [GetRequest]
23
+ # @return [UnitResponse, UnitError]
24
+ def get(params)
25
+ payload = params.to_hash
26
+ response = HttpHelper.get("#{api_url}/check-deposits/#{params.deposit_id}", params: payload, headers: headers)
27
+ response_handler(response)
28
+ end
29
+
30
+ # Get a list of check deposits by calling Unit's API
31
+ # @param params [ListDepositRequest]
32
+ # @return [UnitResponse, UnitError]
33
+ def list(params = nil)
34
+ response = HttpHelper.get("#{api_url}/check-deposits", params: params.to_hash, headers: headers)
35
+ response_handler(response)
36
+ end
37
+
38
+ # Update a check deposit by id by calling Unit's API
39
+ # @param request [PatchCheckDepositRequest]
40
+ # @return [UnitResponse, UnitError]
41
+ def update(request)
42
+ payload = request.to_json_api
43
+ response = HttpHelper.patch("#{api_url}/check-deposits/#{request.deposit_id}", body: payload, headers: headers)
44
+ response_handler(response)
45
+ end
46
+
47
+ # Upload a check deposit image by calling Unit's API
48
+ # @param request [UploadImageRequest]
49
+ # @return [UnitResponse, UnitError]
50
+ def upload(request)
51
+ side = request.is_front_side ? "/front" : "/back"
52
+
53
+ headers_updated = headers.clone
54
+
55
+ headers_updated["Content-Type"] = "image/jpeg"
56
+
57
+ response = HttpHelper.put("#{api_url}/check-deposits/#{request.deposit_id}#{side}", body: request.file_content, headers: headers_updated)
58
+
59
+ response_handler(response)
60
+ end
61
+
62
+ # Get a check deposit image by calling Unit's API
63
+ # @param request [GetImageRequest]
64
+ # @return [UnitResponse, UnitError]
65
+ def get_image(request)
66
+ side = request.is_front_side ? "front" : "back"
67
+ response = HttpHelper.get("#{api_url}/check-deposits/#{request.deposit_id}/#{side}", headers: headers, response_type: "image")
68
+ file_response_handler(response)
69
+ end
70
+
71
+ # Confirm a check deposit by calling Unit's API
72
+ # @param deposit_id [String]
73
+ # @return [UnitResponse, UnitError]
74
+ def confirm_details(deposit_id)
75
+ response = HttpHelper.post("#{api_url}/check-deposits/#{deposit_id}/confirm", headers: headers)
76
+ response_handler(response)
77
+ end
78
+ end
79
+ end
80
+ end
81
+ end
@@ -111,11 +111,8 @@ module Unit
111
111
  # Upload an application document by calling Unit's API
112
112
  # @param application_id [String] The application ID
113
113
  # @param document_id [String] The document ID
114
- # @param file [String] The file path
115
- # @param file_type [String] The file type
116
- # @option file_type [String] :pdf
117
- # @option file_type [String] :jpg
118
- # @option file_type [String] :png
114
+ # @param file [String] The file content
115
+ # @param file_type [String] The file type. One of the Unit::Types::DocumentFileType constants.
119
116
  # @param is_back_side [Boolean] The file is back side
120
117
  # @return [UnitResponse, UnitError]
121
118
  def upload_document(application_id:, document_id:, file:, file_type:, is_back_side: false)
@@ -9,11 +9,8 @@ module Unit
9
9
 
10
10
  # @param application_id [String] The application ID
11
11
  # @param document_id [String] The document ID
12
- # @param file [String] The file path
13
- # @param file_type [String] The file type
14
- # @option file_type [String] :pdf
15
- # @option file_type [String] :jpg
16
- # @option file_type [String] :png
12
+ # @param file [String] The file content
13
+ # @param file_type [String] The file type. One of the Unit::Types::DocumentFileType constants.
17
14
  # @param is_back_side [Boolean] The file is back side
18
15
  def initialize(application_id, document_id, file, file_type, is_back_side: false)
19
16
  @application_id = application_id
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Unit
4
+ module AtmLocation
5
+ autoload :ListByCoordinatesParams, "unit/models/atm_location/list_by_coordinates_params"
6
+ autoload :ListByAddressParams, "unit/models/atm_location/list_by_address_params"
7
+ autoload :ListByPostalCodeParams, "unit/models/atm_location/list_by_postal_code_params"
8
+
9
+ class << self
10
+ # Get a list of ATM locations by coordinates by calling Unit's API
11
+ # @see https://docs.unit.co/cards-atm-locations#list-atm-locations-by-coordinates
12
+ # @param coordinates [Coordinates]
13
+ # @param search_radius [Integer] - optional
14
+ def list_by_coordinates(coordinates:, search_radius: nil)
15
+ params = ListByCoordinatesParams.new(coordinates, search_radius)
16
+ Unit::Resource::AtmLocationResource.list(params)
17
+ end
18
+
19
+ # Get a list of ATM locations by postal code by calling Unit's API
20
+ # @see https://docs.unit.co/cards-atm-locations#list-atm-locations-by-postal-code
21
+ # @param postal_code [String]
22
+ # @param search_radius [Integer] - optional
23
+ def list_by_postal_code(postal_code:, search_radius: nil)
24
+ params = ListByPostalCodeParams.new(postal_code, search_radius)
25
+ Unit::Resource::AtmLocationResource.list(params)
26
+ end
27
+
28
+ # Get a list of ATM locations by address by calling Unit's API
29
+ # @see https://docs.unit.co/cards-atm-locations#list-atm-locations-by-address
30
+ # @param address [Address]
31
+ # @param search_radius [Integer] - optional
32
+ def list_by_address(address:, search_radius: nil)
33
+ params = ListByAddressParams.new(address, search_radius)
34
+ Unit::Resource::AtmLocationResource.list(params)
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ # params fot list atm locations by address
4
+ # @see
5
+ module Unit
6
+ module AtmLocation
7
+ class ListByAddressParams
8
+ attr_reader :address, :search_radius
9
+
10
+ # @param address [Address]
11
+ # @param search_radius [Integer]
12
+ def initialize(address, search_radius = nil)
13
+ @address = address
14
+ @search_radius = search_radius
15
+ end
16
+
17
+ def to_hash
18
+ params = {
19
+ "filter[address]": address.represent.to_json,
20
+ "filter[searchRadius]": search_radius
21
+ }
22
+ params.compact
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ # params to list atm locations by coordinates
4
+ # @see https://docs.unit.co/cards-atm-locations/#list-atm-locations-by-coordinates
5
+ module Unit
6
+ module AtmLocation
7
+ class ListByCoordinatesParams
8
+ attr_reader :coordinates, :search_radius
9
+
10
+ # @param coordinates [Coordinates]
11
+ # @param search_radius [Integer]
12
+ def initialize(coordinates, search_radius = nil)
13
+ @coordinates = coordinates
14
+ @search_radius = search_radius
15
+ end
16
+
17
+ def to_hash
18
+ params = {
19
+ "filter[coordinates]": coordinates.represent,
20
+ "filter[searchRadius]": search_radius
21
+ }
22
+ params.compact
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ # params to list atm locations by postal code
4
+ # @see https://docs.unit.co/cards-atm-locations/#list-atm-locations-by-postal-code
5
+ module Unit
6
+ module AtmLocation
7
+ class ListByPostalCodeParams
8
+ attr_reader :postal_code, :search_radius
9
+
10
+ # @param postal_code [String]
11
+ # @param search_radius [Integer]
12
+ def initialize(postal_code, search_radius = nil)
13
+ @postal_code = postal_code
14
+ @search_radius = search_radius
15
+ end
16
+
17
+ def to_hash
18
+ params = {
19
+ "filter[postalCode]": postal_code,
20
+ "filter[searchRadius]": search_radius
21
+ }
22
+ params.compact
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,107 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Unit
4
+ module CheckDeposit
5
+ CHECK_DEPOSIT_LIMIT = 100
6
+ CHECK_DEPOSIT_OFFSET = 0
7
+
8
+ autoload :CreateCheckDepositRequest, "unit/models/check_deposit/create_check_deposit_request"
9
+ autoload :GetRequest, "unit/models/check_deposit/get_request"
10
+ autoload :ListDepositParams, "unit/models/check_deposit/list_deposit_params"
11
+ autoload :UploadImageRequest, "unit/models/check_deposit/upload_image_request"
12
+ autoload :GetImageRequest, "unit/models/check_deposit/get_image_request"
13
+ autoload :PatchDepositRequest, "unit/models/check_deposit/patch_deposit_request"
14
+
15
+ class << self
16
+ # Create a check deposit
17
+ # @see https://docs.unit.co/check-deposits#create-check-deposit
18
+ # @param account_id [String]
19
+ # @param amount [Integer]
20
+ # @param description [String]
21
+ # @param tags [Hash] - optional
22
+ # @param idempotency_key [String] - optional
23
+ def create_deposit(account_id:, amount:, description:, tags: nil, idempotency_key: nil)
24
+ request = CreateCheckDepositRequest.new(account_id, amount, description, tags, idempotency_key)
25
+ Unit::Resource::CheckDepositResource.create_deposit(request)
26
+ end
27
+
28
+ # Get a check deposit by calling Unit's API
29
+ # @see https://docs.unit.co/check-deposits#get-specific-check-deposit
30
+ # @param deposit_id [String]
31
+ # @param include [Array<String>] - optional
32
+ def get_deposit(deposit_id:, include: nil)
33
+ request = GetRequest.new(deposit_id, include)
34
+ Unit::Resource::CheckDepositResource.get(request)
35
+ end
36
+
37
+ # List check deposits
38
+ # @see https://docs.unit.co/check-deposits#list-check-deposits
39
+ # @param limit [Integer] - optional
40
+ # @param offset [Integer] - optional
41
+ # @param account_id [String] - optional
42
+ # @param customer_id [String] - optional
43
+ # @param tags [Hash] - optional
44
+ # @param sort [String] - optional
45
+ # @param include [Array<String>] - optional
46
+ def list_deposit(limit: CHECK_DEPOSIT_LIMIT, offset: CHECK_DEPOSIT_OFFSET, account_id: nil,
47
+ customer_id: nil, tags: nil, sort: nil, include: nil)
48
+ request = ListDepositParams.new(limit, offset, account_id, customer_id, tags, sort, include)
49
+ Unit::Resource::CheckDepositResource.list(request)
50
+ end
51
+
52
+ # Upload an image front side for a check deposit
53
+ # @see https://docs.unit.co/check-deposits#upload-front-side-image
54
+ # @param deposit_id [String]
55
+ # @param file_content [String]
56
+ # @param is_front_side [Boolean] - optional
57
+ def upload_image_front(deposit_id:, file_content:, is_front_side: true)
58
+ request = UploadImageRequest.new(deposit_id, file_content, is_front_side: is_front_side)
59
+ Unit::Resource::CheckDepositResource.upload(request)
60
+ end
61
+
62
+ # Upload an image back side for a check deposit
63
+ # @see https://docs.unit.co/check-deposits#upload-back-side-image
64
+ # @param deposit_id [String]
65
+ # @param file_content [String]
66
+ # @param is_front_side [Boolean] - optional
67
+ def upload_image_back(deposit_id:, file_content:, is_front_side: false)
68
+ request = UploadImageRequest.new(deposit_id, file_content, is_front_side: is_front_side)
69
+ Unit::Resource::CheckDepositResource.upload(request)
70
+ end
71
+
72
+ # Get a check deposit image front side
73
+ # @see https://docs.unit.co/check-deposits#get-specific-check-deposit-front-image
74
+ # @param deposit_id [String]
75
+ # @param is_front_side [Boolean] - optional
76
+ def get_image_front(deposit_id:, is_front_side: true)
77
+ request = GetImageRequest.new(deposit_id, is_front_side: is_front_side)
78
+ Unit::Resource::CheckDepositResource.get_image(request)
79
+ end
80
+
81
+ # Get a check deposit image back side
82
+ # @see https://docs.unit.co/check-deposits#get-specific-check-deposit-back-image
83
+ # @param deposit_id [String]
84
+ # @param is_front_side [Boolean] - optional
85
+ def get_image_back(deposit_id:, is_front_side: false)
86
+ request = GetImageRequest.new(deposit_id, is_front_side: is_front_side)
87
+ Unit::Resource::CheckDepositResource.get_image(request)
88
+ end
89
+
90
+ # Update a check deposit
91
+ # @see https://docs.unit.co/check-deposits#update-check-deposit
92
+ # @param deposit_id [String]
93
+ # @param tags [Hash] - optional
94
+ def update_deposit(deposit_id:, tags:)
95
+ request = PatchDepositRequest.new(deposit_id, tags)
96
+ Unit::Resource::CheckDepositResource.update(request)
97
+ end
98
+
99
+ # Confirm check deposit details
100
+ # @see https://docs.unit.co/check-deposits#confirm-check-deposit-details
101
+ # @param deposit_id [String]
102
+ def confirm_details(deposit_id:)
103
+ Unit::Resource::CheckDepositResource.confirm_details(deposit_id)
104
+ end
105
+ end
106
+ end
107
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Request to create check deposit
4
+ # @see https://docs.unit.co/check-deposits#create-check-deposit
5
+ module Unit
6
+ module CheckDeposit
7
+ class CreateCheckDepositRequest
8
+ attr_reader :account_id, :amount, :description, :tags, :idempotency_key
9
+
10
+ # @param account_id [String]
11
+ # @param amount [Integer]
12
+ # @param description [String]
13
+ # @param tags [Hash] - optional
14
+ # @param idempotency_key [String] - optional
15
+ def initialize(account_id, amount, description, tags = nil, idempotency_key = nil)
16
+ @account_id = account_id
17
+ @amount = amount
18
+ @description = description
19
+ @tags = tags
20
+ @idempotency_key = idempotency_key
21
+ end
22
+
23
+ def to_json_api
24
+ payload = {
25
+ "data": {
26
+ "type": "checkDeposit",
27
+ "attributes": {
28
+ amount: amount,
29
+ description: description,
30
+ tags: tags,
31
+ idempotency_key: idempotency_key
32
+ },
33
+ "relationships": {
34
+ "account": Unit::Types::Relationship.new("account", account_id).to_hash
35
+ }
36
+ }
37
+ }
38
+ payload[:data][:attributes].compact!
39
+ payload.to_json
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Request to get a check deposit image
4
+ # @see https://docs.unit.co/check-deposits#get-specific-check-deposit-front-image
5
+ # @see https://docs.unit.co/check-deposits#get-specific-check-deposit-back-image
6
+ module Unit
7
+ module CheckDeposit
8
+ class GetImageRequest
9
+ attr_reader :deposit_id, :is_front_side
10
+
11
+ # @param deposit_id [String]
12
+ # @param is_front_side [Boolean] - optional
13
+ def initialize(deposit_id, is_front_side: true)
14
+ @deposit_id = deposit_id
15
+ @is_front_side = is_front_side
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Request to get check deposit by id
4
+ # @see https://docs.unit.co/check-deposits#get-specific-check-deposit
5
+ module Unit
6
+ module CheckDeposit
7
+ class GetRequest
8
+ attr_reader :deposit_id, :include
9
+
10
+ # @param deposit_id [String]
11
+ # @param include [Array<String>] - optional
12
+ def initialize(deposit_id, include = nil)
13
+ @deposit_id = deposit_id
14
+ @include = include
15
+ end
16
+
17
+ def to_hash
18
+ { include: include&.join(",") }.compact
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Request to list check deposits
4
+ # @see https://docs.unit.co/check-deposits#list-check-deposits
5
+ module Unit
6
+ module CheckDeposit
7
+ class ListDepositParams
8
+ attr_reader :limit, :offset, :account_id, :customer_id, :tags, :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 tags [Hash] - optional
15
+ # @param sort [String] - optional
16
+ # @param include [Array<String>] - optional
17
+ def initialize(limit = CHECK_DEPOSIT_LIMIT, offset = CHECK_DEPOSIT_OFFSET, account_id = nil,
18
+ customer_id = nil, tags = nil, sort = nil, include = nil)
19
+ @limit = limit
20
+ @offset = offset
21
+ @account_id = account_id
22
+ @customer_id = customer_id
23
+ @tags = tags
24
+ @sort = sort
25
+ @include = include
26
+ end
27
+
28
+ def to_hash
29
+ params = {
30
+ "page[limit]": limit,
31
+ "page[offset]": offset,
32
+ "filter[accountId]": account_id,
33
+ "filter[customerId]": customer_id,
34
+ "filter[tags]": tags,
35
+ "sort": sort,
36
+ "include": include&.join(",")
37
+ }
38
+ params.compact
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Request to update check deposit
4
+ # @see https://docs.unit.co/check-deposits#update-check-deposit
5
+ module Unit
6
+ module CheckDeposit
7
+ class PatchDepositRequest
8
+ attr_reader :deposit_id, :tags
9
+
10
+ # @param deposit_id [String]
11
+ # @param tags [Hash] - optional
12
+ def initialize(deposit_id, tags)
13
+ @deposit_id = deposit_id
14
+ @tags = tags
15
+ end
16
+
17
+ def to_json_api
18
+ payload = {
19
+ data: {
20
+ type: "checkDeposit",
21
+ attributes: { tags: tags }
22
+ }
23
+ }
24
+ payload[:data][:attributes].compact!
25
+ payload.to_json
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Request to upload a check deposit image
4
+ # @see https://docs.unit.co/check-deposits#upload-front-side-image
5
+ # @see https://docs.unit.co/check-deposits#upload-back-side-image
6
+
7
+ module Unit
8
+ module CheckDeposit
9
+ class UploadImageRequest
10
+ attr_reader :deposit_id, :file_content, :is_front_side
11
+
12
+ # @param deposit_id [String]
13
+ # @param file_content [String]
14
+ # @param is_front_side [Boolean] - optional
15
+ def initialize(deposit_id, file_content, is_front_side: true)
16
+ @deposit_id = deposit_id
17
+ @file_content = file_content
18
+ @is_front_side = is_front_side
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Unit
4
+ module Types
5
+ class Coordinates
6
+ attr_reader :latitude, :longitude
7
+
8
+ # @param latitude [Float] The latitude
9
+ # @param longitude [Float] The longitude
10
+ def initialize(latitude, longitude)
11
+ @latitude = latitude
12
+ @longitude = longitude
13
+ end
14
+
15
+ def represent
16
+ params = {
17
+ longitude: longitude,
18
+ latitude: latitude
19
+ }
20
+ params.compact.to_json
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Unit
4
+ module Types
5
+ class DocumentFileType
6
+ PDF = "pdf"
7
+ JPG = "jpg"
8
+ PNG = "png"
9
+ end
10
+ end
11
+ end
@@ -5,8 +5,10 @@ require "net/http"
5
5
  require "json"
6
6
 
7
7
  module HttpHelper
8
- def self.get(url, headers:, params: nil)
9
- make_request(Net::HTTP::Get, url, headers, params: params)
8
+ VALUES = [:"filter[searchRadius]"].freeze
9
+ RESPONSE_TYPES = %w[delete image].freeze
10
+ def self.get(url, headers:, params: nil, response_type: nil)
11
+ make_request(Net::HTTP::Get, url, headers, params: params, response_type: response_type)
10
12
  end
11
13
 
12
14
  def self.post(url, headers:, body: nil)
@@ -21,11 +23,11 @@ module HttpHelper
21
23
  make_request(Net::HTTP::Patch, url, headers, body: body)
22
24
  end
23
25
 
24
- def self.delete(url, headers:, body: nil)
25
- make_request(Net::HTTP::Delete, url, headers, body: body)
26
+ def self.delete(url, headers:, body: nil, response_type: nil)
27
+ make_request(Net::HTTP::Delete, url, headers, body: body, response_type: response_type)
26
28
  end
27
29
 
28
- def self.make_request(net_http, url, headers, body: nil, params: nil)
30
+ def self.make_request(net_http, url, headers, body: nil, params: nil, response_type: nil)
29
31
  uri = params.nil? ? URI(url) : URI("#{url}?#{encode(params)}")
30
32
  host = uri.host.to_s
31
33
  port = uri.port
@@ -35,20 +37,20 @@ module HttpHelper
35
37
  request = net_http.new uri, headers
36
38
  request.body = body unless body.nil?
37
39
  response = http.request request
38
- response.body = response_check(response)
40
+ response.body = response_check(response, response_type)
39
41
  response
40
42
  end
41
43
  end
42
44
 
43
- def self.response_check(response)
44
- if response.body.include?("html") || response.body.include?("PDF")
45
+ def self.response_check(response, response_type = nil)
46
+ if RESPONSE_TYPES.include?(response_type) || response.body.include?("html") || response.body.include?("PDF")
45
47
  response.body
46
48
  else
47
49
  JSON.parse(response.body)
48
50
  end
49
51
  end
50
52
 
51
- def self.encode(value, key = nil)
53
+ def self.value_check(value, key = nil)
52
54
  case value
53
55
  when Hash then value.map { |k, v| encode(v, append_key(key, k)) }.join("&")
54
56
  when Array then value.map { |v| encode(v, "#{key}[]") }.join("&")
@@ -58,6 +60,10 @@ module HttpHelper
58
60
  end
59
61
  end
60
62
 
63
+ def self.encode(value, key = nil)
64
+ value.instance_of?(Hash) && value.key?(VALUES.map { |val| val }) ? value.map { |k, v| "#{k}=#{v}" }.join("&") : value_check(value, key)
65
+ end
66
+
61
67
  def self.append_key(root_key, key)
62
68
  root_key.nil? ? key : "#{root_key}[#{key}]"
63
69
  end
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.5"
4
+ VERSION = "1.0.2"
5
5
  end
data/lib/unit_ruby_sdk.rb CHANGED
@@ -11,7 +11,8 @@ module Unit
11
11
  autoload :Transaction, "unit/models/transaction/transaction"
12
12
  autoload :Card, "unit/models/card/card"
13
13
  autoload :Statement, "unit/models/statement/statement"
14
-
14
+ autoload :AtmLocation, "unit/models/atm_location/atm_location"
15
+ autoload :CheckDeposit, "unit/models/check_deposit/check_deposit"
15
16
  module Resource
16
17
  autoload :ApplicationResource, "unit/api_resources/application_resource"
17
18
  autoload :CustomerResource, "unit/api_resources/customer_resource"
@@ -21,6 +22,8 @@ module Unit
21
22
  autoload :TransactionResource, "unit/api_resources/transaction_resource"
22
23
  autoload :CardResource, "unit/api_resources/card_resource"
23
24
  autoload :StatementResource, "unit/api_resources/statement_resource"
25
+ autoload :AtmLocationResource, "unit/api_resources/atm_location_resource"
26
+ autoload :CheckDepositResource, "unit/api_resources/check_deposit_resource"
24
27
  end
25
28
 
26
29
  module Types
@@ -37,6 +40,8 @@ module Unit
37
40
  autoload :Relationship, "unit/types/relationship"
38
41
  autoload :RelationshipArray, "unit/types/relationship_array"
39
42
  autoload :RestrictedResource, "unit/types/restricted_resource"
43
+ autoload :DocumentFileType, "unit/types/document_file_type"
44
+ autoload :Coordinates, "unit/types/coordinates"
40
45
  end
41
46
 
42
47
  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.5
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Unit
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-01-11 00:00:00.000000000 Z
11
+ date: 2023-02-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: factory_bot_rails
@@ -97,8 +97,10 @@ files:
97
97
  - lib/unit/api_resources/account_resource.rb
98
98
  - lib/unit/api_resources/api_token_resource.rb
99
99
  - lib/unit/api_resources/application_resource.rb
100
+ - lib/unit/api_resources/atm_location_resource.rb
100
101
  - lib/unit/api_resources/base_resource.rb
101
102
  - lib/unit/api_resources/card_resource.rb
103
+ - lib/unit/api_resources/check_deposit_resource.rb
102
104
  - lib/unit/api_resources/customer_resource.rb
103
105
  - lib/unit/api_resources/payment_resource.rb
104
106
  - lib/unit/api_resources/statement_resource.rb
@@ -124,6 +126,10 @@ files:
124
126
  - lib/unit/models/application/list_application_params.rb
125
127
  - lib/unit/models/application/patch_application_request.rb
126
128
  - lib/unit/models/application/upload_document_request.rb
129
+ - lib/unit/models/atm_location/atm_location.rb
130
+ - lib/unit/models/atm_location/list_by_address_params.rb
131
+ - lib/unit/models/atm_location/list_by_coordinates_params.rb
132
+ - lib/unit/models/atm_location/list_by_postal_code_params.rb
127
133
  - lib/unit/models/card/card.rb
128
134
  - lib/unit/models/card/create_business_debit_card_request.rb
129
135
  - lib/unit/models/card/create_business_virtual_debit_card_request.rb
@@ -131,6 +137,13 @@ files:
131
137
  - lib/unit/models/card/create_individual_virtual_card_request.rb
132
138
  - lib/unit/models/card/list_card_params.rb
133
139
  - lib/unit/models/card/replace_card_request.rb
140
+ - lib/unit/models/check_deposit/check_deposit.rb
141
+ - lib/unit/models/check_deposit/create_check_deposit_request.rb
142
+ - lib/unit/models/check_deposit/get_image_request.rb
143
+ - lib/unit/models/check_deposit/get_request.rb
144
+ - lib/unit/models/check_deposit/list_deposit_params.rb
145
+ - lib/unit/models/check_deposit/patch_deposit_request.rb
146
+ - lib/unit/models/check_deposit/upload_image_request.rb
134
147
  - lib/unit/models/customer/add_authorized_users_request.rb
135
148
  - lib/unit/models/customer/archive_customer_request.rb
136
149
  - lib/unit/models/customer/customer.rb
@@ -156,7 +169,9 @@ files:
156
169
  - lib/unit/types/authorized_user.rb
157
170
  - lib/unit/types/beneficial_owner.rb
158
171
  - lib/unit/types/business_contact.rb
172
+ - lib/unit/types/coordinates.rb
159
173
  - lib/unit/types/device_fingerprint.rb
174
+ - lib/unit/types/document_file_type.rb
160
175
  - lib/unit/types/evaluation_params.rb
161
176
  - lib/unit/types/full_name.rb
162
177
  - lib/unit/types/officer.rb