class PaymentRails::RecipientGateway

Public Class Methods

new(client) click to toggle source
# File lib/paymentrails/gateways/RecipientGateway.rb, line 8
def initialize(client)
  @client = client
end

Public Instance Methods

create(body) click to toggle source
# File lib/paymentrails/gateways/RecipientGateway.rb, line 17
def create(body)
  response = @client.post('/v1/recipients/', body)
  recipient_builder(response)
end
delete(recipient_id) click to toggle source
# File lib/paymentrails/gateways/RecipientGateway.rb, line 27
def delete(recipient_id)
  @client.delete('/v1/recipients/' + recipient_id)
  true
end
find(recipient_id) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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
update(recipient_id, body) click to toggle source
# File lib/paymentrails/gateways/RecipientGateway.rb, line 22
def update(recipient_id, body)
  @client.patch('/v1/recipients/' + recipient_id, body)
  true
end