class BloomRemit2::Recipient

Attributes

address[R]
city[R]
country[R]
deleted[R]
email[R]
first_name[R]
id[R]
last_name[R]
mobile[R]
province[R]
remittance_ids[R]
sender_id[R]
state[R]

Public Class Methods

create(sender_id, recipient_hash) click to toggle source
# File lib/bloom_remit2/recipient.rb, line 4
def create(sender_id, recipient_hash)
  recipient = Client.post(path(sender_id), recipient_hash)
  initialize_from_hash(recipient['recipient'])
end
delete(sender_id, recipient_id) click to toggle source
# File lib/bloom_remit2/recipient.rb, line 28
def delete(sender_id, recipient_id)
  message = Client.delete("#{path(sender_id)}/#{recipient_id}").with_indifferent_access
  if message[:success] == "We've successfully deleted that recipient."
    new(
      recipient_id,
      sender_id,
      deleted: true
    )
  end
end
list(sender_id) click to toggle source
# File lib/bloom_remit2/recipient.rb, line 9
def list(sender_id)
  recipients = Client.get(path(sender_id))
  recipients.map { |recipient| initialize_from_hash(recipient) }
end
new( id, sender_id, first_name=nil, last_name=nil, email=nil, mobile=nil, address=nil, city=nil, province=nil, country=nil, remittance_ids=nil, deleted: false ) click to toggle source
# File lib/bloom_remit2/recipient.rb, line 66
def initialize(
  id,
  sender_id,
  first_name=nil,
  last_name=nil,
  email=nil,
  mobile=nil,
  address=nil,
  city=nil,
  province=nil,
  country=nil,
  remittance_ids=nil,
  deleted: false
)
  @id = id
  @sender_id = sender_id
  @first_name = first_name
  @last_name = last_name
  @email = email
  @mobile = mobile
  @address = address
  @city = city
  @province = province
  @country = country
  @remittance_ids = remittance_ids
  @deleted = deleted
end
retrieve(sender_id, recipient_id) click to toggle source
# File lib/bloom_remit2/recipient.rb, line 14
def retrieve(sender_id, recipient_id)
  recipient = Client.get("#{path(sender_id)}/#{recipient_id}")
  initialize_from_hash(recipient['recipient'], recipient['remittance_ids'])
end
update(sender_id, recipient_id, recipient_hash) click to toggle source
# File lib/bloom_remit2/recipient.rb, line 19
def update(sender_id, recipient_id, recipient_hash)
  body = []
  recipient_hash.each do |k, v|
    body << ["recipient[#{k.to_s.downcase}]", v]
  end
  recipient = Client.put("#{path(sender_id)}/#{recipient_id}", body)
  initialize_from_hash(recipient['recipient'])
end

Private Class Methods

initialize_from_hash(recipient, remittance_ids=nil) click to toggle source
# File lib/bloom_remit2/recipient.rb, line 45
def initialize_from_hash(recipient, remittance_ids=nil)
  recipient = recipient.with_indifferent_access
  new(
    recipient[:id],
    recipient[:sender_id],
    recipient[:first_name],
    recipient[:last_name],
    recipient[:email],
    recipient[:mobile],
    recipient[:address],
    recipient[:city],
    recipient[:state],
    recipient[:country],
    remittance_ids
  )
end
path(sender_id) click to toggle source
# File lib/bloom_remit2/recipient.rb, line 41
def path(sender_id)
  "api/v1/partners/#{BloomRemit2.configuration.api_token}/senders/#{sender_id}/recipients"
end