Subversion Repositories SmartDukaan

Rev

Rev 16527 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 16527 Rev 16530
Line 1... Line 1...
1
package in.shop2020.util;
1
package in.shop2020.util;
2
 
2
 
3
import com.sendgrid.smtpapi.SMTPAPI;
3
import in.shop2020.util.SMTPAPI;
4
import org.apache.http.HttpEntity;
4
import org.apache.http.HttpEntity;
5
import org.apache.http.HttpResponse;
5
import org.apache.http.HttpResponse;
6
import org.apache.http.client.methods.HttpPost;
6
import org.apache.http.client.methods.HttpPost;
7
import org.apache.http.entity.ContentType;
7
import org.apache.http.entity.ContentType;
8
import org.apache.http.entity.mime.MultipartEntityBuilder;
8
import org.apache.http.entity.mime.MultipartEntityBuilder;
9
import org.apache.http.impl.client.CloseableHttpClient;
9
import org.apache.http.impl.client.CloseableHttpClient;
10
import org.apache.http.impl.client.HttpClientBuilder;
10
import org.apache.http.impl.client.HttpClientBuilder;
11
import org.apache.http.util.EntityUtils;
11
import org.apache.http.util.EntityUtils;
-
 
12
import org.json.JSONException;
12
import org.json.JSONObject;
13
import org.json.JSONObject;
13
 
14
 
14
import java.io.*;
15
import java.io.*;
15
import java.util.*;
16
import java.util.*;
16
 
17
 
17
public class SendGrid {
18
public class SendGrid {
18
    private static final String VERSION = "2.2.2";
19
    private static final String VERSION = "2.2.1";
19
    private static final String USER_AGENT = "sendgrid/" + VERSION + ";java";
20
    private static final String USER_AGENT = "sendgrid/" + VERSION + ";java";
20
 
21
 
21
    private static final String PARAM_TO = "to[]";
22
    private static final String PARAM_TO = "to[]";
22
    private static final String PARAM_TONAME = "toname[]";
23
    private static final String PARAM_TONAME = "toname[]";
23
    private static final String PARAM_CC = "cc[]";
24
    private static final String PARAM_CC = "cc[]";
Line 228... Line 229...
228
 
229
 
229
        public String[] getTos() {
230
        public String[] getTos() {
230
            return this.to.toArray(new String[this.to.size()]);
231
            return this.to.toArray(new String[this.to.size()]);
231
        }
232
        }
232
 
233
 
233
        public Email addSmtpApiTo(String to) {
234
        public Email addSmtpApiTo(String to) throws JSONException {
234
            this.smtpapi.addTo(to);
235
            this.smtpapi.addTo(to);
235
            return this;
236
            return this;
236
        }
237
        }
237
 
238
 
238
        public Email addSmtpApiTo(String[] to) {
239
        public Email addSmtpApiTo(String[] to) throws JSONException {
239
            this.smtpapi.addTos(to);
240
            this.smtpapi.addTos(to);
240
            return this;
241
            return this;
241
        }
242
        }
242
 
243
 
243
        public Email addToName(String toname) {
244
        public Email addToName(String toname) {
Line 349... Line 350...
349
 
350
 
350
        public String getHtml() {
351
        public String getHtml() {
351
            return this.html;
352
            return this.html;
352
        }
353
        }
353
 
354
 
354
        public Email addSubstitution(String key, String[] val) {
355
        public Email addSubstitution(String key, String[] val) throws JSONException {
355
            this.smtpapi.addSubstitutions(key, val);
356
            this.smtpapi.addSubstitutions(key, val);
356
            return this;
357
            return this;
357
        }
358
        }
358
 
359
 
359
        public JSONObject getSubstitutions() {
360
        public JSONObject getSubstitutions() throws JSONException {
360
            return this.smtpapi.getSubstitutions();
361
            return this.smtpapi.getSubstitutions();
361
        }
362
        }
362
 
363
 
363
        public Email addUniqueArg(String key, String val) {
364
        public Email addUniqueArg(String key, String val) throws JSONException {
364
            this.smtpapi.addUniqueArg(key, val);
365
            this.smtpapi.addUniqueArg(key, val);
365
            return this;
366
            return this;
366
        }
367
        }
367
 
368
 
368
        public JSONObject getUniqueArgs() {
369
        public JSONObject getUniqueArgs() throws JSONException {
369
            return this.smtpapi.getUniqueArgs();
370
            return this.smtpapi.getUniqueArgs();
370
        }
371
        }
371
 
372
 
372
        public Email addCategory(String category) {
373
        public Email addCategory(String category) throws JSONException {
373
            this.smtpapi.addCategory(category);
374
            this.smtpapi.addCategory(category);
374
            return this;
375
            return this;
375
        }
376
        }
376
 
377
 
377
        public String[] getCategories() {
378
        public String[] getCategories() throws JSONException  {
378
            return this.smtpapi.getCategories();
379
            return this.smtpapi.getCategories();
379
        }
380
        }
380
 
381
 
381
        public Email addSection(String key, String val) {
382
        public Email addSection(String key, String val) throws JSONException {
382
            this.smtpapi.addSection(key, val);
383
            this.smtpapi.addSection(key, val);
383
            return this;
384
            return this;
384
        }
385
        }
385
 
386
 
386
        public JSONObject getSections() {
387
        public JSONObject getSections() throws JSONException  {
387
            return this.smtpapi.getSections();
388
            return this.smtpapi.getSections();
388
        }
389
        }
389
 
390
 
390
        public Email addFilter(String filter_name, String parameter_name, String parameter_value) {
391
        public Email addFilter(String filter_name, String parameter_name, String parameter_value) throws JSONException {
391
            this.smtpapi.addFilter(filter_name, parameter_name, parameter_value);
392
            this.smtpapi.addFilter(filter_name, parameter_name, parameter_value);
392
            return this;
393
            return this;
393
        }
394
        }
394
 
395
 
395
        public JSONObject getFilters() {
396
        public JSONObject getFilters() throws JSONException  {
396
            return this.smtpapi.getFilters();
397
            return this.smtpapi.getFilters();
397
        }
398
        }
398
 
399
 
399
        public Email setASMGroupId(int val) {
400
        public Email setASMGroupId(int val) throws JSONException  {
400
            this.smtpapi.setASMGroupId(val);
401
            this.smtpapi.setASMGroupId(val);
401
            return this;
402
            return this;
402
        }
403
        }
403
 
404
 
404
        public Integer getASMGroupId() {
405
        public Integer getASMGroupId() throws JSONException  {
405
            return this.smtpapi.getASMGroupId();
406
            return this.smtpapi.getASMGroupId();
406
        }
407
        }
407
 
408
 
408
        public Email setSendAt(int sendAt) {
409
        public Email setSendAt(int sendAt) throws JSONException  {
409
            this.smtpapi.setSendAt(sendAt);
410
            this.smtpapi.setSendAt(sendAt);
410
            return this;
411
            return this;
411
        }
412
        }
412
 
413
 
413
        public int getSendAt() {
414
        public int getSendAt() throws JSONException  {
414
            return this.smtpapi.getSendAt();
415
            return this.smtpapi.getSendAt();
415
        }
416
        }
416
 
417
 
417
        /**
418
        /**
418
         * Convenience method to set the template
419
         * Convenience method to set the template
419
         *
420
         *
420
         * @param templateId The ID string of your template
421
         * @param templateId The ID string of your template
421
         * @return this
422
         * @return this
422
         */
423
         */
423
        public Email setTemplateId(String templateId) {
424
        public Email setTemplateId(String templateId) throws JSONException  {
424
            this.getSMTPAPI().addFilter("templates", "enable", 1);
425
            this.getSMTPAPI().addFilter("templates", "enable", 1);
425
            this.getSMTPAPI().addFilter("templates", "template_id", templateId);
426
            this.getSMTPAPI().addFilter("templates", "template_id", templateId);
426
            return this;
427
            return this;
427
        }
428
        }
428
 
429