Skip to content

Commit e5adb95

Browse files
committed
CodemashPushNotification Device methods.
1 parent 9bf9d09 commit e5adb95

File tree

2 files changed

+233
-1
lines changed

2 files changed

+233
-1
lines changed

src/CodemashPushNotification.php

Lines changed: 161 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public function readNotification(array $params): int
142142
* @throws GuzzleException
143143
* @throws RequestValidationException
144144
*/
145-
public function deleteNotification(array $params)
145+
public function deleteNotification(array $params): int
146146
{
147147
$params = CodemashPushNotificationParams::prepGetByIdParams($params);
148148

@@ -153,4 +153,164 @@ public function deleteNotification(array $params)
153153
],
154154
]);
155155
}
156+
157+
/**
158+
* @throws GuzzleException
159+
* @throws RequestValidationException
160+
*/
161+
public function registerDevice(array $params = []): array
162+
{
163+
$params = CodemashPushNotificationParams::prepRegisterDeviceParams($params);
164+
165+
$response = $this->client->request('POST', $this->uriPrefix . 'devices', [
166+
'headers' => [
167+
'Accept' => 'application/json',
168+
'Content-Type' => 'application/json',
169+
],
170+
'body' => toJson($params),
171+
]);
172+
173+
return $response['result'];
174+
}
175+
176+
/**
177+
* @throws GuzzleException
178+
* @throws RequestValidationException
179+
*/
180+
public function registerExpoToken(array $params): string
181+
{
182+
$params = CodemashPushNotificationParams::prepRegisterExpoTokenParams($params);
183+
184+
$response = $this->client->request('POST', $this->uriPrefix . 'token/expo', [
185+
'headers' => [
186+
'Accept' => 'application/json',
187+
'Content-Type' => 'application/json',
188+
],
189+
'body' => toJson($params),
190+
]);
191+
192+
return $response['result'];
193+
}
194+
195+
/**
196+
* @throws GuzzleException
197+
* @throws RequestValidationException
198+
*/
199+
public function getDevice(array $params): array
200+
{
201+
$params = CodemashPushNotificationParams::prepGetByIdParams($params);
202+
203+
$response = $this->client->request('GET', $this->uriPrefix . 'devices/' . $params['id'], [
204+
'headers' => [
205+
'Accept' => 'application/json',
206+
'Content-Type' => 'application/json',
207+
],
208+
]);
209+
210+
return $response['result'];
211+
}
212+
213+
/**
214+
* @throws GuzzleException
215+
*/
216+
public function getDevices(): array
217+
{
218+
$response = $this->client->request('GET', $this->uriPrefix . 'devices', [
219+
'headers' => [
220+
'Accept' => 'application/json',
221+
'Content-Type' => 'application/json',
222+
],
223+
]);
224+
225+
return $response['result'];
226+
}
227+
228+
/**
229+
* @throws GuzzleException
230+
* @throws RequestValidationException
231+
*/
232+
public function deleteDevice(array $params): int
233+
{
234+
$params = CodemashPushNotificationParams::prepGetByIdParams($params);
235+
236+
return $this->client->request('DELETE', $this->uriPrefix . 'devices/' . $params['id'], [
237+
'headers' => [
238+
'Accept' => 'application/json',
239+
'Content-Type' => 'application/json',
240+
],
241+
]);
242+
}
243+
244+
/**
245+
* @throws GuzzleException
246+
* @throws RequestValidationException
247+
*/
248+
public function deleteDeviceToken(array $params): int
249+
{
250+
$params = CodemashPushNotificationParams::prepGetByIdParams($params);
251+
252+
return $this->client->request('DELETE', $this->uriPrefix . 'devices/' . $params['id'] . '/token', [
253+
'headers' => [
254+
'Accept' => 'application/json',
255+
'Content-Type' => 'application/json',
256+
],
257+
]);
258+
}
259+
260+
/**
261+
* @throws GuzzleException
262+
* @throws RequestValidationException
263+
*/
264+
public function updateDeviceMeta(array $params): bool
265+
{
266+
$params = CodemashPushNotificationParams::prepUpdateDeviceMetaParams($params);
267+
268+
$response = $this->client->request('PATCH', $this->uriPrefix . 'devices/' . $params['id'] . '/metadata', [
269+
'headers' => [
270+
'Accept' => 'application/json',
271+
'Content-Type' => 'application/json',
272+
],
273+
'body' => toJson($params),
274+
]);
275+
276+
return $response['result'];
277+
}
278+
279+
/**
280+
* @throws GuzzleException
281+
* @throws RequestValidationException
282+
*/
283+
public function updateDeviceTimezone(array $params): bool
284+
{
285+
$params = CodemashPushNotificationParams::prepUpdateDeviceTimezoneParams($params);
286+
287+
$response = $this->client->request('PATCH', $this->uriPrefix . 'devices/' . $params['id'] . '/timezone', [
288+
'headers' => [
289+
'Accept' => 'application/json',
290+
'Content-Type' => 'application/json',
291+
],
292+
'body' => toJson($params),
293+
]);
294+
295+
return $response['result'];
296+
}
297+
298+
/**
299+
* @throws GuzzleException
300+
* @throws RequestValidationException
301+
*/
302+
public function updateDeviceUser(array $params): bool
303+
{
304+
$params = CodemashPushNotificationParams::prepUpdateDeviceUserParams($params);
305+
306+
$response = $this->client->request('PATCH', $this->uriPrefix . 'devices/' . $params['id'] . '/user', [
307+
'headers' => [
308+
'Accept' => 'application/json',
309+
'Content-Type' => 'application/json',
310+
],
311+
'body' => toJson($params),
312+
]);
313+
314+
return $response['result'];
315+
}
156316
}

src/Params/CodemashPushNotificationParams.php

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,76 @@ public static function prepGetNotificationsParams(array $params): array
4848
'deviceId' => $params['deviceId'] ?? null,
4949
];
5050
}
51+
52+
public static function prepRegisterDeviceParams(array $params): array
53+
{
54+
return [
55+
'userId' => $params['userId'] ?? null,
56+
'timeZone' => $params['timeZone'] ?? null,
57+
'meta' => $params['meta'] ?? null,
58+
];
59+
}
60+
61+
/**
62+
* @throws RequestValidationException
63+
*/
64+
public static function prepRegisterExpoTokenParams(array $params): array
65+
{
66+
$required = ['token'];
67+
68+
validateRequiredRequestParams($required, $params);
69+
70+
return [
71+
'token' => $params['token'],
72+
'deviceId' => $params['deviceId'] ?? null,
73+
'userId' => $params['userId'] ?? null,
74+
'timeZone' => $params['timeZone'] ?? null,
75+
'meta' => $params['meta'] ?? null,
76+
];
77+
}
78+
79+
/**
80+
* @throws RequestValidationException
81+
*/
82+
public static function prepUpdateDeviceMetaParams(array $params): array
83+
{
84+
$required = ['id'];
85+
86+
validateRequiredRequestParams($required, $params);
87+
88+
return [
89+
'id' => $params['id'],
90+
'meta' => $params['meta'] ?? null,
91+
];
92+
}
93+
94+
/**
95+
* @throws RequestValidationException
96+
*/
97+
public static function prepUpdateDeviceTimezoneParams(array $params): array
98+
{
99+
$required = ['id'];
100+
101+
validateRequiredRequestParams($required, $params);
102+
103+
return [
104+
'id' => $params['id'],
105+
'timezone' => $params['timezone'] ?? null,
106+
];
107+
}
108+
109+
/**
110+
* @throws RequestValidationException
111+
*/
112+
public static function prepUpdateDeviceUserParams(array $params): array
113+
{
114+
$required = ['id'];
115+
116+
validateRequiredRequestParams($required, $params);
117+
118+
return [
119+
'id' => $params['id'],
120+
'userId' => $params['userId'] ?? null,
121+
];
122+
}
51123
}

0 commit comments

Comments
 (0)