Class: Readiness::Zendesk::OrganizationMemberships
- Defined in:
- lib/support_readiness/zendesk/organization_memberships.rb
Overview
Defines the class OrganizationMemberships within the module Readiness::Zendesk.
Instance Attribute Summary collapse
- #default ⇒ Object
- #id ⇒ Object
- #organization_id ⇒ Object
- #organization_name ⇒ Object
- #user_id ⇒ Object
- #view_tickets ⇒ Object
Class Method Summary collapse
-
.create!(client, membership) ⇒ Object
Creates an organization membership.
-
.create_many!(client, memberships) ⇒ object
Creates multiple organization memberships via a batch job.
-
.delete!(client, membership) ⇒ Boolean
Deletes an organization membership.
-
.delete_many!(client, mids) ⇒ object
Deletes multiple organization memberships via a batch job.
-
.find(client, oid) ⇒ Hash
Locates an organization membership within Zendesk.
-
.find!(client, oid) ⇒ Hash
Locates an organization membership within Zendesk.
-
.list(client) ⇒ Array
Lists the first 100 organization memberships.
-
.list_many(client, limit = 0) ⇒ Array
Lists many organization memberships.
Instance Method Summary collapse
-
#initialize(object = {}) ⇒ OrganizationMemberships
constructor
Creates a new OrganizationMemberships 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 = {}) ⇒ OrganizationMemberships
Creates a new Readiness::Zendesk::OrganizationMemberships instance
24 25 26 27 28 29 30 31 |
# File 'lib/support_readiness/zendesk/organization_memberships.rb', line 24 def initialize(object = {}) @id = object['id'] @default = object['default'] @organization_id = object['organization_id'] @organization_name = object['organization_name'] @user_id = object['user_id'] @view_tickets = object['view_tickets'] end |
Instance Attribute Details
#default ⇒ Object
13 14 15 |
# File 'lib/support_readiness/zendesk/organization_memberships.rb', line 13 def default @default end |
#id ⇒ Object
13 14 15 |
# File 'lib/support_readiness/zendesk/organization_memberships.rb', line 13 def id @id end |
#organization_id ⇒ Object
13 14 15 |
# File 'lib/support_readiness/zendesk/organization_memberships.rb', line 13 def organization_id @organization_id end |
#organization_name ⇒ Object
13 14 15 |
# File 'lib/support_readiness/zendesk/organization_memberships.rb', line 13 def organization_name @organization_name end |
#user_id ⇒ Object
13 14 15 |
# File 'lib/support_readiness/zendesk/organization_memberships.rb', line 13 def user_id @user_id end |
#view_tickets ⇒ Object
13 14 15 |
# File 'lib/support_readiness/zendesk/organization_memberships.rb', line 13 def view_tickets @view_tickets end |
Class Method Details
.create!(client, membership) ⇒ Object
Creates an organization membership. Will exit if unsuccessful
167 168 169 170 171 |
# File 'lib/support_readiness/zendesk/organization_memberships.rb', line 167 def self.create!(client, membership) response = client.connection.post 'organization_memberships', to_clean_json_with_key(membership, 'organization_membership') handle_request_error(1, 'Zendesk', response.status, { action: 'Create organization membership', message: Oj.load(response.body)}) unless response.status == 201 OrganizationMemberships.new(Oj.load(response.body)['organization_membership']) end |
.create_many!(client, memberships) ⇒ object
Creates multiple organization memberships via a batch job
198 199 200 201 202 203 |
# File 'lib/support_readiness/zendesk/organization_memberships.rb', line 198 def self.create_many!(client, memberships) data = { organization_memberships: memberships.map { |t| to_hash(t).compact } }.to_json response = client.connection.post('organization_memberships/create_many', data) handle_request_error(1, 'Zendesk', response.status, { action: 'Create many organization memberships', message: Oj.load(response.body)}) unless response.status == 200 JobStatuses.new(Oj.load(response.body)['job_status']) end |
.delete!(client, membership) ⇒ Boolean
Deletes an organization membership. Will exit if unsuccessful
225 226 227 228 229 |
# File 'lib/support_readiness/zendesk/organization_memberships.rb', line 225 def self.delete!(client, membership) response = client.connection.delete "organization_memberships/#{membership.id}" handle_request_error(1, 'Zendesk', response.status, { action: 'Delete organization membership', message: Oj.load(response.body)}) unless response.status == 204 true end |
.delete_many!(client, mids) ⇒ object
Deletes multiple organization memberships via a batch job
250 251 252 253 254 |
# File 'lib/support_readiness/zendesk/organization_memberships.rb', line 250 def self.delete_many!(client, mids) response = client.connection.delete("organization_memberships/destroy_many?ids=#{mids.join(',')}") handle_request_error(1, 'Zendesk', response.status, { action: 'Delete many organization memberships', 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 membership within Zendesk. This will not exit on error (except Authentication errors)
112 113 114 115 116 117 118 |
# File 'lib/support_readiness/zendesk/organization_memberships.rb', line 112 def self.find(client, oid) response = client.connection.get("organization_memberships/#{oid}") handle_request_error(0, 'Zendesk', response.status, { action: 'get', id: oid }) unless response.status == 200 return OrganizationMemberships.new(Oj.load(response.body)['organization_membership']) if response.status == 200 Oj.load(response.body) end |
.find!(client, oid) ⇒ Hash
Locates an organization membership within Zendesk. This will exit on error
139 140 141 142 143 |
# File 'lib/support_readiness/zendesk/organization_memberships.rb', line 139 def self.find!(client, oid) response = client.connection.get("organization_memberships/#{oid}") handle_request_error(1, 'Zendesk', response.status, { action: 'Find organization membership', id: oid }) unless response.status == 200 OrganizationMemberships.new(Oj.load(response.body)['organization_membership']) end |
.list(client) ⇒ Array
Lists the first 100 organization memberships
51 52 53 54 55 |
# File 'lib/support_readiness/zendesk/organization_memberships.rb', line 51 def self.list(client) response = client.connection.get("organization_memberships?page[size]=100") handle_request_error(0, 'Zendesk', response.status) unless response.status == 200 Oj.load(response.body)['organization_memberships'].map { |m| OrganizationMemberships.new(m) } end |
.list_many(client, limit = 0) ⇒ Array
Lists many organization memberships. 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.
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/support_readiness/zendesk/organization_memberships.rb', line 77 def self.list_many(client, limit = 0) array = [] opts = "page[size]=100" loop do response = client.connection.get("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 if limit != 0 && array.count >= (limit * 100) break unless body['meta']['has_more'] opts = body['links'] ['next'].split('?').last end array end |