1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Created by PhpStorm. |
4
|
|
|
* User: Matthew |
5
|
|
|
* Date: 21/04/2016 |
6
|
|
|
* Time: 10:23 AM |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace Freshdesk\Resources\Traits; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Monitor Trait |
13
|
|
|
* |
14
|
|
|
* @package Freshdesk\Resources\Traits |
15
|
|
|
*/ |
16
|
|
|
trait MonitorTrait |
17
|
|
|
{ |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @param string $end string |
21
|
|
|
* @return string |
22
|
|
|
* @internal |
23
|
|
|
*/ |
24
|
|
|
abstract protected function endpoint($end = null); |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @return \Freshdesk\Api |
28
|
|
|
* @internal |
29
|
|
|
*/ |
30
|
|
|
abstract protected function api(); |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Monitor a resource |
34
|
|
|
* |
35
|
|
|
* Monitor a resource for the given user |
36
|
|
|
* |
37
|
|
|
* @api |
38
|
|
|
* @param $id The id of the resource |
39
|
|
|
* @param $userId The id of the user |
40
|
|
|
* @return array|null |
41
|
|
|
* @throws \Freshdesk\Exceptions\AccessDeniedException |
42
|
|
|
* @throws \Freshdesk\Exceptions\ApiException |
43
|
|
|
* @throws \Freshdesk\Exceptions\AuthenticationException |
44
|
|
|
* @throws \Freshdesk\Exceptions\ConflictingStateException |
45
|
|
|
* @throws \Freshdesk\Exceptions\NotFoundException |
46
|
|
|
* @throws \Freshdesk\Exceptions\RateLimitExceededException |
47
|
|
|
* @throws \Freshdesk\Exceptions\UnsupportedContentTypeException |
48
|
|
|
* @throws \Freshdesk\Exceptions\MethodNotAllowedException |
49
|
|
|
* @throws \Freshdesk\Exceptions\UnsupportedAcceptHeaderException |
50
|
|
|
* @throws \Freshdesk\Exceptions\ValidationException |
51
|
|
|
*/ |
52
|
|
View Code Duplication |
public function monitor($id, $userId) |
|
|
|
|
53
|
|
|
{ |
54
|
|
|
$data = [ |
55
|
|
|
'user_id' => $userId |
56
|
|
|
]; |
57
|
|
|
|
58
|
|
|
return $this->api()->request('POST', $this->endpoint($id . '/follow'), $data); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Unmonitor a resource |
63
|
|
|
* |
64
|
|
|
* Unmonitor a resource for the given user |
65
|
|
|
* |
66
|
|
|
* @api |
67
|
|
|
* @param $id The id of the resource |
68
|
|
|
* @param $userId The id of the user |
69
|
|
|
* @return array|null |
70
|
|
|
* @throws \Freshdesk\Exceptions\AccessDeniedException |
71
|
|
|
* @throws \Freshdesk\Exceptions\ApiException |
72
|
|
|
* @throws \Freshdesk\Exceptions\AuthenticationException |
73
|
|
|
* @throws \Freshdesk\Exceptions\ConflictingStateException |
74
|
|
|
* @throws \Freshdesk\Exceptions\NotFoundException |
75
|
|
|
* @throws \Freshdesk\Exceptions\RateLimitExceededException |
76
|
|
|
* @throws \Freshdesk\Exceptions\UnsupportedContentTypeException |
77
|
|
|
* @throws \Freshdesk\Exceptions\MethodNotAllowedException |
78
|
|
|
* @throws \Freshdesk\Exceptions\UnsupportedAcceptHeaderException |
79
|
|
|
* @throws \Freshdesk\Exceptions\ValidationException |
80
|
|
|
*/ |
81
|
|
View Code Duplication |
public function unmonitor($id, $userId) |
|
|
|
|
82
|
|
|
{ |
83
|
|
|
$query = [ |
84
|
|
|
'user_id' => $userId |
85
|
|
|
]; |
86
|
|
|
|
87
|
|
|
return $this->api()->request('POST', $this->endpoint($id . '/follow'), null, $query); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Monitor status |
92
|
|
|
* |
93
|
|
|
* Get the monitoring status of the topic for the user |
94
|
|
|
* |
95
|
|
|
* @api |
96
|
|
|
* @param $id The id of the resource |
97
|
|
|
* @param $userId The id of the user |
98
|
|
|
* @return array|null |
99
|
|
|
* @throws \Freshdesk\Exceptions\AccessDeniedException |
100
|
|
|
* @throws \Freshdesk\Exceptions\ApiException |
101
|
|
|
* @throws \Freshdesk\Exceptions\AuthenticationException |
102
|
|
|
* @throws \Freshdesk\Exceptions\ConflictingStateException |
103
|
|
|
* @throws \Freshdesk\Exceptions\NotFoundException |
104
|
|
|
* @throws \Freshdesk\Exceptions\RateLimitExceededException |
105
|
|
|
* @throws \Freshdesk\Exceptions\UnsupportedContentTypeException |
106
|
|
|
* @throws \Freshdesk\Exceptions\MethodNotAllowedException |
107
|
|
|
* @throws \Freshdesk\Exceptions\UnsupportedAcceptHeaderException |
108
|
|
|
* @throws \Freshdesk\Exceptions\ValidationException |
109
|
|
|
*/ |
110
|
|
View Code Duplication |
public function monitorStatus($id, $userId) |
|
|
|
|
111
|
|
|
{ |
112
|
|
|
$query = [ |
113
|
|
|
'user_id' => $userId |
114
|
|
|
]; |
115
|
|
|
|
116
|
|
|
return $this->api()->request('GET', $this->endpoint($id . '/follow'), null, $query); |
117
|
|
|
} |
118
|
|
|
} |
119
|
|
|
|
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.