Class: Telerivet::Group

Inherits:
Entity
  • Object
show all
Defined in:
lib/telerivet/group.rb

Overview

Represents a group used to organize contacts within Telerivet.

Fields:

- id (string, max 34 characters)
  * ID of the group
  * Read-only

- name
  * Name of the group
  * Updatable via API

- dynamic (bool)
  * Whether this is a dynamic or normal group
  * Read-only

- filters (Hash)
  * Key-value pairs of conditions that contacts must match to be members of a dynamic
      group. To filter by a custom variable, precede the variable name with 'vars.'
      (conditions on custom variables may also be provided as a nested object under a `vars`
      key, e.g. `{"vars": {"city": "Manila"}}`); other supported keys are `id`, `name`,
      `phone_number`, `time_created`, `time_updated`, `incoming_message_count`,
      `outgoing_message_count`, `last_incoming_message_time`, `last_outgoing_message_time`,
      `conversation_status`, `send_blocked`, `group` (ID of a normal group whose members
      should be included), `not_group` (ID of a normal group whose members should be
      excluded), and `q` (full-text search query matching contacts like the search box in
      the web app). Each value is either a value to match exactly, or an object with an
      operator such as `ne`, `prefix`, `gte`, `lt`, `exists`, or `not_exists` as the key
      (e.g. `{"gte": 10}`). Null if this is a normal group. Filter conditions can only be
      updated on dynamic groups.
  * Updatable via API

- num_members (int)
  * Number of contacts in the group (null if the group is dynamic)
  * Read-only

- time_created (UNIX timestamp)
  * Time the group was created in Telerivet
  * Read-only

- allow_sending (bool)
  * True if messages can be sent to this group, false otherwise.
  * Updatable via API

- add_time_variable (string)
  * Variable name of a custom contact field that will automatically be set to the
      current date/time on any contact that is added to the group. This variable will only
      be set if the contact does not already have a value for this variable.
  * Updatable via API

- vars (Hash)
  * Custom variables stored for this group. Variable names may be up to 32 characters in
      length and can contain the characters a-z, A-Z, 0-9, and _.
      Values may be strings, numbers, or boolean (true/false).
      String values may be up to 4096 bytes in length when encoded as UTF-8.
      Up to 100 variables are supported per object.
      Setting a variable to null will delete the variable.
  * Updatable via API

- url
  * URL to this group in the Telerivet web app
  * Read-only

- project_id
  * ID of the project this group belongs to
  * Read-only

Instance Method Summary collapse

Methods inherited from Entity

#get, #initialize, #load, #set, #set_data, #to_s, #vars

Constructor Details

This class inherits a constructor from Telerivet::Entity

Instance Method Details

#add_time_variableObject



255
256
257
# File 'lib/telerivet/group.rb', line 255

def add_time_variable
    get('add_time_variable')
end

#add_time_variable=(value) ⇒ Object



259
260
261
# File 'lib/telerivet/group.rb', line 259

def add_time_variable=(value)
    set('add_time_variable', value)
end

#allow_sendingObject



247
248
249
# File 'lib/telerivet/group.rb', line 247

def allow_sending
    get('allow_sending')
end

#allow_sending=(value) ⇒ Object



251
252
253
# File 'lib/telerivet/group.rb', line 251

def allow_sending=(value)
    set('allow_sending', value)
end

#deleteObject

Deletes this group (Note: no contacts are deleted.)



211
212
213
# File 'lib/telerivet/group.rb', line 211

def delete()
    @api.do_request("DELETE", get_base_api_path())
end

#dynamicObject



227
228
229
# File 'lib/telerivet/group.rb', line 227

def dynamic
    get('dynamic')
end

#filtersObject



231
232
233
# File 'lib/telerivet/group.rb', line 231

def filters
    get('filters')
end

#filters=(value) ⇒ Object



235
236
237
# File 'lib/telerivet/group.rb', line 235

def filters=(value)
    set('filters', value)
end

#get_base_api_pathObject



271
272
273
# File 'lib/telerivet/group.rb', line 271

def get_base_api_path()
    "/projects/#{get('project_id')}/groups/#{get('id')}"
end

#idObject



215
216
217
# File 'lib/telerivet/group.rb', line 215

def id
    get('id')
end

#nameObject



219
220
221
# File 'lib/telerivet/group.rb', line 219

def name
    get('name')
end

#name=(value) ⇒ Object



223
224
225
# File 'lib/telerivet/group.rb', line 223

def name=(value)
    set('name', value)
end

#num_membersObject



239
240
241
# File 'lib/telerivet/group.rb', line 239

def num_members
    get('num_members')
end

#project_idObject



267
268
269
# File 'lib/telerivet/group.rb', line 267

def project_id
    get('project_id')
end

#query_contacts(options = nil) ⇒ Object

Queries contacts that are members of the given group.

Arguments:

- options (Hash)

- name
    * Filter contacts by name
    * Allowed modifiers: name[ne], name[prefix], name[not_prefix], name[gte], name[gt],
        name[lt], name[lte]

- phone_number
    * Filter contacts by phone number
    * Allowed modifiers: phone_number[ne], phone_number[prefix],
        phone_number[not_prefix], phone_number[gte], phone_number[gt], phone_number[lt],
        phone_number[lte], phone_number[exists]

- time_created (UNIX timestamp)
    * Filter contacts by time created
    * Allowed modifiers: time_created[min], time_created[max]

- last_message_time (UNIX timestamp)
    * Filter contacts by last time a message was sent or received
    * Allowed modifiers: last_message_time[min], last_message_time[max],
        last_message_time[exists]

- last_incoming_message_time (UNIX timestamp)
    * Filter contacts by last time a message was received
    * Allowed modifiers: last_incoming_message_time[min],
        last_incoming_message_time[max], last_incoming_message_time[exists]

- last_outgoing_message_time (UNIX timestamp)
    * Filter contacts by last time a message was sent
    * Allowed modifiers: last_outgoing_message_time[min],
        last_outgoing_message_time[max], last_outgoing_message_time[exists]

- incoming_message_count (int)
    * Filter contacts by number of messages received from the contact
    * Allowed modifiers: incoming_message_count[ne], incoming_message_count[min],
        incoming_message_count[max]

- outgoing_message_count (int)
    * Filter contacts by number of messages sent to the contact
    * Allowed modifiers: outgoing_message_count[ne], outgoing_message_count[min],
        outgoing_message_count[max]

- send_blocked (bool)
    * Filter contacts by blocked status

- vars (Hash)
    * Filter contacts by value of a custom variable (e.g. vars[email], vars[foo], etc.)
    * Allowed modifiers: vars[foo][ne], vars[foo][prefix], vars[foo][not_prefix],
        vars[foo][gte], vars[foo][gt], vars[foo][lt], vars[foo][lte], vars[foo][min],
        vars[foo][max], vars[foo][exists]

- sort
    * Sort the results based on a field
    * Allowed values: default, name, phone_number, last_message_time
    * Default: default

- sort_dir
    * Sort the results in ascending or descending order
    * Allowed values: asc, desc
    * Default: asc

- page_size (int)
    * Number of results returned per page (max 500)
    * Default: 50

- offset (int)
    * Number of items to skip from beginning of result set
    * Default: 0

Returns: Telerivet::APICursor (of Telerivet::Contact)



149
150
151
152
# File 'lib/telerivet/group.rb', line 149

def query_contacts(options = nil)
    require_relative 'contact'
    @api.cursor(Contact, get_base_api_path() + "/contacts", options)
end

#query_scheduled_messages(options = nil) ⇒ Object

Queries scheduled messages to the given group.

Arguments:

- options (Hash)

- message_type
    * Filter scheduled messages by message_type
    * Allowed values: sms, mms, ussd, ussd_session, call, chat, service

- time_created (UNIX timestamp)
    * Filter scheduled messages by time_created
    * Allowed modifiers: time_created[min], time_created[max]

- next_time (UNIX timestamp)
    * Filter scheduled messages by next_time
    * Allowed modifiers: next_time[min], next_time[max], next_time[exists]

- relative_scheduled_id
    * Filter scheduled messages created for a relative scheduled message

- sort
    * Sort the results based on a field
    * Allowed values: default, next_time
    * Default: default

- sort_dir
    * Sort the results in ascending or descending order
    * Allowed values: asc, desc
    * Default: asc

- page_size (int)
    * Number of results returned per page (max 500)
    * Default: 50

- offset (int)
    * Number of items to skip from beginning of result set
    * Default: 0

Returns: Telerivet::APICursor (of Telerivet::ScheduledMessage)



196
197
198
199
# File 'lib/telerivet/group.rb', line 196

def query_scheduled_messages(options = nil)
    require_relative 'scheduledmessage'
    @api.cursor(ScheduledMessage, get_base_api_path() + "/scheduled", options)
end

#saveObject

Saves any fields that have changed for this group.



204
205
206
# File 'lib/telerivet/group.rb', line 204

def save()
    super
end

#time_createdObject



243
244
245
# File 'lib/telerivet/group.rb', line 243

def time_created
    get('time_created')
end

#urlObject



263
264
265
# File 'lib/telerivet/group.rb', line 263

def url
    get('url')
end