From 6e460d6da45b5adf01959be17f3ccccba6e17c1e Mon Sep 17 00:00:00 2001 From: Bas Gijzen Date: Mon, 8 Jan 2024 17:11:48 +0100 Subject: [PATCH 01/15] Start of implementation --- README.md | 32 ++++++-- pom.xml | 2 +- src/main/java/com/cm/text/models/Body.java | 26 +++---- .../cm/text/models/identity/OtpRequest.java | 77 +++++++++++++++++++ 4 files changed, 115 insertions(+), 22 deletions(-) create mode 100644 src/main/java/com/cm/text/models/identity/OtpRequest.java diff --git a/README.md b/README.md index 5d8b6f5..798e29d 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ You can find our SDK [here](https://mvnrepository.com/artifact/com.cm/text-sdk), com.cm text-sdk - 2.1.0 + 3.0.0 ``` @@ -25,16 +25,16 @@ You will have to add GSON manually: https://mvnrepository.com/artifact/com.googl ## Instantiate the client Use your productToken which authorizes you on the CM platform. Get yours on CM.com -```cs +```java MessagingClient client = new MessagingClient("YourCMProductToken"); ``` ## Send a message By calling `SendTextMessage` and providing message text, sender name, recipient phone number(s). -```cs +```java MessagingClient client = new MessagingClient("YourProductToken"); - client.sendTextMessage("Message Text", "TestSender", new String[] {"00316012345678"}); + client.sendTextMessage("Message Text", "TestSender", new String[] {"00316012345678"}); ``` ## Sending a message with auto detect encoding @@ -45,7 +45,7 @@ In case it detects characters that are not part of the GSM character set, the me see our API docs for more info https://developers.cm.com/messaging/ -```cs +```java MessagingClient client = new MessagingClient("YourProductToken"); MessageBuilder builder = new MessageBuilder("Message Text", "auto", "TestSender", new String[] {"00316012345678"}); @@ -56,7 +56,7 @@ see our API docs for more info https://developers.cm.com/messaging/ ## Sending a rich message By using the `MessageBuilder` it is possible to create images with media for channels such as WhatsApp and Viber -```cs +```java MessagingClient client = new MessagingClient("YourProductToken"); MessageBuilder builder = new MessageBuilder("Message Text", "TestSender", new String[] {"00316012345678"}); @@ -76,7 +76,7 @@ By using the `MessageBuilder` it is possible to create images with media for cha ## Get the result Sending an message returns the response body -```cs +```java { "details": "Created 1 message(s)", "errorCode": 0, @@ -93,7 +93,7 @@ Sending an message returns the response body ## Whatsapp Templates Send WhatsApp template messages using the message builder please take a look at our documentation in the [Whatsapp templates section](https://developers.cm.com/messaging/docs/whatsapp#template) -```cs +```java MessagingClient client = new MessagingClient("YourProductToken"); @@ -127,3 +127,19 @@ MessagingClient client = new MessagingClient("YourProductToken"); ``` +## Using the OTP API +Send a simple OTP code +```java + MessagingClient client = new MessagingClient("YourProductToken"); + client.sendOtp("Sender", "316012345678", "sms"); +``` + +Verify the response code +```java + client.verifyOtp("OTP-ID", "code") +``` + +More advanced scenarios +```java + MessagingClient client = new MessagingClient("YourProductToken"); +``` \ No newline at end of file diff --git a/pom.xml b/pom.xml index 001857a..5ba7914 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ 4.0.0 com.cm text-sdk - 2.1.0 + 3.0.0 jar diff --git a/src/main/java/com/cm/text/models/Body.java b/src/main/java/com/cm/text/models/Body.java index acd79e8..7d1d5a6 100644 --- a/src/main/java/com/cm/text/models/Body.java +++ b/src/main/java/com/cm/text/models/Body.java @@ -4,19 +4,19 @@ public class Body { - /// - /// The actual text body of the message. - /// By default the CM gateway interprets messages as if sent with the standard 7 bit GSM encoding. - /// If you want to send messages using e.g. Arabic, Cyrillic of Greek characters - /// you will need to use the unicode UCS2 encoding. - /// Set the to Auto to let the gateway do the encoding detection. - /// Please note that there are a few limitations to using unicode encoded messages: - /// Unicode messages can contain up to 70 characters. In the case of multipart messages, this becomes 66 characters per - /// part. - /// You will need to POST the XML or JSON file. A HTTP GET request cannot handle the Unicode characters - /// Another note is that not all operators in the world are able to handle Unicode messages, so you will need to test - /// for which operators it works. - /// + /*** + * The actual text body of the message. + * By default the CM gateway interprets messages as if sent with the standard 7 bit GSM encoding. + * If you want to send messages using e.g. Arabic, Cyrillic of Greek characters + * you will need to use the unicode UCS2 encoding. + * Set the to Auto to let the gateway do the encoding detection. + * Please note that there are a few limitations to using unicode encoded messages: + * Unicode messages can contain up to 70 characters. In the case of multipart messages, this becomes 66 characters per + * part. + * You will need to POST the XML or JSON file. A HTTP GET request cannot handle the Unicode characters + * Another note is that not all operators in the world are able to handle Unicode messages, so you will need to test + * for which operators it works. + */ @SerializedName("content") public String Content; diff --git a/src/main/java/com/cm/text/models/identity/OtpRequest.java b/src/main/java/com/cm/text/models/identity/OtpRequest.java new file mode 100644 index 0000000..6e0cf71 --- /dev/null +++ b/src/main/java/com/cm/text/models/identity/OtpRequest.java @@ -0,0 +1,77 @@ +package com.cm.text.models.identity; + +import com.google.gson.annotations.SerializedName; + +public class OtpRequest { + /// + /// Required: This is the sender name. + /// The maximum length is 11 alphanumerical characters or 16 digits. Example: 'MyCompany' + /// + /*** */ + @SerializedName("from") + private String From; + + /// + /// Required: The destination mobile numbers. + /// This value should be in international format. + /// A single mobile number per request. Example: '00447911123456' + /// + [JsonPropertyName("to")] + public string To { get; set; } + + /// + /// The length of the code (min 4, max 10). default: 5. + /// + [JsonPropertyName("digits")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public int? Digits { get; set; } + + /// + /// The expiry in seconds (min 10, max 3600). default: 60 seconds. + /// + [JsonPropertyName("expiry")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public int? Expiry { get; set; } + + /// + /// The channel to send the code. + /// Supported values: auto, sms, push, whatsapp, voice, email. + /// Channel auto is only available with a SOLiD subscription. + /// + [JsonPropertyName("channel")] + public string Channel { get; set; } = "sms"; + + /// + /// The locale, for WhatsApp supported values: en, nl, fr, de, it, es. + /// Default: en + /// + /// For Voice: the spoken language in the voice call, + /// supported values: de-DE, en-AU, en-GB, en-IN, en-US, es-ES, fr-CA, fr-FR, it-IT, ja-JP, nl-NL + /// Default: en-GB. + /// + /// For Email: The locale for the email template. + /// + [JsonPropertyName("locale")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [CanBeNull] + public string Locale { get; set; } + + /// + /// The app key, when is 'push' + /// + [JsonPropertyName("pushAppKey")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [CanBeNull] + public string PushAppKey { get; set; } + + /// + /// For WhatsApp, set a custom message. You can use the placeholder {code}, this will be replaced by the actual code. + /// Example: Your code is: {code}. This is only used as a fallback in case the message could not be delivered via WhatsApp. + /// + /// For email, Set a custom message to be used in the email message. Do not include the {code} placeholder. + /// + [JsonPropertyName("message")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [CanBeNull] + public string Message { get; set; } +} From 893faa4160529826d6a6692545106d2dffa5360b Mon Sep 17 00:00:00 2001 From: Bas Gijzen Date: Tue, 9 Jan 2024 11:44:45 +0100 Subject: [PATCH 02/15] In progress: using Java style comments, encapsulation and method names --- src/main/java/com/cm/text/Config.java | 6 +- src/main/java/com/cm/text/MessageBuilder.java | 117 ++++---- .../java/com/cm/text/MessagingClient.java | 72 +++-- .../cm/text/models/identity/OtpRequest.java | 272 +++++++++++++----- .../java/com/cm/text/utils/HttpHelper.java | 36 ++- 5 files changed, 344 insertions(+), 159 deletions(-) diff --git a/src/main/java/com/cm/text/Config.java b/src/main/java/com/cm/text/Config.java index 9bc9911..7152c0d 100644 --- a/src/main/java/com/cm/text/Config.java +++ b/src/main/java/com/cm/text/Config.java @@ -1,6 +1,8 @@ package com.cm.text; public class Config { - - public static String ApiUrl = "https://gw.cmtelecom.com/v1.0/message"; + /** + * Api url for the business messaging api + */ + public static String BusinessMessagingApiUrl = "https://gw.messaging.cm.com/v1.0/message"; } diff --git a/src/main/java/com/cm/text/MessageBuilder.java b/src/main/java/com/cm/text/MessageBuilder.java index aec099e..24bb2aa 100644 --- a/src/main/java/com/cm/text/MessageBuilder.java +++ b/src/main/java/com/cm/text/MessageBuilder.java @@ -13,18 +13,20 @@ import java.util.ArrayList; import java.util.List; +/** + * Builder class to construct messages + */ public class MessageBuilder { private Message message; private RichContent richContent; - - /// - /// Creates a new MessageBuilder - /// - /// - /// - /// + /** + * Creates a new MessageBuilder + * @param messageText text to send in the message + * @param from sender id + * @param to recipients to send the messages towards + */ public MessageBuilder(String messageText, String from,String[] to) { List recipientList = new ArrayList<>(); @@ -44,7 +46,15 @@ public MessageBuilder(String messageText, String from,String[] to) /// /// /// - public MessageBuilder(String messageText, String type, String from,String[] to) + + /** + * Creates a new MessageBuilder + * @param messageText text to send in the message + * @param type encoding to use (use auto for auto detect encoding) + * @param from sender id + * @param to recipients to send the messages towards + */ + public MessageBuilder(String messageText, String type, String from,String[] to) { List recipientList = new ArrayList<>(); for (String number : to) { @@ -57,50 +67,48 @@ public MessageBuilder(String messageText, String type, String from,String[] to) this.message = new Message(new Body(messageText, type), from, recipientList); } - /// - /// Constructs the message. - /// - /// - public Message Build() + /** + * Constructs the message + * @return the message to send + */ + public Message build() { this.message.RichContent = this.richContent; return this.message; } - /// - /// Adds the allowed channels field, which forces a message to only use certain routes. - /// You can define a list of which channels you want your message to use. - /// Not defining any channels will be interpreted as allowing all channels. - /// - /// - /// Note that for channels other than SMS, CM needs to configure the out going flows. - /// For those flows to work, we need to be contacted. - /// - public MessageBuilder WithAllowedChannels(Channel[] channels) + /** + * Adds the allowed channels field, which forces a message to only use certain routes. + * You can define a list of which channels you want your message to use. + * Not defining any channels will be interpreted as allowing all channels. + * Note that for channels other than SMS, CM needs to configure the out going flows. For those flows to work, we need to be contacted. + * @param channels Define the list of which channels you want your message to use + * @return this builder, for chaining + */ + public MessageBuilder withAllowedChannels(Channel[] channels) { this.message.AllowedChannels = channels; return this; } - /// - /// Add a reference to the message. - /// - /// - /// - public MessageBuilder WithReference(String reference) + /** + * Add a reference to the message. + * @param reference the reference to use + * @return this builder, for chaining + */ + public MessageBuilder withReference(String reference) { this.message.Reference = reference; return this; } - /// - /// Adds a message that replaces the for channels that support - /// rich content (all channels except , - /// and at this moment) - /// - /// - /// - public MessageBuilder WithRichMessage(IRichMessage richMessage) + + /** + * Adds a message that replaces the body for channels that support rich content + * @param richMessage the rich message to add + * @return this builder, for chaining + */ + public MessageBuilder withRichMessage(IRichMessage richMessage) { if (this.richContent == null) this.richContent = new RichContent(); @@ -109,13 +117,12 @@ public MessageBuilder WithRichMessage(IRichMessage richMessage) return this; } - /// - /// Adds suggestions to the message. It is dependent on the channel that is used which - /// suggestions are supported. - /// - /// - /// - public MessageBuilder WithSuggestions(Suggestion[] suggestions) + /** + * Adds suggestions to the message. It is dependent on the channel that is used which suggestions are supported. + * @param suggestions suggestions to add + * @return this builder, for chaining + */ + public MessageBuilder withSuggestions(Suggestion[] suggestions) { if (this.richContent == null) this.richContent = new RichContent(); @@ -123,8 +130,14 @@ public MessageBuilder WithSuggestions(Suggestion[] suggestions) this.richContent.Suggestions = suggestions; return this; } - - public MessageBuilder WithTemplate(TemplateMessage template){ + + /** + * Adds a WhatsApp template message that replaces the body for WhatsApp messages + * please note that you need to have approved wa templates. + * @param template the template to add + * @return this builder, for chaining + */ + public MessageBuilder withTemplate(TemplateMessage template){ if (this.richContent == null) this.richContent = new RichContent(); @@ -132,12 +145,12 @@ public MessageBuilder WithTemplate(TemplateMessage template){ return this; } - /// - /// Add a custom DCS - /// - /// - /// - public MessageBuilder WithDcs(int dcs) + /** + * Adds a custom DCS + * @param dcs data coding scheme see Developer docs for more information + * @return this builder, for chaining + */ + public MessageBuilder withDcs(int dcs) { this.message.Dcs = dcs; return this; diff --git a/src/main/java/com/cm/text/MessagingClient.java b/src/main/java/com/cm/text/MessagingClient.java index da45589..f561e42 100644 --- a/src/main/java/com/cm/text/MessagingClient.java +++ b/src/main/java/com/cm/text/MessagingClient.java @@ -7,59 +7,73 @@ import com.google.gson.Gson; public class MessagingClient { - - private String productToken; - - + + /** + * Product token to use when sending a message + */ + private final String productToken; + + + /** + * Initializes a new instance of the class + * @param productToken The API key/product token to use + */ public MessagingClient( String productToken ) { this.productToken = productToken; } - - + + + /** + * Send a simple message + * @param messageText message content + * @param from sender id + * @param to recipient + * @return response message + */ public Response.HttpResponseBody sendTextMessage( String messageText, String from, String[] to ) { MessageBuilder builder = new MessageBuilder( messageText, from, to ); - Message message = builder.Build(); + Message message = builder.build(); String body = GetHttpPostBody( productToken, message ); - String result = HttpHelper.post( Config.ApiUrl, body ); + String result = HttpHelper.post( Config.BusinessMessagingApiUrl, body ); return getResponseBody( result ); } - - + + /** + * Sends the message towards an end user + * @param message the message to send + * @return message sending result + */ public Response.HttpResponseBody sendMessage( Message message ) { String body = GetHttpPostBody( productToken, message ); - String result = HttpHelper.post( Config.ApiUrl, body ); + String result = HttpHelper.post( Config.BusinessMessagingApiUrl, body ); return getResponseBody( result ); } - - - /// - /// Gets the HTTP post body. - /// - /// The API key. - /// The message to send. - /// + + /** + * Gets the HTTP post response as an object. + * @param body JSON input + * @return Result object + */ protected static Response.HttpResponseBody getResponseBody( String body ) { try { - Response.HttpResponseBody result = new Gson().fromJson( body, Response.HttpResponseBody.class ); - return result; + return new Gson().fromJson( body, Response.HttpResponseBody.class ); } catch ( Exception e ) { throw new RuntimeException( "Invalid json response-body", e ); } } - - - /// - /// Gets the HTTP post body. - /// - /// The API key. - /// The message to send. - /// + + /** + * Transforms the message into JSON + * @param productToken token to add to the JSON + * @param message content to send + * @return JSON body to send + */ protected static String GetHttpPostBody( String productToken, Message message ) { Request.Messages messages = new Request.Messages(); Request.MessagesEnvelope request = new Request.MessagesEnvelope(); diff --git a/src/main/java/com/cm/text/models/identity/OtpRequest.java b/src/main/java/com/cm/text/models/identity/OtpRequest.java index 6e0cf71..7ab70c3 100644 --- a/src/main/java/com/cm/text/models/identity/OtpRequest.java +++ b/src/main/java/com/cm/text/models/identity/OtpRequest.java @@ -3,75 +3,205 @@ import com.google.gson.annotations.SerializedName; public class OtpRequest { - /// - /// Required: This is the sender name. - /// The maximum length is 11 alphanumerical characters or 16 digits. Example: 'MyCompany' - /// - /*** */ - @SerializedName("from") - private String From; - - /// - /// Required: The destination mobile numbers. - /// This value should be in international format. - /// A single mobile number per request. Example: '00447911123456' - /// - [JsonPropertyName("to")] - public string To { get; set; } - - /// - /// The length of the code (min 4, max 10). default: 5. - /// - [JsonPropertyName("digits")] - [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public int? Digits { get; set; } - - /// - /// The expiry in seconds (min 10, max 3600). default: 60 seconds. - /// - [JsonPropertyName("expiry")] - [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public int? Expiry { get; set; } - - /// - /// The channel to send the code. - /// Supported values: auto, sms, push, whatsapp, voice, email. - /// Channel auto is only available with a SOLiD subscription. - /// - [JsonPropertyName("channel")] - public string Channel { get; set; } = "sms"; - - /// - /// The locale, for WhatsApp supported values: en, nl, fr, de, it, es. - /// Default: en - /// - /// For Voice: the spoken language in the voice call, - /// supported values: de-DE, en-AU, en-GB, en-IN, en-US, es-ES, fr-CA, fr-FR, it-IT, ja-JP, nl-NL - /// Default: en-GB. - /// - /// For Email: The locale for the email template. - /// - [JsonPropertyName("locale")] - [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - [CanBeNull] - public string Locale { get; set; } - - /// - /// The app key, when is 'push' - /// - [JsonPropertyName("pushAppKey")] - [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - [CanBeNull] - public string PushAppKey { get; set; } - - /// - /// For WhatsApp, set a custom message. You can use the placeholder {code}, this will be replaced by the actual code. - /// Example: Your code is: {code}. This is only used as a fallback in case the message could not be delivered via WhatsApp. - /// - /// For email, Set a custom message to be used in the email message. Do not include the {code} placeholder. - /// - [JsonPropertyName("message")] - [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - [CanBeNull] - public string Message { get; set; } + + /*** + * Required: This is the sender name. + * The maximum length is 11 alphanumerical characters or 16 digits. Example: 'MyCompany' + */ + @SerializedName("from") + private String from; + + /*** + * Required: The destination mobile numbers. + * This value should be in international format. + * A single mobile number per request. Example: '+316012345678' + */ + @SerializedName("to") + private String to; + + /** + * The length of the code (min 4, max 10). default: 5. + */ + @SerializedName("digits") + private Integer digits; + + /** + * The expiry in seconds (min 10, max 3600). default: 60 seconds. + */ + @SerializedName("expiry") + private Integer expiry; + + /** + * The channel to send the code. + * Supported values: auto, sms, push, whatsapp, voice, email. + * Channel auto is only available with a SOLiD subscription. + */ + @SerializedName("channel") + private String channel = "sms"; + + /** + * The locale, for WhatsApp supported values: en, nl, fr, de, it, es. + * Default: en + * For Voice: the spoken language in the voice call, + * supported values: de-DE, en-AU, en-GB, en-IN, en-US, es-ES, fr-CA, fr-FR, it-IT, ja-JP, nl-NL + * Default: en-GB. + * For Email: The locale for the email template. + */ + @SerializedName("locale") + public String locale; + + /** + * The app key, when Channel is 'push' + */ + @SerializedName("pushAppKey") + private String pushAppKey; + + /** + * For WhatsApp, set a custom message. You can use the placeholder {code}, this will be replaced by the actual code. + * Example: Your code is: {code}. This is only used as a fallback in case the message could not be delivered via WhatsApp. + * For email, Set a custom message to be used in the email message. Do not include the {code} placeholder. + */ + @SerializedName("message") + private String message; + + /** + * @return This is the sender name. + * The maximum length is 11 alphanumerical characters or 16 digits. Example: 'MyCompany' + */ + public String getFrom() { + return from; + } + + /** + * This is the sender name. + * @param from The maximum length is 11 alphanumerical characters or 16 digits. Example: 'MyCompany' + */ + public void setFrom(String from) { + this.from = from; + } + + /** + * + * @return The destination mobile number. + */ + public String getTo() { + return to; + } + + /** + * Required: The destination mobile number. + * This value should be in international format. single mobile number per request. Example: '+316012345678' + * @param to This value should be in international format. single mobile number per request. Example: '+316012345678' + */ + public void setTo(String to) { + this.to = to; + } + + /** + * @return The length of the code (min 4, max 10). default: 5. + */ + public Integer getDigits() { + return digits; + } + + /** + * @param digits The length of the code (min 4, max 10). default: 5. + */ + public void setDigits(Integer digits) { + this.digits = digits; + } + + /** + * @return The expiry in seconds (min 10, max 3600). default (when null): 60 seconds. + */ + public Integer getExpiry() { + return expiry; + } + + /** + * @param expiry The expiry in seconds (min 10, max 3600). (default: 60 seconds.) + */ + public void setExpiry(Integer expiry) { + this.expiry = expiry; + } + + /** + * The channel to send the code. + * Supported values: auto, sms, push, whatsapp, voice, email. + * Channel auto is only available with a SOLiD subscription. + * @return The channel to send the code + */ + public String getChannel() { + return channel; + } + + /** + * @param channel The channel to send the code. + * Supported values: auto, sms, push, whatsapp, voice, email. + * Channel auto is only available with a SOLiD subscription. + */ + public void setChannel(String channel) { + this.channel = channel; + } + + /** + * The locale, for WhatsApp supported values: en, nl, fr, de, it, es. + * Default: en + * For Voice: the spoken language in the voice call, + * supported values: de-DE, en-AU, en-GB, en-IN, en-US, es-ES, fr-CA, fr-FR, it-IT, ja-JP, nl-NL + * Default: en-GB. + * For Email: The locale for the email template. + * @return the locale + */ + public String getLocale() { + return locale; + } + + /** + * @param locale The locale, for WhatsApp supported values: en, nl, fr, de, it, es. + * Default: en + * For Voice: the spoken language in the voice call, + * supported values: de-DE, en-AU, en-GB, en-IN, en-US, es-ES, fr-CA, fr-FR, it-IT, ja-JP, nl-NL + * Default: en-GB. + * For Email: The locale for the email template. + */ + public void setLocale(String locale) { + this.locale = locale; + } + + /** + * @return The app key, when Channel is 'push' + */ + public String getPushAppKey() { + return pushAppKey; + } + + /** + * @param pushAppKey The app key, when Channel is 'push' + */ + public void setPushAppKey(String pushAppKey) { + this.pushAppKey = pushAppKey; + } + + /** + * For WhatsApp/SMS, set a custom message. You can use the placeholder {code}, this will be replaced by the actual code. + * Example: Your code is: {code}. This is only used as a fallback in case the message could not be delivered via WhatsApp. + * For email, Set a custom message to be used in the email message. Do not include the {code} placeholder + * @return the message + */ + public String getMessage() { + return message; + } + + /** + * For WhatsApp/SMS, set a custom message. You can use the placeholder {code}, this will be replaced by the actual code. + * Example: Your code is: {code}. This is only used as a fallback in case the message could not be delivered via WhatsApp. + * For email, Set a custom message to be used in the email message. Do not include the {code} placeholder. + * @param message the custom message + */ + public void setMessage(String message) { + this.message = message; + } + + } diff --git a/src/main/java/com/cm/text/utils/HttpHelper.java b/src/main/java/com/cm/text/utils/HttpHelper.java index 997e8b9..b257f18 100644 --- a/src/main/java/com/cm/text/utils/HttpHelper.java +++ b/src/main/java/com/cm/text/utils/HttpHelper.java @@ -7,7 +7,24 @@ import java.nio.charset.StandardCharsets; public class HttpHelper { - private static String sendRequest( String method, String url, String data ) { + + /** + * Used to send the HTTP request + * @param url url to send data to + * @param data data to be sent, as JSON + * @return the response (when successful) + */ + private static String sendRequest( String url, String data ) { + return sendRequest(url, data, null); + } + /** + * Used to send the HTTP request + * @param url url to send data to + * @param data data to be sent, as JSON + * @param productTokenHeader when set: X-CM-ProductToken header + * @return the response (when successful) + */ + private static String sendRequest( String url, String data, String productTokenHeader ) { HttpURLConnection conn = null; try { @@ -15,9 +32,12 @@ private static String sendRequest( String method, String url, String data ) { conn = (HttpURLConnection) obj.openConnection(); //add request header - conn.setRequestMethod( method ); + conn.setRequestMethod("POST"); conn.setRequestProperty( "Content-Type", "application/json" ); + if (productTokenHeader != null) { + conn.setRequestProperty("X-CM-ProductToken", productTokenHeader); + } if ( data != null ) { // Send request @@ -46,9 +66,15 @@ private static String sendRequest( String method, String url, String data ) { } } } - - // HTTP POST request + + + /** + * HTTP POST request + * @param url url to send to + * @param urlParameters parameters to use + * @return JSON result + */ public static String post( String url, String urlParameters ) { - return sendRequest( "POST", url, urlParameters ); + return sendRequest(url, urlParameters ); } } From 3b0c9752e1bb514428f7d40eefb974294430c6f0 Mon Sep 17 00:00:00 2001 From: Bas Gijzen Date: Tue, 9 Jan 2024 11:57:23 +0100 Subject: [PATCH 03/15] In progress: using Java style comments, encapsulation and method names --- .../cm/text/models/multichannel/Carousel.java | 54 +++++++-- .../multichannel/CarouselCardWidth.java | 15 ++- .../com/cm/text/models/multichannel/Dial.java | 23 +++- .../models/multichannel/DialSuggestion.java | 41 +++++-- .../models/multichannel/IRichMessage.java | 3 + .../models/multichannel/MediaContent.java | 108 +++++++++++++----- .../models/multichannel/MediaMessage.java | 49 +++++--- .../multichannel/OpenUrlSuggestion.java | 2 +- .../models/multichannel/ReplySuggestion.java | 2 +- .../text/models/multichannel/Suggestion.java | 2 +- .../multichannel/ViewLocationSuggestion.java | 2 +- 11 files changed, 224 insertions(+), 77 deletions(-) diff --git a/src/main/java/com/cm/text/models/multichannel/Carousel.java b/src/main/java/com/cm/text/models/multichannel/Carousel.java index 480d910..07c1ff3 100644 --- a/src/main/java/com/cm/text/models/multichannel/Carousel.java +++ b/src/main/java/com/cm/text/models/multichannel/Carousel.java @@ -3,15 +3,49 @@ import com.google.gson.annotations.SerializedName; public class Carousel { - /// - /// The cards of the carousel - /// - @SerializedName("cards") - public RichCard[] Cards; - - /// - /// The width for the items of the carousel - /// + + /** + * The cards of the carousel + */ + @SerializedName("cards") + private RichCard[] cards; + + /** + * The width for the items of the carousel + */ @SerializedName("cardWidth") - public CarouselCardWidth CarouselCardWidth; + private CarouselCardWidth carouselCardWidth; + + /** + * + * @return The cards of the carousel + */ + public RichCard[] getCards() { + return cards; + } + + /** + * + * @param cards The cards of the carousel + */ + public void setCards(RichCard[] cards) { + this.cards = cards; + } + + /** + * + * @return The width for the items of the carousel + */ + public CarouselCardWidth getCarouselCardWidth() { + return carouselCardWidth; + } + + /** + * + * @param carouselCardWidth The width for the items of the carousel + */ + public void setCarouselCardWidth(CarouselCardWidth carouselCardWidth) { + this.carouselCardWidth = carouselCardWidth; + } + } diff --git a/src/main/java/com/cm/text/models/multichannel/CarouselCardWidth.java b/src/main/java/com/cm/text/models/multichannel/CarouselCardWidth.java index 6dafd9e..e98ead7 100644 --- a/src/main/java/com/cm/text/models/multichannel/CarouselCardWidth.java +++ b/src/main/java/com/cm/text/models/multichannel/CarouselCardWidth.java @@ -1,13 +1,16 @@ package com.cm.text.models.multichannel; +/** + * Used to define how a carousel should look luike + */ public enum CarouselCardWidth { - /// - /// Small cards - /// + /** + * Small + */ Small, - /// - /// Medium sized cards - /// + /** + * Medium-sized cards + */ Medium } diff --git a/src/main/java/com/cm/text/models/multichannel/Dial.java b/src/main/java/com/cm/text/models/multichannel/Dial.java index 07a0d5d..1b42213 100644 --- a/src/main/java/com/cm/text/models/multichannel/Dial.java +++ b/src/main/java/com/cm/text/models/multichannel/Dial.java @@ -3,9 +3,24 @@ import com.google.gson.annotations.SerializedName; public class Dial { - /// - /// The number to call (in international format) - /// + /** + * The number to call (in international format) + */ @SerializedName("phoneNumber") - public String PhoneNumber; + private String phoneNumber; + + /** + * + * @return The number to call (in international format) + */ + public String getPhoneNumber() { + return phoneNumber; + } + + /** + * @param phoneNumber The number to call (in international format) + */ + public void setPhoneNumber(String phoneNumber) { + this.phoneNumber = phoneNumber; + } } diff --git a/src/main/java/com/cm/text/models/multichannel/DialSuggestion.java b/src/main/java/com/cm/text/models/multichannel/DialSuggestion.java index 04b2010..98e1cd4 100644 --- a/src/main/java/com/cm/text/models/multichannel/DialSuggestion.java +++ b/src/main/java/com/cm/text/models/multichannel/DialSuggestion.java @@ -2,21 +2,40 @@ import com.google.gson.annotations.SerializedName; -/// -/// A suggestion, used in -/// When you want to enable the user can call you, or listen to a recorded spoken message, -/// this suggestion can be applied. When clicked starts a new call. -/// +/** + * A suggestion, used in RCS When you want to enable the user can call you, or listen to a recorded spoken message, + * this suggestion can be applied. When clicked starts a new call. + */ public class DialSuggestion extends Suggestion { - /// - /// The dial options - /// + /** + * The dial options + */ @SerializedName("dial") - public Dial Dial; + private Dial dial; + /** + * + * @param dial The dial options to use + */ public DialSuggestion(Dial dial) { - this.Action = "reply"; - this.Dial = dial; + this.action = "reply"; + this.dial = dial; } + + /** + * + * @return The dial options + */ + public Dial getDial() { + return dial; + } + + /** + * @param dial The dial options + */ + public void setDial(Dial dial) { + this.dial = dial; + } + } diff --git a/src/main/java/com/cm/text/models/multichannel/IRichMessage.java b/src/main/java/com/cm/text/models/multichannel/IRichMessage.java index d5c7f65..ff7782c 100644 --- a/src/main/java/com/cm/text/models/multichannel/IRichMessage.java +++ b/src/main/java/com/cm/text/models/multichannel/IRichMessage.java @@ -1,4 +1,7 @@ package com.cm.text.models.multichannel; +/** + * Implemented by several types of rich message + */ public interface IRichMessage { } diff --git a/src/main/java/com/cm/text/models/multichannel/MediaContent.java b/src/main/java/com/cm/text/models/multichannel/MediaContent.java index 5386dfc..011a343 100644 --- a/src/main/java/com/cm/text/models/multichannel/MediaContent.java +++ b/src/main/java/com/cm/text/models/multichannel/MediaContent.java @@ -1,39 +1,93 @@ package com.cm.text.models.multichannel; +/** + * Content of one media item (such as an image or a video) + */ public class MediaContent { - /// - /// The name of the image, audio or video. - /// - public String MediaName; - - /// - /// The location of the image, audio or video. - /// - public String MediaUri; - - /// - /// The mimetype of the image, audio or video. - /// - public String MimeType; - - /// - /// Default constructor - /// + + /** + * The name of the image, audio or video. + */ + private String mediaName; + + /** + * The location of the image, audio or video. + */ + private String mediaUri; + + /** + * The mimetype of the image, audio or video. + */ + private String mimeType; + + /** + * Default constructor + */ public MediaContent() { } - /// - /// Constructor which sets values - /// - /// - /// - /// + + + /** + * Constructor which initializes values + * @param mediaName The name of the image, audio or video. + * @param mediaUri The location of the image, audio or video. + * @param mimeType The mimetype of the image, audio or video. + */ public MediaContent(String mediaName, String mediaUri, String mimeType) { - this.MediaName = mediaName; - this.MediaUri = mediaUri; - this.MimeType = mimeType; + this.mediaName = mediaName; + this.mediaUri = mediaUri; + this.mimeType = mimeType; + } + + /** + * + * @return The name of the image, audio or video. + */ + public String getMediaName() { + return mediaName; + } + + /** + * + * @param mediaName The name of the image, audio or video. + */ + public void setMediaName(String mediaName) { + this.mediaName = mediaName; + } + + /** + * + * @return The location of the image, audio or video. + */ + public String getMediaUri() { + return mediaUri; + } + + /** + * + * @param mediaUri The location of the image, audio or video. + */ + public void setMediaUri(String mediaUri) { + this.mediaUri = mediaUri; + } + + /** + * + * @return The mimetype of the image, audio or video. + */ + public String getMimeType() { + return mimeType; + } + + /** + * + * @param mimeType The mimetype of the image, audio or video. + */ + public void setMimeType(String mimeType) { + this.mimeType = mimeType; } } diff --git a/src/main/java/com/cm/text/models/multichannel/MediaMessage.java b/src/main/java/com/cm/text/models/multichannel/MediaMessage.java index 00884b9..3c776fd 100644 --- a/src/main/java/com/cm/text/models/multichannel/MediaMessage.java +++ b/src/main/java/com/cm/text/models/multichannel/MediaMessage.java @@ -2,28 +2,47 @@ import com.google.gson.annotations.SerializedName; +/** + * Class describing a media message (such as an image or video) + */ public class MediaMessage implements IRichMessage { - /// - /// Default constructor. - /// + /** + * The image or video of the message. + */ + @SerializedName("media") + private MediaContent media; + + /** + * Default constructor + */ public MediaMessage() { } - /// - /// Constructor setting values. - /// - /// - /// - /// + /** + * Constructor setting values. + * @param mediaName The name of the image, audio or video. + * @param mediaUri The location of the image, audio or video. + * @param mimeType The mimetype of the image, audio or video. + */ public MediaMessage(String mediaName, String mediaUri, String mimeType) { - this.Media = new MediaContent(mediaName, mediaUri, mimeType); + this.media = new MediaContent(mediaName, mediaUri, mimeType); } - /// - /// The image or video of the message. - /// - @SerializedName("media") - public MediaContent Media; + /** + * + * @return The image or video of the message. + */ + public MediaContent getMedia() { + return media; + } + + /** + * + * @param media The image or video of the message. + */ + public void setMedia(MediaContent media) { + this.media = media; + } } diff --git a/src/main/java/com/cm/text/models/multichannel/OpenUrlSuggestion.java b/src/main/java/com/cm/text/models/multichannel/OpenUrlSuggestion.java index cb28fcc..f7c6845 100644 --- a/src/main/java/com/cm/text/models/multichannel/OpenUrlSuggestion.java +++ b/src/main/java/com/cm/text/models/multichannel/OpenUrlSuggestion.java @@ -12,7 +12,7 @@ public class OpenUrlSuggestion extends Suggestion { public OpenUrlSuggestion( String label, String url) { - this.Action = "openUrl"; + this.action = "openUrl"; this.Label = label; this.Url = url; } diff --git a/src/main/java/com/cm/text/models/multichannel/ReplySuggestion.java b/src/main/java/com/cm/text/models/multichannel/ReplySuggestion.java index b8d06e0..0613a3b 100644 --- a/src/main/java/com/cm/text/models/multichannel/ReplySuggestion.java +++ b/src/main/java/com/cm/text/models/multichannel/ReplySuggestion.java @@ -12,7 +12,7 @@ public class ReplySuggestion extends Suggestion { public String PostbackData; public ReplySuggestion(String postbackData) { - this.Action = "reply"; + this.action = "reply"; this.PostbackData = postbackData; } } diff --git a/src/main/java/com/cm/text/models/multichannel/Suggestion.java b/src/main/java/com/cm/text/models/multichannel/Suggestion.java index 7cf75b3..6539735 100644 --- a/src/main/java/com/cm/text/models/multichannel/Suggestion.java +++ b/src/main/java/com/cm/text/models/multichannel/Suggestion.java @@ -8,7 +8,7 @@ public abstract class Suggestion { /// The action of this suggestion /// @SerializedName("action") - public String Action; + protected String action; /// /// The text the end user will see diff --git a/src/main/java/com/cm/text/models/multichannel/ViewLocationSuggestion.java b/src/main/java/com/cm/text/models/multichannel/ViewLocationSuggestion.java index d3240a5..1ad638c 100644 --- a/src/main/java/com/cm/text/models/multichannel/ViewLocationSuggestion.java +++ b/src/main/java/com/cm/text/models/multichannel/ViewLocationSuggestion.java @@ -12,7 +12,7 @@ public class ViewLocationSuggestion extends Suggestion { private ViewLocationOptions locationOptions; public ViewLocationSuggestion(ViewLocationOptions locationOptions) { - this.Action = "CreateCalendarEvent"; + this.action = "CreateCalendarEvent"; this.locationOptions = locationOptions; } } From 7eed1aabf3c2f09ed5f8a3dc9deb65394a581431 Mon Sep 17 00:00:00 2001 From: Bas Gijzen Date: Tue, 9 Jan 2024 12:13:12 +0100 Subject: [PATCH 04/15] In progress: using Java style comments, encapsulation and method names (also fixing suggestion actions) --- src/main/java/com/cm/text/MessageBuilder.java | 2 +- .../models/multichannel/DialSuggestion.java | 4 +- .../multichannel/OpenUrlSuggestion.java | 35 +++++- .../models/multichannel/ReplySuggestion.java | 30 ++++- .../cm/text/models/multichannel/RichCard.java | 48 ++++++-- .../text/models/multichannel/RichContent.java | 95 ++++++++++------ .../text/models/multichannel/Suggestion.java | 36 ++++-- .../text/models/multichannel/TextMessage.java | 46 +++++--- .../multichannel/ViewLocationOptions.java | 104 ++++++++++++++---- .../multichannel/ViewLocationSuggestion.java | 32 +++++- 10 files changed, 327 insertions(+), 105 deletions(-) diff --git a/src/main/java/com/cm/text/MessageBuilder.java b/src/main/java/com/cm/text/MessageBuilder.java index 24bb2aa..29eb097 100644 --- a/src/main/java/com/cm/text/MessageBuilder.java +++ b/src/main/java/com/cm/text/MessageBuilder.java @@ -127,7 +127,7 @@ public MessageBuilder withSuggestions(Suggestion[] suggestions) if (this.richContent == null) this.richContent = new RichContent(); - this.richContent.Suggestions = suggestions; + this.richContent.setSuggestions(suggestions); return this; } diff --git a/src/main/java/com/cm/text/models/multichannel/DialSuggestion.java b/src/main/java/com/cm/text/models/multichannel/DialSuggestion.java index 98e1cd4..9bb12ad 100644 --- a/src/main/java/com/cm/text/models/multichannel/DialSuggestion.java +++ b/src/main/java/com/cm/text/models/multichannel/DialSuggestion.java @@ -19,8 +19,8 @@ public class DialSuggestion extends Suggestion { * @param dial The dial options to use */ public DialSuggestion(Dial dial) { - this.action = "reply"; - this.dial = dial; + this.action = "dial"; + this.dial = dial; } /** diff --git a/src/main/java/com/cm/text/models/multichannel/OpenUrlSuggestion.java b/src/main/java/com/cm/text/models/multichannel/OpenUrlSuggestion.java index f7c6845..878e14d 100644 --- a/src/main/java/com/cm/text/models/multichannel/OpenUrlSuggestion.java +++ b/src/main/java/com/cm/text/models/multichannel/OpenUrlSuggestion.java @@ -2,19 +2,42 @@ import com.google.gson.annotations.SerializedName; +/** + * Suggestion for opening an url + */ public class OpenUrlSuggestion extends Suggestion { - /// - /// The url of this suggestion - /// + /** + * The url of this suggestion + */ @SerializedName("url") - public String Url; + private String url; + /** + * Constructor initializing this suggestion + * @param label the label to show + * @param url url to open + */ public OpenUrlSuggestion( String label, String url) { this.action = "openUrl"; - this.Label = label; - this.Url = url; + this.label = label; + this.url = url; } + /** + * + * @return The url of this suggestion + */ + public String getUrl() { + return url; + } + + /** + * + * @param url The url of this suggestion + */ + public void setUrl(String url) { + this.url = url; + } } diff --git a/src/main/java/com/cm/text/models/multichannel/ReplySuggestion.java b/src/main/java/com/cm/text/models/multichannel/ReplySuggestion.java index 0613a3b..9111642 100644 --- a/src/main/java/com/cm/text/models/multichannel/ReplySuggestion.java +++ b/src/main/java/com/cm/text/models/multichannel/ReplySuggestion.java @@ -2,17 +2,35 @@ import com.google.gson.annotations.SerializedName; +/** + * Suggestion to reply with a certain text + */ public class ReplySuggestion extends Suggestion { - /// - /// When the item is selected and the postback data is set, then the Postback data will be - /// sent in a MO instead of the . - /// + /** + * When the item is selected and the postback data is set, then the Postback data will be sent in a MO instead of the label + */ @SerializedName("postbackData") - public String PostbackData; + private String postbackData; public ReplySuggestion(String postbackData) { this.action = "reply"; - this.PostbackData = postbackData; + this.postbackData = postbackData; + } + + /** + * + * @return When the item is selected and the postback data is set, then the Postback data will be sent in a MO instead of the label + */ + public String getPostbackData() { + return postbackData; + } + + /** + * + * @param postbackData When the item is selected and the postback data is set, then the Postback data will be sent in a MO instead of the label + */ + public void setPostbackData(String postbackData) { + this.postbackData = postbackData; } } diff --git a/src/main/java/com/cm/text/models/multichannel/RichCard.java b/src/main/java/com/cm/text/models/multichannel/RichCard.java index 69e27c0..9bd7696 100644 --- a/src/main/java/com/cm/text/models/multichannel/RichCard.java +++ b/src/main/java/com/cm/text/models/multichannel/RichCard.java @@ -3,15 +3,47 @@ import com.google.gson.annotations.SerializedName; public class RichCard extends TextMessage{ - // - /// Optional: the header for a rich card - /// + /** + * Optional: the header for a rich card + */ @SerializedName("header") - public String Header; + private String header; - /// - /// The image or video of the card. - /// + /** + * The image or video of the card. + */ @SerializedName("media") - public MediaContent Media; + private MediaContent media; + + /** + * + * @return the header for a rich card + */ + public String getHeader() { + return header; + } + + /** + * + * @param header the header for a rich card + */ + public void setHeader(String header) { + this.header = header; + } + + /** + * + * @return The image or video of the card. + */ + public MediaContent getMedia() { + return media; + } + + /** + * + * @param media The image or video of the card. + */ + public void setMedia(MediaContent media) { + this.media = media; + } } diff --git a/src/main/java/com/cm/text/models/multichannel/RichContent.java b/src/main/java/com/cm/text/models/multichannel/RichContent.java index a67b7ec..95cb1ac 100644 --- a/src/main/java/com/cm/text/models/multichannel/RichContent.java +++ b/src/main/java/com/cm/text/models/multichannel/RichContent.java @@ -5,58 +5,83 @@ import java.util.Arrays; public class RichContent { - /// - /// Initializes a rich content object - /// - public RichContent() - { - this.Conversation = null; - this.Suggestions = null; - } - /// - /// The messages. - /// + /** + * The messages + */ @SerializedName("conversation") - public IRichMessage[] Conversation ; + private IRichMessage[] conversation; - /// - /// The suggestions - /// + /** + * The suggestions + */ @SerializedName("suggestions") - public Suggestion[] Suggestions; + private Suggestion[] suggestions; + + /** + * Initializes the rich content + */ + public RichContent() + { + this.conversation = null; + this.suggestions = null; + } - /// - /// Adds a message, such as a or . - /// - /// + /** + * Adds a message, such as a RichCard or TextMessage + * @param part the message to add + */ public void AddConversationPart(IRichMessage part) { - if (this.Conversation == null) - this.Conversation = new IRichMessage[] {part}; + if (this.conversation == null) + this.conversation = new IRichMessage[] {part}; else { - IRichMessage[] newArr = this.Conversation; - newArr = Arrays.copyOf(newArr, this.Conversation.length + 1 ); + IRichMessage[] newArr = this.conversation; + newArr = Arrays.copyOf(newArr, this.conversation.length + 1 ); newArr[newArr.length - 1] = part; - this.Conversation = newArr; + this.conversation = newArr; } } - /// - /// Adds a suggestion - /// - /// - public void AddSuggestion(Suggestion suggestion) + /** + * Adds a suggestion + * @param suggestion the suggestion to add + */ + public void addSuggestion(Suggestion suggestion) { - if (this.Suggestions == null) - this.Suggestions = new Suggestion[] {suggestion}; + if (this.suggestions == null) + this.suggestions = new Suggestion[] {suggestion}; else { - Suggestion[] newArr = this.Suggestions; - newArr = Arrays.copyOf(newArr, this.Suggestions.length + 1 ); + Suggestion[] newArr = this.suggestions; + newArr = Arrays.copyOf(newArr, this.suggestions.length + 1 ); newArr[newArr.length - 1] = suggestion; - this.Suggestions = newArr; + this.suggestions = newArr; } } + + /** + * The messages + * @return The messages + */ + public IRichMessage[] getConversation() { + return conversation; + } + + /** + * The suggestions + * @return The suggestions + */ + public Suggestion[] getSuggestions() { + return suggestions; + } + + /** + * + * @param suggestions The suggestions to use + */ + public void setSuggestions(Suggestion[] suggestions) { + this.suggestions = suggestions; + } } diff --git a/src/main/java/com/cm/text/models/multichannel/Suggestion.java b/src/main/java/com/cm/text/models/multichannel/Suggestion.java index 6539735..ff38e5f 100644 --- a/src/main/java/com/cm/text/models/multichannel/Suggestion.java +++ b/src/main/java/com/cm/text/models/multichannel/Suggestion.java @@ -2,17 +2,37 @@ import com.google.gson.annotations.SerializedName; - +/** + * A suggestion represents one option which the end user can use. + */ public abstract class Suggestion { - /// - /// The action of this suggestion - /// + + /** + * The action of this suggestion + */ @SerializedName("action") protected String action; - /// - /// The text the end user will see - /// + /** + * The text the end user will see + */ @SerializedName("label") - public String Label; + protected String label; + + + /** + * + * @return The text the end user will see + */ + public String getLabel() { + return label; + } + + /** + * + * @param label The text the end user will see + */ + public void setLabel(String label) { + this.label = label; + } } diff --git a/src/main/java/com/cm/text/models/multichannel/TextMessage.java b/src/main/java/com/cm/text/models/multichannel/TextMessage.java index 9431049..e5f5e56 100644 --- a/src/main/java/com/cm/text/models/multichannel/TextMessage.java +++ b/src/main/java/com/cm/text/models/multichannel/TextMessage.java @@ -2,26 +2,46 @@ import com.google.gson.annotations.SerializedName; +/** + * A simple text message to send + */ public class TextMessage implements IRichMessage{ - /// - /// Construct an empty text message. - /// + + /** + * The text to display. + */ + @SerializedName("text") + private String text; + + /** + * Construct an empty text message. + */ public TextMessage() { } - /// - /// Construct a text message and initialise the - /// - /// + /** + * Constructs the message with the text + * @param text text for the end user + */ public TextMessage(String text) { - this.Text = text; + this.text = text; } - /// - /// The text to display. - /// - @SerializedName("text") - public String Text; + /** + * + * @return The text to display. + */ + public String getText() { + return text; + } + + /** + * + * @param text The text to display. + */ + public void setText(String text) { + this.text = text; + } } diff --git a/src/main/java/com/cm/text/models/multichannel/ViewLocationOptions.java b/src/main/java/com/cm/text/models/multichannel/ViewLocationOptions.java index fffcbae..e392175 100644 --- a/src/main/java/com/cm/text/models/multichannel/ViewLocationOptions.java +++ b/src/main/java/com/cm/text/models/multichannel/ViewLocationOptions.java @@ -2,34 +2,96 @@ import com.google.gson.annotations.SerializedName; +/** + * Displays a location + */ public class ViewLocationOptions { - /// - /// Optional: The label to display at the pin - /// + /** + * Optional: The label to display at the pin + */ @SerializedName("label") - public String Label; + private String label; - /// - /// The latitude in degrees - /// - /// 51.603802 - /// Either Latitude and or is required + /** + * The latitude in degrees + */ @SerializedName("latitude") - public String Latitude; + private String latitude; - /// - /// The longitude in degrees - /// - /// 4.770821 - /// Either and Longitude or is required + /** + * The longitude in degrees + */ @SerializedName("longitude") - public String Longitude; + private String longitude; - /// - /// Search for this location instead of using the latitude/longitude. - /// - /// Either and or SearchQuery is required + /** + * Search for this location instead of using the latitude/longitude. + */ @SerializedName("searchQuery") - public String SearchQuery; + private String searchQuery; + + /** + * + * @return The label to display at the pin + */ + public String getLabel() { + return label; + } + + /** + * + * @param label Optional: The label to display at the pin + */ + public void setLabel(String label) { + this.label = label; + } + + /** + * + * @return The latitude in degrees + */ + public String getLatitude() { + return latitude; + } + + /** + * + * @param latitude The latitude in degrees + */ + public void setLatitude(String latitude) { + this.latitude = latitude; + } + + /** + * + * @return The longitude in degrees + */ + public String getLongitude() { + return longitude; + } + + /** + * + * @param longitude The longitude in degrees + */ + public void setLongitude(String longitude) { + this.longitude = longitude; + } + + /** + * + * @return Search for this location instead of using the latitude/longitude + */ + public String getSearchQuery() { + return searchQuery; + } + + /** + * + * @param searchQuery Search for this location instead of using the latitude/longitude + */ + public void setSearchQuery(String searchQuery) { + this.searchQuery = searchQuery; + } } diff --git a/src/main/java/com/cm/text/models/multichannel/ViewLocationSuggestion.java b/src/main/java/com/cm/text/models/multichannel/ViewLocationSuggestion.java index 1ad638c..3c61ff2 100644 --- a/src/main/java/com/cm/text/models/multichannel/ViewLocationSuggestion.java +++ b/src/main/java/com/cm/text/models/multichannel/ViewLocationSuggestion.java @@ -2,17 +2,39 @@ import com.google.gson.annotations.SerializedName; +/** + * Suggestion to open a map with a specific location + */ public class ViewLocationSuggestion extends Suggestion { - - /// - /// The location options - /// + /** + * The location options + */ @SerializedName("location") private ViewLocationOptions locationOptions; + /** + * Constructor setting the location + * @param locationOptions the location to display + */ public ViewLocationSuggestion(ViewLocationOptions locationOptions) { - this.action = "CreateCalendarEvent"; + this.action = "viewLocation"; + this.locationOptions = locationOptions; + } + + /** + * + * @return The location options + */ + public ViewLocationOptions getLocationOptions() { + return locationOptions; + } + + /** + * + * @param locationOptions The location options + */ + public void setLocationOptions(ViewLocationOptions locationOptions) { this.locationOptions = locationOptions; } } From c267707b0552c19879c3bfb531b128ffcbbf4d76 Mon Sep 17 00:00:00 2001 From: Bas Gijzen Date: Tue, 9 Jan 2024 12:24:17 +0100 Subject: [PATCH 05/15] In progress: using Java style comments, encapsulation and method names (also fixing suggestion actions) --- src/main/java/com/cm/text/models/Body.java | 122 +++++++++++++--- src/main/java/com/cm/text/models/Channel.java | 131 ++++++++---------- 2 files changed, 160 insertions(+), 93 deletions(-) diff --git a/src/main/java/com/cm/text/models/Body.java b/src/main/java/com/cm/text/models/Body.java index 7d1d5a6..3861565 100644 --- a/src/main/java/com/cm/text/models/Body.java +++ b/src/main/java/com/cm/text/models/Body.java @@ -2,14 +2,17 @@ import com.google.gson.annotations.SerializedName; +/** + * The body of the message + */ public class Body { /*** * The actual text body of the message. - * By default the CM gateway interprets messages as if sent with the standard 7 bit GSM encoding. + * By default, the CM gateway interprets messages as if sent with the standard 7 bit GSM encoding. * If you want to send messages using e.g. Arabic, Cyrillic of Greek characters * you will need to use the unicode UCS2 encoding. - * Set the to Auto to let the gateway do the encoding detection. + * Set the type to Auto to let the gateway do the encoding detection. * Please note that there are a few limitations to using unicode encoded messages: * Unicode messages can contain up to 70 characters. In the case of multipart messages, this becomes 66 characters per * part. @@ -18,26 +21,109 @@ public class Body { * for which operators it works. */ @SerializedName("content") - public String Content; - - /// - /// When the type is set to 'auto' then the gateway will do the encoding detection. - /// In case it detects characters that are not part of the GSM character set, - /// the message will be delivered as Unicode. - /// If the message contains more than 70 characters in Unicode format it will be split into a - /// multipart message. - /// You can limit the number of parts by setting the maximum number of message parts. - /// - /// + private String content; + + /** + * When the type is set to 'auto' then the gateway will do the encoding detection. + * In case it detects characters that are not part of the GSM character set, + * the message will be delivered as Unicode. + * If the message contains more than 70 characters in Unicode format it will be split into a + * multipart message. + * You can limit the number of parts by setting the maximum number of message parts. + */ @SerializedName("type") - public String Type; + private String type; + /** + * + * @param content The actual text body of the message. + * By default, the CM gateway interprets messages as if sent with the standard 7 bit GSM encoding. + * If you want to send messages using e.g. Arabic, Cyrillic of Greek characters + * you will need to use the unicode UCS2 encoding. + * Set the type to Auto to let the gateway do the encoding detection. + * Please note that there are a few limitations to using unicode encoded messages: + * Unicode messages can contain up to 70 characters. In the case of multipart messages, this becomes 66 characters per + * part. + */ public Body(String content) { - this.Content = content; + this.content = content; } - + + /** + * + * @param content The actual text body of the message. + * By default, the CM gateway interprets messages as if sent with the standard 7 bit GSM encoding. + * If you want to send messages using e.g. Arabic, Cyrillic of Greek characters + * you will need to use the unicode UCS2 encoding. + * Set the type to Auto to let the gateway do the encoding detection. + * Please note that there are a few limitations to using unicode encoded messages: + * Unicode messages can contain up to 70 characters. In the case of multipart messages, this becomes 66 characters per + * part. + * @param type When the type is set to 'auto' then the gateway will do the encoding detection. + * In case it detects characters that are not part of the GSM character set, + * the message will be delivered as Unicode. + * If the message contains more than 70 characters in Unicode format it will be split into a + * multipart message. + * You can limit the number of parts by setting the maximum number of message parts. + */ public Body(String content, String type) { - this.Content = content; - this.Type = type; + this.content = content; + this.type = type; + } + + /** + * + * @return The actual text body of the message. + * By default, the CM gateway interprets messages as if sent with the standard 7 bit GSM encoding. + * If you want to send messages using e.g. Arabic, Cyrillic of Greek characters + * you will need to use the unicode UCS2 encoding. + * Set the type to Auto to let the gateway do the encoding detection. + * Please note that there are a few limitations to using unicode encoded messages: + * Unicode messages can contain up to 70 characters. In the case of multipart messages, this becomes 66 characters per + * part. + */ + public String getContent() { + return content; + } + + /** + * + * @param content The actual text body of the message. + * By default, the CM gateway interprets messages as if sent with the standard 7 bit GSM encoding. + * If you want to send messages using e.g. Arabic, Cyrillic of Greek characters + * you will need to use the unicode UCS2 encoding. + * Set the type to Auto to let the gateway do the encoding detection. + * Please note that there are a few limitations to using unicode encoded messages: + * Unicode messages can contain up to 70 characters. In the case of multipart messages, this becomes 66 characters per + * part. + */ + public void setContent(String content) { + this.content = content; + } + + /** + * + * @return When the type is set to 'auto' then the gateway will do the encoding detection. + * In case it detects characters that are not part of the GSM character set, + * the message will be delivered as Unicode. + * If the message contains more than 70 characters in Unicode format it will be split into a + * multipart message. + * You can limit the number of parts by setting the maximum number of message parts. + */ + public String getType() { + return type; + } + + /** + * + * @param type When the type is set to 'auto' then the gateway will do the encoding detection. + * In case it detects characters that are not part of the GSM character set, + * the message will be delivered as Unicode. + * If the message contains more than 70 characters in Unicode format it will be split into a + * multipart message. + * You can limit the number of parts by setting the maximum number of message parts. + */ + public void setType(String type) { + this.type = type; } } diff --git a/src/main/java/com/cm/text/models/Channel.java b/src/main/java/com/cm/text/models/Channel.java index cab52f7..3643805 100644 --- a/src/main/java/com/cm/text/models/Channel.java +++ b/src/main/java/com/cm/text/models/Channel.java @@ -2,108 +2,89 @@ import com.google.gson.annotations.SerializedName; -public enum Channel { - /// - /// Messages will be sent as SMS text messages - /// +/** + * Represents a Channel to use when sending messages + */ +public enum Channel { + + /** + * Messages will be sent as SMS text messages + */ SMS, - /// - /// Send messages using WhatsApp for business - /// - /// - /// Note that CM needs to configure this for you to work. - /// + /** + * Send messages using WhatsApp for business. + * Note that a WhatsApp profile at CM.com is required + */ WhatsApp, - - /// - /// Sends messages to push using Hybrid messages. - /// See also https://developers.cm.com/messaging - /// - /// Works only when is set - Push, - - /// - /// Messages will be sent over RCS. - /// - /// - /// Note that CM needs to configure this for you to work. - /// + /** + * Messages will be sent over RCS. + * Note that CM.Com needs to configure this for you to work + */ RCS, - /// - /// Messages will be sent over Viber. - /// - /// - /// Note that CM needs to configure this for you to work. - /// + /** + * Messages will be sent over Viber. + * Note that CM.Com needs to configure this for you to work. + */ Viber, - /// - /// Messages will be sent using text to speech. - /// - /// - /// Note that CM needs to configure this for you to work. - /// + /** + * Messages will be sent using text to speech. + * Note that CM.Com needs to configure this for you to work. + */ Voice, - /// - /// Messages will be sent over Apple Business Chat. - /// - /// - /// Note that CM needs to configure this for you to work. - /// - // ReSharper disable once InconsistentNaming - iMessage, + /** + * Messages will be sent over Apple Messages for Business. + * Note that CM.Com needs to configure this for you to work. + */ + @SerializedName("Apple Messages for Business") + AppleMessagesForBusiness, /// /// Messages will be sent over Line. /// /// - /// Note that CM needs to configure this for you to work. + /// Note that CM.Com needs to configure this for you to work. /// + /** + * Messages will be sent over Line. + * Note that CM.Com needs to configure this for you to work. + */ Line, - /// - /// Messages will be sent over Twitter. - /// - /// - /// Note that CM needs to configure this for you to work. - /// + + /** + * Messages will be sent over Twitter. + * Note that CM.Com needs to configure this for you to work. + */ Twitter, - /// - /// Messages will be sent over MobilePush. - /// - /// - /// This channel is the successor of the "Push" channel. - /// Contact CM for information on how to migrate your current Push integration /// + /** + * Messages will be sent over MobilePush. + * This channel is the successor of the "Push" channel. + */ MobilePush, - /// - /// Messages will be sent over Facebook Messenger. - /// - /// - /// Note that CM needs to configure this for you to work. - /// + /** + * Messages will be sent over Facebook Messenger. + * Note that CM.Com needs to configure this for you to work. + */ @SerializedName("Facebook Messenger") FacebookMessenger, - /// - /// Messages will be sent over Google Business Messages. - /// - /// - /// Note that CM needs to configure this for you to work. - /// + /** + * Messages will be sent over Google Business Messages. + * Note that CM.Com needs to configure this for you to work. + */ @SerializedName("Google Business Messages") GoogleBusinessMessages, - /// - /// Messages will be sent over Instagram. - /// - /// - /// Note that CM needs to configure this for you to work. - /// + /** + * Messages will be sent over Instagram. + * Note that CM.Com needs to configure this for you to work. + */ Instagram } From ca09ed87e0c10b1478d05ac3887c5ebaefa0d298 Mon Sep 17 00:00:00 2001 From: Bas Gijzen Date: Tue, 9 Jan 2024 15:41:04 +0100 Subject: [PATCH 06/15] In progress: using Java style comments, encapsulation and method names (also fixing suggestion actions) --- src/main/java/com/cm/text/models/Message.java | 545 ++++++++++++++---- .../java/com/cm/text/models/Recipient.java | 29 +- .../java/com/cm/text/utils/HttpHelper.java | 3 + 3 files changed, 447 insertions(+), 130 deletions(-) diff --git a/src/main/java/com/cm/text/models/Message.java b/src/main/java/com/cm/text/models/Message.java index 9ef9ea8..05836f5 100644 --- a/src/main/java/com/cm/text/models/Message.java +++ b/src/main/java/com/cm/text/models/Message.java @@ -1,156 +1,451 @@ package com.cm.text.models; +import com.cm.text.models.multichannel.RichContent; import com.google.gson.annotations.SerializedName; import java.util.List; + +/** + * Class representing one message + */ public class Message { - /// - /// The allowed channels field forces a message to only use certain routes. - /// In this field you can define a list of which channels you want your message to use. - /// Not defining any channels will be interpreted as allowing all channels. - /// - /// - /// Note that for channels other than SMS, CM needs to configure the out going flows. - /// For those flows to work, we need to be contacted. - /// + + /** + * The allowed channels field forces a message to only use certain routes. + * In this field you can define a list of which channels you want your message to use. + * Not defining any channels will be interpreted as allowing all channels. + * Note that for channels other than SMS, CM.Com needs to configure the outgoing flows. + * For those flows to work, we need to be contacted. + */ @SerializedName("allowedChannels") - public Channel[] AllowedChannels; + private Channel[] allowedChannels; - /// - /// Required: The actual text body of the message. - /// + /** + * Required: The actual text body of the message. + */ @SerializedName("body") - public Body Body ; - - /// - /// The custom grouping field is an optional field that can be used to tag messages. - /// These tags are be used by CM products, like the Transactions API. - /// Applying custom grouping names to messages helps filter your messages. - /// With up to three levels of custom grouping fields that can be set, subsets of messages can be - /// further broken down. The custom grouping name can be up to 100 characters of your choosing. - /// It’s recommended to limit the number of unique custom groupings to 1000. - /// Please contact support in case you would like to exceed this number. - /// + private Body body ; + + /** + * The custom grouping field is an optional field that can be used to tag messages. + * These tags are be used by CM products, like the Transactions API. + * Applying custom grouping names to messages helps filter your messages. + * With up to three levels of custom grouping fields that can be set, subsets of messages can be + * further broken down. The custom grouping name can be up to 100 characters of your choosing. + * It’s recommended to limit the number of unique custom groupings to 1000. + * Please contact support in case you would like to exceed this number. + */ @SerializedName("customGrouping") - public String CustomGrouping = "text-sdk-java"; - - /// - /// The custom grouping2 field, like is an optional field that can be used to tag - /// messages. - /// These tags are be used by CM products, like the Transactions API. - /// Applying custom grouping names to messages helps filter your messages. - /// With up to three levels of custom grouping fields that can be set, subsets of messages can be - /// further broken down. The custom grouping name can be up to 100 characters of your choosing. - /// It’s recommended to limit the number of unique custom groupings to 1000. - /// Please contact support in case you would like to exceed this number. - /// + private String customGrouping = "text-sdk-java"; + + /** + * Similar with the customGrouping field + * The custom grouping2 field is an optional field that can be used to tag messages. + * These tags are be used by CM products, like the Transactions API. + * Applying custom grouping names to messages helps filter your messages. + * With up to three levels of custom grouping fields that can be set, subsets of messages can be + * further broken down. The custom grouping name can be up to 100 characters of your choosing. + * It’s recommended to limit the number of unique custom groupings to 1000. + * Please contact support in case you would like to exceed this number. + */ @SerializedName("customGrouping2") - public String CustomGrouping2; - - /// - /// The custom grouping3 field, like and is an optional - /// field that can be used to tag messages. - /// These tags are be used by CM products, like the Transactions API. - /// Applying custom grouping names to messages helps filter your messages. - /// With up to three levels of custom grouping fields that can be set, subsets of messages can be - /// further broken down. The custom grouping name can be up to 100 characters of your choosing. - /// It’s recommended to limit the number of unique custom groupings to 1000. - /// Please contact support in case you would like to exceed this number. - /// - /// Default value within this SDK is + private String customGrouping2; + + /** + * Similar with the other customGrouping fields + * The custom grouping field is an optional field that can be used to tag messages. + * These tags are be used by CM products, like the Transactions API. + * Applying custom grouping names to messages helps filter your messages. + * With up to three levels of custom grouping fields that can be set, subsets of messages can be + * further broken down. The custom grouping name can be up to 100 characters of your choosing. + * It’s recommended to limit the number of unique custom groupings to 1000. + * Please contact support in case you would like to exceed this number. + */ @SerializedName("customGrouping3") - public String CustomGrouping3; + private String customGrouping3; - /// - /// Required: This is the sender name. - /// The maximum length is 11 alphanumerical characters or 16 digits. Example: 'CM Telecom' - /// + /** + * Required: This is the sender name. The maximum length is 11 alphanumerical characters or 16 digits. Example: 'CM Telecom' + */ @SerializedName("from") - public String From; - + private String from; - /// - /// Used when sending multipart or concatenated SMS messages and always used together with - /// . - /// Indicate the minimum and maximum of message parts that you allow the gateway to send for this - /// message. - /// Technically the gateway will first check if a message is larger than 160 characters, if so, the - /// message will be cut into multiple 153 characters parts limited by these parameters. - /// + /** + * Used when sending multipart or concatenated SMS messages and always used together with MinimumNumberOfMessageParts. + * Indicate the minimum and maximum of message parts that you allow the gateway to send for this + * message. + * Technically the gateway will first check if a message is larger than 160 characters, if so, the + * message will be cut into multiple 153 characters parts limited by these parameters. + */ @SerializedName("maximumNumberOfMessageParts") - public Integer MaximumNumberOfMessageParts; - - /// - /// Used when sending multipart or concatenated SMS messages and always used together with - /// . - /// Indicate the minimum and maximum of message parts that you allow the gateway to send for this - /// message. - /// Technically the gateway will first check if a message is larger than 160 characters, if so, the - /// message will be cut into multiple 153 characters parts limited by these parameters. - /// + private Integer maximumNumberOfMessageParts; + + /** + * Used when sending multipart or concatenated SMS messages and always used together with MaximumNumberOfMessageParts. + * Indicate the minimum and maximum of message parts that you allow the gateway to send for this message. + * Technically the gateway will first check if a message is larger than 160 characters, if so, the + * message will be cut into multiple 153 characters parts limited by these parameters. + */ @SerializedName("minimumNumberOfMessageParts") - public Integer MinimumNumberOfMessageParts; + private Integer minimumNumberOfMessageParts; - /// - /// Required: The destination mobile numbers. - /// This value should be in international format. - /// A single mobile number per request. Example: '00447911123456' - /// + /** + * The destination mobile numbers. This value should be in international format.A single mobile number per request. Example: '00447911123456' + */ @SerializedName("to") - public List Recipients; - - /// - /// Optional: For each message you send, you can set a reference. - /// The given reference will be used in the status reports and MO replies for the message, - /// so you can link the messages to the sent batch. - /// For more information on status reports, see: - /// https://developers.cm.com/messaging/docs/incoming-status-report - /// The given reference must be between 1 - 32 alphanumeric characters, and will not work using demo accounts. - /// + private List recipients; + + /** + * Optional: For each message you send, you can set a reference. + * The given reference will be used in the status reports and MO replies for the message, + * so you can link the messages to the message that was sent. + * For more information on status reports, see: + * Developer docs + * The given reference must be between 1 - 32 alphanumeric characters. + */ @SerializedName("reference") - public String Reference; + private String reference; + /** + * Can be used by channels that support rich content (all channels except SMS at the moment) + */ @SerializedName("richContent") - public com.cm.text.models.multichannel.RichContent RichContent; - - /// - /// Optional: For each message you send, you can set a validity. - /// Specify a time at which a delayed message can be considered irrelevant, you can supply an absolute date & time - /// or a relative offset. A message is considered failed if it was not successfully delivered before that time. - /// And via a Status Report we inform you this was the case. - /// For more information on status reports, see: - /// https://developers.cm.com/messaging/docs/incoming-status-report - /// You can supply the time zone for the validity period using either of the following formats: - /// - /// Absolute date and time: - /// - /// 2017-04-20 11:50:05 GMT - /// 2017-04-20 11:50:05+8 - /// 2017-04-20 11:55:05-07:00 - /// If no time zone was specified, CE(S)T will be used. (CM local time) - /// - /// Relative offset in hour(H) or minute(M) - /// - /// 2h - /// 30m - /// You can set the validity in either hours or minutes. A combination of both is not supported. - /// + private com.cm.text.models.multichannel.RichContent richContent; + + /** + * Optional: For each message you send, you can set a validity. + * Specify a time at which a delayed message can be considered irrelevant, you can supply an absolute date & time + * or a relative offset. A message is considered failed if it was not successfully delivered before that time. + * And via a Status Report we inform you this was the case. + * For more information on status reports, see: + * Status report developer docs + * You can supply the time zone for the validity period using either of the following formats: + * Absolute date and time: + * 2017-04-20 11:50:05 GMT + * 2017-04-20 11:50:05+8 + * 2017-04-20 11:55:05-07:00 + * If no time zone was specified, CE(S)T will be used. (CM local time) + * Relative offset in hour(H) or minute(M) + * 2h + * 30m + * You can set the validity in either hours or minutes. A combination of both is not supported. + */ @SerializedName("validity") - public String Validity; + private String validity; - /// - /// Optional: If you set DCS to '0' or do not include the parameter, the messages uses standard GSM encoding. - /// To set your message up for unicode messaging set the value of dcs to 8 - /// https://developers.cm.com/messaging/docs/sms#custom-dcs - /// + /** + * Optional: If you set DCS to '0' or do not include the parameter, the messages uses standard GSM encoding. + * To set your message up for unicode messaging set the value of dcs to 8 + * DCS + */ @SerializedName("dcs") - public int Dcs = 0; + private int dcs = 0; + /** + * Initializes a new message + * @param body The actual text body of the message. + * @param from This is the sender name. The maximum length is 11 alphanumerical characters or 16 digits. Example: 'CM Telecom' + * @param recipientList The destination mobile numbers. This value should be in international format.A single mobile number per request. Example: '00447911123456' + */ public Message(Body body, String from, List recipientList) { - this.Body = body; - this.From = from; - this.Recipients = recipientList; + this.body = body; + this.from = from; + this.recipients = recipientList; + } + + /** + * The actual text body of the message. + * @return The actual text body of the message. + */ + public Body getBody() { + return body; + } + + /** + * + * @param body The actual text body of the message. + */ + public void setBody(Body body) { + this.body = body; + } + + /** + * + * @return This is the sender name. The maximum length is 11 alphanumerical characters or 16 digits. Example: 'CM Telecom' + */ + public String getFrom() { + return from; + } + + /** + * + * @param from This is the sender name. The maximum length is 11 alphanumerical characters or 16 digits. Example: 'CM Telecom' + */ + public void setFrom(String from) { + this.from = from; + } + + /** + * + * @return The destination mobile numbers. This value should be in international format.A single mobile number per request. Example: '00447911123456' + */ + public List getRecipients() { + return recipients; + } + + /** + * + * @param recipients The destination mobile numbers. This value should be in international format.A single mobile number per request. Example: '00447911123456' + */ + public void setRecipients(List recipients) { + this.recipients = recipients; + } + + /** + * + * @return The allowed channels field forces a message to only use certain routes. + * In this field you can define a list of which channels you want your message to use. + * Not defining any channels will be interpreted as allowing all channels. + * Note that for channels other than SMS, CM.Com needs to configure the outgoing flows. + * For those flows to work, we need to be contacted. + */ + public Channel[] getAllowedChannels() { + return allowedChannels; + } + + /** + * + * @param allowedChannels The allowed channels field forces a message to only use certain routes. + * In this field you can define a list of which channels you want your message to use. + * Not defining any channels will be interpreted as allowing all channels. + * Note that for channels other than SMS, CM.Com needs to configure the outgoing flows. + * For those flows to work, we need to be contacted. + */ + public void setAllowedChannels(Channel[] allowedChannels) { + this.allowedChannels = allowedChannels; + } + + /** + * @return The custom grouping field is an optional field that can be used to tag messages. + * These tags are be used by CM products, like the Transactions API. + * Applying custom grouping names to messages helps filter your messages. + * With up to three levels of custom grouping fields that can be set, subsets of messages can be + * further broken down. The custom grouping name can be up to 100 characters of your choosing. + * It’s recommended to limit the number of unique custom groupings to 1000. + * Please contact support in case you would like to exceed this number. + */ + public String getCustomGrouping() { + return customGrouping; + } + + /** + * @param customGrouping The custom grouping field is an optional field that can be used to tag messages. + * These tags are be used by CM products, like the Transactions API. + * Applying custom grouping names to messages helps filter your messages. + * With up to three levels of custom grouping fields that can be set, subsets of messages can be + * further broken down. The custom grouping name can be up to 100 characters of your choosing. + * It’s recommended to limit the number of unique custom groupings to 1000. + * Please contact support in case you would like to exceed this number. + */ + public void setCustomGrouping(String customGrouping) { + this.customGrouping = customGrouping; + } + + /** + * + * @return The custom grouping2 field is an optional field that can be used to tag messages. + * These tags are be used by CM products, like the Transactions API. + * Applying custom grouping names to messages helps filter your messages. + * With up to three levels of custom grouping fields that can be set, subsets of messages can be + * further broken down. The custom grouping name can be up to 100 characters of your choosing. + * It’s recommended to limit the number of unique custom groupings to 1000. + * Please contact support in case you would like to exceed this number. + */ + public String getCustomGrouping2() { + return customGrouping2; + } + + /** + * + * @param customGrouping2 The custom grouping2 field is an optional field that can be used to tag messages. + * These tags are be used by CM products, like the Transactions API. + * Applying custom grouping names to messages helps filter your messages. + * With up to three levels of custom grouping fields that can be set, subsets of messages can be + * further broken down. The custom grouping name can be up to 100 characters of your choosing. + * It’s recommended to limit the number of unique custom groupings to 1000. + * Please contact support in case you would like to exceed this number. + */ + public void setCustomGrouping2(String customGrouping2) { + this.customGrouping2 = customGrouping2; + } + + /** + * @return The custom grouping3 field is an optional field that can be used to tag messages. + * These tags are be used by CM products, like the Transactions API. + * Applying custom grouping names to messages helps filter your messages. + * With up to three levels of custom grouping fields that can be set, subsets of messages can be + * further broken down. The custom grouping name can be up to 100 characters of your choosing. + * It’s recommended to limit the number of unique custom groupings to 1000. + * Please contact support in case you would like to exceed this number. + */ + public String getCustomGrouping3() { + return customGrouping3; + } + + /** + * @param customGrouping3 The custom grouping3 field is an optional field that can be used to tag messages. + * These tags are be used by CM products, like the Transactions API. + * Applying custom grouping names to messages helps filter your messages. + * With up to three levels of custom grouping fields that can be set, subsets of messages can be + * further broken down. The custom grouping name can be up to 100 characters of your choosing. + * It’s recommended to limit the number of unique custom groupings to 1000. + * Please contact support in case you would like to exceed this number. + */ + public void setCustomGrouping3(String customGrouping3) { + this.customGrouping3 = customGrouping3; + } + + /** + * @return Used when sending multipart or concatenated SMS messages and always used together with MinimumNumberOfMessageParts. + * Indicate the minimum and maximum of message parts that you allow the gateway to send for this + * message. + * Technically the gateway will first check if a message is larger than 160 characters, if so, the + * message will be cut into multiple 153 characters parts limited by these parameters. + */ + public Integer getMaximumNumberOfMessageParts() { + return maximumNumberOfMessageParts; + } + + /** + * @param maximumNumberOfMessageParts Used when sending multipart or concatenated SMS messages and always used together with MinimumNumberOfMessageParts. + * Indicate the minimum and maximum of message parts that you allow the gateway to send for this + * message. + * Technically the gateway will first check if a message is larger than 160 characters, if so, the + * message will be cut into multiple 153 characters parts limited by these parameters. + */ + public void setMaximumNumberOfMessageParts(Integer maximumNumberOfMessageParts) { + this.maximumNumberOfMessageParts = maximumNumberOfMessageParts; + } + + /** + * + * @return Used when sending multipart or concatenated SMS messages and always used together with MaximumNumberOfMessageParts. + * Indicate the minimum and maximum of message parts that you allow the gateway to send for this message. + * Technically the gateway will first check if a message is larger than 160 characters, if so, the + * message will be cut into multiple 153 characters parts limited by these parameters. + */ + public Integer getMinimumNumberOfMessageParts() { + return minimumNumberOfMessageParts; + } + + /** + * + * @param minimumNumberOfMessageParts Used when sending multipart or concatenated SMS messages and always used together with MaximumNumberOfMessageParts. + * Indicate the minimum and maximum of message parts that you allow the gateway to send for this message. + * Technically the gateway will first check if a message is larger than 160 characters, if so, the + * message will be cut into multiple 153 characters parts limited by these parameters. + */ + public void setMinimumNumberOfMessageParts(Integer minimumNumberOfMessageParts) { + this.minimumNumberOfMessageParts = minimumNumberOfMessageParts; + } + + /** + * + * @return For each message you send, you can set a reference. + * The given reference will be used in the status reports and MO replies for the message, + * so you can link the messages to the message that was sent. + * For more information on status reports, see: + * Developer docs + */ + public String getReference() { + return reference; + } + + /** + * + * @param reference For each message you send, you can set a reference. + * The given reference will be used in the status reports and MO replies for the message, + * so you can link the messages to the message that was sent. + * For more information on status reports, see: + * Developer docs + */ + public void setReference(String reference) { + this.reference = reference; + } + + /** + * @return Specifies a time at which a delayed message can be considered irrelevant, you can supply an absolute date & time + * or a relative offset. A message is considered failed if it was not successfully delivered before that time. + * And via a Status Report we inform you this was the case. + * For more information on status reports, see: + * Status report developer docs + * You can supply the time zone for the validity period using either of the following formats: + * Absolute date and time: + * 2017-04-20 11:50:05 GMT + * 2017-04-20 11:50:05+8 + * 2017-04-20 11:55:05-07:00 + * If no time zone was specified, CE(S)T will be used. (CM local time) + * Relative offset in hour(H) or minute(M) + * 2h + * 30m + * You can set the validity in either hours or minutes. A combination of both is not supported. + */ + public String getValidity() { + return validity; + } + + /** + * @param validity a time at which a delayed message can be considered irrelevant, you can supply an absolute date & time + * or a relative offset. A message is considered failed if it was not successfully delivered before that time. + * And via a Status Report we inform you this was the case. + * For more information on status reports, see: + * Status report developer docs + * You can supply the time zone for the validity period using either of the following formats: + * Absolute date and time: + * 2017-04-20 11:50:05 GMT + * 2017-04-20 11:50:05+8 + * 2017-04-20 11:55:05-07:00 + * If no time zone was specified, CE(S)T will be used. (CM local time) + * Relative offset in hour(H) or minute(M) + * 2h + * 30m + * You can set the validity in either hours or minutes. A combination of both is not supported. + */ + public void setValidity(String validity) { + this.validity = validity; + } + + /** + * @return The rich content to be sent to the end user + */ + public RichContent getRichContent() { + return richContent; + } + + /** + * @param richContent The rich content to be sent to the end user + */ + public void setRichContent(RichContent richContent) { + this.richContent = richContent; + } + + /** + * @return If you set DCS to '0' or do not include the parameter, the messages uses standard GSM encoding. + * To set your message up for unicode messaging set the value of dcs to 8 + * DCS + */ + public int getDcs() { + return dcs; + } + + /** + * @param dcs If you set DCS to '0' or do not include the parameter, the messages uses standard GSM encoding. + * To set your message up for unicode messaging set the value of dcs to 8 + * DCS + */ + public void setDcs(int dcs) { + this.dcs = dcs; } } diff --git a/src/main/java/com/cm/text/models/Recipient.java b/src/main/java/com/cm/text/models/Recipient.java index 3b3ba6d..4d99902 100644 --- a/src/main/java/com/cm/text/models/Recipient.java +++ b/src/main/java/com/cm/text/models/Recipient.java @@ -2,13 +2,32 @@ import com.google.gson.annotations.SerializedName; +/** + * Class representing one end user + */ public class Recipient { - /// - /// This value should be in international format. - /// A single mobile number per request. Example: '00447911123456' - /// + /** + * This value should be in international format. + * A single mobile number per request. Example: '00447911123456' + */ @SerializedName("number") - public String Number; + private String number; + + /** + * + * @return End user number in international format. Example: '00447911123456' + */ + public String getNumber() { + return number; + } + + /** + * + * @param number End user number in international format. Example: '00447911123456' + */ + public void setNumber(String number) { + this.number = number; + } } diff --git a/src/main/java/com/cm/text/utils/HttpHelper.java b/src/main/java/com/cm/text/utils/HttpHelper.java index b257f18..be1918f 100644 --- a/src/main/java/com/cm/text/utils/HttpHelper.java +++ b/src/main/java/com/cm/text/utils/HttpHelper.java @@ -6,6 +6,9 @@ import java.net.URL; import java.nio.charset.StandardCharsets; +/** + * Helper class to send HTTP requests + */ public class HttpHelper { /** From 982b76f3dcd63faacf4b782c041bd0877f744988 Mon Sep 17 00:00:00 2001 From: Bas Gijzen Date: Tue, 9 Jan 2024 15:44:57 +0100 Subject: [PATCH 07/15] In progress: using Java style comments, encapsulation and method names (also fixing suggestion actions) --- .../java/com/cm/text/models/Response.java | 111 +++++++++++++++--- 1 file changed, 92 insertions(+), 19 deletions(-) diff --git a/src/main/java/com/cm/text/models/Response.java b/src/main/java/com/cm/text/models/Response.java index 1166400..317fd18 100644 --- a/src/main/java/com/cm/text/models/Response.java +++ b/src/main/java/com/cm/text/models/Response.java @@ -1,40 +1,113 @@ package com.cm.text.models; +import com.google.gson.annotations.SerializedName; public class Response { public static class HttpResponseBody { - - public String details ; + @SerializedName("details") + private String details; - - public int errorCode ; + @SerializedName("errorCode") + private int errorCode; - - public ResponseMessageDetail[] messages ; + @SerializedName("messages") + private ResponseMessageDetail[] messages; + + public String getDetails() { + return details; + } + + public void setDetails(String details) { + this.details = details; + } + + public int getErrorCode() { + return errorCode; + } + + public void setErrorCode(int errorCode) { + this.errorCode = errorCode; + } + + public ResponseMessageDetail[] getMessages() { + return messages; + } + + public void setMessages(ResponseMessageDetail[] messages) { + this.messages = messages; + } } - public class ResponseMessageDetail + public static class ResponseMessageDetail { - - public String messageDetails ; + @SerializedName("messageDetails") + private String messageDetails ; + + @SerializedName("messageErrorCode") + private String messageErrorCode; + + @SerializedName("parts") + private int parts; + + @SerializedName("reference") + private String reference; + + @SerializedName("status") + private String status; + + @SerializedName("to") + private String to; + + public String getMessageDetails() { + return messageDetails; + } + + public void setMessageDetails(String messageDetails) { + this.messageDetails = messageDetails; + } + + public String getMessageErrorCode() { + return messageErrorCode; + } + + public void setMessageErrorCode(String messageErrorCode) { + this.messageErrorCode = messageErrorCode; + } + + public int getParts() { + return parts; + } + + public void setParts(int parts) { + this.parts = parts; + } + + public String getReference() { + return reference; + } - - public String messageErrorCode; + public void setReference(String reference) { + this.reference = reference; + } - - public int parts; + public String getStatus() { + return status; + } - - public String reference; + public void setStatus(String status) { + this.status = status; + } - - public String status; + public String getTo() { + return to; + } - - public String to; + public void setTo(String to) { + this.to = to; + } } } From 2b48189ddd7198916909c17c8655cc9b7253fa3a Mon Sep 17 00:00:00 2001 From: Bas Gijzen Date: Tue, 9 Jan 2024 17:07:30 +0100 Subject: [PATCH 08/15] Using Java style comments, encapsulation and method names (also fixing suggestion actions) --- .../models/templates/LocalizableParam.java | 102 ++++++++++++------ .../models/templates/TemplateComponents.java | 71 ++++++++---- .../models/templates/TemplateCurrency.java | 53 +++++++-- .../models/templates/TemplateDateTime.java | 23 +++- .../templates/TemplateDateTimeComponent.java | 97 ++++++++++++----- .../models/templates/TemplateLanguage.java | 72 +++++++++---- .../models/templates/TemplateMessage.java | 39 ++++--- .../templates/TemplateMessageContent.java | 25 ++--- .../models/templates/TemplateParameters.java | 63 ++++++----- .../models/templates/WhatsAppTemplate.java | 94 ++++++++++------ 10 files changed, 436 insertions(+), 203 deletions(-) diff --git a/src/main/java/com/cm/text/models/templates/LocalizableParam.java b/src/main/java/com/cm/text/models/templates/LocalizableParam.java index 12daa9f..43fd645 100644 --- a/src/main/java/com/cm/text/models/templates/LocalizableParam.java +++ b/src/main/java/com/cm/text/models/templates/LocalizableParam.java @@ -2,36 +2,76 @@ import com.google.gson.annotations.SerializedName; +/** + * Represents a localize-able parameter in a template + */ public class LocalizableParam { - /// - /// Source: https://developers.facebook.com/docs/whatsapp/api/messages/message-templates - /// - /// Default text if localization fails - /// - @SerializedName("default") - public String Default; - - /// - /// Source: https://developers.facebook.com/docs/whatsapp/api/messages/message-templates - /// - /// If the currency object is used, it contains required parameters currency_code and amount_1000. - /// - @SerializedName("currency") - public TemplateCurrency Currency; - - /// - /// Source: https://developers.facebook.com/docs/whatsapp/api/messages/message-templates - /// - /// If the date_time object is used, further definition of the date and time is required. - /// - @SerializedName("date_time") - public TemplateDateTime DateTime; - - /// - /// Default constructor - /// - public LocalizableParam() - { - - } + + /** + * Source: Meta docs + * Default text if localization fails + */ + @SerializedName("default") + private String defaultLanguage; + + /** + * If the currency object is used, it contains required parameters currency_code and amount_1000. + * Source: Meta docs + */ + @SerializedName("currency") + private TemplateCurrency currency; + + /** + * If the date_time object is used, further definition of the date and time is required. + * Source: Meta docs + */ + @SerializedName("date_time") + private TemplateDateTime dateTime; + + public LocalizableParam() { + } + + /** + * Source: Meta developer docs + * + * @return Default text if localization fails + */ + public String getDefaultLanguage() { + return defaultLanguage; + } + + /** + * @param defaultLanguage Default text if localization fails, see also Meta developer docs + */ + public void setDefaultLanguage(String defaultLanguage) { + this.defaultLanguage = defaultLanguage; + } + + /** + * @return If the currency object is used, it contains required parameters currency_code and amount_1000. + */ + public TemplateCurrency getCurrency() { + return currency; + } + + /** + * @param currency If the currency object is used, it contains required parameters currency_code and amount_1000. + */ + public void setCurrency(TemplateCurrency currency) { + this.currency = currency; + } + + /** + * @return If the date_time object is used, further definition of the date and time is required. + */ + public TemplateDateTime getDateTime() { + return dateTime; + } + + /** + * @param dateTime If the date_time object is used, further definition of the date and time is required. + */ + public void setDateTime(TemplateDateTime dateTime) { + this.dateTime = dateTime; + } } diff --git a/src/main/java/com/cm/text/models/templates/TemplateComponents.java b/src/main/java/com/cm/text/models/templates/TemplateComponents.java index a2c1aaa..99307a9 100644 --- a/src/main/java/com/cm/text/models/templates/TemplateComponents.java +++ b/src/main/java/com/cm/text/models/templates/TemplateComponents.java @@ -4,34 +4,61 @@ public class TemplateComponents { - /// - /// Source: https://developers.facebook.com/docs/whatsapp/api/messages/message-templates - /// - /// Required, describes the component type. Possible values: header, content, footer. - /// + /** + * Required, describes the component type. Possible values: header, content, footer. + * Source: Meta developer docs + */ @SerializedName("type") - public String Type; - /// - /// Source: https://developers.facebook.com/docs/whatsapp/api/messages/message-templates - /// Can be empty. Array containing the dynamic content of the message. - /// + private String componentType; + /** + * Array containing the dynamic content of the message (can be empty) + * Source: Meta developer docs + */ @SerializedName("parameters") - public TemplateParameters[] Parameters; + public TemplateParameters[] templateParameters; - /// - /// Default constructor - /// public TemplateComponents() { } - /// - /// Constructor which sets values - /// - /// - /// - public TemplateComponents(String type, TemplateParameters[] parameters) { - this.Type = type; - this.Parameters = parameters; + /** + * @param type Required, describes the component type. Possible values: header, content, footer. + * @param templateParameters Array containing the dynamic content of the message (can be empty) + */ + public TemplateComponents(String type, TemplateParameters[] templateParameters) { + this.componentType = type; + this.templateParameters = templateParameters; + } + + /** + * + * @return describes the component type. Possible values: header, content, footer. + */ + public String getComponentType() { + return componentType; + } + + /** + * + * @param componentType describes the component type. Possible values: header, content, footer. + */ + public void setComponentType(String componentType) { + this.componentType = componentType; + } + + /** + * + * @return Array containing the dynamic content of the message (can be empty) + */ + public TemplateParameters[] getTemplateParameters() { + return templateParameters; + } + + /** + * + * @param templateParameters Array containing the dynamic content of the message (can be empty) + */ + public void setTemplateParameters(TemplateParameters[] templateParameters) { + this.templateParameters = templateParameters; } } diff --git a/src/main/java/com/cm/text/models/templates/TemplateCurrency.java b/src/main/java/com/cm/text/models/templates/TemplateCurrency.java index 02b1930..a86770f 100644 --- a/src/main/java/com/cm/text/models/templates/TemplateCurrency.java +++ b/src/main/java/com/cm/text/models/templates/TemplateCurrency.java @@ -2,17 +2,52 @@ import com.google.gson.annotations.SerializedName; +/** + * Represents an amount in a specific currency + */ public class TemplateCurrency { - /// - /// Currency code, for example USD or EUR - /// + /** + * Currency code, for example USD or EUR + */ @SerializedName("currency_code") - public String CurrencyCode; - /// - /// Amount in currency_code times 1000 - /// - /// 50110 EUR becomes €50.11 in the message + private String currencyCode; + + /** + * Amount in currency_code times 1000, Example: 50110 EUR becomes €50.11 in the message + */ @SerializedName("amount_1000") - public Long Amount; + private Long amount; + + /** + * + * @return Currency code, for example USD or EUR + */ + public String getCurrencyCode() { + return currencyCode; + } + + /** + * + * @param currencyCode Currency code, for example USD or EUR + */ + public void setCurrencyCode(String currencyCode) { + this.currencyCode = currencyCode; + } + + /** + * + * @return Amount in currency_code times 1000, Example: 50110 EUR becomes €50.11 in the message + */ + public Long getAmount() { + return amount; + } + + /** + * + * @param amount Amount in currency_code times 1000, Example: 50110 EUR becomes €50.11 in the message + */ + public void setAmount(Long amount) { + this.amount = amount; + } } diff --git a/src/main/java/com/cm/text/models/templates/TemplateDateTime.java b/src/main/java/com/cm/text/models/templates/TemplateDateTime.java index df14934..81b75f7 100644 --- a/src/main/java/com/cm/text/models/templates/TemplateDateTime.java +++ b/src/main/java/com/cm/text/models/templates/TemplateDateTime.java @@ -2,9 +2,24 @@ public class TemplateDateTime { - /// - /// The date component as described in https://developers.facebook.com/docs/whatsapp/api/messages/message-templates - /// - public TemplateDateTimeComponent Component; + /** + * The date component as described in Source: Meta developer docs + */ + private TemplateDateTimeComponent component; + /** + * + * @return The date component + */ + public TemplateDateTimeComponent getComponent() { + return component; + } + + /** + * + * @param component The date component + */ + public void setComponent(TemplateDateTimeComponent component) { + this.component = component; + } } diff --git a/src/main/java/com/cm/text/models/templates/TemplateDateTimeComponent.java b/src/main/java/com/cm/text/models/templates/TemplateDateTimeComponent.java index bca9160..543d3d7 100644 --- a/src/main/java/com/cm/text/models/templates/TemplateDateTimeComponent.java +++ b/src/main/java/com/cm/text/models/templates/TemplateDateTimeComponent.java @@ -3,41 +3,86 @@ import com.google.gson.annotations.SerializedName; public class TemplateDateTimeComponent { - /// - /// The day of the week. - /// - /// There will be no checking whether this is correct, + /** + * The day of the week. + */ @SerializedName("day_of_week") - public String DayOfWeek; + private String dayOfWeek; - /// - /// The day of the month. - /// @SerializedName("day_of_month") - public int DayOfMonth; + private int dayOfMonth; - /// - /// The year. - /// @SerializedName("year") - public int Year; + private int year; + - /// - /// The month. - /// @SerializedName("month") - public int Month; + private int month; - /// - /// The hour (24 hour notation) - /// + /** + * The hour (24 hour notation) + */ @SerializedName("hour") - public int Hour; + private int hour; + + @SerializedName("minute") + private int minute; + + + public String getDayOfWeek() { + return dayOfWeek; + } + + public void setDayOfWeek(String dayOfWeek) { + this.dayOfWeek = dayOfWeek; + } + + public int getDayOfMonth() { + return dayOfMonth; + } + + public void setDayOfMonth(int dayOfMonth) { + this.dayOfMonth = dayOfMonth; + } + + public int getYear() { + return year; + } + + public void setYear(int year) { + this.year = year; + } + + public int getMonth() { + return month; + } + + public void setMonth(int month) { + this.month = month; + } + + /** + * + * @return The hour (24 hour notation) + */ + public int getHour() { + return hour; + } + + /** + * + * @param hour The hour (24 hour notation) + */ + public void setHour(int hour) { + this.hour = hour; + } + + public int getMinute() { + return minute; + } - /// - /// The minute of the hour. - /// - @SerializedName("minute") - public int Minute; + public void setMinute(int minute) { + this.minute = minute; + } } diff --git a/src/main/java/com/cm/text/models/templates/TemplateLanguage.java b/src/main/java/com/cm/text/models/templates/TemplateLanguage.java index 2b48db8..22234ee 100644 --- a/src/main/java/com/cm/text/models/templates/TemplateLanguage.java +++ b/src/main/java/com/cm/text/models/templates/TemplateLanguage.java @@ -4,35 +4,65 @@ public class TemplateLanguage { - /// - /// Source: https://developers.facebook.com/docs/whatsapp/api/messages/message-templates - /// The code of the language or locale to use — Accepts both language and language_locale formats (e.g., en and en_US). - /// + /** + * The code of the language or locale to use — Accepts both language and language_locale formats (e.g., en and en_US). + * Meta developer docs + */ @SerializedName("code") - public String Code; + private String code; - /// - /// Source: https://developers.facebook.com/docs/whatsapp/api/messages/message-templates - /// Options: fallback, deterministic - /// The language policy the message should follow - /// + + /** + * + * The language policy the message should follow Options: fallback, deterministic + * Meta developer docs + */ @SerializedName("policy") - public String Policy; + private String policy; - /// - /// Default constructor - /// public TemplateLanguage() { } - /// - /// Constructor which sets values - /// - /// - /// + /** + * + * @param code The code of the language or locale to use — Accepts both language and language_locale formats (e.g., en and en_US). + * @param policy The language policy the message should follow Options: fallback, deterministic + */ public TemplateLanguage(String code, String policy) { - this.Code = code; - this.Policy = policy; + this.code = code; + this.policy = policy; + } + + /** + * + * @return The code of the language or locale to use — Accepts both language and language_locale formats (e.g., en and en_US). + */ + public String getCode() { + return code; + } + + /** + * + * @param code The code of the language or locale to use — Accepts both language and language_locale formats (e.g., en and en_US). + */ + public void setCode(String code) { + this.code = code; + } + + /** + * + * @return The language policy the message should follow Options: fallback, deterministic + */ + public String getPolicy() { + return policy; + } + + /** + * + * @param policy The language policy the message should follow Options: fallback, deterministic + */ + public void setPolicy(String policy) { + this.policy = policy; } } diff --git a/src/main/java/com/cm/text/models/templates/TemplateMessage.java b/src/main/java/com/cm/text/models/templates/TemplateMessage.java index 89f7801..0b04f36 100644 --- a/src/main/java/com/cm/text/models/templates/TemplateMessage.java +++ b/src/main/java/com/cm/text/models/templates/TemplateMessage.java @@ -4,27 +4,36 @@ import com.google.gson.annotations.SerializedName; public class TemplateMessage implements IRichMessage { - /// - /// The Content of the WhatsApp template message - /// - /// Templates need to be configured by CM and approved by Whatsapp before it is possible - /// to send these messages. - /// + /** + * The Content of the WhatsApp template message. + */ @SerializedName("template") - public TemplateMessageContent Content; + private TemplateMessageContent content; - /// - /// Default constructor - /// public TemplateMessage() { } - /// - /// Constructor which sets values - /// - /// + /** + * + * @param content The Content of the WhatsApp template message. + */ public TemplateMessage(TemplateMessageContent content) { - this.Content = content; + this.content = content; + } + + /** + * + * @return The Content of the WhatsApp template message. + */ + public TemplateMessageContent getContent() { + return content; + } + + /** + * @param content The Content of the WhatsApp template message. + */ + public void setContent(TemplateMessageContent content) { + this.content = content; } } diff --git a/src/main/java/com/cm/text/models/templates/TemplateMessageContent.java b/src/main/java/com/cm/text/models/templates/TemplateMessageContent.java index 432f36c..f7d0cd5 100644 --- a/src/main/java/com/cm/text/models/templates/TemplateMessageContent.java +++ b/src/main/java/com/cm/text/models/templates/TemplateMessageContent.java @@ -4,27 +4,22 @@ public class TemplateMessageContent { - /// - /// The WhatsApp template message - /// - /// Templates need to be configured by CM and approved by Whatsapp before it is possible - /// to send these messages. - /// @SerializedName("whatsapp") - public WhatsAppTemplate WhatsAppTemplate; + private WhatsAppTemplate whatsAppTemplate; - /// - /// Default constructor - /// public TemplateMessageContent() { } - /// - /// Constructor which sets values - /// - /// public TemplateMessageContent(WhatsAppTemplate WhatsAppTemplate) { - this.WhatsAppTemplate = WhatsAppTemplate; + this.whatsAppTemplate = WhatsAppTemplate; + } + + public WhatsAppTemplate getWhatsAppTemplate() { + return whatsAppTemplate; + } + + public void setWhatsAppTemplate(WhatsAppTemplate whatsAppTemplate) { + this.whatsAppTemplate = whatsAppTemplate; } } diff --git a/src/main/java/com/cm/text/models/templates/TemplateParameters.java b/src/main/java/com/cm/text/models/templates/TemplateParameters.java index 106765a..39f2cd2 100644 --- a/src/main/java/com/cm/text/models/templates/TemplateParameters.java +++ b/src/main/java/com/cm/text/models/templates/TemplateParameters.java @@ -4,44 +4,49 @@ import com.google.gson.annotations.SerializedName; public class TemplateParameters { - /// - /// Describes the parameter type. - /// - /// Describes the parameter type. Possible values: text, currency, date_time, image, document. - /// + /** + * Describes the parameter type. Describes the parameter type. Possible values: text, currency, date_time, image, document. + */ @SerializedName("type") - public String Type; + private String parameterType; @SerializedName("text") - public String Text; + private String text; @SerializedName("media") - public MediaContent Media; + private MediaContent media; - /// - /// Default constructor - /// public TemplateParameters() { - } - /// - /// Constructor which sets values for rich media template - /// - /// - /// - /// - public TemplateParameters(String type, MediaContent mediaContent) { - this.Type = type; - this.Media = mediaContent; + public TemplateParameters(String type, MediaContent mediaContent) { + this.parameterType = type; + this.media = mediaContent; } - /// - /// Constructor which sets values for a text template - /// - /// - /// - /// public TemplateParameters(String type, String text) { - this.Type = type; - this.Text = text; + this.parameterType = type; + this.text = text; + } + + /** + * + * @return Describes the parameter type. Describes the parameter type. Possible values: text, currency, date_time, image, document. + */ + public String getParameterType() { + return parameterType; + } + + /** + * @param parameterType Describes the parameter type. Describes the parameter type. Possible values: text, currency, date_time, image, document. + */ + public void setParameterType(String parameterType) { + this.parameterType = parameterType; + } + + public String getText() { + return text; + } + + public void setText(String text) { + this.text = text; } } diff --git a/src/main/java/com/cm/text/models/templates/WhatsAppTemplate.java b/src/main/java/com/cm/text/models/templates/WhatsAppTemplate.java index 027b835..f366200 100644 --- a/src/main/java/com/cm/text/models/templates/WhatsAppTemplate.java +++ b/src/main/java/com/cm/text/models/templates/WhatsAppTemplate.java @@ -4,45 +4,77 @@ public class WhatsAppTemplate { - /// - /// Source: https://developers.facebook.com/docs/whatsapp/api/messages/message-templates - /// The namespace that will be used - /// + /** + * The namespace that will be used + * Source Meta developer docs + */ @SerializedName("namespace") - public String Namespace; - /// - /// Source: https://developers.facebook.com/docs/whatsapp/api/messages/message-templates - /// The element name that indicates which template to use within the namespace - /// + private String namespace; + + /** + * Source Meta developer docs + */ @SerializedName("element_name") - public String Name; - /// - /// Source: https://developers.facebook.com/docs/whatsapp/api/messages/message-templates - /// Allows for the specification of a deterministic or fallback language. - /// - /// The language parameter sets the language policy for an Message Template; - /// you can set it to either fallback or deterministic. - /// + private String name; + @SerializedName("language") - public TemplateLanguage Language; - /// - /// Source: https://developers.facebook.com/docs/whatsapp/api/messages/message-templates - /// This field is an array of values to apply to variables in the template - /// + private TemplateLanguage language; + + /** + * This field is an array of values to apply to variables in the template + * Source Meta developer docs + */ @SerializedName("localizable_params") - public LocalizableParam[] LocalizableParams; + private LocalizableParam[] localizableParams; - /// - /// Source: https://developers.facebook.com/docs/whatsapp/api/messages/message-templates - /// This field is an array of values to apply to variables in the template - /// + /** + * This field is an array of values to apply to variables in the template + * Source Meta developer docs + */ @SerializedName("components") - public TemplateComponents[] Components; + private TemplateComponents[] components; - /// - /// Default constructor - /// public WhatsAppTemplate() { } + + public String getNamespace() { + return namespace; + } + + public void setNamespace(String namespace) { + this.namespace = namespace; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public TemplateLanguage getLanguage() { + return language; + } + + public void setLanguage(TemplateLanguage language) { + this.language = language; + } + + public LocalizableParam[] getLocalizableParams() { + return localizableParams; + } + + public void setLocalizableParams(LocalizableParam[] localizableParams) { + this.localizableParams = localizableParams; + } + + public TemplateComponents[] getComponents() { + return components; + } + + public void setComponents(TemplateComponents[] components) { + this.components = components; + } } From e40feff4b87d520f1d740b93f0f034d01002fb51 Mon Sep 17 00:00:00 2001 From: Bas Gijzen Date: Wed, 10 Jan 2024 10:33:29 +0100 Subject: [PATCH 09/15] Adding OtpResponse data type --- pom.xml | 4 +- .../cm/text/models/identity/OtpResponse.java | 110 ++++++++++++++++++ 2 files changed, 112 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/cm/text/models/identity/OtpResponse.java diff --git a/pom.xml b/pom.xml index 5ba7914..c8c39bd 100644 --- a/pom.xml +++ b/pom.xml @@ -14,8 +14,8 @@ org.apache.maven.plugins maven-compiler-plugin - 7 - 7 + 8 + 8 diff --git a/src/main/java/com/cm/text/models/identity/OtpResponse.java b/src/main/java/com/cm/text/models/identity/OtpResponse.java new file mode 100644 index 0000000..50931d5 --- /dev/null +++ b/src/main/java/com/cm/text/models/identity/OtpResponse.java @@ -0,0 +1,110 @@ +package com.cm.text.models.identity; + +import com.google.gson.annotations.SerializedName; + +import java.time.LocalDateTime; + +public class OtpResponse { + /** + * The identifier of the OTP. + */ + @SerializedName("id") + private String id; + /** + * The channel used to send the code. + */ + @SerializedName("channel") + private String channel; + + /** + * Indicates if the code was valid. + */ + @SerializedName("verified") + private boolean verified; + + /** + * The date the OTP was created. + */ + @SerializedName("createdAt") + private LocalDateTime createdAt; + + /** + * The date the OTP will expire. + */ + @SerializedName("expiresAt") + private LocalDateTime expiresAt; + + /** + * @return The identifier of the OTP, should be used to verify. + */ + public String getId() { + return id; + } + + /** + * + * @param id The identifier of the OTP + */ + public void setId(String id) { + this.id = id; + } + + /** + * @return The channel used to send the code. + */ + public String getChannel() { + return channel; + } + + /** + * @param channel The channel used to send the code. + */ + public void setChannel(String channel) { + this.channel = channel; + } + + /** + * + * @return Indicates if the code was valid. + */ + public boolean isVerified() { + return verified; + } + + /** + * + * @param verified Indicates if the code was valid. + */ + public void setVerified(boolean verified) { + this.verified = verified; + } + + /** + * @return The date the OTP was created. + */ + public LocalDateTime getCreatedAt() { + return createdAt; + } + + + /** + * @param createdAt The date the OTP was created. + */ + public void setCreatedAt(LocalDateTime createdAt) { + this.createdAt = createdAt; + } + + /** + * @return The date the OTP will expire. + */ + public LocalDateTime getExpiresAt() { + return expiresAt; + } + + /** + * @param expiresAt The date the OTP will expire. + */ + public void setExpiresAt(LocalDateTime expiresAt) { + this.expiresAt = expiresAt; + } +} From ba599d3b7b86c76b487d7f80aeaa0e2b47c35117 Mon Sep 17 00:00:00 2001 From: Bas Gijzen Date: Thu, 11 Jan 2024 10:21:46 +0100 Subject: [PATCH 10/15] Implement sending of OTP code --- src/main/java/com/cm/text/Config.java | 9 +++ .../java/com/cm/text/MessagingClient.java | 55 +++++++++++++++++-- .../com/cm/text/models/identity/OtpCheck.java | 43 +++++++++++++++ .../java/com/cm/text/utils/HttpHelper.java | 26 +++++---- 4 files changed, 117 insertions(+), 16 deletions(-) create mode 100644 src/main/java/com/cm/text/models/identity/OtpCheck.java diff --git a/src/main/java/com/cm/text/Config.java b/src/main/java/com/cm/text/Config.java index 7152c0d..aa05044 100644 --- a/src/main/java/com/cm/text/Config.java +++ b/src/main/java/com/cm/text/Config.java @@ -5,4 +5,13 @@ public class Config { * Api url for the business messaging api */ public static String BusinessMessagingApiUrl = "https://gw.messaging.cm.com/v1.0/message"; + + /** + * Url used to request a new OTP + */ + public static String OtpRequestEndpoint = "https://api.cm.com/otp/v2/otp"; + /** + * Url formatter used to get the link to verify OTP code + */ + public static String OtpVerifyEndpointFormatter = "https://api.cm.com/otp/v2/otp/%s/verify"; } diff --git a/src/main/java/com/cm/text/MessagingClient.java b/src/main/java/com/cm/text/MessagingClient.java index f561e42..c8403ac 100644 --- a/src/main/java/com/cm/text/MessagingClient.java +++ b/src/main/java/com/cm/text/MessagingClient.java @@ -3,6 +3,9 @@ import com.cm.text.models.Message; import com.cm.text.models.Request; import com.cm.text.models.Response; +import com.cm.text.models.identity.OtpCheck; +import com.cm.text.models.identity.OtpRequest; +import com.cm.text.models.identity.OtpResponse; import com.cm.text.utils.HttpHelper; import com.google.gson.Gson; @@ -40,7 +43,7 @@ public Response.HttpResponseBody sendTextMessage( String messageText, String fro String result = HttpHelper.post( Config.BusinessMessagingApiUrl, body ); - return getResponseBody( result ); + return getResponseBody( result, Response.HttpResponseBody.class ); } /** @@ -51,17 +54,43 @@ public Response.HttpResponseBody sendTextMessage( String messageText, String fro public Response.HttpResponseBody sendMessage( Message message ) { String body = GetHttpPostBody( productToken, message ); String result = HttpHelper.post( Config.BusinessMessagingApiUrl, body ); - return getResponseBody( result ); + return getResponseBody( result, Response.HttpResponseBody.class ); } + /** + * Sends a One Time Password + * @param request The request to send + * @return response with the identifier to use during verification + */ + public OtpResponse sendOtpRequest(OtpRequest request) { + String body = GetHttpPostBody(request); + String result = HttpHelper.post(Config.OtpRequestEndpoint, body, productToken); + + return getResponseBody(result, OtpResponse.class); + } + + + public OtpResponse verifyOtpRequest(String id, String code) { + return verifyOtpRequest(new OtpCheck(id, code)); + } + + public OtpResponse verifyOtpRequest(OtpCheck otpCheck) { + String body = GetHttpPostBody(otpCheck); + String url = String.format(Config.OtpVerifyEndpointFormatter, otpCheck.getId()); + String result = HttpHelper.post(url, body, productToken); + + return getResponseBody(result, OtpResponse.class); + } + + /** * Gets the HTTP post response as an object. * @param body JSON input * @return Result object */ - protected static Response.HttpResponseBody getResponseBody( String body ) { + protected static T getResponseBody( String body, Class classOfT ) { try { - return new Gson().fromJson( body, Response.HttpResponseBody.class ); + return new Gson().fromJson( body, classOfT ); } catch ( Exception e ) { throw new RuntimeException( "Invalid json response-body", e ); @@ -88,5 +117,23 @@ protected static String GetHttpPostBody( String productToken, Message message ) throw new RuntimeException( "Invalid request body", e ); } } + + protected static String GetHttpPostBody( OtpRequest request ) { + try { + return new Gson().toJson( request ); + } + catch ( Exception e ) { + throw new RuntimeException( "Invalid request body", e ); + } + } + + protected static String GetHttpPostBody( OtpCheck request ) { + try { + return new Gson().toJson( request ); + } + catch ( Exception e ) { + throw new RuntimeException( "Invalid request body", e ); + } + } } diff --git a/src/main/java/com/cm/text/models/identity/OtpCheck.java b/src/main/java/com/cm/text/models/identity/OtpCheck.java new file mode 100644 index 0000000..fa6dc8e --- /dev/null +++ b/src/main/java/com/cm/text/models/identity/OtpCheck.java @@ -0,0 +1,43 @@ +package com.cm.text.models.identity; + +import com.google.gson.annotations.SerializedName; + +/** + * Used to check whether the OTP code is valid + */ +public class OtpCheck { + + /** + * id of the OTP to check + */ + private transient final String id; + /** + * The code to check + */ + @SerializedName("code") + private final String code; + + /** + * @param id id of the OTP to check + * @param code The code to check + */ + public OtpCheck(String id, String code) { + this.id = id; + this.code = code; + } + + /** + * @return id of the OTP to check + */ + public String getId() { + return id; + } + + /** + * + * @return The code to check + */ + public String getCode() { + return code; + } +} diff --git a/src/main/java/com/cm/text/utils/HttpHelper.java b/src/main/java/com/cm/text/utils/HttpHelper.java index be1918f..977c131 100644 --- a/src/main/java/com/cm/text/utils/HttpHelper.java +++ b/src/main/java/com/cm/text/utils/HttpHelper.java @@ -11,15 +11,6 @@ */ public class HttpHelper { - /** - * Used to send the HTTP request - * @param url url to send data to - * @param data data to be sent, as JSON - * @return the response (when successful) - */ - private static String sendRequest( String url, String data ) { - return sendRequest(url, data, null); - } /** * Used to send the HTTP request * @param url url to send data to @@ -74,10 +65,21 @@ private static String sendRequest( String url, String data, String productTokenH /** * HTTP POST request * @param url url to send to - * @param urlParameters parameters to use + * @param requestBody parameters to use + * @return JSON result + */ + public static String post( String url, String requestBody ) { + return post(url, requestBody, null); + } + + /** + * HTTP POST request + * @param url url to send to + * @param requestBody parameters to use + * @param productTokenHeader (can be null) when set send this as the product token header * @return JSON result */ - public static String post( String url, String urlParameters ) { - return sendRequest(url, urlParameters ); + public static String post( String url, String requestBody, String productTokenHeader ) { + return sendRequest(url, requestBody, productTokenHeader ); } } From 9b107c768b67994c8caa401d07a3a59574b5c4b0 Mon Sep 17 00:00:00 2001 From: Bas Gijzen Date: Thu, 11 Jan 2024 12:05:16 +0100 Subject: [PATCH 11/15] Fixing build and adding the OtpRequestBuilder --- src/main/java/com/cm/text/MessageBuilder.java | 15 ++-- .../java/com/cm/text/OtpRequestBuilder.java | 90 +++++++++++++++++++ 2 files changed, 97 insertions(+), 8 deletions(-) create mode 100644 src/main/java/com/cm/text/OtpRequestBuilder.java diff --git a/src/main/java/com/cm/text/MessageBuilder.java b/src/main/java/com/cm/text/MessageBuilder.java index 29eb097..789a270 100644 --- a/src/main/java/com/cm/text/MessageBuilder.java +++ b/src/main/java/com/cm/text/MessageBuilder.java @@ -18,7 +18,7 @@ */ public class MessageBuilder { - private Message message; + private final Message message; private RichContent richContent; /** @@ -32,9 +32,8 @@ public MessageBuilder(String messageText, String from,String[] to) List recipientList = new ArrayList<>(); for (String number : to) { Recipient r = new Recipient(); - r.Number = number; + r.setNumber(number); recipientList.add(r); - } this.message = new Message(new Body(messageText), from, recipientList); @@ -59,7 +58,7 @@ public MessageBuilder(String messageText, String type, String from,String[] to) List recipientList = new ArrayList<>(); for (String number : to) { Recipient r = new Recipient(); - r.Number = number; + r.setNumber(number); recipientList.add(r); } @@ -73,7 +72,7 @@ public MessageBuilder(String messageText, String type, String from,String[] to) */ public Message build() { - this.message.RichContent = this.richContent; + this.message.setRichContent(this.richContent); return this.message; } @@ -87,7 +86,7 @@ public Message build() */ public MessageBuilder withAllowedChannels(Channel[] channels) { - this.message.AllowedChannels = channels; + this.message.setAllowedChannels(channels); return this; } @@ -98,7 +97,7 @@ public MessageBuilder withAllowedChannels(Channel[] channels) */ public MessageBuilder withReference(String reference) { - this.message.Reference = reference; + this.message.setReference(reference); return this; } @@ -152,7 +151,7 @@ public MessageBuilder withTemplate(TemplateMessage template){ */ public MessageBuilder withDcs(int dcs) { - this.message.Dcs = dcs; + this.message.setDcs(dcs); return this; } } diff --git a/src/main/java/com/cm/text/OtpRequestBuilder.java b/src/main/java/com/cm/text/OtpRequestBuilder.java new file mode 100644 index 0000000..2b34290 --- /dev/null +++ b/src/main/java/com/cm/text/OtpRequestBuilder.java @@ -0,0 +1,90 @@ +package com.cm.text; + +import com.cm.text.models.identity.OtpRequest; + +/** + * Builder class to construct an OTP request + */ +public class OtpRequestBuilder { + + private final OtpRequest otpRequest; + + /** + * + * @param from The maximum length is 11 alphanumerical characters or 16 digits. Example: 'MyCompany' + * @param to This value should be in international format. single mobile number per request. Example: '+316012345678' + */ + public OtpRequestBuilder(String from, String to) { + otpRequest = new OtpRequest(); + otpRequest.setFrom(from); + otpRequest.setTo(to); + } + + /** + * @param channel The channel to send the code. + * Supported values: auto, sms, push, whatsapp, voice, email. + * Channel auto is only available with a SOLiD subscription. + * @return This builder object for chaining + */ + public OtpRequestBuilder withChannel(String channel) { + otpRequest.setChannel(channel); + return this; + } + + /** + * + * @param digits The length of the code (min 4, max 10). default: 5. + * @return This builder object for chaining + */ + public OtpRequestBuilder withDigits(int digits) { + otpRequest.setDigits(digits); + return this; + } + + + /** + * @param expiryInSeconds The expiry in seconds (min 10, max 3600). (default: 60 seconds.) + * @return This builder object for chaining + */ + public OtpRequestBuilder withExpiry(int expiryInSeconds) { + otpRequest.setExpiry(expiryInSeconds); + return this; + } + + /** + * + * @param locale The locale, for WhatsApp supported values: en, nl, fr, de, it, es. + * * Default: en + * * For Voice: the spoken language in the voice call, + * * supported values: de-DE, en-AU, en-GB, en-IN, en-US, es-ES, fr-CA, fr-FR, it-IT, ja-JP, nl-NL + * * Default: en-GB. + * * For Email: The locale for the email template. + * @return This builder object for chaining + */ + public OtpRequestBuilder withLocale(String locale) { + otpRequest.setLocale(locale); + return this; + } + + /** + * + * @param pushAppKey The app key, when Channel is 'push' + * @return This builder object for chaining + */ + public OtpRequestBuilder withPushAppKey(String pushAppKey) { + otpRequest.setPushAppKey(pushAppKey); + return this; + } + + /** + * For WhatsApp/SMS, set a custom message. You can use the placeholder {code}, this will be replaced by the actual code. + * Example: Your code is: {code}. This is only used as a fallback in case the message could not be delivered via WhatsApp. + * For email, Set a custom message to be used in the email message. Do not include the {code} placeholder. + * @param message the custom message + * @return This builder object for chaining + */ + public OtpRequestBuilder withMessage(String message) { + otpRequest.setMessage(message); + return this; + } +} From f2d6c00a6f7e81393dc953721202fa99e97caccc Mon Sep 17 00:00:00 2001 From: Bas Gijzen Date: Thu, 11 Jan 2024 12:12:57 +0100 Subject: [PATCH 12/15] Adding comments --- src/main/java/com/cm/text/MessagingClient.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/cm/text/MessagingClient.java b/src/main/java/com/cm/text/MessagingClient.java index c8403ac..4b4e535 100644 --- a/src/main/java/com/cm/text/MessagingClient.java +++ b/src/main/java/com/cm/text/MessagingClient.java @@ -69,11 +69,21 @@ public OtpResponse sendOtpRequest(OtpRequest request) { return getResponseBody(result, OtpResponse.class); } - + /** + * Checks one otp request + * @param id the id to use + * @param code the code to check + * @return the result of the check + */ public OtpResponse verifyOtpRequest(String id, String code) { return verifyOtpRequest(new OtpCheck(id, code)); } + /** + * Checks one otp request + * @param otpCheck the id and code of the check + * @return the result of the check + */ public OtpResponse verifyOtpRequest(OtpCheck otpCheck) { String body = GetHttpPostBody(otpCheck); String url = String.format(Config.OtpVerifyEndpointFormatter, otpCheck.getId()); From 52afff387d18ce736f36a03ddca9da112eb256df Mon Sep 17 00:00:00 2001 From: Bas Gijzen Date: Thu, 11 Jan 2024 16:13:05 +0100 Subject: [PATCH 13/15] Checks and fixes --- README.md | 20 ++++++++++--------- .../java/com/cm/text/MessagingClient.java | 2 +- .../java/com/cm/text/OtpRequestBuilder.java | 7 +++++++ .../cm/text/models/identity/OtpRequest.java | 6 +++++- .../cm/text/models/identity/OtpResponse.java | 15 +++++++------- 5 files changed, 31 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 798e29d..d5afa64 100644 --- a/README.md +++ b/README.md @@ -128,18 +128,20 @@ MessagingClient client = new MessagingClient("YourProductToken"); ## Using the OTP API -Send a simple OTP code +Send an OTP code ```java - MessagingClient client = new MessagingClient("YourProductToken"); - client.sendOtp("Sender", "316012345678", "sms"); + MessagingClient client = new MessagingClient(yourProductToken); + + OtpRequest request = new OtpRequestBuilder(senderName, recipientNumber) + .withMessage("Your OTP code is {code}") + .withChannel("sms") + .build(); + + OtpResponse result = client.sendOtpRequest(request); ``` Verify the response code ```java - client.verifyOtp("OTP-ID", "code") + OtpResponse verifyResult = client.verifyOtpRequest(result.getId(), code); + verifyResult.isVerified(); //represents whether the check was code was correct ``` - -More advanced scenarios -```java - MessagingClient client = new MessagingClient("YourProductToken"); -``` \ No newline at end of file diff --git a/src/main/java/com/cm/text/MessagingClient.java b/src/main/java/com/cm/text/MessagingClient.java index 4b4e535..9f10bbc 100644 --- a/src/main/java/com/cm/text/MessagingClient.java +++ b/src/main/java/com/cm/text/MessagingClient.java @@ -81,7 +81,7 @@ public OtpResponse verifyOtpRequest(String id, String code) { /** * Checks one otp request - * @param otpCheck the id and code of the check + * @param otpCheck the id and code to check * @return the result of the check */ public OtpResponse verifyOtpRequest(OtpCheck otpCheck) { diff --git a/src/main/java/com/cm/text/OtpRequestBuilder.java b/src/main/java/com/cm/text/OtpRequestBuilder.java index 2b34290..c15c212 100644 --- a/src/main/java/com/cm/text/OtpRequestBuilder.java +++ b/src/main/java/com/cm/text/OtpRequestBuilder.java @@ -20,6 +20,13 @@ public OtpRequestBuilder(String from, String to) { otpRequest.setTo(to); } + /** + * @return gets the otp request. + */ + public OtpRequest build() { + return otpRequest; + } + /** * @param channel The channel to send the code. * Supported values: auto, sms, push, whatsapp, voice, email. diff --git a/src/main/java/com/cm/text/models/identity/OtpRequest.java b/src/main/java/com/cm/text/models/identity/OtpRequest.java index 7ab70c3..a19340f 100644 --- a/src/main/java/com/cm/text/models/identity/OtpRequest.java +++ b/src/main/java/com/cm/text/models/identity/OtpRequest.java @@ -37,7 +37,7 @@ public class OtpRequest { * Channel auto is only available with a SOLiD subscription. */ @SerializedName("channel") - private String channel = "sms"; + private String channel; /** * The locale, for WhatsApp supported values: en, nl, fr, de, it, es. @@ -64,6 +64,10 @@ public class OtpRequest { @SerializedName("message") private String message; + public OtpRequest() { + channel = "sms"; + } + /** * @return This is the sender name. * The maximum length is 11 alphanumerical characters or 16 digits. Example: 'MyCompany' diff --git a/src/main/java/com/cm/text/models/identity/OtpResponse.java b/src/main/java/com/cm/text/models/identity/OtpResponse.java index 50931d5..4daa419 100644 --- a/src/main/java/com/cm/text/models/identity/OtpResponse.java +++ b/src/main/java/com/cm/text/models/identity/OtpResponse.java @@ -1,8 +1,7 @@ package com.cm.text.models.identity; import com.google.gson.annotations.SerializedName; - -import java.time.LocalDateTime; +import java.util.Date; public class OtpResponse { /** @@ -26,13 +25,13 @@ public class OtpResponse { * The date the OTP was created. */ @SerializedName("createdAt") - private LocalDateTime createdAt; + private Date createdAt; /** * The date the OTP will expire. */ @SerializedName("expiresAt") - private LocalDateTime expiresAt; + private Date expiresAt; /** * @return The identifier of the OTP, should be used to verify. @@ -82,7 +81,7 @@ public void setVerified(boolean verified) { /** * @return The date the OTP was created. */ - public LocalDateTime getCreatedAt() { + public Date getCreatedAt() { return createdAt; } @@ -90,21 +89,21 @@ public LocalDateTime getCreatedAt() { /** * @param createdAt The date the OTP was created. */ - public void setCreatedAt(LocalDateTime createdAt) { + public void setCreatedAt(Date createdAt) { this.createdAt = createdAt; } /** * @return The date the OTP will expire. */ - public LocalDateTime getExpiresAt() { + public Date getExpiresAt() { return expiresAt; } /** * @param expiresAt The date the OTP will expire. */ - public void setExpiresAt(LocalDateTime expiresAt) { + public void setExpiresAt(Date expiresAt) { this.expiresAt = expiresAt; } } From 86d55270290e1c11c94c3f2436ca670bc07d634d Mon Sep 17 00:00:00 2001 From: Bas Gijzen Date: Thu, 11 Jan 2024 16:21:47 +0100 Subject: [PATCH 14/15] Allow missing docs --- pom.xml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pom.xml b/pom.xml index c8c39bd..046d7df 100644 --- a/pom.xml +++ b/pom.xml @@ -57,6 +57,9 @@ jar + + false + From 9b3030f92fc70803eff9fa370bff59aeb8d8a9e6 Mon Sep 17 00:00:00 2001 From: Bas Gijzen Date: Thu, 11 Jan 2024 16:57:03 +0100 Subject: [PATCH 15/15] Updating changelog --- CHANGELOG.md | 9 ++++++++- .../com/cm/text/models/identity/OtpRequest.java | 15 ++++++++++----- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6abbd50..22cd771 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [3.0.0] - 2024-01-11 +### Added +- OTP API +### Changed +- Updated comments (made them javadoc style) +- Use Javabeans style getters and setters instead of public fields + ## [2.1.0] - 2023-07-07 ### Changed - Implement DCS parameter (#23) @@ -19,4 +26,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Pushed to Maven Central ### Changed -- Changed namespace from com.cmtelecom to com.cm \ No newline at end of file +- Changed namespace from com.cmtelecom to com.cm diff --git a/src/main/java/com/cm/text/models/identity/OtpRequest.java b/src/main/java/com/cm/text/models/identity/OtpRequest.java index a19340f..974ef25 100644 --- a/src/main/java/com/cm/text/models/identity/OtpRequest.java +++ b/src/main/java/com/cm/text/models/identity/OtpRequest.java @@ -69,8 +69,8 @@ public OtpRequest() { } /** + * The sender name The maximum length is 11 alphanumerical characters or 16 digits. Example: 'MyCompany' * @return This is the sender name. - * The maximum length is 11 alphanumerical characters or 16 digits. Example: 'MyCompany' */ public String getFrom() { return from; @@ -85,7 +85,7 @@ public void setFrom(String from) { } /** - * + * The destination mobile number. * @return The destination mobile number. */ public String getTo() { @@ -93,7 +93,7 @@ public String getTo() { } /** - * Required: The destination mobile number. + * Required: The destination mobile number. * This value should be in international format. single mobile number per request. Example: '+316012345678' * @param to This value should be in international format. single mobile number per request. Example: '+316012345678' */ @@ -102,6 +102,7 @@ public void setTo(String to) { } /** + * The length of the code (min 4, max 10). default: 5. * @return The length of the code (min 4, max 10). default: 5. */ public Integer getDigits() { @@ -109,6 +110,7 @@ public Integer getDigits() { } /** + * The length of the code (min 4, max 10). default: 5. * @param digits The length of the code (min 4, max 10). default: 5. */ public void setDigits(Integer digits) { @@ -116,6 +118,7 @@ public void setDigits(Integer digits) { } /** + * The expiry in seconds (min 10, max 3600). default (when null): 60 seconds. * @return The expiry in seconds (min 10, max 3600). default (when null): 60 seconds. */ public Integer getExpiry() { @@ -123,6 +126,7 @@ public Integer getExpiry() { } /** + * The expiry in seconds (min 10, max 3600). (default: 60 seconds.) * @param expiry The expiry in seconds (min 10, max 3600). (default: 60 seconds.) */ public void setExpiry(Integer expiry) { @@ -140,9 +144,10 @@ public String getChannel() { } /** + * The channel to send the code. + * Supported values: auto, sms, push, whatsapp, voice, email. + * Channel auto is only available with a SOLiD subscription. * @param channel The channel to send the code. - * Supported values: auto, sms, push, whatsapp, voice, email. - * Channel auto is only available with a SOLiD subscription. */ public void setChannel(String channel) { this.channel = channel;