Class: RecipientGateway

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

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ RecipientGateway

Returns a new instance of RecipientGateway.



5
6
7
# File 'lib/RecipientGateway.rb', line 5

def initialize(client)
  @client = client
end

Instance Method Details

#create(body) ⇒ Object



14
15
16
17
# File 'lib/RecipientGateway.rb', line 14

def create(body)
  response = @client.post('/v1/recipients/', body)
  recipient_builder(response)
end

#delete(recipient_id) ⇒ Object



24
25
26
27
# File 'lib/RecipientGateway.rb', line 24

def delete(recipient_id)
  @client.delete('/v1/recipients/' + recipient_id)
  true
end

#find(recipient_id) ⇒ Object



9
10
11
12
# File 'lib/RecipientGateway.rb', line 9

def find(recipient_id)
  response = @client.get('/v1/recipients/' + recipient_id)
  recipient_builder(response)
end

#recipient_builder(response) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
# 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) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# 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

#search(page = 1, page_size = 10, term = '') ⇒ Object



29
30
31
32
# File 'lib/RecipientGateway.rb', line 29

def search(page = 1, page_size = 10, term = '')
  response = @client.get('/v1/recipients?page=' + page.to_s + '&pageSize=' + page_size.to_s + '&search=' + term)
  recipient_list_builder(response)
end

#update(recipient_id, body) ⇒ Object



19
20
21
22
# File 'lib/RecipientGateway.rb', line 19

def update(recipient_id, body)
  @client.patch('/v1/recipients/' + recipient_id, body)
  true
end