| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -142,17 +142,37 @@ public TemplateValidation validateTemplate(TemplateToValidate data) throws Postm | |||
| 142 | 142 | return dataHandler.fromJson(response, TemplateValidation.class); | |
| 143 | 143 | } | |
| 144 | 144 | ||
| 145 | - public MessageResponse deliverMessage(TemplatedMessage data) throws PostmarkException, IOException { | ||
| 145 | + public MessageResponse deliverMessageWithTemplate(TemplatedMessage data) throws PostmarkException, IOException { | ||
| 146 | + setTemplateModelToObject(data); | ||
| 146 | 147 | ||
| 148 | + String response = execute(HttpClient.REQUEST_TYPES.POST, getEndpointUrl(sendingEndpoint + "withTemplate"), data); | ||
| 149 | + return dataHandler.fromJson(response, MessageResponse.class); | ||
| 150 | + } | ||
| 151 | + | ||
| 152 | + public ArrayList<MessageResponse> deliverMessageWithTemplate(ArrayList<TemplatedMessage> data) throws PostmarkException, IOException { | ||
| 153 | + | ||
| 154 | + /* | ||
| 155 | + When sending array of emails with templates, additional top level field is used called "Messages". | ||
| 156 | + This introduces unnecessary difference between batch and batchWithTemplates endpoint in data model. | ||
| 157 | + To keep it simple, this additional level is added before executing batch send. | ||
| 158 | + */ | ||
| 159 | + HashMap<String, ArrayList> dataToSend = new HashMap<>(); | ||
| 160 | + dataToSend.put("Messages", data); | ||
| 161 | + | ||
| 162 | + for(TemplatedMessage templateMessage:data) { setTemplateModelToObject(templateMessage); } | ||
| 163 | + | ||
| 164 | + String response = execute(HttpClient.REQUEST_TYPES.POST, getEndpointUrl(sendingEndpoint + "batchWithTemplates"), data); | ||
| 165 | + return dataHandler.fromJson(response, new TypeReference<ArrayList<MessageResponse>>() {}); | ||
| 166 | + } | ||
| 167 | + | ||
| 168 | + private void setTemplateModelToObject(TemplatedMessage data) throws IOException { | ||
| 147 | 169 | /* | |
| 148 | 170 | Since template models can be complex, it is allowed that template model is a String or Object. | |
| 149 | 171 | If it's a String, we will auto convert it to Object. | |
| 150 | 172 | */ | |
| 151 | 173 | if (data.getTemplateModel().getClass() == String.class) { | |
| 152 | 174 | data.setTemplateModel(dataHandler.fromJson(data.getTemplateModel().toString(),Object.class)); | |
| 153 | 175 | } | |
| 154 | - String response = execute(HttpClient.REQUEST_TYPES.POST, getEndpointUrl(sendingEndpoint + "withTemplate"), data); | ||
| 155 | - return dataHandler.fromJson(response, MessageResponse.class); | ||
| 156 | 176 | } | |
| 157 | 177 | ||
| 158 | 178 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments