Class: Unit::Resource::ApplicationResource

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

Class Method Summary collapse

Methods inherited from BaseResource

file_response_handler, response_handler

Class Method Details

.create_application(request) ⇒ UnitResponse, UnitError

Create a new application by calling Unit’s API

Parameters:

  • request (CreateIndividualApplicationRequest, CreateBusinessApplicationRequest)

Returns:



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

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

.get_application(application_id) ⇒ UnitResponse, UnitError

Get an application by calling Unit’s API

Parameters:

  • application_id (String)

Returns:



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

def get_application(application_id)
  response = HttpHelper.get("#{api_url}/applications/#{application_id}", headers: headers)
  response_handler(response)
end

.list_applications(params = nil) ⇒ UnitResponse, UnitError

List applications by calling Unit’s API

Parameters:

  • params (ListApplicationParams) (defaults to: nil)

Returns:



32
33
34
35
# File 'lib/unit/api_resources/application_resource.rb', line 32

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

.update(request) ⇒ UnitResponse, UnitError

Update an application by calling Unit’s API

Parameters:

  • request (PatchApplicationRequest)

Returns:



61
62
63
64
65
# File 'lib/unit/api_resources/application_resource.rb', line 61

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

.upload(request) ⇒ UnitResponse, UnitError

Upload a document to an application

Parameters:

  • request (UploadDocumentRequest)

Returns:



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/unit/api_resources/application_resource.rb', line 40

def upload(request)
  url = "#{api_url}/applications/#{request.application_id}/documents/#{request.document_id}"
  url += "/back" if request.is_back_side

  headers = {
    "Authorization" => "Bearer #{token}",
    "User-Agent" => "unit-ruby-sdk"
  }

  headers["Content-Type"] = "application/pdf" if request.file_type == "pdf"
  headers["Content-Type"] = "image/jpeg" if request.file_type == "jpeg"
  headers["Content-Type"] = "image/png" if request.file_type == "png"

  response = HttpHelper.put(url, body: request.file, headers: headers)

  response_handler(response)
end