|
6 | 6 | import com.messagebird.objects.*; |
7 | 7 |
|
8 | 8 | import java.math.BigInteger; |
9 | | -import java.text.SimpleDateFormat; |
10 | 9 | import java.util.LinkedHashMap; |
11 | 10 | import java.util.List; |
12 | 11 | import java.util.Map; |
13 | 12 |
|
14 | 13 | /** |
15 | 14 | * Message bird general client |
16 | | - * <p/> |
| 15 | + * <p> |
17 | 16 | * <pre> |
18 | 17 | * Initialise this class with a MessageBirdService |
19 | 18 | * // First create your service object |
|
24 | 23 | * Then read your balance like this: |
25 | 24 | * final Balance balance = messageBirdClient.getBalance(); |
26 | 25 | * </pre> |
27 | | - * <p/> |
| 26 | + * <p> |
28 | 27 | * Created by rvt on 1/5/15. |
29 | 28 | */ |
30 | 29 | public class MessageBirdClient { |
31 | 30 | private static final String BALANCEPATH = "/balance"; |
32 | 31 | private static final String HLRPATH = "/hlr"; |
33 | 32 | private static final String MESSAGESPATH = "/messages"; |
34 | 33 | private static final String VOICEMESSAGESPATH = "/voicemessages"; |
| 34 | + private static final String VERIFYPATH = "/verify"; |
35 | 35 | private MessageBirdService messageBirdService; |
36 | 36 |
|
37 | 37 | public MessageBirdClient(final MessageBirdService messageBirdService) { |
@@ -308,4 +308,81 @@ public VoiceMessageList listVoiceMessages(final Integer offset, final Integer li |
308 | 308 | return messageBirdService.requestList(VOICEMESSAGESPATH, offset, limit, VoiceMessageList.class); |
309 | 309 | } |
310 | 310 |
|
| 311 | + /** |
| 312 | + * @param verifyRequest |
| 313 | + * @return Verify object |
| 314 | + * @throws UnauthorizedException |
| 315 | + * @throws GeneralException |
| 316 | + */ |
| 317 | + public Verify sendVerifyToken(VerifyRequest verifyRequest) throws UnauthorizedException, GeneralException { |
| 318 | + if (verifyRequest == null) { |
| 319 | + throw new IllegalArgumentException("Verify request cannot be null"); |
| 320 | + } else if (verifyRequest.getRecipient() == null || verifyRequest.getRecipient().isEmpty()) { |
| 321 | + throw new IllegalArgumentException("Recipient cannot be empty for verify"); |
| 322 | + } |
| 323 | + return messageBirdService.sendPayLoad(VERIFYPATH, verifyRequest, Verify.class); |
| 324 | + } |
| 325 | + |
| 326 | + /** |
| 327 | + * @param recipient |
| 328 | + * @return Verify object |
| 329 | + * @throws UnauthorizedException |
| 330 | + * @throws GeneralException |
| 331 | + */ |
| 332 | + public Verify sendVerifyToken(String recipient) throws UnauthorizedException, GeneralException { |
| 333 | + if (recipient == null || recipient.isEmpty()) { |
| 334 | + throw new IllegalArgumentException("Recipient cannot be empty for verify"); |
| 335 | + } |
| 336 | + VerifyRequest verifyRequest = new VerifyRequest(recipient); |
| 337 | + return this.sendVerifyToken(verifyRequest); |
| 338 | + } |
| 339 | + |
| 340 | + /** |
| 341 | + * |
| 342 | + * @param id |
| 343 | + * @param token |
| 344 | + * @return Verify object |
| 345 | + * @throws NotFoundException |
| 346 | + * @throws GeneralException |
| 347 | + * @throws UnauthorizedException |
| 348 | + */ |
| 349 | + public Verify verifyToken(String id, String token) throws NotFoundException, GeneralException, UnauthorizedException { |
| 350 | + if (id == null || id.isEmpty()) { |
| 351 | + throw new IllegalArgumentException("ID cannot be empty for verify"); |
| 352 | + } else if (token == null || token.isEmpty()) { |
| 353 | + throw new IllegalArgumentException("ID cannot be empty for verify"); |
| 354 | + } |
| 355 | + final Map<String, Object> params = new LinkedHashMap<String, Object>(); |
| 356 | + params.put("token", token); |
| 357 | + return messageBirdService.requestByID(VERIFYPATH, id, params, Verify.class); |
| 358 | + } |
| 359 | + |
| 360 | + /** |
| 361 | + * |
| 362 | + * @param id |
| 363 | + * @return Verify object |
| 364 | + * @throws NotFoundException |
| 365 | + * @throws GeneralException |
| 366 | + * @throws UnauthorizedException |
| 367 | + */ |
| 368 | + public Verify getVerifyObject(String id) throws NotFoundException, GeneralException, UnauthorizedException { |
| 369 | + if (id == null || id.isEmpty()) { |
| 370 | + throw new IllegalArgumentException("ID cannot be empty for verify"); |
| 371 | + } |
| 372 | + return messageBirdService.requestByID(VERIFYPATH, id, Verify.class); |
| 373 | + } |
| 374 | + |
| 375 | + /** |
| 376 | + * |
| 377 | + * @param id |
| 378 | + * @throws NotFoundException |
| 379 | + * @throws GeneralException |
| 380 | + * @throws UnauthorizedException |
| 381 | + */ |
| 382 | + public void deleteVerifyObject(String id) throws NotFoundException, GeneralException, UnauthorizedException { |
| 383 | + if (id == null || id.isEmpty()) { |
| 384 | + throw new IllegalArgumentException("ID cannot be empty for verify"); |
| 385 | + } |
| 386 | + messageBirdService.deleteByID(VERIFYPATH, id); |
| 387 | + } |
311 | 388 | } |
0 commit comments