Class: ZendeskSupportAPI::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/zendesk_support_api/client.rb

Overview

Instance Method Summary collapse

Constructor Details

#initialize(user, token, url) ⇒ Client

Create a new instance of Client

Examples:

ZendeskSupportAPI::Client.new('user', '123', 'zendesk.com/api')
#=> #<ZendeskSupportAPI::Client:0x00007f88779cb330 @user="user",
#=>    @token="123", @url="zendesk.com/api">

Parameters:

  • user (String)
    • The API username to use

  • token (String)
    • The API token to use

  • url (String)
    • The API URL to use



24
25
26
27
28
# File 'lib/zendesk_support_api/client.rb', line 24

def initialize(user, token, url)
  @user = user
  @token = token
  @url = url
end

Instance Method Details

#handle_job(job) ⇒ Hash

Handles responses that create jobs

Parameters:

  • job (Hash)
    • The output from a request that created a job

Returns:

  • (Hash)


69
70
71
72
73
74
75
76
77
# File 'lib/zendesk_support_api/client.rb', line 69

def handle_job(job)
  print 'Checking job'
  while job['job_status']['status'] != 'completed'
    print '.'
    job = ZendeskSupportAPI::Jobs.show(self, job['job_status']['id'])
  end
  puts 'completed'
  job['job_status']['results']
end

#request(http_method, endpoint, params = {}) ⇒ Hash

Make a request to the Zendesk Support API

Examples:

client = ZendeskSupportAPI::Client.new('user', '123', 'zendesk.com/api')
client.response(:get, 'users.json')
#=> {users:[{user1},{user2}...{user100}]}

Parameters:

  • http_method (Symbol)

    The HTTP method to utilize

  • endpoint (String)

    The endpoint to hit

  • params (Hash) (defaults to: {})

    Parameters for the request

Returns:

  • (Hash)


42
43
44
45
# File 'lib/zendesk_support_api/client.rb', line 42

def request(http_method, endpoint, params = {})
  response = client.public_send(http_method, endpoint, params)
  Oj.load(response.body)
end

#spinner(string, num) ⇒ String

Outputs a spinner symbol

Examples:

ZendeskSupportAPI::Client.spinner('users', 1) #=> Grabbing users...  ZendeskSupportAPI::Client.spinner('groups', 3) #=> /

Parameters:

  • string (String)

    The string to output at the beginning

  • num (Integer)

    The index of the iteration

Returns:

  • (String)


57
58
59
60
61
62
# File 'lib/zendesk_support_api/client.rb', line 57

def spinner(string, num)
  print "Grabbing #{string}... " if num.to_i == 1
  symbols = ['-', '\\', '|', '/']
  print symbols[num.to_i % 4]
  print "\b"
end