Skip to content

Commit

Permalink
Merge 0891a52 into f2b208d
Browse files Browse the repository at this point in the history
  • Loading branch information
Jessica Xu committed Jun 16, 2017
2 parents f2b208d + 0891a52 commit 6d9be31
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 50 deletions.
4 changes: 2 additions & 2 deletions lob-java-examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ lob-java-examples$ mvn clean package

### Create letters from CSV

An example showing how to dynamically create letters from a CSV using HTML, a custom font, variable data, and Lob's [Letter API](https://lob.com/services/letters). The example code to create letters from a CSV can be found [here](https://github.com/lob/lob-java/blob/master/lob-java-examples/src/main/java/com/lob/examples/CsvLetterExample.java).
An example showing how to dynamically create letters from a CSV using HTML, a custom font, merge variables, and Lob's [Letter API](https://lob.com/services/letters). The example code to create letters from a CSV can be found [here](https://github.com/lob/lob-java/blob/master/lob-java-examples/src/main/java/com/lob/examples/CsvLetterExample.java).
```bash
lob-java-examples$ mvn exec:java -Dexec.mainClass="com.lob.examples.CsvLetterExample"
```

### Create postcards from CSV

An example showing how to dynamically create postcards from a CSV using HTML, a custom font, variable data, and Lob's [Postcard API](https://lob.com/services/postcards). The example code to create postcards from a CSV can be found [here](https://github.com/lob/lob-java/blob/master/lob-java-examples/src/main/java/com/lob/examples/CsvPostcardExample.java).
An example showing how to dynamically create postcards from a CSV using HTML, a custom font, merge variables, and Lob's [Postcard API](https://lob.com/services/postcards). The example code to create postcards from a CSV can be found [here](https://github.com/lob/lob-java/blob/master/lob-java-examples/src/main/java/com/lob/examples/CsvPostcardExample.java).
```bash
lob-java-examples$ mvn exec:java -Dexec.mainClass="com.lob.examples.CsvPostcardExample"
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ public static void main(final String[] args) throws Exception {
while (iterator.hasNext()) {
final CsvLetter letter = iterator.next();

final Map<String, String> data = new HashMap<String, String>();
data.put("date", today);
data.put("name", letter.name);
data.put("amountDue", letter.amount);
final Map<String, String> mergeVariables = new HashMap<String, String>();
mergeVariables.put("date", today);
mergeVariables.put("name", letter.name);
mergeVariables.put("amountDue", letter.amount);

final LetterRequest letterRequest = LetterRequest.builder()
.to(
Expand All @@ -63,7 +63,7 @@ public static void main(final String[] args) throws Exception {
.from(companyAddress)
.file(letterTemplate)
.color(true)
.data(data)
.mergeVariables(mergeVariables)
.build();

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ public static void main(final String[] args) throws Exception {
while (iterator.hasNext()) {
final CsvPostcard postcard = iterator.next();

final Map<String, String> data = new HashMap<String, String>();
data.put("background_image", postcard.background_image);
data.put("background_color", postcard.background_color);
data.put("name", postcard.name);
data.put("car", postcard.car);
data.put("mileage", postcard.mileage);
final Map<String, String> mergeVariables = new HashMap<String, String>();
mergeVariables.put("background_image", postcard.background_image);
mergeVariables.put("background_color", postcard.background_color);
mergeVariables.put("name", postcard.name);
mergeVariables.put("car", postcard.car);
mergeVariables.put("mileage", postcard.mileage);

final PostcardRequest postcardRequest = PostcardRequest.builder()
.to(
Expand All @@ -52,7 +52,7 @@ public static void main(final String[] args) throws Exception {
.size("4x6")
.front(frontHTML)
.back(backHTML)
.data(data)
.mergeVariables(mergeVariables)
.build();

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,35 @@
import java.util.Map;

public abstract class AbstractDataFieldRequest extends AbstractLobRequest {
private final Map<String, String> data;
private final Map<String, String> mergeVariables;

public AbstractDataFieldRequest(
final Map<String, String> metadata,
final Map<String, String> data,
final Map<String, String> mergeVariables,
final String description) {
super(metadata, description);
this.data = data;
this.mergeVariables = mergeVariables;
}

public Map<String, String> getData() {
return data;
return mergeVariables;
}

@Override
protected LobParamsBuilder beginParams() {
return super.beginParams().putMap("data", this.data);
return super.beginParams().putMap("merge_variables", this.mergeVariables);
}

@Override
public String toString() {
return ", data=" + data + super.toString();
return ", mergeVariables=" + mergeVariables + super.toString();
}

public static abstract class Builder<B extends Builder<B>> extends AbstractLobRequest.Builder<B> {
protected Map<String, String> data;
protected Map<String, String> mergeVariables;

public B data(final Map<String, String> data) {
this.data = data;
public B mergeVariables(final Map<String, String> mergeVariables) {
this.mergeVariables = mergeVariables;
return (B)this;
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/lob/protocol/request/AreaMailRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ public AreaMailRequest(
final OrCollection<ZipCode, ZipCodeRouteId> routes,
final TargetType targetType,
final Map<String, String> metadata,
final Map<String, String> data,
final Map<String, String> mergeVariables,
final String description) {
super(metadata, data, description);
super(metadata, mergeVariables, description);
this.front = checkNotNull(front, "front is required");
this.back = checkNotNull(back, "back is required");
this.routes = checkPresent(routes, "routes is required");
Expand Down Expand Up @@ -173,12 +173,12 @@ public Builder butWith() {
.routes(routes)
.targetType(targetType)
.metadata(metadata)
.data(data)
.mergeVariables(mergeVariables)
.description(description);
}

public AreaMailRequest build() {
return new AreaMailRequest(front, back, routes, targetType, metadata, data, description);
return new AreaMailRequest(front, back, routes, targetType, metadata, mergeVariables, description);
}
}
}
8 changes: 4 additions & 4 deletions src/main/java/com/lob/protocol/request/CheckRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ public CheckRequest(
final String sendDate,
final String mailType,
final Map<String, String> metadata,
final Map<String, String> data,
final Map<String, String> mergeVariables,
final String description) {
super(metadata, data, description);
super(metadata, mergeVariables, description);
this.checkNumber = checkNumber;
this.bankAccount = checkNotNull(bankAccount, "bank account is required");
this.to = checkNotNull(to, "to is required");
Expand Down Expand Up @@ -330,12 +330,12 @@ public Builder butWith() {
.sendDate(sendDate)
.mailType(mailType)
.metadata(metadata)
.data(data)
.mergeVariables(mergeVariables)
.description(description);
}

public CheckRequest build() {
return new CheckRequest(checkNumber, bankAccount, to, from, amount, message, memo, logo, checkBottom, attachment, sendDate, mailType, metadata, data, description);
return new CheckRequest(checkNumber, bankAccount, to, from, amount, message, memo, logo, checkBottom, attachment, sendDate, mailType, metadata, mergeVariables, description);
}
}
}
10 changes: 5 additions & 5 deletions src/main/java/com/lob/protocol/request/LetterRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ public LetterRequest(
final String sendDate,
final String mailType,
final Map<String, String> metadata,
final Map<String, String> data) {
final Map<String, String> mergeVariables) {

super(metadata, data, description);
super(metadata, mergeVariables, description);
this.to = checkNotNull(to, "to is required");
this.from = checkNotNull(from, "from is required");
this.file = checkNotNull(file, "file is required");
Expand Down Expand Up @@ -241,11 +241,11 @@ public Builder butWith() {
.sendDate(sendDate)
.mailType(mailType)
.metadata(metadata)
.data(data);
.mergeVariables(mergeVariables);
}

public LetterRequest build() {
return new LetterRequest(description, to, from, file, color, doubleSided, addressPlacement, extraService, returnEnvelope, perforatedPage, sendDate, mailType, metadata, data);
return new LetterRequest(description, to, from, file, color, doubleSided, addressPlacement, extraService, returnEnvelope, perforatedPage, sendDate, mailType, metadata, mergeVariables);
}
}
}
}
8 changes: 4 additions & 4 deletions src/main/java/com/lob/protocol/request/PostcardRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ public PostcardRequest(
final String mailType,
final String sendDate,
final Map<String, String> metadata,
final Map<String, String> data,
final Map<String, String> mergeVariables,
final String description) {

super(metadata, data, description);
super(metadata, mergeVariables, description);
this.to = checkNotNull(to, "to is required");
this.from = from;
this.message = message;
Expand Down Expand Up @@ -221,12 +221,12 @@ public Builder butWith() {
.sendDate(sendDate)
.mailType(mailType)
.metadata(metadata)
.data(data)
.mergeVariables(mergeVariables)
.description(description);
}

public PostcardRequest build() {
return new PostcardRequest(to, from, message, front, back, size, mailType, sendDate, metadata, data, description);
return new PostcardRequest(to, from, message, front, back, size, mailType, sendDate, metadata, mergeVariables, description);
}
}
}
12 changes: 6 additions & 6 deletions src/test/java/com/lob/client/test/CheckTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ public void testCreateCheck() throws Exception {

@Test
public void testCreateCheckWithFile() throws Exception {
final Map<String, String> data = Maps.newHashMap();
data.put("name", "Donald");
final Map<String, String> mergeVariables = Maps.newHashMap();
mergeVariables.put("name", "Donald");
final AddressResponse address = getAddress();
final BankAccountResponse bankAccount = getAndVerifyBankAccount();

Expand All @@ -168,7 +168,7 @@ public void testCreateCheckWithFile() throws Exception {
.file("<h1 style='padding-top:4in;'>Demo Check for {{name}}</h1>")
.checkNumber(100)
.memo("Test Check")
.data(data);
.mergeVariables(mergeVariables);

final CheckRequest request = builder.build();
assertNotNull(request.getFile());
Expand All @@ -189,8 +189,8 @@ public void testCreateCheckWithFile() throws Exception {

@Test
public void testCreateCheckWithLocalFile() throws Exception {
final Map<String, String> data = Maps.newHashMap();
data.put("name", "Donald");
final Map<String, String> mergeVariables = Maps.newHashMap();
mergeVariables.put("name", "Donald");
final AddressResponse address = getAddress();
final BankAccountResponse bankAccount = getAndVerifyBankAccount();

Expand All @@ -204,7 +204,7 @@ public void testCreateCheckWithLocalFile() throws Exception {
.attachment(ClientUtil.fileFromResource("8.5x11.pdf"))
.checkNumber(100)
.memo("Test Check")
.data(data);
.mergeVariables(mergeVariables);

final CheckRequest request1 = builder.build();
assertNotNull(request1.getFile());
Expand Down
8 changes: 4 additions & 4 deletions src/test/java/com/lob/client/test/LetterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ public void testCreateLetter() throws Exception {
metadata.put("key1", value1);
final AddressResponse address = client.getAddresses(1).get().get(0);

final Map<String, String> data = Maps.newHashMap();
data.put("name", "peter");
final Map<String, String> mergeVariables = Maps.newHashMap();
mergeVariables.put("name", "peter");
final String file = "<html style='padding-top: 3in; margin: .5in;'>HTML Letter for {{name}}</html>";
final LetterRequest.Builder builder = LetterRequest.builder()
.to(address.getId())
.from(address.getId())
.file(file)
.data(data)
.mergeVariables(mergeVariables)
.color(true)
.addressPlacement("top_first_page")
.doubleSided(false)
Expand Down Expand Up @@ -128,7 +128,7 @@ public void testCreateLetter() throws Exception {
assertThat(otherRequest.getDescription(), is("otherRequest"));
assertThat(otherRequest.getFrom().getTypeB(), is(addrRequest));
assertThat(otherRequest.getTo().getTypeB(), is(addrRequest));
assertThat(otherRequest.getData(), is(data));
assertThat(otherRequest.getData(), is(mergeVariables));
assertThat(otherRequest.getMetadata(), is(metadata));
assertFalse(otherRequest.isColor());
assertFalse(otherRequest.isDoubleSided());
Expand Down

0 comments on commit 6d9be31

Please sign in to comment.