This repository has been archived by the owner on Dec 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wp-zendesk-chat-api.php
96 lines (78 loc) · 1.99 KB
/
wp-zendesk-chat-api.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
/**
* WP ZenDesk Chat API (https://developer.zendesk.com/rest_api/docs/chat/introduction)
*
* @package WP-ZD-Chat-API
*/
/* Exit if accessed directly */
if ( ! defined( 'ABSPATH' ) ) {
exit; }
if ( ! class_exists( 'WPZendeskChatAPI' ) ) {
/**
* Seny API Class.
*/
class WPZendeskChatAPI extends ZendeskAPIBase {
private $username;
/**
* Install Name.
*
* @var string
*/
protected $base_uri;
/**
* API Key.
*
* @var string
*/
private $api_key;
protected $args;
protected $is_debug;
/**
* __construct function.
*
* @access public
* @param mixed $install_name Install Name.
* @param mixed $api_key API Key.
* @return void
*/
public function __construct( $domain, $username, $api_key, $debug = false ) {
$this->base_uri = "https://$domain.zendesk.com/api/v2/chats";
$this->username = $username;
$this->api_key = $api_key;
$this->is_debug = $debug;
}
protected function set_headers() {
$this->args['headers'] = array(
'Content-Type' => 'application/json',
'Authorization' => 'Basic ' . base64_encode( $this->username . '/token:' . $this->api_key ),
);
}
protected function run( $route, $args = array(), $method = 'GET', $add_data_type = true ) {
return $this->build_request( $route . ($add_data_type ? '.json' : ''), $args, $method )->fetch();
}
protected function clear() {
$this->args = array();
}
/**
* Function for building zendesk pagination.
*
* @param integer $per_page [description]
* @param integer $page [description]
* @param string $sort_by [description]
* @param string $sort_order [description]
* @return [type] [description]
*/
public function build_zendesk_pagination( $limit = 200, $since_id = -1, $max_id = -1 ) {
$args = array(
'limit' => $limit,
);
if ( -1 !== $since_id ) {
$args['since_id'] = $since_id;
}
if ( -1 !== $max_id ) {
$args['max_id'] = $max_id;
}
return $args;
}
}
}