Skip to content

Commit

Permalink
Merge branch 'main' into fix/dependency_vulnerability
Browse files Browse the repository at this point in the history
  • Loading branch information
Bindambc authored May 6, 2024
2 parents e533d10 + 073ba19 commit d2277a3
Show file tree
Hide file tree
Showing 21 changed files with 416 additions and 138 deletions.
24 changes: 18 additions & 6 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
tests:
- src/test/**/*
- changed-files:
- any-glob-to-any-file: 'src/test/**/*'

java:
- '**/*.java'
- changed-files:
- any-glob-to-any-file: '**/*.java'

documentation:
- '**/*.md'
- changed-files:
- any-glob-to-any-file: '**/*.md'

markdown:
- '**/*.md'
- changed-files:
- any-glob-to-any-file: '**/*.md'

github-actions:
- .github/**/*
- changed-files:
- any-glob-to-any-file: '.github/**/*'

dependencies:
- pom.xml
- changed-files:
- any-glob-to-any-file: 'pom.xml'


8 changes: 4 additions & 4 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:

- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
Expand All @@ -53,7 +53,7 @@ jobs:

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
Expand All @@ -64,7 +64,7 @@ jobs:
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v2
uses: github/codeql-action/autobuild@v3

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl
Expand All @@ -78,6 +78,6 @@ jobs:
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
uses: github/codeql-action/analyze@v3
with:
category: "/language:${{matrix.language}}"
2 changes: 1 addition & 1 deletion .github/workflows/javadoc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
git config --local user.name "github-actions[bot]"
git merge origin/main
- name: Set up JDK 17
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/label.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ jobs:
pull-requests: write

steps:
- uses: actions/labeler@v4
- uses: actions/labeler@v5
with:
repo-token: "${{ secrets.GITHUB_TOKEN }}"
4 changes: 2 additions & 2 deletions .github/workflows/maven-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
Expand All @@ -26,4 +26,4 @@ jobs:
run: mvn -B package --file pom.xml
#coverage
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v4
uses: codecov/codecov-action@v3
2 changes: 1 addition & 1 deletion .github/workflows/maven-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
packages: write
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v3
- uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-javadoc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
Expand Down
11 changes: 6 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<com.squareup.retrofit2.version>2.9.0</com.squareup.retrofit2.version>
<org.mockito.version>5.2.0</org.mockito.version>
<org.junit.jupiter.version>5.10.0</org.junit.jupiter.version>
<org.junit.jupiter.version>5.10.1</org.junit.jupiter.version>
<com.squareup.okhttp3.version>5.0.0-alpha.12</com.squareup.okhttp3.version>

</properties>

<distributionManagement>
Expand Down Expand Up @@ -116,7 +117,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<version>3.12.1</version>
<configuration>
<source>17</source>
<target>17</target>
Expand All @@ -125,12 +126,12 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.1.2</version>
<version>3.2.5</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.5.0</version>
<version>3.6.3</version>
<configuration>
<source>17</source>
<reportOutputDirectory>${project.basedir}</reportOutputDirectory>
Expand All @@ -141,7 +142,7 @@
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.10</version>
<version>0.8.11</version>
<executions>
<execution>
<goals>
Expand Down
30 changes: 22 additions & 8 deletions src/main/java/com/whatsapp/api/WhatsappApiServiceGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
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 okhttp3.OkHttpClient;
import okhttp3.ResponseBody;
import retrofit2.Call;
Expand All @@ -28,7 +31,14 @@
public class WhatsappApiServiceGenerator {

static OkHttpClient sharedClient;
private static final Converter.Factory converterFactory = JacksonConverterFactory.create();
private static final Converter.Factory converterFactory = JacksonConverterFactory.create(
new ObjectMapper()
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
.configure(DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES, false)
.configure(DeserializationFeature.FAIL_ON_UNRESOLVED_OBJECT_IDS, false)
.configure(DeserializationFeature.FAIL_ON_INVALID_SUBTYPE, false)
);

@SuppressWarnings("unchecked")
private static final Converter<ResponseBody, WhatsappApiError> errorBodyConverter = (Converter<ResponseBody, WhatsappApiError>) converterFactory.responseBodyConverter(WhatsappApiError.class, new Annotation[0], null);

Expand All @@ -37,8 +47,11 @@ private WhatsappApiServiceGenerator() {
}

static {
sharedClient = createDefaultHttpClient();
}

sharedClient = new OkHttpClient.Builder()//
public static OkHttpClient createDefaultHttpClient(){
return new OkHttpClient.Builder()//
.callTimeout(20, TimeUnit.SECONDS)//
.pingInterval(20, TimeUnit.SECONDS)//
.build();
Expand All @@ -58,28 +71,29 @@ private WhatsappApiServiceGenerator() {
* </ul>
* <p>
* @param host the host (Not null)
* @param port the port (Not null)
* @param port the port
* @param username the username
* @param pwd the pwd
* @see <a href="https://square.github.io/okhttp/4.x/okhttp/okhttp3/-ok-http-client/-builder/proxy-selector/">Proxy Selector</a>
* @see <a href="https://square.github.io/okhttp/4.x/okhttp/okhttp3/-ok-http-client/-builder/proxy-authenticator/">Proxy Authenticator</a>
*/
public static void setHttpProxy(String host, int port, String username, String pwd) {
Objects.requireNonNull(host, "Host cannot be null");
Objects.requireNonNull(port, "Http Port cannot be null");
CustomHttpProxySelector proxySelector = new CustomHttpProxySelector(host, port);

sharedClient = sharedClient.newBuilder()
.proxySelector(proxySelector)
.build();

if (username == null || pwd == null) {
sharedClient = sharedClient.newBuilder()
.proxySelector(proxySelector)
.build();
//Without authentication
return;
}

CustomProxyAuthenticator proxyAuthenticator = new CustomProxyAuthenticator(username, pwd);

sharedClient = sharedClient.newBuilder()
.authenticator(proxyAuthenticator)
.proxyAuthenticator(proxyAuthenticator)
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@
@JsonInclude(JsonInclude.Include.NON_NULL)
public record Message(

@JsonProperty("id") String id) {
@JsonProperty("id") String id,
@JsonProperty("message_status") String messageStatus)
{
}
34 changes: 22 additions & 12 deletions src/main/java/com/whatsapp/api/domain/phone/PhoneNumber.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,29 @@
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.whatsapp.api.domain.phone.type.NameStatusType;
import com.whatsapp.api.domain.phone.type.PlatformType;
import com.whatsapp.api.domain.phone.type.QualityRatingType;

/**
* The type Phone number.
*
* @param id The ID associated with the phone number.
* @param displayPhoneNumber The string representation of the phone number.
* @param nameStatus The current status of the review of your business name.
* @param id The ID associated with the phone number.
* @param displayPhoneNumber The string representation of the phone number.
* @param nameStatus The current status of the review of your business name.
* @param codeVerificationStatus Code Verification Status
* @param qualityRating The quality rating of the phone number based on how messages have been received by recipients in recent days. Valid values are:
* <ul>
* <li>Green: High Quality</li>
* <li>Yellow: Medium Quality</li>
* <li> Red: Low Quality</li>
* <li>NA: Quality has not been determined</li>
* </ul>
* @param verifiedName the verified name
* @param qualityRating The quality rating of the phone number based on how messages have been received by recipients in recent days. Valid values are:
* <ul>
* <li>Green: High Quality</li>
* <li>Yellow: Medium Quality</li>
* <li>Red: Low Quality</li>
* <li>NA: Quality has not been determined</li>
* </ul>
* @param verifiedName the verified name
* @param platformType Platform the business phone number is registered with.
* @param throughput The business phone number's Cloud API throughput level.
* @see <a href="https://www.facebook.com/business/help/896873687365001">About WhatsApp Business Account Message Quality Rating</a>
* @see <a href="https://developers.facebook.com/docs/graph-api/reference/whats-app-business-account-to-number-current-status/">WhatsApp Business Phone Number</a>
* @see <a href="https://developers.facebook.com/docs/whatsapp/business-platform/changelog/#september-12--2023">WhatsApp Business Platform - Changelog - September 12, 2023</a>
*/
@JsonInclude(value = Include.NON_NULL)
public record PhoneNumber(
Expand All @@ -36,5 +41,10 @@ public record PhoneNumber(

@JsonProperty("code_verification_status") String codeVerificationStatus,

@JsonProperty("name_status") NameStatusType nameStatus) {
@JsonProperty("name_status") NameStatusType nameStatus,

@JsonProperty("platform_type") PlatformType platformType,

@JsonProperty("throughput") Throughput throughput)
{
}
16 changes: 16 additions & 0 deletions src/main/java/com/whatsapp/api/domain/phone/Throughput.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.whatsapp.api.domain.phone;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.whatsapp.api.domain.phone.type.LevelType;

/**
* The type Throughput.
*/
@JsonInclude(value = Include.NON_NULL)
public record Throughput(

@JsonProperty("level") LevelType Level)
{
}
38 changes: 38 additions & 0 deletions src/main/java/com/whatsapp/api/domain/phone/type/LevelType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.whatsapp.api.domain.phone.type;

import com.fasterxml.jackson.annotation.JsonValue;

/**
* The enum Level type.
*/
public enum LevelType
{

/**
* Standard Level type.
*/
STANDARD("STANDARD"),
/**
* High Level type.
*/
HIGH("HIGH"),
NOT_APPLICABLE("NOT_APPLICABLE");

private final String value;

LevelType(String value)
{
this.value = value;
}

/**
* Gets value.
*
* @return the value
*/
@JsonValue
public String getValue()
{
return value;
}
}
38 changes: 38 additions & 0 deletions src/main/java/com/whatsapp/api/domain/phone/type/PlatformType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.whatsapp.api.domain.phone.type;

import com.fasterxml.jackson.annotation.JsonValue;

/**
* The enum Platform type.
*/
public enum PlatformType
{

/**
* Cloud API Platform type.
*/
CLOUD_API("CLOUD_API"),
/**
* On-Premises API Platform type.
*/
ON_PREMISE("ON_PREMISE"),
NOT_APPLICABLE("NOT_APPLICABLE");

private final String value;

PlatformType(String value)
{
this.value = value;
}

/**
* Gets value.
*
* @return the value
*/
@JsonValue
public String getValue()
{
return value;
}
}
Loading

0 comments on commit d2277a3

Please sign in to comment.