Class: GeneratorLabs::Groups
- Inherits:
-
Object
- Object
- GeneratorLabs::Groups
- Defined in:
- lib/generatorlabs/contact.rb
Overview
Group management
Instance Method Summary collapse
-
#create(params) ⇒ Hash
Create a new contact group.
-
#delete(id) ⇒ Hash
Delete a contact group.
-
#get(*ids) ⇒ Hash
Get groups (all, by ID, or by array of IDs).
-
#get_all(params = {}) ⇒ Array
Get all groups with automatic pagination.
-
#initialize(handler) ⇒ Groups
constructor
A new instance of Groups.
-
#update(id, params) ⇒ Hash
Update a contact group.
Constructor Details
#initialize(handler) ⇒ Groups
Returns a new instance of Groups.
129 130 131 |
# File 'lib/generatorlabs/contact.rb', line 129 def initialize(handler) @handler = handler end |
Instance Method Details
#create(params) ⇒ Hash
Create a new contact group
173 174 175 |
# File 'lib/generatorlabs/contact.rb', line 173 def create(params) @handler.post('contact/groups', params) end |
#delete(id) ⇒ Hash
Delete a contact group
188 189 190 |
# File 'lib/generatorlabs/contact.rb', line 188 def delete(id) @handler.delete("contact/groups/#{id}") end |
#get(*ids) ⇒ Hash
Get groups (all, by ID, or by array of IDs)
136 137 138 139 140 141 142 143 144 145 |
# File 'lib/generatorlabs/contact.rb', line 136 def get(*ids) return @handler.get('contact/groups') if ids.empty? # Check if first argument is a hash (parameters) return @handler.get('contact/groups', ids.first) if ids.first.is_a?(Hash) return @handler.get("contact/groups/#{ids.first}") if ids.length == 1 @handler.get('contact/groups', { ids: ids.join(',') }) end |
#get_all(params = {}) ⇒ Array
Get all groups with automatic pagination
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/generatorlabs/contact.rb', line 150 def get_all(params = {}) all_items = [] page = 1 params = params.dup loop do params[:page] = page response = get(params) groups = response['groups'] || [] all_items.concat(groups) break unless page < (response['total_pages'] || 1) && !groups.empty? page += 1 end all_items end |
#update(id, params) ⇒ Hash
Update a contact group
181 182 183 |
# File 'lib/generatorlabs/contact.rb', line 181 def update(id, params) @handler.put("contact/groups/#{id}", params) end |