Skip to content

Commit e1aea90

Browse files
committed
Merge pull request #43 from kalnik-a-a/master
RecipientList List and Retrieve responses. RecipientList asStoredRericipientList method
2 parents 472c179 + d8bf470 commit e1aea90

File tree

5 files changed

+63
-4
lines changed

5 files changed

+63
-4
lines changed

libs/sparkpost-lib/src/main/java/com/sparkpost/model/RecipientList.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,14 @@ public class RecipientList extends Base {
6666
@SerializedName("total_rejected_recipients")
6767
private int totalRejectedRecipients;
6868

69+
/**
70+
* Returns object that can be used to create transmission.
71+
* @return StoredRecipientList object
72+
*/
73+
public StoredRecipientList asStoredRecipientList() {
74+
75+
StoredRecipientList storedRecipientList = new StoredRecipientList();
76+
storedRecipientList.setListId(this.getId());
77+
return storedRecipientList;
78+
}
6979
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.sparkpost.model.responses;
2+
3+
import com.sparkpost.model.RecipientList;
4+
5+
import com.yepher.jsondoc.annotations.Description;
6+
import lombok.Data;
7+
import lombok.EqualsAndHashCode;
8+
9+
@Data
10+
@EqualsAndHashCode(callSuper = true)
11+
public class RecipientListRetrieveResponse extends Response {
12+
13+
@Description(value = "", sample = {""})
14+
private RecipientList results;
15+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.sparkpost.model.responses;
2+
3+
import com.sparkpost.model.RecipientList;
4+
5+
import com.yepher.jsondoc.annotations.Description;
6+
import lombok.Data;
7+
import lombok.EqualsAndHashCode;
8+
9+
import java.util.List;
10+
11+
@Data
12+
@EqualsAndHashCode(callSuper = true)
13+
public class RecipientListsListAllResponse extends Response {
14+
15+
@Description(value = "List of RecipientList", sample = {""})
16+
private List<RecipientList> results;
17+
}

libs/sparkpost-lib/src/main/java/com/sparkpost/resources/ResourceRecipientLists.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
import com.sparkpost.exception.SparkPostException;
55
import com.sparkpost.model.RecipientList;
6+
import com.sparkpost.model.responses.RecipientListRetrieveResponse;
7+
import com.sparkpost.model.responses.RecipientListsListAllResponse;
68
import com.sparkpost.model.responses.Response;
79
import com.sparkpost.transport.RestConnection;
810

@@ -26,16 +28,19 @@ public static Response create(RestConnection conn, Integer maxNumberOfRecipientE
2628
return response;
2729
}
2830

29-
public static Response retrieve(RestConnection conn, String recipientListId, Boolean showRecipients) throws SparkPostException {
31+
public static RecipientListRetrieveResponse retrieve(RestConnection conn, String recipientListId, Boolean showRecipients) throws SparkPostException {
3032
Endpoint ep = new Endpoint("recipient-lists/" + recipientListId);
3133
ep.addParam("show_recipients", showRecipients);
3234
Response response = conn.get(ep.toString());
33-
return response;
35+
36+
RecipientListRetrieveResponse retrieveResponse = RecipientListRetrieveResponse.decode(response, RecipientListRetrieveResponse.class);
37+
return retrieveResponse;
3438
}
3539

36-
public static Response listAll(RestConnection conn) throws SparkPostException {
40+
public static RecipientListsListAllResponse listAll(RestConnection conn) throws SparkPostException {
3741
Response response = conn.get("recipient-lists");
38-
return response;
42+
RecipientListsListAllResponse listResponse = RecipientListsListAllResponse.decode(response, RecipientListsListAllResponse.class);
43+
return listResponse;
3944
}
4045

4146
public static Response delete(RestConnection conn, String recipientListId) throws SparkPostException {

libs/sparkpost-lib/src/test/java/com/sparkpost/model/RecipientListTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,4 +143,16 @@ public void testRecipientAttributesRoundtrip() {
143143
// Internal decoding of this data is tested in it's own tests
144144
Assert.assertNotNull(recipients);
145145
}
146+
147+
/**
148+
*
149+
*/
150+
@Test
151+
public void testRecipientsListToStoredRecipientsListConvertation() {
152+
153+
Gson gson = new Gson();
154+
RecipientList recipientList = gson.fromJson(this.RECIPIENT_LIST_JSON, RecipientList.class);
155+
StoredRecipientList storedRecipientsList = recipientList.asStoredRecipientList();
156+
Assert.assertEquals(storedRecipientsList.getListId(), "unique_id_4_graduate_students_list");
157+
}
146158
}

0 commit comments

Comments
 (0)