Class: PaymentRails::RecipientGateway
- Inherits:
-
Object
- Object
- PaymentRails::RecipientGateway
- Includes:
- GatewayHelper
- Defined in:
- lib/paymentrails/gateways/RecipientGateway.rb
Instance Method Summary collapse
- #create(body) ⇒ Object
- #delete(recipient_id) ⇒ Object
- #find(recipient_id) ⇒ Object
-
#initialize(client) ⇒ RecipientGateway
constructor
A new instance of RecipientGateway.
- #recipient_builder(response) ⇒ Object
- #recipient_list_builder(response) ⇒ Object
-
#search(page = 1, page_size = 10, prefix_search = '', filters = {}) ⇒ Object
TODO: if we can afford a breaking change ideally these should be kwargs.
- #update(recipient_id, body) ⇒ Object
Methods included from GatewayHelper
Constructor Details
#initialize(client) ⇒ RecipientGateway
Returns a new instance of RecipientGateway.
8 9 10 |
# File 'lib/paymentrails/gateways/RecipientGateway.rb', line 8 def initialize(client) @client = client end |
Instance Method Details
#create(body) ⇒ Object
17 18 19 20 |
# File 'lib/paymentrails/gateways/RecipientGateway.rb', line 17 def create(body) response = @client.post('/v1/recipients/', body) recipient_builder(response) end |
#delete(recipient_id) ⇒ Object
27 28 29 30 |
# File 'lib/paymentrails/gateways/RecipientGateway.rb', line 27 def delete(recipient_id) @client.delete('/v1/recipients/' + recipient_id) true end |
#find(recipient_id) ⇒ Object
12 13 14 15 |
# File 'lib/paymentrails/gateways/RecipientGateway.rb', line 12 def find(recipient_id) response = @client.get('/v1/recipients/' + recipient_id) recipient_builder(response) end |
#recipient_builder(response) ⇒ Object
44 45 46 47 48 49 50 51 52 |
# File 'lib/paymentrails/gateways/RecipientGateway.rb', line 44 def recipient_builder(response) recipient = Recipient.new data = JSON.parse(response) data.each do |key, value| next unless key === 'recipient' loosely_hydrate_model(recipient, value) end recipient end |
#recipient_list_builder(response) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/paymentrails/gateways/RecipientGateway.rb', line 54 def recipient_list_builder(response) recipients = [] data = JSON.parse(response) data.each do |key, value| next unless key === 'recipients' value.each do |newKey, _newValue| recipient = loosely_hydrate_model(Recipient.new, newKey) recipients.push(recipient) end end recipients end |
#search(page = 1, page_size = 10, prefix_search = '', filters = {}) ⇒ Object
TODO: if we can afford a breaking change ideally these should be kwargs
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/paymentrails/gateways/RecipientGateway.rb', line 33 def search(page = 1, page_size = 10, prefix_search = '', filters = {}) query_string = URI.encode_www_form( page: page.to_s, pageSize: page_size.to_s, search: prefix_search, **filters ) response = @client.get("/v1/recipients?#{query_string}") recipient_list_builder(response) end |
#update(recipient_id, body) ⇒ Object
22 23 24 25 |
# File 'lib/paymentrails/gateways/RecipientGateway.rb', line 22 def update(recipient_id, body) @client.patch('/v1/recipients/' + recipient_id, body) true end |