class RecipientGateway

Public Class Methods

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

Public Instance Methods

create(body) click to toggle source
# File lib/RecipientGateway.rb, line 14
def create(body)
  response = @client.post('/v1/recipients/', body)
  recipient_builder(response)
end
delete(recipient_id) click to toggle source
# File lib/RecipientGateway.rb, line 24
def delete(recipient_id)
  @client.delete('/v1/recipients/' + recipient_id)
  true
end
find(recipient_id) click to toggle source
# File lib/RecipientGateway.rb, line 9
def find(recipient_id)
  response = @client.get('/v1/recipients/' + recipient_id)
  recipient_builder(response)
end
recipient_builder(response) click to toggle source
# File lib/RecipientGateway.rb, line 34
def recipient_builder(response)
  recipient = Recipient.new
  data = JSON.parse(response)
  data.each do |key, value|
    next unless key === 'recipient'
    value.each do |recipKey, recipValue|
      recipient.send("#{recipKey}=", recipValue)
    end
  end
  recipient
end
recipient_list_builder(response) click to toggle source
# File lib/RecipientGateway.rb, line 46
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 = Recipient.new
      newKey.each do |key1, value1|
        recipient.send("#{key1}=", value1)
      end
      recipients.push(recipient)
    end
  end
  recipients
end
update(recipient_id, body) click to toggle source
# File lib/RecipientGateway.rb, line 19
def update(recipient_id, body)
  @client.patch('/v1/recipients/' + recipient_id, body)
  true
end