- * I am placing this code in the Public Domain. Do with it as you will.
- * This software comes with no guarantees or warranties but with
- * plenty of well-wishing instead!
- * Please visit http://iharder.net/base64
- * periodically to check for updates or to contribute improvements.
- *
- *
- * @author Robert Harder
- * @author rob@iharder.net
- * @version 2.3.7
- */
-class Base64 {
-
-/* ******** P U B L I C F I E L D S ******** */
-
-
- /** No options specified. Value is zero. */
- public final static int NO_OPTIONS = 0;
-
- /** Specify that gzipped data should not be automatically gunzipped. */
- public final static int DONT_GUNZIP = 4;
-
- /**
- * Encode using Base64-like encoding that is URL- and Filename-safe as described
- * in Section 4 of RFC3548:
- * http://www.faqs.org/rfcs/rfc3548.html.
- * It is important to note that data encoded this way is not officially valid Base64,
- * or at the very least should not be called Base64 without also specifying that is
- * was encoded using the URL- and Filename-safe dialect.
- */
- public final static int URL_SAFE = 16;
-
-
- /**
- * Encode using the special "ordered" dialect of Base64 described here:
- * http://www.faqs.org/qa/rfcc-1940.html.
- */
- public final static int ORDERED = 32;
-
-
-/* ******** P R I V A T E F I E L D S ******** */
-
-
- /** The equals sign (=) as a byte. */
- private final static byte EQUALS_SIGN = (byte)'=';
-
-
- /** Preferred encoding. */
- private final static String PREFERRED_ENCODING = "US-ASCII";
-
-
- private final static byte WHITE_SPACE_ENC = -5; // Indicates white space in encoding
- private final static byte EQUALS_SIGN_ENC = -1; // Indicates equals sign in encoding
-
-
-/* ******** S T A N D A R D B A S E 6 4 A L P H A B E T ******** */
-
- /**
- * Translates a Base64 value to either its 6-bit reconstruction value
- * or a negative number indicating some other meaning.
- **/
- private final static byte[] _STANDARD_DECODABET = {
- -9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 0 - 8
- -5,-5, // Whitespace: Tab and Linefeed
- -9,-9, // Decimal 11 - 12
- -5, // Whitespace: Carriage Return
- -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 14 - 26
- -9,-9,-9,-9,-9, // Decimal 27 - 31
- -5, // Whitespace: Space
- -9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 33 - 42
- 62, // Plus sign at decimal 43
- -9,-9,-9, // Decimal 44 - 46
- 63, // Slash at decimal 47
- 52,53,54,55,56,57,58,59,60,61, // Numbers zero through nine
- -9,-9,-9, // Decimal 58 - 60
- -1, // Equals sign at decimal 61
- -9,-9,-9, // Decimal 62 - 64
- 0,1,2,3,4,5,6,7,8,9,10,11,12,13, // Letters 'A' through 'N'
- 14,15,16,17,18,19,20,21,22,23,24,25, // Letters 'O' through 'Z'
- -9,-9,-9,-9,-9,-9, // Decimal 91 - 96
- 26,27,28,29,30,31,32,33,34,35,36,37,38, // Letters 'a' through 'm'
- 39,40,41,42,43,44,45,46,47,48,49,50,51, // Letters 'n' through 'z'
- -9,-9,-9,-9,-9 // Decimal 123 - 127
- ,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 128 - 139
- -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 140 - 152
- -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 153 - 165
- -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 166 - 178
- -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 179 - 191
- -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 192 - 204
- -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 205 - 217
- -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 218 - 230
- -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 231 - 243
- -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9 // Decimal 244 - 255
- };
-
-
-/* ******** U R L S A F E B A S E 6 4 A L P H A B E T ******** */
-
- /**
- * Used in decoding URL- and Filename-safe dialects of Base64.
- */
- private final static byte[] _URL_SAFE_DECODABET = {
- -9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 0 - 8
- -5,-5, // Whitespace: Tab and Linefeed
- -9,-9, // Decimal 11 - 12
- -5, // Whitespace: Carriage Return
- -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 14 - 26
- -9,-9,-9,-9,-9, // Decimal 27 - 31
- -5, // Whitespace: Space
- -9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 33 - 42
- -9, // Plus sign at decimal 43
- -9, // Decimal 44
- 62, // Minus sign at decimal 45
- -9, // Decimal 46
- -9, // Slash at decimal 47
- 52,53,54,55,56,57,58,59,60,61, // Numbers zero through nine
- -9,-9,-9, // Decimal 58 - 60
- -1, // Equals sign at decimal 61
- -9,-9,-9, // Decimal 62 - 64
- 0,1,2,3,4,5,6,7,8,9,10,11,12,13, // Letters 'A' through 'N'
- 14,15,16,17,18,19,20,21,22,23,24,25, // Letters 'O' through 'Z'
- -9,-9,-9,-9, // Decimal 91 - 94
- 63, // Underscore at decimal 95
- -9, // Decimal 96
- 26,27,28,29,30,31,32,33,34,35,36,37,38, // Letters 'a' through 'm'
- 39,40,41,42,43,44,45,46,47,48,49,50,51, // Letters 'n' through 'z'
- -9,-9,-9,-9,-9 // Decimal 123 - 127
- ,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 128 - 139
- -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 140 - 152
- -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 153 - 165
- -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 166 - 178
- -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 179 - 191
- -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 192 - 204
- -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 205 - 217
- -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 218 - 230
- -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 231 - 243
- -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9 // Decimal 244 - 255
- };
-
-
-
-/* ******** O R D E R E D B A S E 6 4 A L P H A B E T ******** */
-
- /**
- * Used in decoding the "ordered" dialect of Base64.
- */
- private final static byte[] _ORDERED_DECODABET = {
- -9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 0 - 8
- -5,-5, // Whitespace: Tab and Linefeed
- -9,-9, // Decimal 11 - 12
- -5, // Whitespace: Carriage Return
- -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 14 - 26
- -9,-9,-9,-9,-9, // Decimal 27 - 31
- -5, // Whitespace: Space
- -9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 33 - 42
- -9, // Plus sign at decimal 43
- -9, // Decimal 44
- 0, // Minus sign at decimal 45
- -9, // Decimal 46
- -9, // Slash at decimal 47
- 1,2,3,4,5,6,7,8,9,10, // Numbers zero through nine
- -9,-9,-9, // Decimal 58 - 60
- -1, // Equals sign at decimal 61
- -9,-9,-9, // Decimal 62 - 64
- 11,12,13,14,15,16,17,18,19,20,21,22,23, // Letters 'A' through 'M'
- 24,25,26,27,28,29,30,31,32,33,34,35,36, // Letters 'N' through 'Z'
- -9,-9,-9,-9, // Decimal 91 - 94
- 37, // Underscore at decimal 95
- -9, // Decimal 96
- 38,39,40,41,42,43,44,45,46,47,48,49,50, // Letters 'a' through 'm'
- 51,52,53,54,55,56,57,58,59,60,61,62,63, // Letters 'n' through 'z'
- -9,-9,-9,-9,-9 // Decimal 123 - 127
- ,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 128 - 139
- -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 140 - 152
- -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 153 - 165
- -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 166 - 178
- -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 179 - 191
- -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 192 - 204
- -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 205 - 217
- -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 218 - 230
- -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 231 - 243
- -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9 // Decimal 244 - 255
- };
-
-
-/* ******** D E T E R M I N E W H I C H A L H A B E T ******** */
-
- /**
- * Returns one of the _SOMETHING_DECODABET byte arrays depending on
- * the options specified.
- * It's possible, though silly, to specify ORDERED and URL_SAFE
- * in which case one of them will be picked, though there is
- * no guarantee as to which one will be picked.
- */
- private final static byte[] getDecodabet( int options ) {
- if( (options & URL_SAFE) == URL_SAFE) {
- return _URL_SAFE_DECODABET;
- } else if ((options & ORDERED) == ORDERED) {
- return _ORDERED_DECODABET;
- } else {
- return _STANDARD_DECODABET;
- }
- } // end getAlphabet
-
-
-
- /** Defeats instantiation. */
- private Base64(){}
-
-
-
-/* ******** D E C O D I N G M E T H O D S ******** */
-
-
- /**
- * Decodes four bytes from array source
- * and writes the resulting bytes (up to three of them)
- * to destination.
- * The source and destination arrays can be manipulated
- * anywhere along their length by specifying
- * srcOffset and destOffset.
- * This method does not check to make sure your arrays
- * are large enough to accomodate srcOffset + 4 for
- * the source array or destOffset + 3 for
- * the destination array.
- * This method returns the actual number of bytes that
- * were converted from the Base64 encoding.
- *
This is the lowest level of the decoding methods with
- * all possible parameters.
- *
- *
- * @param source the array to convert
- * @param srcOffset the index where conversion begins
- * @param destination the array to hold the conversion
- * @param destOffset the index where output will be put
- * @param options alphabet type is pulled from this (standard, url-safe, ordered)
- * @return the number of decoded bytes converted
- * @throws NullPointerException if source or destination arrays are null
- * @throws IllegalArgumentException if srcOffset or destOffset are invalid
- * or there is not enough room in the array.
- * @since 1.3
- */
- private static int decode4to3(
- byte[] source, int srcOffset,
- byte[] destination, int destOffset, int options ) {
-
- // Lots of error checking and exception throwing
- if( source == null ){
- throw new NullPointerException( "Source array was null." );
- } // end if
- if( destination == null ){
- throw new NullPointerException( "Destination array was null." );
- } // end if
- if( srcOffset < 0 || srcOffset + 3 >= source.length ){
- throw new IllegalArgumentException( String.format(
- "Source array with length %d cannot have offset of %d and still process four bytes.", source.length, srcOffset ) );
- } // end if
- if( destOffset < 0 || destOffset +2 >= destination.length ){
- throw new IllegalArgumentException( String.format(
- "Destination array with length %d cannot have offset of %d and still store three bytes.", destination.length, destOffset ) );
- } // end if
-
-
- byte[] DECODABET = getDecodabet( options );
-
- // Example: Dk==
- if( source[ srcOffset + 2] == EQUALS_SIGN ) {
- // Two ways to do the same thing. Don't know which way I like best.
- //int outBuff = ( ( DECODABET[ source[ srcOffset ] ] << 24 ) >>> 6 )
- // | ( ( DECODABET[ source[ srcOffset + 1] ] << 24 ) >>> 12 );
- int outBuff = ( ( DECODABET[ source[ srcOffset ] ] & 0xFF ) << 18 )
- | ( ( DECODABET[ source[ srcOffset + 1] ] & 0xFF ) << 12 );
-
- destination[ destOffset ] = (byte)( outBuff >>> 16 );
- return 1;
- }
-
- // Example: DkL=
- else if( source[ srcOffset + 3 ] == EQUALS_SIGN ) {
- // Two ways to do the same thing. Don't know which way I like best.
- //int outBuff = ( ( DECODABET[ source[ srcOffset ] ] << 24 ) >>> 6 )
- // | ( ( DECODABET[ source[ srcOffset + 1 ] ] << 24 ) >>> 12 )
- // | ( ( DECODABET[ source[ srcOffset + 2 ] ] << 24 ) >>> 18 );
- int outBuff = ( ( DECODABET[ source[ srcOffset ] ] & 0xFF ) << 18 )
- | ( ( DECODABET[ source[ srcOffset + 1 ] ] & 0xFF ) << 12 )
- | ( ( DECODABET[ source[ srcOffset + 2 ] ] & 0xFF ) << 6 );
-
- destination[ destOffset ] = (byte)( outBuff >>> 16 );
- destination[ destOffset + 1 ] = (byte)( outBuff >>> 8 );
- return 2;
- }
-
- // Example: DkLE
- else {
- // Two ways to do the same thing. Don't know which way I like best.
- //int outBuff = ( ( DECODABET[ source[ srcOffset ] ] << 24 ) >>> 6 )
- // | ( ( DECODABET[ source[ srcOffset + 1 ] ] << 24 ) >>> 12 )
- // | ( ( DECODABET[ source[ srcOffset + 2 ] ] << 24 ) >>> 18 )
- // | ( ( DECODABET[ source[ srcOffset + 3 ] ] << 24 ) >>> 24 );
- int outBuff = ( ( DECODABET[ source[ srcOffset ] ] & 0xFF ) << 18 )
- | ( ( DECODABET[ source[ srcOffset + 1 ] ] & 0xFF ) << 12 )
- | ( ( DECODABET[ source[ srcOffset + 2 ] ] & 0xFF ) << 6)
- | ( ( DECODABET[ source[ srcOffset + 3 ] ] & 0xFF ) );
-
-
- destination[ destOffset ] = (byte)( outBuff >> 16 );
- destination[ destOffset + 1 ] = (byte)( outBuff >> 8 );
- destination[ destOffset + 2 ] = (byte)( outBuff );
-
- return 3;
- }
- } // end decodeToBytes
-
-
-
-
- /**
- * Low-level access to decoding ASCII characters in
- * the form of a byte array. Ignores GUNZIP option, if
- * it's set. This is not generally a recommended method,
- * although it is used internally as part of the decoding process.
- * Special case: if len = 0, an empty array is returned. Still,
- * if you need more speed and reduced memory footprint (and aren't
- * gzipping), consider this method.
- *
- * @param source The Base64 encoded data
- * @param off The offset of where to begin decoding
- * @param len The length of characters to decode
- * @param options Can specify options such as alphabet type to use
- * @return decoded data
- * @throws java.io.IOException If bogus characters exist in source data
- * @since 1.3
- */
- public static byte[] decode( byte[] source, int off, int len, int options )
- throws java.io.IOException {
-
- // Lots of error checking and exception throwing
- if( source == null ){
- throw new NullPointerException( "Cannot decode null source array." );
- } // end if
- if( off < 0 || off + len > source.length ){
- throw new IllegalArgumentException( String.format(
- "Source array with length %d cannot have offset of %d and process %d bytes.", source.length, off, len ) );
- } // end if
-
- if( len == 0 ){
- return new byte[0];
- }else if( len < 4 ){
- throw new IllegalArgumentException(
- "Base64-encoded string must have at least four characters, but length specified was " + len );
- } // end if
-
- byte[] DECODABET = getDecodabet( options );
-
- int len34 = len * 3 / 4; // Estimate on array size
- byte[] outBuff = new byte[ len34 ]; // Upper limit on size of output
- int outBuffPosn = 0; // Keep track of where we're writing
-
- byte[] b4 = new byte[4]; // Four byte buffer from source, eliminating white space
- int b4Posn = 0; // Keep track of four byte input buffer
- int i = 0; // Source array counter
- byte sbiDecode = 0; // Special value from DECODABET
-
- for( i = off; i < off+len; i++ ) { // Loop through source
-
- sbiDecode = DECODABET[ source[i]&0xFF ];
-
- // White space, Equals sign, or legit Base64 character
- // Note the values such as -5 and -9 in the
- // DECODABETs at the top of the file.
- if( sbiDecode >= WHITE_SPACE_ENC ) {
- if( sbiDecode >= EQUALS_SIGN_ENC ) {
- b4[ b4Posn++ ] = source[i]; // Save non-whitespace
- if( b4Posn > 3 ) { // Time to decode?
- outBuffPosn += decode4to3( b4, 0, outBuff, outBuffPosn, options );
- b4Posn = 0;
-
- // If that was the equals sign, break out of 'for' loop
- if( source[i] == EQUALS_SIGN ) {
- break;
- } // end if: equals sign
- } // end if: quartet built
- } // end if: equals sign or better
- } // end if: white space, equals sign or better
- else {
- // There's a bad input character in the Base64 stream.
- throw new java.io.IOException( String.format(
- "Bad Base64 input character decimal %d in array position %d", ((int)source[i])&0xFF, i ) );
- } // end else:
- } // each input character
-
- byte[] out = new byte[ outBuffPosn ];
- System.arraycopy( outBuff, 0, out, 0, outBuffPosn );
- return out;
- } // end decode
-
-
-
-
- /**
- * Decodes data from Base64 notation, automatically
- * detecting gzip-compressed data and decompressing it.
- *
- * @param s the string to decode
- * @return the decoded data
- * @throws java.io.IOException If there is a problem
- * @since 1.4
- */
- public static byte[] decode( String s ) throws java.io.IOException {
- return decode( s, NO_OPTIONS );
- }
-
-
-
- /**
- * Decodes data from Base64 notation, automatically
- * detecting gzip-compressed data and decompressing it.
- *
- * @param s the string to decode
- * @param options encode options such as URL_SAFE
- * @return the decoded data
- * @throws java.io.IOException if there is an error
- * @throws NullPointerException if s is null
- * @since 1.4
- */
- public static byte[] decode( String s, int options ) throws java.io.IOException {
-
- if( s == null ){
- throw new NullPointerException( "Input string was null." );
- } // end if
-
- byte[] bytes;
- try {
- bytes = s.getBytes( PREFERRED_ENCODING );
- } // end try
- catch( java.io.UnsupportedEncodingException uee ) {
- bytes = s.getBytes();
- } // end catch
- //
-
- // Decode
- bytes = decode( bytes, 0, bytes.length, options );
-
- // Check to see if it's gzip-compressed
- // GZIP Magic Two-Byte Number: 0x8b1f (35615)
- boolean dontGunzip = (options & DONT_GUNZIP) != 0;
- if( (bytes != null) && (bytes.length >= 4) && (!dontGunzip) ) {
-
- int head = ((int)bytes[0] & 0xff) | ((bytes[1] << 8) & 0xff00);
- if( java.util.zip.GZIPInputStream.GZIP_MAGIC == head ) {
- java.io.ByteArrayInputStream bais = null;
- java.util.zip.GZIPInputStream gzis = null;
- java.io.ByteArrayOutputStream baos = null;
- byte[] buffer = new byte[2048];
- int length = 0;
-
- try {
- baos = new java.io.ByteArrayOutputStream();
- bais = new java.io.ByteArrayInputStream( bytes );
- gzis = new java.util.zip.GZIPInputStream( bais );
-
- while( ( length = gzis.read( buffer ) ) >= 0 ) {
- baos.write(buffer,0,length);
- } // end while: reading input
-
- // No error? Get new bytes.
- bytes = baos.toByteArray();
-
- } // end try
- catch( java.io.IOException e ) {
- e.printStackTrace();
- // Just return originally-decoded bytes
- } // end catch
- finally {
- try{ baos.close(); } catch( Exception e ){}
- try{ gzis.close(); } catch( Exception e ){}
- try{ bais.close(); } catch( Exception e ){}
- } // end finally
-
- } // end if: gzipped
- } // end if: bytes.length >= 2
-
- return bytes;
- } // end decode
-
-} // end class Base64
diff --git a/api/src/main/java/com/messagebird/Request.java b/api/src/main/java/com/messagebird/Request.java
deleted file mode 100644
index 41d9283b..00000000
--- a/api/src/main/java/com/messagebird/Request.java
+++ /dev/null
@@ -1,55 +0,0 @@
-package com.messagebird;
-
-import java.util.Arrays;
-
-/**
- * Holds request data needed to calculate a signature hash for incoming
- * webhooks.
- */
-public class Request {
-
- private final String timestamp;
- private final String queryParameters;
- private final byte[] data;
-
- private final static String QUERY_PARAMETERS_DELIMITER = "&";
-
- /**
- * Constructs a new request instance.
- *
- * @param timestamp Timestamp provided in the MessageBird-Request-Timestamp
- * header.
- * @param queryParameters Query parameters in abc=foo&def=ghi format.
- * @param data Raw body of this request.
- */
- public Request(String timestamp, String queryParameters, byte[] data) {
- if (timestamp == null || timestamp.isEmpty()) {
- throw new IllegalArgumentException("Timestamp can not be null or empty");
- }
-
- this.timestamp = timestamp;
- this.queryParameters = queryParameters;
- this.data = data;
- }
-
- String getTimestamp() {
- return timestamp;
- }
-
- String getSortedQueryParameters() {
- String[] params = queryParameters.split(QUERY_PARAMETERS_DELIMITER);
- Arrays.sort(params);
- StringBuilder sortedParamsAccumulator = new StringBuilder();
- for (int i = 0, paramsLength = params.length; i < paramsLength; i++) {
- sortedParamsAccumulator.append(params[i]);
- if (i < paramsLength - 1) {
- sortedParamsAccumulator.append(QUERY_PARAMETERS_DELIMITER);
- }
- }
- return sortedParamsAccumulator.toString();
- }
-
- byte[] getData() {
- return data;
- }
-}
diff --git a/api/src/main/java/com/messagebird/RequestSigner.java b/api/src/main/java/com/messagebird/RequestSigner.java
deleted file mode 100644
index e2f91d93..00000000
--- a/api/src/main/java/com/messagebird/RequestSigner.java
+++ /dev/null
@@ -1,118 +0,0 @@
-package com.messagebird;
-
-import com.messagebird.exceptions.RequestSigningException;
-
-import javax.crypto.Mac;
-import javax.crypto.spec.SecretKeySpec;
-import java.io.IOException;
-import java.nio.charset.Charset;
-import java.nio.charset.StandardCharsets;
-import java.security.InvalidKeyException;
-import java.security.MessageDigest;
-import java.security.NoSuchAlgorithmException;
-import java.util.Arrays;
-
-/**
- * RequestSigner is used to verify HTTP requests and is an implementation of:
- * https://developers.messagebird.com/docs/verify-http-requests. Retrieve your
- * signing key at https://dashboard.messagebird.com/developers/settings.
- */
-public class RequestSigner {
-
- private static final String ALGORITHM_SHA256 = "SHA-256";
- private static final String ALGORITHM_HMAC_SHA256 = "HmacSHA256";
- private static final Charset CHARSET_UTF8 = StandardCharsets.UTF_8;
-
- private SecretKeySpec secret;
-
- /**
- * Constructs a new RequestSigner instance.
- *
- * @param key Signing key. Can be retrieved through
- * https://dashboard.messagebird.com/developers/settings. This
- * is NOT your API key.
- */
- public RequestSigner(byte[] key) {
- this.secret = new SecretKeySpec(key, ALGORITHM_HMAC_SHA256);
- }
-
- /**
- * Computes the signature for the provided request and determines whether
- * it matches the expected signature (from the raw MessageBird-Signature header).
- *
- * @param expectedSignature Signature from the MessageBird-Signature
- * header in its original base64 encoded state.
- * @param request Request containing the values from the incoming webhook.
- * @return True if the computed signature matches the expected signature.
- */
- public boolean isMatch(String expectedSignature, Request request) {
- try {
- return isMatch(Base64.decode(expectedSignature), request);
- } catch (IOException e) {
- throw new RequestSigningException(e);
- }
- }
-
- /**
- * Computes the signature for the provided request and determines whether
- * it matches the expected signature
- *
- * @param expectedSignature Decoded (with base64) signature
- * from the MessageBird-Signature header
- * @param request Request containing the values from the incoming webhook.
- * @return True if the computed signature matches the expected signature.
- */
- public boolean isMatch(byte[] expectedSignature, Request request) {
- return Arrays.equals(computeSignature(request), expectedSignature);
- }
-
- /**
- * Computes the signature for a request instance.
- *
- * @param request Request to compute signature for.
- * @return HMAC-SHA2556 signature for the provided request.
- */
- private byte[] computeSignature(Request request) {
- String timestampAndQuery = request.getTimestamp() + '\n' +
- request.getSortedQueryParameters() + '\n';
-
- byte[] timestampAndQueryBytes = timestampAndQuery.getBytes(CHARSET_UTF8);
- byte[] bodyHashBytes = getSha256Hash(request.getData());
-
- return getHmacSha256Signature(appendArrays(timestampAndQueryBytes, bodyHashBytes));
- }
-
- private byte[] getSha256Hash(byte[] bytes) {
- try {
- return MessageDigest.getInstance(ALGORITHM_SHA256).digest(bytes);
- } catch (NoSuchAlgorithmException e) {
- throw new RequestSigningException(e);
- }
- }
-
- /**
- * Stitches the two arrays together and returns a new one.
- *
- * @param first Start of the new array.
- * @param second End of the new array.
- * @return New array based on first and second.
- */
- private byte[] appendArrays(byte[] first, byte[] second) {
- byte[] result = new byte[first.length + second.length];
- System.arraycopy(first, 0, result, 0, first.length);
- System.arraycopy(second, 0, result, first.length, second.length);
-
- return result;
- }
-
- private byte[] getHmacSha256Signature(byte[] bytes) {
- try {
- Mac mac = Mac.getInstance(ALGORITHM_HMAC_SHA256);
- mac.init(secret);
-
- return mac.doFinal(bytes);
- } catch (InvalidKeyException | NoSuchAlgorithmException e) {
- throw new RequestSigningException(e);
- }
- }
-}
diff --git a/api/src/main/java/com/messagebird/RequestValidator.java b/api/src/main/java/com/messagebird/RequestValidator.java
new file mode 100644
index 00000000..f585cf55
--- /dev/null
+++ b/api/src/main/java/com/messagebird/RequestValidator.java
@@ -0,0 +1,83 @@
+package com.messagebird;
+
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+
+import com.auth0.jwt.JWT;
+import com.auth0.jwt.JWTVerifier.BaseVerification;
+import com.auth0.jwt.algorithms.Algorithm;
+import com.auth0.jwt.exceptions.JWTVerificationException;
+import com.auth0.jwt.exceptions.SignatureVerificationException;
+import com.auth0.jwt.interfaces.Clock;
+import com.auth0.jwt.interfaces.DecodedJWT;
+import com.auth0.jwt.interfaces.JWTVerifier;
+import com.messagebird.exceptions.RequestValidationException;
+
+/**
+ * RequestValidator
+ */
+public class RequestValidator {
+
+ public static final String SIGNATURE_HEADER = "MessageBird-Signature-JWT";
+ private static final String ALGORITHM_SHA256 = "SHA-256";
+ public static final char[] HEX_DIGITS = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e',
+ 'f' };
+
+ private String signatureKey;
+
+ public RequestValidator(String signatureKey) {
+ this.signatureKey = signatureKey;
+ }
+
+ DecodedJWT validateSignature(Clock clock, String signature, String url, byte[] requestBody)
+ throws RequestValidationException {
+ Algorithm algorithmHS = Algorithm.HMAC256(this.signatureKey);
+ DecodedJWT jwt = JWT.decode(signature);
+ BaseVerification builder = (BaseVerification) JWT.require(algorithmHS).withIssuer("MessageBird").acceptLeeway(1)
+ .withClaim("url_hash", calculateSha256(url.getBytes()));
+
+ if (requestBody != null && requestBody.length > 0) {
+ builder.withClaim("payload_hash", calculateSha256(requestBody));
+ } else if (!jwt.getClaim("payload_hash").isNull()) {
+ throw new RequestValidationException("The Claim 'payload_hash' was set but no payload value.");
+ }
+
+ JWTVerifier verifier;
+ if (clock == null) {
+ verifier = builder.build();
+ } else {
+ verifier = builder.build(clock);
+ }
+
+ try {
+ return verifier.verify(jwt);
+ } catch (SignatureVerificationException e) {
+ throw new RequestValidationException("Signature is invalid.", e);
+ } catch (JWTVerificationException e) {
+ throw new RequestValidationException(e.getMessage());
+ }
+ }
+
+ public DecodedJWT validateSignature(String signature, String url, byte[] requestBody)
+ throws RequestValidationException {
+ return validateSignature(null, signature, url, requestBody);
+ }
+
+ private static String calculateSha256(byte[] bytes) {
+ try {
+ return encodeHex(MessageDigest.getInstance(ALGORITHM_SHA256).digest(bytes));
+ } catch (NoSuchAlgorithmException e) {
+ throw new RequestValidationException(e);
+ }
+ }
+
+ private static String encodeHex(final byte[] data) {
+ final int l = data.length;
+ final char[] out = new char[l << 1];
+ for (int i = 0, j = 0; i < l; i++) {
+ out[j++] = HEX_DIGITS[(0xF0 & data[i]) >>> 4];
+ out[j++] = HEX_DIGITS[0x0F & data[i]];
+ }
+ return new String(out);
+ }
+}
\ No newline at end of file
diff --git a/api/src/main/java/com/messagebird/exceptions/RequestSigningException.java b/api/src/main/java/com/messagebird/exceptions/RequestSigningException.java
deleted file mode 100644
index 9f993375..00000000
--- a/api/src/main/java/com/messagebird/exceptions/RequestSigningException.java
+++ /dev/null
@@ -1,18 +0,0 @@
-package com.messagebird.exceptions;
-
-/**
- * Thrown if an error occurs during request signing.
- */
-public class RequestSigningException extends RuntimeException {
-
- public RequestSigningException() {
- }
-
- public RequestSigningException(String message) {
- super(message);
- }
-
- public RequestSigningException(Throwable cause) {
- super(cause);
- }
-}
diff --git a/api/src/main/java/com/messagebird/exceptions/RequestValidationException.java b/api/src/main/java/com/messagebird/exceptions/RequestValidationException.java
new file mode 100644
index 00000000..f759b211
--- /dev/null
+++ b/api/src/main/java/com/messagebird/exceptions/RequestValidationException.java
@@ -0,0 +1,22 @@
+package com.messagebird.exceptions;
+
+/**
+ * Thrown if an error occurs during request signing.
+ */
+public class RequestValidationException extends RuntimeException {
+
+ public RequestValidationException() {
+ }
+
+ public RequestValidationException(String message) {
+ super(message);
+ }
+
+ public RequestValidationException(Throwable cause) {
+ super(cause);
+ }
+
+ public RequestValidationException(String message, Throwable cause) {
+ super(message, cause);
+ }
+}
diff --git a/api/src/test/java/com/messagebird/RequestSignerTest.java b/api/src/test/java/com/messagebird/RequestSignerTest.java
deleted file mode 100644
index 435ef1ce..00000000
--- a/api/src/test/java/com/messagebird/RequestSignerTest.java
+++ /dev/null
@@ -1,110 +0,0 @@
-package com.messagebird;
-
-import org.junit.Test;
-
-import java.nio.charset.StandardCharsets;
-
-import static org.junit.Assert.*;
-
-public class RequestSignerTest {
-
- /**
- * Helper to get the bytes the provided UTF-8 encoded string represents.
- */
- private static byte[] getBytes(String s) {
- return s.getBytes(StandardCharsets.UTF_8);
- }
-
- @Test
- public void testIsMatchEmptyQueryParamsAndEmptyData() {
- RequestSigner requestSigner = new RequestSigner(getBytes("secret"));
- String expectedSignature = "LISw4Je7n0/MkYDgVSzTJm8dW6BkytKTXMZZk1IElMs=";
- Request request = new Request("1544544948", "", getBytes(""));
-
- assertTrue(requestSigner.isMatch(expectedSignature, request));
- }
-
- @Test
- public void testIsMatchWithData() {
- RequestSigner requestSigner = new RequestSigner(getBytes("secret"));
- String expectedSignature = "p2e20OtAg39DEmz1ORHpjQ556U4o1ZaH4NWbM9Q8Qjk=";
- Request request = new Request("1544544948", "", getBytes("{\"a key\":\"some value\"}"));
-
- assertTrue(requestSigner.isMatch(expectedSignature, request));
- }
-
- @Test
- public void testIsMatchWithQueryParams() {
- RequestSigner requestSigner = new RequestSigner(getBytes("secret"));
- String expectedSignature = "Tfn+nRUBsn6lQgf6IpxBMS1j9lm7XsGjt5xh47M3jCk=";
- Request request = new Request("1544544948", "abc=foo&def=bar", getBytes(""));
-
- assertTrue(requestSigner.isMatch(expectedSignature, request));
- }
-
- @Test
- public void testIsMatchWithShuffledQueryParams() {
- RequestSigner requestSigner = new RequestSigner(getBytes("secret"));
- String expectedSignature = "Tfn+nRUBsn6lQgf6IpxBMS1j9lm7XsGjt5xh47M3jCk=";
- Request request = new Request("1544544948", "def=bar&abc=foo", getBytes(""));
-
- assertTrue(requestSigner.isMatch(expectedSignature, request));
- }
-
- @Test
- public void testIsMatchWithDataAndQueryParams() {
- RequestSigner requestSigner = new RequestSigner(getBytes("other-secret"));
- String expectedSignature = "orb0adPhRCYND1WCAvPBr+qjm4STGtyvNDIDNBZ4Ir4=";
- Request request = new Request("1544544948", "abc=foo&def=bar", getBytes("{\"a key\":\"some value\"}"));
-
- assertTrue(requestSigner.isMatch(expectedSignature, request));
- }
-
- @Test
- public void testIsNotMatch() {
- RequestSigner requestSigner = new RequestSigner(getBytes("secret"));
- String expectedSignature = "";
- Request request = new Request("1544544948", "abc=foo&def=bar", getBytes("{\"a key\":\"some value\"}"));
-
- assertFalse(requestSigner.isMatch(expectedSignature, request));
- }
-
- @Test
- public void testWithRealSignature() {
- /*
- * Here we use real signature from MessageBird webhook call
- */
-
- RequestSigner requestSigner = new RequestSigner(getBytes("Wb3N9gKeFf8ZoCzlOb5lJSic7bHLUcSu"));
- String requestSignature = "5Jha9Yyhwgc1nTsgJ9WyzeHilsuUumydICdf4LuIZE8=";
- String requestTimestamp = "1547036603";
- String requestParams = "id=57db52e04e2f4001b555f79813a0f503&mccmnc=20409&ported=0&recipient=31667788880&reference=curl&status=delivered&statusDatetime=2019-01-09T12%3A23%3A23%2B00%3A00";
- byte[] requestBody = new byte[0];
-
- String spoiledSignature = "5Jha9Yyhwgc1nTsgJ9WyzeHilsuUumydICdf4LUIZE8=";
- String spoiledTimestamp = "1547036605";
- String spoiledParams = "id=57db52e04e2f4001b555f79813a0f503&mccmnc=20409&ported=0&recipient=31667788880&reference=curvy&status=delivered&statusDatetime=2019-01-09T12%3A23%3A23%2B00%3A00";
- byte[] spoiledBody = getBytes("get shit spoiled");
-
- assertTrue(
- "Definitely valid signature is threaten as invalid",
- requestSigner.isMatch(requestSignature, new Request(requestTimestamp, requestParams, requestBody))
- );
- assertFalse(
- "Invalid signature is threaten as invalid",
- requestSigner.isMatch(spoiledSignature, new Request(requestTimestamp, requestParams, requestBody))
- );
- assertFalse(
- "Signature is still valid with replaced timestamp",
- requestSigner.isMatch(requestSignature, new Request(spoiledTimestamp, requestParams, requestBody))
- );
- assertFalse(
- "Signature is still valid with replaced params",
- requestSigner.isMatch(requestSignature, new Request(requestTimestamp, spoiledParams, requestBody))
- );
- assertFalse(
- "Signature is still valid with replaced body",
- requestSigner.isMatch(requestSignature, new Request(requestTimestamp, requestParams, spoiledBody))
- );
- }
-}
diff --git a/api/src/test/java/com/messagebird/RequestValidatorTest.java b/api/src/test/java/com/messagebird/RequestValidatorTest.java
new file mode 100644
index 00000000..6c19fde4
--- /dev/null
+++ b/api/src/test/java/com/messagebird/RequestValidatorTest.java
@@ -0,0 +1,165 @@
+package com.messagebird;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThrows;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
+
+import java.nio.charset.Charset;
+import java.time.OffsetDateTime;
+import java.util.Date;
+
+import com.auth0.jwt.interfaces.Clock;
+import com.messagebird.exceptions.RequestValidationException;
+
+import org.junit.Test;
+
+public class RequestValidatorTest {
+
+ private static final String TEST_SIGNATURE_KEY = "hunter2";
+
+ private static final String TEST_BASE_URL = "https://example.com";
+
+ @Test
+ public void testValidWithNoParamsBody() {
+ String signature = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJNZXNzYWdlQmlyZCIsImlhdCI6MTYyNTQ3OTIwMCwiZXhwIjoxNjI1NDc5MjYwLCJqdGkiOiI1OWEyNDRkYy1lOWFkLTRlMjMtOTc3OC0zNzFmYWEyMzhmNzIiLCJ1cmxfaGFzaCI6IjBmMTE1ZGIwNjJiN2MwZGQwMzBiMTY4NzhjOTlkZWE1YzM1NGI0OWRjMzdiMzhlYjg4NDYxNzljNzc4M2U5ZDcifQ.SrhlKJ-ES4Dg8BBXKtop3u92Z_k4L4VjHKsyHWpweGE";
+ String signatureKey = TEST_SIGNATURE_KEY;
+ String receivedAt = "2021-07-05T12:00:00+02:00";
+ String requestParams = "";
+ String requestPayload = "";
+
+ runTestValidateSignature(signature, signatureKey, receivedAt, requestParams, requestPayload);
+ }
+
+ @Test
+ public void testValidWithParamsAndWithoutBody() {
+ String signature = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJNZXNzYWdlQmlyZCIsImlhdCI6MTYyNTQ3OTIwMCwiZXhwIjoxNjI1NDc5MjYwLCJqdGkiOiJjOTQ2YWY3Ny1lMTgyLTRlYWEtYjJmZi0xYTU0NWI1ZTk5MWEiLCJ1cmxfaGFzaCI6IjQxZjA1ZjBkZGQwYTIyYWIyMDlhYzQ2ZjQ3YzQ1NzJkOWNlZmEyNTdlZDc0YjI0MDA0YmFlNzUzZWNlNmMyNjAifQ.wUeGukU50HcPIr8d-zcCpttlGnPE-W57ujVb36AbAYw";
+ String signatureKey = TEST_SIGNATURE_KEY;
+ String receivedAt = "2021-07-05T12:00:00+02:00";
+ String requestParams = "/path?bar=1&foo=2";
+ String requestPayload = "";
+
+ runTestValidateSignature(signature, signatureKey, receivedAt, requestParams, requestPayload);
+ }
+
+ @Test
+ public void testValidWithParamsAndBody() {
+ String signature = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJNZXNzYWdlQmlyZCIsImlhdCI6MTYyNTQ3OTIwMCwiZXhwIjoxNjI1NDc5MjYwLCJqdGkiOiI5M2U1NTAwNi1hMGU4LTQ1MjYtYTE5MC1mYTVmZjAwZWExMTYiLCJ1cmxfaGFzaCI6IjQxZjA1ZjBkZGQwYTIyYWIyMDlhYzQ2ZjQ3YzQ1NzJkOWNlZmEyNTdlZDc0YjI0MDA0YmFlNzUzZWNlNmMyNjAiLCJwYXlsb2FkX2hhc2giOiJkZmZkNjAyMWJiMmJkNWIwYWY2NzYyOTA4MDllYzNhNTMxOTFkZDgxYzdmNzBhNGIyODY4OGEzNjIxODI5ODZmIn0.K6HyLDRdYgQBKN2tBcu0dOSxsfb_lOLaWby3un4rxIc";
+ String signatureKey = TEST_SIGNATURE_KEY;
+ String receivedAt = "2021-07-05T12:00:00+02:00";
+ String requestParams = "/path?bar=1&foo=2";
+ String requestPayload = "Hello, World!";
+
+ runTestValidateSignature(signature, signatureKey, receivedAt, requestParams, requestPayload);
+ }
+
+ @Test
+ public void testInvalidTokenReceivedBeforeIssued() {
+ String signature = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJNZXNzYWdlQmlyZCIsImlhdCI6MTYyNTQ4MjgwMCwiZXhwIjoxNjI1NDgyODYwLCJqdGkiOiJmOWY4YzM4Mi0yNDQ5LTQzMTEtYjcyYi0xZGY3MTY4NzkzMWUiLCJ1cmxfaGFzaCI6IjBmMTE1ZGIwNjJiN2MwZGQwMzBiMTY4NzhjOTlkZWE1YzM1NGI0OWRjMzdiMzhlYjg4NDYxNzljNzc4M2U5ZDcifQ._59NNTg0j5YVXCRHgyeJAj8n6rTg1gwTh_I_coe7RDQ";
+ String signatureKey = TEST_SIGNATURE_KEY;
+ String receivedAt = "2021-07-05T12:00:00+02:00";
+ String requestParams = "";
+ String requestPayload = "";
+
+ RequestValidationException e = assertThrows(RequestValidationException.class,
+ () -> runTestValidateSignature(signature, signatureKey, receivedAt, requestParams, requestPayload));
+ assertTrue(e.getMessage().contains("The Token can't be used before"));
+ }
+
+ @Test
+ public void testInvalidTokenReceivedAfterExpired() {
+ String signature = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJNZXNzYWdlQmlyZCIsImlhdCI6MTYyNTQ3NTYwMCwiZXhwIjoxNjI1NDc1NjYwLCJqdGkiOiI1ZjAyZjUyMi02MDMwLTQ2YzgtYjVhMy0wMTI0NjQ3OGQ4YmMiLCJ1cmxfaGFzaCI6IjBmMTE1ZGIwNjJiN2MwZGQwMzBiMTY4NzhjOTlkZWE1YzM1NGI0OWRjMzdiMzhlYjg4NDYxNzljNzc4M2U5ZDcifQ.iGUCLsYVQG4iYWe2MkRoLQBBMzq7p_bLy4u0mhC3Jfc";
+ String signatureKey = TEST_SIGNATURE_KEY;
+ String receivedAt = "2021-07-05T12:00:00+02:00";
+ String requestParams = "";
+ String requestPayload = "";
+
+ RequestValidationException e = assertThrows(RequestValidationException.class,
+ () -> runTestValidateSignature(signature, signatureKey, receivedAt, requestParams, requestPayload));
+ assertTrue(e.getMessage().contains("The Token has expired"));
+ }
+
+ @Test
+ public void testInvalidTokenReceivedOnDifferentURL() {
+ String signature = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJNZXNzYWdlQmlyZCIsImlhdCI6MTYyNTQ3OTIwMCwiZXhwIjoxNjI1NDc5MjYwLCJqdGkiOiJhNzVjOTA5Ni1lODIzLTQ0MmItODVmMi03ZDNjOWQ5YjcyNmIiLCJ1cmxfaGFzaCI6IjlmZGExZmNkYzc0YjEwMzUzNjhlNWY2NjhmNTdjOTFlOTk0MTJmZjU5Y2YwM2E0NmNlYjk1YWVhNWU2YjU4ZmQifQ.G4lpxrDOxZs75G1vIJ6J1jVbYS19tx2yq-lkIE-oETY";
+ String signatureKey = TEST_SIGNATURE_KEY;
+ String receivedAt = "2021-07-05T12:00:00+02:00";
+ String requestParams = "";
+ String requestPayload = "";
+
+ RequestValidationException e = assertThrows(RequestValidationException.class,
+ () -> runTestValidateSignature(signature, signatureKey, receivedAt, requestParams, requestPayload));
+ assertEquals("The Claim 'url_hash' value doesn't match the required one.", e.getMessage());
+ }
+
+ @Test
+ public void testInvalidPayloadNotMatch() {
+ String signature = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJNZXNzYWdlQmlyZCIsImlhdCI6MTYyNTQ3OTIwMCwiZXhwIjoxNjI1NDc5MjYwLCJqdGkiOiIxNDUwMTUzMi05NmYyLTQ2ODQtOTgzMi02OGYwOTUxYWUzNDIiLCJ1cmxfaGFzaCI6IjBmMTE1ZGIwNjJiN2MwZGQwMzBiMTY4NzhjOTlkZWE1YzM1NGI0OWRjMzdiMzhlYjg4NDYxNzljNzc4M2U5ZDciLCJwYXlsb2FkX2hhc2giOiIzMjRjYzA2N2IyNTdlZGEwYmNiZDljOGQ4MTgwNzdhMDlhOTU2OGMwZDRjYTA2MDM4ZGVkOGZhZGRmODEzZmQ2In0.rQqiANogDOMafgg_B6p362PuhInAro9lMm2j_vruBA0";
+ String signatureKey = TEST_SIGNATURE_KEY;
+ String receivedAt = "2021-07-05T12:00:00+02:00";
+ String requestParams = "";
+ String requestPayload = "Hello, World!";
+
+ RequestValidationException e = assertThrows(RequestValidationException.class,
+ () -> runTestValidateSignature(signature, signatureKey, receivedAt, requestParams, requestPayload));
+ assertEquals("The Claim 'payload_hash' value doesn't match the required one.", e.getMessage());
+ }
+
+ @Test
+ public void testInvalidSignatureKey() {
+ String signature = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJNZXNzYWdlQmlyZCIsImlhdCI6MTYyNTQ3OTIwMCwiZXhwIjoxNjI1NDc5MjYwLCJqdGkiOiIyNDNjMjdhZS0yZjAyLTQ2YTAtODg1Mi1jNjZmMzdlYTlmNDYiLCJ1cmxfaGFzaCI6IjBmMTE1ZGIwNjJiN2MwZGQwMzBiMTY4NzhjOTlkZWE1YzM1NGI0OWRjMzdiMzhlYjg4NDYxNzljNzc4M2U5ZDcifQ._Uwf4HMtfAT6jvbBbh85Q9TunX0QlsXoaLGKX0I4VDg";
+ String signatureKey = TEST_SIGNATURE_KEY;
+ String receivedAt = "2021-07-05T12:00:00+02:00";
+ String requestParams = "";
+ String requestPayload = "Hello, World!";
+
+ RequestValidationException e = assertThrows(RequestValidationException.class,
+ () -> runTestValidateSignature(signature, signatureKey, receivedAt, requestParams, requestPayload));
+
+ assertEquals("Signature is invalid.", e.getMessage());
+ }
+
+ @Test
+ public void testInvalidMissingPayload() {
+ String signature = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJNZXNzYWdlQmlyZCIsImlhdCI6MTYyNTQ3OTIwMCwiZXhwIjoxNjI1NDc5MjYwLCJqdGkiOiIxNDUwMTUzMi05NmYyLTQ2ODQtOTgzMi02OGYwOTUxYWUzNDIiLCJ1cmxfaGFzaCI6IjBmMTE1ZGIwNjJiN2MwZGQwMzBiMTY4NzhjOTlkZWE1YzM1NGI0OWRjMzdiMzhlYjg4NDYxNzljNzc4M2U5ZDciLCJwYXlsb2FkX2hhc2giOiIzMjRjYzA2N2IyNTdlZGEwYmNiZDljOGQ4MTgwNzdhMDlhOTU2OGMwZDRjYTA2MDM4ZGVkOGZhZGRmODEzZmQ2In0.rQqiANogDOMafgg_B6p362PuhInAro9lMm2j_vruBA0";
+ String signatureKey = TEST_SIGNATURE_KEY;
+ String receivedAt = "2021-07-05T12:00:00+02:00";
+ String requestParams = "";
+ String requestPayload = "";
+
+ RequestValidationException e = assertThrows(RequestValidationException.class,
+ () -> runTestValidateSignature(signature, signatureKey, receivedAt, requestParams, requestPayload));
+ assertEquals("The Claim 'payload_hash' was set but no payload value.", e.getMessage());
+ }
+
+ @Test
+ public void testInvalidUnexpectedPayload() {
+ String signature = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJNZXNzYWdlQmlyZCIsImlhdCI6MTYyNTQ3OTIwMCwiZXhwIjoxNjI1NDc5MjYwLCJqdGkiOiI1OWEyNDRkYy1lOWFkLTRlMjMtOTc3OC0zNzFmYWEyMzhmNzIiLCJ1cmxfaGFzaCI6IjBmMTE1ZGIwNjJiN2MwZGQwMzBiMTY4NzhjOTlkZWE1YzM1NGI0OWRjMzdiMzhlYjg4NDYxNzljNzc4M2U5ZDcifQ.SrhlKJ-ES4Dg8BBXKtop3u92Z_k4L4VjHKsyHWpweGE";
+ String signatureKey = TEST_SIGNATURE_KEY;
+ String receivedAt = "2021-07-05T12:00:00+02:00";
+ String requestParams = "";
+ String requestPayload = "Hello, World!";
+
+ RequestValidationException e = assertThrows(RequestValidationException.class,
+ () -> runTestValidateSignature(signature, signatureKey, receivedAt, requestParams, requestPayload));
+ assertEquals("The Claim 'payload_hash' value doesn't match the required one.", e.getMessage());
+ }
+
+ private void runTestValidateSignature(String signature, String signatureKey, String receivedAt,
+ String requestParams, String requestPayload) {
+ String reqUrl = TEST_BASE_URL + requestParams;
+ if (requestParams == "") {
+ reqUrl += "/";
+ }
+
+ RequestValidator validator = new RequestValidator(signatureKey);
+
+ Clock clock = mock(Clock.class);
+ Date clockDate = spy(Date.from(OffsetDateTime.parse(receivedAt).toInstant()));
+ when(clock.getToday()).thenReturn(clockDate);
+
+ validator.validateSignature(clock, signature, reqUrl, requestPayload.getBytes(Charset.forName("UTF-8")));
+ }
+}
From 4595214371d47cacc6b900e86021bc42863c814a Mon Sep 17 00:00:00 2001
From: "khanh.nguyen"
Date: Thu, 22 Jul 2021 17:32:39 +0200
Subject: [PATCH 002/216] Add test data for request validator unittest.
---
.../com/messagebird/RequestValidator.java | 22 +-
.../com/messagebird/RequestValidatorTest.java | 200 +++---
api/src/test/resources/webhook_test_data.json | 567 ++++++++++++++++++
3 files changed, 657 insertions(+), 132 deletions(-)
create mode 100644 api/src/test/resources/webhook_test_data.json
diff --git a/api/src/main/java/com/messagebird/RequestValidator.java b/api/src/main/java/com/messagebird/RequestValidator.java
index f585cf55..bf7a9451 100644
--- a/api/src/main/java/com/messagebird/RequestValidator.java
+++ b/api/src/main/java/com/messagebird/RequestValidator.java
@@ -23,23 +23,33 @@ public class RequestValidator {
public static final char[] HEX_DIGITS = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e',
'f' };
- private String signatureKey;
+ private final Algorithm algorithm;
public RequestValidator(String signatureKey) {
- this.signatureKey = signatureKey;
+ this.algorithm = Algorithm.HMAC256(signatureKey);
+ }
+
+ public RequestValidator(byte[] signatureKey) {
+ this.algorithm = Algorithm.HMAC256(signatureKey);
}
DecodedJWT validateSignature(Clock clock, String signature, String url, byte[] requestBody)
throws RequestValidationException {
- Algorithm algorithmHS = Algorithm.HMAC256(this.signatureKey);
DecodedJWT jwt = JWT.decode(signature);
- BaseVerification builder = (BaseVerification) JWT.require(algorithmHS).withIssuer("MessageBird").acceptLeeway(1)
+ BaseVerification builder = (BaseVerification) JWT.require(this.algorithm)
+ .withIssuer("MessageBird")
+ .acceptLeeway(1)
.withClaim("url_hash", calculateSha256(url.getBytes()));
+ boolean payloadHashClaimExist = !jwt.getClaim("payload_hash").isNull();
+
if (requestBody != null && requestBody.length > 0) {
+ if (!payloadHashClaimExist) {
+ throw new RequestValidationException("The Claim 'payload_hash' is not set but payload is present.");
+ }
builder.withClaim("payload_hash", calculateSha256(requestBody));
- } else if (!jwt.getClaim("payload_hash").isNull()) {
- throw new RequestValidationException("The Claim 'payload_hash' was set but no payload value.");
+ } else if (payloadHashClaimExist) {
+ throw new RequestValidationException("The Claim 'payload_hash' is set but actual payload is missing.");
}
JWTVerifier verifier;
diff --git a/api/src/test/java/com/messagebird/RequestValidatorTest.java b/api/src/test/java/com/messagebird/RequestValidatorTest.java
index 6c19fde4..2101b1c1 100644
--- a/api/src/test/java/com/messagebird/RequestValidatorTest.java
+++ b/api/src/test/java/com/messagebird/RequestValidatorTest.java
@@ -1,165 +1,113 @@
package com.messagebird;
-import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
+import java.io.IOException;
import java.nio.charset.Charset;
import java.time.OffsetDateTime;
+import java.util.Collection;
import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+import javax.annotation.Resources;
import com.auth0.jwt.interfaces.Clock;
+import com.fasterxml.jackson.core.JsonParseException;
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.JsonMappingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
import com.messagebird.exceptions.RequestValidationException;
import org.junit.Test;
+import org.junit.function.ThrowingRunnable;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+@RunWith(Parameterized.class)
public class RequestValidatorTest {
- private static final String TEST_SIGNATURE_KEY = "hunter2";
-
- private static final String TEST_BASE_URL = "https://example.com";
-
- @Test
- public void testValidWithNoParamsBody() {
- String signature = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJNZXNzYWdlQmlyZCIsImlhdCI6MTYyNTQ3OTIwMCwiZXhwIjoxNjI1NDc5MjYwLCJqdGkiOiI1OWEyNDRkYy1lOWFkLTRlMjMtOTc3OC0zNzFmYWEyMzhmNzIiLCJ1cmxfaGFzaCI6IjBmMTE1ZGIwNjJiN2MwZGQwMzBiMTY4NzhjOTlkZWE1YzM1NGI0OWRjMzdiMzhlYjg4NDYxNzljNzc4M2U5ZDcifQ.SrhlKJ-ES4Dg8BBXKtop3u92Z_k4L4VjHKsyHWpweGE";
- String signatureKey = TEST_SIGNATURE_KEY;
- String receivedAt = "2021-07-05T12:00:00+02:00";
- String requestParams = "";
- String requestPayload = "";
-
- runTestValidateSignature(signature, signatureKey, receivedAt, requestParams, requestPayload);
+ /**
+ * WebhookSignatureTestCase
+ */
+ public static class WebhookSignatureTestCase {
+ public String name;
+ public String method;
+ public String secret;
+ public String url;
+ public String payload;
+ public String timestamp;
+ public String token;
+ public String outcome;
}
- @Test
- public void testValidWithParamsAndWithoutBody() {
- String signature = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJNZXNzYWdlQmlyZCIsImlhdCI6MTYyNTQ3OTIwMCwiZXhwIjoxNjI1NDc5MjYwLCJqdGkiOiJjOTQ2YWY3Ny1lMTgyLTRlYWEtYjJmZi0xYTU0NWI1ZTk5MWEiLCJ1cmxfaGFzaCI6IjQxZjA1ZjBkZGQwYTIyYWIyMDlhYzQ2ZjQ3YzQ1NzJkOWNlZmEyNTdlZDc0YjI0MDA0YmFlNzUzZWNlNmMyNjAifQ.wUeGukU50HcPIr8d-zcCpttlGnPE-W57ujVb36AbAYw";
- String signatureKey = TEST_SIGNATURE_KEY;
- String receivedAt = "2021-07-05T12:00:00+02:00";
- String requestParams = "/path?bar=1&foo=2";
- String requestPayload = "";
-
- runTestValidateSignature(signature, signatureKey, receivedAt, requestParams, requestPayload);
- }
+ /**
+ * Error Map that maps test data expected outcome to actual error message.
+ */
+ private static final Map ERROR_MAP = new HashMap() {
+ {
+ put("invalid jwt: claim iat is in the future", "The Token can't be used before");
+ put("invalid jwt: claim exp is in the past", "The Token has expired on");
+ put("invalid jwt: claim url_hash is invalid", "The Claim 'url_hash' value doesn't match the required one.");
+ put("invalid jwt: claim payload_hash is invalid",
+ "The Claim 'payload_hash' value doesn't match the required one.");
+ put("invalid jwt: signature is invalid", "Signature is invalid.");
+ put("invalid jwt: claim payload_hash is set but actual payload is missing",
+ "The Claim 'payload_hash' is set but actual payload is missing.");
+ put("invalid jwt: claim payload_hash is not set but payload is present",
+ "The Claim 'payload_hash' is not set but payload is present.");
- @Test
- public void testValidWithParamsAndBody() {
- String signature = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJNZXNzYWdlQmlyZCIsImlhdCI6MTYyNTQ3OTIwMCwiZXhwIjoxNjI1NDc5MjYwLCJqdGkiOiI5M2U1NTAwNi1hMGU4LTQ1MjYtYTE5MC1mYTVmZjAwZWExMTYiLCJ1cmxfaGFzaCI6IjQxZjA1ZjBkZGQwYTIyYWIyMDlhYzQ2ZjQ3YzQ1NzJkOWNlZmEyNTdlZDc0YjI0MDA0YmFlNzUzZWNlNmMyNjAiLCJwYXlsb2FkX2hhc2giOiJkZmZkNjAyMWJiMmJkNWIwYWY2NzYyOTA4MDllYzNhNTMxOTFkZDgxYzdmNzBhNGIyODY4OGEzNjIxODI5ODZmIn0.K6HyLDRdYgQBKN2tBcu0dOSxsfb_lOLaWby3un4rxIc";
- String signatureKey = TEST_SIGNATURE_KEY;
- String receivedAt = "2021-07-05T12:00:00+02:00";
- String requestParams = "/path?bar=1&foo=2";
- String requestPayload = "Hello, World!";
-
- runTestValidateSignature(signature, signatureKey, receivedAt, requestParams, requestPayload);
- }
+ }
+ };
- @Test
- public void testInvalidTokenReceivedBeforeIssued() {
- String signature = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJNZXNzYWdlQmlyZCIsImlhdCI6MTYyNTQ4MjgwMCwiZXhwIjoxNjI1NDgyODYwLCJqdGkiOiJmOWY4YzM4Mi0yNDQ5LTQzMTEtYjcyYi0xZGY3MTY4NzkzMWUiLCJ1cmxfaGFzaCI6IjBmMTE1ZGIwNjJiN2MwZGQwMzBiMTY4NzhjOTlkZWE1YzM1NGI0OWRjMzdiMzhlYjg4NDYxNzljNzc4M2U5ZDcifQ._59NNTg0j5YVXCRHgyeJAj8n6rTg1gwTh_I_coe7RDQ";
- String signatureKey = TEST_SIGNATURE_KEY;
- String receivedAt = "2021-07-05T12:00:00+02:00";
- String requestParams = "";
- String requestPayload = "";
-
- RequestValidationException e = assertThrows(RequestValidationException.class,
- () -> runTestValidateSignature(signature, signatureKey, receivedAt, requestParams, requestPayload));
- assertTrue(e.getMessage().contains("The Token can't be used before"));
- }
+ private final WebhookSignatureTestCase testCase;
- @Test
- public void testInvalidTokenReceivedAfterExpired() {
- String signature = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJNZXNzYWdlQmlyZCIsImlhdCI6MTYyNTQ3NTYwMCwiZXhwIjoxNjI1NDc1NjYwLCJqdGkiOiI1ZjAyZjUyMi02MDMwLTQ2YzgtYjVhMy0wMTI0NjQ3OGQ4YmMiLCJ1cmxfaGFzaCI6IjBmMTE1ZGIwNjJiN2MwZGQwMzBiMTY4NzhjOTlkZWE1YzM1NGI0OWRjMzdiMzhlYjg4NDYxNzljNzc4M2U5ZDcifQ.iGUCLsYVQG4iYWe2MkRoLQBBMzq7p_bLy4u0mhC3Jfc";
- String signatureKey = TEST_SIGNATURE_KEY;
- String receivedAt = "2021-07-05T12:00:00+02:00";
- String requestParams = "";
- String requestPayload = "";
-
- RequestValidationException e = assertThrows(RequestValidationException.class,
- () -> runTestValidateSignature(signature, signatureKey, receivedAt, requestParams, requestPayload));
- assertTrue(e.getMessage().contains("The Token has expired"));
+ public RequestValidatorTest(String testName, WebhookSignatureTestCase testCase) {
+ this.testCase = testCase;
}
- @Test
- public void testInvalidTokenReceivedOnDifferentURL() {
- String signature = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJNZXNzYWdlQmlyZCIsImlhdCI6MTYyNTQ3OTIwMCwiZXhwIjoxNjI1NDc5MjYwLCJqdGkiOiJhNzVjOTA5Ni1lODIzLTQ0MmItODVmMi03ZDNjOWQ5YjcyNmIiLCJ1cmxfaGFzaCI6IjlmZGExZmNkYzc0YjEwMzUzNjhlNWY2NjhmNTdjOTFlOTk0MTJmZjU5Y2YwM2E0NmNlYjk1YWVhNWU2YjU4ZmQifQ.G4lpxrDOxZs75G1vIJ6J1jVbYS19tx2yq-lkIE-oETY";
- String signatureKey = TEST_SIGNATURE_KEY;
- String receivedAt = "2021-07-05T12:00:00+02:00";
- String requestParams = "";
- String requestPayload = "";
-
- RequestValidationException e = assertThrows(RequestValidationException.class,
- () -> runTestValidateSignature(signature, signatureKey, receivedAt, requestParams, requestPayload));
- assertEquals("The Claim 'url_hash' value doesn't match the required one.", e.getMessage());
- }
+ @Parameters(name = "{0}")
+ public static Collection
*
- *
"url_hash" - the raw URL hashed with SHA256 ensuring the URL wasn't altered (validated by default)
- *
"payload_hash" - the raw payload hashed with SHA256 ensuring the payload wasn't altered (validated by default)
- *
"jti" - a unique token ID to implement an optional non-replay check (NOT validated by default)
- *
"nbf" - the not before timestamp (validated by default)
- *
"exp" - the expiration timestamp is ensuring that a request isn't captured and used at a later time. (validated by default)
- *
"iss" - the issuer name, always MessageBird (validated by default)
+ *
"url_hash" - the raw URL hashed with SHA256 ensuring the URL wasn't altered.
+ *
"payload_hash" - the raw payload hashed with SHA256 ensuring the payload wasn't altered.
+ *
"jti" - a unique token ID to implement an optional non-replay check (NOT validated by default).
+ *
"nbf" - the not before timestamp.
+ *
"exp" - the expiration timestamp is ensuring that a request isn't captured and used at a later time.
+ *
"iss" - the issuer name, always MessageBird.
*
*
* @param clock custom {@link Clock} instance to validate timestamp claims.
* @param signature the actual signature.
- * @param url the raw url including the protocol, hostname and query string, https://example.com/?example=42.
+ * @param url the raw url including the protocol, hostname and query string,
+ * {@code https://example.com/?example=42}.
* @param requestBody the raw request body.
* @return raw signature payload as {@link DecodedJWT} object.
* @throws RequestValidationException when the signature is invalid.
+ * @see Verify HTTP Requests
*/
public DecodedJWT validateSignature(Clock clock, String signature, String url, byte[] requestBody)
throws RequestValidationException {
+ if (signature == null || signature.length() == 0)
+ throw new RequestValidationException("The signature can not be empty.");
+
+ if (!skipURLValidation && (url == null || url.length() == 0))
+ throw new RequestValidationException("The url can not be empty.");
+
DecodedJWT jwt = JWT.decode(signature);
Algorithm algorithm;
@@ -86,11 +123,12 @@ public DecodedJWT validateSignature(Clock clock, String signature, String url, b
BaseVerification builder = (BaseVerification) JWT.require(algorithm)
.withIssuer("MessageBird")
.ignoreIssuedAt()
- .acceptLeeway(1)
- .withClaim("url_hash", calculateSha256(url.getBytes()));
+ .acceptLeeway(1);
- boolean payloadHashClaimExist = !jwt.getClaim("payload_hash").isNull();
+ if (!skipURLValidation)
+ builder.withClaim("url_hash", calculateSha256(url.getBytes()));
+ boolean payloadHashClaimExist = !jwt.getClaim("payload_hash").isNull();
if (requestBody != null && requestBody.length > 0) {
if (!payloadHashClaimExist) {
throw new RequestValidationException("The Claim 'payload_hash' is not set but payload is present.");
@@ -100,12 +138,7 @@ public DecodedJWT validateSignature(Clock clock, String signature, String url, b
throw new RequestValidationException("The Claim 'payload_hash' is set but actual payload is missing.");
}
- JWTVerifier verifier;
- if (clock == null) {
- verifier = builder.build();
- } else {
- verifier = builder.build(clock);
- }
+ JWTVerifier verifier = clock == null ? builder.build() : builder.build(clock);
try {
return verifier.verify(jwt);
@@ -119,29 +152,36 @@ public DecodedJWT validateSignature(Clock clock, String signature, String url, b
/**
* Returns raw signature payload after validating a signature successfully,
* otherwise throws {@code RequestValidationException}.
- *
- * This JWT is signed with a MessageBird account unique secret key, ensuring the request is from MessageBird and a specific account.
- * The JWT contains the following claims:
- *
- *
"url_hash" - the raw URL hashed with SHA256 ensuring the URL wasn't altered (validated by default)
- *
"payload_hash" - the raw payload hashed with SHA256 ensuring the payload wasn't altered (validated by default)
- *
"jti" - a unique token ID to implement an optional non-replay check (NOT validated by default)
- *
"nbf" - the not before timestamp (validated by default)
- *
"exp" - the expiration timestamp is ensuring that a request isn't captured and used at a later time. (validated by default)
- *
"iss" - the issuer name, always MessageBird (validated by default)
- *
*
* @param signature the actual signature.
- * @param url the raw url including the protocol, hostname and query string, https://example.com/?example=42.
+ * @param url the raw url including the protocol, hostname and query string,
+ * {@code https://example.com/?example=42}.
* @param requestBody the raw request body.
* @return raw signature payload as {@link DecodedJWT} object.
* @throws RequestValidationException when the signature is invalid.
+ * @see RequestValidator#validateSignature(Clock, String, String, byte[])
*/
public DecodedJWT validateSignature(String signature, String url, byte[] requestBody)
throws RequestValidationException {
return validateSignature(null, signature, url, requestBody);
}
+ /**
+ * Validates request signature with URL validation disabled.
+ * Note that no query parameters should be trusted and this only works if {@code RequestValidator} is constructed
+ * with {@code skipURLValidation} set to true.
+ *
+ * @param signature the actual signature.
+ * @param requestBody the raw request body.
+ * @return raw signature payload as {@link DecodedJWT} object.
+ * @throws RequestValidationException when the signature is invalid.
+ * @see RequestValidator#validateSignature(String, String, byte[])
+ */
+ public DecodedJWT validateSignature(String signature, byte[] requestBody)
+ throws RequestValidationException {
+ return validateSignature(null, signature, null, requestBody);
+ }
+
private static String calculateSha256(byte[] bytes) {
try {
return encodeHex(MessageDigest.getInstance(ALGORITHM_SHA256).digest(bytes));
diff --git a/examples/src/main/java/ExampleRequestSignatureValidation.java b/examples/src/main/java/ExampleRequestSignatureValidation.java
index 4c4dbe00..4f54297c 100644
--- a/examples/src/main/java/ExampleRequestSignatureValidation.java
+++ b/examples/src/main/java/ExampleRequestSignatureValidation.java
@@ -13,6 +13,7 @@
import java.io.IOException;
import java.net.InetSocketAddress;
+import java.net.URI;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.Map;
@@ -47,7 +48,7 @@
* *NOTE* you should use `Live` key for receiving webhooks
*
* Run this example as:
- * java -jar $MBEXAMPLEPORT test_accesskey test_secret $FORWARDING_URL/webhook
+ * java -jar $MBEXAMPLEPORT test_accesskey test_secret $FORWARDING_URL
*
* Now you able to play:
* send an SMS:
@@ -80,7 +81,8 @@ public static void main(String[] args) {
int serverPort = Integer.parseInt(args[0]);
String apiKey = args[1];
String apiSecret = args[2];
- URL reportURL = new URL(args[3]);
+ String forwardURL = args[3];
+ URL reportURL = new URL(forwardURL + "/webhook");
RequestValidator reqValidator = new RequestValidator(apiSecret);
@@ -89,7 +91,7 @@ public static void main(String[] args) {
final MessageBirdClient messageBirdClient = new MessageBirdClient(wsr);
HttpServer httpServer = HttpServer.create(new InetSocketAddress(serverPort), 0);
- httpServer.createContext("/webhook", new MessageBirdWebhookHandler(reqValidator));
+ httpServer.createContext("/webhook", new MessageBirdWebhookHandler(reqValidator, forwardURL));
httpServer.createContext("/send", new MessageBirdSender(messageBirdClient, reportURL));
@@ -108,9 +110,11 @@ public static void main(String[] args) {
static class MessageBirdWebhookHandler extends HttpHandlerHelpers implements HttpHandler {
private final RequestValidator reqValidator;
+ private final String baseURL;
- MessageBirdWebhookHandler(RequestValidator reqSigner) {
+ MessageBirdWebhookHandler(RequestValidator reqSigner, String baseURL) {
this.reqValidator = reqSigner;
+ this.baseURL = baseURL;
}
@Override
@@ -119,7 +123,7 @@ public void handle(HttpExchange he) throws IOException {
try {
String requestSignature = he.getRequestHeaders().getFirst(RequestValidator.SIGNATURE_HEADER);
- String requestURL = he.getRequestURI().toString();
+ String requestURL = URI.create(baseURL).resolve(he.getRequestURI()).toString();
byte[] requestBody = readAllBytes(he.getRequestBody());
printRequest(
From 44bf5ae6cc7ea163cfb74ff2f2ac17b21707315b Mon Sep 17 00:00:00 2001
From: "deniz@messagebird.com"
Date: Mon, 13 Sep 2021 16:23:51 +0200
Subject: [PATCH 008/216] added new classes for media template support
---
.../conversations/ConversationContentHsm.java | 14 +++-
.../objects/conversations/HSMCurrency.java | 31 +++++++
.../objects/conversations/Media.java | 31 +++++++
.../conversations/MessageComponent.java | 53 ++++++++++++
.../objects/conversations/MessageParam.java | 81 +++++++++++++++++++
.../conversations/TemplateMediaType.java | 46 +++++++++++
6 files changed, 255 insertions(+), 1 deletion(-)
create mode 100644 api/src/main/java/com/messagebird/objects/conversations/HSMCurrency.java
create mode 100644 api/src/main/java/com/messagebird/objects/conversations/Media.java
create mode 100644 api/src/main/java/com/messagebird/objects/conversations/MessageComponent.java
create mode 100644 api/src/main/java/com/messagebird/objects/conversations/MessageParam.java
create mode 100644 api/src/main/java/com/messagebird/objects/conversations/TemplateMediaType.java
diff --git a/api/src/main/java/com/messagebird/objects/conversations/ConversationContentHsm.java b/api/src/main/java/com/messagebird/objects/conversations/ConversationContentHsm.java
index 3da74c2c..824f7fc8 100644
--- a/api/src/main/java/com/messagebird/objects/conversations/ConversationContentHsm.java
+++ b/api/src/main/java/com/messagebird/objects/conversations/ConversationContentHsm.java
@@ -18,17 +18,20 @@ public class ConversationContentHsm {
private String templateName;
private ConversationHsmLanguage language;
private List params;
+ private List components;
public ConversationContentHsm(
final String namespace,
final String templateName,
final ConversationHsmLanguage language,
- final List params
+ final List params,
+ final List components
) {
this.namespace = namespace;
this.templateName = templateName;
this.language = language;
this.params = params;
+ this.components = components;
}
public ConversationContentHsm(
@@ -85,6 +88,14 @@ public void setParams(final List params) {
this.params = params;
}
+ public List getComponents() {
+ return components;
+ }
+
+ public void setComponents(List components) {
+ this.components = components;
+ }
+
@Override
public String toString() {
return "ConversationContentHsm{" +
@@ -92,6 +103,7 @@ public String toString() {
", templateName='" + templateName + '\'' +
", language=" + language +
", params=" + params +
+ ", components=" + components +
'}';
}
}
diff --git a/api/src/main/java/com/messagebird/objects/conversations/HSMCurrency.java b/api/src/main/java/com/messagebird/objects/conversations/HSMCurrency.java
new file mode 100644
index 00000000..24ea4be6
--- /dev/null
+++ b/api/src/main/java/com/messagebird/objects/conversations/HSMCurrency.java
@@ -0,0 +1,31 @@
+package com.messagebird.objects.conversations;
+
+public class HSMCurrency {
+
+ private String currencyCode;
+ private int amount;
+
+ public String getCurrencyCode() {
+ return currencyCode;
+ }
+
+ public void setCurrencyCode(String currencyCode) {
+ this.currencyCode = currencyCode;
+ }
+
+ public int getAmount() {
+ return amount;
+ }
+
+ public void setAmount(int amount) {
+ this.amount = amount;
+ }
+
+ @Override
+ public String toString() {
+ return "HSMCurrency{" +
+ "currencyCode='" + currencyCode + '\'' +
+ ", amount=" + amount +
+ '}';
+ }
+}
diff --git a/api/src/main/java/com/messagebird/objects/conversations/Media.java b/api/src/main/java/com/messagebird/objects/conversations/Media.java
new file mode 100644
index 00000000..4a9bf4ea
--- /dev/null
+++ b/api/src/main/java/com/messagebird/objects/conversations/Media.java
@@ -0,0 +1,31 @@
+package com.messagebird.objects.conversations;
+
+public class Media {
+
+ private String url;
+ private String caption;
+
+ public String getUrl() {
+ return url;
+ }
+
+ public void setUrl(String url) {
+ this.url = url;
+ }
+
+ public String getCaption() {
+ return caption;
+ }
+
+ public void setCaption(String caption) {
+ this.caption = caption;
+ }
+
+ @Override
+ public String toString() {
+ return "Media{" +
+ "url='" + url + '\'' +
+ ", caption='" + caption + '\'' +
+ '}';
+ }
+}
diff --git a/api/src/main/java/com/messagebird/objects/conversations/MessageComponent.java b/api/src/main/java/com/messagebird/objects/conversations/MessageComponent.java
new file mode 100644
index 00000000..22081acb
--- /dev/null
+++ b/api/src/main/java/com/messagebird/objects/conversations/MessageComponent.java
@@ -0,0 +1,53 @@
+package com.messagebird.objects.conversations;
+
+import java.util.List;
+
+public class MessageComponent {
+
+ private String type;
+ private String sub_type;
+ private int index;
+ private List parameters;
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ public String getSub_type() {
+ return sub_type;
+ }
+
+ public void setSub_type(String sub_type) {
+ this.sub_type = sub_type;
+ }
+
+ public int getIndex() {
+ return index;
+ }
+
+ public void setIndex(int index) {
+ this.index = index;
+ }
+
+ public List getParameters() {
+ return parameters;
+ }
+
+ public void setParameters(List parameters) {
+ this.parameters = parameters;
+ }
+
+ @Override
+ public String toString() {
+ return "MessageComponent{" +
+ "type='" + type + '\'' +
+ ", sub_type='" + sub_type + '\'' +
+ ", index=" + index +
+ ", parameters=" + parameters +
+ '}';
+ }
+}
diff --git a/api/src/main/java/com/messagebird/objects/conversations/MessageParam.java b/api/src/main/java/com/messagebird/objects/conversations/MessageParam.java
new file mode 100644
index 00000000..8de37ab7
--- /dev/null
+++ b/api/src/main/java/com/messagebird/objects/conversations/MessageParam.java
@@ -0,0 +1,81 @@
+package com.messagebird.objects.conversations;
+
+public class MessageParam {
+
+ private TemplateMediaType type;
+ private String text;
+ private String payload;
+ private HSMCurrency currency;
+ private String dateTime;
+ private Media document;
+ private Media image;
+
+ public TemplateMediaType getType() {
+ return type;
+ }
+
+ public void setType(TemplateMediaType type) {
+ this.type = type;
+ }
+
+ public String getText() {
+ return text;
+ }
+
+ public void setText(String text) {
+ this.text = text;
+ }
+
+ public String getPayload() {
+ return payload;
+ }
+
+ public void setPayload(String payload) {
+ this.payload = payload;
+ }
+
+ public HSMCurrency getCurrency() {
+ return currency;
+ }
+
+ public void setCurrency(HSMCurrency currency) {
+ this.currency = currency;
+ }
+
+ public String getDateTime() {
+ return dateTime;
+ }
+
+ public void setDateTime(String dateTime) {
+ this.dateTime = dateTime;
+ }
+
+ public Media getDocument() {
+ return document;
+ }
+
+ public void setDocument(Media document) {
+ this.document = document;
+ }
+
+ public Media getImage() {
+ return image;
+ }
+
+ public void setImage(Media image) {
+ this.image = image;
+ }
+
+ @Override
+ public String toString() {
+ return "MessageParam{" +
+ "type=" + type +
+ ", text='" + text + '\'' +
+ ", payload='" + payload + '\'' +
+ ", currency=" + currency +
+ ", dateTime='" + dateTime + '\'' +
+ ", document=" + document +
+ ", image=" + image +
+ '}';
+ }
+}
diff --git a/api/src/main/java/com/messagebird/objects/conversations/TemplateMediaType.java b/api/src/main/java/com/messagebird/objects/conversations/TemplateMediaType.java
new file mode 100644
index 00000000..51afa594
--- /dev/null
+++ b/api/src/main/java/com/messagebird/objects/conversations/TemplateMediaType.java
@@ -0,0 +1,46 @@
+package com.messagebird.objects.conversations;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonValue;
+
+public enum TemplateMediaType {
+
+ IMAGE("image"),
+ DOCUMENT("document"),
+ TEXT("text"),
+ CURRENCY("currency"),
+ DATETIME("date_time"),
+ PAYLOAD("payload");
+
+ private final String type;
+
+ TemplateMediaType(final String type) {
+ this.type = type;
+ }
+
+ @JsonCreator
+ public static TemplateMediaType forValue(String value) {
+ for (TemplateMediaType templateMediaType: TemplateMediaType.values()) {
+ if (templateMediaType.getType().equals(value)) {
+ return templateMediaType;
+ }
+ }
+
+ return null;
+ }
+
+ @JsonValue
+ public String toJson() {
+ return getType();
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ @Override
+ public String toString() {
+ return getType();
+ }
+
+}
\ No newline at end of file
From e308ca022156766540587d72897f81859854d618 Mon Sep 17 00:00:00 2001
From: cemturker
Date: Tue, 14 Sep 2021 13:47:37 +0300
Subject: [PATCH 009/216] Add example for HSM media template
---
.../conversations/MessageComponent.java | 10 +-
.../conversations/MessageComponentType.java | 44 ++++++++
...ampleConversationSendHSMMediaTemplate.java | 103 ++++++++++++++++++
3 files changed, 152 insertions(+), 5 deletions(-)
create mode 100644 api/src/main/java/com/messagebird/objects/conversations/MessageComponentType.java
create mode 100644 examples/src/main/java/ExampleConversationSendHSMMediaTemplate.java
diff --git a/api/src/main/java/com/messagebird/objects/conversations/MessageComponent.java b/api/src/main/java/com/messagebird/objects/conversations/MessageComponent.java
index 22081acb..9dd25b3a 100644
--- a/api/src/main/java/com/messagebird/objects/conversations/MessageComponent.java
+++ b/api/src/main/java/com/messagebird/objects/conversations/MessageComponent.java
@@ -4,17 +4,17 @@
public class MessageComponent {
- private String type;
+ private MessageComponentType type;
private String sub_type;
private int index;
private List parameters;
- public String getType() {
- return type;
+ public void setType(MessageComponentType type) {
+ this.type = type;
}
- public void setType(String type) {
- this.type = type;
+ public MessageComponentType getType() {
+ return type;
}
public String getSub_type() {
diff --git a/api/src/main/java/com/messagebird/objects/conversations/MessageComponentType.java b/api/src/main/java/com/messagebird/objects/conversations/MessageComponentType.java
new file mode 100644
index 00000000..073b5735
--- /dev/null
+++ b/api/src/main/java/com/messagebird/objects/conversations/MessageComponentType.java
@@ -0,0 +1,44 @@
+package com.messagebird.objects.conversations;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonValue;
+
+public enum MessageComponentType {
+
+ HEADER("header"),
+ BODY("body"),
+ FOOTER("footer"),
+ BUTTONS("buttons");
+
+
+ private final String type;
+
+ MessageComponentType(final String type) {
+ this.type = type;
+ }
+
+ @JsonCreator
+ public static MessageComponentType forValue(String value) {
+ for (MessageComponentType componentType: MessageComponentType.values()) {
+ if (componentType.getType().equals(value)) {
+ return componentType;
+ }
+ }
+
+ return null;
+ }
+
+ @JsonValue
+ public String toJson() {
+ return getType();
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ @Override
+ public String toString() {
+ return getType();
+ }
+}
diff --git a/examples/src/main/java/ExampleConversationSendHSMMediaTemplate.java b/examples/src/main/java/ExampleConversationSendHSMMediaTemplate.java
new file mode 100644
index 00000000..3f495aee
--- /dev/null
+++ b/examples/src/main/java/ExampleConversationSendHSMMediaTemplate.java
@@ -0,0 +1,103 @@
+import com.messagebird.MessageBirdClient;
+import com.messagebird.MessageBirdService;
+import com.messagebird.MessageBirdServiceImpl;
+import com.messagebird.exceptions.GeneralException;
+import com.messagebird.exceptions.UnauthorizedException;
+import com.messagebird.objects.conversations.ConversationContent;
+import com.messagebird.objects.conversations.ConversationContentHsm;
+import com.messagebird.objects.conversations.ConversationContentType;
+import com.messagebird.objects.conversations.ConversationHsmLanguage;
+import com.messagebird.objects.conversations.ConversationSendRequest;
+import com.messagebird.objects.conversations.ConversationSendResponse;
+import com.messagebird.objects.conversations.Media;
+import com.messagebird.objects.conversations.MessageComponent;
+import com.messagebird.objects.conversations.MessageComponentType;
+import com.messagebird.objects.conversations.MessageParam;
+import com.messagebird.objects.conversations.TemplateMediaType;
+import java.util.ArrayList;
+import java.util.List;
+
+public class ExampleConversationSendHSMMediaTemplate {
+
+ // Reference Example: https://developers.messagebird.com/quickstarts/whatsapp/send-media-template-message/
+ public static void main(String[] args) {
+
+ if (args.length < 4) {
+ System.out.println("Please at least specify your access key, the channel id and destination address.\n" +
+ "Usage : java -jar test_accesskey(Required) channel_id(Required) from(Required) to(Required)");
+ return;
+ }
+
+ //First create your service object
+ final MessageBirdService wsr = new MessageBirdServiceImpl(args[0]);
+ //Add the service to the client
+ final MessageBirdClient messageBirdClient = new MessageBirdClient(wsr);
+
+
+ ConversationContent conversationContent = new ConversationContent();
+ ConversationContentHsm conversationContentHsm = new ConversationContentHsm();
+ conversationContentHsm.setNamespace("20332cd4_f095_b080_d255_35677159aaff");
+ conversationContentHsm.setTemplateName("33172012024_ship_img_but_1");
+ ConversationHsmLanguage language = new ConversationHsmLanguage();
+ language.setCode("en");
+ conversationContentHsm.setLanguage(language);
+ List messageComponents = new ArrayList<>();
+ //Define header component with image
+ MessageComponent messageHeaderComponent = new MessageComponent();
+ messageHeaderComponent.setType(MessageComponentType.HEADER);
+ MessageParam imageParam = new MessageParam();
+ Media media = new Media();
+ media.setUrl("https://i.ytimg.com/vi/3fDoOw4lIeU/maxresdefault.jpg");
+ imageParam.setImage(media);
+ imageParam.setType(TemplateMediaType.IMAGE);
+ List messageHeaderParams = new ArrayList<>();
+ messageHeaderParams.add(imageParam);
+ messageHeaderComponent.setParameters(messageHeaderParams);
+ //Define body component with texts
+ MessageComponent messageBodyComponent = new MessageComponent();
+ messageBodyComponent.setType(MessageComponentType.BODY);
+ List messageBodyParams = new ArrayList<>();
+ messageBodyComponent.setParameters(messageBodyParams);
+ MessageParam firstText = new MessageParam();
+ firstText.setType(TemplateMediaType.TEXT);
+ firstText.setText("John");
+ messageBodyParams.add(firstText);
+
+ MessageParam secondText = new MessageParam();
+ secondText.setType(TemplateMediaType.TEXT);
+ secondText.setText("MB93824");
+ messageBodyParams.add(secondText);
+
+ MessageParam thirdText = new MessageParam();
+ thirdText.setType(TemplateMediaType.TEXT);
+ thirdText.setText("2 days");
+ messageBodyParams.add(thirdText);
+
+ MessageParam fourthText = new MessageParam();
+ fourthText.setType(TemplateMediaType.TEXT);
+ fourthText.setText("MessageBird");
+ messageBodyParams.add(fourthText);
+
+ messageComponents.add(messageHeaderComponent);
+ messageComponents.add(messageBodyComponent);
+ conversationContentHsm.setComponents(messageComponents);
+ conversationContent.setHsm(conversationContentHsm);
+ ConversationSendRequest request = new ConversationSendRequest(
+ args[2],
+ ConversationContentType.HSM,
+ conversationContent,
+ args[1],
+ "",
+ null,
+ null,
+ null);
+
+ try {
+ ConversationSendResponse sendResponse = messageBirdClient.sendMessage(request);
+ System.out.println(sendResponse.toString());
+
+ } catch (GeneralException | UnauthorizedException exception) {
+ exception.printStackTrace();
+ }
+ }
+}
From efa9070ac167cff4e51124a2245d50d1d753acc3 Mon Sep 17 00:00:00 2001
From: "deniz@messagebird.com"
Date: Tue, 14 Sep 2021 15:45:38 +0200
Subject: [PATCH 010/216] new release
---
api/pom.xml | 2 +-
api/src/main/java/com/messagebird/MessageBirdServiceImpl.java | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/api/pom.xml b/api/pom.xml
index 0f0ef660..89378e1b 100644
--- a/api/pom.xml
+++ b/api/pom.xml
@@ -4,7 +4,7 @@
com.messagebirdmessagebird-api
- 3.1.1
diff --git a/api/src/main/java/com/messagebird/MessageBirdServiceImpl.java b/api/src/main/java/com/messagebird/MessageBirdServiceImpl.java
index e31187b4..23850cf9 100644
--- a/api/src/main/java/com/messagebird/MessageBirdServiceImpl.java
+++ b/api/src/main/java/com/messagebird/MessageBirdServiceImpl.java
@@ -61,7 +61,7 @@ public class MessageBirdServiceImpl implements MessageBirdService {
private final String accessKey;
private final String serviceUrl;
- private final String clientVersion = "3.1.1";
+ private final String clientVersion = "3.1.2";
private final String userAgentString;
private Proxy proxy = null;
From 1fa7a2139d5107f1ab38ab1abbfd197959a3b85d Mon Sep 17 00:00:00 2001
From: "deniz@messagebird.com"
Date: Tue, 14 Sep 2021 15:46:18 +0200
Subject: [PATCH 011/216] [maven-release-plugin] prepare release v3.1.2
---
api/pom.xml | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/api/pom.xml b/api/pom.xml
index 89378e1b..ee0104f7 100644
--- a/api/pom.xml
+++ b/api/pom.xml
@@ -4,7 +4,7 @@
com.messagebirdmessagebird-api
- 3.1.2-SNAPSHOT
@@ -42,7 +42,7 @@
scm:git:git@github.com:messagebird/java-rest-api.gitscm:git:git@github.com:messagebird/java-rest-api.gitgit@github.com:messagebird/java-rest-api.git
- HEAD
+ v3.1.2
From ddf327b93ac0d4e88c76bfae9df9d45ed2933adc Mon Sep 17 00:00:00 2001
From: "deniz@messagebird.com"
Date: Tue, 14 Sep 2021 15:46:23 +0200
Subject: [PATCH 012/216] [maven-release-plugin] prepare for next development
iteration
---
api/pom.xml | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/api/pom.xml b/api/pom.xml
index ee0104f7..eba7bc41 100644
--- a/api/pom.xml
+++ b/api/pom.xml
@@ -4,7 +4,7 @@
com.messagebirdmessagebird-api
- 3.1.2
@@ -42,7 +42,7 @@
scm:git:git@github.com:messagebird/java-rest-api.gitscm:git:git@github.com:messagebird/java-rest-api.gitgit@github.com:messagebird/java-rest-api.git
- v3.1.2
+ HEAD
From ce8e0fde7f510b4705c36808eaa4e62136964c20 Mon Sep 17 00:00:00 2001
From: "deniz@messagebird.com"
Date: Wed, 15 Sep 2021 08:18:56 +0200
Subject: [PATCH 013/216] updated for the new release
---
api/pom.xml | 2 +-
examples/pom.xml | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/api/pom.xml b/api/pom.xml
index eba7bc41..47e53822 100644
--- a/api/pom.xml
+++ b/api/pom.xml
@@ -4,7 +4,7 @@
com.messagebirdmessagebird-api
- 3.1.3-SNAPSHOT
diff --git a/examples/pom.xml b/examples/pom.xml
index 6839c044..438522e7 100644
--- a/examples/pom.xml
+++ b/examples/pom.xml
@@ -6,7 +6,7 @@
com.messagebirdexamples
- 3.1.1
+ 3.1.2
@@ -20,7 +20,7 @@
com.messagebirdmessagebird-api
- 3.1.1
+ 3.1.2compile
From cbac7847010174d7b0dcaab987649fd45ca50587 Mon Sep 17 00:00:00 2001
From: ssk910
Date: Wed, 29 Sep 2021 17:22:42 +0900
Subject: [PATCH 014/216] feat: Add features for integrations API
Added missing features and examples as below:
- Create template
- List templates
- List templates by name
- Fetch template by name and language
- Delete templates by name
- Delete template by name and language
Reference: https://developers.messagebird.com/api/integrations/
Committed because java-rest-api SDK does not include integrations API.
Please feel free to refactor my codes.
Need to write unit test.
---
.../com/messagebird/MessageBirdClient.java | 180 +++++++++++++++++-
.../com/messagebird/MessageBirdService.java | 30 ++-
.../messagebird/MessageBirdServiceImpl.java | 51 +++--
.../objects/integrations/HSMCategory.java | 55 ++++++
.../objects/integrations/HSMComponent.java | 144 ++++++++++++++
.../integrations/HSMComponentButton.java | 89 +++++++++
.../integrations/HSMComponentButtonType.java | 48 +++++
.../integrations/HSMComponentFormat.java | 49 +++++
.../integrations/HSMComponentType.java | 47 +++++
.../objects/integrations/HSMExample.java | 54 ++++++
.../integrations/HSMRejectedReason.java | 51 +++++
.../objects/integrations/HSMStatus.java | 51 +++++
.../integrations/WhatsAppTemplate.java | 86 +++++++++
.../integrations/WhatsAppTemplateList.java | 12 ++
.../WhatsAppTemplateResponse.java | 105 ++++++++++
.../src/main/java/ExampleCreateTemplate.java | 97 ++++++++++
...xampleDeleteTemplateByNameAndLanguage.java | 40 ++++
.../java/ExampleDeleteTemplatesByName.java | 39 ++++
...ExampleFetchTemplateByNameAndLanguage.java | 41 ++++
.../src/main/java/ExampleListTemplates.java | 36 ++++
.../main/java/ExampleListTemplatesByName.java | 41 ++++
21 files changed, 1326 insertions(+), 20 deletions(-)
create mode 100644 api/src/main/java/com/messagebird/objects/integrations/HSMCategory.java
create mode 100644 api/src/main/java/com/messagebird/objects/integrations/HSMComponent.java
create mode 100644 api/src/main/java/com/messagebird/objects/integrations/HSMComponentButton.java
create mode 100644 api/src/main/java/com/messagebird/objects/integrations/HSMComponentButtonType.java
create mode 100644 api/src/main/java/com/messagebird/objects/integrations/HSMComponentFormat.java
create mode 100644 api/src/main/java/com/messagebird/objects/integrations/HSMComponentType.java
create mode 100644 api/src/main/java/com/messagebird/objects/integrations/HSMExample.java
create mode 100644 api/src/main/java/com/messagebird/objects/integrations/HSMRejectedReason.java
create mode 100644 api/src/main/java/com/messagebird/objects/integrations/HSMStatus.java
create mode 100644 api/src/main/java/com/messagebird/objects/integrations/WhatsAppTemplate.java
create mode 100644 api/src/main/java/com/messagebird/objects/integrations/WhatsAppTemplateList.java
create mode 100644 api/src/main/java/com/messagebird/objects/integrations/WhatsAppTemplateResponse.java
create mode 100644 examples/src/main/java/ExampleCreateTemplate.java
create mode 100644 examples/src/main/java/ExampleDeleteTemplateByNameAndLanguage.java
create mode 100644 examples/src/main/java/ExampleDeleteTemplatesByName.java
create mode 100644 examples/src/main/java/ExampleFetchTemplateByNameAndLanguage.java
create mode 100644 examples/src/main/java/ExampleListTemplates.java
create mode 100644 examples/src/main/java/ExampleListTemplatesByName.java
diff --git a/api/src/main/java/com/messagebird/MessageBirdClient.java b/api/src/main/java/com/messagebird/MessageBirdClient.java
index 0bff2580..317b02d4 100644
--- a/api/src/main/java/com/messagebird/MessageBirdClient.java
+++ b/api/src/main/java/com/messagebird/MessageBirdClient.java
@@ -24,8 +24,8 @@
import com.messagebird.objects.PhoneNumbersResponse;
import com.messagebird.objects.PurchasedNumber;
import com.messagebird.objects.PurchasedNumberCreatedResponse;
-import com.messagebird.objects.PurchasedNumbersResponse;
import com.messagebird.objects.PurchasedNumbersFilter;
+import com.messagebird.objects.PurchasedNumbersResponse;
import com.messagebird.objects.Verify;
import com.messagebird.objects.VerifyMessage;
import com.messagebird.objects.VerifyRequest;
@@ -46,6 +46,9 @@
import com.messagebird.objects.conversations.ConversationWebhookCreateRequest;
import com.messagebird.objects.conversations.ConversationWebhookList;
import com.messagebird.objects.conversations.ConversationWebhookUpdateRequest;
+import com.messagebird.objects.integrations.WhatsAppTemplate;
+import com.messagebird.objects.integrations.WhatsAppTemplateList;
+import com.messagebird.objects.integrations.WhatsAppTemplateResponse;
import com.messagebird.objects.voicecalls.RecordingResponse;
import com.messagebird.objects.voicecalls.TranscriptionResponse;
import com.messagebird.objects.voicecalls.VoiceCall;
@@ -59,20 +62,19 @@
import com.messagebird.objects.voicecalls.Webhook;
import com.messagebird.objects.voicecalls.WebhookList;
import com.messagebird.objects.voicecalls.WebhookResponseData;
-
import java.io.UnsupportedEncodingException;
import java.math.BigInteger;
-import java.nio.charset.StandardCharsets;
import java.net.URLEncoder;
+import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
-import java.util.HashSet;
/**
* Message bird general client
@@ -102,6 +104,8 @@ public class MessageBirdClient {
static final String VOICE_CALLS_BASE_URL = "https://voice.messagebird.com";
static final String NUMBERS_CALLS_BASE_URL = "https://numbers.messagebird.com/v1";
static final String MESSAGING_BASE_URL = "https://messaging.messagebird.com/v1";
+ static final String INTEGRATIONS_BASE_URL_V2 = "https://integrations.messagebird.com/v2";
+ static final String INTEGRATIONS_BASE_URL_V3 = "https://integrations.messagebird.com/v3";
private static String[] supportedLanguages = {"de-DE", "en-AU", "en-UK", "en-US", "es-ES", "es-LA", "fr-FR", "it-IT", "nl-NL", "pt-BR"};
private static final String BALANCEPATH = "/balance";
@@ -118,6 +122,7 @@ public class MessageBirdClient {
private static final String CONVERSATION_SEND_PATH = "/send";
private static final String CONVERSATION_MESSAGE_PATH = "/messages";
private static final String CONVERSATION_WEBHOOK_PATH = "/webhooks";
+ private static final String INTEGRATIONS_WHATSAPP_PATH = "/platforms/whatsapp";
static final String VOICECALLSPATH = "/calls";
static final String LEGSPATH = "/legs";
static final String RECORDINGPATH = "/recordings";
@@ -126,6 +131,7 @@ public class MessageBirdClient {
static final String VOICECALLFLOWPATH = "/call-flows";
private static final String VOICELEGS_SUFFIX_PATH = "/legs";
static final String FILES_PATH = "/files";
+ static final String TEMPLATES_PATH = "/templates";
static final String RECORDING_DOWNLOAD_FORMAT = ".wav";
@@ -1848,4 +1854,168 @@ public String downloadFile(String id, String filename, String basePath) throws G
final String url = String.format("%s%s/%s", MESSAGING_BASE_URL, FILES_PATH, id);
return messageBirdService.getBinaryData(url, basePath, filename);
}
-}
+
+ /****************************************************************************************************/
+ /** WhatsApp Templates **/
+ /****************************************************************************************************/
+
+ /**
+ * Create a WhatsApp message template through messagebird.
+ *
+ * @param template {@link WhatsAppTemplate} object to be created
+ * @return {@link WhatsAppTemplateResponse} response object
+ * @throws UnauthorizedException if client is unauthorized
+ * @throws GeneralException general exception or invalid template format
+ */
+ public WhatsAppTemplateResponse createWhatsAppTemplate(final WhatsAppTemplate template)
+ throws UnauthorizedException, GeneralException {
+ template.validate();
+
+ String url = String.format(
+ "%s%s%s",
+ INTEGRATIONS_BASE_URL_V2,
+ INTEGRATIONS_WHATSAPP_PATH,
+ TEMPLATES_PATH
+ );
+ return messageBirdService.sendPayLoad(url, template, WhatsAppTemplateResponse.class);
+ }
+
+ /**
+ * Gets a WhatsAppTemplate listing with specified pagination options.
+ *
+ * @param offset Number of objects to skip.
+ * @param limit Number of objects to take.
+ * @return List of templates.
+ * @throws UnauthorizedException if client is unauthorized
+ * @throws GeneralException general exception
+ */
+ public WhatsAppTemplateList listWhatsAppTemplates(final int offset, final int limit)
+ throws UnauthorizedException, GeneralException {
+ String url = String.format(
+ "%s%s%s",
+ INTEGRATIONS_BASE_URL_V3,
+ INTEGRATIONS_WHATSAPP_PATH,
+ TEMPLATES_PATH
+ );
+ return messageBirdService.requestList(url, offset, limit, WhatsAppTemplateList.class);
+ }
+
+ /**
+ * Gets a template listing with default pagination options.
+ *
+ * @return List of whatsapp templates.
+ * @throws UnauthorizedException if client is unauthorized
+ * @throws GeneralException general exception
+ */
+ public WhatsAppTemplateList listWhatsAppTemplates() throws UnauthorizedException, GeneralException {
+ final int offset = 0;
+ final int limit = 10;
+
+ return listWhatsAppTemplates(offset, limit);
+ }
+
+ /**
+ * Retrieves the template of an existing template name.
+ *
+ * @param templateName A name as returned by getWhatsAppTemplateBy in the name variable
+ * @return {@code List} template list
+ * @throws UnauthorizedException if client is unauthorized
+ * @throws GeneralException general exception
+ * @throws NotFoundException if template name is not found
+ */
+ public List getWhatsAppTemplatesBy(final String templateName)
+ throws GeneralException, UnauthorizedException, NotFoundException {
+ if (templateName == null) {
+ throw new IllegalArgumentException("Template name must be specified.");
+ }
+
+ String url = String.format(
+ "%s%s%s",
+ INTEGRATIONS_BASE_URL_V2,
+ INTEGRATIONS_WHATSAPP_PATH,
+ TEMPLATES_PATH
+ );
+
+ final WhatsAppTemplateResponse[] templateResponses = messageBirdService.requestByID(url, templateName, WhatsAppTemplateResponse[].class);
+ return Arrays.asList(templateResponses);
+ }
+
+ /**
+ * Retrieves the template of an existing template name and language.
+ *
+ * @param templateName A name as returned by getWhatsAppTemplateBy in the name variable
+ * @param language A language code as returned by getWhatsAppTemplateBy in the language variable
+ *
+ * @return {@code WhatsAppTemplateResponse} template list
+ * @throws UnauthorizedException if client is unauthorized
+ * @throws GeneralException general exception
+ * @throws NotFoundException if template name and language are not found
+ */
+ public WhatsAppTemplateResponse fetchWhatsAppTemplateBy(final String templateName, final String language)
+ throws GeneralException, UnauthorizedException, NotFoundException {
+ if (templateName == null || language == null) {
+ throw new IllegalArgumentException("Template name and language must be specified.");
+ }
+
+ String url = String.format(
+ "%s%s%s/%s/%s",
+ INTEGRATIONS_BASE_URL_V2,
+ INTEGRATIONS_WHATSAPP_PATH,
+ TEMPLATES_PATH,
+ templateName,
+ language
+ );
+ return messageBirdService.request(url, WhatsAppTemplateResponse.class);
+ }
+
+
+ /**
+ * Delete templates of an existing template name.
+ *
+ * @param templateName A template name which is created on the MessageBird platform
+ * @throws UnauthorizedException if client is unauthorized
+ * @throws GeneralException general exception
+ * @throws NotFoundException if template name is not found
+ */
+ public void deleteTemplatesBy(final String templateName)
+ throws UnauthorizedException, GeneralException, NotFoundException {
+ if (templateName == null) {
+ throw new IllegalArgumentException("Template name must be specified.");
+ }
+
+ String url = String.format(
+ "%s%s%s/%s",
+ INTEGRATIONS_BASE_URL_V2,
+ INTEGRATIONS_WHATSAPP_PATH,
+ TEMPLATES_PATH,
+ templateName
+ );
+ messageBirdService.delete(url, null);
+ }
+
+ /**
+ * Delete template of an existing template name and language.
+ *
+ * @param templateName A template name which is created on the MessageBird platform
+ * @param language A language which is created on the MessageBird platform
+ * @throws UnauthorizedException if client is unauthorized
+ * @throws GeneralException general exception
+ * @throws NotFoundException if template name or language are not found
+ */
+ public void deleteTemplatesBy(final String templateName, final String language)
+ throws UnauthorizedException, GeneralException, NotFoundException {
+ if (templateName == null || language == null) {
+ throw new IllegalArgumentException("Template name and language must be specified.");
+ }
+
+ String url = String.format(
+ "%s%s%s/%s/%s",
+ INTEGRATIONS_BASE_URL_V2,
+ INTEGRATIONS_WHATSAPP_PATH,
+ TEMPLATES_PATH,
+ templateName,
+ language
+ );
+ messageBirdService.delete(url, null);
+ }
+}
\ No newline at end of file
diff --git a/api/src/main/java/com/messagebird/MessageBirdService.java b/api/src/main/java/com/messagebird/MessageBirdService.java
index fdbf6f43..7f0a8641 100644
--- a/api/src/main/java/com/messagebird/MessageBirdService.java
+++ b/api/src/main/java/com/messagebird/MessageBirdService.java
@@ -1,16 +1,29 @@
package com.messagebird;
-import java.util.Map;
-
import com.messagebird.exceptions.GeneralException;
import com.messagebird.exceptions.NotFoundException;
import com.messagebird.exceptions.UnauthorizedException;
import com.messagebird.objects.PagedPaging;
+import java.util.Map;
/**
* Created by rvt on 1/7/15.
*/
public interface MessageBirdService {
+
+ /**
+ * Send GET request . It will retrieve a json object R back.
+ *
+ * @author ssk910
+ * @param request path to the request, for example "/messages/id/language"
+ * @param clazz Class type to return
+ * @return new class with returned dataset
+ * @throws UnauthorizedException if client is unauthorized
+ * @throws GeneralException general exception
+ * @throws NotFoundException if id not found
+ */
+ R request(String request, Class clazz) throws UnauthorizedException, GeneralException, NotFoundException;
+
/**
* Execute a object by ID request. It will add the id to the request parameter and retreive a json object R back.
*
@@ -36,6 +49,19 @@ public interface MessageBirdService {
*/
void deleteByID(String request, String id) throws UnauthorizedException, GeneralException, NotFoundException;
+ /**
+ * Send DELETE request. It will retrieve a json object R back.
+ *
+ * @author ssk910
+ * @param request path to the request, for example "/messages/id/language"
+ * @param clazz Class type to return
+ * @return class with returned dataset
+ * @throws UnauthorizedException if client is unauthorized
+ * @throws GeneralException general exception
+ * @throws NotFoundException if id not found
+ */
+ R delete(String request, Class clazz) throws UnauthorizedException, GeneralException, NotFoundException;
+
/**
* Request a List 'of' object.
* Allow to request a listMessage or listViewMessages objects.
diff --git a/api/src/main/java/com/messagebird/MessageBirdServiceImpl.java b/api/src/main/java/com/messagebird/MessageBirdServiceImpl.java
index 23850cf9..93507d08 100644
--- a/api/src/main/java/com/messagebird/MessageBirdServiceImpl.java
+++ b/api/src/main/java/com/messagebird/MessageBirdServiceImpl.java
@@ -1,17 +1,5 @@
package com.messagebird;
-import java.io.*;
-import java.lang.reflect.Field;
-import java.lang.reflect.Modifier;
-import java.net.HttpURLConnection;
-import java.net.Proxy;
-import java.net.URL;
-import java.net.URLEncoder;
-import java.nio.charset.StandardCharsets;
-import java.text.DateFormat;
-import java.text.SimpleDateFormat;
-import java.util.*;
-
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JsonNode;
@@ -22,6 +10,29 @@
import com.messagebird.exceptions.UnauthorizedException;
import com.messagebird.objects.ErrorReport;
import com.messagebird.objects.PagedPaging;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+import java.net.HttpURLConnection;
+import java.net.Proxy;
+import java.net.URL;
+import java.net.URLEncoder;
+import java.nio.charset.StandardCharsets;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Scanner;
/**
* Implementation of MessageBirdService
@@ -98,6 +109,12 @@ public MessageBirdServiceImpl(final String accessKey) {
this(accessKey, "https://rest.messagebird.com");
}
+ @Override
+ public R request(String request, Class clazz)
+ throws UnauthorizedException, GeneralException, NotFoundException {
+ return getJsonData(request, null, "GET", clazz);
+ }
+
@Override
public R requestByID(String request, String id, Class clazz) throws UnauthorizedException, GeneralException, NotFoundException {
String path = "";
@@ -126,6 +143,11 @@ public void deleteByID(String request, String id) throws UnauthorizedException,
getJsonData(request + "/" + id, null, "DELETE", null);
}
+ @Override
+ public R delete(String request, Class clazz) throws UnauthorizedException, GeneralException, NotFoundException {
+ return getJsonData(request, null, "DELETE", clazz);
+ }
+
@Override
public R requestList(String request, Integer offset, Integer limit, Class clazz) throws UnauthorizedException, GeneralException {
Map map = new LinkedHashMap<>();
@@ -235,7 +257,10 @@ public T getJsonData(final String request, final P payload, final String
mapper.enable(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES);
mapper.enable(MapperFeature.ACCEPT_CASE_INSENSITIVE_ENUMS);
- return mapper.readValue(body, clazz);
+ // Prevents mismatched exception when clazz is null
+ return clazz == null
+ ? null
+ : mapper.readValue(body, clazz);
} catch (IOException ioe) {
throw new GeneralException(ioe);
}
diff --git a/api/src/main/java/com/messagebird/objects/integrations/HSMCategory.java b/api/src/main/java/com/messagebird/objects/integrations/HSMCategory.java
new file mode 100644
index 00000000..15f4d31d
--- /dev/null
+++ b/api/src/main/java/com/messagebird/objects/integrations/HSMCategory.java
@@ -0,0 +1,55 @@
+package com.messagebird.objects.integrations;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonValue;
+
+/**
+ * An enum for HSMComponentFormat
+ *
+ * @see HSMComponentFormat
+ * @author ssk910
+ */
+public enum HSMCategory {
+
+ ACCOUNT_UPDATE("ACCOUNT_UPDATE"),
+ PAYMENT_UPDATE("PAYMENT_UPDATE"),
+ PERSONAL_FINANCE_UPDATE("PERSONAL_FINANCE_UPDATE"),
+ SHIPPING_UPDATE("SHIPPING_UPDATE"),
+ RESERVATION_UPDATE("RESERVATION_UPDATE"),
+ ISSUE_RESOLUTION("ISSUE_RESOLUTION"),
+ APPOINTMENT_UPDATE("APPOINTMENT_UPDATE"),
+ TRANSPORTATION_UPDATE("TRANSPORTATION_UPDATE"),
+ TICKET_UPDATE("TICKET_UPDATE"),
+ ALERT_UPDATE("ALERT_UPDATE");
+
+ private final String category;
+
+ HSMCategory(String category) {
+ this.category = category;
+ }
+
+ @JsonCreator
+ public static HSMCategory forValue(String value) {
+ for (HSMCategory hsmCategory : HSMCategory.values()) {
+ if (hsmCategory.getCategory().equals(value)) {
+ return hsmCategory;
+ }
+ }
+
+ return null;
+ }
+
+ @JsonValue
+ public String toJson() {
+ return getCategory();
+ }
+
+ public String getCategory() {
+ return category;
+ }
+
+ @Override
+ public String toString() {
+ return getCategory();
+ }
+}
diff --git a/api/src/main/java/com/messagebird/objects/integrations/HSMComponent.java b/api/src/main/java/com/messagebird/objects/integrations/HSMComponent.java
new file mode 100644
index 00000000..eb6b5694
--- /dev/null
+++ b/api/src/main/java/com/messagebird/objects/integrations/HSMComponent.java
@@ -0,0 +1,144 @@
+package com.messagebird.objects.integrations;
+
+import com.messagebird.exceptions.GeneralException;
+import java.util.List;
+
+/**
+ * A class for HSMComponent object
+ *
+ * @see HSMComponent
+ * @author ssk910
+ */
+public class HSMComponent {
+
+ private HSMComponentType type;
+ private HSMComponentFormat format;
+ private String text;
+ private List buttons;
+ private HSMExample example;
+
+ public HSMComponentType getType() {
+ return type;
+ }
+
+ public void setType(HSMComponentType type) {
+ this.type = type;
+ }
+
+ public HSMComponentFormat getFormat() {
+ return format;
+ }
+
+ public void setFormat(HSMComponentFormat format) {
+ this.format = format;
+ }
+
+ public String getText() {
+ return text;
+ }
+
+ public void setText(String text) {
+ this.text = text;
+ }
+
+ public List getButtons() {
+ return buttons;
+ }
+
+ public void setButtons(List buttons) {
+ this.buttons = buttons;
+ }
+
+ public HSMExample getExample() {
+ return example;
+ }
+
+ public void setExample(HSMExample example) {
+ this.example = example;
+ }
+
+ @Override
+ public String toString() {
+ return "HSMComponent{" +
+ "type='" + type + '\'' +
+ ", format='" + format + '\'' +
+ ", text='" + text + '\'' +
+ ", buttons=" + buttons +
+ ", example=" + example +
+ '}';
+ }
+
+ /**
+ * Check if this component is valid.
+ *
+ * @throws GeneralException Occurs when validation is not passed.
+ */
+ public void validateComponent() throws GeneralException {
+ this.validateButtons();
+ this.validateComponentExample();
+ }
+
+ /**
+ * Check if button list is valid.
+ *
+ * @throws GeneralException Occurs when validation is not passed.
+ */
+ private void validateButtons() throws GeneralException {
+ if (this.buttons == null) {
+ return;
+ }
+
+ for (final HSMComponentButton button : this.buttons) {
+ button.validateButtonExample();
+ }
+ }
+
+ /**
+ * Check for header_text and header_url.
+ *
+ * @throws GeneralException Occurs when {@code header_text} or {@code header_url} is not able to use.
+ */
+ private void validateComponentExample() throws GeneralException {
+ final boolean isExampleNotNull = this.example != null;
+ final boolean isHeaderTextNotEmpty =
+ isExampleNotNull && !(this.example.getHeader_text() == null || this.example.getHeader_text()
+ .isEmpty());
+ final boolean isHeaderUrlNotEmpty =
+ isExampleNotNull && !(this.example.getHeader_url() == null || this.example.getHeader_url()
+ .isEmpty());
+
+ if (isHeaderTextNotEmpty) {
+ this.checkHeaderText();
+ }
+
+ if (isHeaderUrlNotEmpty) {
+ this.checkHeaderUrl();
+ }
+ }
+
+ /**
+ * Check if header_text is able to use.
+ *
+ * @throws GeneralException Occurs when type is not {@code HEADER} and format is not {@code TEXT}.
+ */
+ private void checkHeaderText() throws GeneralException {
+ if (!(type.equals(HSMComponentType.HEADER)
+ && format.equals(HSMComponentFormat.TEXT))
+ ) {
+ throw new GeneralException("\"header_text\" is available for only HEADER type and TEXT format.");
+ }
+ }
+
+ /**
+ * Check if header_url is able to use.
+ *
+ * @throws GeneralException Occurs when type is not {@code HEADER} and format is not {@code IMAGE}.
+ */
+ private void checkHeaderUrl() throws GeneralException {
+ if (!(type.equals(HSMComponentType.HEADER)
+ && format.equals(HSMComponentFormat.IMAGE))
+ ) {
+ throw new GeneralException("\"header_url\" is available for only HEADER type and IMAGE format.");
+ }
+ }
+}
diff --git a/api/src/main/java/com/messagebird/objects/integrations/HSMComponentButton.java b/api/src/main/java/com/messagebird/objects/integrations/HSMComponentButton.java
new file mode 100644
index 00000000..02dd241c
--- /dev/null
+++ b/api/src/main/java/com/messagebird/objects/integrations/HSMComponentButton.java
@@ -0,0 +1,89 @@
+package com.messagebird.objects.integrations;
+
+import com.messagebird.exceptions.GeneralException;
+import java.util.List;
+
+/**
+ * HSMComponentButton
+ *
+ * @see HSMComponentButton
+ * @author ssk910
+ */
+public class HSMComponentButton {
+
+ private HSMComponentButtonType type;
+ private String text;
+ private String url;
+ private String phone_number;
+ private List example;
+
+ public HSMComponentButtonType getType() {
+ return type;
+ }
+
+ public void setType(HSMComponentButtonType type) {
+ this.type = type;
+ }
+
+ public String getText() {
+ return text;
+ }
+
+ public void setText(String text) {
+ this.text = text;
+ }
+
+ public String getUrl() {
+ return url;
+ }
+
+ public void setUrl(String url) {
+ this.url = url;
+ }
+
+ public String getPhone_number() {
+ return phone_number;
+ }
+
+ public void setPhone_number(String phone_number) {
+ this.phone_number = phone_number;
+ }
+
+ public List getExample() {
+ return example;
+ }
+
+ public void setExample(List example) {
+ this.example = example;
+ }
+
+ @Override
+ public String toString() {
+ return "HSMComponentButton{" +
+ "type=" + type +
+ ", text='" + text + '\'' +
+ ", url='" + url + '\'' +
+ ", phone_number='" + phone_number + '\'' +
+ ", example=" + example +
+ '}';
+ }
+
+ /**
+ * Check if example field is able to use.
+ *
+ * @throws GeneralException Occurs if button type is not {@code URL} or {@code QUICK_REPLY}.
+ */
+ public void validateButtonExample() throws GeneralException {
+ final boolean isExampleEmpty = this.example == null || this.example.isEmpty();
+ final boolean isNotProperType = !(this.type.equals(HSMComponentButtonType.URL)
+ || this.type.equals(HSMComponentButtonType.QUICK_REPLY));
+
+ if (isExampleEmpty) {
+ return;
+ }
+
+ if (isNotProperType) {
+ throw new GeneralException("An example field in HSMComponentButton is available for only URL or QUICK_REPLY button types.");
+ }
+ }
+}
diff --git a/api/src/main/java/com/messagebird/objects/integrations/HSMComponentButtonType.java b/api/src/main/java/com/messagebird/objects/integrations/HSMComponentButtonType.java
new file mode 100644
index 00000000..937f6baf
--- /dev/null
+++ b/api/src/main/java/com/messagebird/objects/integrations/HSMComponentButtonType.java
@@ -0,0 +1,48 @@
+package com.messagebird.objects.integrations;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonValue;
+
+/**
+ * HSMComponentButtonType
+ *
+ * @see HSMComponentButtonType
+ * @author ssk910
+ */
+public enum HSMComponentButtonType {
+
+ PHONE_NUMBER("PHONE_NUMBER"),
+ URL("URL"),
+ QUICK_REPLY("QUICK_REPLY");
+
+ private final String type;
+
+ HSMComponentButtonType(String type) {
+ this.type = type;
+ }
+
+ @JsonCreator
+ public static HSMComponentButtonType forValue(String value) {
+ for (HSMComponentButtonType hsmComponentButtonType : HSMComponentButtonType.values()) {
+ if (hsmComponentButtonType.getType().equals(value)) {
+ return hsmComponentButtonType;
+ }
+ }
+
+ return null;
+ }
+
+ @JsonValue
+ public String toJson() {
+ return getType();
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ @Override
+ public String toString() {
+ return getType();
+ }
+}
diff --git a/api/src/main/java/com/messagebird/objects/integrations/HSMComponentFormat.java b/api/src/main/java/com/messagebird/objects/integrations/HSMComponentFormat.java
new file mode 100644
index 00000000..ac7d199d
--- /dev/null
+++ b/api/src/main/java/com/messagebird/objects/integrations/HSMComponentFormat.java
@@ -0,0 +1,49 @@
+package com.messagebird.objects.integrations;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonValue;
+
+/**
+ * An enum for HSMComponentFormat
+ *
+ * @see HSMComponentFormat
+ * @author ssk910
+ */
+public enum HSMComponentFormat {
+
+ TEXT("TEXT"),
+ IMAGE("IMAGE"),
+ DOCUMENT("DOCUMENT"),
+ VIDEO("VIDEO");
+
+ private final String format;
+
+ HSMComponentFormat(String format) {
+ this.format = format;
+ }
+
+ @JsonCreator
+ public static HSMComponentFormat forValue(String value) {
+ for (HSMComponentFormat hsmComponentFormat : HSMComponentFormat.values()) {
+ if (hsmComponentFormat.getFormat().equals(value)) {
+ return hsmComponentFormat;
+ }
+ }
+
+ return null;
+ }
+
+ @JsonValue
+ public String toJson() {
+ return getFormat();
+ }
+
+ public String getFormat() {
+ return format;
+ }
+
+ @Override
+ public String toString() {
+ return getFormat();
+ }
+}
diff --git a/api/src/main/java/com/messagebird/objects/integrations/HSMComponentType.java b/api/src/main/java/com/messagebird/objects/integrations/HSMComponentType.java
new file mode 100644
index 00000000..0acda414
--- /dev/null
+++ b/api/src/main/java/com/messagebird/objects/integrations/HSMComponentType.java
@@ -0,0 +1,47 @@
+package com.messagebird.objects.integrations;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonValue;
+
+/**
+ * An enum for HSMComponentType
+ *
+ * @see HSMComponentType
+ */
+public enum HSMComponentType {
+ BODY("BODY"),
+ HEADER("HEADER"),
+ FOOTER("FOOTER"),
+ BUTTONS("BUTTONS");
+
+ private final String type;
+
+ HSMComponentType(String type) {
+ this.type = type;
+ }
+
+ @JsonCreator
+ public static HSMComponentType forValue(String value) {
+ for (HSMComponentType hsmComponentType : HSMComponentType.values()) {
+ if (hsmComponentType.getType().equals(value)) {
+ return hsmComponentType;
+ }
+ }
+
+ return null;
+ }
+
+ @JsonValue
+ public String toJson() {
+ return getType();
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ @Override
+ public String toString() {
+ return getType();
+ }
+}
diff --git a/api/src/main/java/com/messagebird/objects/integrations/HSMExample.java b/api/src/main/java/com/messagebird/objects/integrations/HSMExample.java
new file mode 100644
index 00000000..a28fcc38
--- /dev/null
+++ b/api/src/main/java/com/messagebird/objects/integrations/HSMExample.java
@@ -0,0 +1,54 @@
+package com.messagebird.objects.integrations;
+
+import java.util.List;
+
+/**
+ * HSMExample object
+ *
+ * @see HSMExample object
+ * @author ssk910
+ */
+public class HSMExample {
+
+ /* Example values for HEADER type components, TEXT format */
+ private List header_text;
+
+ /* Example set of values for the body text variables */
+ private List> body_text;
+
+ /* Example values for HEADER type components, IMAGE format */
+ private List header_url;
+
+ public List getHeader_text() {
+ return header_text;
+ }
+
+ public void setHeader_text(List header_text) {
+ this.header_text = header_text;
+ }
+
+ public List> getBody_text() {
+ return body_text;
+ }
+
+ public void setBody_text(List> body_text) {
+ this.body_text = body_text;
+ }
+
+ public List getHeader_url() {
+ return header_url;
+ }
+
+ public void setHeader_url(List header_url) {
+ this.header_url = header_url;
+ }
+
+ @Override
+ public String toString() {
+ return "HSMExample{" +
+ "header_text=" + header_text +
+ ", body_text=" + body_text +
+ ", header_url=" + header_url +
+ '}';
+ }
+}
diff --git a/api/src/main/java/com/messagebird/objects/integrations/HSMRejectedReason.java b/api/src/main/java/com/messagebird/objects/integrations/HSMRejectedReason.java
new file mode 100644
index 00000000..55937ef4
--- /dev/null
+++ b/api/src/main/java/com/messagebird/objects/integrations/HSMRejectedReason.java
@@ -0,0 +1,51 @@
+package com.messagebird.objects.integrations;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonValue;
+
+/**
+ * An enum class for HSMRejectedReason
+ *
+ * @see HSMRejectedReason object
+ * @author ssk910
+ */
+public enum HSMRejectedReason {
+
+ ABUSIVE_CONTENT("ABUSIVE_CONTENT"),
+ INVALID_FORMAT("INVALID_FORMAT"),
+ NONE("NONE"),
+ PROMOTIONAL("PROMOTIONAL"),
+ TAG_CONTENT_MISMATCH("TAG_CONTENT_MISMATCH"),
+ NON_TRANSIENT_ERROR("NON_TRANSIENT_ERROR");
+
+ private final String rejectedReason;
+
+ HSMRejectedReason(String rejectedReason) {
+ this.rejectedReason = rejectedReason;
+ }
+
+ @JsonCreator
+ public static HSMRejectedReason forValue(String value) {
+ for (HSMRejectedReason hsmRejectedReason : HSMRejectedReason.values()) {
+ if (hsmRejectedReason.getRejectedReason().equals(value)) {
+ return hsmRejectedReason;
+ }
+ }
+
+ return null;
+ }
+
+ @JsonValue
+ public String toJson() {
+ return getRejectedReason();
+ }
+
+ public String getRejectedReason() {
+ return rejectedReason;
+ }
+
+ @Override
+ public String toString() {
+ return getRejectedReason();
+ }
+}
diff --git a/api/src/main/java/com/messagebird/objects/integrations/HSMStatus.java b/api/src/main/java/com/messagebird/objects/integrations/HSMStatus.java
new file mode 100644
index 00000000..fa179b0f
--- /dev/null
+++ b/api/src/main/java/com/messagebird/objects/integrations/HSMStatus.java
@@ -0,0 +1,51 @@
+package com.messagebird.objects.integrations;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonValue;
+
+/**
+ * An enum for HSMStatus object
+ *
+ * @see HSMStatus object
+ * @author ssk910
+ */
+public enum HSMStatus {
+
+ NEW("NEW"),
+ APPROVED("APPROVED"),
+ PENDING("PENDING"),
+ REJECTED("REJECTED"),
+ PENDING_DELETION("PENDING_DELETION"),
+ DELETED("DELETED");
+
+ private final String status;
+
+ HSMStatus(String status) {
+ this.status = status;
+ }
+
+ @JsonCreator
+ public static HSMStatus forValue(String value) {
+ for (HSMStatus hsmStatus : HSMStatus.values()) {
+ if (hsmStatus.getStatus().equals(value)) {
+ return hsmStatus;
+ }
+ }
+
+ return null;
+ }
+
+ @JsonValue
+ public String toJson() {
+ return getStatus();
+ }
+
+ public String getStatus() {
+ return status;
+ }
+
+ @Override
+ public String toString() {
+ return getStatus();
+ }
+}
diff --git a/api/src/main/java/com/messagebird/objects/integrations/WhatsAppTemplate.java b/api/src/main/java/com/messagebird/objects/integrations/WhatsAppTemplate.java
new file mode 100644
index 00000000..3d3ba755
--- /dev/null
+++ b/api/src/main/java/com/messagebird/objects/integrations/WhatsAppTemplate.java
@@ -0,0 +1,86 @@
+package com.messagebird.objects.integrations;
+
+import com.messagebird.exceptions.GeneralException;
+import java.util.List;
+
+/**
+ * WhatsApp Template Object as integrations API request.
+ *
+ * @see Integrations API
+ * @author ssk910
+ */
+public class WhatsAppTemplate {
+
+ private String name;
+ private String language;
+ private List components;
+ private HSMCategory category;
+
+ public WhatsAppTemplate() {
+ }
+
+ public WhatsAppTemplate(String name, String language,
+ List components, HSMCategory category) {
+ this.name = name;
+ this.language = language;
+ this.components = components;
+ this.category = category;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getLanguage() {
+ return language;
+ }
+
+ public void setLanguage(String language) {
+ this.language = language;
+ }
+
+ public List getComponents() {
+ return components;
+ }
+
+ public void setComponents(List components) {
+ this.components = components;
+ }
+
+ public HSMCategory getCategory() {
+ return category;
+ }
+
+ public void setCategory(HSMCategory category) {
+ this.category = category;
+ }
+
+ /**
+ * Check if components field is valid.
+ *
+ * @throws GeneralException Occurs when it is invalid.
+ */
+ public void validate() throws GeneralException {
+ if (this.components == null) {
+ return;
+ }
+
+ for (final HSMComponent component : this.components) {
+ component.validateComponent();
+ }
+ }
+
+ @Override
+ public String toString() {
+ return "WhatsAppTemplate{" +
+ "name='" + name + '\'' +
+ ", language='" + language + '\'' +
+ ", components=" + components +
+ ", category='" + category + '\'' +
+ '}';
+ }
+}
diff --git a/api/src/main/java/com/messagebird/objects/integrations/WhatsAppTemplateList.java b/api/src/main/java/com/messagebird/objects/integrations/WhatsAppTemplateList.java
new file mode 100644
index 00000000..9e6e4894
--- /dev/null
+++ b/api/src/main/java/com/messagebird/objects/integrations/WhatsAppTemplateList.java
@@ -0,0 +1,12 @@
+package com.messagebird.objects.integrations;
+
+import com.messagebird.objects.ListBase;
+
+/**
+ * Response object representing the Template list type.
+ *
+ * @author ssk910
+ */
+public class WhatsAppTemplateList extends ListBase {
+
+}
diff --git a/api/src/main/java/com/messagebird/objects/integrations/WhatsAppTemplateResponse.java b/api/src/main/java/com/messagebird/objects/integrations/WhatsAppTemplateResponse.java
new file mode 100644
index 00000000..687401b8
--- /dev/null
+++ b/api/src/main/java/com/messagebird/objects/integrations/WhatsAppTemplateResponse.java
@@ -0,0 +1,105 @@
+package com.messagebird.objects.integrations;
+
+import java.io.Serializable;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * WhatsApp Template response using integrations API.
+ *
+ * @author ssk910
+ */
+public class WhatsAppTemplateResponse implements Serializable {
+
+ private static final long serialVersionUID = 7154209824478715861L;
+ private String name;
+ private String language;
+ private HSMCategory category;
+ private List components;
+ private HSMStatus status;
+ private HSMRejectedReason rejectedReason;
+ private Date createdAt;
+ private Date updatedAt;
+
+ public static long getSerialVersionUID() {
+ return serialVersionUID;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getLanguage() {
+ return language;
+ }
+
+ public void setLanguage(String language) {
+ this.language = language;
+ }
+
+ public HSMCategory getCategory() {
+ return category;
+ }
+
+ public void setCategory(HSMCategory category) {
+ this.category = category;
+ }
+
+ public List getComponents() {
+ return components;
+ }
+
+ public void setComponents(List components) {
+ this.components = components;
+ }
+
+ public HSMStatus getStatus() {
+ return status;
+ }
+
+ public void setStatus(HSMStatus status) {
+ this.status = status;
+ }
+
+ public HSMRejectedReason getRejectedReason() {
+ return rejectedReason;
+ }
+
+ public void setRejectedReason(HSMRejectedReason rejectedReason) {
+ this.rejectedReason = rejectedReason;
+ }
+
+ public Date getCreatedAt() {
+ return createdAt;
+ }
+
+ public void setCreatedAt(Date createdAt) {
+ this.createdAt = createdAt;
+ }
+
+ public Date getUpdatedAt() {
+ return updatedAt;
+ }
+
+ public void setUpdatedAt(Date updatedAt) {
+ this.updatedAt = updatedAt;
+ }
+
+ @Override
+ public String toString() {
+ return "WhatsAppTemplateResponse{" +
+ "name='" + name + '\'' +
+ ", language='" + language + '\'' +
+ ", category='" + category + '\'' +
+ ", components=" + components +
+ ", status='" + status + '\'' +
+ ", rejectedReason='" + rejectedReason + '\'' +
+ ", createdAt=" + createdAt +
+ ", updatedAt=" + updatedAt +
+ '}';
+ }
+}
diff --git a/examples/src/main/java/ExampleCreateTemplate.java b/examples/src/main/java/ExampleCreateTemplate.java
new file mode 100644
index 00000000..275c5bab
--- /dev/null
+++ b/examples/src/main/java/ExampleCreateTemplate.java
@@ -0,0 +1,97 @@
+import com.messagebird.MessageBirdClient;
+import com.messagebird.MessageBirdService;
+import com.messagebird.MessageBirdServiceImpl;
+import com.messagebird.exceptions.GeneralException;
+import com.messagebird.exceptions.UnauthorizedException;
+import com.messagebird.objects.integrations.HSMCategory;
+import com.messagebird.objects.integrations.HSMComponent;
+import com.messagebird.objects.integrations.HSMComponentButton;
+import com.messagebird.objects.integrations.HSMComponentButtonType;
+import com.messagebird.objects.integrations.HSMComponentFormat;
+import com.messagebird.objects.integrations.HSMComponentType;
+import com.messagebird.objects.integrations.HSMExample;
+import com.messagebird.objects.integrations.WhatsAppTemplate;
+import com.messagebird.objects.integrations.WhatsAppTemplateResponse;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * Create template.
+ *
+ * @see Doc - Create template
+ * @author ssk910
+ */
+public class ExampleCreateTemplate {
+
+ public static void main(String[] args) {
+ if (args.length < 2) {
+ System.out.println("Please specify your access key and a template name example : java -jar test_accesskey \"My template name\"");
+ return;
+ }
+
+ // First create your service object
+ final MessageBirdService wsr = new MessageBirdServiceImpl(args[0]);
+
+ // Add the service to the client
+ final MessageBirdClient messageBirdClient = new MessageBirdClient(wsr);
+
+ /* header */
+ final HSMComponent headerComponent = new HSMComponent();
+ final HSMExample headerExample = new HSMExample();
+ headerExample.setHeader_url(Arrays.asList("https://images.freeimages.com/images/small-previews/c5a/colourful-paper-rip-1-1195879.jpg"));
+
+ headerComponent.setType(HSMComponentType.HEADER);
+ headerComponent.setFormat(HSMComponentFormat.IMAGE);
+ headerComponent.setExample(headerExample);
+
+ /* body */
+ final HSMComponent bodyComponent = new HSMComponent();
+ final HSMExample bodyExample = new HSMExample();
+ final List> bodyText = new ArrayList<>();
+ bodyText.add(Arrays.asList("John"));
+ bodyText.add(Arrays.asList("Anna"));
+ bodyExample.setBody_text(bodyText);
+
+ bodyComponent.setType(HSMComponentType.BODY);
+ bodyComponent.setText("Hey {{1}}! This is a sample template from Java.");
+ bodyComponent.setExample(bodyExample);
+
+ /* footer */
+ final HSMComponent footerComponent = new HSMComponent();
+ footerComponent.setType(HSMComponentType.FOOTER);
+ footerComponent.setText("This is a sample footer");
+
+ /* button */
+ final HSMComponent buttonComponent = new HSMComponent();
+ final List buttons = new ArrayList<>();
+ final HSMComponentButton button = new HSMComponentButton();
+ button.setType(HSMComponentButtonType.URL);
+ button.setText("Touch it");
+ button.setUrl("https://www.messagebird.com");
+ button.setExample(Arrays.asList("https://developers.messagebird.com"));
+ buttons.add(button);
+ buttonComponent.setType(HSMComponentType.BUTTONS);
+ buttonComponent.setButtons(buttons);
+
+ /* set components */
+ final WhatsAppTemplate template = new WhatsAppTemplate();
+ final List components = new ArrayList<>();
+ components.add(headerComponent);
+ components.add(bodyComponent);
+ components.add(footerComponent);
+ components.add(buttonComponent);
+
+ template.setName(args[1]);
+ template.setLanguage("en_US");
+ template.setComponents(components);
+ template.setCategory(HSMCategory.ACCOUNT_UPDATE);
+
+ try {
+ WhatsAppTemplateResponse response = messageBirdClient.createWhatsAppTemplate(template);
+ System.out.println(response.toString());
+ } catch (GeneralException | UnauthorizedException exception) {
+ exception.printStackTrace();
+ }
+ }
+}
diff --git a/examples/src/main/java/ExampleDeleteTemplateByNameAndLanguage.java b/examples/src/main/java/ExampleDeleteTemplateByNameAndLanguage.java
new file mode 100644
index 00000000..1b215f10
--- /dev/null
+++ b/examples/src/main/java/ExampleDeleteTemplateByNameAndLanguage.java
@@ -0,0 +1,40 @@
+import com.messagebird.MessageBirdClient;
+import com.messagebird.MessageBirdService;
+import com.messagebird.MessageBirdServiceImpl;
+import com.messagebird.exceptions.GeneralException;
+import com.messagebird.exceptions.NotFoundException;
+import com.messagebird.exceptions.UnauthorizedException;
+
+/**
+ * Delete template by name and language
+ *
+ * @see Delete template by name and language
+ * @author ssk910
+ */
+public class ExampleDeleteTemplateByNameAndLanguage {
+
+ public static void main(String[] args) {
+ if (args.length < 3) {
+ System.out.println("Please specify your access key and a template name example : java -jar test_accesskey \"My template name\" \"Template language\"");
+ return;
+ }
+
+ // First create your service object
+ final MessageBirdService wsr = new MessageBirdServiceImpl(args[0]);
+
+ // Add the service to the client
+ final MessageBirdClient messageBirdClient = new MessageBirdClient(wsr);
+
+ // template name and langugae from input
+ final String templateName = args[1];
+ final String language = args[2];
+
+ try {
+ System.out.println("Deleting WhatsApp Template list by {name: " + templateName + ", language: " + language + "}");
+ messageBirdClient.deleteTemplatesBy(templateName, language);
+ System.out.println("Deleted {name: " + templateName + ", language: " + language + "}");
+ } catch (GeneralException | UnauthorizedException | NotFoundException exception) {
+ exception.printStackTrace();
+ }
+ }
+}
diff --git a/examples/src/main/java/ExampleDeleteTemplatesByName.java b/examples/src/main/java/ExampleDeleteTemplatesByName.java
new file mode 100644
index 00000000..c8d529f3
--- /dev/null
+++ b/examples/src/main/java/ExampleDeleteTemplatesByName.java
@@ -0,0 +1,39 @@
+import com.messagebird.MessageBirdClient;
+import com.messagebird.MessageBirdService;
+import com.messagebird.MessageBirdServiceImpl;
+import com.messagebird.exceptions.GeneralException;
+import com.messagebird.exceptions.NotFoundException;
+import com.messagebird.exceptions.UnauthorizedException;
+
+/**
+ * List templates by name
+ *
+ * @see List templates by name
+ * @author ssk910
+ */
+public class ExampleDeleteTemplatesByName {
+
+ public static void main(String[] args) {
+ if (args.length < 2) {
+ System.out.println("Please specify your access key and a template name example : java -jar test_accesskey \"My template name\"");
+ return;
+ }
+
+ // First create your service object
+ final MessageBirdService wsr = new MessageBirdServiceImpl(args[0]);
+
+ // Add the service to the client
+ final MessageBirdClient messageBirdClient = new MessageBirdClient(wsr);
+
+ // template name from input
+ final String templateName = args[1];
+
+ try {
+ System.out.println("Deleting WhatsApp Templates by name : " + templateName);
+ messageBirdClient.deleteTemplatesBy(templateName);
+ System.out.println("Template [" + templateName + "] deleted.");
+ } catch (GeneralException | UnauthorizedException | NotFoundException exception) {
+ exception.printStackTrace();
+ }
+ }
+}
diff --git a/examples/src/main/java/ExampleFetchTemplateByNameAndLanguage.java b/examples/src/main/java/ExampleFetchTemplateByNameAndLanguage.java
new file mode 100644
index 00000000..e1ad9bb6
--- /dev/null
+++ b/examples/src/main/java/ExampleFetchTemplateByNameAndLanguage.java
@@ -0,0 +1,41 @@
+import com.messagebird.MessageBirdClient;
+import com.messagebird.MessageBirdService;
+import com.messagebird.MessageBirdServiceImpl;
+import com.messagebird.exceptions.GeneralException;
+import com.messagebird.exceptions.NotFoundException;
+import com.messagebird.exceptions.UnauthorizedException;
+import com.messagebird.objects.integrations.WhatsAppTemplateResponse;
+
+/**
+ * Fetch template by name and language
+ *
+ * @see Fetch template by name and language
+ * @author ssk910
+ */
+public class ExampleFetchTemplateByNameAndLanguage {
+
+ public static void main(String[] args) {
+ if (args.length < 3) {
+ System.out.println("Please specify your access key and a template name example : java -jar test_accesskey \"My template name\" \"Template language\"");
+ return;
+ }
+
+ // First create your service object
+ final MessageBirdService wsr = new MessageBirdServiceImpl(args[0]);
+
+ // Add the service to the client
+ final MessageBirdClient messageBirdClient = new MessageBirdClient(wsr);
+
+ // template name and langugae from input
+ final String templateName = args[1];
+ final String language = args[2];
+
+ try {
+ System.out.println("Fetching WhatsApp Template list by {name: " + templateName + ", language: " + language + "}");
+ final WhatsAppTemplateResponse template = messageBirdClient.fetchWhatsAppTemplateBy(templateName, language);
+ System.out.println(template.toString());
+ } catch (GeneralException | UnauthorizedException | NotFoundException exception) {
+ exception.printStackTrace();
+ }
+ }
+}
diff --git a/examples/src/main/java/ExampleListTemplates.java b/examples/src/main/java/ExampleListTemplates.java
new file mode 100644
index 00000000..db9fc21b
--- /dev/null
+++ b/examples/src/main/java/ExampleListTemplates.java
@@ -0,0 +1,36 @@
+import com.messagebird.MessageBirdClient;
+import com.messagebird.MessageBirdService;
+import com.messagebird.MessageBirdServiceImpl;
+import com.messagebird.exceptions.GeneralException;
+import com.messagebird.exceptions.UnauthorizedException;
+import com.messagebird.objects.integrations.WhatsAppTemplateList;
+
+/**
+ * List templates
+ *
+ * @see List templates
+ * @author ssk910
+ */
+public class ExampleListTemplates {
+
+ public static void main(String[] args) {
+ if (args.length == 0) {
+ System.out.println("Please specify your access key example : java -jar test_accesskey");
+ return;
+ }
+
+ // First create your service object
+ final MessageBirdService wsr = new MessageBirdServiceImpl(args[0]);
+
+ // Add the service to the client
+ final MessageBirdClient messageBirdClient = new MessageBirdClient(wsr);
+
+ try {
+ System.out.println("Retrieving WhatsApp Template list");
+ final WhatsAppTemplateList templateList = messageBirdClient.listWhatsAppTemplates();
+ System.out.println(templateList.toString());
+ } catch (GeneralException | UnauthorizedException exception) {
+ exception.printStackTrace();
+ }
+ }
+}
diff --git a/examples/src/main/java/ExampleListTemplatesByName.java b/examples/src/main/java/ExampleListTemplatesByName.java
new file mode 100644
index 00000000..e68a6446
--- /dev/null
+++ b/examples/src/main/java/ExampleListTemplatesByName.java
@@ -0,0 +1,41 @@
+import com.messagebird.MessageBirdClient;
+import com.messagebird.MessageBirdService;
+import com.messagebird.MessageBirdServiceImpl;
+import com.messagebird.exceptions.GeneralException;
+import com.messagebird.exceptions.NotFoundException;
+import com.messagebird.exceptions.UnauthorizedException;
+import com.messagebird.objects.integrations.WhatsAppTemplateResponse;
+import java.util.List;
+
+/**
+ * List templates by name
+ *
+ * @see List templates by name
+ * @author ssk910
+ */
+public class ExampleListTemplatesByName {
+
+ public static void main(String[] args) {
+ if (args.length < 2) {
+ System.out.println("Please specify your access key and a template name example : java -jar test_accesskey \"My template name\"");
+ return;
+ }
+
+ // First create your service object
+ final MessageBirdService wsr = new MessageBirdServiceImpl(args[0]);
+
+ // Add the service to the client
+ final MessageBirdClient messageBirdClient = new MessageBirdClient(wsr);
+
+ // template name from input
+ final String templateName = args[1];
+
+ try {
+ System.out.println("Retrieving WhatsApp Template list by name : " + templateName);
+ final List templateList = messageBirdClient.getWhatsAppTemplatesBy(templateName);
+ System.out.println(templateList.toString());
+ } catch (GeneralException | UnauthorizedException | NotFoundException exception) {
+ exception.printStackTrace();
+ }
+ }
+}
From 994aa7c6a9070e285a8089e8ca15f4320abb5e81 Mon Sep 17 00:00:00 2001
From: ssk910
Date: Thu, 30 Sep 2021 22:33:11 +0900
Subject: [PATCH 015/216] feat: Add features for retrieve list of specified
objects
MessageBirdServiceImpl.getJsonDataAsList() method needs to refactor.
It has some duplicated code as mentioned at todo comment.
---
.../com/messagebird/MessageBirdService.java | 15 +++++
.../messagebird/MessageBirdServiceImpl.java | 67 ++++++++++++++++++-
2 files changed, 81 insertions(+), 1 deletion(-)
diff --git a/api/src/main/java/com/messagebird/MessageBirdService.java b/api/src/main/java/com/messagebird/MessageBirdService.java
index 7f0a8641..43201fb7 100644
--- a/api/src/main/java/com/messagebird/MessageBirdService.java
+++ b/api/src/main/java/com/messagebird/MessageBirdService.java
@@ -4,6 +4,7 @@
import com.messagebird.exceptions.NotFoundException;
import com.messagebird.exceptions.UnauthorizedException;
import com.messagebird.objects.PagedPaging;
+import java.util.List;
import java.util.Map;
/**
@@ -38,6 +39,20 @@ public interface MessageBirdService {
R requestByID(String request, String id, Map params, Class clazz) throws UnauthorizedException, GeneralException, NotFoundException;
+ /**
+ * Execute a object by ID request. It will add the id to the request parameter and retrieve a list of an object E back.
+ *
+ * @author ssk910
+ * @param request path to the request, for example "/messages"
+ * @param id id of the object to request. id can be null in case request's that don't need a id, for example /balance
+ * @param elementClass Class type of List to return
+ * @return new list of elementClass
+ * @throws UnauthorizedException if client is unauthorized
+ * @throws GeneralException general exception
+ * @throws NotFoundException
+ */
+ List requestByIdAsList(String request, String id, Class elementClass) throws UnauthorizedException, GeneralException, NotFoundException;
+
/**
* Delete a object by ID.
*
diff --git a/api/src/main/java/com/messagebird/MessageBirdServiceImpl.java b/api/src/main/java/com/messagebird/MessageBirdServiceImpl.java
index 93507d08..2497d524 100644
--- a/api/src/main/java/com/messagebird/MessageBirdServiceImpl.java
+++ b/api/src/main/java/com/messagebird/MessageBirdServiceImpl.java
@@ -1,6 +1,7 @@
package com.messagebird;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
+import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.MapperFeature;
@@ -27,6 +28,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
+import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
@@ -138,6 +140,17 @@ public R requestByID(String request, String id, Map params,
return getJsonData(request + path + queryParams, null, "GET", clazz);
}
+ @Override
+ public List requestByIdAsList(String request, String id, Class elementClass)
+ throws UnauthorizedException, GeneralException, NotFoundException {
+ String path = "";
+ if (id != null) {
+ path = "/" + id;
+ }
+
+ return getJsonDataAsList(request + path, null, "GET", elementClass);
+ }
+
@Override
public void deleteByID(String request, String id) throws UnauthorizedException, GeneralException, NotFoundException {
getJsonData(request + "/" + id, null, "DELETE", null);
@@ -234,6 +247,10 @@ public T getJsonData(final String request, final P payload, final String
return getJsonData(request, payload, requestType, new HashMap<>(), clazz);
}
+ public
List getJsonDataAsList(final String request, final P payload, final String requestType, final Class elementClass) throws UnauthorizedException, GeneralException, NotFoundException {
+ return getJsonDataAsList(request, payload, requestType, new HashMap<>(), elementClass);
+ }
+
public T getJsonData(final String request, final P payload, final String requestType, final Map headers, final Class clazz) throws UnauthorizedException, GeneralException, NotFoundException {
if (request == null) {
throw new IllegalArgumentException(REQUEST_VALUE_MUST_BE_SPECIFIED);
@@ -260,7 +277,7 @@ public T getJsonData(final String request, final P payload, final String
// Prevents mismatched exception when clazz is null
return clazz == null
? null
- : mapper.readValue(body, clazz);
+ : this.readValue(mapper, body, clazz);
} catch (IOException ioe) {
throw new GeneralException(ioe);
}
@@ -271,6 +288,54 @@ public T getJsonData(final String request, final P payload, final String
return null;
}
+ // todo: need to refactor for duplicated code.
+ public
List getJsonDataAsList(final String request,
+ final P payload, final String requestType, final Map headers, final Class elementClass)
+ throws UnauthorizedException, GeneralException, NotFoundException {
+ if (request == null) {
+ throw new IllegalArgumentException(REQUEST_VALUE_MUST_BE_SPECIFIED);
+ }
+
+ String url = request;
+ if (!isURLAbsolute(url)) {
+ url = serviceUrl + url;
+ }
+ final APIResponse apiResponse = doRequest(requestType, url, headers, payload);
+
+ final String body = apiResponse.getBody();
+ final int status = apiResponse.getStatus();
+
+ if (status == HttpURLConnection.HTTP_OK || status == HttpURLConnection.HTTP_CREATED || status == HttpURLConnection.HTTP_ACCEPTED) {
+ try {
+ final ObjectMapper mapper = new ObjectMapper();
+ // If we as new properties, we don't want the system to fail, we rather want to ignore them
+ mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
+ // Enable case insensitivity to avoid parsing errors if parameters' case in api response doesn't match sdk's
+ mapper.enable(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES);
+ mapper.enable(MapperFeature.ACCEPT_CASE_INSENSITIVE_ENUMS);
+
+ // Prevents mismatched exception when clazz is null
+ return this.readValueAsList(mapper, body, elementClass);
+ } catch (IOException ioe) {
+ throw new GeneralException(ioe);
+ }
+ } else if (status == HttpURLConnection.HTTP_NO_CONTENT) {
+ return Collections.emptyList(); // no content doesn't mean an error
+ }
+ handleHttpFailStatuses(status, body);
+ return Collections.emptyList();
+ }
+
+ private T readValue(ObjectMapper mapper, String content, Class clazz)
+ throws JsonProcessingException {
+ return mapper.readValue(content, clazz);
+ }
+
+ private List readValueAsList(ObjectMapper mapper, String content, final Class elementClass)
+ throws JsonProcessingException {
+ return mapper.readValue(content, mapper.getTypeFactory().constructCollectionType(List.class, elementClass));
+ }
+
private void handleHttpFailStatuses(final int status, String body) throws UnauthorizedException, NotFoundException, GeneralException {
if (status == HttpURLConnection.HTTP_UNAUTHORIZED) {
final List errorReport = getErrorReportOrNull(body);
From b9a59fb7a59e9743b624d5a3f37b941cdb17d03d Mon Sep 17 00:00:00 2001
From: ssk910
Date: Thu, 30 Sep 2021 22:35:26 +0900
Subject: [PATCH 016/216] test: Add unit tests for Integrations API
Added just a few unit tests.
---
.../com/messagebird/MessageBirdClient.java | 5 +-
.../messagebird/MessageBirdClientTest.java | 189 ++++++++++++++++++
.../test/java/com/messagebird/TestUtil.java | 109 ++++++++++
3 files changed, 300 insertions(+), 3 deletions(-)
diff --git a/api/src/main/java/com/messagebird/MessageBirdClient.java b/api/src/main/java/com/messagebird/MessageBirdClient.java
index 317b02d4..fc075fa0 100644
--- a/api/src/main/java/com/messagebird/MessageBirdClient.java
+++ b/api/src/main/java/com/messagebird/MessageBirdClient.java
@@ -122,7 +122,7 @@ public class MessageBirdClient {
private static final String CONVERSATION_SEND_PATH = "/send";
private static final String CONVERSATION_MESSAGE_PATH = "/messages";
private static final String CONVERSATION_WEBHOOK_PATH = "/webhooks";
- private static final String INTEGRATIONS_WHATSAPP_PATH = "/platforms/whatsapp";
+ static final String INTEGRATIONS_WHATSAPP_PATH = "/platforms/whatsapp";
static final String VOICECALLSPATH = "/calls";
static final String LEGSPATH = "/legs";
static final String RECORDINGPATH = "/recordings";
@@ -1936,8 +1936,7 @@ public List getWhatsAppTemplatesBy(final String templa
TEMPLATES_PATH
);
- final WhatsAppTemplateResponse[] templateResponses = messageBirdService.requestByID(url, templateName, WhatsAppTemplateResponse[].class);
- return Arrays.asList(templateResponses);
+ return messageBirdService.requestByIdAsList(url, templateName, WhatsAppTemplateResponse.class);
}
/**
diff --git a/api/src/test/java/com/messagebird/MessageBirdClientTest.java b/api/src/test/java/com/messagebird/MessageBirdClientTest.java
index 956b177b..73731f96 100644
--- a/api/src/test/java/com/messagebird/MessageBirdClientTest.java
+++ b/api/src/test/java/com/messagebird/MessageBirdClientTest.java
@@ -4,10 +4,19 @@
import com.messagebird.exceptions.NotFoundException;
import com.messagebird.exceptions.UnauthorizedException;
import com.messagebird.objects.*;
+import com.messagebird.objects.integrations.WhatsAppTemplate;
+import com.messagebird.objects.integrations.WhatsAppTemplateList;
+import com.messagebird.objects.integrations.WhatsAppTemplateResponse;
import com.messagebird.objects.voicecalls.*;
+import java.util.ArrayList;
+import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
+import org.junit.Rule;
import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Captor;
import org.mockito.Mockito;
import java.io.*;
@@ -17,6 +26,7 @@
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
+import org.mockito.stubbing.OngoingStubbing;
import static com.messagebird.MessageBirdClient.*;
import static org.junit.Assert.*;
@@ -33,6 +43,13 @@ public class MessageBirdClientTest {
MessageBirdServiceImpl messageBirdService;
MessageBirdClient messageBirdClient;
+ @Captor
+ ArgumentCaptor argument = ArgumentCaptor.forClass(WhatsAppTemplateResponse.class);
+
+ @Captor
+ ArgumentCaptor valueCaptor;
+
+
@BeforeClass
public static void setUpClass() {
messageBirdAccessKey = System.getProperty("messageBirdAccessKey");
@@ -1042,4 +1059,176 @@ public void testDownloadFileWithNullBasePath() throws GeneralException, Unauthor
String url = MESSAGING_BASE_URL + FILES_PATH + "/" + id;
verify(messageBirdServiceMock, times(1)).getBinaryData(url, null, filename);
}
+
+ /****************************************************************************************************/
+ /** Testing WhatsApp Templates **/
+ /****************************************************************************************************/
+
+ @Test
+ public void testCreateWhatsAppTemplate() throws UnauthorizedException, GeneralException {
+ final WhatsAppTemplateResponse templateResponse = TestUtil.createWhatsAppTemplateResponse("sample_template_name", "ko");
+ final WhatsAppTemplate template = TestUtil.createWhatsAppTemplate("sample_template_name", "ko");
+
+ MessageBirdService messageBirdServiceMock = mock(MessageBirdService.class);
+ MessageBirdClient messageBirdClientInjectMock = new MessageBirdClient(messageBirdServiceMock);
+
+ String url = String.format(
+ "%s%s%s",
+ INTEGRATIONS_BASE_URL_V2,
+ INTEGRATIONS_WHATSAPP_PATH,
+ TEMPLATES_PATH
+ );
+
+ when(messageBirdServiceMock.sendPayLoad(url, template, WhatsAppTemplateResponse.class))
+ .thenReturn(templateResponse);
+
+ final WhatsAppTemplateResponse response = messageBirdClientInjectMock.createWhatsAppTemplate(template);
+
+ verify(messageBirdServiceMock, times(1)).sendPayLoad(url, template, WhatsAppTemplateResponse.class);
+ assertNotNull(response);
+ assertEquals(response.getName(), templateResponse.getName());
+ assertEquals(response.getLanguage(), templateResponse.getLanguage());
+ assertEquals(response.getCategory(), templateResponse.getCategory());
+ assertEquals(response.getStatus(), templateResponse.getStatus());
+ assertEquals(response.getCreatedAt(), templateResponse.getCreatedAt());
+ assertEquals(response.getUpdatedAt(), templateResponse.getUpdatedAt());
+
+ /* verify components */
+ for (int i = 0; i < response.getComponents().size(); i++) {
+ assertEquals(response.getComponents().get(i).getType(), templateResponse.getComponents().get(i).getType());
+ assertEquals(response.getComponents().get(i).getFormat(), templateResponse.getComponents().get(i).getFormat());
+ assertEquals(response.getComponents().get(i).getText(), templateResponse.getComponents().get(i).getText());
+ }
+ }
+
+ @Test
+ public void testListWhatsAppTemplates() throws UnauthorizedException, GeneralException {
+ final WhatsAppTemplateList templateList = TestUtil.createWhatsAppTemplateList("sample_template_name");
+ MessageBirdService messageBirdServiceMock = mock(MessageBirdService.class);
+ MessageBirdClient messageBirdClientInjectMock = new MessageBirdClient(messageBirdServiceMock);
+
+ String url = String.format(
+ "%s%s%s",
+ INTEGRATIONS_BASE_URL_V3,
+ INTEGRATIONS_WHATSAPP_PATH,
+ TEMPLATES_PATH
+ );
+
+ when(messageBirdServiceMock.requestList(url, 0, 0, WhatsAppTemplateList.class))
+ .thenReturn(templateList);
+
+ final WhatsAppTemplateList response = messageBirdClientInjectMock.listWhatsAppTemplates(0, 0);
+ verify(messageBirdServiceMock, times(1)).requestList(url, 0, 0, WhatsAppTemplateList.class);
+ assertNotNull(response);
+ for(int i = 0; i < response.getItems().size() ; i++) {
+ assertReflectionEquals(response.getItems().get(i), templateList.getItems().get(i));
+ }
+ }
+
+ @Test
+ public void testGetWhatsAppTemplatesBy()
+ throws GeneralException, UnauthorizedException, NotFoundException, ClassNotFoundException {
+ final String templateName = "sample_template_name";
+ final WhatsAppTemplateResponse templateResponse1 = TestUtil.createWhatsAppTemplateResponse(templateName, "en_US");
+ final WhatsAppTemplateResponse templateResponse2 = TestUtil.createWhatsAppTemplateResponse("another_template", "en_US");
+ final List templateList = new ArrayList<>();
+ templateList.add(templateResponse1);
+ templateList.add(templateResponse2);
+
+ MessageBirdService messageBirdServiceMock = mock(MessageBirdService.class);
+ MessageBirdClient messageBirdClientInjectMock = new MessageBirdClient(messageBirdServiceMock);
+
+ String url = String.format(
+ "%s%s%s",
+ INTEGRATIONS_BASE_URL_V2,
+ INTEGRATIONS_WHATSAPP_PATH,
+ TEMPLATES_PATH
+ );
+
+ when(messageBirdServiceMock.requestByIdAsList(url, templateName, WhatsAppTemplateResponse.class))
+ .thenReturn(templateList);
+
+ final List response = messageBirdClientInjectMock.getWhatsAppTemplatesBy(templateName);
+ verify(messageBirdServiceMock, times(1)).requestByIdAsList(url, templateName, WhatsAppTemplateResponse.class);
+ assertNotNull(response);
+ assertEquals(response.size(), templateList.size());
+ for(int i = 0; i < response.size() ; i++) {
+ assertReflectionEquals(response.get(i), templateList.get(i));
+ }
+ }
+
+ @Test
+ public void testFetchWhatsAppTemplateBy()
+ throws UnauthorizedException, GeneralException, NotFoundException {
+ final String templateName = "sample_template_name";
+ final String language = "ko";
+ final WhatsAppTemplateResponse template = TestUtil.createWhatsAppTemplateResponse(templateName, language);
+
+ MessageBirdService messageBirdServiceMock = mock(MessageBirdService.class);
+ MessageBirdClient messageBirdClientInjectMock = new MessageBirdClient(messageBirdServiceMock);
+
+ String url = String.format(
+ "%s%s%s/%s/%s",
+ INTEGRATIONS_BASE_URL_V2,
+ INTEGRATIONS_WHATSAPP_PATH,
+ TEMPLATES_PATH,
+ templateName,
+ language
+ );
+
+ when(messageBirdServiceMock.request(url, WhatsAppTemplateResponse.class))
+ .thenReturn(template);
+
+ final WhatsAppTemplateResponse response = messageBirdClientInjectMock.fetchWhatsAppTemplateBy(templateName, language);
+ verify(messageBirdServiceMock, times(1)).request(url, WhatsAppTemplateResponse.class);
+ assertNotNull(response);
+ assertEquals(response.getName(), template.getName());
+ assertEquals(response.getLanguage(), template.getLanguage());
+ assertEquals(response.getStatus(), template.getStatus());
+ assertReflectionEquals(response.getComponents(), template.getComponents());
+ }
+
+ @Test
+ public void testDeleteTemplatesByName()
+ throws UnauthorizedException, GeneralException, NotFoundException {
+ final String templateName = "sample_template_name";
+
+ MessageBirdService messageBirdServiceMock = mock(MessageBirdService.class);
+ MessageBirdClient messageBirdClientInjectMock = new MessageBirdClient(messageBirdServiceMock);
+
+ String url = String.format(
+ "%s%s%s/%s",
+ INTEGRATIONS_BASE_URL_V2,
+ INTEGRATIONS_WHATSAPP_PATH,
+ TEMPLATES_PATH,
+ templateName
+ );
+
+ when(messageBirdServiceMock.delete(url, null)).thenReturn(null);
+ messageBirdClientInjectMock.deleteTemplatesBy(templateName);
+ verify(messageBirdServiceMock).delete(url, null);
+ }
+
+ @Test
+ public void testDeleteTemplatesByNameAndLanguage()
+ throws UnauthorizedException, GeneralException, NotFoundException {
+ final String templateName = "sample_template_name";
+ final String language = "en_US";
+
+ MessageBirdService messageBirdServiceMock = mock(MessageBirdService.class);
+ MessageBirdClient messageBirdClientInjectMock = new MessageBirdClient(messageBirdServiceMock);
+
+ String url = String.format(
+ "%s%s%s/%s/%s",
+ INTEGRATIONS_BASE_URL_V2,
+ INTEGRATIONS_WHATSAPP_PATH,
+ TEMPLATES_PATH,
+ templateName,
+ language
+ );
+
+ when(messageBirdServiceMock.delete(url, null)).thenReturn(null);
+ messageBirdClientInjectMock.deleteTemplatesBy(templateName, language);
+ verify(messageBirdServiceMock).delete(url, null);
+ }
}
diff --git a/api/src/test/java/com/messagebird/TestUtil.java b/api/src/test/java/com/messagebird/TestUtil.java
index 5a854b45..07072aff 100644
--- a/api/src/test/java/com/messagebird/TestUtil.java
+++ b/api/src/test/java/com/messagebird/TestUtil.java
@@ -2,6 +2,17 @@
import com.messagebird.objects.*;
import com.messagebird.objects.conversations.*;
+import com.messagebird.objects.integrations.HSMCategory;
+import com.messagebird.objects.integrations.HSMComponent;
+import com.messagebird.objects.integrations.HSMComponentButton;
+import com.messagebird.objects.integrations.HSMComponentButtonType;
+import com.messagebird.objects.integrations.HSMComponentFormat;
+import com.messagebird.objects.integrations.HSMComponentType;
+import com.messagebird.objects.integrations.HSMExample;
+import com.messagebird.objects.integrations.HSMStatus;
+import com.messagebird.objects.integrations.WhatsAppTemplate;
+import com.messagebird.objects.integrations.WhatsAppTemplateList;
+import com.messagebird.objects.integrations.WhatsAppTemplateResponse;
import com.messagebird.objects.voicecalls.*;
import java.util.*;
@@ -240,4 +251,102 @@ static ConversationWebhookCreateRequest createConversationWebhookRequest() {
)
);
}
+
+ private static HSMComponent createHSMComponentHeader() {
+ final HSMComponent headerComponent = new HSMComponent();
+ final HSMExample headerExample = new HSMExample();
+ headerExample.setHeader_url(Arrays.asList("https://www.mysample.com/sample.img"));
+
+ headerComponent.setType(HSMComponentType.HEADER);
+ headerComponent.setFormat(HSMComponentFormat.IMAGE);
+ headerComponent.setExample(headerExample);
+
+ return headerComponent;
+ }
+
+ private static HSMComponent createHSMComponentBody() {
+ final HSMComponent bodyComponent = new HSMComponent();
+ final HSMExample bodyExample = new HSMExample();
+ final List> bodyText = new ArrayList<>();
+ bodyText.add(Arrays.asList("John"));
+ bodyText.add(Arrays.asList("Anna"));
+ bodyExample.setBody_text(bodyText);
+
+ bodyComponent.setType(HSMComponentType.BODY);
+ bodyComponent.setText("Hey {{1}}! This is a sample template from Java.");
+ bodyComponent.setExample(bodyExample);
+
+ return bodyComponent;
+ }
+
+ private static HSMComponent createHSMComponentFooter() {
+ final HSMComponent footerComponent = new HSMComponent();
+ footerComponent.setType(HSMComponentType.FOOTER);
+ footerComponent.setText("This is a sample footer");
+
+ return footerComponent;
+ }
+
+ private static HSMComponent createHSMComponentButton() {
+ final HSMComponent buttonComponent = new HSMComponent();
+ final List buttons = new ArrayList<>();
+ final HSMComponentButton button = new HSMComponentButton();
+ button.setType(HSMComponentButtonType.URL);
+ button.setText("Touch it");
+ button.setUrl("https://www.messagebird.com");
+ button.setExample(Arrays.asList("https://developers.messagebird.com"));
+ buttons.add(button);
+ buttonComponent.setType(HSMComponentType.BUTTONS);
+ buttonComponent.setButtons(buttons);
+
+ return buttonComponent;
+ }
+
+ public static WhatsAppTemplateResponse createWhatsAppTemplateResponse(final String templateName, final String language) {
+ final WhatsAppTemplateResponse templateResponse = new WhatsAppTemplateResponse();
+ templateResponse.setName(templateName);
+ templateResponse.setLanguage(language);
+ templateResponse.setCategory(HSMCategory.ACCOUNT_UPDATE);
+ templateResponse.setStatus(HSMStatus.NEW);
+ templateResponse.setCreatedAt(new Date());
+ templateResponse.setUpdatedAt(new Date());
+
+ final List components = new ArrayList<>();
+ components.add(createHSMComponentHeader());
+ components.add(createHSMComponentBody());
+ components.add(createHSMComponentFooter());
+ components.add(createHSMComponentButton());
+ templateResponse.setComponents(components);
+
+ return templateResponse;
+ }
+
+ public static WhatsAppTemplate createWhatsAppTemplate(final String templateName, final String language) {
+ final WhatsAppTemplate template = new WhatsAppTemplate();
+ template.setName(templateName);
+ template.setLanguage(language);
+ template.setCategory(HSMCategory.ACCOUNT_UPDATE);
+
+ final List components = new ArrayList<>();
+ components.add(createHSMComponentHeader());
+ components.add(createHSMComponentBody());
+ components.add(createHSMComponentFooter());
+ components.add(createHSMComponentButton());
+ template.setComponents(components);
+
+ return template;
+ }
+
+ public static WhatsAppTemplateList createWhatsAppTemplateList(final String templateName) {
+ final WhatsAppTemplateResponse template1 = TestUtil.createWhatsAppTemplateResponse(templateName, "en_US");
+ final WhatsAppTemplateResponse template2 = TestUtil.createWhatsAppTemplateResponse(templateName, "ko");
+ final WhatsAppTemplateList templateList = new WhatsAppTemplateList();
+
+ List templateResponseList = new ArrayList<>();
+ templateResponseList.add(template1);
+ templateResponseList.add(template2);
+
+ templateList.setItems(templateResponseList);
+ return templateList;
+ }
}
From 2d4593e15389051ce3a3d2f53540366027d6d779 Mon Sep 17 00:00:00 2001
From: ssk910
Date: Tue, 5 Oct 2021 13:15:50 +0900
Subject: [PATCH 017/216] refactor: Rename classes and interfaces
Applied @olimpias 's suggestion in #160
---
.../com/messagebird/MessageBirdClient.java | 28 ++++-----
.../{WhatsAppTemplate.java => Template.java} | 8 +--
...AppTemplateList.java => TemplateList.java} | 2 +-
...ateResponse.java => TemplateResponse.java} | 4 +-
.../messagebird/MessageBirdClientTest.java | 57 +++++++------------
.../test/java/com/messagebird/TestUtil.java | 24 ++++----
.../src/main/java/ExampleCreateTemplate.java | 8 +--
...ExampleFetchTemplateByNameAndLanguage.java | 4 +-
.../src/main/java/ExampleListTemplates.java | 4 +-
.../main/java/ExampleListTemplatesByName.java | 4 +-
10 files changed, 65 insertions(+), 78 deletions(-)
rename api/src/main/java/com/messagebird/objects/integrations/{WhatsAppTemplate.java => Template.java} (90%)
rename api/src/main/java/com/messagebird/objects/integrations/{WhatsAppTemplateList.java => TemplateList.java} (69%)
rename api/src/main/java/com/messagebird/objects/integrations/{WhatsAppTemplateResponse.java => TemplateResponse.java} (94%)
diff --git a/api/src/main/java/com/messagebird/MessageBirdClient.java b/api/src/main/java/com/messagebird/MessageBirdClient.java
index fc075fa0..d463488a 100644
--- a/api/src/main/java/com/messagebird/MessageBirdClient.java
+++ b/api/src/main/java/com/messagebird/MessageBirdClient.java
@@ -46,9 +46,9 @@
import com.messagebird.objects.conversations.ConversationWebhookCreateRequest;
import com.messagebird.objects.conversations.ConversationWebhookList;
import com.messagebird.objects.conversations.ConversationWebhookUpdateRequest;
-import com.messagebird.objects.integrations.WhatsAppTemplate;
-import com.messagebird.objects.integrations.WhatsAppTemplateList;
-import com.messagebird.objects.integrations.WhatsAppTemplateResponse;
+import com.messagebird.objects.integrations.Template;
+import com.messagebird.objects.integrations.TemplateList;
+import com.messagebird.objects.integrations.TemplateResponse;
import com.messagebird.objects.voicecalls.RecordingResponse;
import com.messagebird.objects.voicecalls.TranscriptionResponse;
import com.messagebird.objects.voicecalls.VoiceCall;
@@ -1862,12 +1862,12 @@ public String downloadFile(String id, String filename, String basePath) throws G
/**
* Create a WhatsApp message template through messagebird.
*
- * @param template {@link WhatsAppTemplate} object to be created
- * @return {@link WhatsAppTemplateResponse} response object
+ * @param template {@link Template} object to be created
+ * @return {@link TemplateResponse} response object
* @throws UnauthorizedException if client is unauthorized
* @throws GeneralException general exception or invalid template format
*/
- public WhatsAppTemplateResponse createWhatsAppTemplate(final WhatsAppTemplate template)
+ public TemplateResponse createWhatsAppTemplate(final Template template)
throws UnauthorizedException, GeneralException {
template.validate();
@@ -1877,7 +1877,7 @@ public WhatsAppTemplateResponse createWhatsAppTemplate(final WhatsAppTemplate te
INTEGRATIONS_WHATSAPP_PATH,
TEMPLATES_PATH
);
- return messageBirdService.sendPayLoad(url, template, WhatsAppTemplateResponse.class);
+ return messageBirdService.sendPayLoad(url, template, TemplateResponse.class);
}
/**
@@ -1889,7 +1889,7 @@ public WhatsAppTemplateResponse createWhatsAppTemplate(final WhatsAppTemplate te
* @throws UnauthorizedException if client is unauthorized
* @throws GeneralException general exception
*/
- public WhatsAppTemplateList listWhatsAppTemplates(final int offset, final int limit)
+ public TemplateList listWhatsAppTemplates(final int offset, final int limit)
throws UnauthorizedException, GeneralException {
String url = String.format(
"%s%s%s",
@@ -1897,7 +1897,7 @@ public WhatsAppTemplateList listWhatsAppTemplates(final int offset, final int li
INTEGRATIONS_WHATSAPP_PATH,
TEMPLATES_PATH
);
- return messageBirdService.requestList(url, offset, limit, WhatsAppTemplateList.class);
+ return messageBirdService.requestList(url, offset, limit, TemplateList.class);
}
/**
@@ -1907,7 +1907,7 @@ public WhatsAppTemplateList listWhatsAppTemplates(final int offset, final int li
* @throws UnauthorizedException if client is unauthorized
* @throws GeneralException general exception
*/
- public WhatsAppTemplateList listWhatsAppTemplates() throws UnauthorizedException, GeneralException {
+ public TemplateList listWhatsAppTemplates() throws UnauthorizedException, GeneralException {
final int offset = 0;
final int limit = 10;
@@ -1923,7 +1923,7 @@ public WhatsAppTemplateList listWhatsAppTemplates() throws UnauthorizedException
* @throws GeneralException general exception
* @throws NotFoundException if template name is not found
*/
- public List getWhatsAppTemplatesBy(final String templateName)
+ public List getWhatsAppTemplatesBy(final String templateName)
throws GeneralException, UnauthorizedException, NotFoundException {
if (templateName == null) {
throw new IllegalArgumentException("Template name must be specified.");
@@ -1936,7 +1936,7 @@ public List getWhatsAppTemplatesBy(final String templa
TEMPLATES_PATH
);
- return messageBirdService.requestByIdAsList(url, templateName, WhatsAppTemplateResponse.class);
+ return messageBirdService.requestByIdAsList(url, templateName, TemplateResponse.class);
}
/**
@@ -1950,7 +1950,7 @@ public List getWhatsAppTemplatesBy(final String templa
* @throws GeneralException general exception
* @throws NotFoundException if template name and language are not found
*/
- public WhatsAppTemplateResponse fetchWhatsAppTemplateBy(final String templateName, final String language)
+ public TemplateResponse fetchWhatsAppTemplateBy(final String templateName, final String language)
throws GeneralException, UnauthorizedException, NotFoundException {
if (templateName == null || language == null) {
throw new IllegalArgumentException("Template name and language must be specified.");
@@ -1964,7 +1964,7 @@ public WhatsAppTemplateResponse fetchWhatsAppTemplateBy(final String templateNam
templateName,
language
);
- return messageBirdService.request(url, WhatsAppTemplateResponse.class);
+ return messageBirdService.request(url, TemplateResponse.class);
}
diff --git a/api/src/main/java/com/messagebird/objects/integrations/WhatsAppTemplate.java b/api/src/main/java/com/messagebird/objects/integrations/Template.java
similarity index 90%
rename from api/src/main/java/com/messagebird/objects/integrations/WhatsAppTemplate.java
rename to api/src/main/java/com/messagebird/objects/integrations/Template.java
index 3d3ba755..6bcf145d 100644
--- a/api/src/main/java/com/messagebird/objects/integrations/WhatsAppTemplate.java
+++ b/api/src/main/java/com/messagebird/objects/integrations/Template.java
@@ -4,22 +4,22 @@
import java.util.List;
/**
- * WhatsApp Template Object as integrations API request.
+ * Template Object as integrations API request.
*
* @see Integrations API
* @author ssk910
*/
-public class WhatsAppTemplate {
+public class Template {
private String name;
private String language;
private List components;
private HSMCategory category;
- public WhatsAppTemplate() {
+ public Template() {
}
- public WhatsAppTemplate(String name, String language,
+ public Template(String name, String language,
List components, HSMCategory category) {
this.name = name;
this.language = language;
diff --git a/api/src/main/java/com/messagebird/objects/integrations/WhatsAppTemplateList.java b/api/src/main/java/com/messagebird/objects/integrations/TemplateList.java
similarity index 69%
rename from api/src/main/java/com/messagebird/objects/integrations/WhatsAppTemplateList.java
rename to api/src/main/java/com/messagebird/objects/integrations/TemplateList.java
index 9e6e4894..5cea4023 100644
--- a/api/src/main/java/com/messagebird/objects/integrations/WhatsAppTemplateList.java
+++ b/api/src/main/java/com/messagebird/objects/integrations/TemplateList.java
@@ -7,6 +7,6 @@
*
* @author ssk910
*/
-public class WhatsAppTemplateList extends ListBase {
+public class TemplateList extends ListBase {
}
diff --git a/api/src/main/java/com/messagebird/objects/integrations/WhatsAppTemplateResponse.java b/api/src/main/java/com/messagebird/objects/integrations/TemplateResponse.java
similarity index 94%
rename from api/src/main/java/com/messagebird/objects/integrations/WhatsAppTemplateResponse.java
rename to api/src/main/java/com/messagebird/objects/integrations/TemplateResponse.java
index 687401b8..ac34efd0 100644
--- a/api/src/main/java/com/messagebird/objects/integrations/WhatsAppTemplateResponse.java
+++ b/api/src/main/java/com/messagebird/objects/integrations/TemplateResponse.java
@@ -5,11 +5,11 @@
import java.util.List;
/**
- * WhatsApp Template response using integrations API.
+ * Template response using integrations API.
*
* @author ssk910
*/
-public class WhatsAppTemplateResponse implements Serializable {
+public class TemplateResponse implements Serializable {
private static final long serialVersionUID = 7154209824478715861L;
private String name;
diff --git a/api/src/test/java/com/messagebird/MessageBirdClientTest.java b/api/src/test/java/com/messagebird/MessageBirdClientTest.java
index 73731f96..ea7ed524 100644
--- a/api/src/test/java/com/messagebird/MessageBirdClientTest.java
+++ b/api/src/test/java/com/messagebird/MessageBirdClientTest.java
@@ -4,19 +4,14 @@
import com.messagebird.exceptions.NotFoundException;
import com.messagebird.exceptions.UnauthorizedException;
import com.messagebird.objects.*;
-import com.messagebird.objects.integrations.WhatsAppTemplate;
-import com.messagebird.objects.integrations.WhatsAppTemplateList;
-import com.messagebird.objects.integrations.WhatsAppTemplateResponse;
+import com.messagebird.objects.integrations.Template;
+import com.messagebird.objects.integrations.TemplateList;
+import com.messagebird.objects.integrations.TemplateResponse;
import com.messagebird.objects.voicecalls.*;
import java.util.ArrayList;
-import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
-import org.junit.Rule;
import org.junit.Test;
-import org.junit.rules.ExpectedException;
-import org.mockito.ArgumentCaptor;
-import org.mockito.Captor;
import org.mockito.Mockito;
import java.io.*;
@@ -26,7 +21,6 @@
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
-import org.mockito.stubbing.OngoingStubbing;
import static com.messagebird.MessageBirdClient.*;
import static org.junit.Assert.*;
@@ -43,13 +37,6 @@ public class MessageBirdClientTest {
MessageBirdServiceImpl messageBirdService;
MessageBirdClient messageBirdClient;
- @Captor
- ArgumentCaptor argument = ArgumentCaptor.forClass(WhatsAppTemplateResponse.class);
-
- @Captor
- ArgumentCaptor valueCaptor;
-
-
@BeforeClass
public static void setUpClass() {
messageBirdAccessKey = System.getProperty("messageBirdAccessKey");
@@ -1066,8 +1053,8 @@ public void testDownloadFileWithNullBasePath() throws GeneralException, Unauthor
@Test
public void testCreateWhatsAppTemplate() throws UnauthorizedException, GeneralException {
- final WhatsAppTemplateResponse templateResponse = TestUtil.createWhatsAppTemplateResponse("sample_template_name", "ko");
- final WhatsAppTemplate template = TestUtil.createWhatsAppTemplate("sample_template_name", "ko");
+ final TemplateResponse templateResponse = TestUtil.createWhatsAppTemplateResponse("sample_template_name", "ko");
+ final Template template = TestUtil.createWhatsAppTemplate("sample_template_name", "ko");
MessageBirdService messageBirdServiceMock = mock(MessageBirdService.class);
MessageBirdClient messageBirdClientInjectMock = new MessageBirdClient(messageBirdServiceMock);
@@ -1079,12 +1066,12 @@ public void testCreateWhatsAppTemplate() throws UnauthorizedException, GeneralEx
TEMPLATES_PATH
);
- when(messageBirdServiceMock.sendPayLoad(url, template, WhatsAppTemplateResponse.class))
+ when(messageBirdServiceMock.sendPayLoad(url, template, TemplateResponse.class))
.thenReturn(templateResponse);
- final WhatsAppTemplateResponse response = messageBirdClientInjectMock.createWhatsAppTemplate(template);
+ final TemplateResponse response = messageBirdClientInjectMock.createWhatsAppTemplate(template);
- verify(messageBirdServiceMock, times(1)).sendPayLoad(url, template, WhatsAppTemplateResponse.class);
+ verify(messageBirdServiceMock, times(1)).sendPayLoad(url, template, TemplateResponse.class);
assertNotNull(response);
assertEquals(response.getName(), templateResponse.getName());
assertEquals(response.getLanguage(), templateResponse.getLanguage());
@@ -1103,7 +1090,7 @@ public void testCreateWhatsAppTemplate() throws UnauthorizedException, GeneralEx
@Test
public void testListWhatsAppTemplates() throws UnauthorizedException, GeneralException {
- final WhatsAppTemplateList templateList = TestUtil.createWhatsAppTemplateList("sample_template_name");
+ final TemplateList templateList = TestUtil.createWhatsAppTemplateList("sample_template_name");
MessageBirdService messageBirdServiceMock = mock(MessageBirdService.class);
MessageBirdClient messageBirdClientInjectMock = new MessageBirdClient(messageBirdServiceMock);
@@ -1114,11 +1101,11 @@ public void testListWhatsAppTemplates() throws UnauthorizedException, GeneralExc
TEMPLATES_PATH
);
- when(messageBirdServiceMock.requestList(url, 0, 0, WhatsAppTemplateList.class))
+ when(messageBirdServiceMock.requestList(url, 0, 0, TemplateList.class))
.thenReturn(templateList);
- final WhatsAppTemplateList response = messageBirdClientInjectMock.listWhatsAppTemplates(0, 0);
- verify(messageBirdServiceMock, times(1)).requestList(url, 0, 0, WhatsAppTemplateList.class);
+ final TemplateList response = messageBirdClientInjectMock.listWhatsAppTemplates(0, 0);
+ verify(messageBirdServiceMock, times(1)).requestList(url, 0, 0, TemplateList.class);
assertNotNull(response);
for(int i = 0; i < response.getItems().size() ; i++) {
assertReflectionEquals(response.getItems().get(i), templateList.getItems().get(i));
@@ -1129,9 +1116,9 @@ public void testListWhatsAppTemplates() throws UnauthorizedException, GeneralExc
public void testGetWhatsAppTemplatesBy()
throws GeneralException, UnauthorizedException, NotFoundException, ClassNotFoundException {
final String templateName = "sample_template_name";
- final WhatsAppTemplateResponse templateResponse1 = TestUtil.createWhatsAppTemplateResponse(templateName, "en_US");
- final WhatsAppTemplateResponse templateResponse2 = TestUtil.createWhatsAppTemplateResponse("another_template", "en_US");
- final List templateList = new ArrayList<>();
+ final TemplateResponse templateResponse1 = TestUtil.createWhatsAppTemplateResponse(templateName, "en_US");
+ final TemplateResponse templateResponse2 = TestUtil.createWhatsAppTemplateResponse("another_template", "en_US");
+ final List templateList = new ArrayList<>();
templateList.add(templateResponse1);
templateList.add(templateResponse2);
@@ -1145,11 +1132,11 @@ public void testGetWhatsAppTemplatesBy()
TEMPLATES_PATH
);
- when(messageBirdServiceMock.requestByIdAsList(url, templateName, WhatsAppTemplateResponse.class))
+ when(messageBirdServiceMock.requestByIdAsList(url, templateName, TemplateResponse.class))
.thenReturn(templateList);
- final List response = messageBirdClientInjectMock.getWhatsAppTemplatesBy(templateName);
- verify(messageBirdServiceMock, times(1)).requestByIdAsList(url, templateName, WhatsAppTemplateResponse.class);
+ final List response = messageBirdClientInjectMock.getWhatsAppTemplatesBy(templateName);
+ verify(messageBirdServiceMock, times(1)).requestByIdAsList(url, templateName, TemplateResponse.class);
assertNotNull(response);
assertEquals(response.size(), templateList.size());
for(int i = 0; i < response.size() ; i++) {
@@ -1162,7 +1149,7 @@ public void testFetchWhatsAppTemplateBy()
throws UnauthorizedException, GeneralException, NotFoundException {
final String templateName = "sample_template_name";
final String language = "ko";
- final WhatsAppTemplateResponse template = TestUtil.createWhatsAppTemplateResponse(templateName, language);
+ final TemplateResponse template = TestUtil.createWhatsAppTemplateResponse(templateName, language);
MessageBirdService messageBirdServiceMock = mock(MessageBirdService.class);
MessageBirdClient messageBirdClientInjectMock = new MessageBirdClient(messageBirdServiceMock);
@@ -1176,11 +1163,11 @@ public void testFetchWhatsAppTemplateBy()
language
);
- when(messageBirdServiceMock.request(url, WhatsAppTemplateResponse.class))
+ when(messageBirdServiceMock.request(url, TemplateResponse.class))
.thenReturn(template);
- final WhatsAppTemplateResponse response = messageBirdClientInjectMock.fetchWhatsAppTemplateBy(templateName, language);
- verify(messageBirdServiceMock, times(1)).request(url, WhatsAppTemplateResponse.class);
+ final TemplateResponse response = messageBirdClientInjectMock.fetchWhatsAppTemplateBy(templateName, language);
+ verify(messageBirdServiceMock, times(1)).request(url, TemplateResponse.class);
assertNotNull(response);
assertEquals(response.getName(), template.getName());
assertEquals(response.getLanguage(), template.getLanguage());
diff --git a/api/src/test/java/com/messagebird/TestUtil.java b/api/src/test/java/com/messagebird/TestUtil.java
index 07072aff..9cf0b2b9 100644
--- a/api/src/test/java/com/messagebird/TestUtil.java
+++ b/api/src/test/java/com/messagebird/TestUtil.java
@@ -10,9 +10,9 @@
import com.messagebird.objects.integrations.HSMComponentType;
import com.messagebird.objects.integrations.HSMExample;
import com.messagebird.objects.integrations.HSMStatus;
-import com.messagebird.objects.integrations.WhatsAppTemplate;
-import com.messagebird.objects.integrations.WhatsAppTemplateList;
-import com.messagebird.objects.integrations.WhatsAppTemplateResponse;
+import com.messagebird.objects.integrations.Template;
+import com.messagebird.objects.integrations.TemplateList;
+import com.messagebird.objects.integrations.TemplateResponse;
import com.messagebird.objects.voicecalls.*;
import java.util.*;
@@ -302,8 +302,8 @@ private static HSMComponent createHSMComponentButton() {
return buttonComponent;
}
- public static WhatsAppTemplateResponse createWhatsAppTemplateResponse(final String templateName, final String language) {
- final WhatsAppTemplateResponse templateResponse = new WhatsAppTemplateResponse();
+ public static TemplateResponse createWhatsAppTemplateResponse(final String templateName, final String language) {
+ final TemplateResponse templateResponse = new TemplateResponse();
templateResponse.setName(templateName);
templateResponse.setLanguage(language);
templateResponse.setCategory(HSMCategory.ACCOUNT_UPDATE);
@@ -321,8 +321,8 @@ public static WhatsAppTemplateResponse createWhatsAppTemplateResponse(final Stri
return templateResponse;
}
- public static WhatsAppTemplate createWhatsAppTemplate(final String templateName, final String language) {
- final WhatsAppTemplate template = new WhatsAppTemplate();
+ public static Template createWhatsAppTemplate(final String templateName, final String language) {
+ final Template template = new Template();
template.setName(templateName);
template.setLanguage(language);
template.setCategory(HSMCategory.ACCOUNT_UPDATE);
@@ -337,12 +337,12 @@ public static WhatsAppTemplate createWhatsAppTemplate(final String templateName,
return template;
}
- public static WhatsAppTemplateList createWhatsAppTemplateList(final String templateName) {
- final WhatsAppTemplateResponse template1 = TestUtil.createWhatsAppTemplateResponse(templateName, "en_US");
- final WhatsAppTemplateResponse template2 = TestUtil.createWhatsAppTemplateResponse(templateName, "ko");
- final WhatsAppTemplateList templateList = new WhatsAppTemplateList();
+ public static TemplateList createWhatsAppTemplateList(final String templateName) {
+ final TemplateResponse template1 = TestUtil.createWhatsAppTemplateResponse(templateName, "en_US");
+ final TemplateResponse template2 = TestUtil.createWhatsAppTemplateResponse(templateName, "ko");
+ final TemplateList templateList = new TemplateList();
- List templateResponseList = new ArrayList<>();
+ List templateResponseList = new ArrayList<>();
templateResponseList.add(template1);
templateResponseList.add(template2);
diff --git a/examples/src/main/java/ExampleCreateTemplate.java b/examples/src/main/java/ExampleCreateTemplate.java
index 275c5bab..8e2d9887 100644
--- a/examples/src/main/java/ExampleCreateTemplate.java
+++ b/examples/src/main/java/ExampleCreateTemplate.java
@@ -10,8 +10,8 @@
import com.messagebird.objects.integrations.HSMComponentFormat;
import com.messagebird.objects.integrations.HSMComponentType;
import com.messagebird.objects.integrations.HSMExample;
-import com.messagebird.objects.integrations.WhatsAppTemplate;
-import com.messagebird.objects.integrations.WhatsAppTemplateResponse;
+import com.messagebird.objects.integrations.Template;
+import com.messagebird.objects.integrations.TemplateResponse;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -75,7 +75,7 @@ public static void main(String[] args) {
buttonComponent.setButtons(buttons);
/* set components */
- final WhatsAppTemplate template = new WhatsAppTemplate();
+ final Template template = new Template();
final List components = new ArrayList<>();
components.add(headerComponent);
components.add(bodyComponent);
@@ -88,7 +88,7 @@ public static void main(String[] args) {
template.setCategory(HSMCategory.ACCOUNT_UPDATE);
try {
- WhatsAppTemplateResponse response = messageBirdClient.createWhatsAppTemplate(template);
+ TemplateResponse response = messageBirdClient.createWhatsAppTemplate(template);
System.out.println(response.toString());
} catch (GeneralException | UnauthorizedException exception) {
exception.printStackTrace();
diff --git a/examples/src/main/java/ExampleFetchTemplateByNameAndLanguage.java b/examples/src/main/java/ExampleFetchTemplateByNameAndLanguage.java
index e1ad9bb6..02377ed0 100644
--- a/examples/src/main/java/ExampleFetchTemplateByNameAndLanguage.java
+++ b/examples/src/main/java/ExampleFetchTemplateByNameAndLanguage.java
@@ -4,7 +4,7 @@
import com.messagebird.exceptions.GeneralException;
import com.messagebird.exceptions.NotFoundException;
import com.messagebird.exceptions.UnauthorizedException;
-import com.messagebird.objects.integrations.WhatsAppTemplateResponse;
+import com.messagebird.objects.integrations.TemplateResponse;
/**
* Fetch template by name and language
@@ -32,7 +32,7 @@ public static void main(String[] args) {
try {
System.out.println("Fetching WhatsApp Template list by {name: " + templateName + ", language: " + language + "}");
- final WhatsAppTemplateResponse template = messageBirdClient.fetchWhatsAppTemplateBy(templateName, language);
+ final TemplateResponse template = messageBirdClient.fetchWhatsAppTemplateBy(templateName, language);
System.out.println(template.toString());
} catch (GeneralException | UnauthorizedException | NotFoundException exception) {
exception.printStackTrace();
diff --git a/examples/src/main/java/ExampleListTemplates.java b/examples/src/main/java/ExampleListTemplates.java
index db9fc21b..b91b2ec2 100644
--- a/examples/src/main/java/ExampleListTemplates.java
+++ b/examples/src/main/java/ExampleListTemplates.java
@@ -3,7 +3,7 @@
import com.messagebird.MessageBirdServiceImpl;
import com.messagebird.exceptions.GeneralException;
import com.messagebird.exceptions.UnauthorizedException;
-import com.messagebird.objects.integrations.WhatsAppTemplateList;
+import com.messagebird.objects.integrations.TemplateList;
/**
* List templates
@@ -27,7 +27,7 @@ public static void main(String[] args) {
try {
System.out.println("Retrieving WhatsApp Template list");
- final WhatsAppTemplateList templateList = messageBirdClient.listWhatsAppTemplates();
+ final TemplateList templateList = messageBirdClient.listWhatsAppTemplates();
System.out.println(templateList.toString());
} catch (GeneralException | UnauthorizedException exception) {
exception.printStackTrace();
diff --git a/examples/src/main/java/ExampleListTemplatesByName.java b/examples/src/main/java/ExampleListTemplatesByName.java
index e68a6446..36159796 100644
--- a/examples/src/main/java/ExampleListTemplatesByName.java
+++ b/examples/src/main/java/ExampleListTemplatesByName.java
@@ -4,7 +4,7 @@
import com.messagebird.exceptions.GeneralException;
import com.messagebird.exceptions.NotFoundException;
import com.messagebird.exceptions.UnauthorizedException;
-import com.messagebird.objects.integrations.WhatsAppTemplateResponse;
+import com.messagebird.objects.integrations.TemplateResponse;
import java.util.List;
/**
@@ -32,7 +32,7 @@ public static void main(String[] args) {
try {
System.out.println("Retrieving WhatsApp Template list by name : " + templateName);
- final List templateList = messageBirdClient.getWhatsAppTemplatesBy(templateName);
+ final List templateList = messageBirdClient.getWhatsAppTemplatesBy(templateName);
System.out.println(templateList.toString());
} catch (GeneralException | UnauthorizedException | NotFoundException exception) {
exception.printStackTrace();
From ef2bd682e43fda6a5c00c255509d64ca7f5141a6 Mon Sep 17 00:00:00 2001
From: ssk910
Date: Thu, 7 Oct 2021 21:14:56 +0900
Subject: [PATCH 018/216] feat: Add more validations for required fields in
Template
#160
---
.../com/messagebird/MessageBirdClient.java | 7 +-
.../objects/integrations/HSMComponent.java | 25 +++---
.../integrations/HSMComponentButton.java | 7 +-
.../objects/integrations/Template.java | 80 +++++++++++++++----
4 files changed, 84 insertions(+), 35 deletions(-)
diff --git a/api/src/main/java/com/messagebird/MessageBirdClient.java b/api/src/main/java/com/messagebird/MessageBirdClient.java
index d463488a..920f8a86 100644
--- a/api/src/main/java/com/messagebird/MessageBirdClient.java
+++ b/api/src/main/java/com/messagebird/MessageBirdClient.java
@@ -1864,11 +1864,12 @@ public String downloadFile(String id, String filename, String basePath) throws G
*
* @param template {@link Template} object to be created
* @return {@link TemplateResponse} response object
- * @throws UnauthorizedException if client is unauthorized
- * @throws GeneralException general exception or invalid template format
+ * @throws UnauthorizedException if client is unauthorized
+ * @throws GeneralException general exception
+ * @throws IllegalArgumentException invalid template format
*/
public TemplateResponse createWhatsAppTemplate(final Template template)
- throws UnauthorizedException, GeneralException {
+ throws UnauthorizedException, GeneralException, IllegalArgumentException {
template.validate();
String url = String.format(
diff --git a/api/src/main/java/com/messagebird/objects/integrations/HSMComponent.java b/api/src/main/java/com/messagebird/objects/integrations/HSMComponent.java
index eb6b5694..51b7efba 100644
--- a/api/src/main/java/com/messagebird/objects/integrations/HSMComponent.java
+++ b/api/src/main/java/com/messagebird/objects/integrations/HSMComponent.java
@@ -1,6 +1,5 @@
package com.messagebird.objects.integrations;
-import com.messagebird.exceptions.GeneralException;
import java.util.List;
/**
@@ -71,9 +70,9 @@ public String toString() {
/**
* Check if this component is valid.
*
- * @throws GeneralException Occurs when validation is not passed.
+ * @throws IllegalArgumentException Occurs when validation is not passed.
*/
- public void validateComponent() throws GeneralException {
+ public void validateComponent() throws IllegalArgumentException {
this.validateButtons();
this.validateComponentExample();
}
@@ -81,9 +80,9 @@ public void validateComponent() throws GeneralException {
/**
* Check if button list is valid.
*
- * @throws GeneralException Occurs when validation is not passed.
+ * @throws IllegalArgumentException Occurs when validation is not passed.
*/
- private void validateButtons() throws GeneralException {
+ private void validateButtons() throws IllegalArgumentException {
if (this.buttons == null) {
return;
}
@@ -96,9 +95,9 @@ private void validateButtons() throws GeneralException {
/**
* Check for header_text and header_url.
*
- * @throws GeneralException Occurs when {@code header_text} or {@code header_url} is not able to use.
+ * @throws IllegalArgumentException Occurs when {@code header_text} or {@code header_url} is not able to use.
*/
- private void validateComponentExample() throws GeneralException {
+ private void validateComponentExample() throws IllegalArgumentException {
final boolean isExampleNotNull = this.example != null;
final boolean isHeaderTextNotEmpty =
isExampleNotNull && !(this.example.getHeader_text() == null || this.example.getHeader_text()
@@ -119,26 +118,26 @@ private void validateComponentExample() throws GeneralException {
/**
* Check if header_text is able to use.
*
- * @throws GeneralException Occurs when type is not {@code HEADER} and format is not {@code TEXT}.
+ * @throws IllegalArgumentException Occurs when type is not {@code HEADER} and format is not {@code TEXT}.
*/
- private void checkHeaderText() throws GeneralException {
+ private void checkHeaderText() throws IllegalArgumentException {
if (!(type.equals(HSMComponentType.HEADER)
&& format.equals(HSMComponentFormat.TEXT))
) {
- throw new GeneralException("\"header_text\" is available for only HEADER type and TEXT format.");
+ throw new IllegalArgumentException("\"header_text\" is available for only HEADER type and TEXT format.");
}
}
/**
* Check if header_url is able to use.
*
- * @throws GeneralException Occurs when type is not {@code HEADER} and format is not {@code IMAGE}.
+ * @throws IllegalArgumentException Occurs when type is not {@code HEADER} and format is not {@code IMAGE}.
*/
- private void checkHeaderUrl() throws GeneralException {
+ private void checkHeaderUrl() throws IllegalArgumentException {
if (!(type.equals(HSMComponentType.HEADER)
&& format.equals(HSMComponentFormat.IMAGE))
) {
- throw new GeneralException("\"header_url\" is available for only HEADER type and IMAGE format.");
+ throw new IllegalArgumentException("\"header_url\" is available for only HEADER type and IMAGE format.");
}
}
}
diff --git a/api/src/main/java/com/messagebird/objects/integrations/HSMComponentButton.java b/api/src/main/java/com/messagebird/objects/integrations/HSMComponentButton.java
index 02dd241c..6438f79e 100644
--- a/api/src/main/java/com/messagebird/objects/integrations/HSMComponentButton.java
+++ b/api/src/main/java/com/messagebird/objects/integrations/HSMComponentButton.java
@@ -1,6 +1,5 @@
package com.messagebird.objects.integrations;
-import com.messagebird.exceptions.GeneralException;
import java.util.List;
/**
@@ -71,9 +70,9 @@ public String toString() {
/**
* Check if example field is able to use.
*
- * @throws GeneralException Occurs if button type is not {@code URL} or {@code QUICK_REPLY}.
+ * @throws IllegalArgumentException Occurs if button type is not {@code URL} or {@code QUICK_REPLY}.
*/
- public void validateButtonExample() throws GeneralException {
+ public void validateButtonExample() throws IllegalArgumentException {
final boolean isExampleEmpty = this.example == null || this.example.isEmpty();
final boolean isNotProperType = !(this.type.equals(HSMComponentButtonType.URL)
|| this.type.equals(HSMComponentButtonType.QUICK_REPLY));
@@ -83,7 +82,7 @@ public void validateButtonExample() throws GeneralException {
}
if (isNotProperType) {
- throw new GeneralException("An example field in HSMComponentButton is available for only URL or QUICK_REPLY button types.");
+ throw new IllegalArgumentException("An example field in HSMComponentButton is available for only URL or QUICK_REPLY button types.");
}
}
}
diff --git a/api/src/main/java/com/messagebird/objects/integrations/Template.java b/api/src/main/java/com/messagebird/objects/integrations/Template.java
index 6bcf145d..715aeb48 100644
--- a/api/src/main/java/com/messagebird/objects/integrations/Template.java
+++ b/api/src/main/java/com/messagebird/objects/integrations/Template.java
@@ -1,6 +1,5 @@
package com.messagebird.objects.integrations;
-import com.messagebird.exceptions.GeneralException;
import java.util.List;
/**
@@ -59,28 +58,79 @@ public void setCategory(HSMCategory category) {
this.category = category;
}
+ @Override
+ public String toString() {
+ return "WhatsAppTemplate{" +
+ "name='" + name + '\'' +
+ ", language='" + language + '\'' +
+ ", components=" + components +
+ ", category='" + category + '\'' +
+ '}';
+ }
+
+ /**
+ * Validate required fields: components, name, language, category
+ *
+ * @throws IllegalArgumentException if required fields are invalid.
+ */
+ public void validate() throws IllegalArgumentException {
+ this.validateComponents();
+ this.validateName();
+ this.validateLanguage();
+ this.validateCategory();
+ }
+
/**
* Check if components field is valid.
*
- * @throws GeneralException Occurs when it is invalid.
+ * @throws IllegalArgumentException If components field is null or empty list.
*/
- public void validate() throws GeneralException {
- if (this.components == null) {
- return;
+ private void validateComponents() throws IllegalArgumentException {
+ final boolean componentsNotEmpty = !(this.components == null || this.components.isEmpty());
+
+ if (componentsNotEmpty) {
+ for (final HSMComponent component : this.components) {
+ component.validateComponent();
+ }
+ } else {
+ throw new IllegalArgumentException("A \"components\" field is required and should not be empty list.");
}
+ }
- for (final HSMComponent component : this.components) {
- component.validateComponent();
+ /**
+ * Check if name field is valid.
+ *
+ * @throws IllegalArgumentException If name field is null or empty string.
+ */
+ private void validateName() {
+ if (this.name == null) {
+ throw new IllegalArgumentException("A \"name\" field is required.");
+ } else if (this.name.length() == 0) {
+ throw new IllegalArgumentException("A \"name\" field can not be an empty string.");
}
}
- @Override
- public String toString() {
- return "WhatsAppTemplate{" +
- "name='" + name + '\'' +
- ", language='" + language + '\'' +
- ", components=" + components +
- ", category='" + category + '\'' +
- '}';
+ /**
+ * Check if language field is valid.
+ *
+ * @throws IllegalArgumentException If language field is null or empty string.
+ */
+ private void validateLanguage() {
+ if (this.language == null) {
+ throw new IllegalArgumentException("A \"language\" field is required.");
+ } else if (this.language.length() == 0) {
+ throw new IllegalArgumentException("A \"language\" field can not be an empty string.");
+ }
+ }
+
+ /**
+ * Check if category field is valid.
+ *
+ * @throws IllegalArgumentException If category field is null.
+ */
+ private void validateCategory() {
+ if (this.category == null) {
+ throw new IllegalArgumentException("A \"category\" field is required.");
+ }
}
}
From e528447951c8f19cc690e5ded657ff5595e777a6 Mon Sep 17 00:00:00 2001
From: "deniz@messagebird.com"
Date: Fri, 8 Oct 2021 10:27:53 +0200
Subject: [PATCH 019/216] partners api implemented
---
.../com/messagebird/MessageBirdClient.java | 117 +++++++++++++-----
.../com/messagebird/objects/AccessKey.java | 31 +++++
.../objects/ChildAccountCreateResponse.java | 51 ++++++++
.../objects/ChildAccountDetailedResponse.java | 13 ++
.../objects/ChildAccountResponse.java | 22 ++++
.../objects/PartnerAccountsResponse.java | 15 +++
.../messagebird/MessageBirdClientTest.java | 82 ++++++++++++
.../test/java/com/messagebird/TestUtil.java | 39 ++++++
.../main/java/ExampleCreateChildAccount.java | 26 ++++
.../main/java/ExampleDeleteChildAccount.java | 27 ++++
.../main/java/ExampleGetChildAccountById.java | 26 ++++
.../main/java/ExampleGetChildAccounts.java | 24 ++++
.../main/java/ExampleUpdateChildAccount.java | 25 ++++
13 files changed, 468 insertions(+), 30 deletions(-)
create mode 100644 api/src/main/java/com/messagebird/objects/AccessKey.java
create mode 100644 api/src/main/java/com/messagebird/objects/ChildAccountCreateResponse.java
create mode 100644 api/src/main/java/com/messagebird/objects/ChildAccountDetailedResponse.java
create mode 100644 api/src/main/java/com/messagebird/objects/ChildAccountResponse.java
create mode 100644 api/src/main/java/com/messagebird/objects/PartnerAccountsResponse.java
create mode 100644 examples/src/main/java/ExampleCreateChildAccount.java
create mode 100644 examples/src/main/java/ExampleDeleteChildAccount.java
create mode 100644 examples/src/main/java/ExampleGetChildAccountById.java
create mode 100644 examples/src/main/java/ExampleGetChildAccounts.java
create mode 100644 examples/src/main/java/ExampleUpdateChildAccount.java
diff --git a/api/src/main/java/com/messagebird/MessageBirdClient.java b/api/src/main/java/com/messagebird/MessageBirdClient.java
index 0bff2580..378cf334 100644
--- a/api/src/main/java/com/messagebird/MessageBirdClient.java
+++ b/api/src/main/java/com/messagebird/MessageBirdClient.java
@@ -3,35 +3,7 @@
import com.messagebird.exceptions.GeneralException;
import com.messagebird.exceptions.NotFoundException;
import com.messagebird.exceptions.UnauthorizedException;
-import com.messagebird.objects.Balance;
-import com.messagebird.objects.Contact;
-import com.messagebird.objects.ContactList;
-import com.messagebird.objects.ContactRequest;
-import com.messagebird.objects.ErrorReport;
-import com.messagebird.objects.FileUploadResponse;
-import com.messagebird.objects.Group;
-import com.messagebird.objects.GroupList;
-import com.messagebird.objects.GroupRequest;
-import com.messagebird.objects.Hlr;
-import com.messagebird.objects.Lookup;
-import com.messagebird.objects.LookupHlr;
-import com.messagebird.objects.Message;
-import com.messagebird.objects.MessageList;
-import com.messagebird.objects.MessageResponse;
-import com.messagebird.objects.MsgType;
-import com.messagebird.objects.PagedPaging;
-import com.messagebird.objects.PhoneNumbersLookup;
-import com.messagebird.objects.PhoneNumbersResponse;
-import com.messagebird.objects.PurchasedNumber;
-import com.messagebird.objects.PurchasedNumberCreatedResponse;
-import com.messagebird.objects.PurchasedNumbersResponse;
-import com.messagebird.objects.PurchasedNumbersFilter;
-import com.messagebird.objects.Verify;
-import com.messagebird.objects.VerifyMessage;
-import com.messagebird.objects.VerifyRequest;
-import com.messagebird.objects.VoiceMessage;
-import com.messagebird.objects.VoiceMessageList;
-import com.messagebird.objects.VoiceMessageResponse;
+import com.messagebird.objects.*;
import com.messagebird.objects.conversations.Conversation;
import com.messagebird.objects.conversations.ConversationList;
import com.messagebird.objects.conversations.ConversationMessage;
@@ -103,6 +75,7 @@ public class MessageBirdClient {
static final String NUMBERS_CALLS_BASE_URL = "https://numbers.messagebird.com/v1";
static final String MESSAGING_BASE_URL = "https://messaging.messagebird.com/v1";
private static String[] supportedLanguages = {"de-DE", "en-AU", "en-UK", "en-US", "es-ES", "es-LA", "fr-FR", "it-IT", "nl-NL", "pt-BR"};
+ static final String PARTNER_ACCOUNTS_BASE_URL = "https://partner-accounts.messagebird.com";
private static final String BALANCEPATH = "/balance";
private static final String CONTACTPATH = "/contacts";
@@ -496,7 +469,7 @@ Verify getVerifyObject(String id) throws NotFoundException, GeneralException, Un
}
/**
- * @param id id is for the email message part of a verify object
+ * @param messageId is for the email message part of a verify object
* @return Verify object
* @throws NotFoundException if id is not found
* @throws UnauthorizedException if client is unauthorized
@@ -1848,4 +1821,88 @@ public String downloadFile(String id, String filename, String basePath) throws G
final String url = String.format("%s%s/%s", MESSAGING_BASE_URL, FILES_PATH, id);
return messageBirdService.getBinaryData(url, basePath, filename);
}
+
+ /**
+ * Function to create a child account
+ *
+ * @param name of child account to create
+ * @return ChildAccountResponse created
+ * @throws UnauthorizedException if client is unauthorized
+ * @throws GeneralException general exception
+ */
+ public ChildAccountCreateResponse createChildAccount(String name) throws UnauthorizedException, GeneralException {
+ if (name == null) {
+ throw new IllegalArgumentException("Name must be specified.");
+ }
+
+ String url = String.format("%s%s", PARTNER_ACCOUNTS_BASE_URL, "/child-accounts");
+ return messageBirdService.sendPayLoad(url, name, ChildAccountCreateResponse.class);
+ }
+
+ /**
+ * Function to update a child account
+ *
+ * @param id of child account to update
+ * @return ChildAccountResponse created
+ * @throws UnauthorizedException if client is unauthorized
+ * @throws GeneralException general exception
+ */
+ public ChildAccountResponse updateChildAccount(String name, String id) throws UnauthorizedException, GeneralException {
+ if (name == null) {
+ throw new IllegalArgumentException("Name must be specified.");
+ }
+
+ if (id == null) {
+ throw new IllegalArgumentException("Child account id must be specified.");
+ }
+
+ final String url = String.format("%s/child-accounts/%s", PARTNER_ACCOUNTS_BASE_URL, id);
+ return messageBirdService.sendPayLoad("PATCH", url, name, ChildAccountResponse.class);
+ }
+
+ /**
+ * Function to get a child account
+ *
+ * @param id of child account to update
+ * @return ChildAccountResponse created
+ * @throws UnauthorizedException if client is unauthorized
+ * @throws GeneralException general exception
+ * @throws NotFoundException if id is not found
+ */
+ public ChildAccountDetailedResponse getChildAccountById(String id) throws UnauthorizedException, GeneralException, NotFoundException {
+ if (id == null) {
+ throw new IllegalArgumentException("Child account id must be specified.");
+ }
+
+ return messageBirdService.requestByID(PARTNER_ACCOUNTS_BASE_URL, id, ChildAccountDetailedResponse.class);
+ }
+
+ /**
+ * Function to get a child account
+ *
+ * @return ChildAccountResponse created
+ * @throws UnauthorizedException if client is unauthorized
+ * @throws GeneralException general exception
+ */
+ public PartnerAccountsResponse getChildAccounts(final Integer offset, final Integer limit) throws UnauthorizedException, GeneralException {
+ verifyOffsetAndLimit(offset, limit);
+ return messageBirdService.requestList(PARTNER_ACCOUNTS_BASE_URL, offset, limit, PartnerAccountsResponse.class);
+ }
+
+ /**
+ * Function to delete a child account
+ *
+ * @param id of child account to delete
+ * @throws UnauthorizedException if client is unauthorized
+ * @throws GeneralException general exception
+ * @throws NotFoundException if id is not found
+ */
+ public void deleteChildAccount(String id) throws UnauthorizedException, GeneralException, NotFoundException {
+ if (id == null) {
+ throw new IllegalArgumentException("Child account id must be specified.");
+ }
+
+ String url = String.format("%s/child-accounts/%s", PARTNER_ACCOUNTS_BASE_URL, id);
+ messageBirdService.deleteByID(url, id);
+ }
}
diff --git a/api/src/main/java/com/messagebird/objects/AccessKey.java b/api/src/main/java/com/messagebird/objects/AccessKey.java
new file mode 100644
index 00000000..14505dc7
--- /dev/null
+++ b/api/src/main/java/com/messagebird/objects/AccessKey.java
@@ -0,0 +1,31 @@
+package com.messagebird.objects;
+
+public class AccessKey {
+ private String id;
+ private String key;
+ private String mod;
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public String getKey() {
+ return key;
+ }
+
+ public void setKey(String key) {
+ this.key = key;
+ }
+
+ public String getMod() {
+ return mod;
+ }
+
+ public void setMod(String mod) {
+ this.mod = mod;
+ }
+}
diff --git a/api/src/main/java/com/messagebird/objects/ChildAccountCreateResponse.java b/api/src/main/java/com/messagebird/objects/ChildAccountCreateResponse.java
new file mode 100644
index 00000000..768fd71f
--- /dev/null
+++ b/api/src/main/java/com/messagebird/objects/ChildAccountCreateResponse.java
@@ -0,0 +1,51 @@
+package com.messagebird.objects;
+
+import java.util.List;
+
+public class ChildAccountCreateResponse {
+ private String id;
+ private String name;
+ private List accessKeys;
+ private String signingKey;
+ private String invoiceAggregation;
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public List getAccessKeys() {
+ return accessKeys;
+ }
+
+ public void setAccessKeys(List accessKeys) {
+ this.accessKeys = accessKeys;
+ }
+
+ public String getSigningKey() {
+ return signingKey;
+ }
+
+ public void setSigningKey(String signingKey) {
+ this.signingKey = signingKey;
+ }
+
+ public String getInvoiceAggregation() {
+ return invoiceAggregation;
+ }
+
+ public void setInvoiceAggregation(String invoiceAggregation) {
+ this.invoiceAggregation = invoiceAggregation;
+ }
+}
diff --git a/api/src/main/java/com/messagebird/objects/ChildAccountDetailedResponse.java b/api/src/main/java/com/messagebird/objects/ChildAccountDetailedResponse.java
new file mode 100644
index 00000000..d3aac825
--- /dev/null
+++ b/api/src/main/java/com/messagebird/objects/ChildAccountDetailedResponse.java
@@ -0,0 +1,13 @@
+package com.messagebird.objects;
+
+public class ChildAccountDetailedResponse extends ChildAccountResponse{
+ private String invoiceAggregation;
+
+ public String getInvoiceAggregation() {
+ return invoiceAggregation;
+ }
+
+ public void setInvoiceAggregation(String invoiceAggregation) {
+ this.invoiceAggregation = invoiceAggregation;
+ }
+}
diff --git a/api/src/main/java/com/messagebird/objects/ChildAccountResponse.java b/api/src/main/java/com/messagebird/objects/ChildAccountResponse.java
new file mode 100644
index 00000000..2e4853aa
--- /dev/null
+++ b/api/src/main/java/com/messagebird/objects/ChildAccountResponse.java
@@ -0,0 +1,22 @@
+package com.messagebird.objects;
+
+public class ChildAccountResponse {
+ private String id;
+ private String name;
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+}
diff --git a/api/src/main/java/com/messagebird/objects/PartnerAccountsResponse.java b/api/src/main/java/com/messagebird/objects/PartnerAccountsResponse.java
new file mode 100644
index 00000000..410cd360
--- /dev/null
+++ b/api/src/main/java/com/messagebird/objects/PartnerAccountsResponse.java
@@ -0,0 +1,15 @@
+package com.messagebird.objects;
+
+import java.util.List;
+
+public class PartnerAccountsResponse {
+ private List childAccountResponses;
+
+ public List getChildAccountResponses() {
+ return childAccountResponses;
+ }
+
+ public void setChildAccountResponses(List childAccountResponses) {
+ this.childAccountResponses = childAccountResponses;
+ }
+}
diff --git a/api/src/test/java/com/messagebird/MessageBirdClientTest.java b/api/src/test/java/com/messagebird/MessageBirdClientTest.java
index 956b177b..457cd94e 100644
--- a/api/src/test/java/com/messagebird/MessageBirdClientTest.java
+++ b/api/src/test/java/com/messagebird/MessageBirdClientTest.java
@@ -19,6 +19,7 @@
import java.util.Map;
import static com.messagebird.MessageBirdClient.*;
+import static com.messagebird.TestUtil.*;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
import static org.unitils.reflectionassert.ReflectionAssert.assertReflectionEquals;
@@ -1042,4 +1043,85 @@ public void testDownloadFileWithNullBasePath() throws GeneralException, Unauthor
String url = MESSAGING_BASE_URL + FILES_PATH + "/" + id;
verify(messageBirdServiceMock, times(1)).getBinaryData(url, null, filename);
}
+
+ @Test
+ public void testCreateChildAccounts() throws GeneralException, UnauthorizedException {
+ MessageBirdService messageBirdServiceMock = mock(MessageBirdService.class);
+ MessageBirdClient messageBirdClientInjectMock = new MessageBirdClient(messageBirdServiceMock);
+ ChildAccountCreateResponse childAccountCreateResponse = createChildAccountCreateResponse();
+ when(messageBirdServiceMock.sendPayLoad(PARTNER_ACCOUNTS_BASE_URL + "/child-accounts" , "name", ChildAccountCreateResponse.class))
+ .thenReturn(childAccountCreateResponse);
+ final ChildAccountCreateResponse response = messageBirdClientInjectMock.createChildAccount("name");
+
+ verify(messageBirdServiceMock, times(1))
+ .sendPayLoad(PARTNER_ACCOUNTS_BASE_URL + "/child-accounts" , "name", ChildAccountCreateResponse.class);
+ assertNotNull(response);
+ assertEquals(response.getId(), childAccountCreateResponse.getId());
+ assertEquals(response.getName(), childAccountCreateResponse.getName());
+ assertEquals(response.getInvoiceAggregation(), childAccountCreateResponse.getInvoiceAggregation());
+ assertEquals(response.getSigningKey(), childAccountCreateResponse.getSigningKey());
+ assertEquals(response.getAccessKeys().get(0).getId(), childAccountCreateResponse.getAccessKeys().get(0).getId());
+ assertEquals(response.getAccessKeys().get(0).getKey(), childAccountCreateResponse.getAccessKeys().get(0).getKey());
+ assertEquals(response.getAccessKeys().get(0).getMod(), childAccountCreateResponse.getAccessKeys().get(0).getMod());
+ }
+
+ @Test
+ public void testGetChildAccount() throws GeneralException, UnauthorizedException, NotFoundException {
+ MessageBirdService messageBirdServiceMock = mock(MessageBirdService.class);
+ MessageBirdClient messageBirdClientInjectMock = new MessageBirdClient(messageBirdServiceMock);
+ ChildAccountDetailedResponse childAccountDetailedResponse = createChildAccountDetailedResponse();
+ when(messageBirdServiceMock.requestByID(PARTNER_ACCOUNTS_BASE_URL, "ANY_ID", ChildAccountDetailedResponse.class))
+ .thenReturn(childAccountDetailedResponse);
+ ChildAccountDetailedResponse response = messageBirdClientInjectMock.getChildAccountById("ANY_ID");
+
+ verify(messageBirdServiceMock, times(1))
+ .requestByID(PARTNER_ACCOUNTS_BASE_URL, "ANY_ID", ChildAccountDetailedResponse.class);
+ assertNotNull(response);
+ assertEquals(response.getId(), childAccountDetailedResponse.getId());
+ assertEquals(response.getName(), childAccountDetailedResponse.getName());
+ assertEquals(response.getInvoiceAggregation(), childAccountDetailedResponse.getInvoiceAggregation());
+ }
+
+ @Test
+ public void testGetChildAccounts() throws GeneralException, UnauthorizedException {
+ MessageBirdService messageBirdServiceMock = mock(MessageBirdService.class);
+ MessageBirdClient messageBirdClientInjectMock = new MessageBirdClient(messageBirdServiceMock);
+ PartnerAccountsResponse partnerAccountsResponse = createPartnerAccountsResponse();
+ when(messageBirdServiceMock.requestList(PARTNER_ACCOUNTS_BASE_URL, 1, 10, PartnerAccountsResponse.class))
+ .thenReturn(partnerAccountsResponse);
+
+ PartnerAccountsResponse response = messageBirdClientInjectMock.getChildAccounts(1, 10);
+
+ verify(messageBirdServiceMock, times(1))
+ .requestList(PARTNER_ACCOUNTS_BASE_URL, 1, 10, PartnerAccountsResponse.class);
+ assertNotNull(response);
+ assertEquals(response.getChildAccountResponses().get(0).getId(), partnerAccountsResponse.getChildAccountResponses().get(0).getId());
+ assertEquals(response.getChildAccountResponses().get(0).getName(), partnerAccountsResponse.getChildAccountResponses().get(0).getName());
+ }
+
+ @Test
+ public void testUpdateChildAccount() throws GeneralException, UnauthorizedException {
+ MessageBirdService messageBirdServiceMock = mock(MessageBirdService.class);
+ MessageBirdClient messageBirdClientInjectMock = new MessageBirdClient(messageBirdServiceMock);
+ ChildAccountResponse childAccountResponse = createChildAccountResponse();
+ final String url = String.format("%s/child-accounts/%s", PARTNER_ACCOUNTS_BASE_URL, "ANY_ID");
+ when(messageBirdServiceMock.sendPayLoad("PATCH", url, "ANY_NAME", ChildAccountResponse.class))
+ .thenReturn(childAccountResponse);
+ ChildAccountResponse response = messageBirdClientInjectMock.updateChildAccount("ANY_NAME", "ANY_ID");
+
+ verify(messageBirdServiceMock, times(1))
+ .sendPayLoad("PATCH", url, "ANY_NAME", ChildAccountResponse.class);
+ assertNotNull(response);
+ assertEquals(response.getId(), childAccountResponse.getId());
+ assertEquals(response.getName(), childAccountResponse.getName());
+ }
+
+ @Test
+ public void testDeleteChildAccount() throws GeneralException, UnauthorizedException, NotFoundException {
+ MessageBirdService messageBirdServiceMock = mock(MessageBirdService.class);
+ MessageBirdClient messageBirdClientInjectMock = new MessageBirdClient(messageBirdServiceMock);
+ String url = String.format("%s/child-accounts/%s", PARTNER_ACCOUNTS_BASE_URL, "ANY_ID");
+ doNothing().when(messageBirdServiceMock).deleteByID(url, "ANY_ID");
+ messageBirdClientInjectMock.deleteChildAccount("id");
+ }
}
diff --git a/api/src/test/java/com/messagebird/TestUtil.java b/api/src/test/java/com/messagebird/TestUtil.java
index 5a854b45..fef25193 100644
--- a/api/src/test/java/com/messagebird/TestUtil.java
+++ b/api/src/test/java/com/messagebird/TestUtil.java
@@ -240,4 +240,43 @@ static ConversationWebhookCreateRequest createConversationWebhookRequest() {
)
);
}
+
+ public static ChildAccountCreateResponse createChildAccountCreateResponse() {
+ final AccessKey accessKey = new AccessKey();
+ accessKey.setId("ANY_ID");
+ accessKey.setKey("ANY_KEY");
+ accessKey.setMod("ANY_MOD");
+
+ final ChildAccountCreateResponse childAccountCreateResponse = new ChildAccountCreateResponse();
+ childAccountCreateResponse.setId("ANY_ID");
+ childAccountCreateResponse.setName("ANY_NAME");
+ childAccountCreateResponse.setAccessKeys(Collections.singletonList(accessKey));
+ childAccountCreateResponse.setInvoiceAggregation("ANY_INVOICE_AGGREGATION");
+ childAccountCreateResponse.setSigningKey("ANY_SIGNING_KEY");
+
+ return childAccountCreateResponse;
+ }
+
+ public static ChildAccountDetailedResponse createChildAccountDetailedResponse(){
+ final ChildAccountDetailedResponse childAccountDetailedResponse = new ChildAccountDetailedResponse();
+ childAccountDetailedResponse.setId("ANY_ID");
+ childAccountDetailedResponse.setName("ANY_NAME");
+ childAccountDetailedResponse.setInvoiceAggregation("ANY_INVOICE_AGGREGATION");
+ return childAccountDetailedResponse;
+ }
+
+ public static ChildAccountResponse createChildAccountResponse(){
+ final ChildAccountResponse childAccountResponse = new ChildAccountResponse();
+ childAccountResponse.setId("ANY_ID");
+ childAccountResponse.setName("ANY_NAME");
+ return childAccountResponse;
+ }
+
+ public static PartnerAccountsResponse createPartnerAccountsResponse(){
+ final ChildAccountResponse childAccountResponse = createChildAccountResponse();
+ final PartnerAccountsResponse partnerAccountsResponse = new PartnerAccountsResponse();
+ partnerAccountsResponse.setChildAccountResponses(Collections.singletonList(childAccountResponse));
+ return partnerAccountsResponse;
+ }
+
}
diff --git a/examples/src/main/java/ExampleCreateChildAccount.java b/examples/src/main/java/ExampleCreateChildAccount.java
new file mode 100644
index 00000000..e4ec5df7
--- /dev/null
+++ b/examples/src/main/java/ExampleCreateChildAccount.java
@@ -0,0 +1,26 @@
+import com.messagebird.MessageBirdClient;
+import com.messagebird.MessageBirdService;
+import com.messagebird.MessageBirdServiceImpl;
+import com.messagebird.exceptions.GeneralException;
+import com.messagebird.exceptions.UnauthorizedException;
+
+public class ExampleCreateChildAccount {
+ public static void main(String[] args) {
+ if (args.length < 2) {
+ System.out.println("Please specify your access key and name of child account arguments");
+ return;
+ }
+
+ final MessageBirdService wsr = new MessageBirdServiceImpl(args[0]);
+ final MessageBirdClient messageBirdClient = new MessageBirdClient(wsr);
+
+ try {
+ System.out.println("Creating a child account of partner accounts");
+ messageBirdClient.createChildAccount(args[1]);
+ System.out.println("Child account is created");
+
+ } catch (GeneralException | UnauthorizedException exception) {
+ exception.printStackTrace();
+ }
+ }
+}
diff --git a/examples/src/main/java/ExampleDeleteChildAccount.java b/examples/src/main/java/ExampleDeleteChildAccount.java
new file mode 100644
index 00000000..2724a59a
--- /dev/null
+++ b/examples/src/main/java/ExampleDeleteChildAccount.java
@@ -0,0 +1,27 @@
+import com.messagebird.MessageBirdClient;
+import com.messagebird.MessageBirdService;
+import com.messagebird.MessageBirdServiceImpl;
+import com.messagebird.exceptions.GeneralException;
+import com.messagebird.exceptions.NotFoundException;
+import com.messagebird.exceptions.UnauthorizedException;
+
+public class ExampleDeleteChildAccount {
+ public static void main(String[] args) {
+ if (args.length < 2) {
+ System.out.println("Please specify your access key and id of child account arguments");
+ return;
+ }
+
+ final MessageBirdService wsr = new MessageBirdServiceImpl(args[0]);
+ final MessageBirdClient messageBirdClient = new MessageBirdClient(wsr);
+
+ try {
+ System.out.println("Deleting a child account of partner accounts");
+ messageBirdClient.deleteChildAccount(args[1]);
+ System.out.println("Child account is deleted");
+
+ } catch (GeneralException | UnauthorizedException | NotFoundException exception) {
+ exception.printStackTrace();
+ }
+ }
+}
diff --git a/examples/src/main/java/ExampleGetChildAccountById.java b/examples/src/main/java/ExampleGetChildAccountById.java
new file mode 100644
index 00000000..ae1acbc9
--- /dev/null
+++ b/examples/src/main/java/ExampleGetChildAccountById.java
@@ -0,0 +1,26 @@
+import com.messagebird.MessageBirdClient;
+import com.messagebird.MessageBirdService;
+import com.messagebird.MessageBirdServiceImpl;
+import com.messagebird.exceptions.GeneralException;
+import com.messagebird.exceptions.NotFoundException;
+import com.messagebird.exceptions.UnauthorizedException;
+
+public class ExampleGetChildAccountById {
+ public static void main(String[] args) {
+ if (args.length < 2) {
+ System.out.println("Please specify your access key and id of child account arguments");
+ return;
+ }
+
+ final MessageBirdService wsr = new MessageBirdServiceImpl(args[0]);
+ final MessageBirdClient messageBirdClient = new MessageBirdClient(wsr);
+
+ try {
+ System.out.println("Get a child account by id");
+ messageBirdClient.getChildAccountById(args[1]);
+
+ } catch (GeneralException | UnauthorizedException | NotFoundException exception) {
+ exception.printStackTrace();
+ }
+ }
+}
diff --git a/examples/src/main/java/ExampleGetChildAccounts.java b/examples/src/main/java/ExampleGetChildAccounts.java
new file mode 100644
index 00000000..5d7be592
--- /dev/null
+++ b/examples/src/main/java/ExampleGetChildAccounts.java
@@ -0,0 +1,24 @@
+import com.messagebird.MessageBirdClient;
+import com.messagebird.MessageBirdService;
+import com.messagebird.MessageBirdServiceImpl;
+import com.messagebird.exceptions.GeneralException;
+import com.messagebird.exceptions.UnauthorizedException;
+
+public class ExampleGetChildAccounts {
+ public static void main(String[] args) {
+ if (args.length < 2) {
+ System.out.println("Please specify your access key, offset, limit arguments");
+ return;
+ }
+
+ final MessageBirdService wsr = new MessageBirdServiceImpl(args[0]);
+ final MessageBirdClient messageBirdClient = new MessageBirdClient(wsr);
+
+ try {
+ System.out.println("Get a child accounts of partner account");
+ messageBirdClient.getChildAccounts(Integer.valueOf(args[1]), Integer.valueOf(args[2]));
+ } catch (GeneralException | UnauthorizedException exception) {
+ exception.printStackTrace();
+ }
+ }
+}
diff --git a/examples/src/main/java/ExampleUpdateChildAccount.java b/examples/src/main/java/ExampleUpdateChildAccount.java
new file mode 100644
index 00000000..e90b9b51
--- /dev/null
+++ b/examples/src/main/java/ExampleUpdateChildAccount.java
@@ -0,0 +1,25 @@
+import com.messagebird.MessageBirdClient;
+import com.messagebird.MessageBirdService;
+import com.messagebird.MessageBirdServiceImpl;
+import com.messagebird.exceptions.GeneralException;
+import com.messagebird.exceptions.UnauthorizedException;
+
+public class ExampleUpdateChildAccount {
+ public static void main(String[] args) {
+ if (args.length < 2) {
+ System.out.println("Please specify your access key, name of child account, id of child account parameters");
+ return;
+ }
+
+ final MessageBirdService wsr = new MessageBirdServiceImpl(args[0]);
+ final MessageBirdClient messageBirdClient = new MessageBirdClient(wsr);
+
+ try {
+ System.out.println("Updating a child account");
+ messageBirdClient.updateChildAccount(args[1], args[2]);
+ System.out.println("Child account is updated");
+ } catch (GeneralException | UnauthorizedException exception) {
+ exception.printStackTrace();
+ }
+ }
+}
From 7dfcb052dd3366dddbc170b3425347dbb41d4a65 Mon Sep 17 00:00:00 2001
From: "deniz@messagebird.com"
Date: Fri, 8 Oct 2021 11:05:20 +0200
Subject: [PATCH 020/216] updated after review
---
.../objects/ChildAccountCreateResponse.java | 20 +------------------
1 file changed, 1 insertion(+), 19 deletions(-)
diff --git a/api/src/main/java/com/messagebird/objects/ChildAccountCreateResponse.java b/api/src/main/java/com/messagebird/objects/ChildAccountCreateResponse.java
index 768fd71f..57aff09e 100644
--- a/api/src/main/java/com/messagebird/objects/ChildAccountCreateResponse.java
+++ b/api/src/main/java/com/messagebird/objects/ChildAccountCreateResponse.java
@@ -2,29 +2,11 @@
import java.util.List;
-public class ChildAccountCreateResponse {
- private String id;
- private String name;
+public class ChildAccountCreateResponse extends ChildAccountResponse{
private List accessKeys;
private String signingKey;
private String invoiceAggregation;
- public String getId() {
- return id;
- }
-
- public void setId(String id) {
- this.id = id;
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
public List getAccessKeys() {
return accessKeys;
}
From 3895bc1cb85d281f02d67ed6458eaf235ecb072f Mon Sep 17 00:00:00 2001
From: "deniz@messagebird.com"
Date: Fri, 8 Oct 2021 14:11:57 +0200
Subject: [PATCH 021/216] minor things are updated
---
.../java/com/messagebird/MessageBirdClient.java | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/api/src/main/java/com/messagebird/MessageBirdClient.java b/api/src/main/java/com/messagebird/MessageBirdClient.java
index 7a817c3a..7cdfbc68 100644
--- a/api/src/main/java/com/messagebird/MessageBirdClient.java
+++ b/api/src/main/java/com/messagebird/MessageBirdClient.java
@@ -678,8 +678,8 @@ public VoiceCallFlowResponse sendVoiceCallFlow(final VoiceCallFlowRequest voiceC
* @param id String
* @param voiceCallFlowRequest VoiceCallFlowRequest
* @return VoiceCallFlowResponse
- * @throws UnauthorizedException
- * @throws GeneralException
+ * @throws UnauthorizedException if client is unauthorized
+ * @throws GeneralException general exception
*/
public VoiceCallFlowResponse updateVoiceCallFlow(String id, VoiceCallFlowRequest voiceCallFlowRequest)
throws UnauthorizedException, GeneralException {
@@ -1893,7 +1893,7 @@ public TemplateList listWhatsAppTemplates() throws UnauthorizedException, Genera
* Retrieves the template of an existing template name.
*
* @param templateName A name as returned by getWhatsAppTemplateBy in the name variable
- * @return {@code List} template list
+ * @return {@code List} template list
* @throws UnauthorizedException if client is unauthorized
* @throws GeneralException general exception
* @throws NotFoundException if template name is not found
@@ -1920,7 +1920,7 @@ public List getWhatsAppTemplatesBy(final String templateName)
* @param templateName A name as returned by getWhatsAppTemplateBy in the name variable
* @param language A language code as returned by getWhatsAppTemplateBy in the language variable
*
- * @return {@code WhatsAppTemplateResponse} template list
+ * @return {@code TemplateResponse} template list
* @throws UnauthorizedException if client is unauthorized
* @throws GeneralException general exception
* @throws NotFoundException if template name and language are not found
@@ -2000,7 +2000,7 @@ public void deleteTemplatesBy(final String templateName, final String language)
* @throws UnauthorizedException if client is unauthorized
* @throws GeneralException general exception
*/
- public ChildAccountCreateResponse createChildAccount(String name) throws UnauthorizedException, GeneralException {
+ public ChildAccountCreateResponse createChildAccount(final String name) throws UnauthorizedException, GeneralException {
if (name == null) {
throw new IllegalArgumentException("Name must be specified.");
}
@@ -2017,7 +2017,7 @@ public ChildAccountCreateResponse createChildAccount(String name) throws Unautho
* @throws UnauthorizedException if client is unauthorized
* @throws GeneralException general exception
*/
- public ChildAccountResponse updateChildAccount(String name, String id) throws UnauthorizedException, GeneralException {
+ public ChildAccountResponse updateChildAccount(final String name, final String id) throws UnauthorizedException, GeneralException {
if (name == null) {
throw new IllegalArgumentException("Name must be specified.");
}
@@ -2039,7 +2039,7 @@ public ChildAccountResponse updateChildAccount(String name, String id) throws Un
* @throws GeneralException general exception
* @throws NotFoundException if id is not found
*/
- public ChildAccountDetailedResponse getChildAccountById(String id) throws UnauthorizedException, GeneralException, NotFoundException {
+ public ChildAccountDetailedResponse getChildAccountById(final String id) throws UnauthorizedException, GeneralException, NotFoundException {
if (id == null) {
throw new IllegalArgumentException("Child account id must be specified.");
}
@@ -2067,7 +2067,7 @@ public PartnerAccountsResponse getChildAccounts(final Integer offset, final Inte
* @throws GeneralException general exception
* @throws NotFoundException if id is not found
*/
- public void deleteChildAccount(String id) throws UnauthorizedException, GeneralException, NotFoundException {
+ public void deleteChildAccount(final String id) throws UnauthorizedException, GeneralException, NotFoundException {
if (id == null) {
throw new IllegalArgumentException("Child account id must be specified.");
}
From 45952f878658869158fd0302b8ff8cb5c45f2815 Mon Sep 17 00:00:00 2001
From: "deniz@messagebird.com"
Date: Fri, 8 Oct 2021 14:38:59 +0200
Subject: [PATCH 022/216] added toString methods
---
.../main/java/com/messagebird/objects/AccessKey.java | 9 +++++++++
.../objects/ChildAccountCreateResponse.java | 11 +++++++++++
.../objects/ChildAccountDetailedResponse.java | 9 +++++++++
.../com/messagebird/objects/ChildAccountResponse.java | 8 ++++++++
examples/src/main/java/ExampleCreateChildAccount.java | 5 +++--
5 files changed, 40 insertions(+), 2 deletions(-)
diff --git a/api/src/main/java/com/messagebird/objects/AccessKey.java b/api/src/main/java/com/messagebird/objects/AccessKey.java
index 14505dc7..65ee9fd7 100644
--- a/api/src/main/java/com/messagebird/objects/AccessKey.java
+++ b/api/src/main/java/com/messagebird/objects/AccessKey.java
@@ -28,4 +28,13 @@ public String getMod() {
public void setMod(String mod) {
this.mod = mod;
}
+
+ @Override
+ public String toString() {
+ return "AccessKey{" +
+ "id='" + id + '\'' +
+ ", key='" + key + '\'' +
+ ", mod='" + mod + '\'' +
+ '}';
+ }
}
diff --git a/api/src/main/java/com/messagebird/objects/ChildAccountCreateResponse.java b/api/src/main/java/com/messagebird/objects/ChildAccountCreateResponse.java
index 57aff09e..dcf201b6 100644
--- a/api/src/main/java/com/messagebird/objects/ChildAccountCreateResponse.java
+++ b/api/src/main/java/com/messagebird/objects/ChildAccountCreateResponse.java
@@ -30,4 +30,15 @@ public String getInvoiceAggregation() {
public void setInvoiceAggregation(String invoiceAggregation) {
this.invoiceAggregation = invoiceAggregation;
}
+
+ @Override
+ public String toString() {
+ return "ChildAccountCreateResponse{" +
+ "id='" + getId() + '\'' +
+ ", name='" + getName() + '\'' +
+ ", accessKeys=" + accessKeys + '\'' +
+ ", signingKey='" + signingKey + '\'' +
+ ", invoiceAggregation='" + invoiceAggregation + '\'' +
+ '}';
+ }
}
diff --git a/api/src/main/java/com/messagebird/objects/ChildAccountDetailedResponse.java b/api/src/main/java/com/messagebird/objects/ChildAccountDetailedResponse.java
index d3aac825..cdf23d4a 100644
--- a/api/src/main/java/com/messagebird/objects/ChildAccountDetailedResponse.java
+++ b/api/src/main/java/com/messagebird/objects/ChildAccountDetailedResponse.java
@@ -10,4 +10,13 @@ public String getInvoiceAggregation() {
public void setInvoiceAggregation(String invoiceAggregation) {
this.invoiceAggregation = invoiceAggregation;
}
+
+ @Override
+ public String toString() {
+ return "ChildAccountDetailedResponse{" +
+ "id='" + getId() + '\'' +
+ ", name='" + getName() + '\'' +
+ "invoiceAggregation='" + invoiceAggregation + '\'' +
+ '}';
+ }
}
diff --git a/api/src/main/java/com/messagebird/objects/ChildAccountResponse.java b/api/src/main/java/com/messagebird/objects/ChildAccountResponse.java
index 2e4853aa..637a258f 100644
--- a/api/src/main/java/com/messagebird/objects/ChildAccountResponse.java
+++ b/api/src/main/java/com/messagebird/objects/ChildAccountResponse.java
@@ -19,4 +19,12 @@ public String getName() {
public void setName(String name) {
this.name = name;
}
+
+ @Override
+ public String toString() {
+ return "ChildAccountResponse{" +
+ "id='" + id + '\'' +
+ ", name='" + name + '\'' +
+ '}';
+ }
}
diff --git a/examples/src/main/java/ExampleCreateChildAccount.java b/examples/src/main/java/ExampleCreateChildAccount.java
index e4ec5df7..037f90dd 100644
--- a/examples/src/main/java/ExampleCreateChildAccount.java
+++ b/examples/src/main/java/ExampleCreateChildAccount.java
@@ -3,6 +3,7 @@
import com.messagebird.MessageBirdServiceImpl;
import com.messagebird.exceptions.GeneralException;
import com.messagebird.exceptions.UnauthorizedException;
+import com.messagebird.objects.ChildAccountCreateResponse;
public class ExampleCreateChildAccount {
public static void main(String[] args) {
@@ -16,8 +17,8 @@ public static void main(String[] args) {
try {
System.out.println("Creating a child account of partner accounts");
- messageBirdClient.createChildAccount(args[1]);
- System.out.println("Child account is created");
+ ChildAccountCreateResponse childAccount = messageBirdClient.createChildAccount(args[1]);
+ System.out.println("Child account is created: " + childAccount.toString());
} catch (GeneralException | UnauthorizedException exception) {
exception.printStackTrace();
From 6cc657f88cb81e62a63967710057e24e61242ea2 Mon Sep 17 00:00:00 2001
From: "deniz@messagebird.com"
Date: Fri, 8 Oct 2021 16:56:59 +0200
Subject: [PATCH 023/216] updated examples
---
.../com/messagebird/MessageBirdClient.java | 22 +++----
.../objects/ChildAccountDetailedResponse.java | 2 +-
.../objects/ChildAccountRequest.java | 13 +++++
.../objects/ChildAccountResponse.java | 6 +-
.../objects/PartnerAccountsResponse.java | 12 +---
.../messagebird/MessageBirdClientTest.java | 57 ++++++++++---------
.../test/java/com/messagebird/TestUtil.java | 2 +-
.../main/java/ExampleCreateChildAccount.java | 5 +-
.../main/java/ExampleGetChildAccountById.java | 5 +-
.../main/java/ExampleGetChildAccounts.java | 4 +-
.../main/java/ExampleUpdateChildAccount.java | 5 +-
11 files changed, 74 insertions(+), 59 deletions(-)
create mode 100644 api/src/main/java/com/messagebird/objects/ChildAccountRequest.java
diff --git a/api/src/main/java/com/messagebird/MessageBirdClient.java b/api/src/main/java/com/messagebird/MessageBirdClient.java
index 7cdfbc68..5f8d489f 100644
--- a/api/src/main/java/com/messagebird/MessageBirdClient.java
+++ b/api/src/main/java/com/messagebird/MessageBirdClient.java
@@ -47,7 +47,6 @@
import java.util.Locale;
import java.util.Map;
import java.util.Set;
-import java.util.HashSet;
/**
* Message bird general client
@@ -1995,18 +1994,18 @@ public void deleteTemplatesBy(final String templateName, final String language)
/**
* Function to create a child account
*
- * @param name of child account to create
+ * @param childAccountRequest of child account to create
* @return ChildAccountResponse created
* @throws UnauthorizedException if client is unauthorized
* @throws GeneralException general exception
*/
- public ChildAccountCreateResponse createChildAccount(final String name) throws UnauthorizedException, GeneralException {
- if (name == null) {
+ public ChildAccountCreateResponse createChildAccount(final ChildAccountRequest childAccountRequest) throws UnauthorizedException, GeneralException {
+ if (childAccountRequest.getName() == null || childAccountRequest.getName().isEmpty()) {
throw new IllegalArgumentException("Name must be specified.");
}
String url = String.format("%s%s", PARTNER_ACCOUNTS_BASE_URL, "/child-accounts");
- return messageBirdService.sendPayLoad(url, name, ChildAccountCreateResponse.class);
+ return messageBirdService.sendPayLoad(url, childAccountRequest, ChildAccountCreateResponse.class);
}
/**
@@ -2025,9 +2024,10 @@ public ChildAccountResponse updateChildAccount(final String name, final String i
if (id == null) {
throw new IllegalArgumentException("Child account id must be specified.");
}
-
+ final ChildAccountRequest childAccountRequest = new ChildAccountRequest();
+ childAccountRequest.setName(name);
final String url = String.format("%s/child-accounts/%s", PARTNER_ACCOUNTS_BASE_URL, id);
- return messageBirdService.sendPayLoad("PATCH", url, name, ChildAccountResponse.class);
+ return messageBirdService.sendPayLoad("PATCH", url, childAccountRequest, ChildAccountResponse.class);
}
/**
@@ -2043,8 +2043,7 @@ public ChildAccountDetailedResponse getChildAccountById(final String id) throws
if (id == null) {
throw new IllegalArgumentException("Child account id must be specified.");
}
-
- return messageBirdService.requestByID(PARTNER_ACCOUNTS_BASE_URL, id, ChildAccountDetailedResponse.class);
+ return messageBirdService.requestByID(PARTNER_ACCOUNTS_BASE_URL + "/child-accounts", id, ChildAccountDetailedResponse.class);
}
/**
@@ -2056,7 +2055,7 @@ public ChildAccountDetailedResponse getChildAccountById(final String id) throws
*/
public PartnerAccountsResponse getChildAccounts(final Integer offset, final Integer limit) throws UnauthorizedException, GeneralException {
verifyOffsetAndLimit(offset, limit);
- return messageBirdService.requestList(PARTNER_ACCOUNTS_BASE_URL, offset, limit, PartnerAccountsResponse.class);
+ return messageBirdService.requestList(PARTNER_ACCOUNTS_BASE_URL + "/child-accounts", offset, limit, PartnerAccountsResponse.class);
}
/**
@@ -2072,7 +2071,8 @@ public void deleteChildAccount(final String id) throws UnauthorizedException, Ge
throw new IllegalArgumentException("Child account id must be specified.");
}
- String url = String.format("%s/child-accounts/%s", PARTNER_ACCOUNTS_BASE_URL, id);
+ String url = String.format("%s/child-accounts", PARTNER_ACCOUNTS_BASE_URL);
+ System.out.println("url: " + url);
messageBirdService.deleteByID(url, id);
}
}
diff --git a/api/src/main/java/com/messagebird/objects/ChildAccountDetailedResponse.java b/api/src/main/java/com/messagebird/objects/ChildAccountDetailedResponse.java
index cdf23d4a..e39d5969 100644
--- a/api/src/main/java/com/messagebird/objects/ChildAccountDetailedResponse.java
+++ b/api/src/main/java/com/messagebird/objects/ChildAccountDetailedResponse.java
@@ -16,7 +16,7 @@ public String toString() {
return "ChildAccountDetailedResponse{" +
"id='" + getId() + '\'' +
", name='" + getName() + '\'' +
- "invoiceAggregation='" + invoiceAggregation + '\'' +
+ ", invoiceAggregation='" + invoiceAggregation + '\'' +
'}';
}
}
diff --git a/api/src/main/java/com/messagebird/objects/ChildAccountRequest.java b/api/src/main/java/com/messagebird/objects/ChildAccountRequest.java
new file mode 100644
index 00000000..aa0e9e5f
--- /dev/null
+++ b/api/src/main/java/com/messagebird/objects/ChildAccountRequest.java
@@ -0,0 +1,13 @@
+package com.messagebird.objects;
+
+public class ChildAccountRequest {
+ private String name;
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+}
diff --git a/api/src/main/java/com/messagebird/objects/ChildAccountResponse.java b/api/src/main/java/com/messagebird/objects/ChildAccountResponse.java
index 637a258f..de232f05 100644
--- a/api/src/main/java/com/messagebird/objects/ChildAccountResponse.java
+++ b/api/src/main/java/com/messagebird/objects/ChildAccountResponse.java
@@ -1,6 +1,10 @@
package com.messagebird.objects;
-public class ChildAccountResponse {
+import java.io.Serializable;
+
+public class ChildAccountResponse implements Serializable {
+ private static final long serialVersionUID = -8605510461438669942L;
+
private String id;
private String name;
diff --git a/api/src/main/java/com/messagebird/objects/PartnerAccountsResponse.java b/api/src/main/java/com/messagebird/objects/PartnerAccountsResponse.java
index 410cd360..deb82067 100644
--- a/api/src/main/java/com/messagebird/objects/PartnerAccountsResponse.java
+++ b/api/src/main/java/com/messagebird/objects/PartnerAccountsResponse.java
@@ -1,15 +1,5 @@
package com.messagebird.objects;
-import java.util.List;
+public class PartnerAccountsResponse extends ListBase{
-public class PartnerAccountsResponse {
- private List childAccountResponses;
-
- public List getChildAccountResponses() {
- return childAccountResponses;
- }
-
- public void setChildAccountResponses(List childAccountResponses) {
- this.childAccountResponses = childAccountResponses;
- }
}
diff --git a/api/src/test/java/com/messagebird/MessageBirdClientTest.java b/api/src/test/java/com/messagebird/MessageBirdClientTest.java
index b523a2a4..c948154e 100644
--- a/api/src/test/java/com/messagebird/MessageBirdClientTest.java
+++ b/api/src/test/java/com/messagebird/MessageBirdClientTest.java
@@ -134,7 +134,7 @@ public void testListScheduledMessages() throws Exception {
public void testListScheduledMessagesWrongFilter() throws Exception {
Map filters = new LinkedHashMap<>();
filters.put("does not exist", null);
-
+
messageBirdClient.listMessagesFiltered(null, null, filters);
}
@@ -816,7 +816,7 @@ public void testListNumbersForPurchase() throws IllegalArgumentException, Genera
final PhoneNumbersResponse response = messageBirdClientMock.listNumbersForPurchase("NL");
verify(messageBirdServiceMock, times(1)).requestByID(url, "NL", PhoneNumbersResponse.class);
-
+
assertNotNull(response);
assertEquals(response, mockedResponse);
}
@@ -835,7 +835,7 @@ public void testListNumbersForPurchaseWithParams() throws IllegalArgumentExcepti
options.setLimit(1);
options.setNumber(562);
options.setSearchPattern(PhoneNumberSearchPattern.START);
-
+
when(messageBirdServiceMock.requestByID(url, "US", options.toHashMap(), PhoneNumbersResponse.class))
.thenReturn(mockedResponse);
@@ -853,12 +853,12 @@ public void testPurchaseNumber() throws UnauthorizedException, GeneralException
MessageBirdService messageBirdServiceMock = mock(MessageBirdService.class);
MessageBirdClient messageBirdClientMock = new MessageBirdClient(messageBirdServiceMock);
-
+
final Map payload = new LinkedHashMap();
payload.put("number", "15625267429");
payload.put("countryCode", "US");
payload.put("billingIntervalMonths", 1);
-
+
when(messageBirdServiceMock.sendPayLoad(url, payload, PurchasedNumberCreatedResponse.class))
.thenReturn(purchasedNumberMockData);
final PurchasedNumberCreatedResponse response = messageBirdClientMock.purchaseNumber("15625267429", "US", 1);
@@ -866,13 +866,13 @@ public void testPurchaseNumber() throws UnauthorizedException, GeneralException
assertNotNull(response);
assertEquals(response, purchasedNumberMockData);
}
-
+
@Test
public void testListPurchasedNumbers() throws UnauthorizedException, GeneralException, NotFoundException {
final String url = String.format("%s/phone-numbers", NUMBERS_CALLS_BASE_URL);
-
+
PurchasedNumbersResponse purchasedNumbersMockData = new PurchasedNumbersResponse();
-
+
MessageBirdService messageBirdServiceMock = mock(MessageBirdService.class);
MessageBirdClient messageBirdClientMock = new MessageBirdClient(messageBirdServiceMock);
@@ -895,9 +895,9 @@ public void testListPurchasedNumbers() throws UnauthorizedException, GeneralExce
@Test
public void testViewPurchasedNumber() throws UnauthorizedException, GeneralException, NotFoundException {
final String url = String.format("%s/phone-numbers", NUMBERS_CALLS_BASE_URL);
-
+
PurchasedNumber purchasedNumberMockData = new PurchasedNumber();
-
+
MessageBirdService messageBirdServiceMock = mock(MessageBirdService.class);
MessageBirdClient messageBirdClientMock = new MessageBirdClient(messageBirdServiceMock);
when(messageBirdServiceMock.requestByID(url, "15625267429", PurchasedNumber.class))
@@ -913,15 +913,15 @@ public void testViewPurchasedNumber() throws UnauthorizedException, GeneralExce
public void updatePurchasedNumber() throws UnauthorizedException, GeneralException {
final String phoneNumber = "15625267429";
final String url = String.format("%s/phone-numbers/%s", NUMBERS_CALLS_BASE_URL, phoneNumber);
-
+
PurchasedNumber updatedNumberMock = new PurchasedNumber();
-
+
MessageBirdService messageBirdServiceMock = mock(MessageBirdService.class);
MessageBirdClient messageBirdClientMock = new MessageBirdClient(messageBirdServiceMock);
-
+
final Map> payload = new HashMap>();
payload.put("tags", Collections.singletonList("tag"));
-
+
when(messageBirdServiceMock.sendPayLoad("PATCH", url, payload, PurchasedNumber.class))
.thenReturn(updatedNumberMock);
final PurchasedNumber response = messageBirdClientMock.updateNumber(phoneNumber, "tag");
@@ -934,10 +934,10 @@ public void updatePurchasedNumber() throws UnauthorizedException, GeneralExcept
public void deletePurchasedNumber() throws UnauthorizedException, GeneralException, NotFoundException {
final String phoneNumber = "15625267429";
final String url = String.format("%s/phone-numbers", NUMBERS_CALLS_BASE_URL);
-
+
MessageBirdService messageBirdServiceMock = mock(MessageBirdService.class);
MessageBirdClient messageBirdClientMock = new MessageBirdClient(messageBirdServiceMock);
-
+
messageBirdClientMock.cancelNumber(phoneNumber);
verify(messageBirdServiceMock, times(1)).deleteByID(url, phoneNumber);
}
@@ -1225,12 +1225,14 @@ public void testCreateChildAccounts() throws GeneralException, UnauthorizedExcep
MessageBirdService messageBirdServiceMock = mock(MessageBirdService.class);
MessageBirdClient messageBirdClientInjectMock = new MessageBirdClient(messageBirdServiceMock);
ChildAccountCreateResponse childAccountCreateResponse = createChildAccountCreateResponse();
- when(messageBirdServiceMock.sendPayLoad(PARTNER_ACCOUNTS_BASE_URL + "/child-accounts" , "name", ChildAccountCreateResponse.class))
+ ChildAccountRequest childAccountRequest = new ChildAccountRequest();
+ childAccountRequest.setName("name");
+ when(messageBirdServiceMock.sendPayLoad(PARTNER_ACCOUNTS_BASE_URL + "/child-accounts" , childAccountRequest, ChildAccountCreateResponse.class))
.thenReturn(childAccountCreateResponse);
- final ChildAccountCreateResponse response = messageBirdClientInjectMock.createChildAccount("name");
+ final ChildAccountCreateResponse response = messageBirdClientInjectMock.createChildAccount(childAccountRequest);
verify(messageBirdServiceMock, times(1))
- .sendPayLoad(PARTNER_ACCOUNTS_BASE_URL + "/child-accounts" , "name", ChildAccountCreateResponse.class);
+ .sendPayLoad(PARTNER_ACCOUNTS_BASE_URL + "/child-accounts" , childAccountRequest, ChildAccountCreateResponse.class);
assertNotNull(response);
assertEquals(response.getId(), childAccountCreateResponse.getId());
assertEquals(response.getName(), childAccountCreateResponse.getName());
@@ -1246,12 +1248,12 @@ public void testGetChildAccount() throws GeneralException, UnauthorizedException
MessageBirdService messageBirdServiceMock = mock(MessageBirdService.class);
MessageBirdClient messageBirdClientInjectMock = new MessageBirdClient(messageBirdServiceMock);
ChildAccountDetailedResponse childAccountDetailedResponse = createChildAccountDetailedResponse();
- when(messageBirdServiceMock.requestByID(PARTNER_ACCOUNTS_BASE_URL, "ANY_ID", ChildAccountDetailedResponse.class))
+ when(messageBirdServiceMock.requestByID(PARTNER_ACCOUNTS_BASE_URL + "/child-accounts", "ANY_ID", ChildAccountDetailedResponse.class))
.thenReturn(childAccountDetailedResponse);
ChildAccountDetailedResponse response = messageBirdClientInjectMock.getChildAccountById("ANY_ID");
verify(messageBirdServiceMock, times(1))
- .requestByID(PARTNER_ACCOUNTS_BASE_URL, "ANY_ID", ChildAccountDetailedResponse.class);
+ .requestByID(PARTNER_ACCOUNTS_BASE_URL + "/child-accounts", "ANY_ID", ChildAccountDetailedResponse.class);
assertNotNull(response);
assertEquals(response.getId(), childAccountDetailedResponse.getId());
assertEquals(response.getName(), childAccountDetailedResponse.getName());
@@ -1263,16 +1265,16 @@ public void testGetChildAccounts() throws GeneralException, UnauthorizedExceptio
MessageBirdService messageBirdServiceMock = mock(MessageBirdService.class);
MessageBirdClient messageBirdClientInjectMock = new MessageBirdClient(messageBirdServiceMock);
PartnerAccountsResponse partnerAccountsResponse = createPartnerAccountsResponse();
- when(messageBirdServiceMock.requestList(PARTNER_ACCOUNTS_BASE_URL, 1, 10, PartnerAccountsResponse.class))
+ when(messageBirdServiceMock.requestList(PARTNER_ACCOUNTS_BASE_URL + "/child-accounts", 1, 10, PartnerAccountsResponse.class))
.thenReturn(partnerAccountsResponse);
PartnerAccountsResponse response = messageBirdClientInjectMock.getChildAccounts(1, 10);
verify(messageBirdServiceMock, times(1))
- .requestList(PARTNER_ACCOUNTS_BASE_URL, 1, 10, PartnerAccountsResponse.class);
+ .requestList(PARTNER_ACCOUNTS_BASE_URL + "/child-accounts", 1, 10, PartnerAccountsResponse.class);
assertNotNull(response);
- assertEquals(response.getChildAccountResponses().get(0).getId(), partnerAccountsResponse.getChildAccountResponses().get(0).getId());
- assertEquals(response.getChildAccountResponses().get(0).getName(), partnerAccountsResponse.getChildAccountResponses().get(0).getName());
+ assertEquals(response.getItems().get(0).getId(), partnerAccountsResponse.getItems().get(0).getId());
+ assertEquals(response.getItems().get(0).getName(), partnerAccountsResponse.getItems().get(0).getName());
}
@Test
@@ -1280,13 +1282,12 @@ public void testUpdateChildAccount() throws GeneralException, UnauthorizedExcept
MessageBirdService messageBirdServiceMock = mock(MessageBirdService.class);
MessageBirdClient messageBirdClientInjectMock = new MessageBirdClient(messageBirdServiceMock);
ChildAccountResponse childAccountResponse = createChildAccountResponse();
- final String url = String.format("%s/child-accounts/%s", PARTNER_ACCOUNTS_BASE_URL, "ANY_ID");
- when(messageBirdServiceMock.sendPayLoad("PATCH", url, "ANY_NAME", ChildAccountResponse.class))
+ when(messageBirdServiceMock.sendPayLoad(any(), any(), any(), any()))
.thenReturn(childAccountResponse);
ChildAccountResponse response = messageBirdClientInjectMock.updateChildAccount("ANY_NAME", "ANY_ID");
verify(messageBirdServiceMock, times(1))
- .sendPayLoad("PATCH", url, "ANY_NAME", ChildAccountResponse.class);
+ .sendPayLoad(any(), any(), any(), any());
assertNotNull(response);
assertEquals(response.getId(), childAccountResponse.getId());
assertEquals(response.getName(), childAccountResponse.getName());
diff --git a/api/src/test/java/com/messagebird/TestUtil.java b/api/src/test/java/com/messagebird/TestUtil.java
index 0e293855..a66c0aad 100644
--- a/api/src/test/java/com/messagebird/TestUtil.java
+++ b/api/src/test/java/com/messagebird/TestUtil.java
@@ -384,7 +384,7 @@ public static ChildAccountResponse createChildAccountResponse(){
public static PartnerAccountsResponse createPartnerAccountsResponse(){
final ChildAccountResponse childAccountResponse = createChildAccountResponse();
final PartnerAccountsResponse partnerAccountsResponse = new PartnerAccountsResponse();
- partnerAccountsResponse.setChildAccountResponses(Collections.singletonList(childAccountResponse));
+ partnerAccountsResponse.setItems(Collections.singletonList(childAccountResponse));
return partnerAccountsResponse;
}
}
diff --git a/examples/src/main/java/ExampleCreateChildAccount.java b/examples/src/main/java/ExampleCreateChildAccount.java
index 037f90dd..2c71ae51 100644
--- a/examples/src/main/java/ExampleCreateChildAccount.java
+++ b/examples/src/main/java/ExampleCreateChildAccount.java
@@ -3,6 +3,7 @@
import com.messagebird.MessageBirdServiceImpl;
import com.messagebird.exceptions.GeneralException;
import com.messagebird.exceptions.UnauthorizedException;
+import com.messagebird.objects.ChildAccountRequest;
import com.messagebird.objects.ChildAccountCreateResponse;
public class ExampleCreateChildAccount {
@@ -17,7 +18,9 @@ public static void main(String[] args) {
try {
System.out.println("Creating a child account of partner accounts");
- ChildAccountCreateResponse childAccount = messageBirdClient.createChildAccount(args[1]);
+ final ChildAccountRequest childAccountRequest = new ChildAccountRequest();
+ childAccountRequest.setName(args[1]);
+ ChildAccountCreateResponse childAccount = messageBirdClient.createChildAccount(childAccountRequest);
System.out.println("Child account is created: " + childAccount.toString());
} catch (GeneralException | UnauthorizedException exception) {
diff --git a/examples/src/main/java/ExampleGetChildAccountById.java b/examples/src/main/java/ExampleGetChildAccountById.java
index ae1acbc9..2e42fd6e 100644
--- a/examples/src/main/java/ExampleGetChildAccountById.java
+++ b/examples/src/main/java/ExampleGetChildAccountById.java
@@ -4,6 +4,7 @@
import com.messagebird.exceptions.GeneralException;
import com.messagebird.exceptions.NotFoundException;
import com.messagebird.exceptions.UnauthorizedException;
+import com.messagebird.objects.ChildAccountDetailedResponse;
public class ExampleGetChildAccountById {
public static void main(String[] args) {
@@ -17,8 +18,8 @@ public static void main(String[] args) {
try {
System.out.println("Get a child account by id");
- messageBirdClient.getChildAccountById(args[1]);
-
+ ChildAccountDetailedResponse response = messageBirdClient.getChildAccountById(args[1]);
+ System.out.println("Response: " + response.toString());
} catch (GeneralException | UnauthorizedException | NotFoundException exception) {
exception.printStackTrace();
}
diff --git a/examples/src/main/java/ExampleGetChildAccounts.java b/examples/src/main/java/ExampleGetChildAccounts.java
index 5d7be592..01a29dbb 100644
--- a/examples/src/main/java/ExampleGetChildAccounts.java
+++ b/examples/src/main/java/ExampleGetChildAccounts.java
@@ -3,6 +3,7 @@
import com.messagebird.MessageBirdServiceImpl;
import com.messagebird.exceptions.GeneralException;
import com.messagebird.exceptions.UnauthorizedException;
+import com.messagebird.objects.PartnerAccountsResponse;
public class ExampleGetChildAccounts {
public static void main(String[] args) {
@@ -16,7 +17,8 @@ public static void main(String[] args) {
try {
System.out.println("Get a child accounts of partner account");
- messageBirdClient.getChildAccounts(Integer.valueOf(args[1]), Integer.valueOf(args[2]));
+ PartnerAccountsResponse response = messageBirdClient.getChildAccounts(Integer.valueOf(args[1]), Integer.valueOf(args[2]));
+ System.out.println("response: " + response);
} catch (GeneralException | UnauthorizedException exception) {
exception.printStackTrace();
}
diff --git a/examples/src/main/java/ExampleUpdateChildAccount.java b/examples/src/main/java/ExampleUpdateChildAccount.java
index e90b9b51..1976f6ab 100644
--- a/examples/src/main/java/ExampleUpdateChildAccount.java
+++ b/examples/src/main/java/ExampleUpdateChildAccount.java
@@ -3,6 +3,7 @@
import com.messagebird.MessageBirdServiceImpl;
import com.messagebird.exceptions.GeneralException;
import com.messagebird.exceptions.UnauthorizedException;
+import com.messagebird.objects.ChildAccountResponse;
public class ExampleUpdateChildAccount {
public static void main(String[] args) {
@@ -16,8 +17,8 @@ public static void main(String[] args) {
try {
System.out.println("Updating a child account");
- messageBirdClient.updateChildAccount(args[1], args[2]);
- System.out.println("Child account is updated");
+ ChildAccountResponse response = messageBirdClient.updateChildAccount(args[1], args[2]);
+ System.out.println("Child account is updated: " + response.toString());
} catch (GeneralException | UnauthorizedException exception) {
exception.printStackTrace();
}
From 89715d8b384b10ba864cfb29a8dacd2d3c2e628a Mon Sep 17 00:00:00 2001
From: "deniz@messagebird.com"
Date: Fri, 8 Oct 2021 17:33:47 +0200
Subject: [PATCH 024/216] getAccounts is fixed
---
.../java/com/messagebird/MessageBirdClient.java | 4 ++--
.../objects/PartnerAccountsResponse.java | 5 -----
.../com/messagebird/MessageBirdClientTest.java | 15 ++++++++-------
api/src/test/java/com/messagebird/TestUtil.java | 7 -------
.../src/main/java/ExampleGetChildAccounts.java | 6 ++++--
5 files changed, 14 insertions(+), 23 deletions(-)
delete mode 100644 api/src/main/java/com/messagebird/objects/PartnerAccountsResponse.java
diff --git a/api/src/main/java/com/messagebird/MessageBirdClient.java b/api/src/main/java/com/messagebird/MessageBirdClient.java
index 5f8d489f..cd8ca60a 100644
--- a/api/src/main/java/com/messagebird/MessageBirdClient.java
+++ b/api/src/main/java/com/messagebird/MessageBirdClient.java
@@ -2053,9 +2053,9 @@ public ChildAccountDetailedResponse getChildAccountById(final String id) throws
* @throws UnauthorizedException if client is unauthorized
* @throws GeneralException general exception
*/
- public PartnerAccountsResponse getChildAccounts(final Integer offset, final Integer limit) throws UnauthorizedException, GeneralException {
+ public List getChildAccounts(final Integer offset, final Integer limit) throws UnauthorizedException, GeneralException {
verifyOffsetAndLimit(offset, limit);
- return messageBirdService.requestList(PARTNER_ACCOUNTS_BASE_URL + "/child-accounts", offset, limit, PartnerAccountsResponse.class);
+ return messageBirdService.requestList(PARTNER_ACCOUNTS_BASE_URL + "/child-accounts", offset, limit, List.class);
}
/**
diff --git a/api/src/main/java/com/messagebird/objects/PartnerAccountsResponse.java b/api/src/main/java/com/messagebird/objects/PartnerAccountsResponse.java
deleted file mode 100644
index deb82067..00000000
--- a/api/src/main/java/com/messagebird/objects/PartnerAccountsResponse.java
+++ /dev/null
@@ -1,5 +0,0 @@
-package com.messagebird.objects;
-
-public class PartnerAccountsResponse extends ListBase{
-
-}
diff --git a/api/src/test/java/com/messagebird/MessageBirdClientTest.java b/api/src/test/java/com/messagebird/MessageBirdClientTest.java
index c948154e..139ede8a 100644
--- a/api/src/test/java/com/messagebird/MessageBirdClientTest.java
+++ b/api/src/test/java/com/messagebird/MessageBirdClientTest.java
@@ -24,6 +24,7 @@
import static com.messagebird.MessageBirdClient.*;
import static com.messagebird.TestUtil.*;
+import static com.messagebird.TestUtil.createChildAccountDetailedResponse;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
import static org.unitils.reflectionassert.ReflectionAssert.assertReflectionEquals;
@@ -1264,17 +1265,17 @@ public void testGetChildAccount() throws GeneralException, UnauthorizedException
public void testGetChildAccounts() throws GeneralException, UnauthorizedException {
MessageBirdService messageBirdServiceMock = mock(MessageBirdService.class);
MessageBirdClient messageBirdClientInjectMock = new MessageBirdClient(messageBirdServiceMock);
- PartnerAccountsResponse partnerAccountsResponse = createPartnerAccountsResponse();
- when(messageBirdServiceMock.requestList(PARTNER_ACCOUNTS_BASE_URL + "/child-accounts", 1, 10, PartnerAccountsResponse.class))
- .thenReturn(partnerAccountsResponse);
+ List childAccountResponses = Collections.singletonList(createChildAccountResponse());
+ when(messageBirdServiceMock.requestList(PARTNER_ACCOUNTS_BASE_URL + "/child-accounts", 1, 10, List.class))
+ .thenReturn(childAccountResponses);
- PartnerAccountsResponse response = messageBirdClientInjectMock.getChildAccounts(1, 10);
+ List response = messageBirdClientInjectMock.getChildAccounts(1, 10);
verify(messageBirdServiceMock, times(1))
- .requestList(PARTNER_ACCOUNTS_BASE_URL + "/child-accounts", 1, 10, PartnerAccountsResponse.class);
+ .requestList(PARTNER_ACCOUNTS_BASE_URL + "/child-accounts", 1, 10, List.class);
assertNotNull(response);
- assertEquals(response.getItems().get(0).getId(), partnerAccountsResponse.getItems().get(0).getId());
- assertEquals(response.getItems().get(0).getName(), partnerAccountsResponse.getItems().get(0).getName());
+ assertEquals(response.get(0).getId(), childAccountResponses.get(0).getId());
+ assertEquals(response.get(0).getName(), childAccountResponses.get(0).getName());
}
@Test
diff --git a/api/src/test/java/com/messagebird/TestUtil.java b/api/src/test/java/com/messagebird/TestUtil.java
index a66c0aad..7518776b 100644
--- a/api/src/test/java/com/messagebird/TestUtil.java
+++ b/api/src/test/java/com/messagebird/TestUtil.java
@@ -380,11 +380,4 @@ public static ChildAccountResponse createChildAccountResponse(){
childAccountResponse.setName("ANY_NAME");
return childAccountResponse;
}
-
- public static PartnerAccountsResponse createPartnerAccountsResponse(){
- final ChildAccountResponse childAccountResponse = createChildAccountResponse();
- final PartnerAccountsResponse partnerAccountsResponse = new PartnerAccountsResponse();
- partnerAccountsResponse.setItems(Collections.singletonList(childAccountResponse));
- return partnerAccountsResponse;
- }
}
diff --git a/examples/src/main/java/ExampleGetChildAccounts.java b/examples/src/main/java/ExampleGetChildAccounts.java
index 01a29dbb..79dd17cb 100644
--- a/examples/src/main/java/ExampleGetChildAccounts.java
+++ b/examples/src/main/java/ExampleGetChildAccounts.java
@@ -3,7 +3,9 @@
import com.messagebird.MessageBirdServiceImpl;
import com.messagebird.exceptions.GeneralException;
import com.messagebird.exceptions.UnauthorizedException;
-import com.messagebird.objects.PartnerAccountsResponse;
+import com.messagebird.objects.ChildAccountResponse;
+
+import java.util.List;
public class ExampleGetChildAccounts {
public static void main(String[] args) {
@@ -17,7 +19,7 @@ public static void main(String[] args) {
try {
System.out.println("Get a child accounts of partner account");
- PartnerAccountsResponse response = messageBirdClient.getChildAccounts(Integer.valueOf(args[1]), Integer.valueOf(args[2]));
+ List response = messageBirdClient.getChildAccounts(Integer.valueOf(args[1]), Integer.valueOf(args[2]));
System.out.println("response: " + response);
} catch (GeneralException | UnauthorizedException exception) {
exception.printStackTrace();
From 74e2370069cd4350893fe0e101a1343573384f34 Mon Sep 17 00:00:00 2001
From: "deniz@messagebird.com"
Date: Mon, 11 Oct 2021 10:23:26 +0200
Subject: [PATCH 025/216] new release changes
---
api/pom.xml | 2 +-
api/src/main/java/com/messagebird/MessageBirdServiceImpl.java | 2 +-
examples/pom.xml | 4 ++--
3 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/api/pom.xml b/api/pom.xml
index 47e53822..073b9f80 100644
--- a/api/pom.xml
+++ b/api/pom.xml
@@ -4,7 +4,7 @@
com.messagebirdmessagebird-api
- 3.1.2
diff --git a/api/src/main/java/com/messagebird/MessageBirdServiceImpl.java b/api/src/main/java/com/messagebird/MessageBirdServiceImpl.java
index 2497d524..b941ea0f 100644
--- a/api/src/main/java/com/messagebird/MessageBirdServiceImpl.java
+++ b/api/src/main/java/com/messagebird/MessageBirdServiceImpl.java
@@ -74,7 +74,7 @@ public class MessageBirdServiceImpl implements MessageBirdService {
private final String accessKey;
private final String serviceUrl;
- private final String clientVersion = "3.1.2";
+ private final String clientVersion = "3.1.4";
private final String userAgentString;
private Proxy proxy = null;
diff --git a/examples/pom.xml b/examples/pom.xml
index 438522e7..c551756a 100644
--- a/examples/pom.xml
+++ b/examples/pom.xml
@@ -6,7 +6,7 @@
com.messagebirdexamples
- 3.1.2
+ 3.1.4
@@ -20,7 +20,7 @@
com.messagebirdmessagebird-api
- 3.1.2
+ 3.1.4compile
From 6e07c1dde7e7b54524d97d9f0475c4388b10fcaa Mon Sep 17 00:00:00 2001
From: "deniz@messagebird.com"
Date: Mon, 11 Oct 2021 10:24:25 +0200
Subject: [PATCH 026/216] [maven-release-plugin] prepare release v3.1.4
---
api/pom.xml | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/api/pom.xml b/api/pom.xml
index 073b9f80..6e21c631 100644
--- a/api/pom.xml
+++ b/api/pom.xml
@@ -4,7 +4,7 @@
com.messagebirdmessagebird-api
- 3.1.4-SNAPSHOT
@@ -42,7 +42,7 @@
scm:git:git@github.com:messagebird/java-rest-api.gitscm:git:git@github.com:messagebird/java-rest-api.gitgit@github.com:messagebird/java-rest-api.git
- HEAD
+ v3.1.4
From 3c34b3b186db79779b64d8a907e0181fade0ab25 Mon Sep 17 00:00:00 2001
From: "deniz@messagebird.com"
Date: Mon, 11 Oct 2021 10:24:28 +0200
Subject: [PATCH 027/216] [maven-release-plugin] prepare for next development
iteration
---
api/pom.xml | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/api/pom.xml b/api/pom.xml
index 6e21c631..2da56990 100644
--- a/api/pom.xml
+++ b/api/pom.xml
@@ -4,7 +4,7 @@
com.messagebirdmessagebird-api
- 3.1.4
@@ -42,7 +42,7 @@
scm:git:git@github.com:messagebird/java-rest-api.gitscm:git:git@github.com:messagebird/java-rest-api.gitgit@github.com:messagebird/java-rest-api.git
- v3.1.4
+ HEAD
From 4fd0996c25ca93b2579609adc4ead7a4bbb4f44f Mon Sep 17 00:00:00 2001
From: "deniz@messagebird.com"
Date: Mon, 11 Oct 2021 14:38:11 +0200
Subject: [PATCH 028/216] new release changes
---
api/pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/api/pom.xml b/api/pom.xml
index 2da56990..d56811e3 100644
--- a/api/pom.xml
+++ b/api/pom.xml
@@ -4,7 +4,7 @@
com.messagebirdmessagebird-api
- 3.1.5-SNAPSHOT
From e540a5e9c22323dc51c9de62ccb49fdd5d6a206a Mon Sep 17 00:00:00 2001
From: "khanh.nguyen"
Date: Tue, 19 Oct 2021 12:16:24 +0200
Subject: [PATCH 029/216] Update request signature validation example
---
.../java/ExampleRequestSignatureValidation.java | 17 +++++++++--------
1 file changed, 9 insertions(+), 8 deletions(-)
diff --git a/examples/src/main/java/ExampleRequestSignatureValidation.java b/examples/src/main/java/ExampleRequestSignatureValidation.java
index 4f54297c..e7b92566 100644
--- a/examples/src/main/java/ExampleRequestSignatureValidation.java
+++ b/examples/src/main/java/ExampleRequestSignatureValidation.java
@@ -22,25 +22,26 @@
* Created by hasselbach
*
* For exposing your application for external calls (webhooks from MessageBird)
- * you can use serveo.net: `ssh -R 80:localhost:3000 serveo.net`
+ * you can use localtunnel (requires NodeJS).
*
- * Here is example of usage
+ * Here is example of usage:
+ *
+ * Install localtunnel globally:
+ * npm install -g localtunnel
*
* Select a free port: 3000, for example
* export MBEXAMPLEPORT=3000
*
* Run:
- * ssh -R 80:localhost:$MBEXAMPLEPORT serveo.net
+ * lt --port $MBEXAMPLEPORT
*
* It will show you something like this:
- * Hi there
- * Forwarding HTTP traffic from https://blabla.serveo.net
- * Press g to start a GUI session and ctrl-c to quit.
+ * your url is: https://loud-yak-31.loca.lt
*
* * NOTE * you should not terminate this process, so next operations should be done in the other terminal session
*
* Remember the address from output:
- * export FORWARDING_URL=https://blabla.serveo.net
+ * export FORWARDING_URL=https://loud-yak-31.loca.lt
*
* Take your access and secret key from Dashboard:
* secret key from https://dashboard.messagebird.com/en/developers/settings
@@ -57,8 +58,8 @@
* and then you will see in example app output:
* New request:
* GET /webhook?id=ee2d02749a6fb78a572bd7ce9118dff&mccmnc=20409&ported=0&recipient=XXXXXX&reference=example-server&status=delivered&statusDatetime=2019-01-10T09%3A23%3A03%2B00%3A00
- * Request has valid signature
* Message for XXXXXX is delivered
+ * Request has valid signature
*
* Description of webhook parameters can be found on
* https://developers.messagebird.com/docs/sms-messaging#handle-a-status-report
From a376f3115246476dd85316bb7a41b7e650f2908c Mon Sep 17 00:00:00 2001
From: cemturker
Date: Fri, 5 Nov 2021 11:13:34 +0100
Subject: [PATCH 030/216] Add messaging listings with query param for
Conversations API
---
.../com/messagebird/MessageBirdClient.java | 20 +++++++++
...istConversationMessagesWithQueryParam.java | 43 +++++++++++++++++++
2 files changed, 63 insertions(+)
create mode 100644 examples/src/main/java/ExampleListConversationMessagesWithQueryParam.java
diff --git a/api/src/main/java/com/messagebird/MessageBirdClient.java b/api/src/main/java/com/messagebird/MessageBirdClient.java
index cd8ca60a..a5337d91 100644
--- a/api/src/main/java/com/messagebird/MessageBirdClient.java
+++ b/api/src/main/java/com/messagebird/MessageBirdClient.java
@@ -117,6 +117,9 @@ public class MessageBirdClient {
private static final String[] MESSAGE_LIST_FILTERS_VALS = {"originator", "recipient", "direction", "searchterm", "type", "contact_id", "status", "from", "until"};
private static final Set MESSAGE_LIST_FILTERS = new HashSet<>(Arrays.asList(MESSAGE_LIST_FILTERS_VALS));
+ private static final String[] CONVERSATION_MESSAGE_LIST_FILTERS_VALS = {"ids", "from"};
+ private static final Set CONVERSATION_MESSAGE_LIST_FILTERS = new HashSet<>(Arrays.asList(CONVERSATION_MESSAGE_LIST_FILTERS_VALS));
+
private final String DOWNLOADS = "Downloads";
private MessageBirdService messageBirdService;
@@ -1006,6 +1009,23 @@ public ConversationMessage viewConversationMessage(final String messageId)
return messageBirdService.requestByID(url, messageId, ConversationMessage.class);
}
+ /**
+ * Gets messages based on query param.
+ *
+ * @param queryParams
+ * @return The retrieved messages.
+ */
+ public ConversationMessageList listConversationMessagesWithQueryParam(Map queryParams)
+ throws NotFoundException, GeneralException, UnauthorizedException {
+ for (String queryParam : queryParams.keySet()) {
+ if (!CONVERSATION_MESSAGE_LIST_FILTERS.contains(queryParam)) {
+ throw new IllegalArgumentException("Invalid filter name: " + queryParam);
+ }
+ }
+ String url = CONVERSATIONS_BASE_URL + CONVERSATION_MESSAGE_PATH;
+ return messageBirdService.requestByID(url, null, queryParams, ConversationMessageList.class);
+ }
+
/**
* Sends a message to an existing Conversation.
*
diff --git a/examples/src/main/java/ExampleListConversationMessagesWithQueryParam.java b/examples/src/main/java/ExampleListConversationMessagesWithQueryParam.java
new file mode 100644
index 00000000..fe7ec7e7
--- /dev/null
+++ b/examples/src/main/java/ExampleListConversationMessagesWithQueryParam.java
@@ -0,0 +1,43 @@
+import com.messagebird.MessageBirdClient;
+import com.messagebird.MessageBirdService;
+import com.messagebird.MessageBirdServiceImpl;
+import com.messagebird.exceptions.GeneralException;
+import com.messagebird.exceptions.NotFoundException;
+import com.messagebird.exceptions.UnauthorizedException;
+import com.messagebird.objects.conversations.ConversationMessageList;
+import java.util.HashMap;
+
+public class ExampleListConversationMessagesWithQueryParam {
+ public static void main(String[] args) {
+
+ if (args.length == 0) {
+ System.out.println("Please specify your access key example : java -jar test_accesskey");
+ return;
+ }
+
+ // First create your service object
+ final MessageBirdService wsr = new MessageBirdServiceImpl(args[0]);
+
+ // Add the service to the client
+ final MessageBirdClient messageBirdClient = new MessageBirdClient(wsr);
+
+ try {
+ // Get list of conversation messages with query param
+ System.out.println("Retrieving message list");
+ final ConversationMessageList conversationMessageList = messageBirdClient.listConversationMessagesWithQueryParam(
+ new HashMap() {
+ {
+ put("ids", "9f0b413e79e24d76b01b895381b12a6d,d46054ee0f7245bcbc7ba586878d0ab4");
+ }
+ });
+
+ // Display balance
+ System.out.println(conversationMessageList.toString());
+ } catch (UnauthorizedException | GeneralException | NotFoundException exception) {
+ if (exception.getErrors() != null) {
+ System.out.println(exception.getErrors().toString());
+ }
+ exception.printStackTrace();
+ }
+ }
+}
From d27b0300f23e5a92dc2835ad26d4f2eb907de5bd Mon Sep 17 00:00:00 2001
From: cemturker
Date: Fri, 5 Nov 2021 11:14:31 +0100
Subject: [PATCH 031/216] fix the comment
---
.../java/ExampleListConversationMessagesWithQueryParam.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/examples/src/main/java/ExampleListConversationMessagesWithQueryParam.java b/examples/src/main/java/ExampleListConversationMessagesWithQueryParam.java
index fe7ec7e7..5ab13cf5 100644
--- a/examples/src/main/java/ExampleListConversationMessagesWithQueryParam.java
+++ b/examples/src/main/java/ExampleListConversationMessagesWithQueryParam.java
@@ -31,7 +31,7 @@ public static void main(String[] args) {
}
});
- // Display balance
+ // Display conversation Message list
System.out.println(conversationMessageList.toString());
} catch (UnauthorizedException | GeneralException | NotFoundException exception) {
if (exception.getErrors() != null) {
From 99ff4016903044738aa6462ddbbebb07ee9d2703 Mon Sep 17 00:00:00 2001
From: cemturker
Date: Fri, 5 Nov 2021 11:15:19 +0100
Subject: [PATCH 032/216] Add comments
---
api/src/main/java/com/messagebird/MessageBirdClient.java | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/api/src/main/java/com/messagebird/MessageBirdClient.java b/api/src/main/java/com/messagebird/MessageBirdClient.java
index a5337d91..0e4f9ce2 100644
--- a/api/src/main/java/com/messagebird/MessageBirdClient.java
+++ b/api/src/main/java/com/messagebird/MessageBirdClient.java
@@ -1010,9 +1010,9 @@ public ConversationMessage viewConversationMessage(final String messageId)
}
/**
- * Gets messages based on query param.
+ * Gets conversation messages based on query param.
*
- * @param queryParams
+ * @param queryParams only `ids` and `from` is available as an option
* @return The retrieved messages.
*/
public ConversationMessageList listConversationMessagesWithQueryParam(Map queryParams)
From d5fe3f95aff24541d617920573cda22ad49b0cbe Mon Sep 17 00:00:00 2001
From: "deniz@messagebird.com"
Date: Sat, 6 Nov 2021 23:54:40 +0100
Subject: [PATCH 033/216] create child account response fields are updated
---
.../com/messagebird/objects/AccessKey.java | 64 +++++++++++++++++--
.../objects/ChildAccountCreateResponse.java | 13 +++-
.../messagebird/MessageBirdClientTest.java | 2 +-
.../test/java/com/messagebird/TestUtil.java | 2 +-
4 files changed, 71 insertions(+), 10 deletions(-)
diff --git a/api/src/main/java/com/messagebird/objects/AccessKey.java b/api/src/main/java/com/messagebird/objects/AccessKey.java
index 65ee9fd7..78d168c0 100644
--- a/api/src/main/java/com/messagebird/objects/AccessKey.java
+++ b/api/src/main/java/com/messagebird/objects/AccessKey.java
@@ -1,9 +1,16 @@
package com.messagebird.objects;
+import java.util.List;
+
public class AccessKey {
private String id;
- private String key;
+ private String access_key;
private String mod;
+ private String description;
+ private int core_user_id;
+ private int user_id;
+ private int external_id;
+ private List roles;
public String getId() {
return id;
@@ -13,12 +20,12 @@ public void setId(String id) {
this.id = id;
}
- public String getKey() {
- return key;
+ public String getAccess_key() {
+ return access_key;
}
- public void setKey(String key) {
- this.key = key;
+ public void setAccess_key(String access_key) {
+ this.access_key = access_key;
}
public String getMod() {
@@ -29,12 +36,57 @@ public void setMod(String mod) {
this.mod = mod;
}
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public int getCore_user_id() {
+ return core_user_id;
+ }
+
+ public void setCore_user_id(int core_user_id) {
+ this.core_user_id = core_user_id;
+ }
+
+ public int getUser_id() {
+ return user_id;
+ }
+
+ public void setUser_id(int user_id) {
+ this.user_id = user_id;
+ }
+
+ public int getExternal_id() {
+ return external_id;
+ }
+
+ public void setExternal_id(int external_id) {
+ this.external_id = external_id;
+ }
+
+ public List getRoles() {
+ return roles;
+ }
+
+ public void setRoles(List roles) {
+ this.roles = roles;
+ }
+
@Override
public String toString() {
return "AccessKey{" +
"id='" + id + '\'' +
- ", key='" + key + '\'' +
+ ", access_key='" + access_key + '\'' +
", mod='" + mod + '\'' +
+ ", description='" + description + '\'' +
+ ", core_user_id=" + core_user_id +
+ ", user_id=" + user_id +
+ ", external_id=" + external_id +
+ ", roles=" + roles +
'}';
}
}
diff --git a/api/src/main/java/com/messagebird/objects/ChildAccountCreateResponse.java b/api/src/main/java/com/messagebird/objects/ChildAccountCreateResponse.java
index dcf201b6..40ec38a4 100644
--- a/api/src/main/java/com/messagebird/objects/ChildAccountCreateResponse.java
+++ b/api/src/main/java/com/messagebird/objects/ChildAccountCreateResponse.java
@@ -6,6 +6,7 @@ public class ChildAccountCreateResponse extends ChildAccountResponse{
private List accessKeys;
private String signingKey;
private String invoiceAggregation;
+ private String paymentMoment;
public List getAccessKeys() {
return accessKeys;
@@ -31,14 +32,22 @@ public void setInvoiceAggregation(String invoiceAggregation) {
this.invoiceAggregation = invoiceAggregation;
}
+ public String getPaymentMoment() {
+ return paymentMoment;
+ }
+
+ public void setPaymentMoment(String paymentMoment) {
+ this.paymentMoment = paymentMoment;
+ }
+
@Override
public String toString() {
return "ChildAccountCreateResponse{" +
"id='" + getId() + '\'' +
", name='" + getName() + '\'' +
", accessKeys=" + accessKeys + '\'' +
- ", signingKey='" + signingKey + '\'' +
", invoiceAggregation='" + invoiceAggregation + '\'' +
+ ", paymentMoment='" + paymentMoment + '\'' +
'}';
- }
+ }
}
diff --git a/api/src/test/java/com/messagebird/MessageBirdClientTest.java b/api/src/test/java/com/messagebird/MessageBirdClientTest.java
index 139ede8a..e342c165 100644
--- a/api/src/test/java/com/messagebird/MessageBirdClientTest.java
+++ b/api/src/test/java/com/messagebird/MessageBirdClientTest.java
@@ -1240,7 +1240,7 @@ public void testCreateChildAccounts() throws GeneralException, UnauthorizedExcep
assertEquals(response.getInvoiceAggregation(), childAccountCreateResponse.getInvoiceAggregation());
assertEquals(response.getSigningKey(), childAccountCreateResponse.getSigningKey());
assertEquals(response.getAccessKeys().get(0).getId(), childAccountCreateResponse.getAccessKeys().get(0).getId());
- assertEquals(response.getAccessKeys().get(0).getKey(), childAccountCreateResponse.getAccessKeys().get(0).getKey());
+ assertEquals(response.getAccessKeys().get(0).getAccess_key(), childAccountCreateResponse.getAccessKeys().get(0).getAccess_key());
assertEquals(response.getAccessKeys().get(0).getMod(), childAccountCreateResponse.getAccessKeys().get(0).getMod());
}
diff --git a/api/src/test/java/com/messagebird/TestUtil.java b/api/src/test/java/com/messagebird/TestUtil.java
index 7518776b..269f8e40 100644
--- a/api/src/test/java/com/messagebird/TestUtil.java
+++ b/api/src/test/java/com/messagebird/TestUtil.java
@@ -353,7 +353,7 @@ public static TemplateList createWhatsAppTemplateList(final String templateName)
public static ChildAccountCreateResponse createChildAccountCreateResponse() {
final AccessKey accessKey = new AccessKey();
accessKey.setId("ANY_ID");
- accessKey.setKey("ANY_KEY");
+ accessKey.setAccess_key("ANY_KEY");
accessKey.setMod("ANY_MOD");
final ChildAccountCreateResponse childAccountCreateResponse = new ChildAccountCreateResponse();
From 6a6a13552846e2392dc35b8cc6181302f8098036 Mon Sep 17 00:00:00 2001
From: "deniz@messagebird.com"
Date: Mon, 8 Nov 2021 18:55:56 +0100
Subject: [PATCH 034/216] updated after review
---
.../java/com/messagebird/objects/AccessKey.java | 15 +++++++++------
.../com/messagebird/MessageBirdClientTest.java | 2 +-
api/src/test/java/com/messagebird/TestUtil.java | 2 +-
3 files changed, 11 insertions(+), 8 deletions(-)
diff --git a/api/src/main/java/com/messagebird/objects/AccessKey.java b/api/src/main/java/com/messagebird/objects/AccessKey.java
index 78d168c0..d03a23d3 100644
--- a/api/src/main/java/com/messagebird/objects/AccessKey.java
+++ b/api/src/main/java/com/messagebird/objects/AccessKey.java
@@ -1,10 +1,13 @@
package com.messagebird.objects;
+import com.fasterxml.jackson.annotation.JsonProperty;
+
import java.util.List;
public class AccessKey {
private String id;
- private String access_key;
+ @JsonProperty("access_key")
+ private String accessKey;
private String mod;
private String description;
private int core_user_id;
@@ -20,12 +23,12 @@ public void setId(String id) {
this.id = id;
}
- public String getAccess_key() {
- return access_key;
+ public String getAccessKey() {
+ return accessKey;
}
- public void setAccess_key(String access_key) {
- this.access_key = access_key;
+ public void setAccessKey(String accessKey) {
+ this.accessKey = accessKey;
}
public String getMod() {
@@ -80,7 +83,7 @@ public void setRoles(List roles) {
public String toString() {
return "AccessKey{" +
"id='" + id + '\'' +
- ", access_key='" + access_key + '\'' +
+ ", access_key='" + accessKey + '\'' +
", mod='" + mod + '\'' +
", description='" + description + '\'' +
", core_user_id=" + core_user_id +
diff --git a/api/src/test/java/com/messagebird/MessageBirdClientTest.java b/api/src/test/java/com/messagebird/MessageBirdClientTest.java
index e342c165..af9c170f 100644
--- a/api/src/test/java/com/messagebird/MessageBirdClientTest.java
+++ b/api/src/test/java/com/messagebird/MessageBirdClientTest.java
@@ -1240,7 +1240,7 @@ public void testCreateChildAccounts() throws GeneralException, UnauthorizedExcep
assertEquals(response.getInvoiceAggregation(), childAccountCreateResponse.getInvoiceAggregation());
assertEquals(response.getSigningKey(), childAccountCreateResponse.getSigningKey());
assertEquals(response.getAccessKeys().get(0).getId(), childAccountCreateResponse.getAccessKeys().get(0).getId());
- assertEquals(response.getAccessKeys().get(0).getAccess_key(), childAccountCreateResponse.getAccessKeys().get(0).getAccess_key());
+ assertEquals(response.getAccessKeys().get(0).getAccessKey(), childAccountCreateResponse.getAccessKeys().get(0).getAccessKey());
assertEquals(response.getAccessKeys().get(0).getMod(), childAccountCreateResponse.getAccessKeys().get(0).getMod());
}
diff --git a/api/src/test/java/com/messagebird/TestUtil.java b/api/src/test/java/com/messagebird/TestUtil.java
index 269f8e40..19c30c46 100644
--- a/api/src/test/java/com/messagebird/TestUtil.java
+++ b/api/src/test/java/com/messagebird/TestUtil.java
@@ -353,7 +353,7 @@ public static TemplateList createWhatsAppTemplateList(final String templateName)
public static ChildAccountCreateResponse createChildAccountCreateResponse() {
final AccessKey accessKey = new AccessKey();
accessKey.setId("ANY_ID");
- accessKey.setAccess_key("ANY_KEY");
+ accessKey.setAccessKey("ANY_KEY");
accessKey.setMod("ANY_MOD");
final ChildAccountCreateResponse childAccountCreateResponse = new ChildAccountCreateResponse();
From fac98a4c9f9ae1cabbe8c215451adf6c2a139714 Mon Sep 17 00:00:00 2001
From: "deniz@messagebird.com"
Date: Mon, 8 Nov 2021 18:59:59 +0100
Subject: [PATCH 035/216] updated
---
.../com/messagebird/objects/AccessKey.java | 39 ++++++++++---------
1 file changed, 21 insertions(+), 18 deletions(-)
diff --git a/api/src/main/java/com/messagebird/objects/AccessKey.java b/api/src/main/java/com/messagebird/objects/AccessKey.java
index d03a23d3..e98106f0 100644
--- a/api/src/main/java/com/messagebird/objects/AccessKey.java
+++ b/api/src/main/java/com/messagebird/objects/AccessKey.java
@@ -10,9 +10,12 @@ public class AccessKey {
private String accessKey;
private String mod;
private String description;
- private int core_user_id;
- private int user_id;
- private int external_id;
+ @JsonProperty("core_user_id")
+ private int coreUserId;
+ @JsonProperty("user_id")
+ private int userId;
+ @JsonProperty("external_id")
+ private int externalId;
private List roles;
public String getId() {
@@ -47,28 +50,28 @@ public void setDescription(String description) {
this.description = description;
}
- public int getCore_user_id() {
- return core_user_id;
+ public int getCoreUserId() {
+ return coreUserId;
}
- public void setCore_user_id(int core_user_id) {
- this.core_user_id = core_user_id;
+ public void setCoreUserId(int coreUserId) {
+ this.coreUserId = coreUserId;
}
- public int getUser_id() {
- return user_id;
+ public int getUserId() {
+ return userId;
}
- public void setUser_id(int user_id) {
- this.user_id = user_id;
+ public void setUserId(int userId) {
+ this.userId = userId;
}
- public int getExternal_id() {
- return external_id;
+ public int getExternalId() {
+ return externalId;
}
- public void setExternal_id(int external_id) {
- this.external_id = external_id;
+ public void setExternalId(int externalId) {
+ this.externalId = externalId;
}
public List getRoles() {
@@ -86,9 +89,9 @@ public String toString() {
", access_key='" + accessKey + '\'' +
", mod='" + mod + '\'' +
", description='" + description + '\'' +
- ", core_user_id=" + core_user_id +
- ", user_id=" + user_id +
- ", external_id=" + external_id +
+ ", core_user_id=" + coreUserId +
+ ", user_id=" + userId +
+ ", external_id=" + externalId +
", roles=" + roles +
'}';
}
From 673677b5b9ddceb97c77913ce001eb61d7831024 Mon Sep 17 00:00:00 2001
From: "deniz@messagebird.com"
Date: Mon, 8 Nov 2021 19:46:09 +0100
Subject: [PATCH 036/216] updated for a new release
---
api/pom.xml | 2 +-
api/src/main/java/com/messagebird/MessageBirdServiceImpl.java | 2 +-
examples/pom.xml | 4 ++--
3 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/api/pom.xml b/api/pom.xml
index d56811e3..2da56990 100644
--- a/api/pom.xml
+++ b/api/pom.xml
@@ -4,7 +4,7 @@
com.messagebirdmessagebird-api
- 3.1.4
diff --git a/api/src/main/java/com/messagebird/MessageBirdServiceImpl.java b/api/src/main/java/com/messagebird/MessageBirdServiceImpl.java
index b941ea0f..5c025928 100644
--- a/api/src/main/java/com/messagebird/MessageBirdServiceImpl.java
+++ b/api/src/main/java/com/messagebird/MessageBirdServiceImpl.java
@@ -74,7 +74,7 @@ public class MessageBirdServiceImpl implements MessageBirdService {
private final String accessKey;
private final String serviceUrl;
- private final String clientVersion = "3.1.4";
+ private final String clientVersion = "3.1.5";
private final String userAgentString;
private Proxy proxy = null;
diff --git a/examples/pom.xml b/examples/pom.xml
index c551756a..6aabbb55 100644
--- a/examples/pom.xml
+++ b/examples/pom.xml
@@ -6,7 +6,7 @@
com.messagebirdexamples
- 3.1.4
+ 3.1.5
@@ -20,7 +20,7 @@
com.messagebirdmessagebird-api
- 3.1.4
+ 3.1.5compile
From d00a6584804b75fc3cfabd9be0374b7f9eb84447 Mon Sep 17 00:00:00 2001
From: "deniz@messagebird.com"
Date: Mon, 8 Nov 2021 19:47:16 +0100
Subject: [PATCH 037/216] [maven-release-plugin] prepare release v3.1.5
---
api/pom.xml | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/api/pom.xml b/api/pom.xml
index 2da56990..023f3d77 100644
--- a/api/pom.xml
+++ b/api/pom.xml
@@ -4,7 +4,7 @@
com.messagebirdmessagebird-api
- 3.1.5-SNAPSHOT
@@ -42,7 +42,7 @@
scm:git:git@github.com:messagebird/java-rest-api.gitscm:git:git@github.com:messagebird/java-rest-api.gitgit@github.com:messagebird/java-rest-api.git
- HEAD
+ v3.1.5
From 04e4383e08cfc4f87ff2c3467430dff16d3ad815 Mon Sep 17 00:00:00 2001
From: "deniz@messagebird.com"
Date: Mon, 8 Nov 2021 19:47:19 +0100
Subject: [PATCH 038/216] [maven-release-plugin] prepare for next development
iteration
---
api/pom.xml | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/api/pom.xml b/api/pom.xml
index 023f3d77..e0b0981c 100644
--- a/api/pom.xml
+++ b/api/pom.xml
@@ -4,7 +4,7 @@
com.messagebirdmessagebird-api
- 3.1.5
@@ -42,7 +42,7 @@
scm:git:git@github.com:messagebird/java-rest-api.gitscm:git:git@github.com:messagebird/java-rest-api.gitgit@github.com:messagebird/java-rest-api.git
- v3.1.5
+ HEAD
From f1624f768dd4493b4571dca070411034921bd7df Mon Sep 17 00:00:00 2001
From: "deniz@messagebird.com"
Date: Tue, 9 Nov 2021 09:15:52 +0100
Subject: [PATCH 039/216] updated for a new verrsion
---
api/pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/api/pom.xml b/api/pom.xml
index e0b0981c..8ad1aa5c 100644
--- a/api/pom.xml
+++ b/api/pom.xml
@@ -4,7 +4,7 @@
com.messagebirdmessagebird-api
- 3.1.6-SNAPSHOT
From 36f5eeca985c8ffe39402259f8e3ba84d3d25a0e Mon Sep 17 00:00:00 2001
From: "deniz@messagebird.com"
Date: Tue, 9 Nov 2021 10:51:37 +0100
Subject: [PATCH 040/216] updated a field in AccessKey class
---
.../main/java/com/messagebird/objects/AccessKey.java | 12 ++++++------
.../java/com/messagebird/MessageBirdClientTest.java | 2 +-
api/src/test/java/com/messagebird/TestUtil.java | 2 +-
3 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/api/src/main/java/com/messagebird/objects/AccessKey.java b/api/src/main/java/com/messagebird/objects/AccessKey.java
index e98106f0..4d529711 100644
--- a/api/src/main/java/com/messagebird/objects/AccessKey.java
+++ b/api/src/main/java/com/messagebird/objects/AccessKey.java
@@ -8,7 +8,7 @@ public class AccessKey {
private String id;
@JsonProperty("access_key")
private String accessKey;
- private String mod;
+ private String mode;
private String description;
@JsonProperty("core_user_id")
private int coreUserId;
@@ -34,12 +34,12 @@ public void setAccessKey(String accessKey) {
this.accessKey = accessKey;
}
- public String getMod() {
- return mod;
+ public String getMode() {
+ return mode;
}
- public void setMod(String mod) {
- this.mod = mod;
+ public void setMode(String mode) {
+ this.mode = mode;
}
public String getDescription() {
@@ -87,7 +87,7 @@ public String toString() {
return "AccessKey{" +
"id='" + id + '\'' +
", access_key='" + accessKey + '\'' +
- ", mod='" + mod + '\'' +
+ ", mod='" + mode + '\'' +
", description='" + description + '\'' +
", core_user_id=" + coreUserId +
", user_id=" + userId +
diff --git a/api/src/test/java/com/messagebird/MessageBirdClientTest.java b/api/src/test/java/com/messagebird/MessageBirdClientTest.java
index af9c170f..67eb3c47 100644
--- a/api/src/test/java/com/messagebird/MessageBirdClientTest.java
+++ b/api/src/test/java/com/messagebird/MessageBirdClientTest.java
@@ -1241,7 +1241,7 @@ public void testCreateChildAccounts() throws GeneralException, UnauthorizedExcep
assertEquals(response.getSigningKey(), childAccountCreateResponse.getSigningKey());
assertEquals(response.getAccessKeys().get(0).getId(), childAccountCreateResponse.getAccessKeys().get(0).getId());
assertEquals(response.getAccessKeys().get(0).getAccessKey(), childAccountCreateResponse.getAccessKeys().get(0).getAccessKey());
- assertEquals(response.getAccessKeys().get(0).getMod(), childAccountCreateResponse.getAccessKeys().get(0).getMod());
+ assertEquals(response.getAccessKeys().get(0).getMode(), childAccountCreateResponse.getAccessKeys().get(0).getMode());
}
@Test
diff --git a/api/src/test/java/com/messagebird/TestUtil.java b/api/src/test/java/com/messagebird/TestUtil.java
index 19c30c46..d5cf47a9 100644
--- a/api/src/test/java/com/messagebird/TestUtil.java
+++ b/api/src/test/java/com/messagebird/TestUtil.java
@@ -354,7 +354,7 @@ public static ChildAccountCreateResponse createChildAccountCreateResponse() {
final AccessKey accessKey = new AccessKey();
accessKey.setId("ANY_ID");
accessKey.setAccessKey("ANY_KEY");
- accessKey.setMod("ANY_MOD");
+ accessKey.setMode("ANY_MOD");
final ChildAccountCreateResponse childAccountCreateResponse = new ChildAccountCreateResponse();
childAccountCreateResponse.setId("ANY_ID");
From 5fdde1165b4f506643860047809978d9b1c5b788 Mon Sep 17 00:00:00 2001
From: "deniz@messagebird.com"
Date: Tue, 9 Nov 2021 11:04:03 +0100
Subject: [PATCH 041/216] new release
---
api/pom.xml | 2 +-
api/src/main/java/com/messagebird/MessageBirdServiceImpl.java | 2 +-
examples/pom.xml | 4 ++--
3 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/api/pom.xml b/api/pom.xml
index 8ad1aa5c..e0b0981c 100644
--- a/api/pom.xml
+++ b/api/pom.xml
@@ -4,7 +4,7 @@
com.messagebirdmessagebird-api
- 3.1.5
diff --git a/api/src/main/java/com/messagebird/MessageBirdServiceImpl.java b/api/src/main/java/com/messagebird/MessageBirdServiceImpl.java
index 5c025928..8e0b5976 100644
--- a/api/src/main/java/com/messagebird/MessageBirdServiceImpl.java
+++ b/api/src/main/java/com/messagebird/MessageBirdServiceImpl.java
@@ -74,7 +74,7 @@ public class MessageBirdServiceImpl implements MessageBirdService {
private final String accessKey;
private final String serviceUrl;
- private final String clientVersion = "3.1.5";
+ private final String clientVersion = "3.1.6";
private final String userAgentString;
private Proxy proxy = null;
diff --git a/examples/pom.xml b/examples/pom.xml
index 6aabbb55..821e40fa 100644
--- a/examples/pom.xml
+++ b/examples/pom.xml
@@ -6,7 +6,7 @@
com.messagebirdexamples
- 3.1.5
+ 3.1.6
@@ -20,7 +20,7 @@
com.messagebirdmessagebird-api
- 3.1.5
+ 3.1.6compile
From 2cbd643ad79fb77ce3a0d62a026babe007f55fd6 Mon Sep 17 00:00:00 2001
From: "deniz@messagebird.com"
Date: Tue, 9 Nov 2021 11:05:08 +0100
Subject: [PATCH 042/216] [maven-release-plugin] prepare release v3.1.6
---
api/pom.xml | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/api/pom.xml b/api/pom.xml
index e0b0981c..5a84584b 100644
--- a/api/pom.xml
+++ b/api/pom.xml
@@ -4,7 +4,7 @@
com.messagebirdmessagebird-api
- 3.1.6-SNAPSHOT
@@ -42,7 +42,7 @@
scm:git:git@github.com:messagebird/java-rest-api.gitscm:git:git@github.com:messagebird/java-rest-api.gitgit@github.com:messagebird/java-rest-api.git
- HEAD
+ v3.1.6
From b891023571f970cdb8277d770ba25153e5d57db4 Mon Sep 17 00:00:00 2001
From: "deniz@messagebird.com"
Date: Tue, 9 Nov 2021 11:05:12 +0100
Subject: [PATCH 043/216] [maven-release-plugin] prepare for next development
iteration
---
api/pom.xml | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/api/pom.xml b/api/pom.xml
index 5a84584b..c9c15b88 100644
--- a/api/pom.xml
+++ b/api/pom.xml
@@ -4,7 +4,7 @@
com.messagebirdmessagebird-api
- 3.1.6
@@ -42,7 +42,7 @@
scm:git:git@github.com:messagebird/java-rest-api.gitscm:git:git@github.com:messagebird/java-rest-api.gitgit@github.com:messagebird/java-rest-api.git
- v3.1.6
+ HEAD
From 265c9d112e11f405890e9920c5e6810337045c9a Mon Sep 17 00:00:00 2001
From: "deniz@messagebird.com"
Date: Tue, 9 Nov 2021 16:53:47 +0100
Subject: [PATCH 044/216] updated
---
api/pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/api/pom.xml b/api/pom.xml
index c9c15b88..f23a8bd8 100644
--- a/api/pom.xml
+++ b/api/pom.xml
@@ -4,7 +4,7 @@
com.messagebirdmessagebird-api
- 3.1.7-SNAPSHOT
From fd2e3055cf0e5e8c3a55f84edc83339d5170881f Mon Sep 17 00:00:00 2001
From: "deniz@messagebird.com"
Date: Thu, 11 Nov 2021 10:57:27 +0100
Subject: [PATCH 045/216] added new fields on MessageResponse class
---
.../messagebird/objects/MessageResponse.java | 70 ++++++++++++++++++-
1 file changed, 67 insertions(+), 3 deletions(-)
diff --git a/api/src/main/java/com/messagebird/objects/MessageResponse.java b/api/src/main/java/com/messagebird/objects/MessageResponse.java
index 8b480e25..91d4d6da 100644
--- a/api/src/main/java/com/messagebird/objects/MessageResponse.java
+++ b/api/src/main/java/com/messagebird/objects/MessageResponse.java
@@ -196,7 +196,7 @@ public Map getTypeDetails() {
static public class Recipients implements Serializable {
private static final long serialVersionUID = 547164972757802213L;
-
+ private Integer totalCount;
private Integer totalSentCount;
private Integer totalDeliveredCount;
private Integer totalDeliveryFailedCount;
@@ -208,13 +208,18 @@ public Recipients() {
@Override
public String toString() {
return "Recipients{" +
- "totalSentCount=" + totalSentCount +
+ "totalCount=" + totalCount +
+ ", totalSentCount=" + totalSentCount +
", totalDeliveredCount=" + totalDeliveredCount +
", totalDeliveryFailedCount=" + totalDeliveryFailedCount +
", items=" + items +
'}';
}
+ public Integer getTotalCount() {
+ return totalCount;
+ }
+
/**
* The count of recipients that have the message pending (status sent, and buffered).
*
@@ -260,10 +265,20 @@ static public class Items implements Serializable {
private static final long serialVersionUID = -4104837036540050532L;
private BigInteger recipient;
+ private BigInteger originator;
private String status;
private Date statusDatetime;
+ private String recipientCountry;
+ private Integer recipientCountryPrefix;
+ private String recipientOperator;
+ private Integer messageLength;
+ private String statusReason;
@Nullable
private Price price;
+ private String mccmnc;
+ private String mcc;
+ private String mnc;
+ private int messagePartCount;
public Items() {
}
@@ -272,10 +287,20 @@ public Items() {
public String toString() {
return "Items{" +
"recipient=" + recipient +
+ ", originator=" + originator +
", status='" + status + '\'' +
", statusDatetime=" + statusDatetime +
+ ", recipientCountry='" + recipientCountry + '\'' +
+ ", recipientCountryPrefix=" + recipientCountryPrefix +
+ ", recipientOperator='" + recipientOperator + '\'' +
+ ", messageLength=" + messageLength +
+ ", statusReason='" + statusReason + '\'' +
", price=" + price +
- "}";
+ ", mccmnc='" + mccmnc + '\'' +
+ ", mcc='" + mcc + '\'' +
+ ", mnc='" + mnc + '\'' +
+ ", messagePartCount=" + messagePartCount +
+ '}';
}
/**
@@ -309,6 +334,45 @@ public Price getPrice() {
return price;
}
+ public BigInteger getOriginator() {
+ return originator;
+ }
+
+ public String getRecipientCountry() {
+ return recipientCountry;
+ }
+
+ public Integer getRecipientCountryPrefix() {
+ return recipientCountryPrefix;
+ }
+
+ public String getRecipientOperator() {
+ return recipientOperator;
+ }
+
+ public Integer getMessageLength() {
+ return messageLength;
+ }
+
+ public String getStatusReason() {
+ return statusReason;
+ }
+
+ public String getMccmnc() {
+ return mccmnc;
+ }
+
+ public String getMcc() {
+ return mcc;
+ }
+
+ public String getMnc() {
+ return mnc;
+ }
+
+ public int getMessagePartCount() {
+ return messagePartCount;
+ }
}
/**
From 72796a9c3a524528e7f36c346305669f8723681e Mon Sep 17 00:00:00 2001
From: "deniz@messagebird.com"
Date: Thu, 11 Nov 2021 11:11:03 +0100
Subject: [PATCH 046/216] preparing a new release
---
api/pom.xml | 2 +-
api/src/main/java/com/messagebird/MessageBirdServiceImpl.java | 2 +-
examples/pom.xml | 4 ++--
3 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/api/pom.xml b/api/pom.xml
index f23a8bd8..c9c15b88 100644
--- a/api/pom.xml
+++ b/api/pom.xml
@@ -4,7 +4,7 @@
com.messagebirdmessagebird-api
- 3.1.6
diff --git a/api/src/main/java/com/messagebird/MessageBirdServiceImpl.java b/api/src/main/java/com/messagebird/MessageBirdServiceImpl.java
index 8e0b5976..69e6f220 100644
--- a/api/src/main/java/com/messagebird/MessageBirdServiceImpl.java
+++ b/api/src/main/java/com/messagebird/MessageBirdServiceImpl.java
@@ -74,7 +74,7 @@ public class MessageBirdServiceImpl implements MessageBirdService {
private final String accessKey;
private final String serviceUrl;
- private final String clientVersion = "3.1.6";
+ private final String clientVersion = "3.1.7";
private final String userAgentString;
private Proxy proxy = null;
diff --git a/examples/pom.xml b/examples/pom.xml
index 821e40fa..3353a261 100644
--- a/examples/pom.xml
+++ b/examples/pom.xml
@@ -6,7 +6,7 @@
com.messagebirdexamples
- 3.1.6
+ 3.1.7
@@ -20,7 +20,7 @@
com.messagebirdmessagebird-api
- 3.1.6
+ 3.1.7compile
From 09be655286f498155cf34cef6627c486911541bf Mon Sep 17 00:00:00 2001
From: "deniz@messagebird.com"
Date: Thu, 11 Nov 2021 11:12:43 +0100
Subject: [PATCH 047/216] [maven-release-plugin] prepare release v3.1.7
---
api/pom.xml | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/api/pom.xml b/api/pom.xml
index c9c15b88..e14eec8c 100644
--- a/api/pom.xml
+++ b/api/pom.xml
@@ -4,7 +4,7 @@
com.messagebirdmessagebird-api
- 3.1.7-SNAPSHOT
@@ -42,7 +42,7 @@
scm:git:git@github.com:messagebird/java-rest-api.gitscm:git:git@github.com:messagebird/java-rest-api.gitgit@github.com:messagebird/java-rest-api.git
- HEAD
+ v3.1.7
From aee2c719d4f41a962532ab8b09d5e67f71ad22c6 Mon Sep 17 00:00:00 2001
From: "deniz@messagebird.com"
Date: Thu, 11 Nov 2021 11:12:46 +0100
Subject: [PATCH 048/216] [maven-release-plugin] prepare for next development
iteration
---
api/pom.xml | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/api/pom.xml b/api/pom.xml
index e14eec8c..1c1e9b3c 100644
--- a/api/pom.xml
+++ b/api/pom.xml
@@ -4,7 +4,7 @@
com.messagebirdmessagebird-api
- 3.1.7
@@ -42,7 +42,7 @@
scm:git:git@github.com:messagebird/java-rest-api.gitscm:git:git@github.com:messagebird/java-rest-api.gitgit@github.com:messagebird/java-rest-api.git
- v3.1.7
+ HEAD
From fffb40ba17b7b1aca65ecffd20f2c1456737dc66 Mon Sep 17 00:00:00 2001
From: "deniz@messagebird.com"
Date: Thu, 11 Nov 2021 17:44:20 +0100
Subject: [PATCH 049/216] updated pom
---
api/pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/api/pom.xml b/api/pom.xml
index 1c1e9b3c..f7a7fb61 100644
--- a/api/pom.xml
+++ b/api/pom.xml
@@ -4,7 +4,7 @@
com.messagebirdmessagebird-api
- 3.1.8-SNAPSHOT
From 13c2c247abab54fe77048941e003a5eb0c16d078 Mon Sep 17 00:00:00 2001
From: Leandro Pinto
Date: Fri, 17 Dec 2021 11:44:55 +0100
Subject: [PATCH 050/216] Adding support to the new sipResponseCode filed in
the VoiceCallLeg object.
---
.../messagebird/objects/voicecalls/VoiceCallLeg.java | 11 ++++++++---
.../test/java/com/messagebird/VoiceCallingTest.java | 3 ++-
api/src/test/resources/fixtures/call_legs_list.json | 1 +
examples/src/main/java/ExampleViewVoiceCallLegs.java | 2 +-
4 files changed, 12 insertions(+), 5 deletions(-)
diff --git a/api/src/main/java/com/messagebird/objects/voicecalls/VoiceCallLeg.java b/api/src/main/java/com/messagebird/objects/voicecalls/VoiceCallLeg.java
index 93dc0fa2..d09b7bdf 100644
--- a/api/src/main/java/com/messagebird/objects/voicecalls/VoiceCallLeg.java
+++ b/api/src/main/java/com/messagebird/objects/voicecalls/VoiceCallLeg.java
@@ -28,6 +28,7 @@ public class VoiceCallLeg {
public final Date updatedAt;
public final Date answeredAt;
public final Date endedAt;
+ public final SipResponseCode sipResponseCode;
@JsonCreator
@@ -44,7 +45,8 @@ public VoiceCallLeg(
@JsonProperty("createdAt") Date createdAt,
@JsonProperty("updatedAt") Date updatedAt,
@JsonProperty("answeredAt") Date answeredAt,
- @JsonProperty("endedAt") Date endedAt
+ @JsonProperty("endedAt") Date endedAt,
+ @JsonProperty("sipResponseCode") SipResponseCode sipResponseCode
) {
this.id = id;
this.callID = callID;
@@ -59,6 +61,7 @@ public VoiceCallLeg(
this.updatedAt = updatedAt;
this.answeredAt = answeredAt;
this.endedAt = endedAt;
+ this.sipResponseCode = sipResponseCode;
}
@Override
@@ -77,6 +80,7 @@ public String toString() {
", updatedAt='" + updatedAt + '\'' +
", answeredAt='" + answeredAt + '\'' +
", endedAt='" + endedAt + '\'' +
+ ", sipResponseCode='" + sipResponseCode + '\'' +
'}';
}
@@ -97,11 +101,12 @@ public boolean equals(Object o) {
Objects.equals(createdAt, that.createdAt) &&
Objects.equals(updatedAt, that.updatedAt) &&
Objects.equals(answeredAt, that.answeredAt) &&
- Objects.equals(endedAt, that.endedAt);
+ Objects.equals(endedAt, that.endedAt) &&
+ Objects.equals(sipResponseCode, that.sipResponseCode);
}
@Override
public int hashCode() {
- return Objects.hash(id, callID, source, destination, status, direction, cost, currency, duration, createdAt, updatedAt, answeredAt, endedAt);
+ return Objects.hash(id, callID, source, destination, status, direction, cost, currency, duration, createdAt, updatedAt, answeredAt, endedAt, sipResponseCode);
}
}
diff --git a/api/src/test/java/com/messagebird/VoiceCallingTest.java b/api/src/test/java/com/messagebird/VoiceCallingTest.java
index 778f9b1c..cc8ae90e 100644
--- a/api/src/test/java/com/messagebird/VoiceCallingTest.java
+++ b/api/src/test/java/com/messagebird/VoiceCallingTest.java
@@ -3,6 +3,7 @@
import com.messagebird.exceptions.GeneralException;
import com.messagebird.exceptions.NotFoundException;
import com.messagebird.exceptions.UnauthorizedException;
+import com.messagebird.objects.voicecalls.SipResponseCode;
import com.messagebird.objects.voicecalls.VoiceCall;
import com.messagebird.objects.voicecalls.VoiceLegDirection;
import com.messagebird.objects.voicecalls.VoiceLegStatus;
@@ -100,7 +101,7 @@ public void testGetLeg() throws IOException, GeneralException, UnauthorizedExcep
VoiceLegStatus.Hangup, VoiceLegDirection.Outgoing,
new BigDecimal("0.001519"), "EUR", 7,
parseDate("2019-01-10T16:12:54Z"), parseDate("2019-01-10T16:13:54Z"),
- parseDate("2019-01-10T16:13:24Z"), parseDate("2019-01-10T16:13:30Z")
+ parseDate("2019-01-10T16:13:24Z"), parseDate("2019-01-10T16:13:30Z"), SipResponseCode.OK
);
private static Date parseDate(String input) {
diff --git a/api/src/test/resources/fixtures/call_legs_list.json b/api/src/test/resources/fixtures/call_legs_list.json
index 53a20f71..0ea233f6 100644
--- a/api/src/test/resources/fixtures/call_legs_list.json
+++ b/api/src/test/resources/fixtures/call_legs_list.json
@@ -14,6 +14,7 @@
"updatedAt":"2019-01-10T16:13:54Z",
"answeredAt":"2019-01-10T16:13:24Z",
"endedAt":"2019-01-10T16:13:30Z",
+ "sipResponseCode": 200,
"_links":{
"self":"/calls/unforgiven-call/legs/first-leg-of-unforgiven-call"
}
diff --git a/examples/src/main/java/ExampleViewVoiceCallLegs.java b/examples/src/main/java/ExampleViewVoiceCallLegs.java
index 00713686..8429d57c 100644
--- a/examples/src/main/java/ExampleViewVoiceCallLegs.java
+++ b/examples/src/main/java/ExampleViewVoiceCallLegs.java
@@ -34,7 +34,7 @@ public static void main(String[] args) {
messageBirdClient.viewCallLegsByCallId(voiceCall.getId(), null, null);
//Display voice call leg response object
for (VoiceCallLeg callLeg : voiceCallLegResponse.getData()) {
- System.out.printf("\t\t%s -> %s, %s [%s]\n", callLeg.source, callLeg.destination, callLeg.direction, callLeg.status);
+ System.out.printf("\t\t%s -> %s, %s [status: %s sipResponseCode: %s] \n", callLeg.source, callLeg.destination, callLeg.direction, callLeg.status, callLeg.sipResponseCode);
}
}
From 3ade8bed0120bf033f44d6c9fbc6abfe0aba2220 Mon Sep 17 00:00:00 2001
From: Leandro Pinto
Date: Fri, 17 Dec 2021 12:08:27 +0100
Subject: [PATCH 051/216] Adding missing class for SipResponseCode
---
.../objects/voicecalls/SipResponseCode.java | 73 +++++++++++++++++++
.../resources/fixtures/call_legs_get.json | 3 +-
2 files changed, 75 insertions(+), 1 deletion(-)
create mode 100644 api/src/main/java/com/messagebird/objects/voicecalls/SipResponseCode.java
diff --git a/api/src/main/java/com/messagebird/objects/voicecalls/SipResponseCode.java b/api/src/main/java/com/messagebird/objects/voicecalls/SipResponseCode.java
new file mode 100644
index 00000000..7061c8fe
--- /dev/null
+++ b/api/src/main/java/com/messagebird/objects/voicecalls/SipResponseCode.java
@@ -0,0 +1,73 @@
+package com.messagebird.objects.voicecalls;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+
+
+/**
+ * More details, including additional descriptions and common caused can be found here: https://developers.messagebird.com/api/voice-calling/#sip-status-codes
+ * @author leandropinto
+ *
+ */
+public enum SipResponseCode {
+ //Successful
+ OK,
+ //The server understood the request, but is refusing to fulfill it.
+ FORBIDDEN,
+ //The server has definitive information that the user does not exist at the domain specified in the Request-URI.
+ NOT_FOUND,
+ //Couldn't find the user in time.
+ REQUEST_TIMEOUT,
+ //The user existed once, but is not available here any more.
+ GONE,
+ //Callee currently unavailable.
+ TEMPORARILY_UNAVAILABLE,
+ //Request-URI incomplete.
+ ADDRESS_INCOMPLETE,
+ //Callee is busy.
+ BUSY_HERE,
+ //Some aspect of the session description or the Request-URI is not acceptable.
+ NOT_ACCEPTABLE_HERE,
+ //The server could not fulfill the request due to some unexpected condition.
+ INTERNAL_SERVER_ERROR,
+ //The server does not have the ability to fulfill the request, such as because it does not recognize the request method.
+ NOT_IMPLEMENTED,
+ //The server is acting as a gateway or proxy, and received an invalid response from a downstream server while attempting to fulfill the request.
+ BAD_GATEWAY,
+ //The server is undergoing maintenance or is temporarily overloaded and so cannot process the request.
+ SERVICE_UNAVAILABLE;
+
+ @JsonCreator
+ public static SipResponseCode forValue(Integer value) {
+ switch (value) {
+ case 200:
+ return OK;
+ case 403:
+ return FORBIDDEN;
+ case 404:
+ return NOT_FOUND;
+ case 408:
+ return REQUEST_TIMEOUT;
+ case 410:
+ return GONE;
+ case 480:
+ return TEMPORARILY_UNAVAILABLE;
+ case 484:
+ return ADDRESS_INCOMPLETE;
+ case 486:
+ return BUSY_HERE;
+ case 488:
+ return NOT_ACCEPTABLE_HERE;
+ case 500:
+ return INTERNAL_SERVER_ERROR;
+ case 501:
+ return NOT_IMPLEMENTED;
+ case 502:
+ return BAD_GATEWAY;
+ case 503:
+ return SERVICE_UNAVAILABLE;
+
+ default:
+ throw new IllegalArgumentException("Unknown sip response code: " + value);
+ }
+ }
+}
\ No newline at end of file
diff --git a/api/src/test/resources/fixtures/call_legs_get.json b/api/src/test/resources/fixtures/call_legs_get.json
index 64d5f65b..23670a0a 100644
--- a/api/src/test/resources/fixtures/call_legs_get.json
+++ b/api/src/test/resources/fixtures/call_legs_get.json
@@ -13,7 +13,8 @@
"createdAt": "2019-01-10T16:12:54Z",
"updatedAt": "2019-01-10T16:13:54Z",
"answeredAt": "2019-01-10T16:13:24Z",
- "endedAt": "2019-01-10T16:13:30Z"
+ "endedAt": "2019-01-10T16:13:30Z",
+ "sipResponseCode": 200
}
],
"_links": {
From 9f9842f45b6b83d66a1232312af8de87c94d03c3 Mon Sep 17 00:00:00 2001
From: "deniz@messagebird.com"
Date: Sat, 18 Dec 2021 12:33:56 +0100
Subject: [PATCH 052/216] new version update
---
api/pom.xml | 2 +-
api/src/main/java/com/messagebird/MessageBirdServiceImpl.java | 2 +-
examples/pom.xml | 4 ++--
3 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/api/pom.xml b/api/pom.xml
index f7a7fb61..cbf8a706 100644
--- a/api/pom.xml
+++ b/api/pom.xml
@@ -4,7 +4,7 @@
com.messagebirdmessagebird-api
- 3.1.7
diff --git a/api/src/main/java/com/messagebird/MessageBirdServiceImpl.java b/api/src/main/java/com/messagebird/MessageBirdServiceImpl.java
index 69e6f220..7acc804c 100644
--- a/api/src/main/java/com/messagebird/MessageBirdServiceImpl.java
+++ b/api/src/main/java/com/messagebird/MessageBirdServiceImpl.java
@@ -74,7 +74,7 @@ public class MessageBirdServiceImpl implements MessageBirdService {
private final String accessKey;
private final String serviceUrl;
- private final String clientVersion = "3.1.7";
+ private final String clientVersion = "3.1.10";
private final String userAgentString;
private Proxy proxy = null;
diff --git a/examples/pom.xml b/examples/pom.xml
index 3353a261..546c0c25 100644
--- a/examples/pom.xml
+++ b/examples/pom.xml
@@ -6,7 +6,7 @@
com.messagebirdexamples
- 3.1.7
+ 3.1.10
@@ -20,7 +20,7 @@
com.messagebirdmessagebird-api
- 3.1.7
+ 3.1.10compile
From 0a7ae99f38a1f9263dfc1b13313dee20fff8a36f Mon Sep 17 00:00:00 2001
From: denizkilic
Date: Tue, 28 Dec 2021 15:52:08 +0100
Subject: [PATCH 053/216] typo fix in enum type
---
.../messagebird/objects/conversations/MessageComponentType.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/api/src/main/java/com/messagebird/objects/conversations/MessageComponentType.java b/api/src/main/java/com/messagebird/objects/conversations/MessageComponentType.java
index 073b5735..842f49f1 100644
--- a/api/src/main/java/com/messagebird/objects/conversations/MessageComponentType.java
+++ b/api/src/main/java/com/messagebird/objects/conversations/MessageComponentType.java
@@ -8,7 +8,7 @@ public enum MessageComponentType {
HEADER("header"),
BODY("body"),
FOOTER("footer"),
- BUTTONS("buttons");
+ BUTTONS("button");
private final String type;
From 2b557e450f3456cf4274ee4d269695e061c30231 Mon Sep 17 00:00:00 2001
From: denizkilic
Date: Tue, 28 Dec 2021 16:08:23 +0100
Subject: [PATCH 054/216] updated enum name and value
---
.../messagebird/objects/conversations/MessageComponentType.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/api/src/main/java/com/messagebird/objects/conversations/MessageComponentType.java b/api/src/main/java/com/messagebird/objects/conversations/MessageComponentType.java
index 842f49f1..327525fd 100644
--- a/api/src/main/java/com/messagebird/objects/conversations/MessageComponentType.java
+++ b/api/src/main/java/com/messagebird/objects/conversations/MessageComponentType.java
@@ -8,7 +8,7 @@ public enum MessageComponentType {
HEADER("header"),
BODY("body"),
FOOTER("footer"),
- BUTTONS("button");
+ BUTTON("button");
private final String type;
From 7649823d134d91e8b2967d7b5bc4c7558549c40a Mon Sep 17 00:00:00 2001
From: denizkilic
Date: Mon, 3 Jan 2022 13:24:25 +0100
Subject: [PATCH 055/216] new release
---
api/pom.xml | 2 +-
api/src/main/java/com/messagebird/MessageBirdServiceImpl.java | 2 +-
examples/pom.xml | 4 ++--
3 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/api/pom.xml b/api/pom.xml
index cbf8a706..b70108b6 100644
--- a/api/pom.xml
+++ b/api/pom.xml
@@ -4,7 +4,7 @@
com.messagebirdmessagebird-api
- 3.1.10
diff --git a/api/src/main/java/com/messagebird/MessageBirdServiceImpl.java b/api/src/main/java/com/messagebird/MessageBirdServiceImpl.java
index 7acc804c..65c7cda8 100644
--- a/api/src/main/java/com/messagebird/MessageBirdServiceImpl.java
+++ b/api/src/main/java/com/messagebird/MessageBirdServiceImpl.java
@@ -74,7 +74,7 @@ public class MessageBirdServiceImpl implements MessageBirdService {
private final String accessKey;
private final String serviceUrl;
- private final String clientVersion = "3.1.10";
+ private final String clientVersion = "3.2.0";
private final String userAgentString;
private Proxy proxy = null;
diff --git a/examples/pom.xml b/examples/pom.xml
index 546c0c25..bee96a05 100644
--- a/examples/pom.xml
+++ b/examples/pom.xml
@@ -6,7 +6,7 @@
com.messagebirdexamples
- 3.1.10
+ 3.2.0
@@ -20,7 +20,7 @@
com.messagebirdmessagebird-api
- 3.1.10
+ 3.2.0compile
From 71e230f0a52a54f9ea46811f5c641187ab038453 Mon Sep 17 00:00:00 2001
From: denizkilic
Date: Mon, 3 Jan 2022 13:26:05 +0100
Subject: [PATCH 056/216] [maven-release-plugin] prepare release v3.2.0
---
api/pom.xml | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/api/pom.xml b/api/pom.xml
index b70108b6..abffb03a 100644
--- a/api/pom.xml
+++ b/api/pom.xml
@@ -4,7 +4,7 @@
com.messagebirdmessagebird-api
- 3.2.0-SNAPSHOT
@@ -42,7 +42,7 @@
scm:git:git@github.com:messagebird/java-rest-api.gitscm:git:git@github.com:messagebird/java-rest-api.gitgit@github.com:messagebird/java-rest-api.git
- HEAD
+ v3.2.0
From 7389148fe692020127b02d11a9ec71be349d8d23 Mon Sep 17 00:00:00 2001
From: denizkilic
Date: Mon, 3 Jan 2022 13:26:09 +0100
Subject: [PATCH 057/216] [maven-release-plugin] prepare for next development
iteration
---
api/pom.xml | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/api/pom.xml b/api/pom.xml
index abffb03a..da6230ea 100644
--- a/api/pom.xml
+++ b/api/pom.xml
@@ -4,7 +4,7 @@
com.messagebirdmessagebird-api
- 3.2.0
@@ -42,7 +42,7 @@
scm:git:git@github.com:messagebird/java-rest-api.gitscm:git:git@github.com:messagebird/java-rest-api.gitgit@github.com:messagebird/java-rest-api.git
- v3.2.0
+ HEAD
From e9b47c7d603321b6a8f13f81a7c227c80871aeef Mon Sep 17 00:00:00 2001
From: denizkilic
Date: Mon, 3 Jan 2022 17:38:42 +0100
Subject: [PATCH 058/216] updated version
---
api/pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/api/pom.xml b/api/pom.xml
index da6230ea..04fc1a99 100644
--- a/api/pom.xml
+++ b/api/pom.xml
@@ -4,7 +4,7 @@
com.messagebirdmessagebird-api
- 3.2.1-SNAPSHOT
From e5767a7683f9428ea20e6ec104a38c9d5375c04f Mon Sep 17 00:00:00 2001
From: cemturker
Date: Fri, 14 Jan 2022 12:45:40 +0100
Subject: [PATCH 059/216] Use string instead of HSMRejectedReason enum
---
.../integrations/HSMRejectedReason.java | 51 -------------------
.../integrations/TemplateResponse.java | 6 +--
2 files changed, 3 insertions(+), 54 deletions(-)
delete mode 100644 api/src/main/java/com/messagebird/objects/integrations/HSMRejectedReason.java
diff --git a/api/src/main/java/com/messagebird/objects/integrations/HSMRejectedReason.java b/api/src/main/java/com/messagebird/objects/integrations/HSMRejectedReason.java
deleted file mode 100644
index 55937ef4..00000000
--- a/api/src/main/java/com/messagebird/objects/integrations/HSMRejectedReason.java
+++ /dev/null
@@ -1,51 +0,0 @@
-package com.messagebird.objects.integrations;
-
-import com.fasterxml.jackson.annotation.JsonCreator;
-import com.fasterxml.jackson.annotation.JsonValue;
-
-/**
- * An enum class for HSMRejectedReason
- *
- * @see HSMRejectedReason object
- * @author ssk910
- */
-public enum HSMRejectedReason {
-
- ABUSIVE_CONTENT("ABUSIVE_CONTENT"),
- INVALID_FORMAT("INVALID_FORMAT"),
- NONE("NONE"),
- PROMOTIONAL("PROMOTIONAL"),
- TAG_CONTENT_MISMATCH("TAG_CONTENT_MISMATCH"),
- NON_TRANSIENT_ERROR("NON_TRANSIENT_ERROR");
-
- private final String rejectedReason;
-
- HSMRejectedReason(String rejectedReason) {
- this.rejectedReason = rejectedReason;
- }
-
- @JsonCreator
- public static HSMRejectedReason forValue(String value) {
- for (HSMRejectedReason hsmRejectedReason : HSMRejectedReason.values()) {
- if (hsmRejectedReason.getRejectedReason().equals(value)) {
- return hsmRejectedReason;
- }
- }
-
- return null;
- }
-
- @JsonValue
- public String toJson() {
- return getRejectedReason();
- }
-
- public String getRejectedReason() {
- return rejectedReason;
- }
-
- @Override
- public String toString() {
- return getRejectedReason();
- }
-}
diff --git a/api/src/main/java/com/messagebird/objects/integrations/TemplateResponse.java b/api/src/main/java/com/messagebird/objects/integrations/TemplateResponse.java
index ac34efd0..bce35f82 100644
--- a/api/src/main/java/com/messagebird/objects/integrations/TemplateResponse.java
+++ b/api/src/main/java/com/messagebird/objects/integrations/TemplateResponse.java
@@ -17,7 +17,7 @@ public class TemplateResponse implements Serializable {
private HSMCategory category;
private List components;
private HSMStatus status;
- private HSMRejectedReason rejectedReason;
+ private String rejectedReason;
private Date createdAt;
private Date updatedAt;
@@ -65,11 +65,11 @@ public void setStatus(HSMStatus status) {
this.status = status;
}
- public HSMRejectedReason getRejectedReason() {
+ public String getRejectedReason() {
return rejectedReason;
}
- public void setRejectedReason(HSMRejectedReason rejectedReason) {
+ public void setRejectedReason(String rejectedReason) {
this.rejectedReason = rejectedReason;
}
From 16fa1303c2309be61d98dc29b906ed142badd9bb Mon Sep 17 00:00:00 2001
From: denizkilic
Date: Wed, 19 Jan 2022 11:04:48 +0100
Subject: [PATCH 060/216] creating a new release
---
api/pom.xml | 2 +-
api/src/main/java/com/messagebird/MessageBirdServiceImpl.java | 2 +-
examples/pom.xml | 4 ++--
3 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/api/pom.xml b/api/pom.xml
index 04fc1a99..da6230ea 100644
--- a/api/pom.xml
+++ b/api/pom.xml
@@ -4,7 +4,7 @@
com.messagebirdmessagebird-api
- 3.2.0
diff --git a/api/src/main/java/com/messagebird/MessageBirdServiceImpl.java b/api/src/main/java/com/messagebird/MessageBirdServiceImpl.java
index 65c7cda8..211ef6ad 100644
--- a/api/src/main/java/com/messagebird/MessageBirdServiceImpl.java
+++ b/api/src/main/java/com/messagebird/MessageBirdServiceImpl.java
@@ -74,7 +74,7 @@ public class MessageBirdServiceImpl implements MessageBirdService {
private final String accessKey;
private final String serviceUrl;
- private final String clientVersion = "3.2.0";
+ private final String clientVersion = "3.2.1";
private final String userAgentString;
private Proxy proxy = null;
diff --git a/examples/pom.xml b/examples/pom.xml
index bee96a05..9ba1af9d 100644
--- a/examples/pom.xml
+++ b/examples/pom.xml
@@ -6,7 +6,7 @@
com.messagebirdexamples
- 3.2.0
+ 3.2.1
@@ -20,7 +20,7 @@
com.messagebirdmessagebird-api
- 3.2.0
+ 3.2.1compile
From f27ed5c7bded0beb71ce0b1b65c6c880878c6a9e Mon Sep 17 00:00:00 2001
From: denizkilic
Date: Wed, 19 Jan 2022 11:06:02 +0100
Subject: [PATCH 061/216] [maven-release-plugin] prepare release v3.2.1
---
api/pom.xml | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/api/pom.xml b/api/pom.xml
index da6230ea..33da8e48 100644
--- a/api/pom.xml
+++ b/api/pom.xml
@@ -4,7 +4,7 @@
com.messagebirdmessagebird-api
- 3.2.1-SNAPSHOT
@@ -42,7 +42,7 @@
scm:git:git@github.com:messagebird/java-rest-api.gitscm:git:git@github.com:messagebird/java-rest-api.gitgit@github.com:messagebird/java-rest-api.git
- HEAD
+ v3.2.1
From 75fb03b3de7206157f599d4956d6273be5fe4531 Mon Sep 17 00:00:00 2001
From: denizkilic
Date: Wed, 19 Jan 2022 11:06:07 +0100
Subject: [PATCH 062/216] [maven-release-plugin] prepare for next development
iteration
---
api/pom.xml | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/api/pom.xml b/api/pom.xml
index 33da8e48..123a333a 100644
--- a/api/pom.xml
+++ b/api/pom.xml
@@ -4,7 +4,7 @@
com.messagebirdmessagebird-api
- 3.2.1
@@ -42,7 +42,7 @@
scm:git:git@github.com:messagebird/java-rest-api.gitscm:git:git@github.com:messagebird/java-rest-api.gitgit@github.com:messagebird/java-rest-api.git
- v3.2.1
+ HEAD
From 5890056f7114cc2ddce39294c79f753fc5e2de61 Mon Sep 17 00:00:00 2001
From: denizkilic
Date: Wed, 19 Jan 2022 17:29:43 +0100
Subject: [PATCH 063/216] new release
---
api/pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/api/pom.xml b/api/pom.xml
index 123a333a..d585c62c 100644
--- a/api/pom.xml
+++ b/api/pom.xml
@@ -4,7 +4,7 @@
com.messagebirdmessagebird-api
- 3.2.2-SNAPSHOT
From 80e5732d694b3857e76038bb28b4e7431aded0e6 Mon Sep 17 00:00:00 2001
From: Ryan Rupp <3022260+ryanrupp@users.noreply.github.com>
Date: Wed, 16 Mar 2022 12:59:13 -0500
Subject: [PATCH 064/216] Make JetBrains annotations "provided" to avoid
runtime transitive dependency
These are annotations used for static analysis at development time only and not needed at runtime
---
api/pom.xml | 1 +
1 file changed, 1 insertion(+)
diff --git a/api/pom.xml b/api/pom.xml
index d585c62c..1093e786 100644
--- a/api/pom.xml
+++ b/api/pom.xml
@@ -117,6 +117,7 @@
org.jetbrainsannotations13.0
+ provided
From 7de8e9e4ef2ef332c5bbfdd004749103ae3a656f Mon Sep 17 00:00:00 2001
From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com>
Date: Mon, 4 Apr 2022 13:57:09 +0000
Subject: [PATCH 065/216] Bump jackson-databind from 2.11.0 to 2.12.6.1 in /api
Bumps [jackson-databind](https://github.com/FasterXML/jackson) from 2.11.0 to 2.12.6.1.
- [Release notes](https://github.com/FasterXML/jackson/releases)
- [Commits](https://github.com/FasterXML/jackson/commits)
---
updated-dependencies:
- dependency-name: com.fasterxml.jackson.core:jackson-databind
dependency-type: direct:production
...
Signed-off-by: dependabot[bot]
---
api/pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/api/pom.xml b/api/pom.xml
index 1093e786..932b50e7 100644
--- a/api/pom.xml
+++ b/api/pom.xml
@@ -88,7 +88,7 @@
com.fasterxml.jackson.corejackson-databind
- 2.11.0
+ 2.12.6.1com.auth0
From 18e150c3d9fcecb8152cb4494a4b9e9b0315b9f3 Mon Sep 17 00:00:00 2001
From: denizkilic
Date: Mon, 4 Apr 2022 16:38:58 +0200
Subject: [PATCH 066/216] lastest versions of jackson libs
---
api/pom.xml | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/api/pom.xml b/api/pom.xml
index 932b50e7..62d4997b 100644
--- a/api/pom.xml
+++ b/api/pom.xml
@@ -83,12 +83,12 @@
com.fasterxml.jackson.corejackson-annotations
- 2.11.0
+ 2.13.2com.fasterxml.jackson.corejackson-databind
- 2.12.6.1
+ 2.13.2.2com.auth0
@@ -117,7 +117,7 @@
org.jetbrainsannotations13.0
- provided
+
From 043ec405363f4b3448daf5eee9e578b13bb2cb28 Mon Sep 17 00:00:00 2001
From: denizkilic
Date: Mon, 4 Apr 2022 16:45:48 +0200
Subject: [PATCH 067/216] fixed pom file
---
api/pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/api/pom.xml b/api/pom.xml
index 62d4997b..e2ca079b 100644
--- a/api/pom.xml
+++ b/api/pom.xml
@@ -117,7 +117,7 @@
org.jetbrainsannotations13.0
-
+ provided
From 2f4783c9e4b3181787cccf7eb37899c047c5d16c Mon Sep 17 00:00:00 2001
From: denizkilic
Date: Mon, 4 Apr 2022 16:51:37 +0200
Subject: [PATCH 068/216] new release
---
api/pom.xml | 2 +-
api/src/main/java/com/messagebird/MessageBirdServiceImpl.java | 2 +-
examples/pom.xml | 4 ++--
3 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/api/pom.xml b/api/pom.xml
index e2ca079b..1e2d5a67 100644
--- a/api/pom.xml
+++ b/api/pom.xml
@@ -4,7 +4,7 @@
com.messagebirdmessagebird-api
- 3.2.1
diff --git a/api/src/main/java/com/messagebird/MessageBirdServiceImpl.java b/api/src/main/java/com/messagebird/MessageBirdServiceImpl.java
index 211ef6ad..892db5c6 100644
--- a/api/src/main/java/com/messagebird/MessageBirdServiceImpl.java
+++ b/api/src/main/java/com/messagebird/MessageBirdServiceImpl.java
@@ -74,7 +74,7 @@ public class MessageBirdServiceImpl implements MessageBirdService {
private final String accessKey;
private final String serviceUrl;
- private final String clientVersion = "3.2.1";
+ private final String clientVersion = "3.2.2";
private final String userAgentString;
private Proxy proxy = null;
diff --git a/examples/pom.xml b/examples/pom.xml
index 9ba1af9d..c94c0398 100644
--- a/examples/pom.xml
+++ b/examples/pom.xml
@@ -6,7 +6,7 @@
com.messagebirdexamples
- 3.2.1
+ 3.2.2
@@ -20,7 +20,7 @@
com.messagebirdmessagebird-api
- 3.2.1
+ 3.2.2compile
From 1aa500acb4b4302834ab9fa9057d92357f97df7f Mon Sep 17 00:00:00 2001
From: denizkilic
Date: Mon, 4 Apr 2022 16:53:27 +0200
Subject: [PATCH 069/216] [maven-release-plugin] prepare release v3.2.2
---
api/pom.xml | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/api/pom.xml b/api/pom.xml
index 1e2d5a67..bfd7e70e 100644
--- a/api/pom.xml
+++ b/api/pom.xml
@@ -4,7 +4,7 @@
com.messagebirdmessagebird-api
- 3.2.2-SNAPSHOT
@@ -42,7 +42,7 @@
scm:git:git@github.com:messagebird/java-rest-api.gitscm:git:git@github.com:messagebird/java-rest-api.gitgit@github.com:messagebird/java-rest-api.git
- HEAD
+ v3.2.2
From a12c952f4c95d6d80591a7d123dadac8f667940d Mon Sep 17 00:00:00 2001
From: denizkilic
Date: Mon, 4 Apr 2022 16:53:31 +0200
Subject: [PATCH 070/216] [maven-release-plugin] prepare for next development
iteration
---
api/pom.xml | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/api/pom.xml b/api/pom.xml
index bfd7e70e..9b63ea2d 100644
--- a/api/pom.xml
+++ b/api/pom.xml
@@ -4,7 +4,7 @@
com.messagebirdmessagebird-api
- 3.2.2
@@ -42,7 +42,7 @@
scm:git:git@github.com:messagebird/java-rest-api.gitscm:git:git@github.com:messagebird/java-rest-api.gitgit@github.com:messagebird/java-rest-api.git
- v3.2.2
+ HEAD
From 97fc992421c7363bb93052bc2301531ddc75c192 Mon Sep 17 00:00:00 2001
From: denizkilic