Git Product home page Git Product logo

harmony-client's Introduction

Epsilon Harmony client

An Epsilon Harmony client for Java applications.

Dependency

Building

To build library use:

./mvnw package -DskipTests

Testing

Tests could be run by following command:

./mvnw test

Using

HarmonyClient should be shared. It performs best when you create only a single instance and reuse it for all of your calls. This is because each client holds its own connection pool and thread pools. Reusing connections and threads reduces latency and saves memory.

First you need to create a shared instance with default settings clientId, userName and passwords are mandatory to supply, others settings could be overridden, see HarmonyClient.Builder API.

public final HarmonyClient client = new HarmonyClient.Builder()
  .withClientId("<client_id>")
  .withClientPass("<client_pass>")
  .withUserName("<user_name>")
  .withUserPass("<user_pass>")
  .build();

Shutdown isn't necessary.

Send using Java API

Prepare a request with at least one recipient with at least one mail attribute (according to Epsilon) every email should have at least one Recipient with at least one attribute.

SendMailRequest sendMailRequest = new SendMailRequest(
  "<message_id>",
  new SendMailRequest.Recipient("<[email protected]>",
    new SendMailRequest.Attribute("<attr_name>", "<attr_value>")
));
//send email synchronously
try (SendMailResponse sendMailResponse = harmonyClient.sendMail(aolOrgId, sendMailRequest).get()) {
  // process response
}

// or asynchronously
harmonyClient.sendMail(aolOrgId, sendMailRequest).handle((r, e) -> {
  if (e != null) {
    // deal with error
  } else {
    // process response
  }
});

SpringBoot integration

  1. Create configuration for HarmonyClient:
@Configuration
@ConfigurationProperties(prefix="harmony")
public class HarmonyClientConfig {
  private String clientId;
  private String clientPassword;
  private String userName;
  private String userPassword;
  // getter and setters here

  @Bean
  public harmonyClient() {
    return new HarmonyClient.Builder()
      .withClientId(clientId)
      .withClientPass(clientPassword)
      .withUserName(userName)
      .withUserPass(userPassword)
      .build();
  }
}
  1. Provide passwords in application.properties
harmony.client-id="<client-id>"
harmony.client-password="<client-password>"
harmony.user-name="<user-name>"
harmony.user-password="<user-password>"
  1. Inject it into your service
@Autowired
private final HarmonyClient harmonyClient;

Contributing

To generate eclipse project files use:

./mvnw eclipse:eclipse

To generate idea project files use:

./mvnw idea:idea

Or you can import the maven project directly from your favorite IDE.

harmony-client's People

Contributors

mshauneu avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.