Skip to content

Commit 6387449

Browse files
authored
[ISSUE-36] Properly format DateTime value in request parameter (#39)
* [ISSUE-36] Properly format DateTime object to go over the wire * Update changelog * Add final * cleanup
1 parent d1d02fd commit 6387449

File tree

4 files changed

+24
-7
lines changed

4 files changed

+24
-7
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
55
## 1.1.0 (UNRELEASED)
66

77
#### Bugfixes
8-
- [Issue-35](https://github.com/Crim/pardot-java-client/issues/35) Submit POST parameters using UTF-8 charset by default.
8+
- [Issue-35](https://github.com/Crim/pardot-java-client/issues/35) Submit POST parameters using UTF-8 charset by default.
9+
- [Issue-36](https://github.com/Crim/pardot-java-client/issues/36) Sending email with the scheduled_time was broken due to improperly formatted value.
910

1011
#### Internal Dependency Updates
1112
- org.apache.httpcomponents:httpclent from 4.5.6 to 4.5.10

src/main/java/com/darksci/pardot/api/request/BaseRequest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717

1818
package com.darksci.pardot.api.request;
1919

20+
import org.joda.time.DateTime;
21+
22+
import java.text.SimpleDateFormat;
2023
import java.util.Collection;
2124
import java.util.HashMap;
2225
import java.util.LinkedHashSet;
@@ -45,6 +48,17 @@ protected T setParam(final String name, Object value) {
4548
return (T) this;
4649
}
4750

51+
@SuppressWarnings("unchecked")
52+
protected T setParam(final String name, final DateTime value) {
53+
if (value == null) {
54+
params.remove(name);
55+
} else {
56+
final String dateStr = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").format(value.toDate());
57+
return setParam(name, dateStr);
58+
}
59+
return (T) this;
60+
}
61+
4862
/**
4963
* Utility method to set a boolean parameter, converts boolean into string "true"/"false".
5064
*

src/main/java/com/darksci/pardot/api/request/email/EmailSendListRequest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public EmailSendListRequest withCampaignId(final Long campaignId) {
4343
}
4444

4545
/**
46-
* Defiine Name and Email to send the email using.
46+
* Define Name and Email to send the email using.
4747
* @param fromName The name of the sending user.
4848
* @param fromEmail The email of the sending user.
4949
* @return RequestBuilder

src/test/java/com/darksci/pardot/api/PardotClientTest.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@
112112
import com.darksci.pardot.api.response.visitor.VisitorQueryResponse;
113113
import com.darksci.pardot.api.response.visitoractivity.VisitorActivity;
114114
import com.darksci.pardot.api.response.visitoractivity.VisitorActivityQueryResponse;
115+
import org.joda.time.DateTime;
115116
import org.junit.After;
116117
import org.junit.Before;
117118
import org.junit.Test;
@@ -498,21 +499,22 @@ public void emailSendOneToOneTest() {
498499
*/
499500
@Test
500501
public void emailSendListTest() {
501-
final long campaignId = 14885;
502-
final long listId = 33173;
502+
final long campaignId = 1;
503+
final long listId = 5;
504+
final DateTime scheduledTime = DateTime.now().plusDays(2);
503505

504506
EmailSendListRequest request = new EmailSendListRequest()
505507
.withListId(listId)
506508
.withCampaignId(campaignId)
507509
.withFromNameAndEmail("Test User", "[email protected]")
508510
.withReplyToEmail("[email protected]")
509511
.withName("Test List Email Send " + System.currentTimeMillis())
510-
.withOperationalEmail(true)
511512
.withSubject("Test Email From Api")
512513
.withTag("Tag 1")
513514
.withTag("Tag 2")
514-
.withTextContent("Hello %%first_name%%!")
515-
.withHtmlContent("<html><body><h1>Hello %%first_name%%!</h1></body></html>");
515+
.withTextContent("Hello %%first_name%%! %%unsubscribe%%")
516+
.withHtmlContent("<html><body><h1>Hello %%first_name%%! %%unsubscribe%% </h1></body></html>")
517+
.withScheduledTime(scheduledTime);
516518

517519
final Email response = client.emailSendList(request);
518520
assertNotNull("Should not be null", response);

0 commit comments

Comments
 (0)