Module: Clutch
- Defined in:
- lib/clutch.rb,
lib/clutch/client.rb,
lib/clutch/version.rb,
lib/clutch/configuration.rb,
lib/clutch/response_exception.rb
Defined Under Namespace
Classes: Client, Configuration, ResponseException
Constant Summary
collapse
- VERSION =
"0.1.1"
Class Attribute Summary collapse
Class Method Summary
collapse
-
.allocate(card_set_id:) ⇒ Object
-
.client ⇒ Object
-
.configure {|configuration| ... } ⇒ Object
-
.find(card_number:) ⇒ Object
-
.history(card_number:) ⇒ Object
-
.hold(card_number:, dollars:) ⇒ Object
-
.issue(card_number:, dollars:, is_return_related: false) ⇒ Object
-
.redeem(card_number:, dollars:) ⇒ Object
-
.redeem_hold(card_number:, dollars:, hold_transaction_id:) ⇒ Object
-
.release_hold(card_number:, dollars:, hold_transaction_id:) ⇒ Object
-
.search(filters:, returnFields:) ⇒ Object
-
.validate(filters:, returnFields:, pin:) ⇒ Object
Class Attribute Details
.configuration ⇒ Object
Returns the value of attribute configuration.
10
11
12
|
# File 'lib/clutch.rb', line 10
def configuration
@configuration
end
|
Class Method Details
.allocate(card_set_id:) ⇒ Object
24
25
26
|
# File 'lib/clutch.rb', line 24
def allocate(card_set_id:)
client.post "/allocate", cardSetId: card_set_id
end
|
.client ⇒ Object
20
21
22
|
# File 'lib/clutch.rb', line 20
def client
@client ||= Client.new
end
|
12
13
14
|
# File 'lib/clutch.rb', line 12
def configure
yield(configuration)
end
|
.find(card_number:) ⇒ Object
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
# File 'lib/clutch.rb', line 56
def find(card_number:)
result = history(card_number: card_number)
if (result.success)
card = search(
filters: { cardNumber: card_number },
returnFields: {
balances: true,
checkouts: true,
customData: true,
activationDate: true
}
).cards.first
card.activated = true
return card
end
case result.errorMessage
when 'Could not find the specified card.'
raise Clutch::ResponseException.new(result), result.errorMessage
when 'Could not find the account that goes with the specified card.'
return { cardNumber: card_number, activated: false, balances: [] }
else
raise Clutch::ResponseException.new(result), result.errorMessage
end
end
|
.history(card_number:) ⇒ Object
32
33
34
|
# File 'lib/clutch.rb', line 32
def history(card_number:)
client.post "/cardHistory", cardNumber: card_number
end
|
.hold(card_number:, dollars:) ⇒ Object
28
29
30
|
# File 'lib/clutch.rb', line 28
def hold(card_number:, dollars:)
update_balance card_number, dollars, :hold
end
|
.issue(card_number:, dollars:, is_return_related: false) ⇒ Object
36
37
38
|
# File 'lib/clutch.rb', line 36
def issue(card_number:, dollars:, is_return_related: false)
update_balance card_number, dollars, "issue", is_return_related: is_return_related
end
|
.redeem(card_number:, dollars:) ⇒ Object
40
41
42
|
# File 'lib/clutch.rb', line 40
def redeem(card_number:, dollars:)
update_balance card_number, dollars, "redeem"
end
|
.redeem_hold(card_number:, dollars:, hold_transaction_id:) ⇒ Object
44
45
46
|
# File 'lib/clutch.rb', line 44
def redeem_hold(card_number:, dollars:, hold_transaction_id:)
update_balance card_number, dollars, "redeem", hold_transaction_id: hold_transaction_id
end
|
.release_hold(card_number:, dollars:, hold_transaction_id:) ⇒ Object
48
49
50
|
# File 'lib/clutch.rb', line 48
def release_hold(card_number:, dollars:, hold_transaction_id:)
update_balance card_number, dollars, "redeem", hold_transaction_id: hold_transaction_id, release_hold_remainder: true
end
|
.search(filters:, returnFields:) ⇒ Object
52
53
54
|
# File 'lib/clutch.rb', line 52
def search(filters:, returnFields:)
client.post "/search", filters: filters, returnFields: returnFields
end
|
.validate(filters:, returnFields:, pin:) ⇒ Object
83
84
85
86
87
|
# File 'lib/clutch.rb', line 83
def validate(filters:, returnFields:, pin:)
response = client.post "/search", filters: filters, returnFields: returnFields, forcePinValidation: true, pin: pin
raise Clutch::ResponseException.new(response), response.errorMessage unless response.success?
response
end
|