Completed
Push — master ( 6a21b5...b393f5 )
by Matthew
02:21
created

_Discussion::monitorForum()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 8
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 8
loc 8
rs 9.4285
cc 1
eloc 4
nc 1
nop 2
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: Matt
5
 * Date: 20/04/2016
6
 * Time: 2:32 PM
7
 */
8
9
namespace Freshdesk\Resources;
10
11
/**
12
 * Agent resources
13
 *
14
 * @package Freshdesk\Resources
15
 */
16
class _Discussion extends AbstractResource
17
{
18
19
    /**
20
     * The resource endpoint
21
     *
22
     * @var string
23
     */
24
    protected $endpoint = '/discussions/categories';
25
26
    /**
27
     * The forums resource endpoint
28
     *
29
     * @var string
30
     */
31
    private $forumsEndpoint = '/discussions/forums';
0 ignored issues
show
Unused Code introduced by
The property $forumsEndpoint is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
32
33
    /**
34
     * The forums topics resource endpoint
35
     *
36
     * @var string
37
     */
38
    private $topicsEndpoint = '/discussions/topics';
39
40
   
41
42
    /**
43
     * Creates the forums endpoint
44
     * @param null $id
45
     * @return string
46
     */
47
    protected function topicsEndpoint($id = null)
48
    {
49
        return $id == null ? $this->topicsEndpoint : $this->topicsEndpoint . '/' . $id;
50
    }
51
52
    /**
53
     *
54
     * List forum categories.
55
     *
56
     * @param array $query
57
     * @return array|null
58
     * @throws \Freshdesk\Exceptions\AccessDeniedException
59
     * @throws \Freshdesk\Exceptions\ApiException
60
     * @throws \Freshdesk\Exceptions\AuthenticationException
61
     * @throws \Freshdesk\Exceptions\ConflictingStateException
62
     * @throws \Freshdesk\Exceptions\MethodNotAllowedException
63
     * @throws \Freshdesk\Exceptions\NotFoundException
64
     * @throws \Freshdesk\Exceptions\RateLimitExceededException
65
     * @throws \Freshdesk\Exceptions\UnsupportedAcceptHeaderException
66
     * @throws \Freshdesk\Exceptions\UnsupportedContentTypeException
67
     * @throws \Freshdesk\Exceptions\ValidationException
68
     * @internal param $id
69
     */
70
    public function allCategories(array $query = null)
71
    {
72
        return $this->api()->request('GET', $this->endpoint(), null, $query);
73
    }
74
75
    /**
76
     *
77
     * Create a forum category.
78
     *
79
     * @param array $data
80
     * @return array|null
81
     * @throws \Freshdesk\Exceptions\AccessDeniedException
82
     * @throws \Freshdesk\Exceptions\ApiException
83
     * @throws \Freshdesk\Exceptions\AuthenticationException
84
     * @throws \Freshdesk\Exceptions\ConflictingStateException
85
     * @throws \Freshdesk\Exceptions\NotFoundException
86
     * @throws \Freshdesk\Exceptions\RateLimitExceededException
87
     * @throws \Freshdesk\Exceptions\UnsupportedContentTypeException
88
     * @throws \Freshdesk\Exceptions\MethodNotAllowedException
89
     * @throws \Freshdesk\Exceptions\UnsupportedAcceptHeaderException
90
     * @throws \Freshdesk\Exceptions\ValidationException
91
     */
92
    public function createCategory(array $data)
93
    {
94
        return $this->api()->request('POST', $this->endpoint(), $data);
95
    }
96
97
    /**
98
     *
99
     * View a forum category.
100
     *
101
     * @param int $id
102
     * @return array|null
103
     * @param array|null $query
104
     * @throws \Freshdesk\Exceptions\AccessDeniedException
105
     * @throws \Freshdesk\Exceptions\ApiException
106
     * @throws \Freshdesk\Exceptions\AuthenticationException
107
     * @throws \Freshdesk\Exceptions\ConflictingStateException
108
     * @throws \Freshdesk\Exceptions\MethodNotAllowedException
109
     * @throws \Freshdesk\Exceptions\NotFoundException
110
     * @throws \Freshdesk\Exceptions\RateLimitExceededException
111
     * @throws \Freshdesk\Exceptions\UnsupportedAcceptHeaderException
112
     * @throws \Freshdesk\Exceptions\UnsupportedContentTypeException
113
     * @throws \Freshdesk\Exceptions\ValidationException
114
     */
115
    public function viewCategory($id, array $query = null)
116
    {
117
        return $this->api()->request('GET', $this->endpoint($id), null, $query);
118
    }
119
120
    /**
121
     *
122
     * Update a forum category.
123
     *
124
     * @param int $id
125
     * @param array $data
126
     * @return array|null
127
     * @throws \Freshdesk\Exceptions\AccessDeniedException
128
     * @throws \Freshdesk\Exceptions\ApiException
129
     * @throws \Freshdesk\Exceptions\AuthenticationException
130
     * @throws \Freshdesk\Exceptions\ConflictingStateException
131
     * @throws \Freshdesk\Exceptions\MethodNotAllowedException
132
     * @throws \Freshdesk\Exceptions\NotFoundException
133
     * @throws \Freshdesk\Exceptions\RateLimitExceededException
134
     * @throws \Freshdesk\Exceptions\UnsupportedAcceptHeaderException
135
     * @throws \Freshdesk\Exceptions\UnsupportedContentTypeException
136
     * @throws \Freshdesk\Exceptions\ValidationException
137
     */
138
    public function updateCategory($id, array $data)
139
    {
140
        return $this->api()->request('PUT', $this->endpoint($id), $data);
141
    }
142
143
    /**
144
     *
145
     * Delete a forum category.
146
     *
147
     * @param int $id
148
     * @return array|null
149
     * @throws \Freshdesk\Exceptions\AccessDeniedException
150
     * @throws \Freshdesk\Exceptions\ApiException
151
     * @throws \Freshdesk\Exceptions\AuthenticationException
152
     * @throws \Freshdesk\Exceptions\ConflictingStateException
153
     * @throws \Freshdesk\Exceptions\MethodNotAllowedException
154
     * @throws \Freshdesk\Exceptions\NotFoundException
155
     * @throws \Freshdesk\Exceptions\RateLimitExceededException
156
     * @throws \Freshdesk\Exceptions\UnsupportedAcceptHeaderException
157
     * @throws \Freshdesk\Exceptions\UnsupportedContentTypeException
158
     * @throws \Freshdesk\Exceptions\ValidationException
159
     */
160
    public function deleteCategory($id)
161
    {
162
        return  $this->api()->request('DELETE', $this->endpoint($id));
163
    }
164
165
    /**
166
     *
167
     * Create a forum for a category.
168
     *
169
     * @param int $id The category Id
170
     * @param array $data
171
     * @return array|null
172
     * @throws \Freshdesk\Exceptions\AccessDeniedException
173
     * @throws \Freshdesk\Exceptions\ApiException
174
     * @throws \Freshdesk\Exceptions\AuthenticationException
175
     * @throws \Freshdesk\Exceptions\ConflictingStateException
176
     * @throws \Freshdesk\Exceptions\NotFoundException
177
     * @throws \Freshdesk\Exceptions\RateLimitExceededException
178
     * @throws \Freshdesk\Exceptions\UnsupportedContentTypeException
179
     * @throws \Freshdesk\Exceptions\MethodNotAllowedException
180
     * @throws \Freshdesk\Exceptions\UnsupportedAcceptHeaderException
181
     * @throws \Freshdesk\Exceptions\ValidationException
182
     */
183
    public function createForum($id, array $data)
184
    {
185
        return $this->api()->request('POST', $this->endpoint($id), $data);
186
    }
187
188
    /**
189
     *
190
     * View a forum
191
     *
192
     * @param int $id
193
     * @param array|null $query
194
     * @return array|null
195
     * @throws \Freshdesk\Exceptions\AccessDeniedException
196
     * @throws \Freshdesk\Exceptions\ApiException
197
     * @throws \Freshdesk\Exceptions\AuthenticationException
198
     * @throws \Freshdesk\Exceptions\ConflictingStateException
199
     * @throws \Freshdesk\Exceptions\NotFoundException
200
     * @throws \Freshdesk\Exceptions\RateLimitExceededException
201
     * @throws \Freshdesk\Exceptions\UnsupportedContentTypeException
202
     * @throws \Freshdesk\Exceptions\MethodNotAllowedException
203
     * @throws \Freshdesk\Exceptions\UnsupportedAcceptHeaderException
204
     * @throws \Freshdesk\Exceptions\ValidationException
205
     */
206
    public function viewForum($id, array $query = null)
207
    {
208
        return $this->api()->request('GET', $this->forumsEndpoint($id), null, $query);
0 ignored issues
show
Bug introduced by
The method forumsEndpoint() does not exist on Freshdesk\Resources\_Discussion. Did you maybe mean endpoint()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
209
    }
210
211
    /**
212
     *
213
     * Update a forum
214
     *
215
     * @param int $id
216
     * @param array $data
217
     * @return array|null
218
     * @throws \Freshdesk\Exceptions\AccessDeniedException
219
     * @throws \Freshdesk\Exceptions\ApiException
220
     * @throws \Freshdesk\Exceptions\AuthenticationException
221
     * @throws \Freshdesk\Exceptions\ConflictingStateException
222
     * @throws \Freshdesk\Exceptions\NotFoundException
223
     * @throws \Freshdesk\Exceptions\RateLimitExceededException
224
     * @throws \Freshdesk\Exceptions\UnsupportedContentTypeException
225
     * @throws \Freshdesk\Exceptions\MethodNotAllowedException
226
     * @throws \Freshdesk\Exceptions\UnsupportedAcceptHeaderException
227
     * @throws \Freshdesk\Exceptions\ValidationException
228
     */
229
    public function updateForum($id, array $data)
230
    {
231
        return $this->api()->request('PUT', $this->forumsEndpoint($id), $data);
0 ignored issues
show
Bug introduced by
The method forumsEndpoint() does not exist on Freshdesk\Resources\_Discussion. Did you maybe mean endpoint()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
232
    }
233
234
    /**
235
     *
236
     * Update a forum
237
     *
238
     * @param int $id
239
     * @return array|null
240
     * @throws \Freshdesk\Exceptions\AccessDeniedException
241
     * @throws \Freshdesk\Exceptions\ApiException
242
     * @throws \Freshdesk\Exceptions\AuthenticationException
243
     * @throws \Freshdesk\Exceptions\ConflictingStateException
244
     * @throws \Freshdesk\Exceptions\NotFoundException
245
     * @throws \Freshdesk\Exceptions\RateLimitExceededException
246
     * @throws \Freshdesk\Exceptions\UnsupportedContentTypeException
247
     * @throws \Freshdesk\Exceptions\MethodNotAllowedException
248
     * @throws \Freshdesk\Exceptions\UnsupportedAcceptHeaderException
249
     * @throws \Freshdesk\Exceptions\ValidationException
250
     */
251
    public function deleteForum($id)
252
    {
253
        return $this->api()->request('DELETE', $this->forumsEndpoint($id));
0 ignored issues
show
Bug introduced by
The method forumsEndpoint() does not exist on Freshdesk\Resources\_Discussion. Did you maybe mean endpoint()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
254
    }
255
256
    /**
257
     *
258
     * Monitor a forum for the given user
259
     *
260
     * @param int $userId
261
     * @return array|null
262
     * @throws \Freshdesk\Exceptions\AccessDeniedException
263
     * @throws \Freshdesk\Exceptions\ApiException
264
     * @throws \Freshdesk\Exceptions\AuthenticationException
265
     * @throws \Freshdesk\Exceptions\ConflictingStateException
266
     * @throws \Freshdesk\Exceptions\NotFoundException
267
     * @throws \Freshdesk\Exceptions\RateLimitExceededException
268
     * @throws \Freshdesk\Exceptions\UnsupportedContentTypeException
269
     * @throws \Freshdesk\Exceptions\MethodNotAllowedException
270
     * @throws \Freshdesk\Exceptions\UnsupportedAcceptHeaderException
271
     * @throws \Freshdesk\Exceptions\ValidationException
272
     */
273 View Code Duplication
    public function monitorForum($id, $userId)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
274
    {
275
        $data = [
276
           'user_id' => $userId
277
        ];
278
279
        return $this->api()->request('POST', $this->forumsEndpoint($id . '/follow'), $data);
0 ignored issues
show
Bug introduced by
The method forumsEndpoint() does not exist on Freshdesk\Resources\_Discussion. Did you maybe mean endpoint()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
280
    }
281
282
    /**
283
     *
284
     * UnMonitor a forum for the given user
285
     *
286
     * @param int $userId
287
     * @return array|null
288
     * @throws \Freshdesk\Exceptions\AccessDeniedException
289
     * @throws \Freshdesk\Exceptions\ApiException
290
     * @throws \Freshdesk\Exceptions\AuthenticationException
291
     * @throws \Freshdesk\Exceptions\ConflictingStateException
292
     * @throws \Freshdesk\Exceptions\NotFoundException
293
     * @throws \Freshdesk\Exceptions\RateLimitExceededException
294
     * @throws \Freshdesk\Exceptions\UnsupportedContentTypeException
295
     * @throws \Freshdesk\Exceptions\MethodNotAllowedException
296
     * @throws \Freshdesk\Exceptions\UnsupportedAcceptHeaderException
297
     * @throws \Freshdesk\Exceptions\ValidationException
298
     */
299 View Code Duplication
    public function unMonitorForum($id, $userId)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
300
    {
301
        $query = [
302
            'user_id' => $userId
303
        ];
304
305
        return $this->api()->request('POST', $this->forumsEndpoint($id . '/follow'), null, $query);
0 ignored issues
show
Bug introduced by
The method forumsEndpoint() does not exist on Freshdesk\Resources\_Discussion. Did you maybe mean endpoint()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
306
    }
307
308
    /**
309
     *
310
     * UnMonitor a forum for the given user
311
     *
312
     * @param int $userId
313
     * @return array|null
314
     * @throws \Freshdesk\Exceptions\AccessDeniedException
315
     * @throws \Freshdesk\Exceptions\ApiException
316
     * @throws \Freshdesk\Exceptions\AuthenticationException
317
     * @throws \Freshdesk\Exceptions\ConflictingStateException
318
     * @throws \Freshdesk\Exceptions\NotFoundException
319
     * @throws \Freshdesk\Exceptions\RateLimitExceededException
320
     * @throws \Freshdesk\Exceptions\UnsupportedContentTypeException
321
     * @throws \Freshdesk\Exceptions\MethodNotAllowedException
322
     * @throws \Freshdesk\Exceptions\UnsupportedAcceptHeaderException
323
     * @throws \Freshdesk\Exceptions\ValidationException
324
     */
325 View Code Duplication
    public function monitorForumStatus($id, $userId)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
326
    {
327
        $query = [
328
            'user_id' => $userId
329
        ];
330
331
        return $this->api()->request('GET', $this->forumsEndpoint($id . '/follow'), null, $query);
0 ignored issues
show
Bug introduced by
The method forumsEndpoint() does not exist on Freshdesk\Resources\_Discussion. Did you maybe mean endpoint()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
332
    }
333
334
    /**
335
     *
336
     * View all topics for a forum
337
     *
338
     * @param int $id
339
     * @param array|null $query
340
     * @return array|null
341
     * @throws \Freshdesk\Exceptions\AccessDeniedException
342
     * @throws \Freshdesk\Exceptions\ApiException
343
     * @throws \Freshdesk\Exceptions\AuthenticationException
344
     * @throws \Freshdesk\Exceptions\ConflictingStateException
345
     * @throws \Freshdesk\Exceptions\NotFoundException
346
     * @throws \Freshdesk\Exceptions\RateLimitExceededException
347
     * @throws \Freshdesk\Exceptions\UnsupportedContentTypeException
348
     * @throws \Freshdesk\Exceptions\MethodNotAllowedException
349
     * @throws \Freshdesk\Exceptions\UnsupportedAcceptHeaderException
350
     * @throws \Freshdesk\Exceptions\ValidationException
351
     */
352
    public function viewAllForumTopics($id, array $query = null)
353
    {
354
        return $this->api()->request('GET', $this->forumsEndpoint($id . '/topics'), null, $query);
0 ignored issues
show
Bug introduced by
The method forumsEndpoint() does not exist on Freshdesk\Resources\_Discussion. Did you maybe mean endpoint()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
355
    }
356
357
    /**
358
     *
359
     * Create a topic for a forum
360
     *
361
     * @param int $id
362
     * @param array $data
363
     * @return array|null
364
     * @throws \Freshdesk\Exceptions\AccessDeniedException
365
     * @throws \Freshdesk\Exceptions\ApiException
366
     * @throws \Freshdesk\Exceptions\AuthenticationException
367
     * @throws \Freshdesk\Exceptions\ConflictingStateException
368
     * @throws \Freshdesk\Exceptions\NotFoundException
369
     * @throws \Freshdesk\Exceptions\RateLimitExceededException
370
     * @throws \Freshdesk\Exceptions\UnsupportedContentTypeException
371
     * @throws \Freshdesk\Exceptions\MethodNotAllowedException
372
     * @throws \Freshdesk\Exceptions\UnsupportedAcceptHeaderException
373
     * @throws \Freshdesk\Exceptions\ValidationException
374
     */
375
    public function createForumTopic($id, array $data)
376
    {
377
        return $this->api()->request('POST', $this->forumsEndpoint($id . '/topics'), $data);
0 ignored issues
show
Bug introduced by
The method forumsEndpoint() does not exist on Freshdesk\Resources\_Discussion. Did you maybe mean endpoint()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
378
    }
379
380
    /**
381
     *
382
     * View a topic
383
     *
384
     * @param int $id
385
     * @param array $query
386
     * @return array|null
387
     * @throws \Freshdesk\Exceptions\AccessDeniedException
388
     * @throws \Freshdesk\Exceptions\ApiException
389
     * @throws \Freshdesk\Exceptions\AuthenticationException
390
     * @throws \Freshdesk\Exceptions\ConflictingStateException
391
     * @throws \Freshdesk\Exceptions\NotFoundException
392
     * @throws \Freshdesk\Exceptions\RateLimitExceededException
393
     * @throws \Freshdesk\Exceptions\UnsupportedContentTypeException
394
     * @throws \Freshdesk\Exceptions\MethodNotAllowedException
395
     * @throws \Freshdesk\Exceptions\UnsupportedAcceptHeaderException
396
     * @throws \Freshdesk\Exceptions\ValidationException
397
     */
398
    public function viewTopic($id, array $query = null)
399
    {
400
        return $this->api()->request('GET', $this->topicsEndpoint($id), null, $query);
401
    }
402
403
    /**
404
     *
405
     * Update a topic
406
     *
407
     * @param int $id
408
     * @param array $data
409
     * @return array|null
410
     * @throws \Freshdesk\Exceptions\AccessDeniedException
411
     * @throws \Freshdesk\Exceptions\ApiException
412
     * @throws \Freshdesk\Exceptions\AuthenticationException
413
     * @throws \Freshdesk\Exceptions\ConflictingStateException
414
     * @throws \Freshdesk\Exceptions\NotFoundException
415
     * @throws \Freshdesk\Exceptions\RateLimitExceededException
416
     * @throws \Freshdesk\Exceptions\UnsupportedContentTypeException
417
     * @throws \Freshdesk\Exceptions\MethodNotAllowedException
418
     * @throws \Freshdesk\Exceptions\UnsupportedAcceptHeaderException
419
     * @throws \Freshdesk\Exceptions\ValidationException
420
     */
421
    public function updateTopic($id, array $data)
422
    {
423
        return $this->api()->request('PUT', $this->topicsEndpoint($id), $data);
424
    }
425
426
    /**
427
     *
428
     * Delete a topic
429
     *
430
     * @param int $id
431
     * @return array|null
432
     * @throws \Freshdesk\Exceptions\AccessDeniedException
433
     * @throws \Freshdesk\Exceptions\ApiException
434
     * @throws \Freshdesk\Exceptions\AuthenticationException
435
     * @throws \Freshdesk\Exceptions\ConflictingStateException
436
     * @throws \Freshdesk\Exceptions\NotFoundException
437
     * @throws \Freshdesk\Exceptions\RateLimitExceededException
438
     * @throws \Freshdesk\Exceptions\UnsupportedContentTypeException
439
     * @throws \Freshdesk\Exceptions\MethodNotAllowedException
440
     * @throws \Freshdesk\Exceptions\UnsupportedAcceptHeaderException
441
     * @throws \Freshdesk\Exceptions\ValidationException
442
     */
443
    public function deleteTopic($id)
444
    {
445
        return $this->api()->request('DELETE', $this->topicsEndpoint($id));
446
    }
447
448
    /**
449
     *
450
     * List comments in a topic
451
     *
452
     * @param int $id
453
     * @param array $query
454
     * @return array|null
455
     * @throws \Freshdesk\Exceptions\AccessDeniedException
456
     * @throws \Freshdesk\Exceptions\ApiException
457
     * @throws \Freshdesk\Exceptions\AuthenticationException
458
     * @throws \Freshdesk\Exceptions\ConflictingStateException
459
     * @throws \Freshdesk\Exceptions\NotFoundException
460
     * @throws \Freshdesk\Exceptions\RateLimitExceededException
461
     * @throws \Freshdesk\Exceptions\UnsupportedContentTypeException
462
     * @throws \Freshdesk\Exceptions\MethodNotAllowedException
463
     * @throws \Freshdesk\Exceptions\UnsupportedAcceptHeaderException
464
     * @throws \Freshdesk\Exceptions\ValidationException
465
     */
466
    public function allTopicComments($id, array $query = null)
467
    {
468
        return $this->api()->request('GET', $this->topicsEndpoint($id . '/comments'), null, $query);
469
    }
470
471
472
}
473