diff --git a/.github/workflows/maven-ci.yml b/.github/workflows/maven-ci.yml index 3aae14feb..3e30a4cf8 100644 --- a/.github/workflows/maven-ci.yml +++ b/.github/workflows/maven-ci.yml @@ -17,7 +17,7 @@ jobs: steps: - uses: actions/checkout@v4 - name: Set up JDK 17 - uses: actions/setup-java@v4 + uses: actions/setup-java@v3 with: java-version: '17' distribution: 'temurin' @@ -26,4 +26,6 @@ jobs: run: mvn -B package --file pom.xml #coverage - name: Upload coverage reports to Codecov - uses: codecov/codecov-action@v3 + uses: codecov/codecov-action@v4 + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} diff --git a/.gitignore b/.gitignore index c8df4d858..4ff631591 100644 --- a/.gitignore +++ b/.gitignore @@ -25,6 +25,5 @@ hs_err_pid* /.idea/ /target/ /src/test/java/com/whatsapp/api/TestConstants.java -/src/test/java/com/whatsapp/api/TestConstants.java /htmlReport /machinet.conf diff --git a/pom.xml b/pom.xml index 2aa7c8647..d4d3a8288 100644 --- a/pom.xml +++ b/pom.xml @@ -31,9 +31,9 @@ 17 UTF-8 - 2.9.0 - 5.2.0 - 5.10.1 + 2.11.0 + 5.11.0 + 5.10.2 5.0.0-alpha.12 @@ -81,12 +81,6 @@ ${org.mockito.version} test - - org.mockito - mockito-inline - ${org.mockito.version} - test - com.squareup.okhttp3 mockwebserver3 @@ -117,7 +111,7 @@ org.apache.maven.plugins maven-compiler-plugin - 3.12.1 + 3.13.0 17 17 @@ -142,7 +136,7 @@ org.jacoco jacoco-maven-plugin - 0.8.11 + 0.8.12 diff --git a/src/main/java/com/whatsapp/api/WhatsappApiFactory.java b/src/main/java/com/whatsapp/api/WhatsappApiFactory.java index 16474b8ac..5853e8386 100644 --- a/src/main/java/com/whatsapp/api/WhatsappApiFactory.java +++ b/src/main/java/com/whatsapp/api/WhatsappApiFactory.java @@ -1,6 +1,7 @@ package com.whatsapp.api; +import com.whatsapp.api.configuration.ApiVersion; import com.whatsapp.api.impl.WhatsappBusinessCloudApi; import com.whatsapp.api.impl.WhatsappBusinessManagementApi; @@ -44,6 +45,16 @@ public WhatsappBusinessCloudApi newBusinessCloudApi() { return new WhatsappBusinessCloudApi(token); } + /** + * Creates a new synchronous/blocking Whatsapp business cloud api client, especifying the api version + * + * @return the whatsapp business cloud api + */ + public WhatsappBusinessCloudApi newBusinessCloudApi(ApiVersion apiVersion) { + + return new WhatsappBusinessCloudApi(token, apiVersion); + } + /** * Creates a new synchronous/blocking Whatsapp business management api client * diff --git a/src/main/java/com/whatsapp/api/WhatsappApiServiceGenerator.java b/src/main/java/com/whatsapp/api/WhatsappApiServiceGenerator.java index 606688e9d..aea47236d 100644 --- a/src/main/java/com/whatsapp/api/WhatsappApiServiceGenerator.java +++ b/src/main/java/com/whatsapp/api/WhatsappApiServiceGenerator.java @@ -1,17 +1,15 @@ package com.whatsapp.api; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; import com.whatsapp.api.configuration.WhatsappApiConfig; import com.whatsapp.api.domain.errors.Error; import com.whatsapp.api.domain.errors.WhatsappApiError; import com.whatsapp.api.domain.media.MediaFile; import com.whatsapp.api.exception.WhatsappApiException; import com.whatsapp.api.interceptor.AuthenticationInterceptor; -import com.whatsapp.api.utils.proxy.CustomProxyAuthenticator; import com.whatsapp.api.utils.proxy.CustomHttpProxySelector; - -import com.fasterxml.jackson.databind.DeserializationFeature; -import com.fasterxml.jackson.databind.ObjectMapper; - +import com.whatsapp.api.utils.proxy.CustomProxyAuthenticator; import okhttp3.OkHttpClient; import okhttp3.ResponseBody; import retrofit2.Call; @@ -50,7 +48,7 @@ private WhatsappApiServiceGenerator() { sharedClient = createDefaultHttpClient(); } - public static OkHttpClient createDefaultHttpClient(){ + public static OkHttpClient createDefaultHttpClient() { return new OkHttpClient.Builder()// .callTimeout(20, TimeUnit.SECONDS)// .pingInterval(20, TimeUnit.SECONDS)// @@ -70,8 +68,9 @@ public static OkHttpClient createDefaultHttpClient(){ * you can pass {@code null} as parameters for {@code username} and {@code pwd}. * *

+ * * @param host the host (Not null) - * @param port the port + * @param port the port * @param username the username * @param pwd the pwd * @see Proxy Selector @@ -108,14 +107,18 @@ public static void setHttpProxy(String host, int port, String username, String p * @return the s */ public static S createService(Class serviceClass, String token, String baseUrl) { - Retrofit.Builder retrofitBuilder = new Retrofit.Builder().baseUrl(baseUrl).addConverterFactory(converterFactory); + Retrofit.Builder retrofitBuilder = new Retrofit.Builder() + .baseUrl(baseUrl) + .addConverterFactory(converterFactory); if (token == null) { retrofitBuilder.client(sharedClient); } else { AuthenticationInterceptor interceptor = new AuthenticationInterceptor(token); - OkHttpClient adaptedClient = sharedClient.newBuilder().addInterceptor(interceptor).build(); + OkHttpClient adaptedClient = sharedClient.newBuilder() + .addInterceptor(interceptor) + .build(); retrofitBuilder.client(adaptedClient); } @@ -133,7 +136,7 @@ public static S createService(Class serviceClass, String token, String ba */ public static S createService(Class serviceClass, String token) { - var baseUrl = WhatsappApiConfig.BASE_DOMAIN; + var baseUrl = WhatsappApiConfig.getBaseDomain(); return createService(serviceClass, token, baseUrl); } diff --git a/src/main/java/com/whatsapp/api/configuration/ApiVersion.java b/src/main/java/com/whatsapp/api/configuration/ApiVersion.java new file mode 100644 index 000000000..509c3c7bc --- /dev/null +++ b/src/main/java/com/whatsapp/api/configuration/ApiVersion.java @@ -0,0 +1,22 @@ +package com.whatsapp.api.configuration; + +public enum ApiVersion { + + @Deprecated() + V16_0("v16.0"), + V17_0("v17.0"), + V18_0("v18.0"), + V19_0("v19.0"); + + + + private final String value; + + ApiVersion(String value) { + this.value = value; + } + + public String getValue() { + return value; + } +} diff --git a/src/main/java/com/whatsapp/api/configuration/WhatsappApiConfig.java b/src/main/java/com/whatsapp/api/configuration/WhatsappApiConfig.java index 22dfd4497..eaf447265 100644 --- a/src/main/java/com/whatsapp/api/configuration/WhatsappApiConfig.java +++ b/src/main/java/com/whatsapp/api/configuration/WhatsappApiConfig.java @@ -5,14 +5,18 @@ */ public class WhatsappApiConfig { + + private WhatsappApiConfig() { + } + /** * The constant API_VERSION. */ - public final static String API_VERSION = "v16.0"; + private static ApiVersion apiVersion = ApiVersion.V19_0; /** * The constant BASE_DOMAIN. */ - public static String BASE_DOMAIN = "https://graph.facebook.com/"; + private static String baseDomain = "https://graph.facebook.com/"; /** * Sets base domain. @@ -20,7 +24,34 @@ public class WhatsappApiConfig { * @param baseDomain the base domain */ public static void setBaseDomain(String baseDomain) { - BASE_DOMAIN = baseDomain; + WhatsappApiConfig.baseDomain = baseDomain; + } + + /** + * Sets api version. + * + * @param apiVersion the api version enum + */ + public static void setApiVersion(ApiVersion apiVersion) { + WhatsappApiConfig.apiVersion = apiVersion; + } + + /** + * Gets api version + * + * @return apiVersion + */ + public static ApiVersion getApiVersion() { + return apiVersion; + } + + /** + * Gets api version + * + * @return apiVersion + */ + public static String getBaseDomain() { + return baseDomain; } diff --git a/src/main/java/com/whatsapp/api/domain/config/CommerceDataItem.java b/src/main/java/com/whatsapp/api/domain/config/CommerceDataItem.java index 553cd263f..aa30ddcb5 100644 --- a/src/main/java/com/whatsapp/api/domain/config/CommerceDataItem.java +++ b/src/main/java/com/whatsapp/api/domain/config/CommerceDataItem.java @@ -2,6 +2,7 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; /** * The type Commerce data item. diff --git a/src/main/java/com/whatsapp/api/impl/WhatsappBusinessCloudApi.java b/src/main/java/com/whatsapp/api/impl/WhatsappBusinessCloudApi.java index 010e757bc..5a1bbe9ff 100644 --- a/src/main/java/com/whatsapp/api/impl/WhatsappBusinessCloudApi.java +++ b/src/main/java/com/whatsapp/api/impl/WhatsappBusinessCloudApi.java @@ -1,5 +1,6 @@ package com.whatsapp.api.impl; +import com.whatsapp.api.configuration.ApiVersion; import com.whatsapp.api.domain.media.FileType; import com.whatsapp.api.domain.media.Media; import com.whatsapp.api.domain.media.MediaFile; @@ -14,9 +15,8 @@ import okhttp3.MultipartBody; import okhttp3.MultipartBody.Part; -import static com.whatsapp.api.WhatsappApiServiceGenerator.createService; -import static com.whatsapp.api.WhatsappApiServiceGenerator.executeDownloadSync; -import static com.whatsapp.api.WhatsappApiServiceGenerator.executeSync; +import static com.whatsapp.api.WhatsappApiServiceGenerator.*; +import static com.whatsapp.api.configuration.WhatsappApiConfig.getApiVersion; /** * Implementation of WhatsApp Business Platform Cloud API with synchronous/blocking @@ -28,12 +28,28 @@ public class WhatsappBusinessCloudApi { private final WhatsappBusinessCloudApiService whatsappBusinessCloudApiService; + private final ApiVersion apiVersion; + /** * Instantiates a new Whatsapp business cloud api. * * @param token the token */ public WhatsappBusinessCloudApi(String token) { + this.apiVersion = getApiVersion(); + this.whatsappBusinessCloudApiService = createService(WhatsappBusinessCloudApiService.class, token); + + } + + + /** + * Instantiates a new Whatsapp business cloud api, specifying API version + * + * @param token the token + * @param apiVersion api version + */ + public WhatsappBusinessCloudApi(String token, ApiVersion apiVersion) { + this.apiVersion = apiVersion; this.whatsappBusinessCloudApiService = createService(WhatsappBusinessCloudApiService.class, token); } @@ -49,7 +65,7 @@ public WhatsappBusinessCloudApi(String token) { */ public MessageResponse sendMessage(String phoneNumberId, Message message) { - return executeSync(whatsappBusinessCloudApiService.sendMessage(phoneNumberId, message)); + return executeSync(whatsappBusinessCloudApiService.sendMessage(apiVersion.getValue(), phoneNumberId, message)); } /** @@ -73,7 +89,7 @@ public UploadResponse uploadMedia(String phoneNumberId, String fileName, FileTyp var messageProduct = Part.createFormData("messaging_product", "whatsapp"); - return executeSync(whatsappBusinessCloudApiService.uploadMedia(phoneNumberId, body, messageProduct)); + return executeSync(whatsappBusinessCloudApiService.uploadMedia(apiVersion.getValue(), phoneNumberId, body, messageProduct)); } /** @@ -84,7 +100,7 @@ public UploadResponse uploadMedia(String phoneNumberId, String fileName, FileTyp * @see official documentation */ public Media retrieveMediaUrl(String mediaId) { - return executeSync(whatsappBusinessCloudApiService.retrieveMediaUrl(mediaId)); + return executeSync(whatsappBusinessCloudApiService.retrieveMediaUrl(apiVersion.getValue(), mediaId)); } @@ -110,7 +126,7 @@ public MediaFile downloadMediaFile(String url) { */ public Response deleteMedia(String mediaId) { - return executeSync(whatsappBusinessCloudApiService.deleteMedia(mediaId)); + return executeSync(whatsappBusinessCloudApiService.deleteMedia(apiVersion.getValue(), mediaId)); } /** @@ -122,7 +138,7 @@ public Response deleteMedia(String mediaId) { * @see official documentation */ public Response markMessageAsRead(String phoneNumberId, ReadMessage message) { - return executeSync(whatsappBusinessCloudApiService.markMessageAsRead(phoneNumberId, message)); + return executeSync(whatsappBusinessCloudApiService.markMessageAsRead(apiVersion.getValue(), phoneNumberId, message)); } /** @@ -135,7 +151,7 @@ public Response markMessageAsRead(String phoneNumberId, ReadMessage message) { * @see official documentation */ public Response twoStepVerification(String phoneNumberId, TwoStepCode twoStepCode) { - return executeSync(whatsappBusinessCloudApiService.twoStepVerification(phoneNumberId, twoStepCode)); + return executeSync(whatsappBusinessCloudApiService.twoStepVerification(apiVersion.getValue(), phoneNumberId, twoStepCode)); } } diff --git a/src/main/java/com/whatsapp/api/impl/WhatsappBusinessManagementApi.java b/src/main/java/com/whatsapp/api/impl/WhatsappBusinessManagementApi.java index 411ac6c3f..620c3cd97 100644 --- a/src/main/java/com/whatsapp/api/impl/WhatsappBusinessManagementApi.java +++ b/src/main/java/com/whatsapp/api/impl/WhatsappBusinessManagementApi.java @@ -1,5 +1,6 @@ package com.whatsapp.api.impl; +import com.whatsapp.api.configuration.ApiVersion; import com.whatsapp.api.domain.config.CommerceDataItem; import com.whatsapp.api.domain.config.GraphCommerceSettings; import com.whatsapp.api.domain.phone.PhoneNumber; @@ -18,12 +19,15 @@ import static com.whatsapp.api.WhatsappApiServiceGenerator.createService; import static com.whatsapp.api.WhatsappApiServiceGenerator.executeSync; +import static com.whatsapp.api.configuration.WhatsappApiConfig.getApiVersion; /** * The type Whatsapp business management api. */ public class WhatsappBusinessManagementApi { + private final ApiVersion apiVersion; + private final WhatsappBusinessManagementApiService whatsappBusinessManagementApiService; /** @@ -32,6 +36,18 @@ public class WhatsappBusinessManagementApi { * @param token the token */ public WhatsappBusinessManagementApi(String token) { + this.apiVersion = getApiVersion(); + this.whatsappBusinessManagementApiService = createService(WhatsappBusinessManagementApiService.class, token); + } + + /** + * Instantiates a new Whatsapp business management api, specifying api version + * + * @param token the token + * @param apiVersion api version + */ + public WhatsappBusinessManagementApi(String token, ApiVersion apiVersion) { + this.apiVersion = apiVersion; this.whatsappBusinessManagementApiService = createService(WhatsappBusinessManagementApiService.class, token); } @@ -45,7 +61,7 @@ public WhatsappBusinessManagementApi(String token) { */ public Template createMessageTemplate(String whatsappBusinessAccountId, MessageTemplate messageTemplate) { - return executeSync(whatsappBusinessManagementApiService.createMessageTemplate(whatsappBusinessAccountId, messageTemplate)); + return executeSync(whatsappBusinessManagementApiService.createMessageTemplate(apiVersion.getValue(), whatsappBusinessAccountId, messageTemplate)); } /** @@ -58,7 +74,7 @@ public Template createMessageTemplate(String whatsappBusinessAccountId, MessageT */ public Template updateMessageTemplate(String whatsappBusinessAccountId, String messageTemplateId, MessageTemplate messageTemplate) { - return executeSync(whatsappBusinessManagementApiService.updateMessageTemplate(whatsappBusinessAccountId, messageTemplateId, messageTemplate)); + return executeSync(whatsappBusinessManagementApiService.updateMessageTemplate(apiVersion.getValue(), whatsappBusinessAccountId, messageTemplateId, messageTemplate)); } /** @@ -70,7 +86,7 @@ public Template updateMessageTemplate(String whatsappBusinessAccountId, String m */ public Response deleteMessageTemplate(String whatsappBusinessAccountId, String name) { - return executeSync(whatsappBusinessManagementApiService.deleteMessageTemplate(whatsappBusinessAccountId, name)); + return executeSync(whatsappBusinessManagementApiService.deleteMessageTemplate(apiVersion.getValue(), whatsappBusinessAccountId, name)); } /** @@ -84,7 +100,7 @@ public Response deleteMessageTemplate(String whatsappBusinessAccountId, String n * @see Message templates */ public MessageTemplates retrieveTemplates(String whatsappBusinessAccountId) { - return executeSync(whatsappBusinessManagementApiService.retrieveTemplates(whatsappBusinessAccountId)); + return executeSync(whatsappBusinessManagementApiService.retrieveTemplates(apiVersion.getValue(), whatsappBusinessAccountId)); } /** @@ -96,7 +112,7 @@ public MessageTemplates retrieveTemplates(String whatsappBusinessAccountId) { * @see Message templates */ public MessageTemplates retrieveTemplates(String whatsappBusinessAccountId, int limit) { - return executeSync(whatsappBusinessManagementApiService.retrieveTemplates(whatsappBusinessAccountId, Map.of("limit", limit))); + return executeSync(whatsappBusinessManagementApiService.retrieveTemplates(apiVersion.getValue(), whatsappBusinessAccountId, Map.of("limit", limit))); } /** @@ -108,7 +124,7 @@ public MessageTemplates retrieveTemplates(String whatsappBusinessAccountId, int * @see Message templates */ public MessageTemplates retrieveTemplates(String whatsappBusinessAccountId, String templateName) { - return executeSync(whatsappBusinessManagementApiService.retrieveTemplates(whatsappBusinessAccountId, Map.of("name", templateName))); + return executeSync(whatsappBusinessManagementApiService.retrieveTemplates(apiVersion.getValue(), whatsappBusinessAccountId, Map.of("name", templateName))); } /** @@ -120,7 +136,7 @@ public MessageTemplates retrieveTemplates(String whatsappBusinessAccountId, Stri * @return message templates */ public MessageTemplates retrieveTemplates(String whatsappBusinessAccountId, int limit, String after) { - return executeSync(whatsappBusinessManagementApiService.retrieveTemplates(whatsappBusinessAccountId, Map.of("limit", limit, "after", after))); + return executeSync(whatsappBusinessManagementApiService.retrieveTemplates(apiVersion.getValue(), whatsappBusinessAccountId, Map.of("limit", limit, "after", after))); } /** @@ -132,7 +148,7 @@ public MessageTemplates retrieveTemplates(String whatsappBusinessAccountId, int */ public PhoneNumber retrievePhoneNumber(String phoneNumberId) { - return executeSync(whatsappBusinessManagementApiService.retrievePhoneNumber(phoneNumberId, new HashMap<>())); + return executeSync(whatsappBusinessManagementApiService.retrievePhoneNumber(apiVersion.getValue(), phoneNumberId, new HashMap<>())); } @@ -150,7 +166,7 @@ public PhoneNumber retrievePhoneNumber(String phoneNumberId) { */ public PhoneNumber retrievePhoneNumber(String phoneNumberId, String... fields) { Objects.requireNonNull(fields, "fields cannot be null"); - return executeSync(whatsappBusinessManagementApiService.retrievePhoneNumber(phoneNumberId, Map.of("fields", String.join(",", fields)))); + return executeSync(whatsappBusinessManagementApiService.retrievePhoneNumber(apiVersion.getValue(), phoneNumberId, Map.of("fields", String.join(",", fields)))); } @@ -163,7 +179,7 @@ public PhoneNumber retrievePhoneNumber(String phoneNumberId, String... fields) { * @see api docs */ public PhoneNumbers retrievePhoneNumbers(String whatsappBusinessAccountId) { - return executeSync(whatsappBusinessManagementApiService.retrievePhoneNumbers(whatsappBusinessAccountId)); + return executeSync(whatsappBusinessManagementApiService.retrievePhoneNumbers(apiVersion.getValue(), whatsappBusinessAccountId)); } @@ -175,7 +191,7 @@ public PhoneNumbers retrievePhoneNumbers(String whatsappBusinessAccountId) { * @return the response */ public Response requestCode(String phoneNumberId, RequestCode requestCode) { - return executeSync(whatsappBusinessManagementApiService.requestCode(phoneNumberId, requestCode)); + return executeSync(whatsappBusinessManagementApiService.requestCode(apiVersion.getValue(), phoneNumberId, requestCode)); } /** @@ -187,7 +203,7 @@ public Response requestCode(String phoneNumberId, RequestCode requestCode) { * @return the response */ public Response verifyCode(String phoneNumberId, VerifyCode verifyCode) { - return executeSync(whatsappBusinessManagementApiService.verifyCode(phoneNumberId, verifyCode)); + return executeSync(whatsappBusinessManagementApiService.verifyCode(apiVersion.getValue(), phoneNumberId, verifyCode)); } @@ -205,7 +221,7 @@ public Response verifyCode(String phoneNumberId, VerifyCode verifyCode) { * @see api docs */ public GraphCommerceSettings getWhatsappCommerceSettings(String phoneNumberId, String... fields) { - return executeSync(whatsappBusinessManagementApiService.getWhatsappCommerceSettings(phoneNumberId, Map.of("fields", String.join(",", fields)))); + return executeSync(whatsappBusinessManagementApiService.getWhatsappCommerceSettings(apiVersion.getValue(), phoneNumberId, Map.of("fields", String.join(",", fields)))); } /** @@ -217,7 +233,7 @@ public GraphCommerceSettings getWhatsappCommerceSettings(String phoneNumberId, S * @see api docs */ public Response updateWhatsappCommerceSettings(String phoneNumberId, CommerceDataItem commerceDataItem) { - return executeSync(whatsappBusinessManagementApiService.updateWhatsappCommerceSettings(phoneNumberId, commerceDataItem)); + return executeSync(whatsappBusinessManagementApiService.updateWhatsappCommerceSettings(apiVersion.getValue(), phoneNumberId, commerceDataItem)); } } diff --git a/src/main/java/com/whatsapp/api/service/WhatsappBusinessCloudApiService.java b/src/main/java/com/whatsapp/api/service/WhatsappBusinessCloudApiService.java index fe5cb6654..fc1c7f5f3 100644 --- a/src/main/java/com/whatsapp/api/service/WhatsappBusinessCloudApiService.java +++ b/src/main/java/com/whatsapp/api/service/WhatsappBusinessCloudApiService.java @@ -10,18 +10,7 @@ import okhttp3.MultipartBody; import okhttp3.ResponseBody; import retrofit2.Call; -import retrofit2.http.Body; -import retrofit2.http.DELETE; -import retrofit2.http.GET; -import retrofit2.http.Headers; -import retrofit2.http.Multipart; -import retrofit2.http.POST; -import retrofit2.http.Part; -import retrofit2.http.Path; -import retrofit2.http.Streaming; -import retrofit2.http.Url; - -import static com.whatsapp.api.configuration.WhatsappApiConfig.API_VERSION; +import retrofit2.http.*; /** * The interface Whatsapp business cloud api service. @@ -35,8 +24,8 @@ public interface WhatsappBusinessCloudApiService { * @param message the message * @return the call */ - @POST("/" + API_VERSION + "/{Phone-Number-ID}/messages") - Call sendMessage(@Path("Phone-Number-ID") String phoneNumberId, @Body Message message); + @POST("/{api-version}/{Phone-Number-ID}/messages") + Call sendMessage(@Path("api-version") String apiVersion, @Path("Phone-Number-ID") String phoneNumberId, @Body Message message); /** * Upload media call. @@ -47,8 +36,8 @@ public interface WhatsappBusinessCloudApiService { * @return the call */ @Multipart - @POST("/" + API_VERSION + "/{Phone-Number-ID}/media") - Call uploadMedia(@Path("Phone-Number-ID") String phoneNumberId, @Part MultipartBody.Part file, + @POST("/{api-version}/{Phone-Number-ID}/media") + Call uploadMedia(@Path("api-version") String apiVersion, @Path("Phone-Number-ID") String phoneNumberId, @Part MultipartBody.Part file, @Part MultipartBody.Part messageProduct); /** @@ -57,8 +46,8 @@ Call uploadMedia(@Path("Phone-Number-ID") String phoneNumberId, * @param mediaId the media id * @return the call */ - @GET("/" + API_VERSION + "/{media-id}") - Call retrieveMediaUrl(@Path("media-id") String mediaId); + @GET("/{api-version}/{media-id}") + Call retrieveMediaUrl(@Path("api-version") String apiVersion, @Path("media-id") String mediaId); /** * Download media file call. @@ -77,8 +66,8 @@ Call uploadMedia(@Path("Phone-Number-ID") String phoneNumberId, * @param mediaId the media id * @return the call */ - @DELETE("/" + API_VERSION + "/{media-id}") - Call deleteMedia(@Path("media-id") String mediaId); + @DELETE("/{api-version}/{media-id}") + Call deleteMedia(@Path("api-version") String apiVersion, @Path("media-id") String mediaId); /** * Send mark Meassge as read call. @@ -87,8 +76,8 @@ Call uploadMedia(@Path("Phone-Number-ID") String phoneNumberId, * @param message the message * @return the call */ - @POST("/" + API_VERSION + "/{Phone-Number-ID}/messages") - Call markMessageAsRead(@Path("Phone-Number-ID") String phoneNumberId, @Body ReadMessage message); + @POST("/{api-version}/{Phone-Number-ID}/messages") + Call markMessageAsRead(@Path("api-version") String apiVersion, @Path("Phone-Number-ID") String phoneNumberId, @Body ReadMessage message); /** * Two-step verification call. @@ -97,7 +86,7 @@ Call uploadMedia(@Path("Phone-Number-ID") String phoneNumberId, * @param twoStepCode the two-step code * @return the call */ - @POST("/" + API_VERSION + "/{Phone-Number-ID}") - Call twoStepVerification(@Path("Phone-Number-ID") String phoneNumberId, @Body TwoStepCode twoStepCode); + @POST("/{api-version}/{Phone-Number-ID}") + Call twoStepVerification(@Path("api-version") String apiVersion, @Path("Phone-Number-ID") String phoneNumberId, @Body TwoStepCode twoStepCode); } diff --git a/src/main/java/com/whatsapp/api/service/WhatsappBusinessManagementApiService.java b/src/main/java/com/whatsapp/api/service/WhatsappBusinessManagementApiService.java index bb98d6570..13e690041 100644 --- a/src/main/java/com/whatsapp/api/service/WhatsappBusinessManagementApiService.java +++ b/src/main/java/com/whatsapp/api/service/WhatsappBusinessManagementApiService.java @@ -11,18 +11,10 @@ import com.whatsapp.api.domain.templates.response.MessageTemplates; import com.whatsapp.api.domain.templates.response.Template; import retrofit2.Call; -import retrofit2.http.Body; -import retrofit2.http.DELETE; -import retrofit2.http.GET; -import retrofit2.http.POST; -import retrofit2.http.Path; -import retrofit2.http.Query; -import retrofit2.http.QueryMap; +import retrofit2.http.*; import java.util.Map; -import static com.whatsapp.api.configuration.WhatsappApiConfig.API_VERSION; - /** * The interface Whatsapp business management api service. */ @@ -36,8 +28,8 @@ public interface WhatsappBusinessManagementApiService { * @param messageTemplate the message template * @return the call */ - @POST("/" + API_VERSION + "/{whatsapp-business-account-ID}/message_templates") - Call