1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SolutionDrive\HipchatAPIv2Client\Model; |
4
|
|
|
|
5
|
|
|
class Webhook implements WebhookInterface |
6
|
|
|
{ |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* The unique identifier for the created entity |
10
|
|
|
* @var string|null |
11
|
|
|
*/ |
12
|
|
|
protected $id = null; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* The URL to send the webhook POST to |
16
|
|
|
* @var string |
17
|
|
|
*/ |
18
|
|
|
protected $url; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* The regular expression pattern to match against messages. |
22
|
|
|
* Only applicable for message events. |
23
|
|
|
* @var string |
24
|
|
|
*/ |
25
|
|
|
protected $pattern; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* The event to listen for |
29
|
|
|
* Valid values: |
30
|
|
|
* room_message, room_notification, room_exit, room_enter, room_topic_change. |
31
|
|
|
* @var string |
32
|
|
|
*/ |
33
|
|
|
protected $event; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* The label for this webhook |
37
|
|
|
* @var string |
38
|
|
|
*/ |
39
|
|
|
protected $name; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* URLs to retrieve webhook information |
43
|
|
|
* @var array |
44
|
|
|
*/ |
45
|
|
|
protected $links; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Webhook constructor |
49
|
|
|
*/ |
50
|
11 |
|
public function __construct($json = null) |
51
|
|
|
{ |
52
|
11 |
|
if ($json) { |
53
|
1 |
|
$this->parseJson($json); |
54
|
|
|
} else { |
55
|
10 |
|
$this->url = ''; |
56
|
10 |
|
$this->pattern = ''; |
57
|
10 |
|
$this->event = 'room_message'; |
58
|
10 |
|
$this->name = ''; |
59
|
10 |
|
$this->links = []; |
60
|
|
|
} |
61
|
11 |
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @inheritdoc |
65
|
|
|
*/ |
66
|
2 |
|
public function parseJson($json) |
67
|
|
|
{ |
68
|
2 |
|
$this->id = isset($json['id']) ? $json['id'] : null; |
69
|
2 |
|
$this->url = $json['url']; |
70
|
2 |
|
$this->pattern = $json['pattern']; |
71
|
2 |
|
$this->event = $json['event']; |
72
|
2 |
|
$this->name = $json['name']; |
73
|
2 |
|
$this->links = (isset($json['links']) && is_array($json['links'])) ? $json['links'] : array(); |
74
|
2 |
|
} |
75
|
|
|
|
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @inheritdoc |
79
|
|
|
*/ |
80
|
1 |
|
public function toJson() |
81
|
|
|
{ |
82
|
1 |
|
$json = array(); |
83
|
1 |
|
$json['id'] = $this->id; |
84
|
1 |
|
$json['url'] = $this->url; |
85
|
1 |
|
$json['pattern'] = $this->pattern; |
86
|
1 |
|
$json['event'] = $this->event; |
87
|
1 |
|
$json['name'] = $this->name; |
88
|
1 |
|
$json['links'] = $this->links; |
89
|
|
|
|
90
|
1 |
|
return $json; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @inheritdoc |
95
|
|
|
*/ |
96
|
2 |
|
public function getId() |
97
|
|
|
{ |
98
|
2 |
|
return $this->id; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @inheritdoc |
103
|
|
|
*/ |
104
|
2 |
|
public function setId($id) |
105
|
|
|
{ |
106
|
2 |
|
$this->id = $id; |
107
|
2 |
|
return $this; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @inheritdoc |
112
|
|
|
*/ |
113
|
2 |
|
public function getEvent() { |
114
|
2 |
|
return $this->event; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* @inheritdoc |
119
|
|
|
*/ |
120
|
2 |
|
public function setEvent($event) { |
121
|
2 |
|
$this->event = $event; |
122
|
2 |
|
return $this; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* @inheritdoc |
127
|
|
|
*/ |
128
|
2 |
|
public function getLinks() |
129
|
|
|
{ |
130
|
2 |
|
return $this->links; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* @inheritdoc |
135
|
|
|
*/ |
136
|
2 |
|
public function setLinks($links) |
137
|
|
|
{ |
138
|
2 |
|
$this->links = $links; |
139
|
2 |
|
return $this; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* @inheritdoc |
144
|
|
|
*/ |
145
|
2 |
|
public function getName() |
146
|
|
|
{ |
147
|
2 |
|
return $this->name; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* @inheritdoc |
152
|
|
|
*/ |
153
|
2 |
|
public function setName($name) |
154
|
|
|
{ |
155
|
2 |
|
$this->name = $name; |
156
|
2 |
|
return $this; |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* @inheritdoc |
161
|
|
|
*/ |
162
|
2 |
|
public function getPattern() |
163
|
|
|
{ |
164
|
2 |
|
return $this->pattern; |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* @inheritdoc |
169
|
|
|
*/ |
170
|
2 |
|
public function setPattern($pattern) |
171
|
|
|
{ |
172
|
2 |
|
$this->pattern = $pattern; |
173
|
2 |
|
return $this; |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
/** |
177
|
|
|
* @inheritdoc |
178
|
|
|
*/ |
179
|
2 |
|
public function getUrl() |
180
|
|
|
{ |
181
|
2 |
|
return $this->url; |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
/** |
185
|
|
|
* @inheritdoc |
186
|
|
|
*/ |
187
|
2 |
|
public function setUrl($url) |
188
|
|
|
{ |
189
|
2 |
|
$this->url = $url; |
190
|
2 |
|
return $this; |
191
|
|
|
} |
192
|
|
|
} |
193
|
|
|
|