Class: Unit::Resource::CounterpartyResource

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

Class Method Summary collapse

Methods inherited from BaseResource

file_response_handler, response_handler

Class Method Details

.create_counterparty(request) ⇒ UnitResponse, UnitError

Create a counterparty by calling Unit’s API

Parameters:

  • request (CreateCounterpartyRequest, CreateWithPlaidTokenRequest)

Returns:



16
17
18
19
20
# File 'lib/unit/api_resources/counterparty_resource.rb', line 16

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

.delete(counterparty_id) ⇒ UnitResponse, UnitError

Delete counterparty by calling Unit’s API

Parameters:

  • counterparty_id

    String

Returns:



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

def delete(counterparty_id)
  response = HttpHelper.delete("#{api_url}/counterparties/#{counterparty_id}", headers: headers, response_type: "delete")
  file_response_handler(response)
end

.get_counterparty(counterparty_id) ⇒ UnitResponse, UnitError

Get counterparty by id by calling Unit’s API

Parameters:

  • counterparty_id

    String

Returns:



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

def get_counterparty(counterparty_id)
  response = HttpHelper.get("#{api_url}/counterparties/#{counterparty_id}", headers: headers)
  response_handler(response)
end

.get_counterparty_balance(counterparty_id) ⇒ UnitResponse, UnitError

Get counterparty balance

Parameters:

  • counterparty_id

    String

Returns:



50
51
52
53
# File 'lib/unit/api_resources/counterparty_resource.rb', line 50

def get_counterparty_balance(counterparty_id)
  response = HttpHelper.get("#{api_url}/counterparties/#{counterparty_id}/balance", headers: headers)
  response_handler(response)
end

.list(params = nil) ⇒ UnitResponse, UnitError

List counterparties

Parameters:

  • params (ListCounterpartyParams) (defaults to: nil)

Returns:



58
59
60
61
# File 'lib/unit/api_resources/counterparty_resource.rb', line 58

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

.update_counterparty(request) ⇒ UnitResponse, UnitError

Update counterparty by calling Unit’s API

Parameters:

  • request (UpdateCounterpartyRequest)

Returns:



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

def update_counterparty(request)
  payload = request.to_json_api
  response = HttpHelper.patch("#{api_url}/counterparties/#{request.counterparty_id}", body: payload, headers: headers)
  response_handler(response)
end