1 | <?php |
||
2 | |||
3 | namespace alexjose; |
||
4 | |||
5 | use GuzzleHttp\Client; |
||
6 | |||
7 | class ZoomApi{ |
||
8 | |||
9 | private $apiKey; |
||
10 | private $apiSecret; |
||
11 | private $apiUrl; |
||
12 | private $apiClient; |
||
13 | |||
14 | public function __construct($apiKey, $apiSecret, $apiUrl = 'https://api.zoom.us/v1/') |
||
15 | { |
||
16 | $this->apiKey = $apiKey; |
||
17 | $this->apiSecret = $apiSecret; |
||
18 | $this->apiUrl = $apiUrl; |
||
19 | |||
20 | $this->apiClient = new Client([ |
||
21 | // Base URI is used with relative requests |
||
22 | 'base_uri' => $this->apiUrl, |
||
23 | ]); |
||
24 | } |
||
25 | |||
26 | public function send($uri, $data = []) |
||
27 | { |
||
28 | $data['api_key'] = $this->apiKey; |
||
29 | $data['api_secret'] = $this->apiSecret; |
||
30 | |||
31 | try{ |
||
32 | $response = $this->apiClient->post($uri, [ |
||
33 | 'form_params' => $data |
||
34 | ]); |
||
35 | |||
36 | // $body = $response->getBody()->getContents(); |
||
0 ignored issues
–
show
|
|||
37 | $result = json_decode($response->getBody(), true); |
||
38 | }catch(GuzzleHttp\Exception\ClientException $ex){ |
||
0 ignored issues
–
show
|
|||
39 | throw $ex; |
||
40 | } |
||
41 | |||
42 | return $result; |
||
43 | } |
||
44 | |||
45 | /** |
||
46 | * |
||
47 | * List Users |
||
48 | * |
||
49 | * @param integer $pageSize The amount of records returns within a single API call. Max of 300 users. |
||
50 | * @param integer $pageNumber Current page number of returned records. Default to 1. |
||
51 | * @return array |
||
52 | */ |
||
53 | public function listUsers($pageSize = 30, $pageNumber = 1) |
||
54 | { |
||
55 | $data['page_size'] = $pageSize; |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||
56 | $data['page_number'] = $pageNumber; |
||
57 | |||
58 | return $this->send('user/list', $data); |
||
59 | } |
||
60 | |||
61 | /** |
||
62 | * |
||
63 | * Create A Meeting |
||
64 | * |
||
65 | * @param string $hostId Meeting host user ID. Can be any user under this account |
||
66 | * @param integer $type Meeting type |
||
67 | * @param string $topic Meeting topic. Max of 300 characters |
||
68 | * @param array $data Additional Data |
||
69 | * @return array |
||
70 | */ |
||
71 | public function createMeeting($hostId, $type, $topic, $data = []) |
||
72 | { |
||
73 | |||
74 | $validTypes = [1, 2, 3, 8]; |
||
75 | |||
76 | if(!in_array($type, $validTypes)){ |
||
77 | throw new \InvalidArgumentException('Invalid `type` passed. Possible values for `type` are ' . implode(", ", $validTypes)); |
||
78 | } |
||
79 | |||
80 | $optionalFields = [ |
||
81 | 'start_time', |
||
82 | 'duration', |
||
83 | 'timezone', |
||
84 | 'password', |
||
85 | 'recurrence', |
||
86 | 'option_registration', |
||
87 | 'registration_type', |
||
88 | 'option_jbh', |
||
89 | 'option_start_type', |
||
90 | 'option_host_video', |
||
91 | 'option_participants_video', |
||
92 | 'option_cn_meeting', |
||
93 | 'option_in_meeting', |
||
94 | 'option_audio', |
||
95 | 'option_enforce_login', |
||
96 | 'option_enforce_login_domains', |
||
97 | 'option_alternative_hosts', |
||
98 | 'option_alternative_host_ids', |
||
99 | 'option_use_pmi', |
||
100 | 'option_auto_record_type', |
||
101 | ]; |
||
102 | |||
103 | $invalidDataKeys = array_diff(array_keys($data), $optionalFields); |
||
104 | |||
105 | if(!empty($invalidDataKeys)){ |
||
106 | throw new \InvalidArgumentException('Invalid data passed. `' . implode(", ", $invalidDataKeys) . '` are not allowed.'); |
||
107 | } |
||
108 | |||
109 | $data['host_id'] = $hostId; |
||
110 | $data['type'] = $type; |
||
111 | $data['topic'] = $topic; |
||
112 | |||
113 | return $this->send('meeting/create', $data); |
||
114 | } |
||
115 | |||
116 | } |
||
117 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.