|
| 1 | +package io.cryptolens.methods; |
| 2 | + |
| 3 | +import io.cryptolens.internal.BasicResult; |
| 4 | +import io.cryptolens.internal.HelperMethods; |
| 5 | +import io.cryptolens.models.*; |
| 6 | + |
| 7 | +import java.util.HashMap; |
| 8 | +import java.util.Map; |
| 9 | + |
| 10 | +/** |
| 11 | + * Methods related to the Message API (https://app.cryptolens.io/docs/api/v3/Message). |
| 12 | + * You can broadcast new messages by visiting https://app.cryptolens.io/Message. |
| 13 | + */ |
| 14 | +public class Message { |
| 15 | + |
| 16 | + // create an overload without the error object |
| 17 | + |
| 18 | + /** |
| 19 | + * This method will return a list of messages that were broadcasted. |
| 20 | + * You can create new messages here. Messages can be filtered based |
| 21 | + * on the time and the channel. |
| 22 | + * @param token The access token with 'GetMessages' permission. |
| 23 | + * @param model Method parameters. |
| 24 | + * @param error The error object whose Message field will be populated if an error has occurred. Please initialize |
| 25 | + * this parameter, i.e. define <code>APIError error = new APIError();</code> and then pass |
| 26 | + * <code>error</code> into this parameter. |
| 27 | + */ |
| 28 | + public GetMessagesResult GetMessages (String token, GetMessagesModel model) { |
| 29 | + return GetMessages(token, model, null); |
| 30 | + } |
| 31 | + |
| 32 | + |
| 33 | + /** |
| 34 | + * This method will return a list of messages that were broadcasted. |
| 35 | + * You can create new messages here. Messages can be filtered based |
| 36 | + * on the time and the channel. |
| 37 | + * @param token The access token with 'GetMessages' permission. |
| 38 | + * @param model Method parameters. |
| 39 | + * @param error The error object whose Message field will be populated if an error has occurred. Please initialize |
| 40 | + * this parameter, i.e. define <code>APIError error = new APIError();</code> and then pass |
| 41 | + * <code>error</code> into this parameter. |
| 42 | + */ |
| 43 | + public GetMessagesResult GetMessages (String token, GetMessagesModel model, APIError error) { |
| 44 | + |
| 45 | + |
| 46 | + Map<String,String> extraParams = new HashMap<>(); |
| 47 | + extraParams.put("token", token); |
| 48 | + |
| 49 | + GetMessagesResult result = HelperMethods.SendRequestToWebAPI("message/GetMessages", model, extraParams, GetMessagesResult.class, error); |
| 50 | + |
| 51 | + if(result == null || result.result == 1) { |
| 52 | + if(result != null) { |
| 53 | + if (error != null) { |
| 54 | + error.message = result.message; |
| 55 | + error.errorType = ErrorType.WebAPIError; |
| 56 | + } |
| 57 | + } else { |
| 58 | + if (error != null) { |
| 59 | + error.errorType = ErrorType.WebAPIError; |
| 60 | + } |
| 61 | + } |
| 62 | + } |
| 63 | + |
| 64 | + return result; |
| 65 | + } |
| 66 | + |
| 67 | +} |
0 commit comments