unit_ruby_sdk 0.1.0

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 (42) hide show
  1. checksums.yaml +7 -0
  2. data/.rspec +2 -0
  3. data/.rubocop.yml +28 -0
  4. data/CHANGELOG.md +5 -0
  5. data/Gemfile +16 -0
  6. data/Gemfile.lock +131 -0
  7. data/LICENSE.txt +373 -0
  8. data/README.md +1 -0
  9. data/Rakefile +8 -0
  10. data/lib/unit/api_resources/application_resource.rb +75 -0
  11. data/lib/unit/api_resources/base_resource.rb +36 -0
  12. data/lib/unit/api_resources/customer_resource.rb +69 -0
  13. data/lib/unit/errors/unit_error.rb +27 -0
  14. data/lib/unit/errors/unit_error_payload.rb +24 -0
  15. data/lib/unit/models/applications/create_business_application_request.rb +78 -0
  16. data/lib/unit/models/applications/create_individual_application_request.rb +88 -0
  17. data/lib/unit/models/applications/list_application_params.rb +38 -0
  18. data/lib/unit/models/applications/patch_application_request.rb +29 -0
  19. data/lib/unit/models/applications/upload_document_request.rb +24 -0
  20. data/lib/unit/models/customers/add_authorized_users_request.rb +27 -0
  21. data/lib/unit/models/customers/archive_customer_request.rb +26 -0
  22. data/lib/unit/models/customers/list_customer_params.rb +38 -0
  23. data/lib/unit/models/customers/patch_business_customer_request.rb +44 -0
  24. data/lib/unit/models/customers/patch_individual_customer_request.rb +45 -0
  25. data/lib/unit/models/customers/remove_authorized_users_request.rb +27 -0
  26. data/lib/unit/models/unit_resource.rb +18 -0
  27. data/lib/unit/models/unit_response.rb +15 -0
  28. data/lib/unit/types/address.rb +31 -0
  29. data/lib/unit/types/authorized_user.rb +28 -0
  30. data/lib/unit/types/beneficial_owner.rb +48 -0
  31. data/lib/unit/types/business_contact.rb +25 -0
  32. data/lib/unit/types/device_fingerprint.rb +19 -0
  33. data/lib/unit/types/evaluation_params.rb +18 -0
  34. data/lib/unit/types/full_name.rb +19 -0
  35. data/lib/unit/types/officer.rb +48 -0
  36. data/lib/unit/types/phone.rb +19 -0
  37. data/lib/unit/types/power_of_attorney_agent.rb +48 -0
  38. data/lib/unit/types/relationship.rb +18 -0
  39. data/lib/unit/types/relationship_array.rb +23 -0
  40. data/lib/unit/version.rb +5 -0
  41. data/lib/unit_ruby_sdk.rb +8 -0
  42. metadata +97 -0
@@ -0,0 +1,69 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "httparty"
4
+
5
+ require_relative "../api_resources/base_resource"
6
+ require_relative "../models/unit_response"
7
+ require_relative "../errors/unit_error"
8
+ require_relative "../models/customers/patch_individual_customer_request"
9
+ require_relative "../models/customers/patch_business_customer_request"
10
+
11
+ # class for creating requests for customers to Unit API and parsing responses
12
+ # See: https://docs.unit.co/customers/
13
+ module Unit
14
+ class CustomerResource < Unit::BaseResource
15
+ # Update a customer by calling Unit's API
16
+ # @param [PatchIndividualCustomerRequest, PatchBusinessCustomerRequest, PatchTrustCustomerRequest] request
17
+ # @return [UnitResponse, UnitError]
18
+ def update(request)
19
+ payload = request.to_json_api
20
+ response = HTTParty.patch("#{api_url}/customers/#{request.customer_id}", body: payload, headers: headers)
21
+ response_handler(response)
22
+ end
23
+
24
+ # Get a customer by calling Unit's API
25
+ # @param [Integer] customer_id
26
+ # @return [UnitResponse, UnitError]
27
+ def get(customer_id)
28
+ response = HTTParty.get("#{api_url}/customers/#{customer_id}", headers: headers)
29
+ response_handler(response)
30
+ end
31
+
32
+ # Get customers by calling Unit's API
33
+ # @param [ListCustomerParams] params
34
+ # @return [UnitResponse, UnitError]
35
+ def list(params = nil)
36
+ response = HTTParty.get("#{api_url}/customers", body: params&.to_hash&.to_json, headers: headers)
37
+ response_handler(response)
38
+ end
39
+
40
+ # Archive customers by calling Unit's API
41
+ # @param [ArchiveCustomerRequest] request
42
+ # @return [UnitResponse, UnitError]
43
+ def archive(request)
44
+ payload = request.to_json_api
45
+ response = HTTParty.post("#{api_url}/customers/#{request.customer_id}/archive", body: payload, headers: headers)
46
+ response_handler(response)
47
+ end
48
+
49
+ # Add authorized users to a customer by calling Unit's API
50
+ # @param [AddAuthorizedUsersRequest] request
51
+ # @return [UnitResponse, UnitError]
52
+ def add_authorized_users(request)
53
+ payload = request.to_json_api
54
+ response = HTTParty.post("#{api_url}/customers/#{request.customer_id}/authorized-users",
55
+ body: payload,
56
+ headers: headers)
57
+ response_handler(response)
58
+ end
59
+
60
+ # Remove authorized users from a customer by calling Unit's API
61
+ # @param [RemoveAuthorizedUsersRequest] request
62
+ # @return [UnitResponse, UnitError]
63
+ def remove_authorized_users(request)
64
+ payload = request.to_json_api
65
+ response = HTTParty.delete("#{api_url}/customers/#{request.customer_id}/authorized-users", body: payload, headers: headers)
66
+ response_handler(response)
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "unit_error_payload"
4
+
5
+ # Represents an Error returned from Unit's API
6
+ module Unit
7
+ class UnitError
8
+ # Create a new UnitError
9
+ # @param [Array<UnitErrorPayload>] errors
10
+ def initialize(errors)
11
+ @errors = errors
12
+ end
13
+
14
+ # Creates a new UnitError from given response.
15
+ # @param [Hash] response The response returned from Unit's API
16
+ # @return [UnitError] a new UnitError populated with values taken from the response
17
+ def self.from_json_api(response)
18
+ errors = response["errors"]
19
+
20
+ errors&.map do |error|
21
+ UnitErrorPayload.new(error["title"], error["status"],
22
+ error["detail"], error["details"], error["source"], error["code"])
23
+ end
24
+ UnitError.new(errors)
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Unit
4
+ class UnitErrorPayload
5
+ attr_reader :title, :status, :detail, :details, :source, :code
6
+
7
+ # @param title [String] The title of the error
8
+ # @param status [String] The HTTP status code
9
+ # @param detail [String] The additional information about the error
10
+ # @param details [String] The details of the error
11
+ # @param source [Hash] The source of the error
12
+ # @param code [String] A Unit-specific code, uniquely identifying the error type
13
+ # Check out documentation link for more details: https://docs.unit.co/about-jsonapi/#intro-errors
14
+ def initialize(title, status, detail, details = nil,
15
+ source = nil, code = nil)
16
+ @title = title
17
+ @status = status
18
+ @detail = detail
19
+ @details = details
20
+ @source = source
21
+ @code = code
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,78 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "unit/types/full_name"
4
+ require "unit/types/address"
5
+ require "unit/types/phone"
6
+ require "unit/types/business_contact"
7
+ require "unit/types/beneficial_owner"
8
+ require "unit/types/officer"
9
+
10
+ # Request to create a business application
11
+ # See: https://docs.unit.co/applications/#create-business-application
12
+ class CreateBusinessApplicationRequest
13
+ attr_reader :name, :address, :phone, :state_of_incorporation, :ein, :industry, :contact, :officer, :beneficial_owners,
14
+ :entity_type, :dba, :ip, :website, :tags, :idempotency_key, :device_fingerprints, :type
15
+
16
+ # @param name [String]
17
+ # @param address [Address]
18
+ # @param phone [Phone]
19
+ # @param state_of_incorporation [String]
20
+ # @param ein [String]
21
+ # @param industry [String]
22
+ # @param contact [BusinessContact]
23
+ # @param officer [Officer]
24
+ # @param beneficial_owners [Array]
25
+ # @param entity_type [String]
26
+ # @param optional dba [String]
27
+ # @param optional ip [String]
28
+ # @param optional website [String]
29
+ # @param optional tags [Hash]
30
+ # @param optional idempotency_key [String]
31
+ # @param optional device_fingerprints [DeviceFingerprint]
32
+ def initialize(name, address, phone, state_of_incorporation, ein, industry, contact, officer,
33
+ beneficial_owners, entity_type, dba = nil, ip = nil, website = nil, tags = nil, idempotency_key = nil,
34
+ device_fingerprints = nil)
35
+ @name = name
36
+ @address = address
37
+ @phone = phone
38
+ @state_of_incorporation = state_of_incorporation
39
+ @ein = ein
40
+ @industry = industry
41
+ @contact = contact
42
+ @officer = officer
43
+ @beneficial_owners = beneficial_owners.map(&:represent)
44
+ @entity_type = entity_type
45
+ @dba = dba
46
+ @ip = ip
47
+ @website = website
48
+ @tags = tags
49
+ @idempotency_key = idempotency_key
50
+ @device_fingerprints = device_fingerprints
51
+ @type = "businessApplication"
52
+ end
53
+
54
+ def to_json_api
55
+ payload = {
56
+ data: {
57
+ type: type,
58
+ attributes: {
59
+ name: name,
60
+ address: address.represent,
61
+ phone: phone.represent,
62
+ stateOfIncorporation: state_of_incorporation,
63
+ ein: ein,
64
+ industry: industry,
65
+ contact: contact.represent,
66
+ officer: officer.represent,
67
+ beneficialOwners: beneficial_owners,
68
+ entityType: entity_type,
69
+ dba: dba,
70
+ ip: ip,
71
+ website: website
72
+ }
73
+ }
74
+ }
75
+ payload[:data][:attributes].compact!
76
+ payload.to_json
77
+ end
78
+ end
@@ -0,0 +1,88 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "unit/types/full_name"
4
+ require "unit/types/address"
5
+ require "unit/types/phone"
6
+ require "unit/types/device_fingerprint"
7
+
8
+ # Request to create an individual application
9
+ # See https://docs.unit.co/applications/#create-individual-application
10
+ class CreateIndividualApplicationRequest
11
+ attr_reader :type, :ssn, :full_name, :date_of_birth, :address, :email, :phone, :ip, :ein, :industry, :dba, :sole_proprietorship,
12
+ :passport, :nationality, :device_fingerprints, :idempotency_key, :tags, :jwt_subject, :power_of_attorney_agent,
13
+ :evaluation_params
14
+
15
+ # @param ssn [String]
16
+ # @param full_name [FullName]
17
+ # @param date_of_birth [Date]
18
+ # @param address [Address]
19
+ # @param email [String]
20
+ # @param phone [Phone]
21
+ # @param optional ip [String]
22
+ # @param optional ein [String]
23
+ # @param optional industry [String]
24
+ # @param optional dba [String]
25
+ # @param optional sole_proprietorship [Boolean]
26
+ # @param optional passport [String]
27
+ # @param optional nationality [String]
28
+ # @param optional device_fingerprints [DeviceFingerprint]
29
+ # @param optional idempotency_key [String]
30
+ # @param optional tags [Hash]
31
+ # @param optional jwt_subject [String]
32
+ # @param optional power_of_attorney_agent [PowerOfAttorneyAgent]
33
+ # @param optional evaluation_params [EvaluationParams]
34
+ def initialize(ssn, full_name, date_of_birth, address, email, phone, ip = nil, ein = nil, industry = nil, dba = nil, sole_proprietorship = nil, passport = nil,
35
+ nationality = nil, device_fingerprints = nil, idempotency_key = nil, tags = nil, jwt_subject = nil, power_of_attorney_agent = nil,
36
+ evaluation_params = nil)
37
+ @ssn = ssn
38
+ @full_name = full_name
39
+ @date_of_birth = date_of_birth
40
+ @address = address
41
+ @phone = phone
42
+ @email = email
43
+ @ip = ip
44
+ @ein = ein
45
+ @industry = industry
46
+ @dba = dba
47
+ @sole_proprietorship = sole_proprietorship
48
+ @passport = passport
49
+ @nationality = nationality
50
+ @device_fingerprints = device_fingerprints
51
+ @idempotency_key = idempotency_key
52
+ @tags = tags
53
+ @jwt_object = jwt_subject
54
+ @power_of_attorney_agent = power_of_attorney_agent
55
+ @evaluation_params = evaluation_params
56
+ @type = "individualApplication"
57
+ end
58
+
59
+ def to_json_api
60
+ payload = {
61
+ data: {
62
+ type: type,
63
+ attributes: {
64
+ ssn: ssn,
65
+ fullName: full_name.represent,
66
+ dateOfBirth: date_of_birth,
67
+ address: address.represent,
68
+ email: email,
69
+ phone: phone.represent,
70
+ ip: ip,
71
+ ein: ein,
72
+ industry: industry,
73
+ dba: dba,
74
+ soleProprietorship: sole_proprietorship,
75
+ passport: passport,
76
+ nationality: nationality,
77
+ idempotencyKey: idempotency_key,
78
+ tags: tags,
79
+ jwtSubject: jwt_subject,
80
+ powerOfAttorneyAgent: power_of_attorney_agent&.represent,
81
+ evaluationParams: evaluation_params&.represent
82
+ }
83
+ }
84
+ }
85
+ payload[:data][:attributes].compact!
86
+ payload.to_json
87
+ end
88
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ # params for list applications
4
+ # See: https://docs.unit.co/applications/#list-applications
5
+ class ListApplicationParams
6
+ attr_reader :offset, :limit, :email, :tags, :query, :sort
7
+
8
+ # @param offset [Integer] Number of resources to skip. See pagination: https://docs.unit.co/#intro-pagination
9
+ # @param limit [Integer] The limit Maximum number of resources that will be returned. Maximum is 1000 resources.
10
+ # @param email [String] Filter applications by email address (case sensitive).
11
+ # @param tags [String] Filter applications by tags. More information regarding tags: https://docs.unit.co/#tags
12
+ # @param query [String] Search term according to the: https://docs.unit.co/#full-text-search
13
+ # @param status [String] Filter applications by status: https://docs.unit.co/applications/#application-statuses
14
+ # @param sort [String] Sorts the resources by the specified field.
15
+ # @option sort=createdAt for ascending order
16
+ # @option sort=-createdAt (leading minus sign) for descending order.
17
+ def initialize(offset = 0, limit = 100, email = nil, tags = nil,
18
+ query = nil, status = nil, sort = nil)
19
+ @offset = offset
20
+ @limit = limit
21
+ @email = email
22
+ @tags = tags
23
+ @query = query
24
+ @status = status
25
+ @sort = sort
26
+ end
27
+
28
+ def to_hash
29
+ params = { "page[limit]": limit,
30
+ "page[offset]": offset,
31
+ "filter[email]": email,
32
+ "filter[tags]": tags,
33
+ "filter[query]": query,
34
+ "filter[status]": status,
35
+ "sort": sort }
36
+ params.compact!
37
+ end
38
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Request to update application
4
+ # See for updating business application: https://docs.unit.co/applications/#update-business-application
5
+ # See for updating individual application: https://docs.unit.co/applications/#update-individual-application
6
+ class PatchApplicationRequest
7
+ attr_reader :application_id, :type, :tags
8
+
9
+ # @param application_id [String] The application id
10
+ # @param type [String] The type
11
+ # @param optional tags [String] The tags
12
+ def initialize(application_id, type, tags = nil)
13
+ @application_id = application_id
14
+ @type = type
15
+ @tags = tags
16
+ end
17
+
18
+ # @return [String] The JSON API payload
19
+ def to_json_api
20
+ payload = {
21
+ data: {
22
+ type: type,
23
+ attributes: { tags: tags }
24
+ }
25
+ }
26
+ payload[:data][:attributes].compact!
27
+ payload.to_json
28
+ end
29
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Creates request for uploading a document
4
+ # See: https://docs.unit.co/application-documents/#upload-document
5
+ class UploadDocumentRequest
6
+ attr_reader :application_id, :document_id, :file, :file_type, :content_type, :is_back_side
7
+
8
+ # @param application_id [String] The application ID
9
+ # @param document_id [String] The document ID
10
+ # @param file [String] The file path
11
+ # @param file_type [String] The file type
12
+ # @option file_type [String] :pdf
13
+ # @option file_type [String] :jpg
14
+ # @option file_type [String] :png
15
+ # @param is_back_side [Boolean] The file is back side
16
+ def initialize(application_id, document_id, file, file_type,
17
+ is_back_side = nil)
18
+ @application_id = application_id
19
+ @document_id = document_id
20
+ @file = file
21
+ @file_type = file_type
22
+ @is_back_side = is_back_side
23
+ end
24
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Request to add authorized users to a project
4
+ # See: https://docs.unit.co/customers#add-authorized-users
5
+ class AddAuthorizedUsersRequest
6
+ attr_reader :customer_id, :authorized_users
7
+
8
+ # @param customer_id [String] The id of customer
9
+ # @param authorized_users [Array<AuthorizedUser>] The authorized users
10
+ def initialize(customer_id, authorized_users)
11
+ @customer_id = customer_id
12
+ @authorized_users = authorized_users
13
+ end
14
+
15
+ def to_json_api
16
+ payload = {
17
+ data: {
18
+ type: "addAuthorizedUsers",
19
+ attributes: {
20
+ authorizedUsers: authorized_users.map(&:represent)
21
+ }
22
+ }
23
+ }
24
+ payload[:data][:attributes].compact!
25
+ payload.to_json
26
+ end
27
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Request to archive customer
4
+ # See: https://docs.unit.co/customers#archive-customer
5
+ class ArchiveCustomerRequest
6
+ attr_reader :customer_id, :reason
7
+
8
+ # @param customer_id [String] The id of customer
9
+ # @param optional reason [String] The reason for archiving the customer
10
+ # @option reason [String] Need to be one of the following: Inactive, FraudACHActivity, FraudCardActivity, FraudCheckActivity, FraudApplicationHistory, FraudAccountActivity, FraudClientIdentified, FraudLinkedToFraudulentCustomer.
11
+ def initialize(customer_id, reason = nil)
12
+ @customer_id = customer_id
13
+ @reason = reason
14
+ end
15
+
16
+ def to_json_api
17
+ payload = {
18
+ data: {
19
+ type: "archiveCustomer",
20
+ attributes: { reason: reason }
21
+ }
22
+ }
23
+ payload[:data][:attributes].compact!
24
+ payload.to_json
25
+ end
26
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ # params for listing customers
4
+ # See: https://docs.unit.co/customers#list-customers
5
+ class ListCustomerParams
6
+ attr_reader :limit, :offset, :query, :email, :tags, :status, :sort
7
+
8
+ # @param optional limit [Integer] Maximum number of resources that will be returned. Maximum is 1000 resources.
9
+ # @param optional offset [Integer] Number of resources to skip. See pagination: https://docs.unit.co/#intro-pagination
10
+ # @param optional query [String] Search term according to the: https://docs.unit.co/#full-text-search
11
+ # @param optional email [String] Filter customers by email address (case sensitive).
12
+ # @param optional tags [Hash] Filter customers by tags. More information regarding tags: https://docs.unit.co/#tags
13
+ # @param optional status [String] Filter customers by status. One of: Active, Archived
14
+ # @param optional sort [String] Sorts the resources by the specified field.
15
+ # @option sort=createdAt for ascending order
16
+ # @option sort=-createdAt (leading minus sign) for descending order.
17
+ def initialize(limit = 100, offset = 0, query = nil, email = nil, tags = nil, status = nil,
18
+ sort = nil)
19
+ @limit = limit
20
+ @offset = offset
21
+ @query = query
22
+ @email = email
23
+ @tags = tags
24
+ @status = status
25
+ @sort = sort
26
+ end
27
+
28
+ def to_hash
29
+ params = { "page[limit]": limit,
30
+ "page[offset]": offset,
31
+ "filter[query]": query,
32
+ "filter[email]": email,
33
+ "filter[tags]": tags,
34
+ "filter[status]": status,
35
+ "sort": sort }
36
+ params.compact!
37
+ end
38
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Update business customer information request
4
+ # See: https://docs.unit.co/customers#update-business-customer
5
+ class PatchBusinessCustomerRequest
6
+ attr_reader :customer_id, :address, :phone, :contact, :authorized_users, :dba, :tags
7
+
8
+ # @param customer_id [String] The id of business
9
+ # @param optional address [Address] The address of business
10
+ # @param optional phone [Phone] The phone of business
11
+ # @param optional contact [BusinessContact] The primary contact of the business
12
+ # @param optional authorized_users [Array<AuthorizedUser>] The authorized users of business
13
+ # @param optional dba [String] The dba of business. To modify or add needed to specify the new dba name.
14
+ # @param optional tags [Hash] Provides opportunity to add, update or delete tags from resources with the tags attribute on the corresponding Update operation
15
+ # more information regarding tags: https://docs.unit.co/#updating-tags
16
+ def initialize(customer_id, address = nil, phone = nil, contact = nil,
17
+ authorized_users = nil, dba = nil, tags = nil)
18
+ @customer_id = customer_id
19
+ @address = address
20
+ @phone = phone
21
+ @contact = contact
22
+ @authorized_users = authorized_users
23
+ @dba = dba
24
+ @tags = tags
25
+ end
26
+
27
+ def to_json_api
28
+ payload = {
29
+ data: {
30
+ type: "businessCustomer",
31
+ attributes: {
32
+ address: address&.represent,
33
+ phone: phone&.represent,
34
+ contact: contact&.represent,
35
+ authorized_users: authorized_users&.map(&:represent),
36
+ dba: dba,
37
+ tags: tags
38
+ }
39
+ }
40
+ }
41
+ payload[:data][:attributes].compact!
42
+ payload.to_json
43
+ end
44
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Update individual customer information request
4
+ # See: https://docs.unit.co/customers#update-individual-customer
5
+ class PatchIndividualCustomerRequest
6
+ attr_reader :customer_id, :address, :phone, :email, :dba, :authorized_users, :tags, :jwt_subject
7
+
8
+ # @param customer_id [String] The id of individual customer
9
+ # @param optional address [Address] The address of individual customer
10
+ # @param optional phone [Phone] The phone of individual customer
11
+ # @param optional email [String] The email of individual customer
12
+ # @param optional dba [String] The dba of individual customer. If the individual is a sole proprietor who is doing business under a different name.
13
+ # @param optional authorized_users [Array<AuthorizedUser>] The authorized users of individual customer
14
+ # @param optional tags [Hash] Provides opportunity to add, update or delete tags from resources with the tags attribute on the corresponding Update operation
15
+ # @param optional jwt_subject [String] The subject of the JWT
16
+ # More information regarding JWTSubject: https://docs.unit.co/customer-api-tokens/#customers-create-customer-bearer-token-jwt
17
+ def initialize(customer_id, address = nil, phone = nil, email = nil, dba = nil, authorized_users = nil, tags = nil, jwt_subject = nil)
18
+ @customer_id = customer_id
19
+ @address = address
20
+ @phone = phone
21
+ @email = email
22
+ @dba = dba
23
+ @authorized_users = authorized_users
24
+ @tags = tags
25
+ @jwt_subject = jwt_subject
26
+ end
27
+
28
+ def to_json_api
29
+ payload = {
30
+ data: {
31
+ type: "individualCustomer",
32
+ attributes: {
33
+ address: address&.represent,
34
+ phone: phone&.represent,
35
+ email: email,
36
+ dba: dba,
37
+ authorized_users: authorized_users&.map(&:represent),
38
+ tags: tags
39
+ }
40
+ }
41
+ }
42
+ payload[:data][:attributes].compact!
43
+ payload.to_json
44
+ end
45
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Request to remove authorized users from customer
4
+ # See: https://docs.unit.co/customers#remove-authorized-users
5
+ class RemoveAuthorizedUsersRequest
6
+ attr_reader :customer_id, :authorized_users_emails
7
+
8
+ # @param customer_id [String] The id of customer
9
+ # @param authorized_users_emails [Array<String>] The list of authorized users emails to remove from the customer.
10
+ def initialize(customer_id, authorized_users_emails)
11
+ @customer_id = customer_id
12
+ @authorized_users_emails = authorized_users_emails
13
+ end
14
+
15
+ def to_json_api
16
+ payload = {
17
+ data: {
18
+ type: "removeAuthorizedUsers",
19
+ attributes: {
20
+ authorizedUsersEmails: authorized_users_emails
21
+ }
22
+ }
23
+ }
24
+ payload[:data][:attributes].compact!
25
+ payload.to_json
26
+ end
27
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ # class that represents objects that can be created
4
+ # Unit's resources include applications, customers, cards, accounts, transactions
5
+ class UnitResource
6
+ attr_reader :id, :type, :attributes, :relationships
7
+
8
+ # @param id [String] The resource's ID
9
+ # @param type [String] The type of the resource
10
+ # @param attributes [Hash] The attributes
11
+ # @param relationships [Hash] The relationships
12
+ def initialize(id, type, attributes, relationships)
13
+ @id = id
14
+ @type = type
15
+ @attributes = attributes
16
+ @relationships = relationships
17
+ end
18
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Represents a response from Unit's API
4
+ class UnitResponse
5
+ attr_reader :data, :included
6
+
7
+ # @param data [Hash] The JSON API payload
8
+ # @param included [Array] The JSON API payload
9
+
10
+ def initialize(data, included, meta)
11
+ @data = data
12
+ @included = included
13
+ @meta = meta
14
+ end
15
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Address
4
+ attr_reader :street, :street2, :city, :state, :postal_code, :country
5
+
6
+ # @param street [String]
7
+ # @param city [String]
8
+ # @param state [String]
9
+ # @param postal_code [String]
10
+ # @param country [String]
11
+ # @param optional street2 [String]
12
+ def initialize(street, city, state, postal_code, country, street2 = nil)
13
+ @street = street
14
+ @street2 = street2
15
+ @city = city
16
+ @state = state
17
+ @postal_code = postal_code
18
+ @country = country
19
+ end
20
+
21
+ def represent
22
+ {
23
+ street: street,
24
+ street2: street2,
25
+ city: city,
26
+ state: state,
27
+ postalCode: postal_code,
28
+ country: country
29
+ }
30
+ end
31
+ end