Class: SynapsePayRest::Transactions
- Inherits:
-
Object
- Object
- SynapsePayRest::Transactions
- Defined in:
- lib/synapse_pay_rest/api/transactions.rb
Overview
Implement idempotency keys
Wrapper class for /trans endpoints
Constant Summary collapse
- VALID_QUERY_PARAMS =
TODO:
Refactor to HTTPClient
Valid optional args for #get
[:page, :per_page].freeze
Instance Attribute Summary collapse
Instance Method Summary collapse
-
#create(user_id:, node_id:, payload:, idempotency_key: nil) ⇒ Hash
Sends a POST request to /trans endpoint to create a new transaction.
-
#delete(user_id:, node_id:, trans_id:) ⇒ Hash
Sends a DELETE request to /trans endpoint to cancel a transaction.
-
#get(user_id:, node_id:, trans_id: nil, **options) ⇒ Hash
Sends a GET request to /trans endpoint.
-
#initialize(client) ⇒ Transactions
constructor
A new instance of Transactions.
-
#update(user_id:, node_id:, trans_id:, payload:) ⇒ Hash
Sends a PATCH request to /trans endpoint to update a transaction.
Constructor Details
#initialize(client) ⇒ Transactions
Returns a new instance of Transactions.
16 17 18 |
# File 'lib/synapse_pay_rest/api/transactions.rb', line 16 def initialize(client) @client = client end |
Instance Attribute Details
#client ⇒ SynapsePayRest::HTTPClient
13 14 15 |
# File 'lib/synapse_pay_rest/api/transactions.rb', line 13 def client @client end |
Instance Method Details
#create(user_id:, node_id:, payload:, idempotency_key: nil) ⇒ Hash
Sends a POST request to /trans endpoint to create a new transaction. Returns the response.
HTTP response from API
60 61 62 63 |
# File 'lib/synapse_pay_rest/api/transactions.rb', line 60 def create(user_id:, node_id:, payload:, idempotency_key: nil) path = create_transaction_path(user_id: user_id, node_id: node_id) client.post(path, payload, idempotency_key: idempotency_key) end |
#delete(user_id:, node_id:, trans_id:) ⇒ Hash
Sends a DELETE request to /trans endpoint to cancel a transaction. Returns the response.
HTTP response from API
94 95 96 97 |
# File 'lib/synapse_pay_rest/api/transactions.rb', line 94 def delete(user_id:, node_id:, trans_id:) path = create_transaction_path(user_id: user_id, node_id: node_id, trans_id: trans_id) client.delete(path) end |
#get(user_id:, node_id:, trans_id: nil, **options) ⇒ Hash
Probably should use CGI or RestClient’s param builder instead of
Sends a GET request to /trans endpoint. Queries a specific transaction_id if trans_id supplied, else queries all transactions. Returns the response.
HTTP response from API
rolling our own, probably error-prone and untested version github.com/rest-client/rest-client#usage-raw-url
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/synapse_pay_rest/api/transactions.rb', line 37 def get(user_id:, node_id:, trans_id: nil, **) path = create_transaction_path(user_id: user_id, node_id: node_id, trans_id: trans_id) params = VALID_QUERY_PARAMS.map do |p| [p] ? "#{p}=#{[p]}" : nil end.compact path += '?' + params.join('&') if params.any? client.get(path) end |
#update(user_id:, node_id:, trans_id:, payload:) ⇒ Hash
Sends a PATCH request to /trans endpoint to update a transaction. Returns the response.
HTTP response from API
78 79 80 81 |
# File 'lib/synapse_pay_rest/api/transactions.rb', line 78 def update(user_id:, node_id:, trans_id:, payload:) path = create_transaction_path(user_id: user_id, node_id: node_id, trans_id: trans_id) client.patch(path, payload) end |