Skip to content

Instantly share code, notes, and snippets.

@lobot
Last active June 1, 2022 18:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lobot/ab49befc52b8e42104665c6d82dec983 to your computer and use it in GitHub Desktop.
Save lobot/ab49befc52b8e42104665c6d82dec983 to your computer and use it in GitHub Desktop.
tracking-event-changes-java
package com.company.app;
import java.util.HashMap;
import com.lob.Lob;
import com.lob.model.Address;
import com.lob.model.Postcard;
import com.lob.net.LobResponse;
public class App
{
public static void main( String[] args )
{
Lob.init("<LOB_TEST_API_KEY>");
try {
HashMap<String, String> map = new HashMap<>();
map.put("Name","Harry Zhang");
map.put("Line1","210 King Street");
map.put("City","San Francisco");
map.put("State","CA");
map.put("Zip","94107");
LobResponse<Postcard> response = new Postcard.RequestBuilder()
.setDescription("First Postcard")
.setTo(new Address.RequestBuilder()
.setName(map.get("Name"))
.setLine1(map.get("Line1"))
.setCity(map.get("City"))
.setState(map.get("State"))
.setZip(map.get("Zip")))
.setFrom( new Address.RequestBuilder()
.setName("LEORE AVIDAR")
.setLine1("210 KING STREET")
.setCity("SAN FRANCISCO")
.setState("CA")
.setZip("94107")
)
.setFront("<html style='padding: 1in; font-size: 50;'>Front HTML</html>")
.setBack("<html style='padding: 1in; font-size: 20;'>Back HTML</html>")
.create();
Postcard result = response.getResponseBody();
//CHECK IF ADDRESS ELEMENT CHANGED IN THE RESPONSE
String check_address_1 = map.get("Line1").equals(result.getTo().getLine1()) ? "ADDRESS 1 : No Update" : "ADDRESS 1 : Update in database from " + map.get("Line1") + " to: " + result.getTo().getLine1();
String check_adddress_city = map.get("City").equals(result.getTo().getCity()) ? "CITY : No Update" : "CITY : Update in database from " + map.get("City") + " to: " + result.getTo().getCity();
String check_adddress_state = map.get("State").equals(result.getTo().getState()) ? "STATE : No Update" : "STATE : Update in database from " + map.get("State") + " to: " + result.getTo().getState();
String check_adddress_zip = map.get("Zip").equals(result.getTo().getZip()) ? "ZIP : No Update" : "ZIP : Update in database from " + map.get("Zip") + " to: " + result.getTo().getZip();
System.out.println(check_address_1);
System.out.println(check_adddress_city);
System.out.println(check_adddress_state);
System.out.println(check_adddress_zip);
} catch (Exception err) {
System.out.println("Error on postcard creation: " + err);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment