Class: ZendeskSupportAPI::Organizations

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

Overview

Class Method Summary collapse

Class Method Details

.bulk_delete(client, ids) ⇒ ZendeskSupportAPI::Client.handle_job

Deletes many organizations

Parameters:

Returns:



206
207
208
209
210
# File 'lib/zendesk_support_api/organizations.rb', line 206

def self.bulk_delete(client, ids)
  url = "#{orgs}/destroy_many.json?ids=#{ids.join(',')}"
  res = client.request(:delete, url)
  client.handle_job(res)
end

.create(client, org) ⇒ Hash|String

Creates an organization

Examples:

org = {
  name: 'Test Organization',
}
ZendeskSupportAPI::Organizations.create(client, org)
#=> {
#=>   "url": "",
#=>   "id": 123,
#=>   "name": "Test Organization",
#=>   ...
#=> }

Parameters:

Returns:

  • (Hash|String)


106
107
108
109
110
111
# File 'lib/zendesk_support_api/organizations.rb', line 106

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

  res['organization']
end

.create_many(client, orgs) ⇒ ZendeskSupportAPI::Client.handle_job

Creates many organizations

Parameters:

Returns:



119
120
121
122
123
# File 'lib/zendesk_support_api/organizations.rb', line 119

def self.create_many(client, orgs)
  url = "#{orgs}/create_many.json"
  res = client.request(:post, url, organizations: orgs)
  client.handle_job(res)
end

.create_or_update(client, org) ⇒ Hash|String

Creates or updates an organization

Examples:

org = {
  name: 'Test Organization',
}
ZendeskSupportAPI::Organizations.create_or_update(client, org)
#=> {
#=>   "url": "",
#=>   "id": 123,
#=>   "name": "Test Organization",
#=>   ...
#=> }

Parameters:

Returns:

  • (Hash|String)


143
144
145
146
147
148
149
# File 'lib/zendesk_support_api/organizations.rb', line 143

def self.create_or_update(client, org)
  url = "#{orgs}/create_or_update.json"
  res = client.request(:post, url, organization: org)
  return "Create/Update failed: #{res['description']}" if res['error']

  res['organization']
end

.delete(client, oid) ⇒ String

Deletes an organization

Examples:

ZendeskSupportAPI::Organizations.delete(client, 123)
#=> Organization 123 has been deleted
ZendeskSupportAPI::Organizations.delete(client, 123)
#=> "Deletion of 123 failed: RecordNotFound"

Parameters:

Returns:

  • (String)


193
194
195
196
197
198
# File 'lib/zendesk_support_api/organizations.rb', line 193

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

  "Organization #{uid} has been deleted"
end

.list(client) ⇒ Array

Lists Organizations (first 100)

Examples:

ZendeskSupportAPI::Organizations.list(client)
#=> [
#=>   {
#=>     "url": "https://zendesk.com/api/v2/organizations/1.json",
#=>     "id": 1,
#=>     "name": "One Organization",
#=>     ...
#=>   },
#=>   ...
#=>   {
#=>     "url": "https://zendesk.com/api/v2/organizations/100.json",
#=>     "id: 100,
#=>     "name": "Other Organization",
#=>     ...
#=>   }
#=> ]

Parameters:

Returns:

  • (Array)


37
38
39
# File 'lib/zendesk_support_api/organizations.rb', line 37

def self.list(client)
  client.request(:get, "#{orgs}.json")[orgs]
end

.members(client, oid) ⇒ Array

Get an Organization’s members

Examples:

ZendeskSupportAPI::Organizations.members(client, 123)
#=> [
#=>   {
#=>     "id": 1,
#=>     "name": "Albert",
#=>     "email": "[email protected]",
#=>     ...
#=>   },
#=>   ...
#=>   {
#=>     "id": 22,
#=>     "name": "Victor",
#=>     "email": "[email protected]",
#=>     ...
#=>   }
#=> ]

Parameters:

Returns:

  • (Array)


263
264
265
266
# File 'lib/zendesk_support_api/organizations.rb', line 263

def self.members(client, oid)
  url = "#{orgs}/#{oid}/organization_memberships.json?include=users"
  client.request(:get, url)['users']
end

.orgsString

Prints out organizations

Returns:

  • (String)


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

def self.orgs
  'organizations'
end

.search_by_external_id(client, eid) ⇒ Array

Searches for orgs by their external_id (first 100)

Examples:

ZendeskSupportAPI::Organizations.search_by_external_id(client, 'abc123')
#=> [
#=>   {
#=>     "url": "https://zendesk.com/api/v2/organizations/1.json",
#=>     "id": 1,
#=>     "name": "One Organization",
#=>     ...
#=>   },
#=>   ...
#=>   {
#=>     "url": "https://zendesk.com/api/v2/organizations/100.json",
#=>     "id: 100,
#=>     "name": "Other Organization",
#=>     ...
#=>   }
#=> ]

Parameters:

Returns:

  • (Array)


236
237
238
# File 'lib/zendesk_support_api/organizations.rb', line 236

def self.search_by_external_id(client, eid)
  client.request(:get, "#{orgs}/search.json?external_id=#{eid}")[orgs]
end

.show(client, oid) ⇒ Hash

Shows info about an organization

Examples:

ZendeskSupportAPI::Organizations.show(client, 123)
#=> {
#=>   "url": "https://zendesk.com/api/v2/organizations/1.json",
#=>   "id": 1,
#=>   "name": "One Organization",
#=>   ...
#=> }

Parameters:

Returns:

  • (Hash)


56
57
58
# File 'lib/zendesk_support_api/organizations.rb', line 56

def self.show(client, oid)
  client.request(:get, "#{orgs}/#{oid}.json")['organization']
end

.show_many(client, oids) ⇒ Array

Show several organizations

Examples:

ZendeskSupportAPI::Organizations.show(client, [1,2])
#=> [
#=>   {
#=>     "url": "https://zendesk.com/api/v2/organizations/1.json",
#=>     "id": 1,
#=>     "name": "One Organization",
#=>     ...
#=>   },
#=>   {
#=>     "url": "https://zendesk.com/api/v2/organizations/2.json",
#=>     "id": 2,
#=>     "name": "Two Organization",
#=>     ...
#=>   }
#=> ]

Parameters:

Returns:

  • (Array)


83
84
85
86
# File 'lib/zendesk_support_api/organizations.rb', line 83

def self.show_many(client, oids)
  ids = "ids=#{oids.join(',')}"
  client.request(:get, "#{orgs}/show_many.json?#{ids}")[orgs]
end

.update(client, oid, org) ⇒ Hash|String

Updates an organization

Examples:

ZendeskSupportAPI::Organizations.update(client, 123, org)
#=> {organization}

Parameters:

  • client (ZendeskSupportAPI::Client)

    The client instance to use

  • oid (Integer)

    The Organization ID to use

  • org (Hash)

    The organization info to use

Returns:

  • (Hash|String)


162
163
164
165
166
167
# File 'lib/zendesk_support_api/organizations.rb', line 162

def self.update(client, oid, org)
  res = client.request(:post, "#{orgs}/#{oid}.json", organization: org)
  return "Update of #{uid} failed: #{res['error']}" if res['error']

  res['organization']
end

.update_many(client, orgs) ⇒ ZendeskSupportAPI::Client.handle_job

Updates many organizations

Parameters:

Returns:



175
176
177
178
179
# File 'lib/zendesk_support_api/organizations.rb', line 175

def self.update_many(client, orgs)
  url = "#{orgs}/update_many.json"
  res = client.request(:put, url, organizations: orgs)
  client.handle_job(res)
end