Class: Unit::Resource::CardResource

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

Class Method Summary collapse

Methods inherited from BaseResource

file_response_handler, response_handler

Class Method Details

.close_card(card_id) ⇒ UnitResponse, UnitError

Close a card by calling Unit’s API

Parameters:

  • card_id (String)

Returns:



48
49
50
51
# File 'lib/unit/api_resources/card_resource.rb', line 48

def close_card(card_id)
  response = HttpHelper.post("#{api_url}/cards/#{card_id}/close", headers: headers)
  response_handler(response)
end

.create_card(request) ⇒ UnitResponse, UnitError

Create a new card by calling Unit’s API

Parameters:

  • request (CreateIndividualDebitCardRequest, CreateIndividualVirtualCardRequest)

Returns:



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

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

.freeze_card(card_id) ⇒ UnitResponse, UnitError

Freeze a card by calling Unit’s API

Parameters:

  • card_id (String)

Returns:



56
57
58
59
# File 'lib/unit/api_resources/card_resource.rb', line 56

def freeze_card(card_id)
  response = HttpHelper.post("#{api_url}/cards/#{card_id}/freeze", headers: headers)
  response_handler(response)
end

.get_card(card_id) ⇒ UnitResponse, UnitError

Get a card by id by calling Unit’s API

Parameters:

  • card_id (String)

Returns:



81
82
83
84
# File 'lib/unit/api_resources/card_resource.rb', line 81

def get_card(card_id)
  response = HttpHelper.get("#{api_url}/cards/#{card_id}", headers: headers)
  response_handler(response)
end

.get_pin_status(card_id) ⇒ UnitResponse, UnitError

Get pin status by calling Unit’s API

Parameters:

  • card_id (String)

Returns:



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

def get_pin_status(card_id)
  response = HttpHelper.get("#{api_url}/cards/#{card_id}/secure-data/pin/status", headers: headers)
  response_handler(response)
end

.limits(card_id) ⇒ UnitResponse, UnitError

Get card limits by calling Unit’s API

Parameters:

  • card_id (String)

Returns:



105
106
107
108
# File 'lib/unit/api_resources/card_resource.rb', line 105

def limits(card_id)
  response = HttpHelper.get("#{api_url}/cards/#{card_id}/limits", headers: headers)
  response_handler(response)
end

.list_cards(params = nil) ⇒ UnitResponse, UnitError

List cards by calling Unit’s API

Parameters:

  • params (ListCardParams) (defaults to: nil)

Returns:



97
98
99
100
# File 'lib/unit/api_resources/card_resource.rb', line 97

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

.replace_card(request) ⇒ UnitResponse, UnitError

Replace a card by calling Unit’s API

Parameters:

  • request (ReplaceCardRequest)

Returns:



72
73
74
75
76
# File 'lib/unit/api_resources/card_resource.rb', line 72

def replace_card(request)
  payload = request.to_json_api
  response = HttpHelper.post("#{api_url}/cards/#{request.card_id}/replace", body: payload, headers: headers)
  response_handler(response)
end

.report_lost(card_id) ⇒ UnitResponse, UnitError

Report a card as a lost by calling Unit’s API

Parameters:

  • card_id (String)

Returns:



40
41
42
43
# File 'lib/unit/api_resources/card_resource.rb', line 40

def report_lost(card_id)
  response = HttpHelper.post("#{api_url}/cards/#{card_id}/report-lost", headers: headers)
  response_handler(response)
end

.report_stolen(card_id) ⇒ UnitResponse, UnitError

Report a card as a stolen by calling Unit’s API

Parameters:

  • card_id (String)

Returns:



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

def report_stolen(card_id)
  response = HttpHelper.post("#{api_url}/cards/#{card_id}/report-stolen", headers: headers)
  response_handler(response)
end

.unfreeze_card(card_id) ⇒ UnitResponse, UnitError

Unfreeze a card by calling Unit’s API

Parameters:

  • card_id (String)

Returns:



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

def unfreeze_card(card_id)
  response = HttpHelper.post("#{api_url}/cards/#{card_id}/unfreeze", headers: headers)
  response_handler(response)
end

.update(request) ⇒ Object

Update card by calling Unit’s API

Parameters:

  • request (PatchBusinessCardRequest, PatchBusinessCreditCardRequest, PatchBusinessVirtualCardRequest, PatchBusinessVirtualCreditCardRequest)


88
89
90
91
92
# File 'lib/unit/api_resources/card_resource.rb', line 88

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