Class: Readiness::Zendesk::OAuthClients

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

Overview

Author:

  • Jason Colyer

Since:

  • 1.0.125

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 = {}) ⇒ OAuthClients

Creates a new Readiness::Zendesk::OAuthClients instance

Examples:

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

Parameters:

Author:

  • Jason Colyer

Since:

  • 1.0.125



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/support_readiness/zendesk/oauth_clients.rb', line 28

def initialize(object = {})
  @company = object['company']
  @created_at = object['created_at']
  @description = object['description']
  @id = object['id']
  @identifier = object['identifier']
  @name = object['name']
  @redirect_uri = object['redirect_uri']
  @secret = object['secret']
  @unique_id = object['unique_id']
  @updated_at = object['updated_at']
  @user_id = object['user_id']
end

Instance Attribute Details

#companyObject

Since:

  • 1.0.125



17
18
19
# File 'lib/support_readiness/zendesk/oauth_clients.rb', line 17

def company
  @company
end

#created_atObject

Since:

  • 1.0.125



17
18
19
# File 'lib/support_readiness/zendesk/oauth_clients.rb', line 17

def created_at
  @created_at
end

#descriptionObject

Since:

  • 1.0.125



17
18
19
# File 'lib/support_readiness/zendesk/oauth_clients.rb', line 17

def description
  @description
end

#idObject

Since:

  • 1.0.125



17
18
19
# File 'lib/support_readiness/zendesk/oauth_clients.rb', line 17

def id
  @id
end

#identifierObject

Since:

  • 1.0.125



17
18
19
# File 'lib/support_readiness/zendesk/oauth_clients.rb', line 17

def identifier
  @identifier
end

#nameObject

Since:

  • 1.0.125



17
18
19
# File 'lib/support_readiness/zendesk/oauth_clients.rb', line 17

def name
  @name
end

#redirect_uriObject

Since:

  • 1.0.125



17
18
19
# File 'lib/support_readiness/zendesk/oauth_clients.rb', line 17

def redirect_uri
  @redirect_uri
end

#secretObject

Since:

  • 1.0.125



17
18
19
# File 'lib/support_readiness/zendesk/oauth_clients.rb', line 17

def secret
  @secret
end

#unique_idObject

Since:

  • 1.0.125



17
18
19
# File 'lib/support_readiness/zendesk/oauth_clients.rb', line 17

def unique_id
  @unique_id
end

#updated_atObject

Since:

  • 1.0.125



17
18
19
# File 'lib/support_readiness/zendesk/oauth_clients.rb', line 17

def updated_at
  @updated_at
end

#user_idObject

Since:

  • 1.0.125



17
18
19
# File 'lib/support_readiness/zendesk/oauth_clients.rb', line 17

def user_id
  @user_id
end

Class Method Details

.find(client, cid) ⇒ Object

Locates an OAuth client 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)
oauth_client = Readiness::Zendesk::OAuthClients.find(client, 223443)
pp oauth_client.name
# => "Test Client"

Parameters:

  • client (Object)

    An instance of Client

  • cid (Integer[ The OAuth client ID to find)

    id [Integer[ The OAuth client ID to find

  • return (Hash)

See Also:

Author:

  • Jason Colyer

Since:

  • 1.0.125



94
95
96
97
98
99
100
# File 'lib/support_readiness/zendesk/oauth_clients.rb', line 94

def self.find(client, cid)
  response = client.connection.get("oauth/clients/#{cid}")
  handle_request_error(0, 'Zendesk', response.status,  { action: 'get', id: cid }) unless response.status == 200
  return OAuthClients.new(Oj.load(response.body)['client']) if response.status == 200

  Oj.load(response.body)
end

.find!(client, cid) ⇒ Object

Locates an OAuth client 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)
oauth_client = Readiness::Zendesk::OAuthClients.find!(client, 223443)
pp oauth_client.name
# => "Test Client"

Parameters:

  • client (Object)

    An instance of Client

  • cid (Integer[ The OAuth client ID to find)

    id [Integer[ The OAuth client ID to find

  • return (Hash)

See Also:

Author:

  • Jason Colyer

Since:

  • 1.0.125



121
122
123
124
125
# File 'lib/support_readiness/zendesk/oauth_clients.rb', line 121

def self.find!(client, cid)
  response = client.connection.get("oauth/clients/#{cid}")
  handle_request_error(1, 'Zendesk', response.status, { action: 'Find OAuth client', id: cid }) unless response.status == 200
  OAuthClients.new(Oj.load(response.body)['client'])
end

.find_by_name(client, name, cache = nil) ⇒ Object

Locates an OAuth client within Zendesk by name. Can utilize a cache for quicker results

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)
oauth_client = Readiness::Zendesk::OAuthClients.find_by_name(client, 'Test Client')
pp oauth_client.id
# => 223443

Parameters:

  • client (Object)

    An instance of Client

  • name (String)

    The OAuth client name to look for

  • cache (Array) (defaults to: nil)

    The results of #list

Returns:

Author:

  • Jason Colyer

Since:

  • 1.0.125



146
147
148
149
150
151
152
153
# File 'lib/support_readiness/zendesk/oauth_clients.rb', line 146

def self.find_by_name(client, name, cache = nil)
  oauth_clients = if cache.nil?
                    OAuthClients.list(client)
                  else
                    cache
                  end
  oauth_clients.detect { |o| o.name == name }
end

.list(client) ⇒ Array

Lists all OAuth clients.

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)
oauth_clients = Readiness::Zendesk::OAuthClients.list(client)
pp oauth_clients.count
# => 12

Parameters:

  • client (Object)

    An instance of Client

Returns:

  • (Array)

See Also:

Author:

  • Jason Colyer

Since:

  • 1.0.125



60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/support_readiness/zendesk/oauth_clients.rb', line 60

def self.list(client)
  array = []
  opts = 'page[size]=100'
  loop do
    response = client.connection.get("oauth/clients?#{opts}")
    handle_request_error(0, 'Zendesk', response.status) unless response.status == 200
    body = Oj.load(response.body)
    array += body['clients'].map { |c| OAuthClients.new(c) }
    break unless body['meta']['has_more']

    opts = body['links']['next'].split('?').last
  end
  array
end