Class: Readiness::Zendesk::Webhooks

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

Overview

TODO:

Find methods

TODO:

Create method

TODO:

Update method

TODO:

Patch method

TODO:

Test method

TODO:

Delete method

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

Author:

  • Jason Colyer

Since:

  • 1.0.92

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

Creates a new Readiness::Zendesk::Webhooks instance

Examples:

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

Parameters:

Author:

  • Jason Colyer

Since:

  • 1.0.92



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

def initialize(object = {})
  @authenticiation = object['authenticiation']
  @custom_headers = object['custom_headers']
  @endpoint = object['endpoint']
  @http_method = object['http_method']
  @id = object['id']
  @name = object['name']
  @request_format = object['request_format']
  @status = object['status']
  @subscriptions = object['subscriptions']
end

Instance Attribute Details

#authenticiationObject

Since:

  • 1.0.92



19
20
21
# File 'lib/support_readiness/zendesk/webhooks.rb', line 19

def authenticiation
  @authenticiation
end

#custom_headersObject

Since:

  • 1.0.92



19
20
21
# File 'lib/support_readiness/zendesk/webhooks.rb', line 19

def custom_headers
  @custom_headers
end

#endpointObject

Since:

  • 1.0.92



19
20
21
# File 'lib/support_readiness/zendesk/webhooks.rb', line 19

def endpoint
  @endpoint
end

#http_methodObject

Since:

  • 1.0.92



19
20
21
# File 'lib/support_readiness/zendesk/webhooks.rb', line 19

def http_method
  @http_method
end

#idObject

Since:

  • 1.0.92



19
20
21
# File 'lib/support_readiness/zendesk/webhooks.rb', line 19

def id
  @id
end

#nameObject

Since:

  • 1.0.92



19
20
21
# File 'lib/support_readiness/zendesk/webhooks.rb', line 19

def name
  @name
end

#request_formatObject

Since:

  • 1.0.92



19
20
21
# File 'lib/support_readiness/zendesk/webhooks.rb', line 19

def request_format
  @request_format
end

#statusObject

Since:

  • 1.0.92



19
20
21
# File 'lib/support_readiness/zendesk/webhooks.rb', line 19

def status
  @status
end

#subscriptionsObject

Since:

  • 1.0.92



19
20
21
# File 'lib/support_readiness/zendesk/webhooks.rb', line 19

def subscriptions
  @subscriptions
end

Class Method Details

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

Locates a webhook within Zendesk by name. Can utilize a cacheh 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)
webhook = Readiness::Zendesk::Webhooks.find_by_name!(client, 'Post update to ticket')
pp webhook.id
# => "01FQKTKVAQJ2BYDZ47KT35SCP9"
list = Readiness::Zendesk::Webhhooks.list(client)
webhook = Readiness::Zendesk::Webhooks.find_by_name!(client, 'Post update to ticket', list)
pp webhook.id
# => "01FQKTKVAQJ2BYDZ47KT35SCP9"

Parameters:

  • client (Object)

    An instance of Client

  • name (String)

    The webhook name to look for

  • cache (Array) (defaults to: nil)

    The results of #list

Returns:

Author:

  • Jason Colyer

Since:

  • 1.0.92



98
99
100
101
102
103
104
105
# File 'lib/support_readiness/zendesk/webhooks.rb', line 98

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

.list(client) ⇒ Array

Lists webhooks

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)
categories = Readiness::Zendesk::Webhooks.list(client)
pp categories.first.id
# => 10001

Parameters:

  • client (Object)

    An instance of Client

Returns:

  • (Array)

See Also:

Author:

  • Jason Colyer

Since:

  • 1.0.92



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

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

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