diff --git a/examples/mailsettings/GetAddressWhitelistMailSettings.java b/examples/mailsettings/GetAddressWhitelistMailSettings.java new file mode 100644 index 00000000..fdc81c1b --- /dev/null +++ b/examples/mailsettings/GetAddressWhitelistMailSettings.java @@ -0,0 +1,28 @@ +import com.sendgrid.Method; +import com.sendgrid.Request; +import com.sendgrid.Response; +import com.sendgrid.SendGrid; + +import java.io.IOException; + +////////////////////////////////////////////////////////////////// +// Retrieve address whitelist mail settings +// GET /mail_settings/address_whitelist + + +public class GetAddressWhitelistMailSettings { + public static void main(String[] args) throws IOException { + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("mail_settings/address_whitelist"); + Response response = sg.api(request); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); + } catch (IOException ex) { + throw ex; + } + } +} \ No newline at end of file diff --git a/examples/mailsettings/GetAllMailSettings.java b/examples/mailsettings/GetAllMailSettings.java new file mode 100644 index 00000000..e85b6e48 --- /dev/null +++ b/examples/mailsettings/GetAllMailSettings.java @@ -0,0 +1,30 @@ +import java.io.IOException; + +import com.sendgrid.Method; +import com.sendgrid.Request; +import com.sendgrid.Response; +import com.sendgrid.SendGrid; + +////////////////////////////////////////////////////////////////// +// Retrieve all mail settings +// GET /mail_settings + + +public class GetAllMailSettings { + public static void main(String[] args) throws IOException { + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("mail_settings"); + request.addQueryParam("limit", "1"); + request.addQueryParam("offset", "1"); + Response response = sg.api(request); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); + } catch (IOException ex) { + throw ex; + } + } +} diff --git a/examples/mailsettings/GetBCCMailSettings.java b/examples/mailsettings/GetBCCMailSettings.java new file mode 100644 index 00000000..90ab31d9 --- /dev/null +++ b/examples/mailsettings/GetBCCMailSettings.java @@ -0,0 +1,28 @@ +import java.io.IOException; + +import com.sendgrid.Method; +import com.sendgrid.Request; +import com.sendgrid.Response; +import com.sendgrid.SendGrid; + +////////////////////////////////////////////////////////////////// +// Retrieve all BCC mail settings +// GET /mail_settings/bcc + + +public class GetBCCMailSettings { + public static void main(String[] args) throws IOException { + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("mail_settings/bcc"); + Response response = sg.api(request); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); + } catch (IOException ex) { + throw ex; + } + } +} \ No newline at end of file diff --git a/examples/mailsettings/GetBouncePurgeMailSettings.java b/examples/mailsettings/GetBouncePurgeMailSettings.java new file mode 100644 index 00000000..2f390764 --- /dev/null +++ b/examples/mailsettings/GetBouncePurgeMailSettings.java @@ -0,0 +1,28 @@ +import com.sendgrid.Method; +import com.sendgrid.Request; +import com.sendgrid.Response; +import com.sendgrid.SendGrid; + +import java.io.IOException; + +////////////////////////////////////////////////////////////////// +// Retrieve bounce purge mail settings +// GET /mail_settings/bounce_purge + + +public class GetBouncePurgeMailSettings { + public static void main(String[] args) throws IOException { + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("mail_settings/bounce_purge"); + Response response = sg.api(request); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); + } catch (IOException ex) { + throw ex; + } + } +} \ No newline at end of file diff --git a/examples/mailsettings/GetFooterMailSettings.java b/examples/mailsettings/GetFooterMailSettings.java new file mode 100644 index 00000000..bea04d0b --- /dev/null +++ b/examples/mailsettings/GetFooterMailSettings.java @@ -0,0 +1,31 @@ +import java.io.IOException; + +import com.sendgrid.Method; +import com.sendgrid.Method; +import com.sendgrid.Request; +import com.sendgrid.Response; +import com.sendgrid.SendGrid; + +import java.io.IOException; + +////////////////////////////////////////////////////////////////// +// Retrieve footer mail settings +// GET /mail_settings/footer + + +public class GetFooterMailSettings { + public static void main(String[] args) throws IOException { + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("mail_settings/footer"); + Response response = sg.api(request); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); + } catch (IOException ex) { + throw ex; + } + } +} \ No newline at end of file diff --git a/examples/mailsettings/GetForwardBounceMailSettings.java b/examples/mailsettings/GetForwardBounceMailSettings.java new file mode 100644 index 00000000..33331585 --- /dev/null +++ b/examples/mailsettings/GetForwardBounceMailSettings.java @@ -0,0 +1,31 @@ +import java.io.IOException; + +import com.sendgrid.Method; +import com.sendgrid.Method; +import com.sendgrid.Request; +import com.sendgrid.Response; +import com.sendgrid.SendGrid; + +import java.io.IOException; + +////////////////////////////////////////////////////////////////// +// Retrieve forward bounce mail settings +// GET /mail_settings/forward_bounce + + +public class GetForwardBounceMailSettings { + public static void main(String[] args) throws IOException { + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("mail_settings/forward_bounce"); + Response response = sg.api(request); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); + } catch (IOException ex) { + throw ex; + } + } +} \ No newline at end of file diff --git a/examples/mailsettings/GetForwardSpamMailSettings.java b/examples/mailsettings/GetForwardSpamMailSettings.java new file mode 100644 index 00000000..0b890294 --- /dev/null +++ b/examples/mailsettings/GetForwardSpamMailSettings.java @@ -0,0 +1,28 @@ +import com.sendgrid.Method; +import com.sendgrid.Request; +import com.sendgrid.Response; +import com.sendgrid.SendGrid; + +import java.io.IOException; + +////////////////////////////////////////////////////////////////// +// Retrieve forward spam mail settings +// GET /mail_settings/forward_spam + + +public class GetForwardSpamMailSettings { + public static void main(String[] args) throws IOException { + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("mail_settings/forward_spam"); + Response response = sg.api(request); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); + } catch (IOException ex) { + throw ex; + } + } +} \ No newline at end of file diff --git a/examples/mailsettings/GetPlainContentMailSettings.java b/examples/mailsettings/GetPlainContentMailSettings.java new file mode 100644 index 00000000..38f7cfe4 --- /dev/null +++ b/examples/mailsettings/GetPlainContentMailSettings.java @@ -0,0 +1,28 @@ +import java.io.IOException; + +import com.sendgrid.Method; +import com.sendgrid.Request; +import com.sendgrid.Response; +import com.sendgrid.SendGrid; + +////////////////////////////////////////////////////////////////// +// Retrieve plain content mail settings +// GET /mail_settings/plain_content + + +public class GetPlainContentMailSettings { + public static void main(String[] args) throws IOException { + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("mail_settings/plain_content"); + Response response = sg.api(request); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); + } catch (IOException ex) { + throw ex; + } + } +} \ No newline at end of file diff --git a/examples/mailsettings/GetSpamCheckMailSettings.java b/examples/mailsettings/GetSpamCheckMailSettings.java new file mode 100644 index 00000000..9460cac0 --- /dev/null +++ b/examples/mailsettings/GetSpamCheckMailSettings.java @@ -0,0 +1,28 @@ +import java.io.IOException; + +import com.sendgrid.Method; +import com.sendgrid.Request; +import com.sendgrid.Response; +import com.sendgrid.SendGrid; + +////////////////////////////////////////////////////////////////// +// Retrieve spam check mail settings +// GET /mail_settings/spam_check + + +public class GetSpamCheckMailSettings { + public static void main(String[] args) throws IOException { + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("mail_settings/spam_check"); + Response response = sg.api(request); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); + } catch (IOException ex) { + throw ex; + } + } +} \ No newline at end of file diff --git a/examples/mailsettings/GetTemplateMailSettings.java b/examples/mailsettings/GetTemplateMailSettings.java new file mode 100644 index 00000000..8b648be4 --- /dev/null +++ b/examples/mailsettings/GetTemplateMailSettings.java @@ -0,0 +1,28 @@ +import java.io.IOException; + +import com.sendgrid.Method; +import com.sendgrid.Request; +import com.sendgrid.Response; +import com.sendgrid.SendGrid; + +////////////////////////////////////////////////////////////////// +// Retrieve legacy template mail settings +// GET /mail_settings/template + + +public class GetTemplateMailSettings { + public static void main(String[] args) throws IOException { + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("mail_settings/template"); + Response response = sg.api(request); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); + } catch (IOException ex) { + throw ex; + } + } +} \ No newline at end of file diff --git a/examples/mailsettings/README.md b/examples/mailsettings/README.md new file mode 100644 index 00000000..34e83317 --- /dev/null +++ b/examples/mailsettings/README.md @@ -0,0 +1,23 @@ +![SendGrid Logo](https://uiux.s3.amazonaws.com/2016-logos/email-logo%402x.png) + +This folder contains various examples on using the Mail Settings endpoint of SendGrid with Java: + +* [Retrieve all mail settings (GET /mail_settings)](GetAllMailSettings.java) +* [Retrieve address whitelist mail settings (GET /mail_settings/address_whitelist)](GetAddressWhitelistMailSettings.java) +* [Retrieve all BCC mail settings (GET /mail_settings/bcc)](GetBCCMailSettings.java) +* [Retrieve bounce purge mail settings (GET /mail_settings/bounce_purge)](GetBouncePurgeMailSettings.java) +* [Retrieve footer mail settings (GET /mail_settings/footer)](GetFooterMailSettings.java) +* [Retrieve forward bounce mail settings (GET /mail_settings/forward_bounce)](GetForwardBounceMailSettings.java) +* [Retrieve forward spam mail settings (GET /mail_settings/forward_spam)](GetForwardSpamMailSettings.java) +* [Retrieve plain content mail settings (GET /mail_settings/plain_content)](GetPlainContentMailSettings.java) +* [Retrieve spam check mail settings (GET /mail_settings/spam_check)](GetSpamCheckMailSettings.java) +* [Retrieve legacy template mail settings (GET /mail_settings/template)](GetTemplateMailSettings.java) +* [Update address whitelist mail settings (PATCH /mail_settings/address_whitelist)](UpdateAddressWhitelist.java) +* [Update BCC mail settings (PATCH /mail_settings/bcc)](UpdateBCCMailSettings.java) +* [Update bounce purge mail settings (PATCH /mail_settings/bounce_purge)](UpdateBouncePurgeMailSettings.java) +* [Update footer mail settings (PATCH /mail_settings/footer)](UpdateFooterMailSettings.java) +* [Update forward bounce mail settings (PATCH /mail_settings/forward_bounce)](UpdateForwardBounceMailSettings.java) +* [Update forward spam mail settings (PATCH /mail_settings/forward_spam)](UpdateForwardSpamMailSettings.java) +* [Update plain content mail settings (PATCH /mail_settings/plain_content)](UpdatePlainContentMailSettings.java) +* [Update spam check mail settings (PATCH /mail_settings/spam_check)](UpdateSpamCheckMailSettings.java) +* [Update template mail settings (PATCH /mail_settings/template)](UpdateTemplateMailSettings.java) diff --git a/examples/mailsettings/UpdateAddressWhitelist.java b/examples/mailsettings/UpdateAddressWhitelist.java new file mode 100644 index 00000000..db58c282 --- /dev/null +++ b/examples/mailsettings/UpdateAddressWhitelist.java @@ -0,0 +1,29 @@ +import java.io.IOException; + +import com.sendgrid.Method; +import com.sendgrid.Request; +import com.sendgrid.Response; +import com.sendgrid.SendGrid; + +////////////////////////////////////////////////////////////////// +// Update address whitelist mail settings +// PATCH /mail_settings/address_whitelist + + +public class UpdateAddressWhitelist { + public static void main(String[] args) throws IOException { + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.PATCH); + request.setEndpoint("mail_settings/address_whitelist"); + request.setBody("{\"list\":[\"email1@example.com\",\"example.com\"],\"enabled\":true}"); + Response response = sg.api(request); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); + } catch (IOException ex) { + throw ex; + } + } +} \ No newline at end of file diff --git a/examples/mailsettings/UpdateBCCMailSettings.java b/examples/mailsettings/UpdateBCCMailSettings.java new file mode 100644 index 00000000..33faba1a --- /dev/null +++ b/examples/mailsettings/UpdateBCCMailSettings.java @@ -0,0 +1,29 @@ +import java.io.IOException; + +import com.sendgrid.Method; +import com.sendgrid.Request; +import com.sendgrid.Response; +import com.sendgrid.SendGrid; + +////////////////////////////////////////////////////////////////// +// Update BCC mail settings +// PATCH /mail_settings/bcc + + +public class UpdateBCCMailSettings { + public static void main(String[] args) throws IOException { + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.PATCH); + request.setEndpoint("mail_settings/bcc"); + request.setBody("{\"enabled\":false,\"email\":\"email@example.com\"}"); + Response response = sg.api(request); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); + } catch (IOException ex) { + throw ex; + } + } +} \ No newline at end of file diff --git a/examples/mailsettings/UpdateBouncePurgeMailSettings.java b/examples/mailsettings/UpdateBouncePurgeMailSettings.java new file mode 100644 index 00000000..83a53e10 --- /dev/null +++ b/examples/mailsettings/UpdateBouncePurgeMailSettings.java @@ -0,0 +1,29 @@ +import java.io.IOException; + +import com.sendgrid.Method; +import com.sendgrid.Request; +import com.sendgrid.Response; +import com.sendgrid.SendGrid; + +////////////////////////////////////////////////////////////////// +// Update bounce purge mail settings +// PATCH /mail_settings/bounce_purge + + +public class UpdateBouncePurgeMailSettings { + public static void main(String[] args) throws IOException { + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.PATCH); + request.setEndpoint("mail_settings/bounce_purge"); + request.setBody("{\"hard_bounces\":5,\"soft_bounces\":5,\"enabled\":true}"); + Response response = sg.api(request); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); + } catch (IOException ex) { + throw ex; + } + } +} \ No newline at end of file diff --git a/examples/mailsettings/UpdateFooterMailSettings.java b/examples/mailsettings/UpdateFooterMailSettings.java new file mode 100644 index 00000000..fedf35b0 --- /dev/null +++ b/examples/mailsettings/UpdateFooterMailSettings.java @@ -0,0 +1,29 @@ +import java.io.IOException; + +import com.sendgrid.Method; +import com.sendgrid.Request; +import com.sendgrid.Response; +import com.sendgrid.SendGrid; + +////////////////////////////////////////////////////////////////// +// Update footer mail settings +// PATCH /mail_settings/footer + + +public class UpdateFooterMailSettings { + public static void main(String[] args) throws IOException { + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.PATCH); + request.setEndpoint("mail_settings/footer"); + request.setBody("{\"html_content\":\"...\",\"enabled\":true,\"plain_content\":\"...\"}"); + Response response = sg.api(request); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); + } catch (IOException ex) { + throw ex; + } + } +} \ No newline at end of file diff --git a/examples/mailsettings/UpdateForwardBounceMailSettings.java b/examples/mailsettings/UpdateForwardBounceMailSettings.java new file mode 100644 index 00000000..677b94e9 --- /dev/null +++ b/examples/mailsettings/UpdateForwardBounceMailSettings.java @@ -0,0 +1,29 @@ +import java.io.IOException; + +import com.sendgrid.Method; +import com.sendgrid.Request; +import com.sendgrid.Response; +import com.sendgrid.SendGrid; + +////////////////////////////////////////////////////////////////// +// Update forward bounce mail settings +// PATCH /mail_settings/forward_bounce + + +public class UpdateForwardBounceMailSettings { + public static void main(String[] args) throws IOException { + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.PATCH); + request.setEndpoint("mail_settings/forward_bounce"); + request.setBody("{\"enabled\":true,\"email\":\"example@example.com\"}"); + Response response = sg.api(request); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); + } catch (IOException ex) { + throw ex; + } + } +} \ No newline at end of file diff --git a/examples/mailsettings/UpdateForwardSpamMailSettings.java b/examples/mailsettings/UpdateForwardSpamMailSettings.java new file mode 100644 index 00000000..3b27f353 --- /dev/null +++ b/examples/mailsettings/UpdateForwardSpamMailSettings.java @@ -0,0 +1,29 @@ +import java.io.IOException; + +import com.sendgrid.Method; +import com.sendgrid.Request; +import com.sendgrid.Response; +import com.sendgrid.SendGrid; + +////////////////////////////////////////////////////////////////// +// Update forward spam mail settings +// PATCH /mail_settings/forward_spam + + +public class UpdateForwardSpamMailSettings { + public static void main(String[] args) throws IOException { + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.PATCH); + request.setEndpoint("mail_settings/forward_spam"); + request.setBody("{\"enabled\":false,\"email\":\"\"}"); + Response response = sg.api(request); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); + } catch (IOException ex) { + throw ex; + } + } +} \ No newline at end of file diff --git a/examples/mailsettings/UpdatePlainContentMailSettings.java b/examples/mailsettings/UpdatePlainContentMailSettings.java new file mode 100644 index 00000000..4cb680f5 --- /dev/null +++ b/examples/mailsettings/UpdatePlainContentMailSettings.java @@ -0,0 +1,29 @@ +import java.io.IOException; + +import com.sendgrid.Method; +import com.sendgrid.Request; +import com.sendgrid.Response; +import com.sendgrid.SendGrid; + +////////////////////////////////////////////////////////////////// +// Update plain content mail settings +// PATCH /mail_settings/plain_content + + +public class UpdatePlainContentMailSettings { + public static void main(String[] args) throws IOException { + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.PATCH); + request.setEndpoint("mail_settings/plain_content"); + request.setBody("{\"enabled\":false}"); + Response response = sg.api(request); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); + } catch (IOException ex) { + throw ex; + } + } +} \ No newline at end of file diff --git a/examples/mailsettings/UpdateSpamCheckMailSettings.java b/examples/mailsettings/UpdateSpamCheckMailSettings.java new file mode 100644 index 00000000..e7cf8dc2 --- /dev/null +++ b/examples/mailsettings/UpdateSpamCheckMailSettings.java @@ -0,0 +1,29 @@ +import java.io.IOException; + +import com.sendgrid.Method; +import com.sendgrid.Request; +import com.sendgrid.Response; +import com.sendgrid.SendGrid; + +////////////////////////////////////////////////////////////////// +// Update spam check mail settings +// PATCH /mail_settings/spam_check + + +public class UpdateSpamCheckMailSettings { + public static void main(String[] args) throws IOException { + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.PATCH); + request.setEndpoint("mail_settings/spam_check"); + request.setBody("{\"url\":\"url\",\"max_score\":5,\"enabled\":true}"); + Response response = sg.api(request); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); + } catch (IOException ex) { + throw ex; + } + } +} \ No newline at end of file diff --git a/examples/mailsettings/UpdateTemplateMailSettings.java b/examples/mailsettings/UpdateTemplateMailSettings.java new file mode 100644 index 00000000..57e1b22a --- /dev/null +++ b/examples/mailsettings/UpdateTemplateMailSettings.java @@ -0,0 +1,29 @@ +import java.io.IOException; + +import com.sendgrid.Method; +import com.sendgrid.Request; +import com.sendgrid.Response; +import com.sendgrid.SendGrid; + +////////////////////////////////////////////////////////////////// +// Update template mail settings +// PATCH /mail_settings/template + + +public class UpdateTemplateMailSettings { + public static void main(String[] args) throws IOException { + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.PATCH); + request.setEndpoint("mail_settings/template"); + request.setBody("{\"html_content\":\"<% body %>\",\"enabled\":true}"); + Response response = sg.api(request); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); + } catch (IOException ex) { + throw ex; + } + } +} \ No newline at end of file diff --git a/examples/mailsettings/mailsettings.java b/examples/mailsettings/mailsettings.java deleted file mode 100644 index d42ffd2a..00000000 --- a/examples/mailsettings/mailsettings.java +++ /dev/null @@ -1,438 +0,0 @@ -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; - -import com.sendgrid.*; - -import java.io.IOException; -import java.util.HashMap; -import java.util.Map; - -////////////////////////////////////////////////////////////////// -// Retrieve all mail settings -// GET /mail_settings - - -public class Example { - public static void main(String[] args) throws IOException { - try { - SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); - Request request = new Request(); - request.setMethod(Method.GET); - request.setEndpoint("mail_settings"); - request.addQueryParam("limit", "1"); - request.addQueryParam("offset", "1"); - Response response = sg.api(request); - System.out.println(response.getStatusCode()); - System.out.println(response.getBody()); - System.out.println(response.getHeaders()); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Update address whitelist mail settings -// PATCH /mail_settings/address_whitelist - - -public class Example { - public static void main(String[] args) throws IOException { - try { - SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); - Request request = new Request(); - request.setMethod(Method.PATCH); - request.setEndpoint("mail_settings/address_whitelist"); - request.setBody("{\"list\":[\"email1@example.com\",\"example.com\"],\"enabled\":true}"); - Response response = sg.api(request); - System.out.println(response.getStatusCode()); - System.out.println(response.getBody()); - System.out.println(response.getHeaders()); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Retrieve address whitelist mail settings -// GET /mail_settings/address_whitelist - - -public class Example { - public static void main(String[] args) throws IOException { - try { - SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); - Request request = new Request(); - request.setMethod(Method.GET); - request.setEndpoint("mail_settings/address_whitelist"); - Response response = sg.api(request); - System.out.println(response.getStatusCode()); - System.out.println(response.getBody()); - System.out.println(response.getHeaders()); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Update BCC mail settings -// PATCH /mail_settings/bcc - - -public class Example { - public static void main(String[] args) throws IOException { - try { - SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); - Request request = new Request(); - request.setMethod(Method.PATCH); - request.setEndpoint("mail_settings/bcc"); - request.setBody("{\"enabled\":false,\"email\":\"email@example.com\"}"); - Response response = sg.api(request); - System.out.println(response.getStatusCode()); - System.out.println(response.getBody()); - System.out.println(response.getHeaders()); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Retrieve all BCC mail settings -// GET /mail_settings/bcc - - -public class Example { - public static void main(String[] args) throws IOException { - try { - SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); - Request request = new Request(); - request.setMethod(Method.GET); - request.setEndpoint("mail_settings/bcc"); - Response response = sg.api(request); - System.out.println(response.getStatusCode()); - System.out.println(response.getBody()); - System.out.println(response.getHeaders()); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Update bounce purge mail settings -// PATCH /mail_settings/bounce_purge - - -public class Example { - public static void main(String[] args) throws IOException { - try { - SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); - Request request = new Request(); - request.setMethod(Method.PATCH); - request.setEndpoint("mail_settings/bounce_purge"); - request.setBody("{\"hard_bounces\":5,\"soft_bounces\":5,\"enabled\":true}"); - Response response = sg.api(request); - System.out.println(response.getStatusCode()); - System.out.println(response.getBody()); - System.out.println(response.getHeaders()); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Retrieve bounce purge mail settings -// GET /mail_settings/bounce_purge - - -public class Example { - public static void main(String[] args) throws IOException { - try { - SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); - Request request = new Request(); - request.setMethod(Method.GET); - request.setEndpoint("mail_settings/bounce_purge"); - Response response = sg.api(request); - System.out.println(response.getStatusCode()); - System.out.println(response.getBody()); - System.out.println(response.getHeaders()); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Update footer mail settings -// PATCH /mail_settings/footer - - -public class Example { - public static void main(String[] args) throws IOException { - try { - SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); - Request request = new Request(); - request.setMethod(Method.PATCH); - request.setEndpoint("mail_settings/footer"); - request.setBody("{\"html_content\":\"...\",\"enabled\":true,\"plain_content\":\"...\"}"); - Response response = sg.api(request); - System.out.println(response.getStatusCode()); - System.out.println(response.getBody()); - System.out.println(response.getHeaders()); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Retrieve footer mail settings -// GET /mail_settings/footer - - -public class Example { - public static void main(String[] args) throws IOException { - try { - SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); - Request request = new Request(); - request.setMethod(Method.GET); - request.setEndpoint("mail_settings/footer"); - Response response = sg.api(request); - System.out.println(response.getStatusCode()); - System.out.println(response.getBody()); - System.out.println(response.getHeaders()); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Update forward bounce mail settings -// PATCH /mail_settings/forward_bounce - - -public class Example { - public static void main(String[] args) throws IOException { - try { - SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); - Request request = new Request(); - request.setMethod(Method.PATCH); - request.setEndpoint("mail_settings/forward_bounce"); - request.setBody("{\"enabled\":true,\"email\":\"example@example.com\"}"); - Response response = sg.api(request); - System.out.println(response.getStatusCode()); - System.out.println(response.getBody()); - System.out.println(response.getHeaders()); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Retrieve forward bounce mail settings -// GET /mail_settings/forward_bounce - - -public class Example { - public static void main(String[] args) throws IOException { - try { - SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); - Request request = new Request(); - request.setMethod(Method.GET); - request.setEndpoint("mail_settings/forward_bounce"); - Response response = sg.api(request); - System.out.println(response.getStatusCode()); - System.out.println(response.getBody()); - System.out.println(response.getHeaders()); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Update forward spam mail settings -// PATCH /mail_settings/forward_spam - - -public class Example { - public static void main(String[] args) throws IOException { - try { - SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); - Request request = new Request(); - request.setMethod(Method.PATCH); - request.setEndpoint("mail_settings/forward_spam"); - request.setBody("{\"enabled\":false,\"email\":\"\"}"); - Response response = sg.api(request); - System.out.println(response.getStatusCode()); - System.out.println(response.getBody()); - System.out.println(response.getHeaders()); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Retrieve forward spam mail settings -// GET /mail_settings/forward_spam - - -public class Example { - public static void main(String[] args) throws IOException { - try { - SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); - Request request = new Request(); - request.setMethod(Method.GET); - request.setEndpoint("mail_settings/forward_spam"); - Response response = sg.api(request); - System.out.println(response.getStatusCode()); - System.out.println(response.getBody()); - System.out.println(response.getHeaders()); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Update plain content mail settings -// PATCH /mail_settings/plain_content - - -public class Example { - public static void main(String[] args) throws IOException { - try { - SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); - Request request = new Request(); - request.setMethod(Method.PATCH); - request.setEndpoint("mail_settings/plain_content"); - request.setBody("{\"enabled\":false}"); - Response response = sg.api(request); - System.out.println(response.getStatusCode()); - System.out.println(response.getBody()); - System.out.println(response.getHeaders()); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Retrieve plain content mail settings -// GET /mail_settings/plain_content - - -public class Example { - public static void main(String[] args) throws IOException { - try { - SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); - Request request = new Request(); - request.setMethod(Method.GET); - request.setEndpoint("mail_settings/plain_content"); - Response response = sg.api(request); - System.out.println(response.getStatusCode()); - System.out.println(response.getBody()); - System.out.println(response.getHeaders()); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Update spam check mail settings -// PATCH /mail_settings/spam_check - - -public class Example { - public static void main(String[] args) throws IOException { - try { - SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); - Request request = new Request(); - request.setMethod(Method.PATCH); - request.setEndpoint("mail_settings/spam_check"); - request.setBody("{\"url\":\"url\",\"max_score\":5,\"enabled\":true}"); - Response response = sg.api(request); - System.out.println(response.getStatusCode()); - System.out.println(response.getBody()); - System.out.println(response.getHeaders()); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Retrieve spam check mail settings -// GET /mail_settings/spam_check - - -public class Example { - public static void main(String[] args) throws IOException { - try { - SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); - Request request = new Request(); - request.setMethod(Method.GET); - request.setEndpoint("mail_settings/spam_check"); - Response response = sg.api(request); - System.out.println(response.getStatusCode()); - System.out.println(response.getBody()); - System.out.println(response.getHeaders()); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Update template mail settings -// PATCH /mail_settings/template - - -public class Example { - public static void main(String[] args) throws IOException { - try { - SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); - Request request = new Request(); - request.setMethod(Method.PATCH); - request.setEndpoint("mail_settings/template"); - request.setBody("{\"html_content\":\"<% body %>\",\"enabled\":true}"); - Response response = sg.api(request); - System.out.println(response.getStatusCode()); - System.out.println(response.getBody()); - System.out.println(response.getHeaders()); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Retrieve legacy template mail settings -// GET /mail_settings/template - - -public class Example { - public static void main(String[] args) throws IOException { - try { - SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); - Request request = new Request(); - request.setMethod(Method.GET); - request.setEndpoint("mail_settings/template"); - Response response = sg.api(request); - System.out.println(response.getStatusCode()); - System.out.println(response.getBody()); - System.out.println(response.getHeaders()); - } catch (IOException ex) { - throw ex; - } - } -} - diff --git a/src/main/java/com/sendgrid/helpers/mail/objects/BccSettings.java b/src/main/java/com/sendgrid/helpers/mail/objects/BccSettings.java index 37be0866..7d3d1d64 100644 --- a/src/main/java/com/sendgrid/helpers/mail/objects/BccSettings.java +++ b/src/main/java/com/sendgrid/helpers/mail/objects/BccSettings.java @@ -9,7 +9,7 @@ * automatically sent to the specified email address * for every email that is sent. */ -@JsonInclude(Include.NON_DEFAULT) +@JsonInclude(Include.NON_EMPTY) public class BccSettings { @JsonProperty("enable") private boolean enable; @JsonProperty("email") private String email; diff --git a/src/main/java/com/sendgrid/helpers/mail/objects/ClickTrackingSetting.java b/src/main/java/com/sendgrid/helpers/mail/objects/ClickTrackingSetting.java index 2c139cda..b8bd4d30 100644 --- a/src/main/java/com/sendgrid/helpers/mail/objects/ClickTrackingSetting.java +++ b/src/main/java/com/sendgrid/helpers/mail/objects/ClickTrackingSetting.java @@ -9,6 +9,7 @@ * Settings to determine how you would like to track the * metrics of how your recipients interact with your email. */ +@JsonInclude(Include.NON_EMPTY) public class ClickTrackingSetting { @JsonProperty("enable") private boolean enable; @JsonProperty("enable_text") private boolean enableText; diff --git a/src/main/java/com/sendgrid/helpers/mail/objects/FooterSetting.java b/src/main/java/com/sendgrid/helpers/mail/objects/FooterSetting.java index 1428b66b..dc965d66 100644 --- a/src/main/java/com/sendgrid/helpers/mail/objects/FooterSetting.java +++ b/src/main/java/com/sendgrid/helpers/mail/objects/FooterSetting.java @@ -8,7 +8,7 @@ * An object representing the default footer * that you would like included on every email. */ -@JsonInclude(Include.NON_DEFAULT) +@JsonInclude(Include.NON_EMPTY) public class FooterSetting { @JsonProperty("enable") private boolean enable; @JsonProperty("text") private String text; diff --git a/src/main/java/com/sendgrid/helpers/mail/objects/GoogleAnalyticsSetting.java b/src/main/java/com/sendgrid/helpers/mail/objects/GoogleAnalyticsSetting.java index eac91899..3f98636a 100644 --- a/src/main/java/com/sendgrid/helpers/mail/objects/GoogleAnalyticsSetting.java +++ b/src/main/java/com/sendgrid/helpers/mail/objects/GoogleAnalyticsSetting.java @@ -7,7 +7,7 @@ /** * An object configuring the tracking provided by Google Analytics. */ -@JsonInclude(Include.NON_DEFAULT) +@JsonInclude(Include.NON_EMPTY) public class GoogleAnalyticsSetting { @JsonProperty("enable") private boolean enable; @JsonProperty("utm_source") private String campaignSource; diff --git a/src/main/java/com/sendgrid/helpers/mail/objects/OpenTrackingSetting.java b/src/main/java/com/sendgrid/helpers/mail/objects/OpenTrackingSetting.java index deba6d33..bbddd482 100644 --- a/src/main/java/com/sendgrid/helpers/mail/objects/OpenTrackingSetting.java +++ b/src/main/java/com/sendgrid/helpers/mail/objects/OpenTrackingSetting.java @@ -10,7 +10,7 @@ * pixel image in the body of the content. When the pixel is * loaded, we can log that the email was opened. */ -@JsonInclude(Include.NON_DEFAULT) +@JsonInclude(Include.NON_EMPTY) public class OpenTrackingSetting { @JsonProperty("enable") private boolean enable; @JsonProperty("substitution_tag") private String substitutionTag; diff --git a/src/main/java/com/sendgrid/helpers/mail/objects/SpamCheckSetting.java b/src/main/java/com/sendgrid/helpers/mail/objects/SpamCheckSetting.java index dbd43955..f0c6ec9f 100644 --- a/src/main/java/com/sendgrid/helpers/mail/objects/SpamCheckSetting.java +++ b/src/main/java/com/sendgrid/helpers/mail/objects/SpamCheckSetting.java @@ -8,7 +8,7 @@ * A setting object that allows you to test the content of * your email for spam. */ -@JsonInclude(Include.NON_DEFAULT) +@JsonInclude(Include.NON_EMPTY) public class SpamCheckSetting { @JsonProperty("enable") private boolean enable; @JsonProperty("threshold") private int spamThreshold; diff --git a/src/main/java/com/sendgrid/helpers/mail/objects/SubscriptionTrackingSetting.java b/src/main/java/com/sendgrid/helpers/mail/objects/SubscriptionTrackingSetting.java index 304eb916..3f740266 100644 --- a/src/main/java/com/sendgrid/helpers/mail/objects/SubscriptionTrackingSetting.java +++ b/src/main/java/com/sendgrid/helpers/mail/objects/SubscriptionTrackingSetting.java @@ -11,7 +11,7 @@ * would like to specify the location of the link within your * email, you may use the substitution_tag. */ -@JsonInclude(Include.NON_DEFAULT) +@JsonInclude(Include.NON_EMPTY) public class SubscriptionTrackingSetting { @JsonProperty("enable") private boolean enable; @JsonProperty("text") private String text; diff --git a/src/test/java/com/sendgrid/LicenseTest.java b/src/test/java/com/sendgrid/LicenseTest.java index 82a6432d..1e06bf71 100644 --- a/src/test/java/com/sendgrid/LicenseTest.java +++ b/src/test/java/com/sendgrid/LicenseTest.java @@ -13,7 +13,7 @@ public class LicenseTest { @Test public void testLicenseShouldHaveCorrectYear() throws IOException { String copyrightText = null; - try (BufferedReader br = new BufferedReader(new FileReader("./LICENSE.txt"))) { + try (BufferedReader br = new BufferedReader(new FileReader("./LICENSE.md"))) { for (String line; (line = br.readLine()) != null; ) { if (line.startsWith("Copyright")) { copyrightText = line; diff --git a/src/test/java/com/sendgrid/helpers/mail/objects/SettingsSerializationTest.java b/src/test/java/com/sendgrid/helpers/mail/objects/SettingsSerializationTest.java new file mode 100644 index 00000000..74e6c8b5 --- /dev/null +++ b/src/test/java/com/sendgrid/helpers/mail/objects/SettingsSerializationTest.java @@ -0,0 +1,86 @@ +package com.sendgrid.helpers.mail.objects; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.sendgrid.BccSettings; +import com.sendgrid.ClickTrackingSetting; +import com.sendgrid.FooterSetting; +import com.sendgrid.GoogleAnalyticsSetting; +import com.sendgrid.OpenTrackingSetting; +import com.sendgrid.SpamCheckSetting; +import com.sendgrid.SubscriptionTrackingSetting; +import org.junit.Assert; +import org.junit.Test; + +public class SettingsSerializationTest { + + private ObjectMapper mapper = new ObjectMapper(); + + @Test + public void testOpenTrackingSettingSerialization() throws Exception { + OpenTrackingSetting setting = new OpenTrackingSetting(); + setting.setEnable(false); + + String json = mapper.writeValueAsString(setting); + Assert.assertEquals(json, "{\"enable\":false}"); + } + + @Test + public void testClickTrackingSettingSerialization() throws Exception { + ClickTrackingSetting setting = new ClickTrackingSetting(); + setting.setEnable(false); + + String json = mapper.writeValueAsString(setting); + System.out.println(json); + Assert.assertEquals(json, "{\"enable\":false,\"enable_text\":false}"); + } + + @Test + public void testSubscriptionTrackingSettingSerialization() throws Exception { + SubscriptionTrackingSetting setting = new SubscriptionTrackingSetting(); + setting.setEnable(false); + + String json = mapper.writeValueAsString(setting); + System.out.println(json); + Assert.assertEquals(json, "{\"enable\":false}"); + } + + @Test + public void testGoogleAnalyticsTrackingSettingSerialization() throws Exception { + GoogleAnalyticsSetting setting = new GoogleAnalyticsSetting(); + setting.setEnable(false); + + String json = mapper.writeValueAsString(setting); + System.out.println(json); + Assert.assertEquals(json, "{\"enable\":false}"); + } + + @Test + public void testSpamCheckSettingSerialization() throws Exception { + SpamCheckSetting setting = new SpamCheckSetting(); + setting.setEnable(false); + + String json = mapper.writeValueAsString(setting); + System.out.println(json); + Assert.assertEquals(json, "{\"enable\":false,\"threshold\":0}"); + } + + @Test + public void testFooterSettingSerialization() throws Exception { + FooterSetting setting = new FooterSetting(); + setting.setEnable(false); + + String json = mapper.writeValueAsString(setting); + System.out.println(json); + Assert.assertEquals(json, "{\"enable\":false}"); + } + + @Test + public void testBccSettingsSerialization() throws Exception { + BccSettings settings = new BccSettings(); + settings.setEnable(false); + + String json = mapper.writeValueAsString(settings); + System.out.println(json); + Assert.assertEquals(json, "{\"enable\":false}"); + } +}