Class: BloomRemit2::Recipient

Inherits:
Object
  • Object
show all
Defined in:
lib/bloom_remit2/recipient.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#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) ⇒ Recipient

Returns a new instance of Recipient.



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# 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

Instance Attribute Details

#addressObject (readonly)

Returns the value of attribute address.



63
64
65
# File 'lib/bloom_remit2/recipient.rb', line 63

def address
  @address
end

#cityObject (readonly)

Returns the value of attribute city.



63
64
65
# File 'lib/bloom_remit2/recipient.rb', line 63

def city
  @city
end

#countryObject (readonly)

Returns the value of attribute country.



63
64
65
# File 'lib/bloom_remit2/recipient.rb', line 63

def country
  @country
end

#deletedObject (readonly)

Returns the value of attribute deleted.



63
64
65
# File 'lib/bloom_remit2/recipient.rb', line 63

def deleted
  @deleted
end

#emailObject (readonly)

Returns the value of attribute email.



63
64
65
# File 'lib/bloom_remit2/recipient.rb', line 63

def email
  @email
end

#first_nameObject (readonly)

Returns the value of attribute first_name.



63
64
65
# File 'lib/bloom_remit2/recipient.rb', line 63

def first_name
  @first_name
end

#idObject (readonly)

Returns the value of attribute id.



63
64
65
# File 'lib/bloom_remit2/recipient.rb', line 63

def id
  @id
end

#last_nameObject (readonly)

Returns the value of attribute last_name.



63
64
65
# File 'lib/bloom_remit2/recipient.rb', line 63

def last_name
  @last_name
end

#mobileObject (readonly)

Returns the value of attribute mobile.



63
64
65
# File 'lib/bloom_remit2/recipient.rb', line 63

def mobile
  @mobile
end

#provinceObject (readonly) Also known as: state

Returns the value of attribute province.



63
64
65
# File 'lib/bloom_remit2/recipient.rb', line 63

def province
  @province
end

#remittance_idsObject (readonly)

Returns the value of attribute remittance_ids.



63
64
65
# File 'lib/bloom_remit2/recipient.rb', line 63

def remittance_ids
  @remittance_ids
end

#sender_idObject (readonly)

Returns the value of attribute sender_id.



63
64
65
# File 'lib/bloom_remit2/recipient.rb', line 63

def sender_id
  @sender_id
end

Class Method Details

.create(sender_id, recipient_hash) ⇒ Object



4
5
6
7
# 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) ⇒ Object



28
29
30
31
32
33
34
35
36
37
# 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) ⇒ Object



9
10
11
12
# 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

.retrieve(sender_id, recipient_id) ⇒ Object



14
15
16
17
# 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) ⇒ Object



19
20
21
22
23
24
25
26
# 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