Class: Readiness::Zendesk::Organizations
- Defined in:
- lib/support_readiness/zendesk/organizations.rb
Overview
Merge org
Show merge
List merges
Defines the class Organizations within the module Readiness::Zendesk.
Instance Attribute Summary collapse
- #details ⇒ Object
- #domain_names ⇒ Object
- #external_id ⇒ Object
- #group_id ⇒ Object
- #id ⇒ Object
- #name ⇒ Object
- #notes ⇒ Object
- #organization_fields ⇒ Object
- #shared_comments ⇒ Object
- #shared_tickets ⇒ Object
- #tags ⇒ Object
Class Method Summary collapse
-
.count(client) ⇒ Hash
Show information on the approximate count of organizations.
-
.create!(client, organization) ⇒ Object
Creates an organization.
-
.create_many!(client, organizations) ⇒ object
Creates multiple organizations via a batch job.
-
.create_or_update!(client, organization) ⇒ Object
Creates or updates an organization.
-
.delete!(client, organization) ⇒ Boolean
Deletes an organization.
-
.delete_many!(client, oids) ⇒ object
Deletes multiple organizations via a batch job.
-
.find(client, oid) ⇒ Hash
Locates an organization within Zendesk.
-
.find!(client, oid) ⇒ Object
Locates an organization within Zendesk.
-
.find_many(client, oids) ⇒ Array
Locates up to 100 organizations within Zendesk.
-
.list(client) ⇒ Array
Lists the first 100 organizations.
-
.list_many(client, limit = 0, sort = 'id') ⇒ Array
Lists many organizations.
-
.memberships(client, organization) ⇒ Array
Lists members of an organization.
-
.tickets(client, organization) ⇒ Array
Lists tickets for an organization.
-
.update!(client, organization) ⇒ Object
Updates an organization.
-
.update_many!(client, organizations) ⇒ object
Updates multiple organizations via a batch job.
-
.users(client, organization) ⇒ Array
Lists users for an organization.
Instance Method Summary collapse
-
#initialize(object = {}) ⇒ Organizations
constructor
Creates a new Organizations instance.
Methods inherited from Client
auth_error, bad_request_error, convert_actions, convert_conditions, convert_standard_names_to_ids, convert_ticket_form_agent_conditions, convert_ticket_form_brands, convert_ticket_form_end_user_conditions, convert_ticket_form_names_to_ids, convert_view_names_to_ids, convert_view_restrictions, covert_ticket_form_field_ids, create_package!, erb_renderer, handle_request_error, not_found_error, not_processible_error, put_into_archive, recursively_deflate_directory, timestamp_filename, to_clean_json, to_clean_json_with_key, to_hash, to_nearly_clean_json, to_nearly_clean_json_with_key, to_param_string, write_entries
Constructor Details
#initialize(object = {}) ⇒ Organizations
Creates a new Readiness::Zendesk::Organizations instance
27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/support_readiness/zendesk/organizations.rb', line 27 def initialize(object = {}) @details = object['details'] @domain_names = object['domain_names'] @external_id = object['external_id'] @group_id = object['group_id'] @id = object['id'] @name = object['name'] @notes = object['notes'] @organization_fields = object['organization_fields'] @shared_comments = object['shared_comments'] @shared_tickets = object['shared_tickets'] @tags = object['tags'] end |
Instance Attribute Details
#details ⇒ Object
16 17 18 |
# File 'lib/support_readiness/zendesk/organizations.rb', line 16 def details @details end |
#domain_names ⇒ Object
16 17 18 |
# File 'lib/support_readiness/zendesk/organizations.rb', line 16 def domain_names @domain_names end |
#external_id ⇒ Object
16 17 18 |
# File 'lib/support_readiness/zendesk/organizations.rb', line 16 def external_id @external_id end |
#group_id ⇒ Object
16 17 18 |
# File 'lib/support_readiness/zendesk/organizations.rb', line 16 def group_id @group_id end |
#id ⇒ Object
16 17 18 |
# File 'lib/support_readiness/zendesk/organizations.rb', line 16 def id @id end |
#name ⇒ Object
16 17 18 |
# File 'lib/support_readiness/zendesk/organizations.rb', line 16 def name @name end |
#notes ⇒ Object
16 17 18 |
# File 'lib/support_readiness/zendesk/organizations.rb', line 16 def notes @notes end |
#organization_fields ⇒ Object
16 17 18 |
# File 'lib/support_readiness/zendesk/organizations.rb', line 16 def organization_fields @organization_fields end |
#shared_comments ⇒ Object
16 17 18 |
# File 'lib/support_readiness/zendesk/organizations.rb', line 16 def shared_comments @shared_comments end |
#shared_tickets ⇒ Object
16 17 18 |
# File 'lib/support_readiness/zendesk/organizations.rb', line 16 def shared_tickets @shared_tickets end |
#tags ⇒ Object
16 17 18 |
# File 'lib/support_readiness/zendesk/organizations.rb', line 16 def @tags end |
Class Method Details
.count(client) ⇒ Hash
Show information on the approximate count of organizations.
119 120 121 122 123 |
# File 'lib/support_readiness/zendesk/organizations.rb', line 119 def self.count(client) response = client.connection.get('organizations/count') handle_request_error(0, 'Zendesk', response.status) unless response.status == 200 Oj.load(response.body)['count'] end |
.create!(client, organization) ⇒ Object
Creates an organization. Will exit if unsuccessful
223 224 225 226 227 |
# File 'lib/support_readiness/zendesk/organizations.rb', line 223 def self.create!(client, organization) response = client.connection.post 'organizations', to_clean_json_with_key(organization, 'organization') handle_request_error(1, 'Zendesk', response.status, { action: 'Create organization', message: Oj.load(response.body)}) unless response.status == 201 Organizations.new(Oj.load(response.body)['organization']) end |
.create_many!(client, organizations) ⇒ object
Creates multiple organizations via a batch job
415 416 417 418 419 420 |
# File 'lib/support_readiness/zendesk/organizations.rb', line 415 def self.create_many!(client, organizations) data = { organizations: organizations.map { |o| to_hash(o).compact } }.to_json response = client.connection.post('organizations/create_many', data) handle_request_error(1, 'Zendesk', response.status, { action: 'Create many organizations', message: Oj.load(response.body)}) unless response.status == 200 JobStatuses.new(Oj.load(response.body)['job_status']) end |
.create_or_update!(client, organization) ⇒ Object
Creates or updates an organization. Will exit if unsuccessful
262 263 264 265 266 |
# File 'lib/support_readiness/zendesk/organizations.rb', line 262 def self.create_or_update!(client, organization) response = client.connection.post 'organizations/create_or_update', to_clean_json_with_key(organization, 'organization') handle_request_error(1, 'Zendesk', response.status, { action: 'Create or update organization', id: organization.name, message: Oj.load(response.body)}) unless [200, 201].include?(response.status) Organizations.new(Oj.load(response.body)['organization']) end |
.delete!(client, organization) ⇒ Boolean
Deletes an organization. Will exit if unsuccessful
315 316 317 318 319 |
# File 'lib/support_readiness/zendesk/organizations.rb', line 315 def self.delete!(client, organization) response = client.connection.delete "organizations/#{organization.id}" handle_request_error(1, 'Zendesk', response.status, { action: 'Delete an organization', id: organization.id, message: Oj.load(response.body)}) unless response.status == 204 true end |
.delete_many!(client, oids) ⇒ object
Deletes multiple organizations via a batch job
472 473 474 475 476 |
# File 'lib/support_readiness/zendesk/organizations.rb', line 472 def self.delete_many!(client, oids) response = client.connection.delete "organizations/destroy_many?ids=#{oids.join(',')}" handle_request_error(1, 'Zendesk', response.status, { action: 'Delete many organizations', message: Oj.load(response.body)}) unless response.status == 200 JobStatuses.new(Oj.load(response.body)['job_status']) end |
.find(client, oid) ⇒ Hash
Locates an organization within Zendesk. This will not exit on error (except Authentication errors)
144 145 146 147 148 149 150 |
# File 'lib/support_readiness/zendesk/organizations.rb', line 144 def self.find(client, oid) response = client.connection.get("organizations/#{oid}") handle_request_error(0, 'Zendesk', response.status, { action: 'get', id: oid }) unless response.status == 200 return Organizations.new(Oj.load(response.body)['organization']) if response.status == 200 Oj.load(response.body) end |
.find!(client, oid) ⇒ Object
Locates an organization within Zendesk. This will exit on error
171 172 173 174 175 |
# File 'lib/support_readiness/zendesk/organizations.rb', line 171 def self.find!(client, oid) response = client.connection.get("organizations/#{oid}") handle_request_error(1, 'Zendesk', response.status, { action: 'Find organization', id: oid }) unless response.status == 200 Organizations.new(Oj.load(response.body)['organization']) end |
.find_many(client, oids) ⇒ Array
Locates up to 100 organizations within Zendesk.
196 197 198 199 200 |
# File 'lib/support_readiness/zendesk/organizations.rb', line 196 def self.find_many(client, oids) response = client.connection.get("organizations/show_many?ids=#{oids.join(',')}") handle_request_error(0, 'Zendesk', response.status, { action: 'get', id: oids }) unless response.status == 200 Oj.load(response.body)['organizations'].map { |o| Organizations.new(o) } end |
.list(client) ⇒ Array
Lists the first 100 organizations
59 60 61 62 63 |
# File 'lib/support_readiness/zendesk/organizations.rb', line 59 def self.list(client) response = client.connection.get("organizations?page[size]=100") handle_request_error(0, 'Zendesk', response.status) unless response.status == 200 Oj.load(response.body)['organizations'].map { |o| Organizations.new(o) } end |
.list_many(client, limit = 0, sort = 'id') ⇒ Array
Lists many organizations. Does not stop until it ends or the page limit is hit. This method can take a long time to run depending on the parameters used.
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/support_readiness/zendesk/organizations.rb', line 85 def self.list_many(client, limit = 0, sort = 'id') array = [] opts = "page[size]=100" loop do response = client.connection.get("organizations?#{opts}") handle_request_error(0, 'Zendesk', response.status) unless response.status == 200 body = Oj.load(response.body) array += body['organizations'].map { |o| Organizations.new(o) } break if limit != 0 && array.count >= (limit * 100) break unless body['meta']['has_more'] opts = body['links'] ['next'].split('?').last end array end |
.memberships(client, organization) ⇒ Array
Lists members of an organization
498 499 500 501 502 503 504 505 506 507 508 509 510 511 |
# File 'lib/support_readiness/zendesk/organizations.rb', line 498 def self.memberships(client, organization) array = [] opts = "page[size]=100" loop do response = client.connection.get("organizations/#{organization.id}/organization_memberships?#{opts}") handle_request_error(0, 'Zendesk', response.status) unless response.status == 200 body = Oj.load(response.body) array += body['organization_memberships'].map { |o| OrganizationMemberships.new(o) } break unless body['meta']['has_more'] opts = body['links'] ['next'].split('?').last end array end |
.tickets(client, organization) ⇒ Array
Lists tickets for an organization.
341 342 343 344 345 346 347 348 349 350 351 352 353 354 |
# File 'lib/support_readiness/zendesk/organizations.rb', line 341 def self.tickets(client, organization) array = [] opts = "page[size]=100" loop do response = client.connection.get("organizations/#{organization.id}/tickets?#{opts}") handle_request_error(0, 'Zendesk', response.status) unless response.status == 200 body = Oj.load(response.body) array += body['tickets'].map { |t| Tickets.new(t) } break unless body['meta']['has_more'] opts = body['links'] ['next'].split('?').last end array end |
.update!(client, organization) ⇒ Object
Updates an organization. Will exit if unsuccessful
289 290 291 292 293 |
# File 'lib/support_readiness/zendesk/organizations.rb', line 289 def self.update!(client, organization) response = client.connection.put "organizations/#{organization.id}", to_clean_json_with_key(organization, 'organization') handle_request_error(1, 'Zendesk', response.status, { action: 'Update organization', id: organization.id, message: Oj.load(response.body)}) unless response.status == 200 Organizations.new(Oj.load(response.body)['organization']) end |
.update_many!(client, organizations) ⇒ object
Updates multiple organizations via a batch job
446 447 448 449 450 451 |
# File 'lib/support_readiness/zendesk/organizations.rb', line 446 def self.update_many!(client, organizations) data = { organizations: organizations.map { |o| to_hash(o).compact } }.to_json response = client.connection.put('organizations/update_many', data) handle_request_error(1, 'Zendesk', response.status, { action: 'Update many organizations', message: Oj.load(response.body)}) unless response.status == 200 JobStatuses.new(Oj.load(response.body)['job_status']) end |
.users(client, organization) ⇒ Array
Lists users for an organization.
376 377 378 379 380 381 382 383 384 385 386 387 388 389 |
# File 'lib/support_readiness/zendesk/organizations.rb', line 376 def self.users(client, organization) array = [] opts = "page[size]=100" loop do response = client.connection.get("organizations/#{organization.id}/users?#{opts}") handle_request_error(0, 'Zendesk', response.status) unless response.status == 200 body = Oj.load(response.body) array += body['users'].map { |u| Users.new(u) } break unless body['meta']['has_more'] opts = body['links'] ['next'].split('?').last end array end |