1 | <?php |
||
9 | class Calendly { |
||
10 | const V1 = "v1"; |
||
11 | |||
12 | /** |
||
13 | * API Host |
||
14 | * @var string |
||
15 | */ |
||
16 | protected $host; |
||
17 | |||
18 | /** |
||
19 | * API Token |
||
20 | * @var string |
||
21 | */ |
||
22 | protected $token; |
||
23 | |||
24 | /** |
||
25 | * API Version to use |
||
26 | * @var string |
||
27 | */ |
||
28 | protected $version; |
||
29 | |||
30 | /** |
||
31 | * The HttpRequest instance that will handle the request |
||
32 | * @var HttpRequest |
||
33 | */ |
||
34 | protected $request; |
||
35 | |||
36 | /** |
||
37 | * Creates a Calendly instance that can register and unregister webhooks with the API |
||
38 | * @param string $token The API token to use |
||
39 | * @param string $version The API version to use |
||
40 | * @param string $host The Host URL |
||
41 | * @param string $request The HttpRequest instance that will handle the request |
||
42 | */ |
||
43 | 24 | public function __construct($token,$version = self::V1,$host = "calendly.com", HttpRequest $request = null){ |
|
49 | |||
50 | /** |
||
51 | * Will register a webhook url for the both invitee events |
||
52 | * @param string $url The webhook url you want to use |
||
53 | * @return array The response array |
||
54 | */ |
||
55 | public function registerAllInviteeEvents($url){ |
||
58 | |||
59 | /** |
||
60 | * Will register a webhook url for the invitee.created event |
||
61 | * @param string $url The webhook url you want to use |
||
62 | * @return array The response array |
||
63 | */ |
||
64 | 3 | public function registerInviteeCreated($url){ |
|
67 | |||
68 | /** |
||
69 | * Will register a webhook url for the invitee.canceled event |
||
70 | * @param string $url The webhook url you want to use |
||
71 | * @return array The response array |
||
72 | */ |
||
73 | 3 | public function registerInviteeCanceled($url){ |
|
76 | |||
77 | /** |
||
78 | * Sends a request to delete a hook |
||
79 | * @param integer|string $id The ID of the hook you want to delete |
||
80 | * @return null returns null when successful |
||
81 | */ |
||
82 | 3 | public function unregister($id){ |
|
86 | |||
87 | /** |
||
88 | * Sends a request to create a hook with the provided data |
||
89 | * @param array $data The data you want to include in the POST request |
||
90 | * @return array The response array |
||
91 | */ |
||
92 | 6 | protected function register($data){ |
|
97 | |||
98 | /** |
||
99 | * Converts an array into a post fields string for CURL |
||
100 | * @param array $data The data you want to convert |
||
101 | * @return string |
||
102 | */ |
||
103 | 12 | protected function buildPostFields(array $data){ |
|
107 | |||
108 | /** |
||
109 | * Builds the URL from the host and version properties |
||
110 | * @param string $action The API action you want to execute |
||
111 | * @return string |
||
112 | */ |
||
113 | 12 | protected function buildUrl($action = "hooks"){ |
|
116 | |||
117 | /** |
||
118 | * Returns the HttpRequest instance |
||
119 | * @param string $url The URL to request |
||
120 | * @return HttpRequest |
||
121 | */ |
||
122 | 9 | protected function getRequest($url){ |
|
129 | |||
130 | /** |
||
131 | * Executes a CURL command to the Calendly API |
||
132 | * @param string $url The URL to send to |
||
133 | * @param string $data Data from the http_build_query function |
||
134 | * @param string $method POST, GET, DELETE, PUT, etc... |
||
135 | * @return array The response data as an assoc array |
||
136 | */ |
||
137 | 9 | protected function exec($url = "", $data = null, $method = "POST"){ |
|
159 | |||
160 | /** |
||
161 | * Returns the response as an array or throws an Exception if it was unsuccessful |
||
162 | * @param string $result JSON string from the response |
||
163 | * @param integer $code The HTTP response code |
||
164 | * @return array |
||
165 | */ |
||
166 | 15 | protected function handleResponse($result,$code){ |
|
174 | } |