Class: Unit::Resource::CustomerResource

Inherits:
BaseResource show all
Defined in:
lib/unit/api_resources/customer_resource.rb

Class Method Summary collapse

Methods inherited from BaseResource

file_response_handler, response_handler

Class Method Details

.add_authorized_users(request) ⇒ UnitResponse, UnitError

Add authorized users to a customer by calling Unit’s API

Parameters:

  • request (AddAuthorizedUsersRequest)

Returns:



51
52
53
54
55
56
57
58
59
# File 'lib/unit/api_resources/customer_resource.rb', line 51

def add_authorized_users(request)
  payload = request.to_json_api
  response = HttpHelper.post(
    "#{api_url}/customers/#{request.customer_id}/authorized-users",
    body: payload,
    headers: headers
  )
  response_handler(response)
end

.archive(request) ⇒ UnitResponse, UnitError

Archive customers by calling Unit’s API

Parameters:

  • request (ArchiveCustomerRequest)

Returns:



42
43
44
45
46
# File 'lib/unit/api_resources/customer_resource.rb', line 42

def archive(request)
  payload = request.to_json_api
  response = HttpHelper.post("#{api_url}/customers/#{request.customer_id}/archive", body: payload, headers: headers)
  response_handler(response)
end

.get(customer_id) ⇒ UnitResponse, UnitError

Get a customer by calling Unit’s API

Parameters:

  • customer_id (String)

Returns:



26
27
28
29
# File 'lib/unit/api_resources/customer_resource.rb', line 26

def get(customer_id)
  response = HttpHelper.get("#{api_url}/customers/#{customer_id}", headers: headers)
  response_handler(response)
end

.list(params = nil) ⇒ UnitResponse, UnitError

Get customers by calling Unit’s API

Parameters:

  • params (ListCustomerParams) (defaults to: nil)

Returns:



34
35
36
37
# File 'lib/unit/api_resources/customer_resource.rb', line 34

def list(params = nil)
  response = HttpHelper.get("#{api_url}/customers", params: params&.to_hash, headers: headers)
  response_handler(response)
end

.remove_authorized_users(request) ⇒ UnitResponse, UnitError

Remove authorized users from a customer by calling Unit’s API

Parameters:

  • request (RemoveAuthorizedUsersRequest)

Returns:



64
65
66
67
68
# File 'lib/unit/api_resources/customer_resource.rb', line 64

def remove_authorized_users(request)
  payload = request.to_json_api
  response = HttpHelper.delete("#{api_url}/customers/#{request.customer_id}/authorized-users", body: payload, headers: headers)
  response_handler(response)
end

.update(request) ⇒ UnitResponse, UnitError

Update a customer by calling Unit’s API

Parameters:

  • request (PatchIndividualCustomerRequest, PatchBusinessCustomerRequest, PatchTrustCustomerRequest)

Returns:



17
18
19
20
21
# File 'lib/unit/api_resources/customer_resource.rb', line 17

def update(request)
  payload = request.to_json_api
  response = HttpHelper.patch("#{api_url}/customers/#{request.customer_id}", body: payload, headers: headers)
  response_handler(response)
end