1818
1919import static com .mailjet .client .MailjetRequestUtil .decodeDecimals ;
2020
21+ import java .io .File ;
2122import java .io .IOException ;
2223import java .io .UnsupportedEncodingException ;
2324import java .net .URLEncoder ;
@@ -71,6 +72,9 @@ public class MailjetRequest {
7172
7273 private String _data ;
7374
75+ @ Getter
76+ private File attachment ;
77+
7478 @ Getter
7579 private final ApiVersion apiVersion ;
7680
@@ -102,7 +106,7 @@ public class MailjetRequest {
102106 * @param res
103107 */
104108 public MailjetRequest (Resource res ) {
105- this ._path = "/REST" ;
109+ this ._path = definePath ( res ) ;
106110 _configuration = 1 ;
107111 resource = res .getResource ();
108112 _action = res .getAction ();
@@ -123,7 +127,7 @@ public MailjetRequest(Resource res) {
123127 * @param id
124128 */
125129 public MailjetRequest (Resource res , long id ) {
126- this ._path = "/REST" ;
130+ this ._path = definePath ( res ) ;
127131 resource = res .getResource ();
128132 _action = res .getAction ();
129133 _withoutNamespace = res .getWithoutNamespace ();
@@ -144,7 +148,7 @@ public MailjetRequest(Resource res, long id) {
144148 * @param id
145149 */
146150 public MailjetRequest (Resource res , String id ) {
147- this ._path = "/REST" ;
151+ this ._path = definePath ( res ) ;
148152 resource = res .getResource ();
149153 _action = res .getAction ();
150154 _withoutNamespace = res .getWithoutNamespace ();
@@ -166,7 +170,7 @@ public MailjetRequest(Resource res, String id) {
166170 * @param actionid the resource action ID
167171 */
168172 public MailjetRequest (Resource res , long id , long actionid ) {
169- this ._path = "/REST" ;
173+ this ._path = definePath ( res ) ;
170174 resource = res .getResource ();
171175 _action = res .getAction ();
172176 _withoutNamespace = res .getWithoutNamespace ();
@@ -184,6 +188,11 @@ public MailjetRequest setData(String path) throws IOException {
184188 return this ;
185189 }
186190
191+ public MailjetRequest attachFile (File file ) {
192+ this .attachment = file ;
193+ return this ;
194+ }
195+
187196 /**
188197 * Pass a String formatted json as the request body
189198 * @param json
@@ -236,7 +245,7 @@ public JSONObject getBodyJSON() {
236245 */
237246 public String getContentType () {
238247 if ("csvdata" .equals (_action ))
239- return "text:csv " ;
248+ return "text/plain " ;
240249 if ("csverror" .equals (_action ))
241250 return "text/plain" ;
242251 else
@@ -263,6 +272,8 @@ public String buildUrl(String baseApiUrl) throws UnsupportedEncodingException {
263272 url = base + '/' + _action ;
264273 else if (_action .equals ("managemanycontacts" ) && id != null )
265274 url = base + '/' + _action + '/' + id ;
275+ else if (_action .equals ("csvdata" ))
276+ url = base + '/' + id + '/' + _action + '/' + "text:plain" ;
266277 else if (_configuration == 1 )
267278 url = base ;
268279 else if (_configuration == 2 )
@@ -359,4 +370,11 @@ public String toString() {
359370 .put ("Body" , _body .toString ())
360371 .toString ();
361372 }
373+
374+ private String definePath (Resource res ) {
375+ if (res .getAction ().equals ("csvdata" )) {
376+ return "/DATA" ;
377+ }
378+ return "/REST" ;
379+ }
362380}
0 commit comments