Class: GeneratorLabs::Contacts
- Inherits:
-
Object
- Object
- GeneratorLabs::Contacts
- Defined in:
- lib/generatorlabs/contact.rb
Overview
Contact management
Instance Method Summary collapse
-
#confirm(id, params) ⇒ Hash
Confirm a contact with an auth code.
-
#create(params) ⇒ Hash
Create a new contact.
-
#delete(id) ⇒ Hash
Delete a contact.
-
#get(*ids) ⇒ Hash
Get contacts (all, by ID, or by array of IDs).
-
#get_all(params = {}) ⇒ Array
Get all contacts with automatic pagination.
-
#initialize(handler) ⇒ Contacts
constructor
A new instance of Contacts.
-
#pause(id) ⇒ Hash
Pause a contact.
-
#resend(id) ⇒ Hash
Resend confirmation to a contact.
-
#resume(id) ⇒ Hash
Resume a contact.
-
#update(id, params) ⇒ Hash
Update a contact.
Constructor Details
#initialize(handler) ⇒ Contacts
Returns a new instance of Contacts.
34 35 36 |
# File 'lib/generatorlabs/contact.rb', line 34 def initialize(handler) @handler = handler end |
Instance Method Details
#confirm(id, params) ⇒ Hash
Confirm a contact with an auth code
115 116 117 |
# File 'lib/generatorlabs/contact.rb', line 115 def confirm(id, params) @handler.post("contact/contacts/#{id}/confirm", params) end |
#create(params) ⇒ Hash
Create a new contact
78 79 80 |
# File 'lib/generatorlabs/contact.rb', line 78 def create(params) @handler.post('contact/contacts', params) end |
#delete(id) ⇒ Hash
Delete a contact
93 94 95 |
# File 'lib/generatorlabs/contact.rb', line 93 def delete(id) @handler.delete("contact/contacts/#{id}") end |
#get(*ids) ⇒ Hash
Get contacts (all, by ID, or by array of IDs)
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/generatorlabs/contact.rb', line 41 def get(*ids) return @handler.get('contact/contacts') if ids.empty? # Check if first argument is a hash (parameters) return @handler.get('contact/contacts', ids.first) if ids.first.is_a?(Hash) return @handler.get("contact/contacts/#{ids.first}") if ids.length == 1 @handler.get('contact/contacts', { ids: ids.join(',') }) end |
#get_all(params = {}) ⇒ Array
Get all contacts with automatic pagination
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/generatorlabs/contact.rb', line 55 def get_all(params = {}) all_items = [] page = 1 params = params.dup loop do params[:page] = page response = get(params) contacts = response['contacts'] || [] all_items.concat(contacts) break unless page < (response['total_pages'] || 1) && !contacts.empty? page += 1 end all_items end |
#pause(id) ⇒ Hash
Pause a contact
100 101 102 |
# File 'lib/generatorlabs/contact.rb', line 100 def pause(id) @handler.post("contact/contacts/#{id}/pause") end |
#resend(id) ⇒ Hash
Resend confirmation to a contact
122 123 124 |
# File 'lib/generatorlabs/contact.rb', line 122 def resend(id) @handler.post("contact/contacts/#{id}/resend") end |
#resume(id) ⇒ Hash
Resume a contact
107 108 109 |
# File 'lib/generatorlabs/contact.rb', line 107 def resume(id) @handler.post("contact/contacts/#{id}/resume") end |
#update(id, params) ⇒ Hash
Update a contact
86 87 88 |
# File 'lib/generatorlabs/contact.rb', line 86 def update(id, params) @handler.put("contact/contacts/#{id}", params) end |