Skip to content

Commit

Permalink
Merge pull request #2 from xdev-software/develop
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
AB-xdev authored Mar 5, 2024
2 parents 7f3e551 + 4c34b8c commit 27237e6
Show file tree
Hide file tree
Showing 404 changed files with 147,577 additions and 48 deletions.
16 changes: 0 additions & 16 deletions .run/Run Demo.run.xml

This file was deleted.

2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
## 1.0.0
Initial release
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ You should have the following things installed:
* Ensure that the JDK/Java-Version is correct


## Releasing [![Build](https://img.shields.io/github/actions/workflow/status/xdev-software/openapi-client-maven-template/release.yml?branch=master)](https://github.com/xdev-software/openapi-client-maven-template/actions/workflows/release.yml)
## Releasing [![Build](https://img.shields.io/github/actions/workflow/status/xdev-software/brevo-java-client/release.yml?branch=master)](https://github.com/xdev-software/brevo-java-client/actions/workflows/release.yml)

Before releasing:
* Consider doing a [test-deployment](https://github.com/xdev-software/openapi-client-maven-template/actions/workflows/test-deploy.yml?query=branch%3Adevelop) before actually releasing.
* Consider doing a [test-deployment](https://github.com/xdev-software/brevo-java-client/actions/workflows/test-deploy.yml?query=branch%3Adevelop) before actually releasing.
* Check the [changelog](CHANGELOG.md)

If the ``develop`` is ready for release, create a pull request to the ``master``-Branch and merge the changes
Expand Down
41 changes: 32 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,38 @@
[![Latest version](https://img.shields.io/maven-central/v/software.xdev/openapi-client-maven-template?logo=apache%20maven)](https://mvnrepository.com/artifact/software.xdev/openapi-client-maven-template)
[![Build](https://img.shields.io/github/actions/workflow/status/xdev-software/openapi-client-maven-template/checkBuild.yml?branch=develop)](https://github.com/xdev-software/openapi-client-maven-template/actions/workflows/checkBuild.yml?query=branch%3Adevelop)
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=xdev-software_openapi-client-maven-template&metric=alert_status)](https://sonarcloud.io/dashboard?id=xdev-software_openapi-client-maven-template)
[![API Specification Editor](https://img.shields.io/badge/API--Spec-Editor-85ea2d?logo=swagger)](https://editor.swagger.io/?url=https://raw.githubusercontent.com/xdev-software/openapi-client-maven-template/develop/openapi/openapi.yml)
[![Latest version](https://img.shields.io/maven-central/v/software.xdev/brevo-java-client?logo=apache%20maven)](https://mvnrepository.com/artifact/software.xdev/brevo-java-client)
[![Build](https://img.shields.io/github/actions/workflow/status/xdev-software/brevo-java-client/checkBuild.yml?branch=develop)](https://github.com/xdev-software/brevo-java-client/actions/workflows/checkBuild.yml?query=branch%3Adevelop)
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=xdev-software_brevo-java-client&metric=alert_status)](https://sonarcloud.io/dashboard?id=xdev-software_brevo-java-client)
[![API Specification Editor](https://img.shields.io/badge/API--Spec-Editor-85ea2d?logo=swagger)](https://editor.swagger.io/?url=https://raw.githubusercontent.com/xdev-software/brevo-java-client/develop/openapi/openapi.yml)

# openapi-client-maven-template
# <img src="https://corp-backend.brevo.com/wp-content/uploads/2023/05/favicon.svg" height="28" /> [brevo](https://brevo.com)-java-client

This client [is generated](./openapi-client-maven-template/pom.xml) from an [``openapi.yml``](./openapi/openapi.yml) using [OpenAPI Generator](https://openapi-generator.tech/).
A Java client for the [Brevo](https://brevo.com) (formerly [SendinBlue](https://help.brevo.com/hc/en-us/articles/11279317272722-FAQs-Sendinblue-becomes-Brevo)) API

> [!IMPORTANT]
> An API-Key is required.<br/>
> You can get it at https://app.brevo.com/settings/keys/api
This client [is generated](./brevo-java-client/pom.xml) from an [``openapi.yml``](./openapi/openapi.yml) using [OpenAPI Generator](https://openapi-generator.tech/).

> [!NOTE]
> <details><summary>Why did you create this API client and not use <a href="https://github.com/sendinblue/APIv3-java-library">the official one</a>?</summary>
>
> We had some problems (as of March 2024) with the "official" client:
> * The client looks seriously outdated:
> * it is still called "SendinBlue"
> * was last updated over a year ago and there was no activity (on issues/PR) since then
> * There is at least one CVE in the underlying HTTP client
> * It looks like there are problems with the underlying dependencies:
> * ``maven-gpg-plugin`` is declared as compile dependency
> * There is a [dependency for Java 7](https://www.threeten.org/threetenbp/) however the client is built for Java 8+
> * ...
>
> </details>
## Installation
[Installation guide for the latest release](https://github.com/xdev-software/openapi-client-maven-template/releases/latest#Installation)
[Installation guide for the latest release](https://github.com/xdev-software/brevo-java-client/releases/latest#Installation)

## Demo
A minimal demo is also available [here](./openapi-client-maven-template-demo/src/main/java/software/xdev/Application.java).
A minimal demo is also available [here](./brevo-java-client-demo/src/main/java/software/xdev/Application.java).

## Support
If you need support as soon as possible and you can't wait for any pull request, feel free to use [our support](https://xdev.software/en/services/support).
Expand All @@ -20,4 +41,6 @@ If you need support as soon as possible and you can't wait for any pull request,
See the [contributing guide](./CONTRIBUTING.md) for detailed instructions on how to get started with our project.

## Dependencies and Licenses
View the [license of the current project](LICENSE) or the [summary including all dependencies](https://xdev-software.github.io/openapi-client-maven-template/dependencies/)
View the [license of the current project](LICENSE) or the [summary including all dependencies](https://xdev-software.github.io/brevo-java-client/dependencies/)

<sub>Disclaimer: This is not an official Brevo product and not associated with Brevo</sub>
2 changes: 1 addition & 1 deletion SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

## Reporting a Vulnerability

Please report a security vulnerability [on GitHub Security Advisories](https://github.com/xdev-software/openapi-client-maven-template/security/advisories/new).
Please report a security vulnerability [on GitHub Security Advisories](https://github.com/xdev-software/brevo-java-client/security/advisories/new).
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>

<groupId>software.xdev</groupId>
<artifactId>openapi-client-maven-template-demo</artifactId>
<artifactId>brevo-java-client-demo</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging>

Expand All @@ -31,7 +31,7 @@
<dependencies>
<dependency>
<groupId>software.xdev</groupId>
<artifactId>openapi-client-maven-template</artifactId>
<artifactId>brevo-java-client</artifactId>
<version>${project.version}</version>
</dependency>

Expand Down
107 changes: 107 additions & 0 deletions brevo-java-client-demo/src/main/java/software/xdev/Application.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
package software.xdev;

import java.util.List;
import java.util.Optional;
import java.util.Scanner;
import java.util.function.Function;

import org.apache.hc.core5.http.HttpStatus;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import software.xdev.brevo.api.ContactsApi;
import software.xdev.brevo.client.ApiClient;
import software.xdev.brevo.client.ApiException;
import software.xdev.brevo.model.CreateContact;
import software.xdev.brevo.model.CreateUpdateContactModel;
import software.xdev.brevo.model.GetContactInfoIdentifierParameter;
import software.xdev.brevo.model.GetExtendedContactDetails;
import software.xdev.brevo.model.UpdateContact;


public final class Application
{
private static final Logger LOG = LoggerFactory.getLogger(Application.class);

// Tries to add an email/contact to a list
public static void main(final String[] args)
{
final ApiClient apiClient = new ApiClient();
apiClient.setApiKey(getProperty("API-KEY", Function.identity()));
apiClient.setUserAgent("Brevo Java Client");

final long listId = getProperty("LIST-ID", Long::parseLong);
final String email = getProperty("EMAIL-FOR-LIST", Function.identity());

final ContactsApi contactsApi = new ContactsApi(apiClient);
try
{
final GetContactInfoIdentifierParameter identifier =
new GetContactInfoIdentifierStringParameter(email);
final GetExtendedContactDetails contactInfo = contactsApi.getContactInfo(
identifier,
null,
null);
LOG.info("Got contact[email={},listIds={}]", contactInfo.getEmail(), contactInfo.getListIds());
if(!contactInfo.getListIds().contains(listId))
{
contactsApi.updateContact(identifier, new UpdateContact().listIds(List.of(listId)));
LOG.info("Updated contact to include listId={}", listId);
}
}
catch(final ApiException ex)
{
if(ex.getCode() == HttpStatus.SC_NOT_FOUND)
{
final CreateUpdateContactModel createdContact = contactsApi.createContact(new CreateContact()
.email(email)
.listIds(List.of(listId)));
LOG.info("Created contact[id={}, email={},listIds={}]", createdContact.getId(), email, listId);
}
}
}

private static <T> T getProperty(final String identifier, final Function<String, T> caster)
{
String value = Optional.ofNullable(System.getenv(identifier))
.orElseGet(() -> System.getProperty(identifier));
if(value == null)
{
LOG.error("Required {} not set in environment variables or system properties", identifier);

LOG.info("Please provide {} over console:", identifier);
try(final Scanner scanner = new Scanner(System.in))
{
value = scanner.nextLine();
}

if(value == null || value.isBlank())
{
LOG.error("Invalid input; Aborting");
System.exit(1);
}
}
return caster.apply(value);
}

private Application()
{
}

@SuppressWarnings("java:S2160")
public static class GetContactInfoIdentifierStringParameter extends GetContactInfoIdentifierParameter
{
private final String value;

public GetContactInfoIdentifierStringParameter(final String value)
{
this.value = value;
}

@Override
public String toString()
{
return this.value;
}
}
}
20 changes: 20 additions & 0 deletions brevo-java-client-demo/src/main/resources/log4j2.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Configuration>
<Configuration status="ERROR">

<Properties>
<Property name="consolePattern">%d{HH:mm:ss} %-5p [%t] [%-25.25c] %m %n</Property>
</Properties>

<Appenders>
<Console name="stdout" target="SYSTEM_OUT">
<PatternLayout pattern="${consolePattern}"/>
</Console>
</Appenders>

<Loggers>
<Root level="INFO">
<AppenderRef ref="stdout"/>
</Root>
</Loggers>
</Configuration>
26 changes: 13 additions & 13 deletions openapi-client-maven-template/pom.xml → brevo-java-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@
<modelVersion>4.0.0</modelVersion>

<groupId>software.xdev</groupId>
<artifactId>openapi-client-maven-template</artifactId>
<artifactId>brevo-java-client</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging>

<name>openapi-client-maven-template</name>
<description>openapi-client-maven-template</description>
<url>https://github.com/xdev-software/openapi-client-maven-template</url>
<name>brevo-java-client</name>
<description>brevo-java-client</description>
<url>https://github.com/xdev-software/brevo-java-client</url>

<scm>
<url>https://github.com/xdev-software/openapi-client-maven-template</url>
<connection>https://github.com/xdev-software/openapi-client-maven-template.git</connection>
<url>https://github.com/xdev-software/brevo-java-client</url>
<connection>https://github.com/xdev-software/brevo-java-client.git</connection>
</scm>

<inceptionYear>2023</inceptionYear>
<inceptionYear>2024</inceptionYear>

<organization>
<name>XDEV Software</name>
Expand Down Expand Up @@ -283,7 +283,7 @@
<profile>
<id>openapi-generator</id>
<properties>
<componentName>INSERT_NAME_HERE</componentName>
<componentName>brevo</componentName>

<generatedDir>${project.basedir}/${generatedDirRelative}</generatedDir>
<openApiRelativeGeneratorDir>src/gen</openApiRelativeGeneratorDir>
Expand Down Expand Up @@ -348,12 +348,12 @@
<!-- Use newer Jakarta EE instead of Javax -->
<useJakartaEe>true</useJakartaEe>
<hideGenerationTimestamp>true</hideGenerationTimestamp>
<!-- No tests and documentation because we don't use that -->
<generateModelTests>false</generateModelTests>
<generateApiTests>false</generateApiTests>
<generateModelDocumentation>false</generateModelDocumentation>
<generateApiDocumentation>false</generateApiDocumentation>
</configOptions>
<!-- No tests and documentation because we don't use that -->
<generateModelTests>false</generateModelTests>
<generateApiTests>false</generateApiTests>
<generateModelDocumentation>false</generateModelDocumentation>
<generateApiDocumentation>false</generateApiDocumentation>
</configuration>
</execution>
</executions>
Expand Down
Loading

0 comments on commit 27237e6

Please sign in to comment.