Class: Unit::Resource::CheckDepositResource

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

Class Method Summary collapse

Methods inherited from BaseResource

file_response_handler, response_handler

Class Method Details

.confirm_details(deposit_id) ⇒ UnitResponse, UnitError

Confirm a check deposit by calling Unit’s API

Parameters:

  • deposit_id (String)

Returns:



74
75
76
77
# File 'lib/unit/api_resources/check_deposit_resource.rb', line 74

def confirm_details(deposit_id)
  response = HttpHelper.post("#{api_url}/check-deposits/#{deposit_id}/confirm", headers: headers)
  response_handler(response)
end

.create_deposit(request) ⇒ UnitResponse, UnitError

Create a check deposit by calling Unit’s API

Parameters:

  • request (CreateCheckDepositRequest)

Returns:



15
16
17
18
19
# File 'lib/unit/api_resources/check_deposit_resource.rb', line 15

def create_deposit(request)
  payload = request.to_json_api
  response = HttpHelper.post("#{api_url}/check-deposits", body: payload, headers: headers)
  response_handler(response)
end

.get(params) ⇒ UnitResponse, UnitError

Get a check deposit by id by calling Unit’s API

Parameters:

  • params (GetRequest)

Returns:



24
25
26
27
28
# File 'lib/unit/api_resources/check_deposit_resource.rb', line 24

def get(params)
  payload = params.to_hash
  response = HttpHelper.get("#{api_url}/check-deposits/#{params.deposit_id}", params: payload, headers: headers)
  response_handler(response)
end

.get_image(request) ⇒ UnitResponse, UnitError

Get a check deposit image by calling Unit’s API

Parameters:

  • request (GetImageRequest)

Returns:



65
66
67
68
69
# File 'lib/unit/api_resources/check_deposit_resource.rb', line 65

def get_image(request)
  side = request.is_front_side ? "front" : "back"
  response = HttpHelper.get("#{api_url}/check-deposits/#{request.deposit_id}/#{side}", headers: headers, response_type: "image")
  file_response_handler(response)
end

.list(params = nil) ⇒ UnitResponse, UnitError

Get a list of check deposits by calling Unit’s API

Parameters:

  • params (ListDepositRequest) (defaults to: nil)

Returns:



33
34
35
36
# File 'lib/unit/api_resources/check_deposit_resource.rb', line 33

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

.update(request) ⇒ UnitResponse, UnitError

Update a check deposit by id by calling Unit’s API

Parameters:

  • request (PatchCheckDepositRequest)

Returns:



41
42
43
44
45
# File 'lib/unit/api_resources/check_deposit_resource.rb', line 41

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

.upload(request) ⇒ UnitResponse, UnitError

Upload a check deposit image by calling Unit’s API

Parameters:

  • request (UploadImageRequest)

Returns:



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

def upload(request)
  side = request.is_front_side ? "/front" : "/back"

  headers_updated = headers.clone

  headers_updated["Content-Type"] = "image/jpeg"

  response = HttpHelper.put("#{api_url}/check-deposits/#{request.deposit_id}#{side}", body: request.file_content, headers: headers_updated)

  response_handler(response)
end