Class: Readiness::Zendesk::OrganizationMemberships

Inherits:
Client
  • Object
show all
Defined in:
lib/support_readiness/zendesk/organization_memberships.rb

Overview

Defines the class OrganizationMemberships within the module Readiness::Zendesk.

Author:

  • Jason Colyer

Since:

  • 1.0.0

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

Examples:

require 'support_readiness'
Readiness::Zendesk::OrganizationMemberships.new

Parameters:

Author:

  • Jason Colyer

Since:

  • 1.0.0



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

#defaultObject

Since:

  • 1.0.0



13
14
15
# File 'lib/support_readiness/zendesk/organization_memberships.rb', line 13

def default
  @default
end

#idObject

Since:

  • 1.0.0



13
14
15
# File 'lib/support_readiness/zendesk/organization_memberships.rb', line 13

def id
  @id
end

#organization_idObject

Since:

  • 1.0.0



13
14
15
# File 'lib/support_readiness/zendesk/organization_memberships.rb', line 13

def organization_id
  @organization_id
end

#organization_nameObject

Since:

  • 1.0.0



13
14
15
# File 'lib/support_readiness/zendesk/organization_memberships.rb', line 13

def organization_name
  @organization_name
end

#user_idObject

Since:

  • 1.0.0



13
14
15
# File 'lib/support_readiness/zendesk/organization_memberships.rb', line 13

def user_id
  @user_id
end

#view_ticketsObject

Since:

  • 1.0.0



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

Examples:

require 'support_readiness'
config = Readiness::Zendesk::Configuration.new
config.username = 'alice@example.com'
config.token = 'test123abc'
config.url = 'https://example.zendesk.com/api/v2'
client = Readiness::Zendesk::Client.new(config)
membership = Readiness::Zendesk::OrganizationMemberships.new
membership.user_id = 72
membership.organization_id = 88
create = Readiness::Zendesk::OrganizationMemberships.create!(client, membership)
pp create.id
# => 461

Parameters:

Returns:

See Also:

Author:

  • Jason Colyer

Since:

  • 1.0.0



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

Examples:

require 'support_readiness'
config = Readiness::Zendesk::Configuration.new
config.username = 'alice@example.com'
config.token = 'test123abc'
config.url = 'https://example.zendesk.com/api/v2'
client = Readiness::Zendesk::Client.new(config)
membership1 = Readiness::Zendesk::OrganizationMemberships.new
membership1.user_id = 72
membership1.organization_id = 88
membership2 = Readiness::Zendesk::OrganizationMemberships.new
membership2.user_id = 27
membership2.organization_id = 88
creates = Readiness::Zendesk::OrganizationMemberships.create_many!(client, membership)
pp creates.id
# => "8b726e606741012ffc2d782bcb7848fe"

Parameters:

Returns:

See Also:

Author:

  • Jason Colyer

Since:

  • 1.0.0



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

Examples:

require 'support_readiness'
config = Readiness::Zendesk::Configuration.new
config.username = 'alice@example.com'
config.token = 'test123abc'
config.url = 'https://example.zendesk.com/api/v2'
client = Readiness::Zendesk::Client.new(config)
membership = Readiness::Zendesk::OrganizationMemberships.find!(client, 461)
delete = Readiness::Zendesk::OrganizationMemberships.delete!(client, membership)
pp delete
# => true

Parameters:

Returns:

  • (Boolean)

See Also:

Author:

  • Jason Colyer

Since:

  • 1.0.0



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

Examples:

require 'support_readiness'
config = Readiness::Zendesk::Configuration.new
config.username = 'alice@example.com'
config.token = 'test123abc'
config.url = 'https://example.zendesk.com/api/v2'
client = Readiness::Zendesk::Client.new(config)
deletes = Readiness::Zendesk::OrganizationMemberships.delete_many!(client, [461, 462])
pp deletes.id
# => "82de0b044094f0c67893ac9fe64f1a99"

Parameters:

  • client (Object)

    An instance of Client

  • mids (Array)

    An array of organization memberships IDs

Returns:

See Also:

Author:

  • Jason Colyer

Since:

  • 1.0.0



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)

Examples:

require 'support_readiness'
config = Readiness::Zendesk::Configuration.new
config.username = 'alice@example.com'
config.token = 'test123abc'
config.url = 'https://example.zendesk.com/api/v2'
client = Readiness::Zendesk::Client.new(config)
membership = Readiness::Zendesk::OrganizationMemberships.find(client, 4)
pp membership.user_id
# => 29

Parameters:

  • client (Object)

    An instance of Client

  • oid (Integer)

    The organization membership ID to find

Returns:

  • (Hash)

See Also:

Author:

  • Jason Colyer

Since:

  • 1.0.0



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

Examples:

require 'support_readiness'
config = Readiness::Zendesk::Configuration.new
config.username = 'alice@example.com'
config.token = 'test123abc'
config.url = 'https://example.zendesk.com/api/v2'
client = Readiness::Zendesk::Client.new(config)
membership = Readiness::Zendesk::OrganizationMemberships.find!(client, 4)
pp membership.user_id
# => 29

Parameters:

  • client (Object)

    An instance of Client

  • oid (Integer)

    The organization membership ID to find

Returns:

  • (Hash)

See Also:

Author:

  • Jason Colyer

Since:

  • 1.0.0



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

Examples:

require 'support_readiness'
config = Readiness::Zendesk::Configuration.new
config.username = 'alice@example.com'
config.token = 'test123abc'
config.url = 'https://example.zendesk.com/api/v2'
client = Readiness::Zendesk::Client.new(config)
memberships = Readiness::Zendesk::OrganizationMemberships.list(client)
pp memberships.first.id
# => 4

Parameters:

  • client (Object)

    An instance of Client

Returns:

  • (Array)

See Also:

Author:

  • Jason Colyer

Since:

  • 1.0.0



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.

Examples:

require 'support_readiness'
config = Readiness::Zendesk::Configuration.new
config.username = 'alice@example.com'
config.token = 'test123abc'
config.url = 'https://example.zendesk.com/api/v2'
client = Readiness::Zendesk::Client.new(config)
memberships = Readiness::Zendesk::OrganizationMemberships.list_many(client, 2)
pp memberships.count
# => 200

Parameters:

  • client (Object)

    An instance of Client

  • limit (Integer) (defaults to: 0)

    The number of pages to stop at. Using 0 means to list all.

Returns:

  • (Array)

See Also:

Author:

  • Jason Colyer

Since:

  • 1.0.0



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