Class: GeneratorLabs::Contacts

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

Overview

Contact management

Instance Method Summary collapse

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

Parameters:

  • id (String, Integer)

    Contact ID

  • params (Hash)

    Confirmation parameters (authcode)

Returns:

  • (Hash)

    Response



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

Parameters:

  • params (Hash)

    Contact parameters

Returns:

  • (Hash)

    Created contact data



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

Parameters:

  • id (String, Integer)

    Contact ID

Returns:

  • (Hash)

    Deletion confirmation



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)

Parameters:

  • ids (nil, String, Integer, Hash, Array)

    Optional ID(s) or parameters

Returns:

  • (Hash)

    Contact data



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

Parameters:

  • params (Hash) (defaults to: {})

    Optional parameters (e.g., page_size)

Returns:

  • (Array)

    All contacts across all pages



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

Parameters:

  • id (String, Integer)

    Contact ID

Returns:

  • (Hash)

    Response



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

Parameters:

  • id (String, Integer)

    Contact ID

Returns:

  • (Hash)

    Response



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

Parameters:

  • id (String, Integer)

    Contact ID

Returns:

  • (Hash)

    Response



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

Parameters:

  • id (String, Integer)

    Contact ID

  • params (Hash)

    Updated parameters

Returns:

  • (Hash)

    Updated contact data



86
87
88
# File 'lib/generatorlabs/contact.rb', line 86

def update(id, params)
  @handler.put("contact/contacts/#{id}", params)
end