Class: ZendeskSupportAPI::Groups

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

Overview

Class Method Summary collapse

Class Method Details

.assignable(client) ⇒ Array

Shows assignable groups (first 100)

Examples:

ZendeskSupportAPI::Groups.assignable(client)
#=> [
#=>   {
#=>     "name":       "DJs",
#=>     "created_at": "2009-05-13T00:07:08Z",
#=>     "updated_at": "2011-07-22T00:11:12Z",
#=>     "id":         211
#=>   },
#=>   {
#=>     "name":       "MCs",
#=>     "created_at": "2009-08-26T00:07:08Z",
#=>     "updated_at": "2010-05-13T00:07:08Z",
#=>     "id":         122
#=>   }
#=> ]

Parameters:

Returns:

  • (Array)


87
88
89
# File 'lib/zendesk_support_api/groups.rb', line 87

def self.assignable(client)
  client.request(:get, 'assignable.json')['groups']
end

.create(client, group) ⇒ String|Hash

Create a group

Examples:

group = {
  name: 'Test Group'
}
ZendeskSupportAPI::Groups.create(client, group)
#=> {
#=>   "name": "Test Group",
#=>   "created_at": "2011-04-20T17:49:00Z",
#=>    "updated_at": "2011-04-20T17:49:00Z",
#=>    "id":         123
#=> }

Parameters:

Returns:

  • (String|Hash)


128
129
130
131
132
133
# File 'lib/zendesk_support_api/groups.rb', line 128

def self.create(client, group)
  res = client.request(:post, 'groups.json', group: group)
  return "Creation failed: #{res['details']}" if res['error']

  res
end

.delete(client, gid) ⇒ String

Deletes a group

Examples:

ZendeskSupportAPI::Groups.delete(client, 123)
#=> Group 123 has been deleted

Parameters:

Returns:

  • (String)


171
172
173
174
175
176
# File 'lib/zendesk_support_api/groups.rb', line 171

def self.delete(client, gid)
  res = client.request(:delete, "groups/#{gid}.json")
  return "Deletion of #{gid} failed: #{res['error']}" if res['error']

  "Group #{gid} has been deleted"
end

.group_object(group, users) ⇒ Hash

Creates a group hash (for mappping the user into the group Hash)

Parameters:

  • group (Hash)

    The group details to use

  • users (Array)

    The Array of users to use

Returns:

  • (Hash)


20
21
22
23
# File 'lib/zendesk_support_api/groups.rb', line 20

def self.group_object(group, users)
  group['user'] = users.select { |u| u['id'] == group['user_id'] }
  group
end

.list(client) ⇒ Array

Lists groups (first 100)

Examples:

ZendeskSupportAPI::Groups.list(client)
#=> [
#=>   {
#=>     "name":       "DJs",
#=>     "created_at": "2009-05-13T00:07:08Z",
#=>     "updated_at": "2011-07-22T00:11:12Z",
#=>     "id":         211
#=>   },
#=>   {
#=>     "name":       "MCs",
#=>     "created_at": "2009-08-26T00:07:08Z",
#=>     "updated_at": "2010-05-13T00:07:08Z",
#=>     "id":         122
#=>   }
#=> ]

Parameters:

Returns:

  • (Array)


61
62
63
# File 'lib/zendesk_support_api/groups.rb', line 61

def self.list(client)
  client.request(:get, 'groups.json')['groups']
end

.next_page(res) ⇒ nil|String

Returns the string of the next_page for pagination

Examples:

ZendeskSupportAPI::Users.next_page(response) #=> nil
ZendeskSupportAPI::Users.next_page(response)
#=> "memberships.json?include=users&page=3

Parameters:

  • res (Hash)

    The Hash containing the response from a request

Returns:

  • (nil|String)


35
36
37
# File 'lib/zendesk_support_api/groups.rb', line 35

def self.next_page(res)
  (res['next_page'].nil? ? nil : res['next_page'].split('/').last)
end

.show(client, gid) ⇒ Hash

Shows info about a specific group

Examples:

ZendeskSupportAPI::Groups.show(client, 122)
#=> {
#=>   "name":       "MCs",
#=>   "created_at": "2009-08-26T00:07:08Z",
#=>   "updated_at": "2010-05-13T00:07:08Z",
#=>   "id":         122
#=> }

Parameters:

Returns:

  • (Hash)


106
107
108
# File 'lib/zendesk_support_api/groups.rb', line 106

def self.show(client, gid)
  client.request(:get, "groups/#{gid}.json")['group']
end

.update(client, gid, group) ⇒ String|Hash

Updates a group

Examples:

group = {
  name: 'Test Group - defunct'
}
ZendeskSupportAPI::Groups.update(client, 123, group)
#=> {
#=>   "name": "Test Group - defunct",
#=>   "created_at": "2011-04-20T17:49:00Z",
#=>    "updated_at": "2011-07-20T17:49:00Z",
#=>    "id":         123
#=> }

Parameters:

  • client (ZendeskSupportAPI::Client)

    The client instance to use

  • gid (Integer)

    The group ID to use

  • group (Hash)

    The group details to use

Returns:

  • (String|Hash)


154
155
156
157
158
159
# File 'lib/zendesk_support_api/groups.rb', line 154

def self.update(client, gid, group)
  res = client.request(:post, "groups/#{gid}.json", group: group)
  return "Update failed: #{res['details']}" if res['error']

  res
end

.user_map(groups, users) ⇒ String

Function to return a string that side-loads users

Returns:

  • (String)


10
11
12
# File 'lib/zendesk_support_api/groups.rb', line 10

def self.user_map(groups, users)
  groups.map { |g| group_object(g, users) }
end