diff --git a/.codeclimate.yml b/.codeclimate.yml new file mode 100644 index 00000000..5b82009c --- /dev/null +++ b/.codeclimate.yml @@ -0,0 +1,8 @@ +--- +plugins: + checkstyle: + enabled: true + fixme: + enabled: true + pmd: + enabled: true diff --git a/.env_sample b/.env_sample new file mode 100644 index 00000000..937e999d --- /dev/null +++ b/.env_sample @@ -0,0 +1 @@ +export SENDGRID_API_KEY='' diff --git a/.github/PULL_REQUEST_TEMPLATE b/.github/PULL_REQUEST_TEMPLATE new file mode 100644 index 00000000..bd65d2ff --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE @@ -0,0 +1,24 @@ + +# Fixes # + +### Checklist +- [ ] I have made a material change to the repo (functionality, testing, spelling, grammar) +- [ ] I have read the [Contribution Guide] and my PR follows them. +- [ ] I updated my branch with the development branch. +- [ ] I have added tests that prove my fix is effective or that my feature works +- [ ] I have added necessary documentation about the functionality in the appropriate .md file +- [ ] I have added in line documentation to the code I modified + +### Short description of what this PR does: +- +- + +If you have questions, please send an email to [Sendgrid](mailto:dx@sendgrid.com), or file a Github Issue in this repository. \ No newline at end of file diff --git a/.gitignore b/.gitignore index 1d9351de..551957d8 100644 --- a/.gitignore +++ b/.gitignore @@ -9,4 +9,9 @@ repo gradle.properties target *.class -examples/Example.java \ No newline at end of file +examples/Example.java +.settings +.classpath +.project +.env +.vscode \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 881ccd72..944f6df3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,12 +1,21 @@ language: java -sudo: false -jdk: -- oraclejdk8 -- oraclejdk7 -- openjdk7 +matrix: + include: + - jdk: openjdk8 + - jdk: oraclejdk8 +before_script: +- "./scripts/startPrism.sh &" +- sleep 20 +before_install: + - cat /etc/hosts # optionally check the content *before* + - sudo hostname "$(hostname | cut -c1-63)" + - sed -e "s/^\\(127\\.0\\.0\\.1.*\\)/\\1 $(hostname | cut -c1-63)/" /etc/hosts > /tmp/hosts + - sudo mv /tmp/hosts /etc/hosts + - cat /etc/hosts # optionally check the content *after* after_script: -- "./gradlew build" -- "./scripts/s3upload.sh" + - lsof -i :4010 -S # adds some debugging statements + - "./gradlew build" + - "./scripts/upload.sh" env: global: - S3_POLICY: ewogICJleHBpcmF0aW9uIjogIjIxMDAtMDEtMDFUMTI6MDA6MDAuMDAwWiIsCiAgImNvbmRpdGlvbnMiOiBbCiAgICB7ImFjbCI6ICJwdWJsaWMtcmVhZCIgfSwKICAgIHsiYnVja2V0IjogInNlbmRncmlkLW9wZW4tc291cmNlIiB9LAogICAgWyJzdGFydHMtd2l0aCIsICIka2V5IiwgInNlbmRncmlkLWphdmEvIl0sCiAgICBbImNvbnRlbnQtbGVuZ3RoLXJhbmdlIiwgMjA0OCwgMjY4NDM1NDU2XSwKICAgIFsiZXEiLCAiJENvbnRlbnQtVHlwZSIsICJhcHBsaWNhdGlvbi96aXAiXQogIF0KfQo= diff --git a/CHANGELOG.md b/CHANGELOG.md index d80ae836..27e2adc1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,144 @@ # Change Log All notable changes to this project will be documented in this file. +## [4.3.0] - 2018-10-11 +### Added +- [PR #449](https://github.com/sendgrid/sendgrid-java/pull/449/files): Dynamic Templates support -- BIG thanks to [Marcus Vinícius](https://github.com/Markuus13) +- [PR #451](https://github.com/sendgrid/sendgrid-java/pull/451/files): Added CodeTriage tag -- BIG thanks to [Anshul Singhal](https://github.com/af4ro) +- [PR #453](https://github.com/sendgrid/sendgrid-java/pull/453/files): Documentation readability update -- BIG thanks to [Anshul Singhal](https://github.com/af4ro) +- [PR #461](https://github.com/sendgrid/sendgrid-java/pull/461/files): Update README to use implementation instead of compile -- BIG thanks to [Rosário Pereira Fernandes](https://github.com/rosariopfernandes) +- [PR #463](https://github.com/sendgrid/sendgrid-java/pull/463/files): Link to the online version of CLA in README.md -- BIG thanks to [Bharat Raghunathan](https://github.com/Bharat123rox) + +### Fix +- [PR #358](https://github.com/sendgrid/sendgrid-java/pull/358): Fixing similar code issue in examples/ips/ips.java -- BIG thanks to [Julian Jacques Maurer](https://github.com/derjayjay) +- [PR #475](https://github.com/sendgrid/sendgrid-java/pull/475): Fix formatting of README in examples/accesssettings -- BIG thanks to [Nathan Seebarran](https://github.com/nathan78906) + +## [4.2.1] - 2018-05-08 +### Security Fix +- Update to latest Jackson recommended dependency, based on [this article](https://medium.com/@cowtowncoder/on-jackson-cves-dont-panic-here-is-what-you-need-to-know-54cd0d6e8062). + +## [4.2.0] - 2018-05-04 +### Added +- [PR #275](https://github.com/sendgrid/sendgrid-java/pull/275/files): Add a way to verify that the content doesn't contain sensitive information -- BIG thanks to [Diego Camargo](https://github.com/belfazt) +- [PR #249](https://github.com/sendgrid/sendgrid-java/pull/249): Add optional rate limit support -- BIG thanks to [Andy Trimble](https://github.com/andy-trimble) +- [PR #379](https://github.com/sendgrid/sendgrid-java/pull/379): Break up the examples in examples/subusers/subusers.java to their own files -- BIG thanks to [huytranrjc](https://github.com/huytranrjc) +- [PR #365](https://github.com/sendgrid/sendgrid-java/pull/365): Test to check year in license file -- BIG thanks to [Alex](https://github.com/pushkyn) +- [PR #345](https://github.com/sendgrid/sendgrid-java/pull/345): Add .codeclimate.yml file -- BIG thanks to [Rostyslav Zatserkovnyi](https://github.com/rzats) +- [PR #319](https://github.com/sendgrid/sendgrid-java/pull/319): Add .env_sample file -- BIG thanks to [Thiago Barbato](https://github.com/thiagobbt) +- [PR #223](https://github.com/sendgrid/sendgrid-java/pull/223): The license file is now in the release jar -- BIG thanks to [sccalabr](https://github.com/sccalabr) +- [PR #224](https://github.com/sendgrid/sendgrid-java/pull/224): Adding SendGridApi interface -- BIG thanks to [sccalabr](https://github.com/sccalabr) + +### Fix +- [PR #410](https://github.com/sendgrid/sendgrid-java/pull/410): Update Jackson dependencies to the latest version -- BIG thanks to [Dmitry Avershin](https://github.com/dmitraver) +- [PR #380](https://github.com/sendgrid/sendgrid-java/pull/380): Fix "similar-code" issue in examples/whitelabel/ips.java -- BIG thanks to [huytranrjc](https://github.com/huytranrjc) +- [PR #255](https://github.com/sendgrid/sendgrid-java/pull/225): Fix Mail deserialization issue -- BIG thanks to [sccalabr](https://github.com/sccalabr) +- [PR #359](https://github.com/sendgrid/sendgrid-java/pull/359): Fix code issue in examples/suppression/suppression.java -- BIG thanks to [Alex](https://github.com/pushkyn) +- [PR #228](https://github.com/sendgrid/sendgrid-java/pull/228): Changes serialization type from default to non-empty -- BIG thanks to [Dmitry Avershin](https://github.com/dmitraver) +- [PR #373](https://github.com/sendgrid/sendgrid-java/pull/373): Fix file_lines issue in examples/mailsettings/mailsettings.java -- BIG thanks to [Mithun Sasidharan](https://github.com/mithunsasidharan) + + +## [4.1.2] - 2017-10-30 +### Added +- PR #220 Alway serialize click-tracking parameters. +- BIG thanks to [Mattia Barbon](https://github.com/mbarbon) + +## [4.1.1] - 2017-10-10 +### Added +- PR #247 Added Javadocs. +- BIG thanks to [Andy Trimble](https://github.com/andy-trimble) + +## [4.1.0] - 2017-08-16 +### Added +- PR #211 Return empty collections in place of nulls +- BIG thanks to [Antonio Bucciol](https://github.com/TBuc) + +## [4.0.1] - 2017-05-22 +### Fix +- PR #199 Return correct Email in getFrom +- BIG thanks to [Jared Dellitt](https://github.com/jareddellitt) + +## [4.0.0] - 2017-04-18 +### BREAKING CHANGE +- PR #162 Update java http client dependency to [4.1.0 from 2.3.4](https://github.com/sendgrid/java-http-client/releases) +- BIG thanks to [Diego Camargo](https://github.com/belfazt) for the pull request! +- The breaking change is that variables that were public are now private and accessible only via getters and setters +- The `Request` object attributes are now only accessible through getters/setters +- `request.method` is now `request.setMethod(string)` +- `request.endpoint` is now `request.setEndpoint(string)` +- `request.body` is now `request.setBody(string)` +- The `Response` object attributes are now only accessible through getters/setters +- `response.statusCode` is now `response.getStatusCode()` +- `response.body` is now `response.getBody()` +- `response.headers` is now `response.getHeaders()` +- Adding a query parameter goes from: + +```java +Map queryParams = new HashMap(); +request.addQueryParam("limit", "1"); +queryParams.put("limit", "1"); +request.queryParams = queryParams; +``` + +to: + +```java +request.addQueryParam("limit", "1"); +``` + +## [3.2.1] - 2017-04-13 +### Added +- PR #175 +- Simplified `makeCall()` method. +- BIG thanks to [Rafał Wrzeszcz](https://github.com/rafalwrzeszcz) for the pull request! + +## [3.2.0] - 2017-03-22 +### Added +- PR #160 +- [Enhancement] Adds an attachment builder that supports InputStream content +- BIG thanks to [Dmitry Avershin](https://github.com/dmitraver) for the pull request! + +## [3.1.0] - 2016-10-11 +### Added +- PR #158, Solves #138 +- [Enhancement] allow using custom Client, http proxy support +- BIG thanks to [David Maicher](https://github.com/dmaicher) for the pull request! + +## [3.0.9] - 2016-08-24 +### Added +- Table of Contents in the README +- Added a [USE_CASES.md](https://github.com/sendgrid/sendgrid-java/blob/master/USE_CASES.md) section, with the first use case example for transactional templates + +## [3.0.8] - 2016-08-09 +### Fixed +- Updated dependency for [java-http-client](https://github.com/sendgrid/java-http-client/releases/tag/v2.3.4) +- [Pull #7](https://github.com/sendgrid/java-http-client/pull/7): Fix Response Charset to UTF-8 +- Fixes [issue #6](https://github.com/sendgrid/java-http-client/issues/6): Multi-byte character got garbled on received mail +- BIG thanks to [Yoichi Kikuta](https://github.com/kikutaro) for the pull request! + +## [3.0.7] - 2016-08-08 +### Added +- Updated dependency for [java-http-client](https://github.com/sendgrid/java-http-client/releases/tag/v2.3.3) +- Pull request [#11](https://github.com/sendgrid/java-http-client/pull/11) +- Solves [issue #10](https://github.com/sendgrid/java-http-client/issues/10): Improve Error Handling +- Now error messages are passed through from the SendGrid server +- BIG thanks to [shuron](https://github.com/shuron) / [Alexander Holbreich](https://github.com/aholbreich) for the pull request! + +## [3.0.6] - 2016-07-26 +### Added +- [Troubleshooting](https://github.com/sendgrid/sendgrid-python/blob/master/TROUBLESHOOTING.md) section + +## [3.0.5] - 2016-07-20 +### Added +- README updates +- Update introduction blurb to include information regarding our forward path +- Update the v3 /mail/send example to include non-helper usage +- Update the generic v3 example to include non-fluent interface usage + +## [3.0.4] - 2016-07-19 +### Fixed +- [Fix for issue #120](https://github.com/sendgrid/sendgrid-java/issues/120): Unsupported Media Type if subject has letters with accent (like 'é' ) +- Updated [java-http-client](https://github.com/sendgrid/java-http-client) dependency to [2.3.2](https://github.com/sendgrid/java-http-client/releases/tag/v2.3.2) + ## [3.0.3] - 2016-07-12 ### Added - Update docs, unit tests and examples to include Sender ID @@ -21,7 +159,7 @@ All notable changes to this project will be documented in this file. ## [2.2.2] - 2015-5-23 ### Fixed -- Subsitution orders being swapped via [#65](https://github.com/sendgrid/sendgrid-java/pull/65) +- Substitution orders being swapped via [#65](https://github.com/sendgrid/sendgrid-java/pull/65) ## [2.2.1] - 2015-5-14 ### Changed diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 00000000..a6ad51a7 --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,42 @@ + + # SendGrid Community Code of Conduct + + The SendGrid open source community is made up of members from around the globe with a diverse set of skills, personalities, and experiences. It is through these differences that our community experiences successes and continued growth. When you're working with members of the community, we encourage you to follow these guidelines, which help steer our interactions and strive to maintain a positive, successful and growing community. + + ### Be Open + Members of the community are open to collaboration, whether it's on pull requests, code reviews, approvals, issues or otherwise. We're receptive to constructive comments and criticism, as the experiences and skill sets of all members contribute to the whole of our efforts. We're accepting of all who wish to take part in our activities, fostering an environment where anyone can participate, and everyone can make a difference. + + ### Be Considerate + Members of the community are considerate of their peers, which include other contributors and users of SendGrid. We're thoughtful when addressing the efforts of others, keeping in mind that often the labor was completed with the intent of the good of the community. We're attentive in our communications, whether in person or online, and we're tactful when approaching differing views. + + ### Be Respectful + Members of the community are respectful. We're respectful of others, their positions, their skills, their commitments and their efforts. We're respectful of the volunteer efforts that permeate the SendGrid community. We're respectful of the processes outlined in the community, and we work within them. When we disagree, we are courteous in raising our issues. Overall, we're good to each other. We contribute to this community not because we have to, but because we want to. If we remember that, these guidelines will come naturally. + + ## Additional Guidance + + ### Disclose Potential Conflicts of Interest + Community discussions often involve interested parties. We expect participants to be aware when they are conflicted due to employment or other projects they are involved in and disclose those interests to other project members. When in doubt, over-disclose. Perceived conflicts of interest are important to address so that the community’s decisions are credible even when unpopular, difficult or favorable to the interests of one group over another. + + ### Interpretation + This Code is not exhaustive or complete. It is not a rulebook; it serves to distill our common understanding of a collaborative, shared environment and goals. We expect it to be followed in spirit as much as in the letter. When in doubt, try to abide by [SendGrid’s cultural values](https://sendgrid.com/blog/employee-engagement-the-4h-way) defined by our “4H’s”: Happy, Hungry, Humble and Honest. + + ### Enforcement + Most members of the SendGrid community always comply with this Code, not because of the existence of this Code, but because they have long experience participating in open source communities where the conduct described above is normal and expected. However, failure to observe this Code may be grounds for suspension, reporting the user for abuse or changing permissions for outside contributors. + + ## If you have concerns about someone’s conduct + **Initiate Direct Contact** - It is always appropriate to email a community member (if contact information is available), mention that you think their behavior was out of line, and (if necessary) point them to this Code. + + **Discuss Publicly** - Discussing publicly is always acceptable. Note, though, that approaching the person directly may be better, as it tends to make them less defensive, and it respects the time of other community members, so you probably want to try direct contact first. + + **Contact the Moderators** - You can reach the SendGrid moderators by emailing dx@sendgrid.com. + + ## Submission to SendGrid Repositories + Finally, just a reminder, changes to the SendGrid repositories will only be accepted upon completion of the [SendGrid Contributor Agreement](https://cla.sendgrid.com). + + ## Attribution + + SendGrid thanks the following, on which it draws for content and inspiration: + + * [Python Community Code of Conduct](https://www.python.org/psf/codeofconduct/) + * [Open Source Initiative General Code of Conduct](https://opensource.org/codeofconduct) + * [Apache Code of Conduct](https://www.apache.org/foundation/policies/conduct.html) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index c8c4e2e4..230fab0b 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,14 +1,20 @@ -Hello! Thank you for choosing to help contribute to one of the SendGrid open source libraries. There are many ways you can contribute and help is always welcome. We simply ask that you follow the following contribution policies. - -- [CLAs and CCLAs](#cla) -- [Roadmap & Milestones](#roadmap) -- [Feature Request](#feature_request) -- [Submit a Bug Report](#submit_a_bug_report) -- [Improvements to the Codebase](#improvements_to_the_codebase) -- [Understanding the Code Base](#understanding_the_codebase) +Hello! Thank you for choosing to help contribute to one of the SendGrid open source libraries. There are many ways you can contribute and help is always welcome. We simply ask that you follow the following contribution policies. + +- [CLAs and CCLAs](#clas-and-cclas) +- [Feature Request](#feature-request) +- [Submit a Bug Report](#submit-a-bug-report) + - [Please use our Bug Report Template](#please-use-our-bug-report-template) +- [Improvements to the Codebase](#improvements-to-the-codebase) + - [Development Environment](#development-environment) + - [Install and Run Locally](#install-and-run-locally) + - [Prerequisites](#prerequisites) + - [Initial setup:](#initial-setup) +- [Environment Variables](#environment-variables) + - [Execute:](#execute) +- [Understanding the Code Base](#understanding-the-code-base) - [Testing](#testing) -- [Style Guidelines & Naming Conventions](#style_guidelines_and_naming_conventions) -- [Creating a Pull Request](#creating_a_pull_request) +- [Style Guidelines & Naming Conventions](#style-guidelines--naming-conventions) +- [Creating a Pull Request](#creating-a-pull-request) We use [Milestones](https://github.com/sendgrid/sendgrid-java/milestones) to help define current roadmaps, please feel free to grab an issue from the current milestone. Please indicate that you have begun work on it to avoid collisions. Once a PR is made, community review, comments, suggestions and additional PRs are welcomed and encouraged. @@ -16,17 +22,17 @@ We use [Milestones](https://github.com/sendgrid/sendgrid-java/milestones) to hel ## CLAs and CCLAs -Before you get started, SendGrid requires that a SendGrid Contributor License Agreement (CLA) or a SendGrid Company Contributor Licensing Agreement (CCLA) be filled out by every contributor to a SendGrid open source project. +Before you get started, SendGrid requires that a SendGrid Contributor License Agreement (CLA) be filled out by every contributor to a SendGrid open source project. -Our goal with the CLA and CCLA is to clarify the rights of our contributors and reduce other risks arising from inappropriate contributions. The CLA also clarifies the rights SendGrid holds in each contribution and helps to avoid misunderstandings over what rights each contributor is required to grant to SendGrid when making a contribution. In this way the CLA and CCLA encourage broad participation by our open source community and help us build strong open source projects, free from any individual contributor withholding or revoking rights to any contribution. +Our goal with the CLA is to clarify the rights of our contributors and reduce other risks arising from inappropriate contributions. The CLA also clarifies the rights SendGrid holds in each contribution and helps to avoid misunderstandings over what rights each contributor is required to grant to SendGrid when making a contribution. In this way the CLA encourages broad participation by our open source community and helps us build strong open source projects, free from any individual contributor withholding or revoking rights to any contribution. -SendGrid does not merge a pull request made against a SendGrid open source project until that pull request is associated with a signed CLA (or CCLA). Copies of the CLA and CCLA are available [here](https://drive.google.com/a/sendgrid.com/file/d/0B0PlcM9qA91LN2VEUTJWU2RIVXc/view). +SendGrid does not merge a pull request made against a SendGrid open source project until that pull request is associated with a signed CLA. Copies of the CLA are available [here](https://gist.github.com/SendGridDX/98b42c0a5d500058357b80278fde3be8#file-sendgrid_cla). -You may submit your completed [CLA or CCLA](https://drive.google.com/a/sendgrid.com/file/d/0B0PlcM9qA91LN2VEUTJWU2RIVXc/view) to SendGrid at [dx@sendgrid.com](mailto:dx@sendgrid.com). SendGrid will then confirm you are ready to begin making contributions. +When you create a Pull Request, after a few seconds, a comment will appear with a link to the CLA. Click the link and fill out the brief form and then click the "I agree" button and you are all set. You will not be asked to re-sign the CLA unless we make a change. There are a few ways to contribute, which we'll enumerate below: - + ## Feature Request If you'd like to make a feature request, please read this section. @@ -36,7 +42,7 @@ The GitHub issue tracker is the preferred channel for library feature requests, - Please **search for existing issues** in order to ensure we don't have duplicate bugs/feature requests. - Please be respectful and considerate of others when commenting on issues - + ## Submit a Bug Report Note: DO NOT include your credentials in ANY code examples, descriptions, or media you make public. @@ -51,20 +57,22 @@ Before you decide to create a new issue, please try the following: ### Please use our Bug Report Template -In order to make the process easier, we've included a [sample bug report template](https://github.com/sendgrid/sendgrid-java/.github/ISSUE_TEMPLATE) (borrowed from [Ghost](https://github.com/TryGhost/Ghost/)). The template uses [GitHub flavored markdown](https://help.github.com/articles/github-flavored-markdown/) for formatting. +In order to make the process easier, we've included a [sample bug report template](https://github.com/sendgrid/sendgrid-java/blob/master/.github/ISSUE_TEMPLATE) (borrowed from [Ghost](https://github.com/TryGhost/Ghost/)). The template uses [GitHub flavored markdown](https://help.github.com/articles/github-flavored-markdown/) for formatting. - + ## Improvements to the Codebase We welcome direct contributions to the sendgrid-java code base. Thank you! +Please note that we utilize the [Gitflow Workflow](https://www.atlassian.com/git/tutorials/comparing-workflows/gitflow-workflow) for Git to help keep project development organized and consistent. + ### Development Environment ### #### Install and Run Locally #### ##### Prerequisites ##### -- Java 1.7 through 1.8 +- Java version Oracle JDK 7, 8 or OpenJDK 7 - [java-http-client](https://github.com/sendgrid/java-http-client) ##### Initial setup: ##### @@ -102,10 +110,10 @@ touch Example.java Add the example you want to test to Example.java, including the headers at the top of the file. ``` bash -javac -classpath ../repo/com/sendgrid/3.0.3/sendgrid-3.0.3-jar.jar:. Example.java && java -classpath ../repo/com/sendgrid/3.0.3/sendgrid-3.0.3-jar.jar:. Example +javac -classpath ../repo/com/sendgrid/4.3.0/sendgrid-4.3.0-jar.jar:. Example.java && java -classpath ../repo/com/sendgrid/4.3.0/sendgrid-4.3.0-jar.jar:. Example ``` - + ## Understanding the Code Base **/examples** @@ -129,11 +137,27 @@ All test files are in the [`tests`](https://github.com/sendgrid/sendgrid-java/tr For the purposes of contributing to this repo, please update the [`SendGridTest.java`](https://github.com/sendgrid/sendgrid-java/tree/master/src/test/java/com/sendgrid/SendGridTest.java) file with unit tests as you modify the code. -```bash -./gradlew test -i -``` +1. Download [prism](http://stoplight.io/platform/prism/) for your platform ([Mac OS X](https://github.com/stoplightio/prism/releases/download/v0.6.21/prism_darwin_amd64), [Linux](https://github.com/stoplightio/prism/releases/download/v0.6.21/prism_linux_amd64), [Windows](https://github.com/stoplightio/prism/releases/download/v0.6.21/prism_windows_amd64.exe)) and save the binary to the sendgrid-java directory (or any directory you would like. The sendgrid-java directory is chosen mostly for convenience.) + +1. Add execute permissions + + ```bash + chmod +x prism + ``` + +1. In a separate terminal, cd into the directory you chose for prism and start the sendgrid local server which the tests will use. - + ```bash + ./prism run --mock --list --spec https://raw.githubusercontent.com/sendgrid/sendgrid-oai/master/oai_stoplight.json + ``` + +1. Now you can run the test suite from the root of the project + + ```bash + ./gradlew test -i + ``` + + ## Style Guidelines & Naming Conventions Generally, we follow the style guidelines as suggested by the official language. However, we ask that you conform to the styles that already exist in the library. If you wish to deviate, please explain your reasoning. @@ -142,7 +166,9 @@ Please run your code through: - [FindBugs](http://findbugs.sourceforge.net/) - [CheckStyle](http://checkstyle.sourceforge.net/) with [Google's Java Style Guide](http://checkstyle.sourceforge.net/reports/google-java-style.html). -## Creating a Pull Request + +## Creating a Pull Request + 1. [Fork](https://help.github.com/fork-a-repo/) the project, clone your fork, and configure the remotes: @@ -150,8 +176,10 @@ Please run your code through: ```bash # Clone your fork of the repo into the current directory git clone https://github.com/sendgrid/sendgrid-java + # Navigate to the newly cloned directory - cd sendgrid-python + cd sendgrid-java + # Assign the original repo to a remote called "upstream" git remote add upstream https://github.com/sendgrid/sendgrid-java ``` @@ -167,7 +195,7 @@ Please run your code through: contain your feature, change, or fix: ```bash - git checkout -b + git checkout -b development ``` 4. Commit your changes in logical chunks. Please adhere to these [git commit @@ -180,10 +208,10 @@ Please run your code through: 4b. Create or update the example code that demonstrates the functionality of this change to the code. -5. Locally merge (or rebase) the upstream development branch into your topic branch: +5. Locally merge (or rebase) the upstream `development` branch into your topic branch: ```bash - git pull [--rebase] upstream master + git pull [--rebase] upstream development ``` 6. Push your topic branch up to your fork: @@ -193,6 +221,6 @@ Please run your code through: ``` 7. [Open a Pull Request](https://help.github.com/articles/using-pull-requests/) - with a clear title and description against the `master` branch. All tests must be passing before we will review the PR. + with a clear title and description against the `development` branch. All tests must be passing before we will review the PR. -If you have any additional questions, please feel free to [email](mailto:dx@sendgrid.com) us or create an issue in this repo. \ No newline at end of file +If you have any additional questions, please feel free to [email](mailto:dx@sendgrid.com) us or create an issue in this repo. diff --git a/LICENSE.txt b/LICENSE.md similarity index 96% rename from LICENSE.txt rename to LICENSE.md index 3e9812c6..7756fd61 100644 --- a/LICENSE.txt +++ b/LICENSE.md @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2013-2016 SendGrid +Copyright (c) 2013-2018 SendGrid, Inc. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 04800673..b4e1566f 100644 --- a/README.md +++ b/README.md @@ -1,41 +1,60 @@ -[![Travis Badge](https://travis-ci.org/sendgrid/sendgrid-java.svg?branch=master)](https://travis-ci.org/sendgrid/sendgrid-java) [![BuildStatus](https://maven-badges.herokuapp.com/maven-central/com.sendgrid/sendgrid-java/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.sendgrid/sendgrid-java) +![SendGrid Logo](https://uiux.s3.amazonaws.com/2016-logos/email-logo%402x.png) -**This library allows you to quickly and easily use the SendGrid Web API via Java.** +[![Travis Badge](https://travis-ci.org/sendgrid/sendgrid-java.svg?branch=master)](https://travis-ci.org/sendgrid/sendgrid-java) +[![Maven Central](https://img.shields.io/maven-central/v/com.sendgrid/sendgrid-java.svg)](http://mvnrepository.com/artifact/com.sendgrid/sendgrid-java) +[![Email Notifications Badge](https://dx.sendgrid.com/badge/java)](https://dx.sendgrid.com/newsletter/java) +[![Twitter Follow](https://img.shields.io/twitter/follow/sendgrid.svg?style=social&label=Follow)](https://twitter.com/sendgrid) +[![GitHub contributors](https://img.shields.io/github/contributors/sendgrid/sendgrid-java.svg)](https://github.com/sendgrid/sendgrid-java/graphs/contributors) +[![Open Source Helpers](https://www.codetriage.com/sendgrid/sendgrid-java/badges/users.svg)](https://www.codetriage.com/sendgrid/sendgrid-java) +[![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](./LICENSE.txt) -# Announcements +**NEW:** Subscribe to email [notifications](https://dx.sendgrid.com/newsletter/java) for releases and breaking changes. + +**This library allows you to quickly and easily use the SendGrid Web API v3 via Java.** -**BREAKING CHANGE as of 2016.06.14** +Version 3.X.X of this library provides full support for all SendGrid [Web API v3](https://sendgrid.com/docs/API_Reference/Web_API_v3/index.html) endpoints, including the new [v3 /mail/send](https://sendgrid.com/blog/introducing-v3mailsend-sendgrids-new-mail-endpoint). -Version `3.X.X` is a breaking change for the entire library. +This library represents the beginning of a new path for SendGrid. We want this library to be community driven and SendGrid led. We need your help to realize this goal. To help make sure we are building the right things in the right order, we ask that you create [issues](https://github.com/sendgrid/sendgrid-java/issues) and [pull requests](https://github.com/sendgrid/sendgrid-java/blob/master/CONTRIBUTING.md) or simply upvote or comment on existing issues or pull requests. -Version 3.X.X brings you full support for all Web API v3 endpoints. We -have the following resources to get you started quickly: +Please browse the rest of this README for further details. -- [SendGrid - Documentation](https://sendgrid.com/docs/API_Reference/Web_API_v3/index.html) -- [Usage - Documentation](https://github.com/sendgrid/sendgrid-java/tree/master/USAGE.md) -- [Example - Code](https://github.com/sendgrid/sendgrid-java/tree/master/examples) -- [Migration from v2 to v3](https://sendgrid.com/docs/Classroom/Send/v3_Mail_Send/how_to_migrate_from_v2_to_v3_mail_send.html) +We appreciate your continued support, thank you! -Thank you for your continued support! +# Table of Contents -All updates to this library is documented in our [CHANGELOG](https://github.com/sendgrid/sendgrid-java/blob/master/CHANGELOG.md). +* [Installation](#installation) +* [Quick Start](#quick-start) +* [Usage](#usage) +* [Use Cases](#use-cases) +* [Announcements](#announcements) +* [Roadmap](#roadmap) +* [How to Contribute](#contribute) +* [Troubleshooting](#troubleshooting) +* [About](#about) +* [License](#license) + # Installation -## Setup Environment Variables +## Prerequisites -First, get your free SendGrid account [here](https://sendgrid.com/free?source=sendgrid-java). +- Java version Oracle JDK 7, 8 or OpenJDK 7 +- The SendGrid service, starting at the [free level](https://sendgrid.com/free?source=sendgrid-java) -Next, update your environment with your [SENDGRID_API_KEY](https://app.sendgrid.com/settings/api_keys). +## Setup Environment Variables + +Update the development environment with your [SENDGRID_API_KEY](https://app.sendgrid.com/settings/api_keys), for example: +1. Copy the sample environment file to a new file +```bash +cp .env_sample .env +``` +2. Edit the new `.env` to add your API key +3. Source the `.env` file to set rhe variable in the current session ```bash -echo "export SENDGRID_API_KEY='YOUR_API_KEY'" > sendgrid.env -echo "sendgrid.env" >> .gitignore -source ./sendgrid.env +source .env ``` + ## Install Package Choose your installation method - Maven w/ Gradle (recommended), Maven or Jar file. @@ -48,7 +67,7 @@ Add the following to your build.gradle file in the root of your project. ... dependencies { ... - compile 'com.sendgrid:sendgrid-java:3.0.3' + implementation 'com.sendgrid:sendgrid-java:4.3.0' } repositories { @@ -57,12 +76,6 @@ repositories { ... ``` -Then import the library - in the file appropriate to your Java project. - -```java -import com.sendgrid.SendGrid; -``` - ### via Maven ``` @@ -73,21 +86,21 @@ mvn install You can just drop the jar file in. It's a fat jar - it has all the dependencies built in. -[sendgrid-java.jar](http://repo1.maven.org/maven2/com/sendgrid/sendgrid-java/3.0.3/sendgrid-java-3.0.3-jar.jar) - -```java -import com.sendgrid.*; -``` +[sendgrid-java.jar](https://github.com/sendgrid/sendgrid-java/releases/download/v4.3.0/sendgrid-java.jar) ## Dependencies -- The SendGrid Service, starting at the [free level](https://sendgrid.com/free?source=sendgrid-java) - [Java-HTTP-Client](https://github.com/sendgrid/java-http-client) + # Quick Start ## Hello Email +The following is the minimum needed code to send an email with the [/mail/send Helper](https://github.com/sendgrid/sendgrid-java/tree/master/src/main/java/com/sendgrid/helpers) ([here](https://github.com/sendgrid/sendgrid-java/blob/master/examples/helpers/mail/Example.java#L30) is a full example): + +### With Mail Helper Class + ```java import com.sendgrid.*; import java.io.IOException; @@ -95,21 +108,50 @@ import java.io.IOException; public class Example { public static void main(String[] args) throws IOException { Email from = new Email("test@example.com"); - String subject = "Hello World from the SendGrid Java Library"; + String subject = "Sending with SendGrid is Fun"; Email to = new Email("test@example.com"); - Content content = new Content("text/plain", "some text here"); + Content content = new Content("text/plain", "and easy to do anywhere, even with Java"); Mail mail = new Mail(from, subject, to, content); SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); try { - request.method = Method.POST; - request.endpoint = "mail/send"; - request.body = mail.build(); + request.setMethod(Method.POST); + request.setEndpoint("mail/send"); + request.setBody(mail.build()); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); + } catch (IOException ex) { + throw ex; + } + } +} +``` + +The `Mail` constructor creates a [personalization object](https://sendgrid.com/docs/Classroom/Send/v3_Mail_Send/personalizations.html) for you. [Here](https://github.com/sendgrid/sendgrid-java/blob/master/examples/helpers/mail/Example.java#L221) is an example of how to add to it. + +### Without Mail Helper Class + +The following is the minimum needed code to send an email without the /mail/send Helper ([here](https://github.com/sendgrid/sendgrid-java/blob/master/examples/mail/mail.java#L54) is a full example): + +```java +import com.sendgrid.*; +import java.io.IOException; + +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.POST); + request.setEndpoint("mail/send"); + request.setBody("{\"personalizations\":[{\"to\":[{\"email\":\"test@example.com\"}],\"subject\":\"Sending with SendGrid is Fun\"}],\"from\":{\"email\":\"test@example.com\"},\"content\":[{\"type\":\"text/plain\",\"value\": \"and easy to do anywhere, even with Java\"}]}"); + 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; } @@ -128,12 +170,12 @@ public class Example { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); try { Request request = new Request(); - request.method = Method.GET; - request.endpoint = "api_keys"; + request.setMethod(Method.GET); + request.setEndpoint("api_keys"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -141,32 +183,58 @@ public class Example { } ``` + # Usage - [SendGrid Docs](https://sendgrid.com/docs/API_Reference/Web_API_v3/index.html) -- [Usage Docs](https://github.com/sendgrid/sendgrid-java/tree/master/USAGE.md) +- [Library Usage Docs](https://github.com/sendgrid/sendgrid-java/tree/master/USAGE.md) - [Example Code](https://github.com/sendgrid/sendgrid-java/tree/master/examples) +- [How-to: Migration from v2 to v3](https://sendgrid.com/docs/Classroom/Send/v3_Mail_Send/how_to_migrate_from_v2_to_v3_mail_send.html) +- [v3 Web API Mail Send Helper](https://github.com/sendgrid/sendgrid-java/tree/master/src/main/java/com/sendgrid/helpers) - build a request object payload for a v3 /mail/send API call. + + + +# Use Cases + +[Examples of common API use cases](https://github.com/sendgrid/sendgrid-java/blob/master/USE_CASES.md), such as how to send an email with a transactional template. + + +# Announcements -## Roadmap +Please see our announcement regarding [breaking changes](https://github.com/sendgrid/sendgrid-java/issues/140). Your support is appreciated! -If you are intersted in the future direction of this project, please take a look at our [milestones](https://github.com/sendgrid/sendgrid-java/milestones). We would love to hear your feedback. +All updates to this library are documented in our [CHANGELOG](https://github.com/sendgrid/sendgrid-java/blob/master/CHANGELOG.md) and [releases](https://github.com/sendgrid/sendgrid-java/releases). You may also subscribe to email [release notifications](https://dx.sendgrid.com/newsletter/java) for releases and breaking changes. -## How to Contribute + +# Roadmap -We encourage contribution to our libraries, please see our [CONTRIBUTING](https://github.com/sendgrid/sendgrid-java/blob/master/CONTRIBUTING.md) guide for details. +If you are interested in the future direction of this project, please take a look at our open [issues](https://github.com/sendgrid/sendgrid-java/issues) and [pull requests](https://github.com/sendgrid/sendgrid-java/pulls). We would love to hear your feedback. + + +# How to Contribute + +We encourage contribution to our libraries (you might even score some nifty swag), please see our [CONTRIBUTING](https://github.com/sendgrid/sendgrid-java/blob/master/CONTRIBUTING.md) guide for details. Quick links: -- [Feature Request](https://github.com/sendgrid/sendgrid-java/blob/master/CONTRIBUTING.md#feature_request) -- [Bug Reports](https://github.com/sendgrid/sendgrid-java/blob/master/CONTRIBUTING.md#submit_a_bug_report) -- [Sign the CLA to Create a Pull Request](https://github.com/sendgrid/sendgrid-java/blob/master/CONTRIBUTING.md#cla) -- [Improvements to the Codebase](https://github.com/sendgrid/sendgrid-java/blob/master/CONTRIBUTING.md#improvements_to_the_codebase) +- [Feature Request](https://github.com/sendgrid/sendgrid-java/blob/master/CONTRIBUTING.md#feature-request) +- [Bug Reports](https://github.com/sendgrid/sendgrid-java/blob/master/CONTRIBUTING.md#submit-a-bug-report) +- [Improvements to the Codebase](https://github.com/sendgrid/sendgrid-java/blob/master/CONTRIBUTING.md#improvements-to-the-codebase) +- [Sign the CLA to Create a Pull Request](https://cla.sendgrid.com/sendgrid/sendgrid-java) + + +# Troubleshooting +Please see our [troubleshooting guide](https://github.com/sendgrid/sendgrid-java/blob/master/TROUBLESHOOTING.md) for common library issues. + + # About -sendgrid-java is guided and supported by the SendGrid [Developer Experience Team](mailto:dx@sendgrid.com). +sendgrid-java is guided and supported by the SendGrid Developer Experience Team. + +Please email the Developer Experience Team [here](mailto:dx@sendgrid.com) in case of any queries. sendgrid-java is maintained and funded by SendGrid, Inc. The names and logos for sendgrid-java are trademarks of SendGrid, Inc. -![SendGrid Logo] -(https://uiux.s3.amazonaws.com/2016-logos/email-logo%402x.png) +# License +[The MIT License (MIT)](LICENSE.txt) diff --git a/TROUBLESHOOTING.md b/TROUBLESHOOTING.md new file mode 100644 index 00000000..e510304b --- /dev/null +++ b/TROUBLESHOOTING.md @@ -0,0 +1,111 @@ +If you have a non-library SendGrid issue, please contact our [support team](https://support.sendgrid.com). + +If you can't find a solution below, please open an [issue](https://github.com/sendgrid/sendgrid-java/issues). + + +## Table of Contents + +* [Migrating from v2 to v3](#migrating) +* [Continue Using v2](#v2) +* [Testing v3 /mail/send Calls Directly](#testing) +* [Versions](#versions) +* [Environment Variables and Your SendGrid API Key](#environment) +* [Using the Package Manager](#package-manager) +* [Android Compatibility](#android) +* [Viewing the Request Body](#request-body) + + +## Migrating from v2 to v3 + +Please review [our guide](https://sendgrid.com/docs/Classroom/Send/v3_Mail_Send/how_to_migrate_from_v2_to_v3_mail_send.html) on how to migrate from v2 to v3. + + +## Continue Using v2 + +[Here](https://github.com/sendgrid/sendgrid-java/tree/b64988f85474e04e9d75e17860d64ffacda1cdff) is the last working version with v2 support. + +### via Maven w/ Gradle + +Add the following to your build.gradle file in the root of your project. + +```groovy +... +dependencies { + ... + compile 'com.sendgrid:sendgrid-java:2.2.2' +} + +repositories { + mavenCentral() +} +... +``` + +### via jar file + +You can just drop the jar file in. It's a fat jar - it has all the dependencies built in. + +[sendgrid-java.jar](http://repo1.maven.org/maven2/com/sendgrid/sendgrid-java/2.2.2/sendgrid-java-2.2.2-jar.jar) + + +## Testing v3 /mail/send Calls Directly + +[Here](https://sendgrid.com/docs/Classroom/Send/v3_Mail_Send/curl_examples.html) are some cURL examples for common use cases. + + +## Versions + +We follow the MAJOR.MINOR.PATCH versioning scheme as described by [SemVer.org](http://semver.org). Therefore, we recommend that you always pin (or vendor) the particular version you are working with to your code and never auto-update to the latest version. Especially when there is a MAJOR point release, since that is guaranteed to be a breaking change. Changes are documented in the [CHANGELOG](https://github.com/sendgrid/sendgrid-java/blob/master/CHANGELOG.md) and [releases](https://github.com/sendgrid/sendgrid-java/releases) section. + + +## Environment Variables and Your SendGrid API Key + +All of our examples assume you are using [environment variables](https://github.com/sendgrid/sendgrid-java#setup-environment-variables) to hold your SendGrid API key. + +If you choose to add your SendGrid API key directly (not recommended): + +`System.getenv("SENDGRID_API_KEY")` + +becomes + +`"SENDGRID_API_KEY"` + +In the first case SENDGRID_API_KEY is in reference to the name of the environment variable, while the second case references the actual SendGrid API Key. + + +## Using the Package Manager + +We upload this library to [Maven](http://repo1.maven.org/maven2/com/sendgrid/sendgrid-java/) whenever we make a release. This allows you to use [maven and gradle](https://maven.apache.org/) for easy installation. + +In most cases we recommend you download the latest version of the library, but if you need a different version, please use: + +```groovy +... +dependencies { + ... + compile 'com.sendgrid:sendgrid-java:X.X.X' +} + +repositories { + mavenCentral() +} +... +``` + + +## Android Compatibility + +Since Android SDK 23, HttpClient is no longer supported. Some workarounds can be found [here](http://stackoverflow.com/questions/32153318/httpclient-wont-import-in-android-studio). + +We have an issue to remove that dependency [here](https://github.com/sendgrid/java-http-client/issues/2), please upvote to move it up the queue. + + +## Viewing the Request Body + +When debugging or testing, it may be useful to examine the raw request body to compare against the [documented format](https://sendgrid.com/docs/API_Reference/api_v3.html). + +You can do this right before you call `request.setBody(mail.build())` like so: + +```java +System.out.println(mail.build()); +``` \ No newline at end of file diff --git a/USAGE.md b/USAGE.md index 98dcfb67..cf25b2c6 100644 --- a/USAGE.md +++ b/USAGE.md @@ -2,7 +2,7 @@ This documentation is based on our [OAI specification](https://github.com/sendgr # INITIALIZATION -```ruby +```java import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; @@ -22,9 +22,9 @@ public class Example { # Table of Contents -* [ACCESS SETTINGS](#access_settings) +* [ACCESS SETTINGS](#access-settings) * [ALERTS](#alerts) -* [API KEYS](#api_keys) +* [API KEYS](#api-keys) * [ASM](#asm) * [BROWSERS](#browsers) * [CAMPAIGNS](#campaigns) @@ -35,21 +35,21 @@ public class Example { * [GEO](#geo) * [IPS](#ips) * [MAIL](#mail) -* [MAIL SETTINGS](#mail_settings) -* [MAILBOX PROVIDERS](#mailbox_providers) -* [PARTNER SETTINGS](#partner_settings) +* [MAIL SETTINGS](#mail-settings) +* [MAILBOX PROVIDERS](#mailbox-providers) +* [PARTNER SETTINGS](#partner-settings) * [SCOPES](#scopes) * [SENDERS](#senders) * [STATS](#stats) * [SUBUSERS](#subusers) * [SUPPRESSION](#suppression) * [TEMPLATES](#templates) -* [TRACKING SETTINGS](#tracking_settings) +* [TRACKING SETTINGS](#tracking-settings) * [USER](#user) * [WHITELABEL](#whitelabel) - + # ACCESS SETTINGS ## Retrieve all recent access attempts @@ -67,15 +67,13 @@ For more information, please see our [User Guide](http://sendgrid.com/docs/User_ try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "access_settings/activity"; - Map queryParams = new HashMap(); - queryParams.put("limit", "1"); - request.queryParams = queryParams; + request.setMethod(Method.GET); + request.setEndpoint("access_settings/activity"); + request.addQueryParam("limit", "1"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -97,13 +95,13 @@ For more information, please see our [User Guide](http://sendgrid.com/docs/User_ try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.POST; - request.endpoint = "access_settings/whitelist"; - request.body = "{\"ips\":[{\"ip\":\"192.168.1.1\"},{\"ip\":\"192.*.*.*\"},{\"ip\":\"192.168.1.3/32\"}]}"; + request.setMethod(Method.POST); + request.setEndpoint("access_settings/whitelist"); + request.setBody("{\"ips\":[{\"ip\":\"192.168.1.1\"},{\"ip\":\"192.*.*.*\"},{\"ip\":\"192.168.1.3/32\"}]}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -123,12 +121,12 @@ For more information, please see our [User Guide](http://sendgrid.com/docs/User_ try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "access_settings/whitelist"; + request.setMethod(Method.GET); + request.setEndpoint("access_settings/whitelist"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -150,20 +148,20 @@ For more information, please see our [User Guide](http://sendgrid.com/docs/User_ try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.DELETE; - request.endpoint = "access_settings/whitelist"; - request.body = "{\"ids\":[1,2,3]}"; + request.setMethod(Method.DELETE); + request.setEndpoint("access_settings/whitelist"); + request.setBody("{\"ids\":[1,2,3]}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } ``` ## Retrieve a specific whitelisted IP -**This endpoint allows you to retreive a specific IP address that has been whitelisted.** +**This endpoint allows you to retrieve a specific IP address that has been whitelisted.** You must include the ID for the specific IP address you want to retrieve in your call. @@ -178,12 +176,12 @@ For more information, please see our [User Guide](http://sendgrid.com/docs/User_ try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "access_settings/whitelist/{rule_id}"; + request.setMethod(Method.GET); + request.setEndpoint("access_settings/whitelist/{rule_id}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -205,12 +203,12 @@ For more information, please see our [User Guide](http://sendgrid.com/docs/User_ try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.DELETE; - request.endpoint = "access_settings/whitelist/{rule_id}"; + request.setMethod(Method.DELETE); + request.setEndpoint("access_settings/whitelist/{rule_id}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -235,20 +233,20 @@ For more information about alerts, please see our [User Guide](https://sendgrid. try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.POST; - request.endpoint = "alerts"; - request.body = "{\"type\":\"stats_notification\",\"frequency\":\"daily\",\"email_to\":\"example@example.com\"}"; + request.setMethod(Method.POST); + request.setEndpoint("alerts"); + request.setBody("{\"type\":\"stats_notification\",\"frequency\":\"daily\",\"email_to\":\"example@example.com\"}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } ``` ## Retrieve all alerts -**This endpoint allows you to retieve all of your alerts.** +**This endpoint allows you to retrieve all of your alerts.** Alerts allow you to specify an email address to receive notifications regarding your email usage or statistics. * Usage alerts allow you to set the threshold at which an alert will be sent. @@ -263,12 +261,12 @@ For more information about alerts, please see our [User Guide](https://sendgrid. try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "alerts"; + request.setMethod(Method.GET); + request.setEndpoint("alerts"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -290,13 +288,13 @@ For more information about alerts, please see our [User Guide](https://sendgrid. try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.PATCH; - request.endpoint = "alerts/{alert_id}"; - request.body = "{\"email_to\":\"example@example.com\"}"; + request.setMethod(Method.PATCH); + request.setEndpoint("alerts/{alert_id}"); + request.setBody("{\"email_to\":\"example@example.com\"}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -318,12 +316,12 @@ For more information about alerts, please see our [User Guide](https://sendgrid. try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "alerts/{alert_id}"; + request.setMethod(Method.GET); + request.setEndpoint("alerts/{alert_id}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -345,22 +343,22 @@ For more information about alerts, please see our [User Guide](https://sendgrid. try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.DELETE; - request.endpoint = "alerts/{alert_id}"; + request.setMethod(Method.DELETE); + request.setEndpoint("alerts/{alert_id}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } ``` - + # API KEYS ## Create API keys -**This enpoint allows you to create a new random API Key for the user.** +**This endpoint allows you to create a new random API Key for the user.** A JSON request body containing a "name" property is required. If number of maximum keys is reached, HTTP 403 will be returned. @@ -377,13 +375,13 @@ See the [API Key Permissions List](https://sendgrid.com/docs/API_Reference/Web_A try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.POST; - request.endpoint = "api_keys"; - request.body = "{\"sample\":\"data\",\"scopes\":[\"mail.send\",\"alerts.create\",\"alerts.read\"],\"name\":\"My API Key\"}"; + request.setMethod(Method.POST); + request.setEndpoint("api_keys"); + request.setBody("{\"sample\":\"data\",\"scopes\":[\"mail.send\",\"alerts.create\",\"alerts.read\"],\"name\":\"My API Key\"}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -401,15 +399,13 @@ The API Keys feature allows customers to be able to generate an API Key credenti try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "api_keys"; - Map queryParams = new HashMap(); - queryParams.put("limit", "1"); - request.queryParams = queryParams; + request.setMethod(Method.GET); + request.setEndpoint("api_keys"); + request.addQueryParam("limit", "1"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -431,13 +427,13 @@ The API Keys feature allows customers to be able to generate an API Key credenti try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.PUT; - request.endpoint = "api_keys/{api_key_id}"; - request.body = "{\"scopes\":[\"user.profile.read\",\"user.profile.update\"],\"name\":\"A New Hope\"}"; + request.setMethod(Method.PUT); + request.setEndpoint("api_keys/{api_key_id}"); + request.setBody("{\"scopes\":[\"user.profile.read\",\"user.profile.update\"],\"name\":\"A New Hope\"}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -463,13 +459,13 @@ The API Keys feature allows customers to be able to generate an API Key credenti try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.PATCH; - request.endpoint = "api_keys/{api_key_id}"; - request.body = "{\"name\":\"A New Hope\"}"; + request.setMethod(Method.PATCH); + request.setEndpoint("api_keys/{api_key_id}"); + request.setBody("{\"name\":\"A New Hope\"}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -487,21 +483,21 @@ If the API Key ID does not exist an HTTP 404 will be returned. try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "api_keys/{api_key_id}"; + request.setMethod(Method.GET); + request.setEndpoint("api_keys/{api_key_id}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } ``` ## Delete API keys -**This endpoint allows you to revoke an existing API Key** +**This endpoint allows you to revoke an existing API Key.** -Authentications using this API Key will fail after this request is made, with some small propogation delay.If the API Key ID does not exist an HTTP 404 will be returned. +Authentications using this API Key will fail after this request is made, with some small propagation delay.If the API Key ID does not exist an HTTP 404 will be returned. The API Keys feature allows customers to be able to generate an API Key credential which can be used for authentication with the SendGrid v3 Web API or the [Mail API Endpoint](https://sendgrid.com/docs/API_Reference/Web_API/mail.html). @@ -518,12 +514,12 @@ The API Keys feature allows customers to be able to generate an API Key credenti try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.DELETE; - request.endpoint = "api_keys/{api_key_id}"; + request.setMethod(Method.DELETE); + request.setEndpoint("api_keys/{api_key_id}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -537,7 +533,7 @@ The API Keys feature allows customers to be able to generate an API Key credenti Suppression groups, or unsubscribe groups, are specific types or categories of email that you would like your recipients to be able to unsubscribe from. For example: Daily Newsletters, Invoices, System Alerts. -The **name** and **description** of the unsubscribe group will be visible by recipients when they are managing their subscriptions. +The **name** and **description** of the unsubscribe group will be visible to recipients when they are managing their subscriptions. Each user can create up to 25 different suppression groups. @@ -548,13 +544,13 @@ Each user can create up to 25 different suppression groups. try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.POST; - request.endpoint = "asm/groups"; - request.body = "{\"is_default\":true,\"description\":\"Suggestions for products our users might like.\",\"name\":\"Product Suggestions\"}"; + request.setMethod(Method.POST); + request.setEndpoint("asm/groups"); + request.setBody("{\"is_default\":true,\"description\":\"Suggestions for products our users might like.\",\"name\":\"Product) Suggestions\"}"; Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -567,7 +563,7 @@ This endpoint will return information for each group ID that you include in your Suppressions are a list of email addresses that will not receive content sent under a given [group](https://sendgrid.com/docs/API_Reference/Web_API_v3/Suppression_Management/groups.html). -Suppression groups, or [unsubscribe groups](https://sendgrid.com/docs/API_Reference/Web_API_v3/Suppression_Management/groups.html), allow you to label a category of content that you regularly send. This gives your recipients the ability to opt out of a specific set of your email. For example, you might define a group for your transactional email, and one for your marketing email so that your users can continue recieving your transactional email witout having to receive your marketing content. +Suppression groups, or [unsubscribe groups](https://sendgrid.com/docs/API_Reference/Web_API_v3/Suppression_Management/groups.html), allow you to label a category of content that you regularly send. This gives your recipients the ability to opt out of a specific set of your email. For example, you might define a group for your transactional email, and one for your marketing email so that your users can continue receiving your transactional email without having to receive your marketing content. ### GET /asm/groups @@ -576,15 +572,13 @@ Suppression groups, or [unsubscribe groups](https://sendgrid.com/docs/API_Refere try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "asm/groups"; - Map queryParams = new HashMap(); - queryParams.put("id", "1"); - request.queryParams = queryParams; + request.setMethod(Method.GET); + request.setEndpoint("asm/groups"); + request.addQueryParam("id", "1"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -595,7 +589,7 @@ Suppression groups, or [unsubscribe groups](https://sendgrid.com/docs/API_Refere Suppression groups, or unsubscribe groups, are specific types or categories of email that you would like your recipients to be able to unsubscribe from. For example: Daily Newsletters, Invoices, System Alerts. -The **name** and **description** of the unsubscribe group will be visible by recipients when they are managing their subscriptions. +The **name** and **description** of the unsubscribe group will be visible to recipients when they are managing their subscriptions. Each user can create up to 25 different suppression groups. @@ -606,13 +600,13 @@ Each user can create up to 25 different suppression groups. try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.PATCH; - request.endpoint = "asm/groups/{group_id}"; - request.body = "{\"description\":\"Suggestions for items our users might like.\",\"name\":\"Item Suggestions\",\"id\":103}"; + request.setMethod(Method.PATCH); + request.setEndpoint("asm/groups/{group_id}"); + request.setBody("{\"description\":\"Suggestions for items our users might like.\",\"name\":\"Item Suggestions\",\"id\":103}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -623,7 +617,7 @@ Each user can create up to 25 different suppression groups. Suppression groups, or unsubscribe groups, are specific types or categories of email that you would like your recipients to be able to unsubscribe from. For example: Daily Newsletters, Invoices, System Alerts. -The **name** and **description** of the unsubscribe group will be visible by recipients when they are managing their subscriptions. +The **name** and **description** of the unsubscribe group will be visible to recipients when they are managing their subscriptions. Each user can create up to 25 different suppression groups. @@ -634,12 +628,12 @@ Each user can create up to 25 different suppression groups. try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "asm/groups/{group_id}"; + request.setMethod(Method.GET); + request.setEndpoint("asm/groups/{group_id}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -652,7 +646,7 @@ You can only delete groups that have not been attached to sent mail in the last Suppression groups, or unsubscribe groups, are specific types or categories of email that you would like your recipients to be able to unsubscribe from. For example: Daily Newsletters, Invoices, System Alerts. -The **name** and **description** of the unsubscribe group will be visible by recipients when they are managing their subscriptions. +The **name** and **description** of the unsubscribe group will be visible to recipients when they are managing their subscriptions. Each user can create up to 25 different suppression groups. @@ -663,12 +657,12 @@ Each user can create up to 25 different suppression groups. try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.DELETE; - request.endpoint = "asm/groups/{group_id}"; + request.setMethod(Method.DELETE); + request.setEndpoint("asm/groups/{group_id}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -688,13 +682,13 @@ Suppressions are recipient email addresses that are added to [unsubscribe groups try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.POST; - request.endpoint = "asm/groups/{group_id}/suppressions"; - request.body = "{\"recipient_emails\":[\"test1@example.com\",\"test2@example.com\"]}"; + request.setMethod(Method.POST); + request.setEndpoint("asm/groups/{group_id}/suppressions"); + request.setBody("{\"recipient_emails\":[\"test1@example.com\",\"test2@example.com\"]}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -712,12 +706,12 @@ Suppressions are recipient email addresses that are added to [unsubscribe groups try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "asm/groups/{group_id}/suppressions"; + request.setMethod(Method.GET); + request.setEndpoint("asm/groups/{group_id}/suppressions"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -737,13 +731,13 @@ Suppressions are a list of email addresses that will not receive content sent un try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.POST; - request.endpoint = "asm/groups/{group_id}/suppressions/search"; - request.body = "{\"recipient_emails\":[\"exists1@example.com\",\"exists2@example.com\",\"doesnotexists@example.com\"]}"; + request.setMethod(Method.POST); + request.setEndpoint("asm/groups/{group_id}/suppressions/search"); + request.setBody("{\"recipient_emails\":[\"exists1@example.com\",\"exists2@example.com\",\"doesnotexists@example.com\"]}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -761,12 +755,12 @@ Suppressions are recipient email addresses that are added to [unsubscribe groups try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.DELETE; - request.endpoint = "asm/groups/{group_id}/suppressions/{email}"; + request.setMethod(Method.DELETE); + request.setEndpoint("asm/groups/{group_id}/suppressions/{email}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -784,12 +778,12 @@ Suppressions are a list of email addresses that will not receive content sent un try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "asm/suppressions"; + request.setMethod(Method.GET); + request.setEndpoint("asm/suppressions"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -807,22 +801,22 @@ A global suppression (or global unsubscribe) is an email address of a recipient try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.POST; - request.endpoint = "asm/suppressions/global"; - request.body = "{\"recipient_emails\":[\"test1@example.com\",\"test2@example.com\"]}"; + request.setMethod(Method.POST); + request.setEndpoint("asm/suppressions/global"); + request.setBody("{\"recipient_emails\":[\"test1@example.com\",\"test2@example.com\"]}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } ``` ## Retrieve a Global Suppression -**This endpoint allows you to retrieve a global suppression. You can also use this endpoint to confirm if an email address is already globally suppresed.** +**This endpoint allows you to retrieve a global suppression. You can also use this endpoint to confirm if an email address is already globally suppressed.** -If the email address you include in the URL path parameter `{email}` is alreayd globally suppressed, the response will include that email address. If the address you enter for `{email}` is not globally suppressed, an empty JSON object `{}` will be returned. +If the email address you include in the URL path parameter `{email}` is already globally suppressed, the response will include that email address. If the address you enter for `{email}` is not globally suppressed, an empty JSON object `{}` will be returned. A global suppression (or global unsubscribe) is an email address of a recipient who does not want to receive any of your messages. A globally suppressed recipient will be removed from any email you send. For more information, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Suppressions/global_unsubscribes.html). @@ -833,12 +827,12 @@ A global suppression (or global unsubscribe) is an email address of a recipient try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "asm/suppressions/global/{email}"; + request.setMethod(Method.GET); + request.setEndpoint("asm/suppressions/global/{email}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -856,12 +850,12 @@ A global suppression (or global unsubscribe) is an email address of a recipient try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.DELETE; - request.endpoint = "asm/suppressions/global/{email}"; + request.setMethod(Method.DELETE); + request.setEndpoint("asm/suppressions/global/{email}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -879,12 +873,12 @@ Suppressions are a list of email addresses that will not receive content sent un try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "asm/suppressions/{email}"; + request.setMethod(Method.GET); + request.setEndpoint("asm/suppressions/{email}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -907,20 +901,18 @@ Advanced Stats provide a more in-depth view of your email statistics and the act try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "browsers/stats"; - Map queryParams = new HashMap(); - queryParams.put("end_date", "2016-04-01"); - queryParams.put("aggregated_by", "day"); - queryParams.put("browsers", "test_string"); - queryParams.put("limit", "test_string"); - queryParams.put("offset", "test_string"); - queryParams.put("start_date", "2016-01-01"); - request.queryParams = queryParams; + request.setMethod(Method.GET); + request.setEndpoint("browsers/stats"); + request.addQueryParam("end_date", "2016-04-01"); + request.addQueryParam("aggregated_by", "day"); + request.addQueryParam("browsers", "test_string"); + request.addQueryParam("limit", "test_string"); + request.addQueryParam("offset", "test_string"); + request.addQueryParam("start_date", "2016-01-01"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -947,13 +939,13 @@ For more information: try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.POST; - request.endpoint = "campaigns"; - request.body = "{\"custom_unsubscribe_url\":\"\",\"html_content\":\"

Check out our spring line!

\",\"list_ids\":[110,124],\"sender_id\":124451,\"subject\":\"New Products for Spring!\",\"plain_content\":\"Check out our spring line!\",\"suppression_group_id\":42,\"title\":\"March Newsletter\",\"segment_ids\":[110],\"categories\":[\"spring line\"],\"ip_pool\":\"marketing\"}"; + request.setMethod(Method.POST); + request.setEndpoint("campaigns"); + request.setBody("{\"custom_unsubscribe_url\":\"\",\"html_content\":\"

Check out our) spring line!

\",\"list_ids\":[110,124],\"sender_id\":124451,\"subject\":\"New Products for Spring!\",\"plain_content\":\"Check out our spring line!\",\"suppression_group_id\":42,\"title\":\"March Newsletter\",\"segment_ids\":[110],\"categories\":[\"spring line\"],\"ip_pool\":\"marketing\"}"; Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -977,16 +969,14 @@ For more information: try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "campaigns"; - Map queryParams = new HashMap(); - queryParams.put("limit", "1"); - queryParams.put("offset", "1"); - request.queryParams = queryParams; + request.setMethod(Method.GET); + request.setEndpoint("campaigns"); + request.addQueryParam("limit", "1"); + request.addQueryParam("offset", "1"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -1006,13 +996,13 @@ For more information: try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.PATCH; - request.endpoint = "campaigns/{campaign_id}"; - request.body = "{\"html_content\":\"

Check out our summer line!

\",\"subject\":\"New Products for Summer!\",\"title\":\"May Newsletter\",\"categories\":[\"summer line\"],\"plain_content\":\"Check out our summer line!\"}"; + request.setMethod(Method.PATCH); + request.setEndpoint("campaigns/{campaign_id}"); + request.setBody("{\"html_content\":\"

Check out our summer line!

\",\"subject\":\"New Products for Summer!\",\"title\":\"May Newsletter\",\"categories\":[\"summer line\"],\"plain_content\":\"Check out our summer line!\"}"; Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -1034,12 +1024,12 @@ For more information: try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "campaigns/{campaign_id}"; + request.setMethod(Method.GET); + request.setEndpoint("campaigns/{campaign_id}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -1061,12 +1051,12 @@ For more information: try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.DELETE; - request.endpoint = "campaigns/{campaign_id}"; + request.setMethod(Method.DELETE); + request.setEndpoint("campaigns/{campaign_id}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -1086,13 +1076,13 @@ For more information: try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.PATCH; - request.endpoint = "campaigns/{campaign_id}/schedules"; - request.body = "{\"send_at\":1489451436}"; + request.setMethod(Method.PATCH); + request.setEndpoint("campaigns/{campaign_id}/schedules"); + request.setBody("{\"send_at\":1489451436}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -1112,13 +1102,13 @@ For more information: try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.POST; - request.endpoint = "campaigns/{campaign_id}/schedules"; - request.body = "{\"send_at\":1489771528}"; + request.setMethod(Method.POST); + request.setEndpoint("campaigns/{campaign_id}/schedules"); + request.setBody("{\"send_at\":1489771528}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -1138,12 +1128,12 @@ For more information: try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "campaigns/{campaign_id}/schedules"; + request.setMethod(Method.GET); + request.setEndpoint("campaigns/{campaign_id}/schedules"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -1166,12 +1156,12 @@ For more information: try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.DELETE; - request.endpoint = "campaigns/{campaign_id}/schedules"; + request.setMethod(Method.DELETE); + request.setEndpoint("campaigns/{campaign_id}/schedules"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -1193,12 +1183,12 @@ For more information: try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.POST; - request.endpoint = "campaigns/{campaign_id}/schedules/now"; + request.setMethod(Method.POST); + request.setEndpoint("campaigns/{campaign_id}/schedules/now"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -1220,13 +1210,13 @@ For more information: try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.POST; - request.endpoint = "campaigns/{campaign_id}/schedules/test"; - request.body = "{\"to\":\"your.email@example.com\"}"; + request.setMethod(Method.POST); + request.setEndpoint("campaigns/{campaign_id}/schedules/test"); + request.setBody("{\"to\":\"your.email@example.com\"}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -1247,17 +1237,15 @@ Categories can help organize your email analytics by enabling you to tag emails try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "categories"; - Map queryParams = new HashMap(); - queryParams.put("category", "test_string"); - queryParams.put("limit", "1"); - queryParams.put("offset", "1"); - request.queryParams = queryParams; + request.setMethod(Method.GET); + request.setEndpoint("categories"); + request.addQueryParam("category", "test_string"); + request.addQueryParam("limit", "1"); + request.addQueryParam("offset", "1"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -1277,20 +1265,18 @@ Categories allow you to group your emails together according to broad topics tha try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "categories/stats"; - Map queryParams = new HashMap(); - queryParams.put("end_date", "2016-04-01"); - queryParams.put("aggregated_by", "day"); - queryParams.put("limit", "1"); - queryParams.put("offset", "1"); - queryParams.put("start_date", "2016-01-01"); - queryParams.put("categories", "test_string"); - request.queryParams = queryParams; + request.setMethod(Method.GET); + request.setEndpoint("categories/stats"); + request.addQueryParam("end_date", "2016-04-01"); + request.addQueryParam("aggregated_by", "day"); + request.addQueryParam("limit", "1"); + request.addQueryParam("offset", "1"); + request.addQueryParam("start_date", "2016-01-01"); + request.addQueryParam("categories", "test_string"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -1310,21 +1296,19 @@ Categories allow you to group your emails together according to broad topics tha try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "categories/stats/sums"; - Map queryParams = new HashMap(); - queryParams.put("end_date", "2016-04-01"); - queryParams.put("aggregated_by", "day"); - queryParams.put("limit", "1"); - queryParams.put("sort_by_metric", "test_string"); - queryParams.put("offset", "1"); - queryParams.put("start_date", "2016-01-01"); - queryParams.put("sort_by_direction", "asc"); - request.queryParams = queryParams; + request.setMethod(Method.GET); + request.setEndpoint("categories/stats/sums"); + request.addQueryParam("end_date", "2016-04-01"); + request.addQueryParam("aggregated_by", "day"); + request.addQueryParam("limit", "1"); + request.addQueryParam("sort_by_metric", "test_string"); + request.addQueryParam("offset", "1"); + request.addQueryParam("start_date", "2016-01-01"); + request.addQueryParam("sort_by_direction", "asc"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -1347,17 +1331,15 @@ Advanced Stats provide a more in-depth view of your email statistics and the act try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "clients/stats"; - Map queryParams = new HashMap(); - queryParams.put("aggregated_by", "day"); - queryParams.put("start_date", "2016-01-01"); - queryParams.put("end_date", "2016-04-01"); - request.queryParams = queryParams; + request.setMethod(Method.GET); + request.setEndpoint("clients/stats"); + request.addQueryParam("aggregated_by", "day"); + request.addQueryParam("start_date", "2016-01-01"); + request.addQueryParam("end_date", "2016-04-01"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -1383,17 +1365,15 @@ Advanced Stats provide a more in-depth view of your email statistics and the act try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "clients/{client_type}/stats"; - Map queryParams = new HashMap(); - queryParams.put("aggregated_by", "day"); - queryParams.put("start_date", "2016-01-01"); - queryParams.put("end_date", "2016-04-01"); - request.queryParams = queryParams; + request.setMethod(Method.GET); + request.setEndpoint("clients/{client_type}/stats"); + request.addQueryParam("aggregated_by", "day"); + request.addQueryParam("start_date", "2016-01-01"); + request.addQueryParam("end_date", "2016-04-01"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -1414,13 +1394,13 @@ The contactdb is a database of your contacts for [SendGrid Marketing Campaigns]( try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.POST; - request.endpoint = "contactdb/custom_fields"; - request.body = "{\"type\":\"text\",\"name\":\"pet\"}"; + request.setMethod(Method.POST); + request.setEndpoint("contactdb/custom_fields"); + request.setBody("{\"type\":\"text\",\"name\":\"pet\"}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -1438,12 +1418,12 @@ The contactdb is a database of your contacts for [SendGrid Marketing Campaigns]( try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "contactdb/custom_fields"; + request.setMethod(Method.GET); + request.setEndpoint("contactdb/custom_fields"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -1461,12 +1441,12 @@ The contactdb is a database of your contacts for [SendGrid Marketing Campaigns]( try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "contactdb/custom_fields/{custom_field_id}"; + request.setMethod(Method.GET); + request.setEndpoint("contactdb/custom_fields/{custom_field_id}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -1484,12 +1464,12 @@ The contactdb is a database of your contacts for [SendGrid Marketing Campaigns]( try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.DELETE; - request.endpoint = "contactdb/custom_fields/{custom_field_id}"; + request.setMethod(Method.DELETE); + request.setEndpoint("contactdb/custom_fields/{custom_field_id}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -1507,13 +1487,13 @@ The Contacts API helps you manage your [Marketing Campaigns](https://sendgrid.co try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.POST; - request.endpoint = "contactdb/lists"; - request.body = "{\"name\":\"your list name\"}"; + request.setMethod(Method.POST); + request.setEndpoint("contactdb/lists"); + request.setBody("{\"name\":\"your list name\"}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -1531,12 +1511,12 @@ The Contacts API helps you manage your [Marketing Campaigns](https://sendgrid.co try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "contactdb/lists"; + request.setMethod(Method.GET); + request.setEndpoint("contactdb/lists"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -1554,13 +1534,13 @@ The Contacts API helps you manage your [Marketing Campaigns](https://sendgrid.co try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.DELETE; - request.endpoint = "contactdb/lists"; - request.body = "[1,2,3,4]"; + request.setMethod(Method.DELETE); + request.setEndpoint("contactdb/lists"); + request.setBody("[1,2,3,4]"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -1579,16 +1559,13 @@ The Contacts API helps you manage your [Marketing Campaigns](https://sendgrid.co try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.PATCH; - request.endpoint = "contactdb/lists/{list_id}"; - request.body = "{\"name\":\"newlistname\"}"; - Map queryParams = new HashMap(); - queryParams.put("list_id", "1"); - request.queryParams = queryParams; + request.setMethod(Method.PATCH); + request.setEndpoint("contactdb/lists/{list_id}"); + request.setBody("{\"name\":\"newlistname\"}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -1606,15 +1583,12 @@ The Contacts API helps you manage your [Marketing Campaigns](https://sendgrid.co try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "contactdb/lists/{list_id}"; - Map queryParams = new HashMap(); - queryParams.put("list_id", "1"); - request.queryParams = queryParams; + request.setMethod(Method.GET); + request.setEndpoint("contactdb/lists/{list_id}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -1632,15 +1606,13 @@ The Contacts API helps you manage your [Marketing Campaigns](https://sendgrid.co try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.DELETE; - request.endpoint = "contactdb/lists/{list_id}"; - Map queryParams = new HashMap(); - queryParams.put("delete_contacts", "true"); - request.queryParams = queryParams; + request.setMethod(Method.DELETE); + request.setEndpoint("contactdb/lists/{list_id}"); + request.addQueryParam("delete_contacts", "true"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -1660,13 +1632,13 @@ The Contacts API helps you manage your [Marketing Campaigns](https://sendgrid.co try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.POST; - request.endpoint = "contactdb/lists/{list_id}/recipients"; - request.body = "[\"recipient_id1\",\"recipient_id2\"]"; + request.setMethod(Method.POST); + request.setEndpoint("contactdb/lists/{list_id}/recipients"); + request.setBody("[\"recipient_id1\",\"recipient_id2\"]"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -1684,17 +1656,14 @@ The Contacts API helps you manage your [Marketing Campaigns](https://sendgrid.co try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "contactdb/lists/{list_id}/recipients"; - Map queryParams = new HashMap(); - queryParams.put("page", "1"); - queryParams.put("page_size", "1"); - queryParams.put("list_id", "1"); - request.queryParams = queryParams; + request.setMethod(Method.GET); + request.setEndpoint("contactdb/lists/{list_id}/recipients"); + request.addQueryParam("page", "1"); + request.addQueryParam("page_size", "1"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -1712,12 +1681,12 @@ The Contacts API helps you manage your [Marketing Campaigns](https://sendgrid.co try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.POST; - request.endpoint = "contactdb/lists/{list_id}/recipients/{recipient_id}"; + request.setMethod(Method.POST); + request.setEndpoint("contactdb/lists/{list_id}/recipients/{recipient_id}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -1735,16 +1704,13 @@ The Contacts API helps you manage your [Marketing Campaigns](https://sendgrid.co try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.DELETE; - request.endpoint = "contactdb/lists/{list_id}/recipients/{recipient_id}"; - Map queryParams = new HashMap(); - queryParams.put("recipient_id", "1"); - queryParams.put("list_id", "1"); - request.queryParams = queryParams; + request.setMethod(Method.DELETE); + request.setEndpoint("contactdb/lists/{list_id}/recipients/{recipient_id}"); + request.addQueryParam("recipient_id", "1"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -1766,13 +1732,13 @@ The contactdb is a database of your contacts for [SendGrid Marketing Campaigns]( try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.PATCH; - request.endpoint = "contactdb/recipients"; - request.body = "[{\"first_name\":\"Guy\",\"last_name\":\"Jones\",\"email\":\"jones@example.com\"}]"; + request.setMethod(Method.PATCH); + request.setEndpoint("contactdb/recipients"); + request.setBody("[{\"first_name\":\"Guy\",\"last_name\":\"Jones\",\"email\":\"jones@example.com\"}]"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -1792,13 +1758,13 @@ The Contacts API helps you manage your [Marketing Campaigns](https://sendgrid.co try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.POST; - request.endpoint = "contactdb/recipients"; - request.body = "[{\"age\":25,\"last_name\":\"User\",\"email\":\"example@example.com\",\"first_name\":\"\"},{\"age\":25,\"last_name\":\"User\",\"email\":\"example2@example.com\",\"first_name\":\"Example\"}]"; + request.setMethod(Method.POST); + request.setEndpoint("contactdb/recipients"); + request.setBody("[{\"age\":25,\"last_name\":\"User\",\"email\":\"example@example.com\",\"first_name\":\"\"},{\"age\":25,\"last)_name\":\"User\",\"email\":\"example2@example.com\",\"first_name\":\"Example\"}]"; Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -1819,16 +1785,14 @@ The Contacts API helps you manage your [Marketing Campaigns](https://sendgrid.co try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "contactdb/recipients"; - Map queryParams = new HashMap(); - queryParams.put("page", "1"); - queryParams.put("page_size", "1"); - request.queryParams = queryParams; + request.setMethod(Method.GET); + request.setEndpoint("contactdb/recipients"); + request.addQueryParam("page", "1"); + request.addQueryParam("page_size", "1"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -1848,13 +1812,13 @@ The contactdb is a database of your contacts for [SendGrid Marketing Campaigns]( try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.DELETE; - request.endpoint = "contactdb/recipients"; - request.body = "[\"recipient_id1\",\"recipient_id2\"]"; + request.setMethod(Method.DELETE); + request.setEndpoint("contactdb/recipients"); + request.setBody("[\"recipient_id1\",\"recipient_id2\"]"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -1874,12 +1838,12 @@ The Contacts API helps you manage your [Marketing Campaigns](https://sendgrid.co try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "contactdb/recipients/billable_count"; + request.setMethod(Method.GET); + request.setEndpoint("contactdb/recipients/billable_count"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -1897,12 +1861,12 @@ The contactdb is a database of your contacts for [SendGrid Marketing Campaigns]( try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "contactdb/recipients/count"; + request.setMethod(Method.GET); + request.setEndpoint("contactdb/recipients/count"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -1929,15 +1893,13 @@ The contactdb is a database of your contacts for [SendGrid Marketing Campaigns]( try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "contactdb/recipients/search"; - Map queryParams = new HashMap(); - queryParams.put("{field_name}", "test_string"); - request.queryParams = queryParams; + request.setMethod(Method.GET); + request.setEndpoint("contactdb/recipients/search"); + request.addQueryParam("{field_name}", "test_string"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -1955,12 +1917,12 @@ The Contacts API helps you manage your [Marketing Campaigns](https://sendgrid.co try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "contactdb/recipients/{recipient_id}"; + request.setMethod(Method.GET); + request.setEndpoint("contactdb/recipients/{recipient_id}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -1978,12 +1940,12 @@ The Contacts API helps you manage your [Marketing Campaigns](https://sendgrid.co try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.DELETE; - request.endpoint = "contactdb/recipients/{recipient_id}"; + request.setMethod(Method.DELETE); + request.setEndpoint("contactdb/recipients/{recipient_id}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -2003,12 +1965,12 @@ The Contacts API helps you manage your [Marketing Campaigns](https://sendgrid.co try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "contactdb/recipients/{recipient_id}/lists"; + request.setMethod(Method.GET); + request.setEndpoint("contactdb/recipients/{recipient_id}/lists"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -2026,12 +1988,12 @@ The contactdb is a database of your contacts for [SendGrid Marketing Campaigns]( try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "contactdb/reserved_fields"; + request.setMethod(Method.GET); + request.setEndpoint("contactdb/reserved_fields"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -2056,7 +2018,7 @@ Valid operators for create and update depend on the type of the field you are se Segment conditions using "eq" or "ne" for email clicks and opens should provide a "field" of either *clicks.campaign_identifier* or *opens.campaign_identifier*. The condition value should be a string containing the id of a completed campaign. -Segments may contain multiple condtions, joined by an "and" or "or" in the "and_or" field. The first condition in the conditions list must have an empty "and_or", and subsequent conditions must all specify an "and_or". +Segments may contain multiple conditions, joined by an "and" or "or" in the "and_or" field. The first condition in the conditions list must have an empty "and_or", and subsequent conditions must all specify an "and_or". The Contacts API helps you manage your [Marketing Campaigns](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/index.html) recipients. @@ -2069,13 +2031,13 @@ For more information about segments in Marketing Campaigns, please see our [User try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.POST; - request.endpoint = "contactdb/segments"; - request.body = "{\"conditions\":[{\"operator\":\"eq\",\"field\":\"last_name\",\"and_or\":\"\",\"value\":\"Miller\"},{\"operator\":\"gt\",\"field\":\"last_clicked\",\"and_or\":\"and\",\"value\":\"01/02/2015\"},{\"operator\":\"eq\",\"field\":\"clicks.campaign_identifier\",\"and_or\":\"or\",\"value\":\"513\"}],\"name\":\"Last Name Miller\",\"list_id\":4}"; + request.setMethod(Method.POST); + request.setEndpoint("contactdb/segments"); + request.setBody("{\"conditions\":[{\"operator\":\"eq\",\"field\":\"last_name\",\"and)_or\":\"\",\"value\":\"Miller\"},{\"operator\":\"gt\",\"field\":\"last_clicked\",\"and_or\":\"and\",\"value\":\"01/02/2015\"},{\"operator\":\"eq\",\"field\":\"clicks.campaign_identifier\",\"and_or\":\"or\",\"value\":\"513\"}],\"name\":\"Last Name Miller\",\"list_id\":4}"; Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -2095,12 +2057,12 @@ For more information about segments in Marketing Campaigns, please see our [User try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "contactdb/segments"; + request.setMethod(Method.GET); + request.setEndpoint("contactdb/segments"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -2120,16 +2082,14 @@ For more information about segments in Marketing Campaigns, please see our [User try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.PATCH; - request.endpoint = "contactdb/segments/{segment_id}"; - request.body = "{\"conditions\":[{\"operator\":\"eq\",\"field\":\"last_name\",\"and_or\":\"\",\"value\":\"Miller\"}],\"name\":\"The Millers\",\"list_id\":5}"; - Map queryParams = new HashMap(); - queryParams.put("segment_id", "test_string"); - request.queryParams = queryParams; + request.setMethod(Method.PATCH); + request.setEndpoint("contactdb/segments/{segment_id}"); + request.setBody("{\"conditions\":[{\"operator\":\"eq\",\"field\":\"last_name\",\"and)_or\":\"\",\"value\":\"Miller\"}],\"name\":\"The Millers\",\"list_id\":5}"; + request.addQueryParam("segment_id", "test_string"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -2149,15 +2109,13 @@ For more information about segments in Marketing Campaigns, please see our [User try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "contactdb/segments/{segment_id}"; - Map queryParams = new HashMap(); - queryParams.put("segment_id", "1"); - request.queryParams = queryParams; + request.setMethod(Method.GET); + request.setEndpoint("contactdb/segments/{segment_id}"); + request.addQueryParam("segment_id", "1"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -2179,15 +2137,13 @@ For more information about segments in Marketing Campaigns, please see our [User try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.DELETE; - request.endpoint = "contactdb/segments/{segment_id}"; - Map queryParams = new HashMap(); - queryParams.put("delete_contacts", "true"); - request.queryParams = queryParams; + request.setMethod(Method.DELETE); + request.setEndpoint("contactdb/segments/{segment_id}"); + request.addQueryParam("delete_contacts", "true"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -2207,16 +2163,14 @@ For more information about segments in Marketing Campaigns, please see our [User try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "contactdb/segments/{segment_id}/recipients"; - Map queryParams = new HashMap(); - queryParams.put("page", "1"); - queryParams.put("page_size", "1"); - request.queryParams = queryParams; + request.setMethod(Method.GET); + request.setEndpoint("contactdb/segments/{segment_id}/recipients"); + request.addQueryParam("page", "1"); + request.addQueryParam("page_size", "1"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -2248,19 +2202,17 @@ Advanced Stats provide a more in-depth view of your email statistics and the act try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "devices/stats"; - Map queryParams = new HashMap(); - queryParams.put("aggregated_by", "day"); - queryParams.put("limit", "1"); - queryParams.put("start_date", "2016-01-01"); - queryParams.put("end_date", "2016-04-01"); - queryParams.put("offset", "1"); - request.queryParams = queryParams; + request.setMethod(Method.GET); + request.setEndpoint("devices/stats"); + request.addQueryParam("aggregated_by", "day"); + request.addQueryParam("limit", "1"); + request.addQueryParam("start_date", "2016-01-01"); + request.addQueryParam("end_date", "2016-04-01"); + request.addQueryParam("offset", "1"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -2283,20 +2235,18 @@ Advanced Stats provide a more in-depth view of your email statistics and the act try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "geo/stats"; - Map queryParams = new HashMap(); - queryParams.put("end_date", "2016-04-01"); - queryParams.put("country", "US"); - queryParams.put("aggregated_by", "day"); - queryParams.put("limit", "1"); - queryParams.put("offset", "1"); - queryParams.put("start_date", "2016-01-01"); - request.queryParams = queryParams; + request.setMethod(Method.GET); + request.setEndpoint("geo/stats"); + request.addQueryParam("end_date", "2016-04-01"); + request.addQueryParam("country", "US"); + request.addQueryParam("aggregated_by", "day"); + request.addQueryParam("limit", "1"); + request.addQueryParam("offset", "1"); + request.addQueryParam("start_date", "2016-01-01"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -2319,19 +2269,17 @@ A single IP address or a range of IP addresses may be dedicated to an account in try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "ips"; - Map queryParams = new HashMap(); - queryParams.put("subuser", "test_string"); - queryParams.put("ip", "test_string"); - queryParams.put("limit", "1"); - queryParams.put("exclude_whitelabels", "true"); - queryParams.put("offset", "1"); - request.queryParams = queryParams; + request.setMethod(Method.GET); + request.setEndpoint("ips"); + request.addQueryParam("subuser", "test_string"); + request.addQueryParam("ip", "test_string"); + request.addQueryParam("limit", "1"); + request.addQueryParam("exclude_whitelabels", "true"); + request.addQueryParam("offset", "1"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -2349,12 +2297,12 @@ A single IP address or a range of IP addresses may be dedicated to an account in try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "ips/assigned"; + request.setMethod(Method.GET); + request.setEndpoint("ips/assigned"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -2378,20 +2326,20 @@ If an IP pool is NOT specified for an email, it will use any IP available, inclu try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.POST; - request.endpoint = "ips/pools"; - request.body = "{\"name\":\"marketing\"}"; + request.setMethod(Method.POST); + request.setEndpoint("ips/pools"); + request.setBody("{\"name\":\"marketing\"}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } ``` ## Retrieve all IP pools. -**This endpoint allows you to retreive all of your IP pools.** +**This endpoint allows you to retrieve all of your IP pools.** IP Pools allow you to group your dedicated SendGrid IP addresses together. For example, you could create separate pools for your transactional and marketing email. When sending marketing emails, specify that you want to use the marketing IP pool. This allows you to maintain separate reputations for your different email traffic. @@ -2406,12 +2354,12 @@ If an IP pool is NOT specified for an email, it will use any IP available, inclu try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "ips/pools"; + request.setMethod(Method.GET); + request.setEndpoint("ips/pools"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -2433,13 +2381,13 @@ If an IP pool is NOT specified for an email, it will use any IP available, inclu try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.PUT; - request.endpoint = "ips/pools/{pool_name}"; - request.body = "{\"name\":\"new_pool_name\"}"; + request.setMethod(Method.PUT); + request.setEndpoint("ips/pools/{pool_name}"); + request.setBody("{\"name\":\"new_pool_name\"}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -2461,12 +2409,12 @@ If an IP pool is NOT specified for an email, it will use any IP available, inclu try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "ips/pools/{pool_name}"; + request.setMethod(Method.GET); + request.setEndpoint("ips/pools/{pool_name}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -2488,12 +2436,12 @@ If an IP pool is NOT specified for an email, it will use any IP available, inclu try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.DELETE; - request.endpoint = "ips/pools/{pool_name}"; + request.setMethod(Method.DELETE); + request.setEndpoint("ips/pools/{pool_name}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -2513,13 +2461,13 @@ A single IP address or a range of IP addresses may be dedicated to an account in try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.POST; - request.endpoint = "ips/pools/{pool_name}/ips"; - request.body = "{\"ip\":\"0.0.0.0\"}"; + request.setMethod(Method.POST); + request.setEndpoint("ips/pools/{pool_name}/ips"); + request.setBody("{\"ip\":\"0.0.0.0\"}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -2539,12 +2487,12 @@ A single IP address or a range of IP addresses may be dedicated to an account in try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.DELETE; - request.endpoint = "ips/pools/{pool_name}/ips/{ip}"; + request.setMethod(Method.DELETE); + request.setEndpoint("ips/pools/{pool_name}/ips/{ip}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -2564,13 +2512,13 @@ For more general information about warming up IPs, please see our [Classroom](ht try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.POST; - request.endpoint = "ips/warmup"; - request.body = "{\"ip\":\"0.0.0.0\"}"; + request.setMethod(Method.POST); + request.setEndpoint("ips/warmup"); + request.setBody("{\"ip\":\"0.0.0.0\"}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -2590,12 +2538,12 @@ For more general information about warming up IPs, please see our [Classroom](ht try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "ips/warmup"; + request.setMethod(Method.GET); + request.setEndpoint("ips/warmup"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -2615,12 +2563,12 @@ For more general information about warming up IPs, please see our [Classroom](ht try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "ips/warmup/{ip_address}"; + request.setMethod(Method.GET); + request.setEndpoint("ips/warmup/{ip_address}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -2640,12 +2588,12 @@ For more general information about warming up IPs, please see our [Classroom](ht try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.DELETE; - request.endpoint = "ips/warmup/{ip_address}"; + request.setMethod(Method.DELETE); + request.setEndpoint("ips/warmup/{ip_address}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -2665,12 +2613,12 @@ A single IP address or a range of IP addresses may be dedicated to an account in try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "ips/{ip_address}"; + request.setMethod(Method.GET); + request.setEndpoint("ips/{ip_address}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -2695,12 +2643,12 @@ More Information: try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.POST; - request.endpoint = "mail/batch"; + request.setMethod(Method.POST); + request.setEndpoint("mail/batch"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -2722,12 +2670,12 @@ More Information: try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "mail/batch/{batch_id}"; + request.setMethod(Method.GET); + request.setEndpoint("mail/batch/{batch_id}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -2751,18 +2699,18 @@ This endpoint has a helper, check it out [here](https://github.com/sendgrid/send try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.POST; - request.endpoint = "mail/send"; - request.body = "{\"custom_args\":{\"New Argument 1\":\"New Value 1\",\"activationAttempt\":\"1\",\"customerAccountNumber\":\"[CUSTOMER ACCOUNT NUMBER GOES HERE]\"},\"from\":{\"email\":\"sam.smith@example.com\",\"name\":\"Sam Smith\"},\"attachments\":[{\"name\":\"file1\",\"filename\":\"file1.jpg\",\"content\":\"[BASE64 encoded content block here]\",\"disposition\":\"inline\",\"content_id\":\"ii_139db99fdb5c3704\",\"type\":\"jpg\"}],\"personalizations\":[{\"to\":[{\"email\":\"john.doe@example.com\",\"name\":\"John Doe\"}],\"cc\":[{\"email\":\"jane.doe@example.com\",\"name\":\"Jane Doe\"}],\"bcc\":[{\"email\":\"sam.doe@example.com\",\"name\":\"Sam Doe\"}],\"custom_args\":{\"New Argument 1\":\"New Value 1\",\"activationAttempt\":\"1\",\"customerAccountNumber\":\"[CUSTOMER ACCOUNT NUMBER GOES HERE]\"},\"headers\":{\"X-Accept-Language\":\"en\",\"X-Mailer\":\"MyApp\"},\"send_at\":1409348513,\"substitutions\":{\"type\":\"object\",\"id\":\"substitutions\"},\"subject\":\"Hello, World!\"}],\"subject\":\"Hello, World!\",\"ip_pool_name\":\"[YOUR POOL NAME GOES HERE]\",\"content\":[{\"type\":\"text/html\",\"value\":\"

Hello, world!

\"}],\"headers\":{},\"asm\":{\"groups_to_display\":[1,2,3],\"group_id\":1},\"batch_id\":\"[YOUR BATCH ID GOES HERE]\",\"tracking_settings\":{\"subscription_tracking\":{\"text\":\"If you would like to unsubscribe and stop receiveing these emails <% click here %>.\",\"enable\":true,\"html\":\"If you would like to unsubscribe and stop receiving these emails <% clickhere %>.\",\"substitution_tag\":\"<%click here%>\"},\"open_tracking\":{\"enable\":true,\"substitution_tag\":\"%opentrack\"},\"click_tracking\":{\"enable\":true,\"enable_text\":true},\"ganalytics\":{\"utm_campaign\":\"[NAME OF YOUR REFERRER SOURCE]\",\"enable\":true,\"utm_name\":\"[NAME OF YOUR CAMPAIGN]\",\"utm_term\":\"[IDENTIFY PAID KEYWORDS HERE]\",\"utm_content\":\"[USE THIS SPACE TO DIFFERENTIATE YOUR EMAIL FROM ADS]\",\"utm_medium\":\"[NAME OF YOUR MARKETING MEDIUM e.g. email]\"}},\"mail_settings\":{\"footer\":{\"text\":\"Thanks,/n The SendGrid Team\",\"enable\":true,\"html\":\"

Thanks
The SendGrid Team

\"},\"spam_check\":{\"threshold\":3,\"post_to_url\":\"http://example.com/compliance\",\"enable\":true},\"bypass_list_management\":{\"enable\":true},\"sandbox_mode\":{\"enable\":false},\"bcc\":{\"enable\":true,\"email\":\"ben.doe@example.com\"}},\"reply_to\":{\"email\":\"sam.smith@example.com\",\"name\":\"Sam Smith\"},\"sections\":{\"section\":{\":sectionName2\":\"section 2 text\",\":sectionName1\":\"section 1 text\"}},\"template_id\":\"[YOUR TEMPLATE ID GOES HERE]\",\"categories\":[\"category1\",\"category2\"],\"send_at\":1409348513}"; + request.setMethod(Method.POST); + request.setEndpoint("mail/send"); + request.setBody("{\"custom_args\":{\"New Argument 1\":\"New Value 1\",\"activationAttempt\":\"1\",\"customerAccountNumber\":\")[CUSTOMER ACCOUNT NUMBER GOES HERE]\"},\"from\":{\"email\":\"sam.smith@example.com\",\"name\":\"Sam Smith\"},\"attachments\":[{\"name\":\"file1\",\"filename\":\"file1.jpg\",\"content\":\"[BASE64 encoded content block here]\",\"disposition\":\"inline\",\"content_id\":\"ii_139db99fdb5c3704\",\"type\":\"jpg\"}],\"personalizations\":[{\"to\":[{\"email\":\"john.doe@example.com\",\"name\":\"John Doe\"}],\"cc\":[{\"email\":\"jane.doe@example.com\",\"name\":\"Jane Doe\"}],\"bcc\":[{\"email\":\"sam.doe@example.com\",\"name\":\"Sam Doe\"}],\"custom_args\":{\"New Argument 1\":\"New Value 1\",\"activationAttempt\":\"1\",\"customerAccountNumber\":\"[CUSTOMER ACCOUNT NUMBER GOES HERE]\"},\"headers\":{\"X-Accept-Language\":\"en\",\"X-Mailer\":\"MyApp\"},\"send_at\":1409348513,\"substitutions\":{\"type\":\"object\",\"id\":\"substitutions\"},\"subject\":\"Hello, World!\"}],\"subject\":\"Hello, World!\",\"ip_pool_name\":\"[YOUR POOL NAME GOES HERE]\",\"content\":[{\"type\":\"text/html\",\"value\":\"

Hello, world!

\"}],\"headers\":{},\"asm\":{\"groups_to_display\":[1,2,3],\"group_id\":1},\"batch_id\":\"[YOUR BATCH ID GOES HERE]\",\"tracking_settings\":{\"subscription_tracking\":{\"text\":\"If you would like to unsubscribe and stop receiving these emails <% click here %>.\",\"enable\":true,\"html\":\"If you would like to unsubscribe and stop receiving these emails <% clickhere %>.\",\"substitution_tag\":\"<%click here%>\"},\"open_tracking\":{\"enable\":true,\"substitution_tag\":\"%opentrack\"},\"click_tracking\":{\"enable\":true,\"enable_text\":true},\"ganalytics\":{\"utm_campaign\":\"[NAME OF YOUR REFERRER SOURCE]\",\"enable\":true,\"utm_name\":\"[NAME OF YOUR CAMPAIGN]\",\"utm_term\":\"[IDENTIFY PAID KEYWORDS HERE]\",\"utm_content\":\"[USE THIS SPACE TO DIFFERENTIATE YOUR EMAIL FROM ADS]\",\"utm_medium\":\"[NAME OF YOUR MARKETING MEDIUM e.g. email]\"}},\"mail_settings\":{\"footer\":{\"text\":\"Thanks,/n The SendGrid Team\",\"enable\":true,\"html\":\"

Thanks
The SendGrid Team

\"},\"spam_check\":{\"threshold\":3,\"post_to_url\":\"http://example.com/compliance\",\"enable\":true},\"bypass_list_management\":{\"enable\":true},\"sandbox_mode\":{\"enable\":false},\"bcc\":{\"enable\":true,\"email\":\"ben.doe@example.com\"}},\"reply_to\":{\"email\":\"sam.smith@example.com\",\"name\":\"Sam Smith\"},\"sections\":{\"section\":{\":sectionName2\":\"section 2 text\",\":sectionName1\":\"section 1 text\"}},\"template_id\":\"[YOUR TEMPLATE ID GOES HERE]\",\"categories\":[\"category1\",\"category2\"],\"send_at\":1409348513}"; Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } ``` - + # MAIL SETTINGS ## Retrieve all mail settings @@ -2778,16 +2726,14 @@ Mail settings allow you to tell SendGrid specific things to do to every email th try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "mail_settings"; - Map queryParams = new HashMap(); - queryParams.put("limit", "1"); - queryParams.put("offset", "1"); - request.queryParams = queryParams; + 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.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -2807,13 +2753,13 @@ Mail settings allow you to tell SendGrid specific things to do to every email th try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.PATCH; - request.endpoint = "mail_settings/address_whitelist"; - request.body = "{\"list\":[\"email1@example.com\",\"example.com\"],\"enabled\":true}"; + 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.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -2833,12 +2779,12 @@ Mail settings allow you to tell SendGrid specific things to do to every email th try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "mail_settings/address_whitelist"; + request.setMethod(Method.GET); + request.setEndpoint("mail_settings/address_whitelist"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -2858,13 +2804,13 @@ Mail settings allow you to tell SendGrid specific things to do to every email th try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.PATCH; - request.endpoint = "mail_settings/bcc"; - request.body = "{\"enabled\":false,\"email\":\"email@example.com\"}"; + 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.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -2884,12 +2830,12 @@ Mail settings allow you to tell SendGrid specific things to do to every email th try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "mail_settings/bcc"; + request.setMethod(Method.GET); + request.setEndpoint("mail_settings/bcc"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -2909,13 +2855,13 @@ Mail settings allow you to tell SendGrid specific things to do to every email th try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.PATCH; - request.endpoint = "mail_settings/bounce_purge"; - request.body = "{\"hard_bounces\":5,\"soft_bounces\":5,\"enabled\":true}"; + 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.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -2935,12 +2881,12 @@ Mail settings allow you to tell SendGrid specific things to do to every email th try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "mail_settings/bounce_purge"; + request.setMethod(Method.GET); + request.setEndpoint("mail_settings/bounce_purge"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -2960,13 +2906,13 @@ Mail settings allow you to tell SendGrid specific things to do to every email th try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.PATCH; - request.endpoint = "mail_settings/footer"; - request.body = "{\"html_content\":\"...\",\"enabled\":true,\"plain_content\":\"...\"}"; + 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.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -2986,12 +2932,12 @@ Mail settings allow you to tell SendGrid specific things to do to every email th try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "mail_settings/footer"; + request.setMethod(Method.GET); + request.setEndpoint("mail_settings/footer"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -3011,13 +2957,13 @@ Mail settings allow you to tell SendGrid specific things to do to every email th try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.PATCH; - request.endpoint = "mail_settings/forward_bounce"; - request.body = "{\"enabled\":true,\"email\":\"example@example.com\"}"; + 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.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -3037,12 +2983,12 @@ Mail settings allow you to tell SendGrid specific things to do to every email th try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "mail_settings/forward_bounce"; + request.setMethod(Method.GET); + request.setEndpoint("mail_settings/forward_bounce"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -3062,13 +3008,13 @@ Mail settings allow you to tell SendGrid specific things to do to every email th try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.PATCH; - request.endpoint = "mail_settings/forward_spam"; - request.body = "{\"enabled\":false,\"email\":\"\"}"; + request.setMethod(Method.PATCH); + request.setEndpoint("mail_settings/forward_spam"); + request.setBody("{\"enabled\":false,\"email\":\"\"}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -3088,12 +3034,12 @@ Mail settings allow you to tell SendGrid specific things to do to every email th try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "mail_settings/forward_spam"; + request.setMethod(Method.GET); + request.setEndpoint("mail_settings/forward_spam"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -3113,13 +3059,13 @@ Mail settings allow you to tell SendGrid specific things to do to every email th try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.PATCH; - request.endpoint = "mail_settings/plain_content"; - request.body = "{\"enabled\":false}"; + request.setMethod(Method.PATCH); + request.setEndpoint("mail_settings/plain_content"); + request.setBody("{\"enabled\":false}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -3139,12 +3085,12 @@ Mail settings allow you to tell SendGrid specific things to do to every email th try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "mail_settings/plain_content"; + request.setMethod(Method.GET); + request.setEndpoint("mail_settings/plain_content"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -3164,13 +3110,13 @@ Mail settings allow you to tell SendGrid specific things to do to every email th try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.PATCH; - request.endpoint = "mail_settings/spam_check"; - request.body = "{\"url\":\"url\",\"max_score\":5,\"enabled\":true}"; + 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.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -3190,12 +3136,12 @@ Mail settings allow you to tell SendGrid specific things to do to every email th try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "mail_settings/spam_check"; + request.setMethod(Method.GET); + request.setEndpoint("mail_settings/spam_check"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -3217,13 +3163,13 @@ Mail settings allow you to tell SendGrid specific things to do to every email th try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.PATCH; - request.endpoint = "mail_settings/template"; - request.body = "{\"html_content\":\"<% body %>\",\"enabled\":true}"; + 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.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -3245,17 +3191,17 @@ Mail settings allow you to tell SendGrid specific things to do to every email th try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "mail_settings/template"; + request.setMethod(Method.GET); + request.setEndpoint("mail_settings/template"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } ``` - + # MAILBOX PROVIDERS ## Retrieve email statistics by mailbox provider. @@ -3273,25 +3219,23 @@ Advanced Stats provide a more in-depth view of your email statistics and the act try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "mailbox_providers/stats"; - Map queryParams = new HashMap(); - queryParams.put("end_date", "2016-04-01"); - queryParams.put("mailbox_providers", "test_string"); - queryParams.put("aggregated_by", "day"); - queryParams.put("limit", "1"); - queryParams.put("offset", "1"); - queryParams.put("start_date", "2016-01-01"); - request.queryParams = queryParams; + request.setMethod(Method.GET); + request.setEndpoint("mailbox_providers/stats"); + request.addQueryParam("end_date", "2016-04-01"); + request.addQueryParam("mailbox_providers", "test_string"); + request.addQueryParam("aggregated_by", "day"); + request.addQueryParam("limit", "1"); + request.addQueryParam("offset", "1"); + request.addQueryParam("start_date", "2016-01-01"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } ``` - + # PARTNER SETTINGS ## Returns a list of all partner settings. @@ -3307,16 +3251,14 @@ Our partner settings allow you to integrate your SendGrid account with our partn try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "partner_settings"; - Map queryParams = new HashMap(); - queryParams.put("limit", "1"); - queryParams.put("offset", "1"); - request.queryParams = queryParams; + request.setMethod(Method.GET); + request.setEndpoint("partner_settings"); + request.addQueryParam("limit", "1"); + request.addQueryParam("offset", "1"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -3336,13 +3278,13 @@ By integrating with New Relic, you can send your SendGrid email statistics to yo try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.PATCH; - request.endpoint = "partner_settings/new_relic"; - request.body = "{\"enable_subuser_statistics\":true,\"enabled\":true,\"license_key\":\"\"}"; + request.setMethod(Method.PATCH); + request.setEndpoint("partner_settings/new_relic"); + request.setBody("{\"enable_subuser_statistics\":true,\"enabled\":true,\"license_key\":\"\"}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -3362,12 +3304,12 @@ By integrating with New Relic, you can send your SendGrid email statistics to yo try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "partner_settings/new_relic"; + request.setMethod(Method.GET); + request.setEndpoint("partner_settings/new_relic"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -3379,7 +3321,7 @@ By integrating with New Relic, you can send your SendGrid email statistics to yo **This endpoint returns a list of all scopes that this user has access to.** -API Keys can be used to authenticate the use of [SendGrids v3 Web API](https://sendgrid.com/docs/API_Reference/Web_API_v3/index.html), or the [Mail API Endpoint](https://sendgrid.com/docs/API_Reference/Web_API/mail.html). API Keys may be assigned certain permissions, or scopes, that limit which API endpoints they are able to access. For a more detailed explanation of how you can use API Key permissios, please visit our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/api_keys.html#-API-Key-Permissions) or [Classroom](https://sendgrid.com/docs/Classroom/Basics/API/api_key_permissions.html). +API Keys can be used to authenticate the use of [SendGrids v3 Web API](https://sendgrid.com/docs/API_Reference/Web_API_v3/index.html), or the [Mail API Endpoint](https://sendgrid.com/docs/API_Reference/Web_API/mail.html). API Keys may be assigned certain permissions, or scopes, that limit which API endpoints they are able to access. For a more detailed explanation of how you can use API Key permissions, please visit our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/api_keys.html#-API-Key-Permissions) or [Classroom](https://sendgrid.com/docs/Classroom/Basics/API/api_key_permissions.html). ### GET /scopes @@ -3388,12 +3330,12 @@ API Keys can be used to authenticate the use of [SendGrids v3 Web API](https://s try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "scopes"; + request.setMethod(Method.GET); + request.setEndpoint("scopes"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -3416,13 +3358,13 @@ Sender Identities are required to be verified before use. If your domain has bee try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.POST; - request.endpoint = "senders"; - request.body = "{\"city\":\"Denver\",\"from\":{\"email\":\"from@example.com\",\"name\":\"Example INC\"},\"zip\":\"80202\",\"country\":\"United States\",\"state\":\"Colorado\",\"address_2\":\"Apt. 456\",\"address\":\"123 Elm St.\",\"reply_to\":{\"email\":\"replyto@example.com\",\"name\":\"Example INC\"},\"nickname\":\"My Sender ID\"}"; + request.setMethod(Method.POST); + request.setEndpoint("senders"); + request.setBody("{\"city\":\"Denver\",\"from\":{\"email\":\"from@example.com\",\"name\":\"Example) INC\"},\"zip\":\"80202\",\"country\":\"United States\",\"state\":\"Colorado\",\"address_2\":\"Apt. 456\",\"address\":\"123 Elm St.\",\"reply_to\":{\"email\":\"replyto@example.com\",\"name\":\"Example INC\"},\"nickname\":\"My Sender ID\"}"; Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -3440,12 +3382,12 @@ Sender Identities are required to be verified before use. If your domain has bee try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "senders"; + request.setMethod(Method.GET); + request.setEndpoint("senders"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -3465,13 +3407,13 @@ Partial updates are allowed, but fields that are marked as "required" in the POS try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.PATCH; - request.endpoint = "senders/{sender_id}"; - request.body = "{\"city\":\"Denver\",\"from\":{\"email\":\"from@example.com\",\"name\":\"Example INC\"},\"zip\":\"80202\",\"country\":\"United States\",\"state\":\"Colorado\",\"address_2\":\"Apt. 456\",\"address\":\"123 Elm St.\",\"reply_to\":{\"email\":\"replyto@example.com\",\"name\":\"Example INC\"},\"nickname\":\"My Sender ID\"}"; + request.setMethod(Method.PATCH); + request.setEndpoint("senders/{sender_id}"); + request.setBody("{\"city\":\"Denver\",\"from\":{\"email\":\"from@example.com\",\"name\":\"Example) INC\"},\"zip\":\"80202\",\"country\":\"United States\",\"state\":\"Colorado\",\"address_2\":\"Apt. 456\",\"address\":\"123 Elm St.\",\"reply_to\":{\"email\":\"replyto@example.com\",\"name\":\"Example INC\"},\"nickname\":\"My Sender ID\"}"; Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -3489,19 +3431,19 @@ Sender Identities are required to be verified before use. If your domain has bee try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "senders/{sender_id}"; + request.setMethod(Method.GET); + request.setEndpoint("senders/{sender_id}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } ``` ## Delete a Sender Identity -**This endoint allows you to delete one of your sender identities.** +**This endpoint allows you to delete one of your sender identities.** Sender Identities are required to be verified before use. If your domain has been whitelabeled it will auto verify on creation. Otherwise an email will be sent to the `from.email`. @@ -3512,19 +3454,19 @@ Sender Identities are required to be verified before use. If your domain has bee try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.DELETE; - request.endpoint = "senders/{sender_id}"; + request.setMethod(Method.DELETE); + request.setEndpoint("senders/{sender_id}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } ``` ## Resend Sender Identity Verification -**This enpdoint allows you to resend a sender identity verification email.** +**This endpoint allows you to resend a sender identity verification email.** Sender Identities are required to be verified before use. If your domain has been whitelabeled it will auto verify on creation. Otherwise an email will be sent to the `from.email`. @@ -3535,12 +3477,12 @@ Sender Identities are required to be verified before use. If your domain has bee try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.POST; - request.endpoint = "senders/{sender_id}/resend_verification"; + request.setMethod(Method.POST); + request.setEndpoint("senders/{sender_id}/resend_verification"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -3561,19 +3503,17 @@ Parent accounts will see aggregated stats for their account and all subuser acco try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "stats"; - Map queryParams = new HashMap(); - queryParams.put("aggregated_by", "day"); - queryParams.put("limit", "1"); - queryParams.put("start_date", "2016-01-01"); - queryParams.put("end_date", "2016-04-01"); - queryParams.put("offset", "1"); - request.queryParams = queryParams; + request.setMethod(Method.GET); + request.setEndpoint("stats"); + request.addQueryParam("aggregated_by", "day"); + request.addQueryParam("limit", "1"); + request.addQueryParam("start_date", "2016-01-01"); + request.addQueryParam("end_date", "2016-04-01"); + request.addQueryParam("offset", "1"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -3597,13 +3537,13 @@ For more information about Subusers: try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.POST; - request.endpoint = "subusers"; - request.body = "{\"username\":\"John@example.com\",\"ips\":[\"1.1.1.1\",\"2.2.2.2\"],\"password\":\"johns_password\",\"email\":\"John@example.com\"}"; + request.setMethod(Method.POST); + request.setEndpoint("subusers"); + request.setBody("{\"username\":\"John@example.com\",\"ips\":[\"1.1.1.1\",\"2.2.2.2\"],\"password\":\"johns_password\",\"email\)":\"John@example.com\"}"; Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -3624,17 +3564,15 @@ For more information about Subusers: try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "subusers"; - Map queryParams = new HashMap(); - queryParams.put("username", "test_string"); - queryParams.put("limit", "1"); - queryParams.put("offset", "1"); - request.queryParams = queryParams; + request.setMethod(Method.GET); + request.setEndpoint("subusers"); + request.addQueryParam("username", "test_string"); + request.addQueryParam("limit", "1"); + request.addQueryParam("offset", "1"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -3652,15 +3590,13 @@ This endpoint allows you to request the reputations for your subusers. try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "subusers/reputations"; - Map queryParams = new HashMap(); - queryParams.put("usernames", "test_string"); - request.queryParams = queryParams; + request.setMethod(Method.GET); + request.setEndpoint("subusers/reputations"); + request.addQueryParam("usernames", "test_string"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -3682,20 +3618,18 @@ For more information, see our [User Guide](https://sendgrid.com/docs/User_Guide/ try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "subusers/stats"; - Map queryParams = new HashMap(); - queryParams.put("end_date", "2016-04-01"); - queryParams.put("aggregated_by", "day"); - queryParams.put("limit", "1"); - queryParams.put("offset", "1"); - queryParams.put("start_date", "2016-01-01"); - queryParams.put("subusers", "test_string"); - request.queryParams = queryParams; + request.setMethod(Method.GET); + request.setEndpoint("subusers/stats"); + request.addQueryParam("end_date", "2016-04-01"); + request.addQueryParam("aggregated_by", "day"); + request.addQueryParam("limit", "1"); + request.addQueryParam("offset", "1"); + request.addQueryParam("start_date", "2016-01-01"); + request.addQueryParam("subusers", "test_string"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -3718,20 +3652,18 @@ For more information, see our [User Guide](https://sendgrid.com/docs/User_Guide/ try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "subusers/stats/monthly"; - Map queryParams = new HashMap(); - queryParams.put("subuser", "test_string"); - queryParams.put("limit", "1"); - queryParams.put("sort_by_metric", "test_string"); - queryParams.put("offset", "1"); - queryParams.put("date", "test_string"); - queryParams.put("sort_by_direction", "asc"); - request.queryParams = queryParams; + request.setMethod(Method.GET); + request.setEndpoint("subusers/stats/monthly"); + request.addQueryParam("subuser", "test_string"); + request.addQueryParam("limit", "1"); + request.addQueryParam("sort_by_metric", "test_string"); + request.addQueryParam("offset", "1"); + request.addQueryParam("date", "test_string"); + request.addQueryParam("sort_by_direction", "asc"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -3752,21 +3684,19 @@ For more information, see our [User Guide](https://sendgrid.com/docs/User_Guide/ try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "subusers/stats/sums"; - Map queryParams = new HashMap(); - queryParams.put("end_date", "2016-04-01"); - queryParams.put("aggregated_by", "day"); - queryParams.put("limit", "1"); - queryParams.put("sort_by_metric", "test_string"); - queryParams.put("offset", "1"); - queryParams.put("start_date", "2016-01-01"); - queryParams.put("sort_by_direction", "asc"); - request.queryParams = queryParams; + request.setMethod(Method.GET); + request.setEndpoint("subusers/stats/sums"); + request.addQueryParam("end_date", "2016-04-01"); + request.addQueryParam("aggregated_by", "day"); + request.addQueryParam("limit", "1"); + request.addQueryParam("sort_by_metric", "test_string"); + request.addQueryParam("offset", "1"); + request.addQueryParam("start_date", "2016-01-01"); + request.addQueryParam("sort_by_direction", "asc"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -3787,13 +3717,13 @@ For more information about Subusers: try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.PATCH; - request.endpoint = "subusers/{subuser_name}"; - request.body = "{\"disabled\":false}"; + request.setMethod(Method.PATCH); + request.setEndpoint("subusers/{subuser_name}"); + request.setBody("{\"disabled\":false}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -3814,12 +3744,12 @@ For more information about Subusers: try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.DELETE; - request.endpoint = "subusers/{subuser_name}"; + request.setMethod(Method.DELETE); + request.setEndpoint("subusers/{subuser_name}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -3840,13 +3770,13 @@ More information: try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.PUT; - request.endpoint = "subusers/{subuser_name}/ips"; - request.body = "[\"127.0.0.1\"]"; + request.setMethod(Method.PUT); + request.setEndpoint("subusers/{subuser_name}/ips"); + request.setBody("[\"127.0.0.1\"]"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -3862,13 +3792,13 @@ Subuser monitor settings allow you to receive a sample of an outgoing message by try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.PUT; - request.endpoint = "subusers/{subuser_name}/monitor"; - request.body = "{\"frequency\":500,\"email\":\"example@example.com\"}"; + request.setMethod(Method.PUT); + request.setEndpoint("subusers/{subuser_name}/monitor"); + request.setBody("{\"frequency\":500,\"email\":\"example@example.com\"}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -3884,13 +3814,13 @@ Subuser monitor settings allow you to receive a sample of an outgoing message by try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.POST; - request.endpoint = "subusers/{subuser_name}/monitor"; - request.body = "{\"frequency\":50000,\"email\":\"example@example.com\"}"; + request.setMethod(Method.POST); + request.setEndpoint("subusers/{subuser_name}/monitor"); + request.setBody("{\"frequency\":50000,\"email\":\"example@example.com\"}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -3906,12 +3836,12 @@ Subuser monitor settings allow you to receive a sample of an outgoing message by try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "subusers/{subuser_name}/monitor"; + request.setMethod(Method.GET); + request.setEndpoint("subusers/{subuser_name}/monitor"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -3927,19 +3857,19 @@ Subuser monitor settings allow you to receive a sample of an outgoing message by try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.DELETE; - request.endpoint = "subusers/{subuser_name}/monitor"; + request.setMethod(Method.DELETE); + request.setEndpoint("subusers/{subuser_name}/monitor"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } ``` ## Retrieve the monthly email statistics for a single subuser -**This endpoint allows you to retrive the monthly email statistics for a specific subuser.** +**This endpoint allows you to retrieve the monthly email statistics for a specific subuser.** While you can always view the statistics for all email activity on your account, subuser statistics enable you to view specific segments of your stats for your subusers. Emails sent, bounces, and spam reports are always tracked for subusers. Unsubscribes, clicks, and opens are tracked if you have enabled the required settings. @@ -3955,19 +3885,17 @@ For more information, see our [User Guide](https://sendgrid.com/docs/User_Guide/ try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "subusers/{subuser_name}/stats/monthly"; - Map queryParams = new HashMap(); - queryParams.put("date", "test_string"); - queryParams.put("sort_by_direction", "asc"); - queryParams.put("limit", "1"); - queryParams.put("sort_by_metric", "test_string"); - queryParams.put("offset", "1"); - request.queryParams = queryParams; + request.setMethod(Method.GET); + request.setEndpoint("subusers/{subuser_name}/stats/monthly"); + request.addQueryParam("date", "test_string"); + request.addQueryParam("sort_by_direction", "asc"); + request.addQueryParam("limit", "1"); + request.addQueryParam("sort_by_metric", "test_string"); + request.addQueryParam("offset", "1"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -3990,18 +3918,16 @@ For more information, please see our [User Guide](https://sendgrid.com/docs/User try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "suppression/blocks"; - Map queryParams = new HashMap(); - queryParams.put("start_time", "1"); - queryParams.put("limit", "1"); - queryParams.put("end_time", "1"); - queryParams.put("offset", "1"); - request.queryParams = queryParams; + request.setMethod(Method.GET); + request.setEndpoint("suppression/blocks"); + request.addQueryParam("start_time", "1"); + request.addQueryParam("limit", "1"); + request.addQueryParam("end_time", "1"); + request.addQueryParam("offset", "1"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -4026,13 +3952,13 @@ For more information, please see our [User Guide](https://sendgrid.com/docs/User try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.DELETE; - request.endpoint = "suppression/blocks"; - request.body = "{\"emails\":[\"example1@example.com\",\"example2@example.com\"],\"delete_all\":false}"; + request.setMethod(Method.DELETE); + request.setEndpoint("suppression/blocks"); + request.setBody("{\"emails\":[\"example1@example.com\",\"example2@example.com\"],\"delete_all\":false}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -4052,12 +3978,12 @@ For more information, please see our [User Guide](https://sendgrid.com/docs/User try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "suppression/blocks/{email}"; + request.setMethod(Method.GET); + request.setEndpoint("suppression/blocks/{email}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -4077,12 +4003,12 @@ For more information, please see our [User Guide](https://sendgrid.com/docs/User try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.DELETE; - request.endpoint = "suppression/blocks/{email}"; + request.setMethod(Method.DELETE); + request.setEndpoint("suppression/blocks/{email}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -4105,16 +4031,14 @@ For more information see: try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "suppression/bounces"; - Map queryParams = new HashMap(); - queryParams.put("start_time", "1"); - queryParams.put("end_time", "1"); - request.queryParams = queryParams; + request.setMethod(Method.GET); + request.setEndpoint("suppression/bounces"); + request.addQueryParam("start_time", "1"); + request.addQueryParam("end_time", "1"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -4140,13 +4064,13 @@ Note: the `delete_all` and `emails` parameters should be used independently of e try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.DELETE; - request.endpoint = "suppression/bounces"; - request.body = "{\"emails\":[\"example@example.com\",\"example2@example.com\"],\"delete_all\":true}"; + request.setMethod(Method.DELETE); + request.setEndpoint("suppression/bounces"); + request.setBody("{\"emails\":[\"example@example.com\",\"example2@example.com\"],\"delete_all\":true}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -4170,12 +4094,12 @@ For more information see: try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "suppression/bounces/{email}"; + request.setMethod(Method.GET); + request.setEndpoint("suppression/bounces/{email}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -4199,15 +4123,13 @@ For more information see: try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.DELETE; - request.endpoint = "suppression/bounces/{email}"; - Map queryParams = new HashMap(); - queryParams.put("email_address", "example@example.com"); - request.queryParams = queryParams; + request.setMethod(Method.DELETE); + request.setEndpoint("suppression/bounces/{email}"); + request.addQueryParam("email_address", "example@example.com"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -4229,18 +4151,16 @@ For more information, please see our [User Guide](https://sendgrid.com/docs/User try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "suppression/invalid_emails"; - Map queryParams = new HashMap(); - queryParams.put("start_time", "1"); - queryParams.put("limit", "1"); - queryParams.put("end_time", "1"); - queryParams.put("offset", "1"); - request.queryParams = queryParams; + request.setMethod(Method.GET); + request.setEndpoint("suppression/invalid_emails"); + request.addQueryParam("start_time", "1"); + request.addQueryParam("limit", "1"); + request.addQueryParam("end_time", "1"); + request.addQueryParam("offset", "1"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -4267,13 +4187,13 @@ For more information, please see our [User Guide](https://sendgrid.com/docs/User try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.DELETE; - request.endpoint = "suppression/invalid_emails"; - request.body = "{\"emails\":[\"example1@example.com\",\"example2@example.com\"],\"delete_all\":false}"; + request.setMethod(Method.DELETE); + request.setEndpoint("suppression/invalid_emails"); + request.setBody("{\"emails\":[\"example1@example.com\",\"example2@example.com\"],\"delete_all\":false}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -4295,12 +4215,12 @@ For more information, please see our [User Guide](https://sendgrid.com/docs/User try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "suppression/invalid_emails/{email}"; + request.setMethod(Method.GET); + request.setEndpoint("suppression/invalid_emails/{email}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -4322,12 +4242,12 @@ For more information, please see our [User Guide](https://sendgrid.com/docs/User try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.DELETE; - request.endpoint = "suppression/invalid_emails/{email}"; + request.setMethod(Method.DELETE); + request.setEndpoint("suppression/invalid_emails/{email}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -4347,12 +4267,12 @@ For more information, please see our [User Guide](https://sendgrid.com/docs/User try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "suppression/spam_report/{email}"; + request.setMethod(Method.GET); + request.setEndpoint("suppression/spam_report/{email}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -4372,12 +4292,12 @@ For more information, please see our [User Guide](https://sendgrid.com/docs/User try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.DELETE; - request.endpoint = "suppression/spam_report/{email}"; + request.setMethod(Method.DELETE); + request.setEndpoint("suppression/spam_report/{email}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -4397,18 +4317,16 @@ For more information, please see our [User Guide](https://sendgrid.com/docs/User try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "suppression/spam_reports"; - Map queryParams = new HashMap(); - queryParams.put("start_time", "1"); - queryParams.put("limit", "1"); - queryParams.put("end_time", "1"); - queryParams.put("offset", "1"); - request.queryParams = queryParams; + request.setMethod(Method.GET); + request.setEndpoint("suppression/spam_reports"); + request.addQueryParam("start_time", "1"); + request.addQueryParam("limit", "1"); + request.addQueryParam("end_time", "1"); + request.addQueryParam("offset", "1"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -4433,13 +4351,13 @@ For more information, please see our [User Guide](https://sendgrid.com/docs/User try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.DELETE; - request.endpoint = "suppression/spam_reports"; - request.body = "{\"emails\":[\"example1@example.com\",\"example2@example.com\"],\"delete_all\":false}"; + request.setMethod(Method.DELETE); + request.setEndpoint("suppression/spam_reports"); + request.setBody("{\"emails\":[\"example1@example.com\",\"example2@example.com\"],\"delete_all\":false}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -4457,18 +4375,16 @@ A global suppression (or global unsubscribe) is an email address of a recipient try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "suppression/unsubscribes"; - Map queryParams = new HashMap(); - queryParams.put("start_time", "1"); - queryParams.put("limit", "1"); - queryParams.put("end_time", "1"); - queryParams.put("offset", "1"); - request.queryParams = queryParams; + request.setMethod(Method.GET); + request.setEndpoint("suppression/unsubscribes"); + request.addQueryParam("start_time", "1"); + request.addQueryParam("limit", "1"); + request.addQueryParam("end_time", "1"); + request.addQueryParam("offset", "1"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -4491,13 +4407,13 @@ Transactional templates are templates created specifically for transactional ema try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.POST; - request.endpoint = "templates"; - request.body = "{\"name\":\"example_name\"}"; + request.setMethod(Method.POST); + request.setEndpoint("templates"); + request.setBody("{\"name\":\"example_name\"}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -4517,12 +4433,12 @@ Transactional templates are templates created specifically for transactional ema try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "templates"; + request.setMethod(Method.GET); + request.setEndpoint("templates"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -4543,13 +4459,13 @@ Transactional templates are templates created specifically for transactional ema try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.PATCH; - request.endpoint = "templates/{template_id}"; - request.body = "{\"name\":\"new_example_name\"}"; + request.setMethod(Method.PATCH); + request.setEndpoint("templates/{template_id}"); + request.setBody("{\"name\":\"new_example_name\"}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -4570,12 +4486,12 @@ Transactional templates are templates created specifically for transactional ema try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "templates/{template_id}"; + request.setMethod(Method.GET); + request.setEndpoint("templates/{template_id}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -4596,12 +4512,12 @@ Transactional templates are templates created specifically for transactional ema try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.DELETE; - request.endpoint = "templates/{template_id}"; + request.setMethod(Method.DELETE); + request.setEndpoint("templates/{template_id}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -4610,7 +4526,7 @@ Transactional templates are templates created specifically for transactional ema **This endpoint allows you to create a new version of a template.** -Each transactional template can have multiple versions, each version with its own subject and content. Each user can have up to 300 versions across across all templates. +Each transactional template can have multiple versions, each version with its own subject and content. Each user can have up to 300 versions across all templates. For more information about transactional templates, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Transactional_Templates/index.html). @@ -4622,13 +4538,13 @@ For more information about transactional templates, please see our [User Guide]( try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.POST; - request.endpoint = "templates/{template_id}/versions"; - request.body = "{\"name\":\"example_version_name\",\"html_content\":\"<%body%>\",\"plain_content\":\"<%body%>\",\"active\":1,\"template_id\":\"ddb96bbc-9b92-425e-8979-99464621b543\",\"subject\":\"<%subject%>\"}"; + request.setMethod(Method.POST); + request.setEndpoint("templates/{template_id}/versions"); + request.setBody("{\"name\":\"example_version_name\",\"html_content\":\"<%body%>\",\"plain_content\":\")<%body%>\",\"active\":1,\"template_id\":\"ddb96bbc-9b92-425e-8979-99464621b543\",\"subject\":\"<%subject%>\"}"; Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -4637,7 +4553,7 @@ For more information about transactional templates, please see our [User Guide]( **This endpoint allows you to edit a version of one of your transactional templates.** -Each transactional template can have multiple versions, each version with its own subject and content. Each user can have up to 300 versions across across all templates. +Each transactional template can have multiple versions, each version with its own subject and content. Each user can have up to 300 versions across all templates. For more information about transactional templates, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Transactional_Templates/index.html). @@ -4654,13 +4570,13 @@ For more information about transactional templates, please see our [User Guide]( try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.PATCH; - request.endpoint = "templates/{template_id}/versions/{version_id}"; - request.body = "{\"active\":1,\"html_content\":\"<%body%>\",\"subject\":\"<%subject%>\",\"name\":\"updated_example_name\",\"plain_content\":\"<%body%>\"}"; + request.setMethod(Method.PATCH); + request.setEndpoint("templates/{template_id}/versions/{version_id}"); + request.setBody("{\"active\":1,\"html_content\":\"<%body%>\",\"subject\":\"<%subject%>\",\"name\":\"updated_example)_name\",\"plain_content\":\"<%body%>\"}"; Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -4669,7 +4585,7 @@ For more information about transactional templates, please see our [User Guide]( **This endpoint allows you to retrieve a specific version of a template.** -Each transactional template can have multiple versions, each version with its own subject and content. Each user can have up to 300 versions across across all templates. +Each transactional template can have multiple versions, each version with its own subject and content. Each user can have up to 300 versions across all templates. For more information about transactional templates, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Transactional_Templates/index.html). @@ -4686,12 +4602,12 @@ For more information about transactional templates, please see our [User Guide]( try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "templates/{template_id}/versions/{version_id}"; + request.setMethod(Method.GET); + request.setEndpoint("templates/{template_id}/versions/{version_id}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -4700,7 +4616,7 @@ For more information about transactional templates, please see our [User Guide]( **This endpoint allows you to delete one of your transactional template versions.** -Each transactional template can have multiple versions, each version with its own subject and content. Each user can have up to 300 versions across across all templates. +Each transactional template can have multiple versions, each version with its own subject and content. Each user can have up to 300 versions across all templates. For more information about transactional templates, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Transactional_Templates/index.html). @@ -4717,12 +4633,12 @@ For more information about transactional templates, please see our [User Guide]( try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.DELETE; - request.endpoint = "templates/{template_id}/versions/{version_id}"; + request.setMethod(Method.DELETE); + request.setEndpoint("templates/{template_id}/versions/{version_id}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -4749,17 +4665,17 @@ For more information about transactional templates, please see our [User Guide]( try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.POST; - request.endpoint = "templates/{template_id}/versions/{version_id}/activate"; + request.setMethod(Method.POST); + request.setEndpoint("templates/{template_id}/versions/{version_id}/activate"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } ``` - + # TRACKING SETTINGS ## Retrieve Tracking Settings @@ -4777,16 +4693,14 @@ For more information about tracking, please see our [User Guide](https://sendgri try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "tracking_settings"; - Map queryParams = new HashMap(); - queryParams.put("limit", "1"); - queryParams.put("offset", "1"); - request.queryParams = queryParams; + request.setMethod(Method.GET); + request.setEndpoint("tracking_settings"); + request.addQueryParam("limit", "1"); + request.addQueryParam("offset", "1"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -4806,13 +4720,13 @@ For more information about tracking, please see our [User Guide](https://sendgri try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.PATCH; - request.endpoint = "tracking_settings/click"; - request.body = "{\"enabled\":true}"; + request.setMethod(Method.PATCH); + request.setEndpoint("tracking_settings/click"); + request.setBody("{\"enabled\":true}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -4832,12 +4746,12 @@ For more information about tracking, please see our [User Guide](https://sendgri try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "tracking_settings/click"; + request.setMethod(Method.GET); + request.setEndpoint("tracking_settings/click"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -4861,13 +4775,13 @@ For more information about tracking, please see our [User Guide](https://sendgri try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.PATCH; - request.endpoint = "tracking_settings/google_analytics"; - request.body = "{\"utm_campaign\":\"website\",\"utm_term\":\"\",\"utm_content\":\"\",\"enabled\":true,\"utm_source\":\"sendgrid.com\",\"utm_medium\":\"email\"}"; + request.setMethod(Method.PATCH); + request.setEndpoint("tracking_settings/google_analytics"); + request.setBody("{\"utm_campaign\":\"website\",\"utm_term\":\"\",\"utm_content\":\"\",\"enabled\":true,\"utm)_source\":\"sendgrid.com\",\"utm_medium\":\"email\"}"; Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -4891,12 +4805,12 @@ For more information about tracking, please see our [User Guide](https://sendgri try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "tracking_settings/google_analytics"; + request.setMethod(Method.GET); + request.setEndpoint("tracking_settings/google_analytics"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -4918,13 +4832,13 @@ For more information about tracking, please see our [User Guide](https://sendgri try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.PATCH; - request.endpoint = "tracking_settings/open"; - request.body = "{\"enabled\":true}"; + request.setMethod(Method.PATCH); + request.setEndpoint("tracking_settings/open"); + request.setBody("{\"enabled\":true}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -4946,12 +4860,12 @@ For more information about tracking, please see our [User Guide](https://sendgri try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "tracking_settings/open"; + request.setMethod(Method.GET); + request.setEndpoint("tracking_settings/open"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -4973,13 +4887,13 @@ For more information about tracking, please see our [User Guide](https://sendgri try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.PATCH; - request.endpoint = "tracking_settings/subscription"; - request.body = "{\"url\":\"url\",\"html_content\":\"html content\",\"enabled\":true,\"landing\":\"landing page html\",\"replace\":\"replacement tag\",\"plain_content\":\"text content\"}"; + request.setMethod(Method.PATCH); + request.setEndpoint("tracking_settings/subscription"); + request.setBody("{\"url\":\"url\",\"html_content\":\"html content\",\"enabled\":true,\"landing\":\"landing page) html\",\"replace\":\"replacement tag\",\"plain_content\":\"text content\"}"; Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -5001,12 +4915,12 @@ For more information about tracking, please see our [User Guide](https://sendgri try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "tracking_settings/subscription"; + request.setMethod(Method.GET); + request.setEndpoint("tracking_settings/subscription"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -5033,12 +4947,12 @@ For more information about your user profile: try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "user/account"; + request.setMethod(Method.GET); + request.setEndpoint("user/account"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -5047,7 +4961,7 @@ For more information about your user profile: **This endpoint allows you to retrieve the current credit balance for your account.** -Your monthly credit allotment limits the number of emails you may send before incurring overage charges. For more information about credits and billing, please visit our [Clssroom](https://sendgrid.com/docs/Classroom/Basics/Billing/billing_info_and_faqs.html). +Your monthly credit allotment limits the number of emails you may send before incurring overage charges. For more information about credits and billing, please visit our [Classroom](https://sendgrid.com/docs/Classroom/Basics/Billing/billing_info_and_faqs.html). ### GET /user/credits @@ -5056,12 +4970,12 @@ Your monthly credit allotment limits the number of emails you may send before in try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "user/credits"; + request.setMethod(Method.GET); + request.setEndpoint("user/credits"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -5083,13 +4997,13 @@ For more information about your user profile: try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.PUT; - request.endpoint = "user/email"; - request.body = "{\"email\":\"example@example.com\"}"; + request.setMethod(Method.PUT); + request.setEndpoint("user/email"); + request.setBody("{\"email\":\"example@example.com\"}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -5111,12 +5025,12 @@ For more information about your user profile: try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "user/email"; + request.setMethod(Method.GET); + request.setEndpoint("user/email"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -5138,13 +5052,13 @@ For more information about your user profile: try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.PUT; - request.endpoint = "user/password"; - request.body = "{\"new_password\":\"new_password\",\"old_password\":\"old_password\"}"; + request.setMethod(Method.PUT); + request.setEndpoint("user/password"); + request.setBody("{\"new_password\":\"new_password\",\"old_password\":\"old_password\"}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -5168,13 +5082,13 @@ It should be noted that any one or more of the parameters can be updated via the try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.PATCH; - request.endpoint = "user/profile"; - request.body = "{\"city\":\"Orange\",\"first_name\":\"Example\",\"last_name\":\"User\"}"; + request.setMethod(Method.PATCH); + request.setEndpoint("user/profile"); + request.setBody("{\"city\":\"Orange\",\"first_name\":\"Example\",\"last_name\":\"User\"}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -5194,12 +5108,12 @@ For more information about your user profile: try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "user/profile"; + request.setMethod(Method.GET); + request.setEndpoint("user/profile"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -5220,13 +5134,13 @@ The Cancel Scheduled Sends feature allows the customer to cancel a scheduled sen try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.POST; - request.endpoint = "user/scheduled_sends"; - request.body = "{\"batch_id\":\"YOUR_BATCH_ID\",\"status\":\"pause\"}"; + request.setMethod(Method.POST); + request.setEndpoint("user/scheduled_sends"); + request.setBody("{\"batch_id\":\"YOUR_BATCH_ID\",\"status\":\"pause\"}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -5244,12 +5158,12 @@ The Cancel Scheduled Sends feature allows the customer to cancel a scheduled sen try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "user/scheduled_sends"; + request.setMethod(Method.GET); + request.setEndpoint("user/scheduled_sends"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -5267,13 +5181,13 @@ The Cancel Scheduled Sends feature allows the customer to cancel a scheduled sen try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.PATCH; - request.endpoint = "user/scheduled_sends/{batch_id}"; - request.body = "{\"status\":\"pause\"}"; + request.setMethod(Method.PATCH); + request.setEndpoint("user/scheduled_sends/{batch_id}"); + request.setBody("{\"status\":\"pause\"}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -5291,12 +5205,12 @@ The Cancel Scheduled Sends feature allows the customer to cancel a scheduled sen try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "user/scheduled_sends/{batch_id}"; + request.setMethod(Method.GET); + request.setEndpoint("user/scheduled_sends/{batch_id}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -5314,12 +5228,12 @@ The Cancel Scheduled Sends feature allows the customer to cancel a scheduled sen try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.DELETE; - request.endpoint = "user/scheduled_sends/{batch_id}"; + request.setMethod(Method.DELETE); + request.setEndpoint("user/scheduled_sends/{batch_id}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -5339,13 +5253,13 @@ The Enforced TLS settings specify whether or not the recipient is required to su try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.PATCH; - request.endpoint = "user/settings/enforced_tls"; - request.body = "{\"require_tls\":true,\"require_valid_cert\":false}"; + request.setMethod(Method.PATCH); + request.setEndpoint("user/settings/enforced_tls"); + request.setBody("{\"require_tls\":true,\"require_valid_cert\":false}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -5365,12 +5279,12 @@ The Enforced TLS settings specify whether or not the recipient is required to su try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "user/settings/enforced_tls"; + request.setMethod(Method.GET); + request.setEndpoint("user/settings/enforced_tls"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -5392,13 +5306,13 @@ For more information about your user profile: try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.PUT; - request.endpoint = "user/username"; - request.body = "{\"username\":\"test_username\"}"; + request.setMethod(Method.PUT); + request.setEndpoint("user/username"); + request.setBody("{\"username\":\"test_username\"}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -5420,12 +5334,12 @@ For more information about your user profile: try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "user/username"; + request.setMethod(Method.GET); + request.setEndpoint("user/username"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -5447,13 +5361,13 @@ Common uses of this data are to remove unsubscribes, react to spam reports, dete try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.PATCH; - request.endpoint = "user/webhooks/event/settings"; - request.body = "{\"group_resubscribe\":true,\"delivered\":true,\"group_unsubscribe\":true,\"spam_report\":true,\"url\":\"url\",\"enabled\":true,\"bounce\":true,\"deferred\":true,\"unsubscribe\":true,\"dropped\":true,\"open\":true,\"click\":true,\"processed\":true}"; + request.setMethod(Method.PATCH); + request.setEndpoint("user/webhooks/event/settings"); + request.setBody("{\"group_resubscribe\":true,\"delivered\":true,\"group_unsubscribe\":true,\"spam_report\":true,\"url\":\"url\)",\"enabled\":true,\"bounce\":true,\"deferred\":true,\"unsubscribe\":true,\"dropped\":true,\"open\":true,\"click\":true,\"processed\":true}"; Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -5475,12 +5389,12 @@ Common uses of this data are to remove unsubscribes, react to spam reports, dete try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "user/webhooks/event/settings"; + request.setMethod(Method.GET); + request.setEndpoint("user/webhooks/event/settings"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -5500,13 +5414,13 @@ Common uses of this data are to remove unsubscribes, react to spam reports, dete try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.POST; - request.endpoint = "user/webhooks/event/test"; - request.body = "{\"url\":\"url\"}"; + request.setMethod(Method.POST); + request.setEndpoint("user/webhooks/event/test"); + request.setBody("{\"url\":\"url\"}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -5524,13 +5438,13 @@ The inbound parse webhook allows you to have incoming emails parsed, extracting try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.POST; - request.endpoint = "user/webhooks/parse/settings"; - request.body = "{\"url\":\"http://email.myhosthame.com\",\"send_raw\":false,\"hostname\":\"myhostname.com\",\"spam_check\":true}"; + request.setMethod(Method.POST); + request.setEndpoint("user/webhooks/parse/settings"); + request.setBody("{\"url\":\"http://email.myhosthame.com\",\"send_raw\":false,\"hostname\":\"myhostname.com\",\"spam)_check\":true}"; Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -5539,7 +5453,7 @@ The inbound parse webhook allows you to have incoming emails parsed, extracting **This endpoint allows you to retrieve all of your current inbound parse settings.** -The inbound parse webhook allows you to have incoming emails parsed, extracting some or all of the contnet, and then have that content POSTed by SendGrid to a URL of your choosing. For more information, please see our [User Guide](https://sendgrid.com/docs/API_Reference/Webhooks/parse.html). +The inbound parse webhook allows you to have incoming emails parsed, extracting some or all of the content, and then have that content POSTed by SendGrid to a URL of your choosing. For more information, please see our [User Guide](https://sendgrid.com/docs/API_Reference/Webhooks/parse.html). ### GET /user/webhooks/parse/settings @@ -5548,12 +5462,12 @@ The inbound parse webhook allows you to have incoming emails parsed, extracting try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "user/webhooks/parse/settings"; + request.setMethod(Method.GET); + request.setEndpoint("user/webhooks/parse/settings"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -5562,7 +5476,7 @@ The inbound parse webhook allows you to have incoming emails parsed, extracting **This endpoint allows you to update a specific inbound parse setting.** -The inbound parse webhook allows you to have incoming emails parsed, extracting some or all of the contnet, and then have that content POSTed by SendGrid to a URL of your choosing. For more information, please see our [User Guide](https://sendgrid.com/docs/API_Reference/Webhooks/parse.html). +The inbound parse webhook allows you to have incoming emails parsed, extracting some or all of the content, and then have that content POSTed by SendGrid to a URL of your choosing. For more information, please see our [User Guide](https://sendgrid.com/docs/API_Reference/Webhooks/parse.html). ### PATCH /user/webhooks/parse/settings/{hostname} @@ -5571,13 +5485,13 @@ The inbound parse webhook allows you to have incoming emails parsed, extracting try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.PATCH; - request.endpoint = "user/webhooks/parse/settings/{hostname}"; - request.body = "{\"url\":\"http://newdomain.com/parse\",\"send_raw\":true,\"spam_check\":false}"; + request.setMethod(Method.PATCH); + request.setEndpoint("user/webhooks/parse/settings/{hostname}"); + request.setBody("{\"url\":\"http://newdomain.com/parse\",\"send_raw\":true,\"spam_check\":false}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -5586,7 +5500,7 @@ The inbound parse webhook allows you to have incoming emails parsed, extracting **This endpoint allows you to retrieve a specific inbound parse setting.** -The inbound parse webhook allows you to have incoming emails parsed, extracting some or all of the contnet, and then have that content POSTed by SendGrid to a URL of your choosing. For more information, please see our [User Guide](https://sendgrid.com/docs/API_Reference/Webhooks/parse.html). +The inbound parse webhook allows you to have incoming emails parsed, extracting some or all of the content, and then have that content POSTed by SendGrid to a URL of your choosing. For more information, please see our [User Guide](https://sendgrid.com/docs/API_Reference/Webhooks/parse.html). ### GET /user/webhooks/parse/settings/{hostname} @@ -5595,12 +5509,12 @@ The inbound parse webhook allows you to have incoming emails parsed, extracting try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "user/webhooks/parse/settings/{hostname}"; + request.setMethod(Method.GET); + request.setEndpoint("user/webhooks/parse/settings/{hostname}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -5609,7 +5523,7 @@ The inbound parse webhook allows you to have incoming emails parsed, extracting **This endpoint allows you to delete a specific inbound parse setting.** -The inbound parse webhook allows you to have incoming emails parsed, extracting some or all of the contnet, and then have that content POSTed by SendGrid to a URL of your choosing. For more information, please see our [User Guide](https://sendgrid.com/docs/API_Reference/Webhooks/parse.html). +The inbound parse webhook allows you to have incoming emails parsed, extracting some or all of the content, and then have that content POSTed by SendGrid to a URL of your choosing. For more information, please see our [User Guide](https://sendgrid.com/docs/API_Reference/Webhooks/parse.html). ### DELETE /user/webhooks/parse/settings/{hostname} @@ -5618,21 +5532,21 @@ The inbound parse webhook allows you to have incoming emails parsed, extracting try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.DELETE; - request.endpoint = "user/webhooks/parse/settings/{hostname}"; + request.setMethod(Method.DELETE); + request.setEndpoint("user/webhooks/parse/settings/{hostname}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } ``` ## Retrieves Inbound Parse Webhook statistics. -**This endpoint allows you to retrieve the statistics for your Parse Webhook useage.** +**This endpoint allows you to retrieve the statistics for your Parse Webhook usage.** -SendGrid's Inbound Parse Webhook allows you to parse the contents and attachments of incomming emails. The Parse API can then POST the parsed emails to a URL that you specify. The Inbound Parse Webhook cannot parse messages greater than 20MB in size, including all attachments. +SendGrid's Inbound Parse Webhook allows you to parse the contents and attachments of incoming emails. The Parse API can then POST the parsed emails to a URL that you specify. The Inbound Parse Webhook cannot parse messages greater than 20MB in size, including all attachments. There are a number of pre-made integrations for the SendGrid Parse Webhook which make processing events easy. You can find these integrations in the [Library Index](https://sendgrid.com/docs/Integrate/libraries.html#-Webhook-Libraries). @@ -5643,19 +5557,17 @@ There are a number of pre-made integrations for the SendGrid Parse Webhook which try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "user/webhooks/parse/stats"; - Map queryParams = new HashMap(); - queryParams.put("aggregated_by", "day"); - queryParams.put("limit", "test_string"); - queryParams.put("start_date", "2016-01-01"); - queryParams.put("end_date", "2016-04-01"); - queryParams.put("offset", "test_string"); - request.queryParams = queryParams; + request.setMethod(Method.GET); + request.setEndpoint("user/webhooks/parse/stats"); + request.addQueryParam("aggregated_by", "day"); + request.addQueryParam("limit", "test_string"); + request.addQueryParam("start_date", "2016-01-01"); + request.addQueryParam("end_date", "2016-04-01"); + request.addQueryParam("offset", "test_string"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -5682,13 +5594,13 @@ For more information on whitelabeling, please see our [User Guide](https://sendg try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.POST; - request.endpoint = "whitelabel/domains"; - request.body = "{\"automatic_security\":false,\"username\":\"john@example.com\",\"domain\":\"example.com\",\"default\":true,\"custom_spf\":true,\"ips\":[\"192.168.1.1\",\"192.168.1.2\"],\"subdomain\":\"news\"}"; + request.setMethod(Method.POST); + request.setEndpoint("whitelabel/domains"); + request.setBody("{\"automatic)_security\":false,\"username\":\"john@example.com\",\"domain\":\"example.com\",\"default\":true,\"custom_spf\":true,\"ips\":[\"192.168.1.1\",\"192.168.1.2\"],\"subdomain\":\"news\"}"; Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -5709,19 +5621,17 @@ For more information on whitelabeling, please see our [User Guide](https://sendg try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "whitelabel/domains"; - Map queryParams = new HashMap(); - queryParams.put("username", "test_string"); - queryParams.put("domain", "test_string"); - queryParams.put("exclude_subusers", "true"); - queryParams.put("limit", "1"); - queryParams.put("offset", "1"); - request.queryParams = queryParams; + request.setMethod(Method.GET); + request.setEndpoint("whitelabel/domains"); + request.addQueryParam("username", "test_string"); + request.addQueryParam("domain", "test_string"); + request.addQueryParam("exclude_subusers", "true"); + request.addQueryParam("limit", "1"); + request.addQueryParam("offset", "1"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -5746,12 +5656,12 @@ For more information on whitelabeling, please see our [User Guide](https://sendg try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "whitelabel/domains/default"; + request.setMethod(Method.GET); + request.setEndpoint("whitelabel/domains/default"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -5762,7 +5672,7 @@ For more information on whitelabeling, please see our [User Guide](https://sendg A domain whitelabel allows you to remove the via or sent on behalf of message that your recipients see when they read your emails. Whitelabeling a domain allows you to replace sendgrid.net with your personal sending domain. You will be required to create a subdomain so that SendGrid can generate the DNS records which you must give to your host provider. If you choose to use Automated Security, SendGrid will provide you with 3 CNAME records. If you turn Automated Security off, you will be given 2 TXT records and 1 MX record. -Domain whitelabels can be associated with (i.e. assigned to) subusers from a parent account. This functionality allows subusers to send mail using their parent's whitelabels. To associate a whitelabel with a subuser, the parent account must first create the whitelabel and validate it. The the parent may then associate the whitelabel via the subuser management tools. +Domain whitelabels can be associated with (i.e. assigned to) subusers from a parent account. This functionality allows subusers to send mail using their parent's whitelabels. To associate a whitelabel with a subuser, the parent account must first create the whitelabel and validate it. The parent may then associate the whitelabel via the subuser management tools. For more information on whitelabeling, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/Whitelabel/index.html) @@ -5778,12 +5688,12 @@ For more information on whitelabeling, please see our [User Guide](https://sendg try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "whitelabel/domains/subuser"; + request.setMethod(Method.GET); + request.setEndpoint("whitelabel/domains/subuser"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -5794,7 +5704,7 @@ For more information on whitelabeling, please see our [User Guide](https://sendg A domain whitelabel allows you to remove the via or sent on behalf of message that your recipients see when they read your emails. Whitelabeling a domain allows you to replace sendgrid.net with your personal sending domain. You will be required to create a subdomain so that SendGrid can generate the DNS records which you must give to your host provider. If you choose to use Automated Security, SendGrid will provide you with 3 CNAME records. If you turn Automated Security off, you will be given 2 TXT records and 1 MX record. -Domain whitelabels can be associated with (i.e. assigned to) subusers from a parent account. This functionality allows subusers to send mail using their parent's whitelabels. To associate a whitelabel with a subuser, the parent account must first create the whitelabel and validate it. The the parent may then associate the whitelabel via the subuser management tools. +Domain whitelabels can be associated with (i.e. assigned to) subusers from a parent account. This functionality allows subusers to send mail using their parent's whitelabels. To associate a whitelabel with a subuser, the parent account must first create the whitelabel and validate it. The parent may then associate the whitelabel via the subuser management tools. For more information on whitelabeling, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/Whitelabel/index.html) @@ -5810,12 +5720,12 @@ For more information on whitelabeling, please see our [User Guide](https://sendg try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.DELETE; - request.endpoint = "whitelabel/domains/subuser"; + request.setMethod(Method.DELETE); + request.setEndpoint("whitelabel/domains/subuser"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -5835,13 +5745,13 @@ For more information on whitelabeling, please see our [User Guide](https://sendg try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.PATCH; - request.endpoint = "whitelabel/domains/{domain_id}"; - request.body = "{\"default\":false,\"custom_spf\":true}"; + request.setMethod(Method.PATCH); + request.setEndpoint("whitelabel/domains/{domain_id}"); + request.setBody("{\"default\":false,\"custom_spf\":true}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -5862,12 +5772,12 @@ For more information on whitelabeling, please see our [User Guide](https://sendg try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "whitelabel/domains/{domain_id}"; + request.setMethod(Method.GET); + request.setEndpoint("whitelabel/domains/{domain_id}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -5887,12 +5797,12 @@ For more information on whitelabeling, please see our [User Guide](https://sendg try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.DELETE; - request.endpoint = "whitelabel/domains/{domain_id}"; + request.setMethod(Method.DELETE); + request.setEndpoint("whitelabel/domains/{domain_id}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -5903,7 +5813,7 @@ For more information on whitelabeling, please see our [User Guide](https://sendg A domain whitelabel allows you to remove the via or sent on behalf of message that your recipients see when they read your emails. Whitelabeling a domain allows you to replace sendgrid.net with your personal sending domain. You will be required to create a subdomain so that SendGrid can generate the DNS records which you must give to your host provider. If you choose to use Automated Security, SendGrid will provide you with 3 CNAME records. If you turn Automated Security off, you will be given 2 TXT records and 1 MX record. -Domain whitelabels can be associated with (i.e. assigned to) subusers from a parent account. This functionality allows subusers to send mail using their parent's whitelabels. To associate a whitelabel with a subuser, the parent account must first create the whitelabel and validate it. The the parent may then associate the whitelabel via the subuser management tools. +Domain whitelabels can be associated with (i.e. assigned to) subusers from a parent account. This functionality allows subusers to send mail using their parent's whitelabels. To associate a whitelabel with a subuser, the parent account must first create the whitelabel and validate it. The parent may then associate the whitelabel via the subuser management tools. For more information on whitelabeling, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/Whitelabel/index.html) @@ -5919,13 +5829,13 @@ For more information on whitelabeling, please see our [User Guide](https://sendg try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.POST; - request.endpoint = "whitelabel/domains/{domain_id}/subuser"; - request.body = "{\"username\":\"jane@example.com\"}"; + request.setMethod(Method.POST); + request.setEndpoint("whitelabel/domains/{domain_id}/subuser"); + request.setBody("{\"username\":\"jane@example.com\"}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -5950,13 +5860,13 @@ For more information on whitelabeling, please see our [User Guide](https://sendg try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.POST; - request.endpoint = "whitelabel/domains/{id}/ips"; - request.body = "{\"ip\":\"192.168.0.1\"}"; + request.setMethod(Method.POST); + request.setEndpoint("whitelabel/domains/{id}/ips"); + request.setBody("{\"ip\":\"192.168.0.1\"}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -5982,12 +5892,12 @@ For more information on whitelabeling, please see our [User Guide](https://sendg try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.DELETE; - request.endpoint = "whitelabel/domains/{id}/ips/{ip}"; + request.setMethod(Method.DELETE); + request.setEndpoint("whitelabel/domains/{id}/ips/{ip}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -6012,12 +5922,12 @@ For more information on whitelabeling, please see our [User Guide](https://sendg try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.POST; - request.endpoint = "whitelabel/domains/{id}/validate"; + request.setMethod(Method.POST); + request.setEndpoint("whitelabel/domains/{id}/validate"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -6039,20 +5949,20 @@ For more information, please see our [User Guide](https://sendgrid.com/docs/API_ try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.POST; - request.endpoint = "whitelabel/ips"; - request.body = "{\"ip\":\"192.168.1.1\",\"domain\":\"example.com\",\"subdomain\":\"email\"}"; + request.setMethod(Method.POST); + request.setEndpoint("whitelabel/ips"); + request.setBody("{\"ip\":\"192.168.1.1\",\"domain\":\"example.com\",\"subdomain\":\"email\"}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } ``` ## Retrieve all IP whitelabels -**This endpoint allows you to retrieve all of the IP whitelabels that have been createdy by this account.** +**This endpoint allows you to retrieve all of the IP whitelabels that have been created by this account.** You may include a search key by using the "ip" parameter. This enables you to perform a prefix search for a given IP segment (e.g. "192."). @@ -6067,17 +5977,15 @@ For more information, please see our [User Guide](https://sendgrid.com/docs/API_ try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "whitelabel/ips"; - Map queryParams = new HashMap(); - queryParams.put("ip", "test_string"); - queryParams.put("limit", "1"); - queryParams.put("offset", "1"); - request.queryParams = queryParams; + request.setMethod(Method.GET); + request.setEndpoint("whitelabel/ips"); + request.addQueryParam("ip", "test_string"); + request.addQueryParam("limit", "1"); + request.addQueryParam("offset", "1"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -6097,12 +6005,12 @@ For more information, please see our [User Guide](https://sendgrid.com/docs/API_ try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "whitelabel/ips/{id}"; + request.setMethod(Method.GET); + request.setEndpoint("whitelabel/ips/{id}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -6122,12 +6030,12 @@ For more information, please see our [User Guide](https://sendgrid.com/docs/API_ try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.DELETE; - request.endpoint = "whitelabel/ips/{id}"; + request.setMethod(Method.DELETE); + request.setEndpoint("whitelabel/ips/{id}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -6147,12 +6055,12 @@ For more information, please see our [User Guide](https://sendgrid.com/docs/API_ try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.POST; - request.endpoint = "whitelabel/ips/{id}/validate"; + request.setMethod(Method.POST); + request.setEndpoint("whitelabel/ips/{id}/validate"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -6172,17 +6080,15 @@ For more information, please see our [User Guide](https://sendgrid.com/docs/API_ try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.POST; - request.endpoint = "whitelabel/links"; - request.body = "{\"default\":true,\"domain\":\"example.com\",\"subdomain\":\"mail\"}"; - Map queryParams = new HashMap(); - queryParams.put("limit", "1"); - queryParams.put("offset", "1"); - request.queryParams = queryParams; + request.setMethod(Method.POST); + request.setEndpoint("whitelabel/links"); + request.setBody("{\"default\":true,\"domain\":\"example.com\",\"subdomain\":\"mail\"}"); + request.addQueryParam("limit", "1"); + request.addQueryParam("offset", "1"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -6202,15 +6108,13 @@ For more information, please see our [User Guide](https://sendgrid.com/docs/API_ try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "whitelabel/links"; - Map queryParams = new HashMap(); - queryParams.put("limit", "1"); - request.queryParams = queryParams; + request.setMethod(Method.GET); + request.setEndpoint("whitelabel/links"); + request.addQueryParam("limit", "1"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -6237,15 +6141,13 @@ For more information, please see our [User Guide](https://sendgrid.com/docs/API_ try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "whitelabel/links/default"; - Map queryParams = new HashMap(); - queryParams.put("domain", "test_string"); - request.queryParams = queryParams; + request.setMethod(Method.GET); + request.setEndpoint("whitelabel/links/default"); + request.addQueryParam("domain", "test_string"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -6255,7 +6157,7 @@ For more information, please see our [User Guide](https://sendgrid.com/docs/API_ **This endpoint allows you to retrieve the associated link whitelabel for a subuser.** Link whitelables can be associated with subusers from the parent account. This functionality allows -subusers to send mail using their parent's linke whitelabels. To associate a link whitelabel, the parent account +subusers to send mail using their parent's link whitelabels. To associate a link whitelabel, the parent account must first create a whitelabel and validate it. The parent may then associate that whitelabel with a subuser via the API or the Subuser Management page in the user interface. Email link whitelabels allow all of the click-tracked links you send in your emails to include the URL of your domain instead of sendgrid.net. @@ -6269,15 +6171,13 @@ For more information, please see our [User Guide](https://sendgrid.com/docs/API_ try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "whitelabel/links/subuser"; - Map queryParams = new HashMap(); - queryParams.put("username", "test_string"); - request.queryParams = queryParams; + request.setMethod(Method.GET); + request.setEndpoint("whitelabel/links/subuser"); + request.addQueryParam("username", "test_string"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -6287,7 +6187,7 @@ For more information, please see our [User Guide](https://sendgrid.com/docs/API_ **This endpoint allows you to disassociate a link whitelabel from a subuser.** Link whitelables can be associated with subusers from the parent account. This functionality allows -subusers to send mail using their parent's linke whitelabels. To associate a link whitelabel, the parent account +subusers to send mail using their parent's link whitelabels. To associate a link whitelabel, the parent account must first create a whitelabel and validate it. The parent may then associate that whitelabel with a subuser via the API or the Subuser Management page in the user interface. Email link whitelabels allow all of the click-tracked links you send in your emails to include the URL of your domain instead of sendgrid.net. @@ -6301,15 +6201,13 @@ For more information, please see our [User Guide](https://sendgrid.com/docs/API_ try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.DELETE; - request.endpoint = "whitelabel/links/subuser"; - Map queryParams = new HashMap(); - queryParams.put("username", "test_string"); - request.queryParams = queryParams; + request.setMethod(Method.DELETE); + request.setEndpoint("whitelabel/links/subuser"); + request.addQueryParam("username", "test_string"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -6329,13 +6227,13 @@ For more information, please see our [User Guide](https://sendgrid.com/docs/API_ try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.PATCH; - request.endpoint = "whitelabel/links/{id}"; - request.body = "{\"default\":true}"; + request.setMethod(Method.PATCH); + request.setEndpoint("whitelabel/links/{id}"); + request.setBody("{\"default\":true}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -6355,12 +6253,12 @@ For more information, please see our [User Guide](https://sendgrid.com/docs/API_ try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "whitelabel/links/{id}"; + request.setMethod(Method.GET); + request.setEndpoint("whitelabel/links/{id}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -6380,12 +6278,12 @@ For more information, please see our [User Guide](https://sendgrid.com/docs/API_ try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.DELETE; - request.endpoint = "whitelabel/links/{id}"; + request.setMethod(Method.DELETE); + request.setEndpoint("whitelabel/links/{id}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -6405,12 +6303,12 @@ For more information, please see our [User Guide](https://sendgrid.com/docs/API_ try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.POST; - request.endpoint = "whitelabel/links/{id}/validate"; + request.setMethod(Method.POST); + request.setEndpoint("whitelabel/links/{id}/validate"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -6420,7 +6318,7 @@ For more information, please see our [User Guide](https://sendgrid.com/docs/API_ **This endpoint allows you to associate a link whitelabel with a subuser account.** Link whitelables can be associated with subusers from the parent account. This functionality allows -subusers to send mail using their parent's linke whitelabels. To associate a link whitelabel, the parent account +subusers to send mail using their parent's link whitelabels. To associate a link whitelabel, the parent account must first create a whitelabel and validate it. The parent may then associate that whitelabel with a subuser via the API or the Subuser Management page in the user interface. Email link whitelabels allow all of the click-tracked links you send in your emails to include the URL of your domain instead of sendgrid.net. @@ -6434,13 +6332,13 @@ For more information, please see our [User Guide](https://sendgrid.com/docs/API_ try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.POST; - request.endpoint = "whitelabel/links/{link_id}/subuser"; - request.body = "{\"username\":\"jane@example.com\"}"; + request.setMethod(Method.POST); + request.setEndpoint("whitelabel/links/{link_id}/subuser"); + request.setBody("{\"username\":\"jane@example.com\"}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } diff --git a/USE_CASES.md b/USE_CASES.md new file mode 100644 index 00000000..0ba2aeb1 --- /dev/null +++ b/USE_CASES.md @@ -0,0 +1,233 @@ +This documentation provides examples for specific use cases. Please [open an issue](https://github.com/sendgrid/sendgrid-java/issues) or make a pull request for any use cases you would like us to document here. Thank you! + +# Table of Contents + +* [Transactional Templates](#transactional-templates) +* [Legacy Templates](#legacy-templates) +* [How to Setup a Domain Whitelabel](#domain-whitelabel) +* [How to View Email Statistics](#email-stats) + + +# Transactional Templates + +For this example, we assume you have created a [transactional template](https://sendgrid.com/docs/User_Guide/Transactional_Templates/index.html). Following is the template content we used for testing. + +Template ID (replace with your own): + +```text +d-2c214ac919e84170b21855cc129b4a5f +``` +Email Subject: + +```text +{{subject}} +``` +Template Body: + +```html + + + + + + Hello {{name}}, +

+ I'm glad you are trying out the template feature! +

+ I hope you are having a great day in {{city}} :) +

+ + +``` + +## With Mail Helper Class + +```java +import com.sendgrid.*; +import java.io.IOException; + +public class Example { + public static void main(String[] args) throws IOException { + Mail mail = new Mail(); + mail.setFrom(new Email("teste@example.com")); + mail.setTemplateId("d-2c214ac919e84170b21855cc129b4a5f"); + + Personalization personalization = new Personalization(); + personalization.addDynamicTemplateData("subject", "Testing Templates"); + personalization.addDynamicTemplateData("name", "Example User"); + personalization.addDynamicTemplateData("city", "Denver"); + personalization.addTo(new Email("test@example.com")); + mail.addPersonalization(personalization); + + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + try { + request.setMethod(Method.POST); + request.setEndpoint("mail/send"); + request.setBody(mail.build()); + 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; + } + } +} +``` + +## Without Mail Helper Class + +```java +import com.sendgrid.*; +import java.io.IOException; + +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.POST); + request.setEndpoint("mail/send"); + request.setBody("{ + \"from\": {\"email\": \"test@example.com\"}, + \"personalizations\": + [{ + \"to\": [{\"email\": \"test@example.com\"}], + \"dynamic_template_data\": {\"subject\": \"Testing Templates\",\"name\": \"Example User\", \"city\": \"Denver\"} + }], + \"template_id\": \"d-2c214ac919e84170b21855cc129b4a5f\"}"); + 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; + } + } +} +``` + + +# Legacy Templates + +For this example, we assume you have created a [legacy template](https://sendgrid.com/docs/User_Guide/Transactional_Templates/index.html). Following is the template content we used for testing. + +Template ID (replace with your own): + +```text +13b8f94f-bcae-4ec6-b752-70d6cb59f932 +``` + +Email Subject: + +```text +<%subject%> +``` + +Template Body: + +```html + + + + + + Hello -name-, +

+ I'm glad you are trying out the template feature! +

+ <%body%> +

+ I hope you are having a great day in -city- :) +

+ + +``` + +## With Mail Helper Class + +```java +import com.sendgrid.*; +import java.io.IOException; + +public class Example { + public static void main(String[] args) throws IOException { + Email from = new Email("test@example.com"); + String subject = "I'm replacing the subject tag"; + Email to = new Email("test@example.com"); + Content content = new Content("text/html", "I'm replacing the body tag"); + Mail mail = new Mail(from, subject, to, content); + mail.personalization.get(0).addSubstitution("-name-", "Example User"); + mail.personalization.get(0).addSubstitution("-city-", "Denver"); + mail.setTemplateId("13b8f94f-bcae-4ec6-b752-70d6cb59f932"); + + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + try { + request.setMethod(Method.POST); + request.setEndpoint("mail/send"); + request.setBody(mail.build()); + 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; + } + } +} +``` + +## Without Mail Helper Class + +```java +import com.sendgrid.*; +import java.io.IOException; + +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.POST); + request.setEndpoint("mail/send"); + request.setBody("{ + \"personalizations\": + [{ + \"to\": [{\"email\": \"test@example.com\"}], + \"substitutions\": {\"-name-\": \"Example User\", \"-city-\": \"Denver\"}, + \"subject\": \"Hello World from the SendGrid Java Library!\" + }], + \"from\": {\"email\": \"test@example.com\"}, + \"content\": + [{ + \"type\": \"text/html\", + \"value\": \"I'm replacing the body tag\" + }] + ,\"template_id\": \"13b8f94f-bcae-4ec6-b752-70d6cb59f932\"}"); + 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; + } + } +} +``` + + +# How to Setup a Domain Whitelabel + +You can find documentation for how to setup a domain whitelabel via the UI [here](https://sendgrid.com/docs/Classroom/Basics/Whitelabel/setup_domain_whitelabel.html) and via API [here](https://github.com/sendgrid/sendgrid-java/blob/master/USAGE.md#whitelabel). + +Find more information about all of SendGrid's whitelabeling related documentation [here](https://sendgrid.com/docs/Classroom/Basics/Whitelabel/index.html). + + +# How to View Email Statistics + +You can find documentation for how to view your email statistics via the UI [here](https://app.sendgrid.com/statistics) and via API [here](https://github.com/sendgrid/sendgrid-java/blob/master/USAGE.md#stats). + +Alternatively, we can post events to a URL of your choice via our [Event Webhook](https://sendgrid.com/docs/API_Reference/Webhooks/event.html) about events that occur as SendGrid processes your email. + diff --git a/bin/com/sendgrid/helpers/README.md b/bin/com/sendgrid/helpers/README.md new file mode 100644 index 00000000..8a2b905d --- /dev/null +++ b/bin/com/sendgrid/helpers/README.md @@ -0,0 +1,19 @@ +**This helper allows you to quickly and easily build a Mail object for sending email through SendGrid.** + +## Dependencies + +- [Jackson](https://github.com/FasterXML/jackson) + +# Quick Start + +Run the [example](https://github.com/sendgrid/sendgrid-java/tree/master/examples/mail) (make sure you have set your environment variable to include your SENDGRID_API_KEY). + +```bash +cd examples/mail +javac -classpath ../../build/libs/sendgrid-4.2.1-jar.jar:. Example.java && java -classpath ../examples/jackson-core-2.9.5.jar:../../build/libs/sendgrid-4.1.0-jar.jar:. Example +``` + +## Usage + +- See the [example](https://github.com/sendgrid/sendgrid-java/tree/master/examples/mail) for a complete working example. +- [Documentation](https://sendgrid.com/docs/API_Reference/Web_API_v3/Mail/overview.html) \ No newline at end of file diff --git a/build.gradle b/build.gradle index 29cc46fb..149f8a6b 100644 --- a/build.gradle +++ b/build.gradle @@ -17,7 +17,7 @@ apply plugin: 'maven' apply plugin: 'signing' group = 'com.sendgrid' -version = '3.0.3' +version = '4.3.0' ext.packaging = 'jar' allprojects { @@ -45,10 +45,10 @@ buildscript { } dependencies { - compile 'com.sendgrid:java-http-client:2.3.2' - compile 'com.fasterxml.jackson.core:jackson-core:2.5.3' - compile 'com.fasterxml.jackson.core:jackson-annotations:2.5.3' - compile 'com.fasterxml.jackson.core:jackson-databind:2.5.3' + compile 'com.sendgrid:java-http-client:4.1.0' + compile 'com.fasterxml.jackson.core:jackson-core:2.9.5' + compile 'com.fasterxml.jackson.core:jackson-annotations:2.9.5' + compile 'com.fasterxml.jackson.core:jackson-databind:2.9.5' testCompile group: 'junit', name: 'junit', version: '4.12' } @@ -75,11 +75,6 @@ fatJar { // copy fatJar to base project directory so they will be in git (and on github for download) build << { - copy { - println "Copying ${fatJar.archiveName} to $projectDir/repo/com/sendgrid/$version" - from("$buildDir/libs/${fatJar.archiveName}") - into("$projectDir/repo/com/sendgrid/$version") - } copy { println "Copying ${fatJar.archiveName} to $projectDir/repo/com/sendgrid" from("$buildDir/libs/${fatJar.archiveName}") @@ -90,10 +85,20 @@ build << { task renameSendGridVersionJarToSendGridJar { doLast { - file("$projectDir/repo/com/sendgrid/${fatJar.archiveName}").renameTo(file("$projectDir/repo/com/sendgrid/sendgrid-jar.jar")) + file("$projectDir/repo/com/sendgrid/${fatJar.archiveName}").renameTo(file("$projectDir/repo/com/sendgrid/sendgrid-java-latest.jar")) + copy { + from("$buildDir/libs/${fatJar.archiveName}") + into("$projectDir/repo/com/sendgrid") + } + file("$projectDir/repo/com/sendgrid/${fatJar.archiveName}").renameTo(file("$projectDir/repo/com/sendgrid/sendgrid-java-${version}.jar")) } } +task startPrism(type: Exec) { + workingDir 'scripts' + commandLine './startPrism.sh' +} + task javadocJar(type: Jar, dependsOn: javadoc) { classifier = 'javadoc' from 'build/docs/javadoc' diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 00000000..66599a60 --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,24 @@ +FROM store/oracle/serverjre:8 + +ENV OAI_SPEC_URL="https://raw.githubusercontent.com/sendgrid/sendgrid-oai/master/oai_stoplight.json" + +RUN yum install -y git + +WORKDIR /root + +# install Prism +ADD https://raw.githubusercontent.com/stoplightio/prism/master/install.sh install.sh +RUN chmod +x ./install.sh && \ + ./install.sh && \ + rm ./install.sh + +# set up default sendgrid env +WORKDIR /root/sources +RUN git clone https://github.com/sendgrid/sendgrid-java.git +WORKDIR /root +RUN ln -s /root/sources/sendgrid-java + +COPY entrypoint.sh entrypoint.sh +RUN chmod +x entrypoint.sh +ENTRYPOINT ["./entrypoint.sh"] +CMD ["--mock"] diff --git a/docker/README.md b/docker/README.md new file mode 100644 index 00000000..7758a41a --- /dev/null +++ b/docker/README.md @@ -0,0 +1,37 @@ +# Supported tags and respective `Dockerfile` links + - `v1.0.0`, `latest` [(Dockerfile)](https://github.com/sendgrid/sendgrid-java/blob/master/docker/Dockerfile) + +# Quick reference +Due to Oracle's JDK license, you must build this Docker image using the official Oracle image located in the Docker Store. You will need a Docker store account. Once you have an account, you must accept the Oracle license [here](https://store.docker.com/images/oracle-serverjre-8). On the command line, type `docker login` and provide your credentials. You may then build the image using this command `docker build -t sendgrid/sendgrid-java -f Dockerfile .` + + - **Where to get help:** + [Contact SendGrid Support](https://support.sendgrid.com/hc/en-us) + + - **Where to file issues:** + https://github.com/sendgrid/sendgrid-java/issues + + - **Where to get more info:** + [USAGE.md](https://github.com/sendgrid/sendgrid-java/blob/master/docker/USAGE.md) + + - **Maintained by:** + [SendGrid Inc.](https://sendgrid.com) + +# Usage examples + - Most recent version: `docker run -it sendgrid/sendgrid-java`. + - Your own fork: + ```sh-session + $ git clone https://github.com/you/cool-sendgrid-java.git + $ realpath cool-sendgrid-java + /path/to/cool-sendgrid-java + $ docker run -it -v /path/to/cool-sendgrid-java:/mnt/sendgrid-java sendgrid/sendgrid-java + ``` + +For more detailed information, see [USAGE.md](https://github.com/sendgrid/sendgrid-java/blob/master/docker/USAGE.md). + +# About + +sendgrid-java is guided and supported by the SendGrid [Developer Experience Team](mailto:dx@sendgrid.com). + +sendgrid-java is maintained and funded by SendGrid, Inc. The names and logos for sendgrid-java are trademarks of SendGrid, Inc. + +![SendGrid Logo](https://uiux.s3.amazonaws.com/2016-logos/email-logo%402x.png) diff --git a/docker/USAGE.md b/docker/USAGE.md new file mode 100644 index 00000000..0cb27fee --- /dev/null +++ b/docker/USAGE.md @@ -0,0 +1,38 @@ +You can use Docker to easily try out or test sendgrid-java. + + +# Quickstart + +1. Install Docker on your machine. +2. If you have not done so, create a Docker Store account [here](https://store.docker.com/signup?next=%2F) +3. Navigate [here](https://store.docker.com/images/oracle-serverjre-8) and click the "Proceed to Checkout" link (don't worry, it's free). +4. On the command line, execute `docker login` and provide your credentials. +5. Build the Docker image using the command `docker build -t sendgrid/sendgrid-java -f Dockerfile .` +6. Run `docker run -it sendgrid/sendgrid-java`. + + +# Info + +This Docker image contains + - `sendgrid-java` + - Stoplight's Prism, which lets you try out the API without actually sending email + +Run it in interactive mode with `-it`. + +You can mount repositories in the `/mnt/sendgrid-java` and `/mnt/java-http-client` directories to use them instead of the default SendGrid libraries. Read on for more info. + + +# Testing +Testing is easy! +1. Run the container: `docker run -it sendgrid/sendgrid-java` +2. `cd sendgrid-java` +3. run `./gradlew test` + + +# About + +sendgrid-java is guided and supported by the SendGrid [Developer Experience Team](mailto:dx@sendgrid.com). + +sendgrid-java is maintained and funded by SendGrid, Inc. The names and logos for sendgrid-java are trademarks of SendGrid, Inc. + +![SendGrid Logo](https://uiux.s3.amazonaws.com/2016-logos/email-logo%402x.png) diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh new file mode 100644 index 00000000..556d85bd --- /dev/null +++ b/docker/entrypoint.sh @@ -0,0 +1,31 @@ +#! /bin/bash +clear + +# check for + link mounted libraries: +if [ -d /mnt/sendgrid-java ] +then + rm /root/sendgrid + ln -s /mnt/sendgrid-java/sendgrid + echo "Linked mounted sendgrid-java's code to /root/sendgrid" +fi + +SENDGRID_JAVA_VERSION="1.0.0" +echo "Welcome to sendgrid-java docker v${SENDGRID_JAVA_VERSION}." +echo + +if [ "$1" != "--no-mock" ] +then + echo "Starting Prism in mock mode. Calls made to Prism will not actually send emails." + echo "Disable this by running this container with --no-mock." + prism run --mock --spec $OAI_SPEC_URL 2> /dev/null & +else + echo "Starting Prism in live (--no-mock) mode. Calls made to Prism will send emails." + prism run --spec $OAI_SPEC_URL 2> /dev/null & +fi +echo "To use Prism, make API calls to localhost:4010. For example," +echo " sg = sendgrid.SendGridAPIClient(" +echo " host='http://localhost:4010/'," +echo " api_key=os.environ.get('SENDGRID_API_KEY_CAMPAIGNS'))" +echo "To stop Prism, run \"kill $!\" from the shell." + +bash \ No newline at end of file diff --git a/examples/accesssettings/CreateAccessSettings.java b/examples/accesssettings/CreateAccessSettings.java new file mode 100644 index 00000000..6c98df1b --- /dev/null +++ b/examples/accesssettings/CreateAccessSettings.java @@ -0,0 +1,30 @@ +import com.sendgrid.Method; +import com.sendgrid.Request; +import com.sendgrid.Response; +import com.sendgrid.SendGrid; + +import java.io.IOException; + +/*Add one or more IPs to the whitelist +POST /access_settings/whitelist +*/ + +public class CreateAccessSettings extends Example { + + private void run() throws IOException { + try { + String endPoint = "access_settings/whitelist"; + String body = "{\"ips\":[{\"ip\":\"192.168.1.1\"},{\"ip\":\"192.*.*.*\"},{\"ip\":\"192.168.1.3/32\"}]}"; + Request request = createRequest(Method.POST, endPoint, body); + Response response = execute(request); + printResponseInfo(response); + } catch (IOException ex) { + throw ex; + } + } + + public static void main(String[] args) throws IOException { + CreateAccessSettings createAccessSettings = new CreateAccessSettings(); + createAccessSettings.run(); + } +} diff --git a/examples/accesssettings/DeleteAccessSettings.java b/examples/accesssettings/DeleteAccessSettings.java new file mode 100644 index 00000000..a1abc860 --- /dev/null +++ b/examples/accesssettings/DeleteAccessSettings.java @@ -0,0 +1,30 @@ +import com.sendgrid.Method; +import com.sendgrid.Request; +import com.sendgrid.Response; +import com.sendgrid.SendGrid; + +import java.io.IOException; + +/* Remove one or more IPs from the whitelist + DELETE /access_settings/whitelist + */ + +public class DeleteAccessSettings extends Example { + + private void run() throws IOException { + try { + String endPoint = "access_settings/whitelist"; + String body = "{\"ids\":[1,2,3]}"; + Request request = createRequest(Method.DELETE, endPoint, body); + Response response = execute(request); + printResponseInfo(response); + } catch (IOException ex) { + throw ex; + } + } + + public static void main(String[] args) throws IOException { + DeleteAccessSettings deleteAccessSettings = new DeleteAccessSettings(); + deleteAccessSettings.run(); + } +} \ No newline at end of file diff --git a/examples/accesssettings/DeleteIPFromAccessSettings.java b/examples/accesssettings/DeleteIPFromAccessSettings.java new file mode 100644 index 00000000..d084c99c --- /dev/null +++ b/examples/accesssettings/DeleteIPFromAccessSettings.java @@ -0,0 +1,29 @@ +import com.sendgrid.Method; +import com.sendgrid.Request; +import com.sendgrid.Response; +import com.sendgrid.SendGrid; + +import java.io.IOException; + +/*Remove a specific IP from the whitelist +DELETE /access_settings/whitelist/{rule_id} +*/ + +public class DeleteIPFromAccessSettings extends Example { + + private void run() throws IOException { + try { + String endPoint = "access_settings/whitelist"; + String body = "{\"ids\":[1,2,3]}"; + Request request = createRequest(Method.DELETE, endPoint, body); + Response response = execute(request); + printResponseInfo(response); + } catch (IOException ex) { + throw ex; + } + } + + public static void main(String[] args) throws IOException { + DeleteIPFromAccessSettings deleteIPFromAccessSettings = new DeleteIPFromAccessSettings(); + deleteIPFromAccessSettings.run(); +} \ No newline at end of file diff --git a/examples/accesssettings/Example.java b/examples/accesssettings/Example.java new file mode 100644 index 00000000..6fd33a36 --- /dev/null +++ b/examples/accesssettings/Example.java @@ -0,0 +1,31 @@ +import com.sendgrid.Method; +import com.sendgrid.Request; +import com.sendgrid.Response; +import com.sendgrid.SendGrid; + +import java.io.IOException; + +public class Example { + + protected Request createRequest(Method method, String endPoint, String requestBody) { + Request request = new Request(); + request.setMethod(method); + request.setEndpoint(endPoint); + if (requestBody != null) { + request.setBody(requestBody); + } + return request; + } + + protected Response execute(Request request) throws IOException { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Response response = sg.api(request); + return response; + } + + protected void printResonseInfo(Response response) { + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); + } +} \ No newline at end of file diff --git a/examples/accesssettings/GetAccessSettings.java b/examples/accesssettings/GetAccessSettings.java new file mode 100644 index 00000000..24beee95 --- /dev/null +++ b/examples/accesssettings/GetAccessSettings.java @@ -0,0 +1,30 @@ +import com.sendgrid.Method; +import com.sendgrid.Request; +import com.sendgrid.Response; +import com.sendgrid.SendGrid; + +import java.io.IOException; + +/*Retrieve a list of currently whitelisted IPs +GET /access_settings/whitelist +*/ + +public class GetAccessSettings extends Example{ + + private void run() throws IOException { + try { + String endPoint = "access_settings/whitelist"; + String body = "{\"ids\":[1,2,3]}"; + Request request = createRequest(Method.DELETE, endPoint, body); + Response response = execute(request); + printResponseInfo(response); + } catch (IOException ex) { + throw ex; + } + } + + public static void main(String[] args) throws IOException { + GetAccessSettings getAccessSettings = new GetAccessSettings(); + getAccessSettings.run(); + } +} \ No newline at end of file diff --git a/examples/accesssettings/GetAccessSettingsActivity.java b/examples/accesssettings/GetAccessSettingsActivity.java new file mode 100644 index 00000000..5ca02258 --- /dev/null +++ b/examples/accesssettings/GetAccessSettingsActivity.java @@ -0,0 +1,33 @@ +import com.sendgrid.Method; +import com.sendgrid.Request; +import com.sendgrid.Response; +import com.sendgrid.SendGrid; + +import java.io.IOException; + +/*Retrieve all recent access attempts +GET /access_settings/activity +*/ + +public class GetAccessSettingsActivity extends Example { + + private void run() throws IOException { + try { + String endPoint = "access_settings/whitelist"; + String body = "{\"ids\":[1,2,3]}"; + Request request = createRequest(Method.DELETE, endPoint, body); + request.addQueryParam("limit", "1"); + Response response = execute(request); + printResponseInfo(response); + } catch (IOException ex) { + throw ex; + } + } + + public static void main(String[] args) throws IOException { + GetAccessSettingsActivity getAccessSettingsActivity = new GetAccessSettingsActivity(); + getAccessSettingsActivity.run(); + } +} + + diff --git a/examples/accesssettings/GetIPFromAccessSettings.java b/examples/accesssettings/GetIPFromAccessSettings.java new file mode 100644 index 00000000..456b141c --- /dev/null +++ b/examples/accesssettings/GetIPFromAccessSettings.java @@ -0,0 +1,30 @@ +import com.sendgrid.Method; +import com.sendgrid.Request; +import com.sendgrid.Response; +import com.sendgrid.SendGrid; + +import java.io.IOException; + +/* Retrieve a specific whitelisted IP +GET /access_settings/whitelist/{rule_id} +*/ + +public class GetIPFromAccessSettings extends Example { + + private void run() throws IOException { + try { + String endPoint = "access_settings/whitelist"; + String body = "{\"ids\":[1,2,3]}"; + Request request = createRequest(Method.DELETE, endPoint, body); + Response response = execute(request); + printResponseInfo(response); + } catch (IOException ex) { + throw ex; + } + } + + public static void main(String[] args) throws IOException { + GetIPFromAccessSettings getIPFromAccessSettings = new GetIPFromAccessSettings(); + getIPFromAccessSettings.run(); + } +} \ No newline at end of file diff --git a/examples/accesssettings/README.md b/examples/accesssettings/README.md new file mode 100644 index 00000000..f68dc86f --- /dev/null +++ b/examples/accesssettings/README.md @@ -0,0 +1,10 @@ +![SendGrid Logo](https://uiux.s3.amazonaws.com/2016-logos/email-logo%402x.png) + +This folder contains various examples on using the ACCESS_SETTINGS endpoint of SendGrid with Java: + +* [Retrieve a list of currently whitelisted IPs (GET /access_settings/whitelist)](GetAccessSettings.java) +* [Retrieve a specific whitelisted IP (GET /access_settings/whitelist/{rule_id})](GetIPFromAccessSettings.java) +* [Retrieve a list of currently whitelisted IPs (GET /access_settings/whitelist)](GetAccessSettingsActivity.java) +* [Remove a specific IP from the whitelist (DELETE /access_settings/whitelist/{rule_id}](DeleteIPFromAccessSettings.java) +* [Remove one or more IPs from the whitelist (DELETE /access_settings/whitelist)](DeleteAccessSettings.java) +* [Add one or more IPs to the whitelist (POST /access_settings/whitelist)](CreateAccessSettings.java) diff --git a/examples/alerts/alerts.java b/examples/alerts/alerts.java index 2ad8f27b..a364c464 100644 --- a/examples/alerts/alerts.java +++ b/examples/alerts/alerts.java @@ -17,13 +17,13 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.POST; - request.endpoint = "alerts"; - request.body = "{\"type\":\"stats_notification\",\"frequency\":\"daily\",\"email_to\":\"example@example.com\"}"; + request.setMethod(Method.POST); + request.setEndpoint("alerts"); + request.setBody("{\"type\":\"stats_notification\",\"frequency\":\"daily\",\"email_to\":\"example@example.com\"}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -40,12 +40,12 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "alerts"; + request.setMethod(Method.GET); + request.setEndpoint("alerts"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -62,13 +62,13 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.PATCH; - request.endpoint = "alerts/{alert_id}"; - request.body = "{\"email_to\":\"example@example.com\"}"; + request.setMethod(Method.PATCH); + request.setEndpoint("alerts/{alert_id}"); + request.setBody("{\"email_to\":\"example@example.com\"}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -85,12 +85,12 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "alerts/{alert_id}"; + request.setMethod(Method.GET); + request.setEndpoint("alerts/{alert_id}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -107,12 +107,12 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.DELETE; - request.endpoint = "alerts/{alert_id}"; + request.setMethod(Method.DELETE); + request.setEndpoint("alerts/{alert_id}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } diff --git a/examples/apikeys/apikeys.java b/examples/apikeys/apikeys.java index 83e00032..d8e41909 100644 --- a/examples/apikeys/apikeys.java +++ b/examples/apikeys/apikeys.java @@ -1,11 +1,9 @@ -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; - -import com.sendgrid.*; +import com.sendgrid.Method; +import com.sendgrid.Request; +import com.sendgrid.Response; +import com.sendgrid.SendGrid; import java.io.IOException; -import java.util.HashMap; -import java.util.Map; ////////////////////////////////////////////////////////////////// // Create API keys @@ -17,13 +15,13 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.POST; - request.endpoint = "api_keys"; - request.body = "{\"sample\":\"data\",\"scopes\":[\"mail.send\",\"alerts.create\",\"alerts.read\"],\"name\":\"My API Key\"}"; + request.setMethod(Method.POST); + request.setEndpoint("api_keys"); + request.setBody("{\"sample\":\"data\",\"scopes\":[\"mail.send\",\"alerts.create\",\"alerts.read\"],\"name\":\"My API Key\"}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -40,15 +38,13 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "api_keys"; - Map queryParams = new HashMap(); - queryParams.put("limit", "1"); - request.queryParams = queryParams; + request.setMethod(Method.GET); + request.setEndpoint("api_keys"); + request.addQueryParam("limit", "1"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -65,13 +61,13 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.PUT; - request.endpoint = "api_keys/{api_key_id}"; - request.body = "{\"scopes\":[\"user.profile.read\",\"user.profile.update\"],\"name\":\"A New Hope\"}"; + request.setMethod(Method.PUT); + request.setEndpoint("api_keys/{api_key_id}"); + request.setBody("{\"scopes\":[\"user.profile.read\",\"user.profile.update\"],\"name\":\"A New Hope\"}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -88,13 +84,13 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.PATCH; - request.endpoint = "api_keys/{api_key_id}"; - request.body = "{\"name\":\"A New Hope\"}"; + request.setMethod(Method.PATCH); + request.setEndpoint("api_keys/{api_key_id}"); + request.setBody("{\"name\":\"A New Hope\"}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -111,12 +107,12 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "api_keys/{api_key_id}"; + request.setMethod(Method.GET); + request.setEndpoint("api_keys/{api_key_id}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -133,12 +129,12 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.DELETE; - request.endpoint = "api_keys/{api_key_id}"; + request.setMethod(Method.DELETE); + request.setEndpoint("api_keys/{api_key_id}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } diff --git a/examples/asm/asm.java b/examples/asm/asm.java index e56a5676..a22c5100 100644 --- a/examples/asm/asm.java +++ b/examples/asm/asm.java @@ -1,11 +1,9 @@ -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; - -import com.sendgrid.*; +import com.sendgrid.Method; +import com.sendgrid.Request; +import com.sendgrid.Response; +import com.sendgrid.SendGrid; import java.io.IOException; -import java.util.HashMap; -import java.util.Map; ////////////////////////////////////////////////////////////////// // Create a new suppression group @@ -17,13 +15,13 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.POST; - request.endpoint = "asm/groups"; - request.body = "{\"is_default\":true,\"description\":\"Suggestions for products our users might like.\",\"name\":\"Product Suggestions\"}"; + request.setMethod(Method.POST); + request.setEndpoint("asm/groups"); + request.setBody("{\"is_default\":true,\"description\":\"Suggestions for products our users might like.\",\"name\":\"Product Suggestions\"}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -40,15 +38,13 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "asm/groups"; - Map queryParams = new HashMap(); - queryParams.put("id", "1"); - request.queryParams = queryParams; + request.setMethod(Method.GET); + request.setEndpoint("asm/groups"); + request.addQueryParam("id", "1"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -65,13 +61,13 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.PATCH; - request.endpoint = "asm/groups/{group_id}"; - request.body = "{\"description\":\"Suggestions for items our users might like.\",\"name\":\"Item Suggestions\",\"id\":103}"; + request.setMethod(Method.PATCH); + request.setEndpoint("asm/groups/{group_id}"); + request.setBody("{\"description\":\"Suggestions for items our users might like.\",\"name\":\"Item Suggestions\",\"id\":103}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -88,12 +84,12 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "asm/groups/{group_id}"; + request.setMethod(Method.GET); + request.setEndpoint("asm/groups/{group_id}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -110,12 +106,12 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.DELETE; - request.endpoint = "asm/groups/{group_id}"; + request.setMethod(Method.DELETE); + request.setEndpoint("asm/groups/{group_id}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -132,13 +128,13 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.POST; - request.endpoint = "asm/groups/{group_id}/suppressions"; - request.body = "{\"recipient_emails\":[\"test1@example.com\",\"test2@example.com\"]}"; + request.setMethod(Method.POST); + request.setEndpoint("asm/groups/{group_id}/suppressions"); + request.setBody("{\"recipient_emails\":[\"test1@example.com\",\"test2@example.com\"]}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -155,12 +151,12 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "asm/groups/{group_id}/suppressions"; + request.setMethod(Method.GET); + request.setEndpoint("asm/groups/{group_id}/suppressions"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -177,13 +173,13 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.POST; - request.endpoint = "asm/groups/{group_id}/suppressions/search"; - request.body = "{\"recipient_emails\":[\"exists1@example.com\",\"exists2@example.com\",\"doesnotexists@example.com\"]}"; + request.setMethod(Method.POST); + request.setEndpoint("asm/groups/{group_id}/suppressions/search"); + request.setBody("{\"recipient_emails\":[\"exists1@example.com\",\"exists2@example.com\",\"doesnotexists@example.com\"]}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -200,12 +196,12 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.DELETE; - request.endpoint = "asm/groups/{group_id}/suppressions/{email}"; + request.setMethod(Method.DELETE); + request.setEndpoint("asm/groups/{group_id}/suppressions/{email}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -222,12 +218,12 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "asm/suppressions"; + request.setMethod(Method.GET); + request.setEndpoint("asm/suppressions"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -244,13 +240,13 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.POST; - request.endpoint = "asm/suppressions/global"; - request.body = "{\"recipient_emails\":[\"test1@example.com\",\"test2@example.com\"]}"; + request.setMethod(Method.POST); + request.setEndpoint("asm/suppressions/global"); + request.setBody("{\"recipient_emails\":[\"test1@example.com\",\"test2@example.com\"]}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -267,12 +263,12 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "asm/suppressions/global/{email}"; + request.setMethod(Method.GET); + request.setEndpoint("asm/suppressions/global/{email}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -289,12 +285,12 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.DELETE; - request.endpoint = "asm/suppressions/global/{email}"; + request.setMethod(Method.DELETE); + request.setEndpoint("asm/suppressions/global/{email}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -311,12 +307,12 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "asm/suppressions/{email}"; + request.setMethod(Method.GET); + request.setEndpoint("asm/suppressions/{email}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } diff --git a/examples/browsers/browsers.java b/examples/browsers/browsers.java index e6085aef..a4eca365 100644 --- a/examples/browsers/browsers.java +++ b/examples/browsers/browsers.java @@ -17,20 +17,18 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "browsers/stats"; - Map queryParams = new HashMap(); - queryParams.put("end_date", "2016-04-01"); - queryParams.put("aggregated_by", "day"); - queryParams.put("browsers", "test_string"); - queryParams.put("limit", "test_string"); - queryParams.put("offset", "test_string"); - queryParams.put("start_date", "2016-01-01"); - request.queryParams = queryParams; + request.setMethod(Method.GET); + request.setEndpoint("browsers/stats"); + request.addQueryParam("end_date", "2016-04-01"); + request.addQueryParam("aggregated_by", "day"); + request.addQueryParam("browsers", "test_string"); + request.addQueryParam("limit", "test_string"); + request.addQueryParam("offset", "test_string"); + request.addQueryParam("start_date", "2016-01-01"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } diff --git a/examples/campaigns/campaigns.java b/examples/campaigns/campaigns.java index f6a051df..6345eca7 100644 --- a/examples/campaigns/campaigns.java +++ b/examples/campaigns/campaigns.java @@ -17,13 +17,13 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.POST; - request.endpoint = "campaigns"; - request.body = "{\"custom_unsubscribe_url\":\"\",\"html_content\":\"

Check out our spring line!

\",\"list_ids\":[110,124],\"sender_id\":124451,\"subject\":\"New Products for Spring!\",\"plain_content\":\"Check out our spring line!\",\"suppression_group_id\":42,\"title\":\"March Newsletter\",\"segment_ids\":[110],\"categories\":[\"spring line\"],\"ip_pool\":\"marketing\"}"; + request.setMethod(Method.POST); + request.setEndpoint("campaigns"); + request.setBody("{\"custom_unsubscribe_url\":\"\",\"html_content\":\"

Check out our spring line!

\",\"list_ids\":[110,124],\"sender_id\":124451,\"subject\":\"New Products for Spring!\",\"plain_content\":\"Check out our spring line!\",\"suppression_group_id\":42,\"title\":\"March Newsletter\",\"segment_ids\":[110],\"categories\":[\"spring line\"],\"ip_pool\":\"marketing\"}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -40,16 +40,14 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "campaigns"; - Map queryParams = new HashMap(); - queryParams.put("limit", "1"); - queryParams.put("offset", "1"); - request.queryParams = queryParams; + request.setMethod(Method.GET); + request.setEndpoint("campaigns"); + request.addQueryParam("limit", "1"); + request.addQueryParam("offset", "1"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -66,13 +64,13 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.PATCH; - request.endpoint = "campaigns/{campaign_id}"; - request.body = "{\"html_content\":\"

Check out our summer line!

\",\"subject\":\"New Products for Summer!\",\"title\":\"May Newsletter\",\"categories\":[\"summer line\"],\"plain_content\":\"Check out our summer line!\"}"; + request.setMethod(Method.PATCH); + request.setEndpoint("campaigns/{campaign_id}"); + request.setBody("{\"html_content\":\"

Check out our summer line!

\",\"subject\":\"New Products for Summer!\",\"title\":\"May Newsletter\",\"categories\":[\"summer line\"],\"plain_content\":\"Check out our summer line!\"}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -89,12 +87,12 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "campaigns/{campaign_id}"; + request.setMethod(Method.GET); + request.setEndpoint("campaigns/{campaign_id}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -111,12 +109,12 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.DELETE; - request.endpoint = "campaigns/{campaign_id}"; + request.setMethod(Method.DELETE); + request.setEndpoint("campaigns/{campaign_id}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -133,13 +131,13 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.PATCH; - request.endpoint = "campaigns/{campaign_id}/schedules"; - request.body = "{\"send_at\":1489451436}"; + request.setMethod(Method.PATCH); + request.setEndpoint("campaigns/{campaign_id}/schedules"); + request.setBody("{\"send_at\":1489451436}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -156,13 +154,13 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.POST; - request.endpoint = "campaigns/{campaign_id}/schedules"; - request.body = "{\"send_at\":1489771528}"; + request.setMethod(Method.POST); + request.setEndpoint("campaigns/{campaign_id}/schedules"); + request.setBody("{\"send_at\":1489771528}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -179,12 +177,12 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "campaigns/{campaign_id}/schedules"; + request.setMethod(Method.GET); + request.setEndpoint("campaigns/{campaign_id}/schedules"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -201,12 +199,12 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.DELETE; - request.endpoint = "campaigns/{campaign_id}/schedules"; + request.setMethod(Method.DELETE); + request.setEndpoint("campaigns/{campaign_id}/schedules"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -223,12 +221,12 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.POST; - request.endpoint = "campaigns/{campaign_id}/schedules/now"; + request.setMethod(Method.POST); + request.setEndpoint("campaigns/{campaign_id}/schedules/now"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -245,13 +243,13 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.POST; - request.endpoint = "campaigns/{campaign_id}/schedules/test"; - request.body = "{\"to\":\"your.email@example.com\"}"; + request.setMethod(Method.POST); + request.setEndpoint("campaigns/{campaign_id}/schedules/test"); + request.setBody("{\"to\":\"your.email@example.com\"}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } diff --git a/examples/categories/categories.java b/examples/categories/categories.java index b6d2f507..7ac73822 100644 --- a/examples/categories/categories.java +++ b/examples/categories/categories.java @@ -17,17 +17,15 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "categories"; - Map queryParams = new HashMap(); - queryParams.put("category", "test_string"); - queryParams.put("limit", "1"); - queryParams.put("offset", "1"); - request.queryParams = queryParams; + request.setMethod(Method.GET); + request.setEndpoint("categories"); + request.addQueryParam("category", "test_string"); + request.addQueryParam("limit", "1"); + request.addQueryParam("offset", "1"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -44,20 +42,18 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "categories/stats"; - Map queryParams = new HashMap(); - queryParams.put("end_date", "2016-04-01"); - queryParams.put("aggregated_by", "day"); - queryParams.put("limit", "1"); - queryParams.put("offset", "1"); - queryParams.put("start_date", "2016-01-01"); - queryParams.put("categories", "test_string"); - request.queryParams = queryParams; + request.setMethod(Method.GET); + request.setEndpoint("categories/stats"); + request.addQueryParam("end_date", "2016-04-01"); + request.addQueryParam("aggregated_by", "day"); + request.addQueryParam("limit", "1"); + request.addQueryParam("offset", "1"); + request.addQueryParam("start_date", "2016-01-01"); + request.addQueryParam("categories", "test_string"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -74,21 +70,19 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "categories/stats/sums"; - Map queryParams = new HashMap(); - queryParams.put("end_date", "2016-04-01"); - queryParams.put("aggregated_by", "day"); - queryParams.put("limit", "1"); - queryParams.put("sort_by_metric", "test_string"); - queryParams.put("offset", "1"); - queryParams.put("start_date", "2016-01-01"); - queryParams.put("sort_by_direction", "asc"); - request.queryParams = queryParams; + request.setMethod(Method.GET); + request.setEndpoint("categories/stats/sums"); + request.addQueryParam("end_date", "2016-04-01"); + request.addQueryParam("aggregated_by", "day"); + request.addQueryParam("limit", "1"); + request.addQueryParam("sort_by_metric", "test_string"); + request.addQueryParam("offset", "1"); + request.addQueryParam("start_date", "2016-01-01"); + request.addQueryParam("sort_by_direction", "asc"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } diff --git a/examples/clients/clients.java b/examples/clients/clients.java index 1d48540c..9b755d86 100644 --- a/examples/clients/clients.java +++ b/examples/clients/clients.java @@ -17,17 +17,15 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "clients/stats"; - Map queryParams = new HashMap(); - queryParams.put("aggregated_by", "day"); - queryParams.put("start_date", "2016-01-01"); - queryParams.put("end_date", "2016-04-01"); - request.queryParams = queryParams; + request.setMethod(Method.GET); + request.setEndpoint("clients/stats"); + request.addQueryParam("aggregated_by", "day"); + request.addQueryParam("start_date", "2016-01-01"); + request.addQueryParam("end_date", "2016-04-01"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -44,17 +42,15 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "clients/{client_type}/stats"; - Map queryParams = new HashMap(); - queryParams.put("aggregated_by", "day"); - queryParams.put("start_date", "2016-01-01"); - queryParams.put("end_date", "2016-04-01"); - request.queryParams = queryParams; + request.setMethod(Method.GET); + request.setEndpoint("clients/{client_type}/stats"); + request.addQueryParam("aggregated_by", "day"); + request.addQueryParam("start_date", "2016-01-01"); + request.addQueryParam("end_date", "2016-04-01"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } diff --git a/examples/contactdb/contactdb.java b/examples/contactdb/contactdb.java deleted file mode 100644 index e57e06a9..00000000 --- a/examples/contactdb/contactdb.java +++ /dev/null @@ -1,739 +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; - -////////////////////////////////////////////////////////////////// -// Create a Custom Field -// POST /contactdb/custom_fields - - -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.method = Method.POST; - request.endpoint = "contactdb/custom_fields"; - request.body = "{\"type\":\"text\",\"name\":\"pet\"}"; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Retrieve all custom fields -// GET /contactdb/custom_fields - - -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.method = Method.GET; - request.endpoint = "contactdb/custom_fields"; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Retrieve a Custom Field -// GET /contactdb/custom_fields/{custom_field_id} - - -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.method = Method.GET; - request.endpoint = "contactdb/custom_fields/{custom_field_id}"; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Delete a Custom Field -// DELETE /contactdb/custom_fields/{custom_field_id} - - -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.method = Method.DELETE; - request.endpoint = "contactdb/custom_fields/{custom_field_id}"; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Create a List -// POST /contactdb/lists - - -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.method = Method.POST; - request.endpoint = "contactdb/lists"; - request.body = "{\"name\":\"your list name\"}"; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Retrieve all lists -// GET /contactdb/lists - - -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.method = Method.GET; - request.endpoint = "contactdb/lists"; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Delete Multiple lists -// DELETE /contactdb/lists - - -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.method = Method.DELETE; - request.endpoint = "contactdb/lists"; - request.body = "[1,2,3,4]"; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Update a List -// PATCH /contactdb/lists/{list_id} - - -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.method = Method.PATCH; - request.endpoint = "contactdb/lists/{list_id}"; - request.body = "{\"name\":\"newlistname\"}"; - Map queryParams = new HashMap(); - queryParams.put("list_id", "1"); - request.queryParams = queryParams; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Retrieve a single list -// GET /contactdb/lists/{list_id} - - -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.method = Method.GET; - request.endpoint = "contactdb/lists/{list_id}"; - Map queryParams = new HashMap(); - queryParams.put("list_id", "1"); - request.queryParams = queryParams; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Delete a List -// DELETE /contactdb/lists/{list_id} - - -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.method = Method.DELETE; - request.endpoint = "contactdb/lists/{list_id}"; - Map queryParams = new HashMap(); - queryParams.put("delete_contacts", "true"); - request.queryParams = queryParams; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Add Multiple Recipients to a List -// POST /contactdb/lists/{list_id}/recipients - - -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.method = Method.POST; - request.endpoint = "contactdb/lists/{list_id}/recipients"; - request.body = "[\"recipient_id1\",\"recipient_id2\"]"; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Retrieve all recipients on a List -// GET /contactdb/lists/{list_id}/recipients - - -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.method = Method.GET; - request.endpoint = "contactdb/lists/{list_id}/recipients"; - Map queryParams = new HashMap(); - queryParams.put("page", "1"); - queryParams.put("page_size", "1"); - queryParams.put("list_id", "1"); - request.queryParams = queryParams; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Add a Single Recipient to a List -// POST /contactdb/lists/{list_id}/recipients/{recipient_id} - - -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.method = Method.POST; - request.endpoint = "contactdb/lists/{list_id}/recipients/{recipient_id}"; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Delete a Single Recipient from a Single List -// DELETE /contactdb/lists/{list_id}/recipients/{recipient_id} - - -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.method = Method.DELETE; - request.endpoint = "contactdb/lists/{list_id}/recipients/{recipient_id}"; - Map queryParams = new HashMap(); - queryParams.put("recipient_id", "1"); - queryParams.put("list_id", "1"); - request.queryParams = queryParams; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Update Recipient -// PATCH /contactdb/recipients - - -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.method = Method.PATCH; - request.endpoint = "contactdb/recipients"; - request.body = "[{\"first_name\":\"Guy\",\"last_name\":\"Jones\",\"email\":\"jones@example.com\"}]"; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Add recipients -// POST /contactdb/recipients - - -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.method = Method.POST; - request.endpoint = "contactdb/recipients"; - request.body = "[{\"age\":25,\"last_name\":\"User\",\"email\":\"example@example.com\",\"first_name\":\"\"},{\"age\":25,\"last_name\":\"User\",\"email\":\"example2@example.com\",\"first_name\":\"Example\"}]"; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Retrieve recipients -// GET /contactdb/recipients - - -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.method = Method.GET; - request.endpoint = "contactdb/recipients"; - Map queryParams = new HashMap(); - queryParams.put("page", "1"); - queryParams.put("page_size", "1"); - request.queryParams = queryParams; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Delete Recipient -// DELETE /contactdb/recipients - - -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.method = Method.DELETE; - request.endpoint = "contactdb/recipients"; - request.body = "[\"recipient_id1\",\"recipient_id2\"]"; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Retrieve the count of billable recipients -// GET /contactdb/recipients/billable_count - - -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.method = Method.GET; - request.endpoint = "contactdb/recipients/billable_count"; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Retrieve a Count of Recipients -// GET /contactdb/recipients/count - - -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.method = Method.GET; - request.endpoint = "contactdb/recipients/count"; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Retrieve recipients matching search criteria -// GET /contactdb/recipients/search - - -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.method = Method.GET; - request.endpoint = "contactdb/recipients/search"; - Map queryParams = new HashMap(); - queryParams.put("{field_name}", "test_string"); - request.queryParams = queryParams; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Retrieve a single recipient -// GET /contactdb/recipients/{recipient_id} - - -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.method = Method.GET; - request.endpoint = "contactdb/recipients/{recipient_id}"; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Delete a Recipient -// DELETE /contactdb/recipients/{recipient_id} - - -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.method = Method.DELETE; - request.endpoint = "contactdb/recipients/{recipient_id}"; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Retrieve the lists that a recipient is on -// GET /contactdb/recipients/{recipient_id}/lists - - -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.method = Method.GET; - request.endpoint = "contactdb/recipients/{recipient_id}/lists"; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Retrieve reserved fields -// GET /contactdb/reserved_fields - - -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.method = Method.GET; - request.endpoint = "contactdb/reserved_fields"; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Create a Segment -// POST /contactdb/segments - - -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.method = Method.POST; - request.endpoint = "contactdb/segments"; - request.body = "{\"conditions\":[{\"operator\":\"eq\",\"field\":\"last_name\",\"and_or\":\"\",\"value\":\"Miller\"},{\"operator\":\"gt\",\"field\":\"last_clicked\",\"and_or\":\"and\",\"value\":\"01/02/2015\"},{\"operator\":\"eq\",\"field\":\"clicks.campaign_identifier\",\"and_or\":\"or\",\"value\":\"513\"}],\"name\":\"Last Name Miller\",\"list_id\":4}"; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Retrieve all segments -// GET /contactdb/segments - - -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.method = Method.GET; - request.endpoint = "contactdb/segments"; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Update a segment -// PATCH /contactdb/segments/{segment_id} - - -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.method = Method.PATCH; - request.endpoint = "contactdb/segments/{segment_id}"; - request.body = "{\"conditions\":[{\"operator\":\"eq\",\"field\":\"last_name\",\"and_or\":\"\",\"value\":\"Miller\"}],\"name\":\"The Millers\",\"list_id\":5}"; - Map queryParams = new HashMap(); - queryParams.put("segment_id", "test_string"); - request.queryParams = queryParams; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Retrieve a segment -// GET /contactdb/segments/{segment_id} - - -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.method = Method.GET; - request.endpoint = "contactdb/segments/{segment_id}"; - Map queryParams = new HashMap(); - queryParams.put("segment_id", "1"); - request.queryParams = queryParams; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Delete a segment -// DELETE /contactdb/segments/{segment_id} - - -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.method = Method.DELETE; - request.endpoint = "contactdb/segments/{segment_id}"; - Map queryParams = new HashMap(); - queryParams.put("delete_contacts", "true"); - request.queryParams = queryParams; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Retrieve recipients on a segment -// GET /contactdb/segments/{segment_id}/recipients - - -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.method = Method.GET; - request.endpoint = "contactdb/segments/{segment_id}/recipients"; - Map queryParams = new HashMap(); - queryParams.put("page", "1"); - queryParams.put("page_size", "1"); - request.queryParams = queryParams; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } catch (IOException ex) { - throw ex; - } - } -} - diff --git a/examples/contactdb/customfields.java b/examples/contactdb/customfields.java new file mode 100644 index 00000000..e4ce5c58 --- /dev/null +++ b/examples/contactdb/customfields.java @@ -0,0 +1,97 @@ +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; + +////////////////////////////////////////////////////////////////// +// Create a Custom Field +// POST /contactdb/custom_fields + + +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.POST); + request.setEndpoint("contactdb/custom_fields"); + request.setBody("{\"type\":\"text\",\"name\":\"pet\"}"); + 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 custom fields +// GET /contactdb/custom_fields + + +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("contactdb/custom_fields"); + 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 a Custom Field +// GET /contactdb/custom_fields/{custom_field_id} + + +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("contactdb/custom_fields/{custom_field_id}"); + 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; + } + } +} + +////////////////////////////////////////////////////////////////// +// Delete a Custom Field +// DELETE /contactdb/custom_fields/{custom_field_id} + + +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.DELETE); + request.setEndpoint("contactdb/custom_fields/{custom_field_id}"); + 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/contactdb/listrecipients.java b/examples/contactdb/listrecipients.java new file mode 100644 index 00000000..cfe621e7 --- /dev/null +++ b/examples/contactdb/listrecipients.java @@ -0,0 +1,102 @@ +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; + +////////////////////////////////////////////////////////////////// +// Add Multiple Recipients to a List +// POST /contactdb/lists/{list_id}/recipients + + +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.POST); + request.setEndpoint("contactdb/lists/{list_id}/recipients"); + request.setBody("[\"recipient_id1\",\"recipient_id2\"]"); + 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 recipients on a List +// GET /contactdb/lists/{list_id}/recipients + + +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("contactdb/lists/{list_id}/recipients"); + request.addQueryParam("page", "1"); + request.addQueryParam("page_size", "1"); + request.addQueryParam("list_id", "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; + } + } +} + +////////////////////////////////////////////////////////////////// +// Add a Single Recipient to a List +// POST /contactdb/lists/{list_id}/recipients/{recipient_id} + + +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.POST); + request.setEndpoint("contactdb/lists/{list_id}/recipients/{recipient_id}"); + 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; + } + } +} + +////////////////////////////////////////////////////////////////// +// Delete a Single Recipient from a Single List +// DELETE /contactdb/lists/{list_id}/recipients/{recipient_id} + + +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.DELETE); + request.setEndpoint("contactdb/lists/{list_id}/recipients/{recipient_id}"); + request.addQueryParam("recipient_id", "1"); + request.addQueryParam("list_id", "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/accesssettings/accesssettings.java b/examples/contactdb/lists.java similarity index 53% rename from examples/accesssettings/accesssettings.java rename to examples/contactdb/lists.java index 5073484f..1e55fd29 100644 --- a/examples/accesssettings/accesssettings.java +++ b/examples/contactdb/lists.java @@ -8,8 +8,8 @@ import java.util.Map; ////////////////////////////////////////////////////////////////// -// Retrieve all recent access attempts -// GET /access_settings/activity +// Create a List +// POST /contactdb/lists public class Example { @@ -17,15 +17,13 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "access_settings/activity"; - Map queryParams = new HashMap(); - queryParams.put("limit", "1"); - request.queryParams = queryParams; + request.setMethod(Method.POST); + request.setEndpoint("contactdb/lists"); + request.setBody("{\"name\":\"your list name\"}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -33,8 +31,8 @@ public static void main(String[] args) throws IOException { } ////////////////////////////////////////////////////////////////// -// Add one or more IPs to the whitelist -// POST /access_settings/whitelist +// Retrieve all lists +// GET /contactdb/lists public class Example { @@ -42,13 +40,12 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.POST; - request.endpoint = "access_settings/whitelist"; - request.body = "{\"ips\":[{\"ip\":\"192.168.1.1\"},{\"ip\":\"192.*.*.*\"},{\"ip\":\"192.168.1.3/32\"}]}"; + request.setMethod(Method.GET); + request.setEndpoint("contactdb/lists"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -56,8 +53,8 @@ public static void main(String[] args) throws IOException { } ////////////////////////////////////////////////////////////////// -// Retrieve a list of currently whitelisted IPs -// GET /access_settings/whitelist +// Delete Multiple lists +// DELETE /contactdb/lists public class Example { @@ -65,12 +62,13 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "access_settings/whitelist"; + request.setMethod(Method.DELETE); + request.setEndpoint("contactdb/lists"); + request.setBody("[1,2,3,4]"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -78,8 +76,8 @@ public static void main(String[] args) throws IOException { } ////////////////////////////////////////////////////////////////// -// Remove one or more IPs from the whitelist -// DELETE /access_settings/whitelist +// Update a List +// PATCH /contactdb/lists/{list_id} public class Example { @@ -87,13 +85,14 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.DELETE; - request.endpoint = "access_settings/whitelist"; - request.body = "{\"ids\":[1,2,3]}"; + request.setMethod(Method.PATCH); + request.setEndpoint("contactdb/lists/{list_id}"); + request.setBody("{\"name\":\"newlistname\"}"); + request.addQueryParam("list_id", "1"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -101,8 +100,8 @@ public static void main(String[] args) throws IOException { } ////////////////////////////////////////////////////////////////// -// Retrieve a specific whitelisted IP -// GET /access_settings/whitelist/{rule_id} +// Retrieve a single list +// GET /contactdb/lists/{list_id} public class Example { @@ -110,12 +109,13 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "access_settings/whitelist/{rule_id}"; + request.setMethod(Method.GET); + request.setEndpoint("contactdb/lists/{list_id}"); + request.addQueryParam("list_id", "1"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -123,8 +123,8 @@ public static void main(String[] args) throws IOException { } ////////////////////////////////////////////////////////////////// -// Remove a specific IP from the whitelist -// DELETE /access_settings/whitelist/{rule_id} +// Delete a List +// DELETE /contactdb/lists/{list_id} public class Example { @@ -132,15 +132,15 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.DELETE; - request.endpoint = "access_settings/whitelist/{rule_id}"; + request.setMethod(Method.DELETE); + request.setEndpoint("contactdb/lists/{list_id}"); + request.addQueryParam("delete_contacts", "true"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } } } - diff --git a/examples/contactdb/recipients.java b/examples/contactdb/recipients.java new file mode 100644 index 00000000..ebba8d90 --- /dev/null +++ b/examples/contactdb/recipients.java @@ -0,0 +1,234 @@ +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; + +////////////////////////////////////////////////////////////////// +// Update Recipient +// PATCH /contactdb/recipients + + +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("contactdb/recipients"); + request.setBody("[{\"first_name\":\"Guy\",\"last_name\":\"Jones\",\"email\":\"jones@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; + } + } +} + +////////////////////////////////////////////////////////////////// +// Add recipients +// POST /contactdb/recipients + + +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.POST); + request.setEndpoint("contactdb/recipients"); + request.setBody("[{\"age\":25,\"last_name\":\"User\",\"email\":\"example@example.com\",\"first_name\":\"\"},{\"age\":25,\"last_name\":\"User\",\"email\":\"example2@example.com\",\"first_name\":\"Example\"}]"); + 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 recipients +// GET /contactdb/recipients + + +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("contactdb/recipients"); + request.addQueryParam("page", "1"); + request.addQueryParam("page_size", "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; + } + } +} + +////////////////////////////////////////////////////////////////// +// Delete Recipient +// DELETE /contactdb/recipients + + +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.DELETE); + request.setEndpoint("contactdb/recipients"); + request.setBody("[\"recipient_id1\",\"recipient_id2\"]"); + 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 the count of billable recipients +// GET /contactdb/recipients/billable_count + + +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("contactdb/recipients/billable_count"); + 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 a Count of Recipients +// GET /contactdb/recipients/count + + +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("contactdb/recipients/count"); + 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 recipients matching search criteria +// GET /contactdb/recipients/search + + +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("contactdb/recipients/search"); + request.addQueryParam("{field_name}", "test_string"); + 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 a single recipient +// GET /contactdb/recipients/{recipient_id} + + +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("contactdb/recipients/{recipient_id}"); + 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; + } + } +} + +////////////////////////////////////////////////////////////////// +// Delete a Recipient +// DELETE /contactdb/recipients/{recipient_id} + + +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.DELETE); + request.setEndpoint("contactdb/recipients/{recipient_id}"); + 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 the lists that a recipient is on +// GET /contactdb/recipients/{recipient_id}/lists + + +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("contactdb/recipients/{recipient_id}/lists"); + 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/contactdb/reservedfields.java b/examples/contactdb/reservedfields.java new file mode 100644 index 00000000..e9ceafa9 --- /dev/null +++ b/examples/contactdb/reservedfields.java @@ -0,0 +1,30 @@ +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 reserved fields +// GET /contactdb/reserved_fields + + +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("contactdb/reserved_fields"); + 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/contactdb/segments.java b/examples/contactdb/segments.java new file mode 100644 index 00000000..84c60027 --- /dev/null +++ b/examples/contactdb/segments.java @@ -0,0 +1,147 @@ +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; + +////////////////////////////////////////////////////////////////// +// Create a Segment +// POST /contactdb/segments + + +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.POST); + request.setEndpoint("contactdb/segments"); + request.setBody("{\"conditions\":[{\"operator\":\"eq\",\"field\":\"last_name\",\"and_or\":\"\",\"value\":\"Miller\"},{\"operator\":\"gt\",\"field\":\"last_clicked\",\"and_or\":\"and\",\"value\":\"01/02/2015\"},{\"operator\":\"eq\",\"field\":\"clicks.campaign_identifier\",\"and_or\":\"or\",\"value\":\"513\"}],\"name\":\"Last Name Miller\",\"list_id\":4}"); + 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 segments +// GET /contactdb/segments + + +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("contactdb/segments"); + 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 a segment +// PATCH /contactdb/segments/{segment_id} + + +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("contactdb/segments/{segment_id}"); + request.setBody("{\"conditions\":[{\"operator\":\"eq\",\"field\":\"last_name\",\"and_or\":\"\",\"value\":\"Miller\"}],\"name\":\"The Millers\",\"list_id\":5}"); + request.addQueryParam("segment_id", "test_string"); + 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 a segment +// GET /contactdb/segments/{segment_id} + + +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("contactdb/segments/{segment_id}"); + request.addQueryParam("segment_id", "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; + } + } +} + +////////////////////////////////////////////////////////////////// +// Delete a segment +// DELETE /contactdb/segments/{segment_id} + + +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.DELETE); + request.setEndpoint("contactdb/segments/{segment_id}"); + request.addQueryParam("delete_contacts", "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 recipients on a segment +// GET /contactdb/segments/{segment_id}/recipients + + +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("contactdb/segments/{segment_id}/recipients"); + request.addQueryParam("page", "1"); + request.addQueryParam("page_size", "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/devices/devices.java b/examples/devices/devices.java index 5dbe9cd5..7c253eac 100644 --- a/examples/devices/devices.java +++ b/examples/devices/devices.java @@ -17,19 +17,17 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "devices/stats"; - Map queryParams = new HashMap(); - queryParams.put("aggregated_by", "day"); - queryParams.put("limit", "1"); - queryParams.put("start_date", "2016-01-01"); - queryParams.put("end_date", "2016-04-01"); - queryParams.put("offset", "1"); - request.queryParams = queryParams; + request.setMethod(Method.GET); + request.setEndpoint("devices/stats"); + request.addQueryParam("aggregated_by", "day"); + request.addQueryParam("limit", "1"); + request.addQueryParam("start_date", "2016-01-01"); + request.addQueryParam("end_date", "2016-04-01"); + request.addQueryParam("offset", "1"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } diff --git a/examples/geo/geo.java b/examples/geo/geo.java index 48309368..6b74fda9 100644 --- a/examples/geo/geo.java +++ b/examples/geo/geo.java @@ -17,20 +17,18 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "geo/stats"; - Map queryParams = new HashMap(); - queryParams.put("end_date", "2016-04-01"); - queryParams.put("country", "US"); - queryParams.put("aggregated_by", "day"); - queryParams.put("limit", "1"); - queryParams.put("offset", "1"); - queryParams.put("start_date", "2016-01-01"); - request.queryParams = queryParams; + request.setMethod(Method.GET); + request.setEndpoint("geo/stats"); + request.addQueryParam("end_date", "2016-04-01"); + request.addQueryParam("country", "US"); + request.addQueryParam("aggregated_by", "day"); + request.addQueryParam("limit", "1"); + request.addQueryParam("offset", "1"); + request.addQueryParam("start_date", "2016-01-01"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } diff --git a/examples/helpers/mail/Example.java b/examples/helpers/mail/Example.java index f40fac05..77c73eb2 100644 --- a/examples/helpers/mail/Example.java +++ b/examples/helpers/mail/Example.java @@ -207,6 +207,26 @@ public static Mail buildKitchenSink() throws IOException { return mail; } + // API V3 Dynamic Template implementation + public static Mail buildDynamicTemplate() throws IOException { + Mail mail = new Mail(); + + Email fromEmail = new Email(); + fromEmail.setName("Example User"); + fromEmail.setEmail("test@example.com"); + mail.setFrom(fromEmail); + + mail.setTemplateId("d-c6dcf1f72bdd4beeb15a9aa6c72fcd2c"); + + Personalization personalization = new Personalization(); + personalization.addDynamicTemplateData("name", "Example User"); + personalization.addDynamicTemplateData("city", "Denver"); + personalization.addTo(new Email("test@example.com")); + mail.addPersonalization(personalization); + + return mail; + } + // Minimum required to send an email public static Mail buildHelloEmail() throws IOException { Email from = new Email("test@example.com"); @@ -230,13 +250,13 @@ public static void baselineExample() throws IOException { Request request = new Request(); Mail helloWorld = buildHelloEmail(); try { - request.method = Method.POST; - request.endpoint = "mail/send"; - request.body = helloWorld.build(); + request.setMethod(Method.POST); + request.setEndpoint("mail/send"); + request.setBody(helloWorld.build()); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -249,20 +269,40 @@ public static void kitchenSinkExample() throws IOException { Request request = new Request(); Mail kitchenSink = buildKitchenSink(); try { - request.method = Method.POST; - request.endpoint = "mail/send"; - request.body = kitchenSink.build(); + request.setMethod(Method.POST); + request.setEndpoint("mail/send"); + request.setBody(kitchenSink.build()); + 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; + } + } + + public static void dynamicTemplateExample() throws IOException { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + sg.addRequestHeader("X-Mock", "true"); + + Request request = new Request(); + Mail dynamicTemplate = buildDynamicTemplate(); + try { + request.setMethod(Method.POST); + request.setEndpoint("mail/send"); + request.setBody(dynamicTemplate.build()); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } } public static void main(String[] args) throws IOException { - baselineExample(); - kitchenSinkExample(); + // baselineExample(); + // kitchenSinkExample(); + dynamicTemplateExample(); } } \ No newline at end of file diff --git a/examples/ips/AddToPool.java b/examples/ips/AddToPool.java new file mode 100644 index 00000000..01e6b16b --- /dev/null +++ b/examples/ips/AddToPool.java @@ -0,0 +1,32 @@ +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; + + +////////////////////////////////////////////////////////////////// +// Add an IP address to a pool +// POST /ips/pools/{pool_name}/ips + + +public class AddIPToPool { + 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.POST); + request.setEndpoint("ips/pools/{pool_name}/ips"); + request.setBody("{\"ip\":\"0.0.0.0\"}"); + 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/ips/AddToWarmup.java b/examples/ips/AddToWarmup.java new file mode 100644 index 00000000..89ebaad1 --- /dev/null +++ b/examples/ips/AddToWarmup.java @@ -0,0 +1,33 @@ +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; + + + +////////////////////////////////////////////////////////////////// +// Add an IP to warmup +// POST /ips/warmup + + +public class AddIPToWarmup { + 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.POST); + request.setEndpoint("ips/warmup"); + request.setBody("{\"ip\":\"0.0.0.0\"}"); + 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/ips/CreatePool.java b/examples/ips/CreatePool.java new file mode 100644 index 00000000..c91d82f0 --- /dev/null +++ b/examples/ips/CreatePool.java @@ -0,0 +1,32 @@ +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; + + +////////////////////////////////////////////////////////////////// +// Create an IP pool. +// POST /ips/pools + + +public class CreateIPPool { + 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.POST); + request.setEndpoint("ips/pools"); + request.setBody("{\"name\":\"marketing\"}"); + 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/ips/DeletePool.java b/examples/ips/DeletePool.java new file mode 100644 index 00000000..51c50249 --- /dev/null +++ b/examples/ips/DeletePool.java @@ -0,0 +1,31 @@ +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; + + +////////////////////////////////////////////////////////////////// +// Delete an IP pool. +// DELETE /ips/pools/{pool_name} + + +public class DeletePool { + 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.DELETE); + request.setEndpoint("ips/pools/{pool_name}"); + 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/ips/README.md b/examples/ips/README.md new file mode 100644 index 00000000..7ded4310 --- /dev/null +++ b/examples/ips/README.md @@ -0,0 +1,18 @@ +![SendGrid Logo](https://uiux.s3.amazonaws.com/2016-logos/email-logo%402x.png) + +This folder contains various examples on using the IPs endpoint of SendGrid with Java: + +* [Retrieve all IP addresses (GET /ips)](RetrieveAllIPs.java) +* [Retrieve all assigned IPs (GET /ips/assigned)](RetrieveAssignedIPs.java) +* [Create an IP pool (POST /ips/pools)](CreatePool.java) +* [Retrieve all IP pools (GET /ips/pools)](RetrieveAllPools.java) +* [Update an IP pools name (PUT /ips/pools/{pool_name})](UpdatePoolName.java) +* [Retrieve all IPs in a specified pool (GET /ips/pools/{pool_name})](RetrieveIPsInPool.java) +* [Delete an IP pool. (DELETE /ips/pools/{pool_name})](DeletePool.java) +* [Add an IP address to a pool (POST /ips/pools/{pool_name}/ips)](AddToPool.java) +* [Remove an IP address from a pool (DELETE /ips/pools/{pool_name}/ips/{ip}](RemoveFromPool.java) +* [Add an IP to warmup (POST /ips/warmup)](AddToWarmup.java) +* [Retrieve all IPs currently in warmup (GET /ips/warmup)](RetrieveIPsInWarmup.java) +* [Retrieve warmup status for a specific IP address (GET /ips/warmup/{ip_address})](RetrieveWarmupStatus.java) +* [Remove an IP from warmup (DELETE /ips/warmup/{ip_address})](RemoveFromWarmup.java) +* [Retrieve all IP pools an IP address belongs to (GET /ips/{ip_address})](RetrievePoolsForIP.java) \ No newline at end of file diff --git a/examples/ips/RemoveFromPool.java b/examples/ips/RemoveFromPool.java new file mode 100644 index 00000000..ceb5f2be --- /dev/null +++ b/examples/ips/RemoveFromPool.java @@ -0,0 +1,31 @@ +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; + + + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + + +////////////////////////////////////////////////////////////////// +// Remove an IP address from a pool. +// DELETE /ips/pools/{pool_name}/ips/{ip} + + +public class RemoveIPFromPool { + 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.DELETE); + request.setEndpoint("ips/pools/{pool_name}/ips/{ip}"); + 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/ips/RemoveFromWarmup.java b/examples/ips/RemoveFromWarmup.java new file mode 100644 index 00000000..b99229de --- /dev/null +++ b/examples/ips/RemoveFromWarmup.java @@ -0,0 +1,32 @@ +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; + + + +////////////////////////////////////////////////////////////////// +// Remove an IP from warmup +// DELETE /ips/warmup/{ip_address} + + +public class RemoveFromWarmup { + 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.DELETE); + request.setEndpoint("ips/warmup/{ip_address}"); + 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/ips/RetrieveAllIPs.java b/examples/ips/RetrieveAllIPs.java new file mode 100644 index 00000000..14845939 --- /dev/null +++ b/examples/ips/RetrieveAllIPs.java @@ -0,0 +1,34 @@ +import com.sendgrid.Method; +import com.sendgrid.Request; +import com.sendgrid.Response; +import com.sendgrid.SendGrid; + +import java.io.IOException; + + +////////////////////////////////////////////////////////////////// +// Retrieve all IP addresses +// GET /ips + + +public class RetrieveAllIPs { + 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("ips"); + request.addQueryParam("subuser", "test_string"); + request.addQueryParam("ip", "test_string"); + request.addQueryParam("limit", "1"); + request.addQueryParam("exclude_whitelabels", "true"); + 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; + } + } +} \ No newline at end of file diff --git a/examples/ips/RetrieveAllPools.java b/examples/ips/RetrieveAllPools.java new file mode 100644 index 00000000..a4362ce0 --- /dev/null +++ b/examples/ips/RetrieveAllPools.java @@ -0,0 +1,30 @@ +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 IP pools. +// GET /ips/pools + + +public class RetieveAllIPPools { + 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("ips/pools"); + 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/ips/RetrieveAssignedIPs.java b/examples/ips/RetrieveAssignedIPs.java new file mode 100644 index 00000000..968834cc --- /dev/null +++ b/examples/ips/RetrieveAssignedIPs.java @@ -0,0 +1,31 @@ +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 assigned IPs +// GET /ips/assigned + + +public class RetrieveAllAssignedIPs { + 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("ips/assigned"); + 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/ips/RetrieveIPsInPool.java b/examples/ips/RetrieveIPsInPool.java new file mode 100644 index 00000000..72330c3f --- /dev/null +++ b/examples/ips/RetrieveIPsInPool.java @@ -0,0 +1,31 @@ +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 IPs in a specified pool. +// GET /ips/pools/{pool_name} + + +public class RetrieveIPsInPool { + 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("ips/pools/{pool_name}"); + 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/ips/RetrieveIPsInWarmup.java b/examples/ips/RetrieveIPsInWarmup.java new file mode 100644 index 00000000..3767656b --- /dev/null +++ b/examples/ips/RetrieveIPsInWarmup.java @@ -0,0 +1,32 @@ +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 IPs currently in warmup +// GET /ips/warmup + + +public class RetrieveIPsInWarmup { + 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("ips/warmup"); + 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/ips/RetrievePoolsForIP.java b/examples/ips/RetrievePoolsForIP.java new file mode 100644 index 00000000..8f19b7a7 --- /dev/null +++ b/examples/ips/RetrievePoolsForIP.java @@ -0,0 +1,33 @@ +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 IP pools an IP address belongs to +// GET /ips/{ip_address} + + +public class RetrieveAllPoolsForIP { + 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("ips/{ip_address}"); + 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/ips/RetrieveWarmupStatus.java b/examples/ips/RetrieveWarmupStatus.java new file mode 100644 index 00000000..5d315b8f --- /dev/null +++ b/examples/ips/RetrieveWarmupStatus.java @@ -0,0 +1,32 @@ +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 warmup status for a specific IP address +// GET /ips/warmup/{ip_address} + + +public class RetrieveIPsWarmupStatus { + 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("ips/warmup/{ip_address}"); + 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/ips/UpdatePoolName.java b/examples/ips/UpdatePoolName.java new file mode 100644 index 00000000..4e9c2a26 --- /dev/null +++ b/examples/ips/UpdatePoolName.java @@ -0,0 +1,32 @@ +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; + + +////////////////////////////////////////////////////////////////// +// Update an IP pools name. +// PUT /ips/pools/{pool_name} + + +public class UpdateIPPoolName { + 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.PUT); + request.setEndpoint("ips/pools/{pool_name}"); + request.setBody("{\"name\":\"new_pool_name\"}"); + 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/ips/ips.java b/examples/ips/ips.java deleted file mode 100644 index b9dfdbef..00000000 --- a/examples/ips/ips.java +++ /dev/null @@ -1,328 +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 IP addresses -// GET /ips - - -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.method = Method.GET; - request.endpoint = "ips"; - Map queryParams = new HashMap(); - queryParams.put("subuser", "test_string"); - queryParams.put("ip", "test_string"); - queryParams.put("limit", "1"); - queryParams.put("exclude_whitelabels", "true"); - queryParams.put("offset", "1"); - request.queryParams = queryParams; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Retrieve all assigned IPs -// GET /ips/assigned - - -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.method = Method.GET; - request.endpoint = "ips/assigned"; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Create an IP pool. -// POST /ips/pools - - -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.method = Method.POST; - request.endpoint = "ips/pools"; - request.body = "{\"name\":\"marketing\"}"; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Retrieve all IP pools. -// GET /ips/pools - - -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.method = Method.GET; - request.endpoint = "ips/pools"; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Update an IP pools name. -// PUT /ips/pools/{pool_name} - - -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.method = Method.PUT; - request.endpoint = "ips/pools/{pool_name}"; - request.body = "{\"name\":\"new_pool_name\"}"; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Retrieve all IPs in a specified pool. -// GET /ips/pools/{pool_name} - - -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.method = Method.GET; - request.endpoint = "ips/pools/{pool_name}"; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Delete an IP pool. -// DELETE /ips/pools/{pool_name} - - -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.method = Method.DELETE; - request.endpoint = "ips/pools/{pool_name}"; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Add an IP address to a pool -// POST /ips/pools/{pool_name}/ips - - -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.method = Method.POST; - request.endpoint = "ips/pools/{pool_name}/ips"; - request.body = "{\"ip\":\"0.0.0.0\"}"; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Remove an IP address from a pool. -// DELETE /ips/pools/{pool_name}/ips/{ip} - - -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.method = Method.DELETE; - request.endpoint = "ips/pools/{pool_name}/ips/{ip}"; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Add an IP to warmup -// POST /ips/warmup - - -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.method = Method.POST; - request.endpoint = "ips/warmup"; - request.body = "{\"ip\":\"0.0.0.0\"}"; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Retrieve all IPs currently in warmup -// GET /ips/warmup - - -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.method = Method.GET; - request.endpoint = "ips/warmup"; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Retrieve warmup status for a specific IP address -// GET /ips/warmup/{ip_address} - - -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.method = Method.GET; - request.endpoint = "ips/warmup/{ip_address}"; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Remove an IP from warmup -// DELETE /ips/warmup/{ip_address} - - -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.method = Method.DELETE; - request.endpoint = "ips/warmup/{ip_address}"; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Retrieve all IP pools an IP address belongs to -// GET /ips/{ip_address} - - -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.method = Method.GET; - request.endpoint = "ips/{ip_address}"; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } catch (IOException ex) { - throw ex; - } - } -} - diff --git a/examples/mail/mail.java b/examples/mail/mail.java index bb856633..52df8be6 100644 --- a/examples/mail/mail.java +++ b/examples/mail/mail.java @@ -17,12 +17,12 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.POST; - request.endpoint = "mail/batch"; + request.setMethod(Method.POST); + request.setEndpoint("mail/batch"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -39,12 +39,12 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "mail/batch/{batch_id}"; + request.setMethod(Method.GET); + request.setEndpoint("mail/batch/{batch_id}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -62,13 +62,13 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.POST; - request.endpoint = "mail/send"; - request.body = "{\"custom_args\":{\"New Argument 1\":\"New Value 1\",\"activationAttempt\":\"1\",\"customerAccountNumber\":\"[CUSTOMER ACCOUNT NUMBER GOES HERE]\"},\"from\":{\"email\":\"sam.smith@example.com\",\"name\":\"Sam Smith\"},\"attachments\":[{\"name\":\"file1\",\"filename\":\"file1.jpg\",\"content\":\"[BASE64 encoded content block here]\",\"disposition\":\"inline\",\"content_id\":\"ii_139db99fdb5c3704\",\"type\":\"jpg\"}],\"personalizations\":[{\"to\":[{\"email\":\"john.doe@example.com\",\"name\":\"John Doe\"}],\"cc\":[{\"email\":\"jane.doe@example.com\",\"name\":\"Jane Doe\"}],\"bcc\":[{\"email\":\"sam.doe@example.com\",\"name\":\"Sam Doe\"}],\"custom_args\":{\"New Argument 1\":\"New Value 1\",\"activationAttempt\":\"1\",\"customerAccountNumber\":\"[CUSTOMER ACCOUNT NUMBER GOES HERE]\"},\"headers\":{\"X-Accept-Language\":\"en\",\"X-Mailer\":\"MyApp\"},\"send_at\":1409348513,\"substitutions\":{\"type\":\"object\",\"id\":\"substitutions\"},\"subject\":\"Hello, World!\"}],\"subject\":\"Hello, World!\",\"ip_pool_name\":\"[YOUR POOL NAME GOES HERE]\",\"content\":[{\"type\":\"text/html\",\"value\":\"

Hello, world!

\"}],\"headers\":{},\"asm\":{\"groups_to_display\":[1,2,3],\"group_id\":1},\"batch_id\":\"[YOUR BATCH ID GOES HERE]\",\"tracking_settings\":{\"subscription_tracking\":{\"text\":\"If you would like to unsubscribe and stop receiveing these emails <% click here %>.\",\"enable\":true,\"html\":\"If you would like to unsubscribe and stop receiving these emails <% clickhere %>.\",\"substitution_tag\":\"<%click here%>\"},\"open_tracking\":{\"enable\":true,\"substitution_tag\":\"%opentrack\"},\"click_tracking\":{\"enable\":true,\"enable_text\":true},\"ganalytics\":{\"utm_campaign\":\"[NAME OF YOUR REFERRER SOURCE]\",\"enable\":true,\"utm_name\":\"[NAME OF YOUR CAMPAIGN]\",\"utm_term\":\"[IDENTIFY PAID KEYWORDS HERE]\",\"utm_content\":\"[USE THIS SPACE TO DIFFERENTIATE YOUR EMAIL FROM ADS]\",\"utm_medium\":\"[NAME OF YOUR MARKETING MEDIUM e.g. email]\"}},\"mail_settings\":{\"footer\":{\"text\":\"Thanks,/n The SendGrid Team\",\"enable\":true,\"html\":\"

Thanks
The SendGrid Team

\"},\"spam_check\":{\"threshold\":3,\"post_to_url\":\"http://example.com/compliance\",\"enable\":true},\"bypass_list_management\":{\"enable\":true},\"sandbox_mode\":{\"enable\":false},\"bcc\":{\"enable\":true,\"email\":\"ben.doe@example.com\"}},\"reply_to\":{\"email\":\"sam.smith@example.com\",\"name\":\"Sam Smith\"},\"sections\":{\"section\":{\":sectionName2\":\"section 2 text\",\":sectionName1\":\"section 1 text\"}},\"template_id\":\"[YOUR TEMPLATE ID GOES HERE]\",\"categories\":[\"category1\",\"category2\"],\"send_at\":1409348513}"; + request.setMethod(Method.POST); + request.setEndpoint("mail/send"); + request.setBody("{\"custom_args\":{\"New Argument 1\":\"New Value 1\",\"activationAttempt\":\"1\",\"customerAccountNumber\":\"[CUSTOMER ACCOUNT NUMBER GOES HERE]\"},\"from\":{\"email\":\"sam.smith@example.com\",\"name\":\"Sam Smith\"},\"attachments\":[{\"name\":\"file1\",\"filename\":\"file1.jpg\",\"content\":\"[BASE64 encoded content block here]\",\"disposition\":\"inline\",\"content_id\":\"ii_139db99fdb5c3704\",\"type\":\"jpg\"}],\"personalizations\":[{\"to\":[{\"email\":\"john.doe@example.com\",\"name\":\"John Doe\"}],\"cc\":[{\"email\":\"jane.doe@example.com\",\"name\":\"Jane Doe\"}],\"bcc\":[{\"email\":\"sam.doe@example.com\",\"name\":\"Sam Doe\"}],\"custom_args\":{\"New Argument 1\":\"New Value 1\",\"activationAttempt\":\"1\",\"customerAccountNumber\":\"[CUSTOMER ACCOUNT NUMBER GOES HERE]\"},\"headers\":{\"X-Accept-Language\":\"en\",\"X-Mailer\":\"MyApp\"},\"send_at\":1409348513,\"substitutions\":{\"type\":\"object\",\"id\":\"substitutions\"},\"subject\":\"Hello, World!\"}],\"subject\":\"Hello, World!\",\"ip_pool_name\":\"[YOUR POOL NAME GOES HERE]\",\"content\":[{\"type\":\"text/html\",\"value\":\"

Hello, world!

\"}],\"headers\":{},\"asm\":{\"groups_to_display\":[1,2,3],\"group_id\":1},\"batch_id\":\"[YOUR BATCH ID GOES HERE]\",\"tracking_settings\":{\"subscription_tracking\":{\"text\":\"If you would like to unsubscribe and stop receiveing these emails <% click here %>.\",\"enable\":true,\"html\":\"If you would like to unsubscribe and stop receiving these emails <% clickhere %>.\",\"substitution_tag\":\"<%click here%>\"},\"open_tracking\":{\"enable\":true,\"substitution_tag\":\"%opentrack\"},\"click_tracking\":{\"enable\":true,\"enable_text\":true},\"ganalytics\":{\"utm_campaign\":\"[NAME OF YOUR REFERRER SOURCE]\",\"enable\":true,\"utm_name\":\"[NAME OF YOUR CAMPAIGN]\",\"utm_term\":\"[IDENTIFY PAID KEYWORDS HERE]\",\"utm_content\":\"[USE THIS SPACE TO DIFFERENTIATE YOUR EMAIL FROM ADS]\",\"utm_medium\":\"[NAME OF YOUR MARKETING MEDIUM e.g. email]\"}},\"mail_settings\":{\"footer\":{\"text\":\"Thanks,/n The SendGrid Team\",\"enable\":true,\"html\":\"

Thanks
The SendGrid Team

\"},\"spam_check\":{\"threshold\":3,\"post_to_url\":\"http://example.com/compliance\",\"enable\":true},\"bypass_list_management\":{\"enable\":true},\"sandbox_mode\":{\"enable\":false},\"bcc\":{\"enable\":true,\"email\":\"ben.doe@example.com\"}},\"reply_to\":{\"email\":\"sam.smith@example.com\",\"name\":\"Sam Smith\"},\"sections\":{\"section\":{\":sectionName2\":\"section 2 text\",\":sectionName1\":\"section 1 text\"}},\"template_id\":\"[YOUR TEMPLATE ID GOES HERE]\",\"categories\":[\"category1\",\"category2\"],\"send_at\":1409348513}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } diff --git a/examples/mailboxproviders/mailboxproviders.java b/examples/mailboxproviders/mailboxproviders.java index 6b412955..4e0c6a06 100644 --- a/examples/mailboxproviders/mailboxproviders.java +++ b/examples/mailboxproviders/mailboxproviders.java @@ -17,20 +17,18 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "mailbox_providers/stats"; - Map queryParams = new HashMap(); - queryParams.put("end_date", "2016-04-01"); - queryParams.put("mailbox_providers", "test_string"); - queryParams.put("aggregated_by", "day"); - queryParams.put("limit", "1"); - queryParams.put("offset", "1"); - queryParams.put("start_date", "2016-01-01"); - request.queryParams = queryParams; + request.setMethod(Method.GET); + request.setEndpoint("mailbox_providers/stats"); + request.addQueryParam("end_date", "2016-04-01"); + request.addQueryParam("mailbox_providers", "test_string"); + request.addQueryParam("aggregated_by", "day"); + request.addQueryParam("limit", "1"); + request.addQueryParam("offset", "1"); + request.addQueryParam("start_date", "2016-01-01"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + 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/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 b74b48bf..00000000 --- a/examples/mailsettings/mailsettings.java +++ /dev/null @@ -1,440 +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.method = Method.GET; - request.endpoint = "mail_settings"; - Map queryParams = new HashMap(); - queryParams.put("limit", "1"); - queryParams.put("offset", "1"); - request.queryParams = queryParams; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } 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.method = Method.PATCH; - request.endpoint = "mail_settings/address_whitelist"; - request.body = "{\"list\":[\"email1@example.com\",\"example.com\"],\"enabled\":true}"; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } 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.method = Method.GET; - request.endpoint = "mail_settings/address_whitelist"; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } 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.method = Method.PATCH; - request.endpoint = "mail_settings/bcc"; - request.body = "{\"enabled\":false,\"email\":\"email@example.com\"}"; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } 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.method = Method.GET; - request.endpoint = "mail_settings/bcc"; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } 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.method = Method.PATCH; - request.endpoint = "mail_settings/bounce_purge"; - request.body = "{\"hard_bounces\":5,\"soft_bounces\":5,\"enabled\":true}"; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } 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.method = Method.GET; - request.endpoint = "mail_settings/bounce_purge"; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } 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.method = Method.PATCH; - request.endpoint = "mail_settings/footer"; - request.body = "{\"html_content\":\"...\",\"enabled\":true,\"plain_content\":\"...\"}"; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } 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.method = Method.GET; - request.endpoint = "mail_settings/footer"; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } 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.method = Method.PATCH; - request.endpoint = "mail_settings/forward_bounce"; - request.body = "{\"enabled\":true,\"email\":\"example@example.com\"}"; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } 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.method = Method.GET; - request.endpoint = "mail_settings/forward_bounce"; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } 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.method = Method.PATCH; - request.endpoint = "mail_settings/forward_spam"; - request.body = "{\"enabled\":false,\"email\":\"\"}"; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } 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.method = Method.GET; - request.endpoint = "mail_settings/forward_spam"; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } 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.method = Method.PATCH; - request.endpoint = "mail_settings/plain_content"; - request.body = "{\"enabled\":false}"; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } 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.method = Method.GET; - request.endpoint = "mail_settings/plain_content"; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } 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.method = Method.PATCH; - request.endpoint = "mail_settings/spam_check"; - request.body = "{\"url\":\"url\",\"max_score\":5,\"enabled\":true}"; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } 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.method = Method.GET; - request.endpoint = "mail_settings/spam_check"; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } 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.method = Method.PATCH; - request.endpoint = "mail_settings/template"; - request.body = "{\"html_content\":\"<% body %>\",\"enabled\":true}"; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } 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.method = Method.GET; - request.endpoint = "mail_settings/template"; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } catch (IOException ex) { - throw ex; - } - } -} - diff --git a/examples/partnersettings/partnersettings.java b/examples/partnersettings/partnersettings.java index b63508a9..b4364bb9 100644 --- a/examples/partnersettings/partnersettings.java +++ b/examples/partnersettings/partnersettings.java @@ -17,16 +17,14 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "partner_settings"; - Map queryParams = new HashMap(); - queryParams.put("limit", "1"); - queryParams.put("offset", "1"); - request.queryParams = queryParams; + request.setMethod(Method.GET); + request.setEndpoint("partner_settings"); + request.addQueryParam("limit", "1"); + request.addQueryParam("offset", "1"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -43,13 +41,13 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.PATCH; - request.endpoint = "partner_settings/new_relic"; - request.body = "{\"enable_subuser_statistics\":true,\"enabled\":true,\"license_key\":\"\"}"; + request.setMethod(Method.PATCH); + request.setEndpoint("partner_settings/new_relic"); + request.setBody("{\"enable_subuser_statistics\":true,\"enabled\":true,\"license_key\":\"\"}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -66,12 +64,12 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "partner_settings/new_relic"; + request.setMethod(Method.GET); + request.setEndpoint("partner_settings/new_relic"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } diff --git a/examples/scopes/scopes.java b/examples/scopes/scopes.java index f892f6ad..69d2db5d 100644 --- a/examples/scopes/scopes.java +++ b/examples/scopes/scopes.java @@ -17,12 +17,12 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "scopes"; + request.setMethod(Method.GET); + request.setEndpoint("scopes"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } diff --git a/examples/senders/senders.java b/examples/senders/senders.java index f101b43f..d81630da 100644 --- a/examples/senders/senders.java +++ b/examples/senders/senders.java @@ -17,13 +17,13 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.POST; - request.endpoint = "senders"; - request.body = "{\"city\":\"Denver\",\"from\":{\"email\":\"from@example.com\",\"name\":\"Example INC\"},\"zip\":\"80202\",\"country\":\"United States\",\"state\":\"Colorado\",\"address_2\":\"Apt. 456\",\"address\":\"123 Elm St.\",\"reply_to\":{\"email\":\"replyto@example.com\",\"name\":\"Example INC\"},\"nickname\":\"My Sender ID\"}"; + request.setMethod(Method.POST); + request.setEndpoint("senders"); + request.setBody("{\"city\":\"Denver\",\"from\":{\"email\":\"from@example.com\",\"name\":\"Example INC\"},\"zip\":\"80202\",\"country\":\"United States\",\"state\":\"Colorado\",\"address_2\":\"Apt. 456\",\"address\":\"123 Elm St.\",\"reply_to\":{\"email\":\"replyto@example.com\",\"name\":\"Example INC\"},\"nickname\":\"My Sender ID\"}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -40,12 +40,12 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "senders"; + request.setMethod(Method.GET); + request.setEndpoint("senders"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -62,13 +62,13 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.PATCH; - request.endpoint = "senders/{sender_id}"; - request.body = "{\"city\":\"Denver\",\"from\":{\"email\":\"from@example.com\",\"name\":\"Example INC\"},\"zip\":\"80202\",\"country\":\"United States\",\"state\":\"Colorado\",\"address_2\":\"Apt. 456\",\"address\":\"123 Elm St.\",\"reply_to\":{\"email\":\"replyto@example.com\",\"name\":\"Example INC\"},\"nickname\":\"My Sender ID\"}"; + request.setMethod(Method.PATCH); + request.setEndpoint("senders/{sender_id}"); + request.setBody("{\"city\":\"Denver\",\"from\":{\"email\":\"from@example.com\",\"name\":\"Example INC\"},\"zip\":\"80202\",\"country\":\"United States\",\"state\":\"Colorado\",\"address_2\":\"Apt. 456\",\"address\":\"123 Elm St.\",\"reply_to\":{\"email\":\"replyto@example.com\",\"name\":\"Example INC\"},\"nickname\":\"My Sender ID\"}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -85,12 +85,12 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "senders/{sender_id}"; + request.setMethod(Method.GET); + request.setEndpoint("senders/{sender_id}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -107,12 +107,12 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.DELETE; - request.endpoint = "senders/{sender_id}"; + request.setMethod(Method.DELETE); + request.setEndpoint("senders/{sender_id}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -129,12 +129,12 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.POST; - request.endpoint = "senders/{sender_id}/resend_verification"; + request.setMethod(Method.POST); + request.setEndpoint("senders/{sender_id}/resend_verification"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } diff --git a/examples/stats/stats.java b/examples/stats/stats.java index cc108212..1dbe5c25 100644 --- a/examples/stats/stats.java +++ b/examples/stats/stats.java @@ -17,19 +17,17 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "stats"; - Map queryParams = new HashMap(); - queryParams.put("aggregated_by", "day"); - queryParams.put("limit", "1"); - queryParams.put("start_date", "2016-01-01"); - queryParams.put("end_date", "2016-04-01"); - queryParams.put("offset", "1"); - request.queryParams = queryParams; + request.setMethod(Method.GET); + request.setEndpoint("stats"); + request.addQueryParam("aggregated_by", "day"); + request.addQueryParam("limit", "1"); + request.addQueryParam("start_date", "2016-01-01"); + request.addQueryParam("end_date", "2016-04-01"); + request.addQueryParam("offset", "1"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } diff --git a/examples/subusers/CreateMonitorSettings.java b/examples/subusers/CreateMonitorSettings.java new file mode 100644 index 00000000..6fecfaff --- /dev/null +++ b/examples/subusers/CreateMonitorSettings.java @@ -0,0 +1,31 @@ +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; + +////////////////////////////////////////////////////////////////// +// Create monitor settings +// POST /subusers/{subuser_name}/monitor + + +public class CreateMonitorSettings { + 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.POST); + request.setEndpoint("subusers/{subuser_name}/monitor"); + request.setBody("{\"frequency\":50000,\"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/subusers/CreateSubUser.java b/examples/subusers/CreateSubUser.java new file mode 100644 index 00000000..9cb283c8 --- /dev/null +++ b/examples/subusers/CreateSubUser.java @@ -0,0 +1,31 @@ +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; + +////////////////////////////////////////////////////////////////// +// Create Subuser +// POST /subusers + + +public class CreateSubUser { + 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.POST); + request.setEndpoint("subusers"); + request.setBody("{\"username\":\"John@example.com\",\"ips\":[\"1.1.1.1\",\"2.2.2.2\"],\"password\":\"johns_password\",\"email\":\"John@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/subusers/DeleteMonitorSettings.java b/examples/subusers/DeleteMonitorSettings.java new file mode 100644 index 00000000..ffcc25c8 --- /dev/null +++ b/examples/subusers/DeleteMonitorSettings.java @@ -0,0 +1,31 @@ +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; + + +////////////////////////////////////////////////////////////////// +// Delete monitor settings +// DELETE /subusers/{subuser_name}/monitor + + +public class DeleteMonitorSettings { + 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.DELETE); + request.setEndpoint("subusers/{subuser_name}/monitor"); + 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/subusers/DeleteSubUser.java b/examples/subusers/DeleteSubUser.java new file mode 100644 index 00000000..68207edf --- /dev/null +++ b/examples/subusers/DeleteSubUser.java @@ -0,0 +1,30 @@ +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; + +////////////////////////////////////////////////////////////////// +// Delete a subuser +// DELETE /subusers/{subuser_name} + + +public class DeleteSubUser { + 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.DELETE); + request.setEndpoint("subusers/{subuser_name}"); + 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/subusers/EnableOrDisableUser.java b/examples/subusers/EnableOrDisableUser.java new file mode 100644 index 00000000..107b7def --- /dev/null +++ b/examples/subusers/EnableOrDisableUser.java @@ -0,0 +1,31 @@ +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; + +////////////////////////////////////////////////////////////////// +// Enable/disable a subuser +// PATCH /subusers/{subuser_name} + + +public class EnableOrDisableUser { + 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("subusers/{subuser_name}"); + request.setBody("{\"disabled\":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/subusers/ListAllSubUsers.java b/examples/subusers/ListAllSubUsers.java new file mode 100644 index 00000000..ebc408f3 --- /dev/null +++ b/examples/subusers/ListAllSubUsers.java @@ -0,0 +1,32 @@ +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; + +////////////////////////////////////////////////////////////////// +// List all Subusers +// GET /subusers + +public class ListAllSubUsers { + 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("subusers"); + request.addQueryParam("username", "test_string"); + 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; + } + } +} \ No newline at end of file diff --git a/examples/subusers/RetrieveEmailStatistics.java b/examples/subusers/RetrieveEmailStatistics.java new file mode 100644 index 00000000..479f4f2e --- /dev/null +++ b/examples/subusers/RetrieveEmailStatistics.java @@ -0,0 +1,37 @@ +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 email statistics for your subusers. +// GET /subusers/stats + + +public class RetrieveEmailStatistics { + 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("subusers/stats"); + request.addQueryParam("end_date", "2016-04-01"); + request.addQueryParam("aggregated_by", "day"); + request.addQueryParam("limit", "1"); + request.addQueryParam("offset", "1"); + request.addQueryParam("start_date", "2016-01-01"); + request.addQueryParam("subusers", "test_string"); + 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/subusers/RetrieveMonitorSettings.java b/examples/subusers/RetrieveMonitorSettings.java new file mode 100644 index 00000000..6d219e2f --- /dev/null +++ b/examples/subusers/RetrieveMonitorSettings.java @@ -0,0 +1,31 @@ +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 monitor settings for a subuser +// GET /subusers/{subuser_name}/monitor + + +public class RetrieveMonitorSettings { + 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("subusers/{subuser_name}/monitor"); + 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/subusers/RetrieveMonthlyEmailStatistics.java b/examples/subusers/RetrieveMonthlyEmailStatistics.java new file mode 100644 index 00000000..b7d1c9b2 --- /dev/null +++ b/examples/subusers/RetrieveMonthlyEmailStatistics.java @@ -0,0 +1,36 @@ +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 the monthly email statistics for a single subuser +// GET /subusers/{subuser_name}/stats/monthly + + +public class RetrieveMonthlyEmailStatistics { + 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("subusers/{subuser_name}/stats/monthly"); + request.addQueryParam("date", "test_string"); + request.addQueryParam("sort_by_direction", "asc"); + request.addQueryParam("limit", "1"); + request.addQueryParam("sort_by_metric", "test_string"); + 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; + } + } +} \ No newline at end of file diff --git a/examples/subusers/RetrieveMonthlyStats.java b/examples/subusers/RetrieveMonthlyStats.java new file mode 100644 index 00000000..7310c072 --- /dev/null +++ b/examples/subusers/RetrieveMonthlyStats.java @@ -0,0 +1,36 @@ +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 monthly stats for all subusers +// GET /subusers/stats/monthly + + +public class RetrieveMonthlyStats { + 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("subusers/stats/monthly"); + request.addQueryParam("subuser", "test_string"); + request.addQueryParam("limit", "1"); + request.addQueryParam("sort_by_metric", "test_string"); + request.addQueryParam("offset", "1"); + request.addQueryParam("date", "test_string"); + request.addQueryParam("sort_by_direction", "asc"); + 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/subusers/RetrieveSubUserReputation.java b/examples/subusers/RetrieveSubUserReputation.java new file mode 100644 index 00000000..18664ed2 --- /dev/null +++ b/examples/subusers/RetrieveSubUserReputation.java @@ -0,0 +1,32 @@ +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 Subuser Reputations +// GET /subusers/reputations + + +public class RetrieveSubUserReputation { + 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("subusers/reputations"); + request.addQueryParam("usernames", "test_string"); + 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/subusers/RetrieveTotalsForEachEmail.java b/examples/subusers/RetrieveTotalsForEachEmail.java new file mode 100644 index 00000000..de741967 --- /dev/null +++ b/examples/subusers/RetrieveTotalsForEachEmail.java @@ -0,0 +1,37 @@ +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 the totals for each email statistic metric for all subusers. +// GET /subusers/stats/sums + + +public class RetrieveTotalsForEachEmail { + 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("subusers/stats/sums"); + request.addQueryParam("end_date", "2016-04-01"); + request.addQueryParam("aggregated_by", "day"); + request.addQueryParam("limit", "1"); + request.addQueryParam("sort_by_metric", "test_string"); + request.addQueryParam("offset", "1"); + request.addQueryParam("start_date", "2016-01-01"); + request.addQueryParam("sort_by_direction", "asc"); + 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/subusers/UpdateAssignedIPs.java b/examples/subusers/UpdateAssignedIPs.java new file mode 100644 index 00000000..60479769 --- /dev/null +++ b/examples/subusers/UpdateAssignedIPs.java @@ -0,0 +1,31 @@ +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; + +////////////////////////////////////////////////////////////////// +// Update IPs assigned to a subuser +// PUT /subusers/{subuser_name}/ips + + +public class UpdateAssignedIps { + 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.PUT); + request.setEndpoint("subusers/{subuser_name}/ips"); + request.setBody("[\"127.0.0.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; + } + } +} \ No newline at end of file diff --git a/examples/subusers/UpdateMonitorSettings.java b/examples/subusers/UpdateMonitorSettings.java new file mode 100644 index 00000000..81567982 --- /dev/null +++ b/examples/subusers/UpdateMonitorSettings.java @@ -0,0 +1,31 @@ +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; + +////////////////////////////////////////////////////////////////// +// Update Monitor Settings for a subuser +// PUT /subusers/{subuser_name}/monitor + + +public class UpdateMonitorSetting { + 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.PUT); + request.setEndpoint("subusers/{subuser_name}/monitor"); + request.setBody("{\"frequency\":500,\"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/subusers/subusers.java b/examples/subusers/subusers.java deleted file mode 100644 index 6a9500be..00000000 --- a/examples/subusers/subusers.java +++ /dev/null @@ -1,362 +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; - -////////////////////////////////////////////////////////////////// -// Create Subuser -// POST /subusers - - -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.method = Method.POST; - request.endpoint = "subusers"; - request.body = "{\"username\":\"John@example.com\",\"ips\":[\"1.1.1.1\",\"2.2.2.2\"],\"password\":\"johns_password\",\"email\":\"John@example.com\"}"; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// List all Subusers -// GET /subusers - - -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.method = Method.GET; - request.endpoint = "subusers"; - Map queryParams = new HashMap(); - queryParams.put("username", "test_string"); - queryParams.put("limit", "1"); - queryParams.put("offset", "1"); - request.queryParams = queryParams; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Retrieve Subuser Reputations -// GET /subusers/reputations - - -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.method = Method.GET; - request.endpoint = "subusers/reputations"; - Map queryParams = new HashMap(); - queryParams.put("usernames", "test_string"); - request.queryParams = queryParams; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Retrieve email statistics for your subusers. -// GET /subusers/stats - - -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.method = Method.GET; - request.endpoint = "subusers/stats"; - Map queryParams = new HashMap(); - queryParams.put("end_date", "2016-04-01"); - queryParams.put("aggregated_by", "day"); - queryParams.put("limit", "1"); - queryParams.put("offset", "1"); - queryParams.put("start_date", "2016-01-01"); - queryParams.put("subusers", "test_string"); - request.queryParams = queryParams; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Retrieve monthly stats for all subusers -// GET /subusers/stats/monthly - - -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.method = Method.GET; - request.endpoint = "subusers/stats/monthly"; - Map queryParams = new HashMap(); - queryParams.put("subuser", "test_string"); - queryParams.put("limit", "1"); - queryParams.put("sort_by_metric", "test_string"); - queryParams.put("offset", "1"); - queryParams.put("date", "test_string"); - queryParams.put("sort_by_direction", "asc"); - request.queryParams = queryParams; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Retrieve the totals for each email statistic metric for all subusers. -// GET /subusers/stats/sums - - -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.method = Method.GET; - request.endpoint = "subusers/stats/sums"; - Map queryParams = new HashMap(); - queryParams.put("end_date", "2016-04-01"); - queryParams.put("aggregated_by", "day"); - queryParams.put("limit", "1"); - queryParams.put("sort_by_metric", "test_string"); - queryParams.put("offset", "1"); - queryParams.put("start_date", "2016-01-01"); - queryParams.put("sort_by_direction", "asc"); - request.queryParams = queryParams; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Enable/disable a subuser -// PATCH /subusers/{subuser_name} - - -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.method = Method.PATCH; - request.endpoint = "subusers/{subuser_name}"; - request.body = "{\"disabled\":false}"; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Delete a subuser -// DELETE /subusers/{subuser_name} - - -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.method = Method.DELETE; - request.endpoint = "subusers/{subuser_name}"; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Update IPs assigned to a subuser -// PUT /subusers/{subuser_name}/ips - - -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.method = Method.PUT; - request.endpoint = "subusers/{subuser_name}/ips"; - request.body = "[\"127.0.0.1\"]"; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Update Monitor Settings for a subuser -// PUT /subusers/{subuser_name}/monitor - - -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.method = Method.PUT; - request.endpoint = "subusers/{subuser_name}/monitor"; - request.body = "{\"frequency\":500,\"email\":\"example@example.com\"}"; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Create monitor settings -// POST /subusers/{subuser_name}/monitor - - -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.method = Method.POST; - request.endpoint = "subusers/{subuser_name}/monitor"; - request.body = "{\"frequency\":50000,\"email\":\"example@example.com\"}"; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Retrieve monitor settings for a subuser -// GET /subusers/{subuser_name}/monitor - - -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.method = Method.GET; - request.endpoint = "subusers/{subuser_name}/monitor"; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Delete monitor settings -// DELETE /subusers/{subuser_name}/monitor - - -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.method = Method.DELETE; - request.endpoint = "subusers/{subuser_name}/monitor"; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Retrieve the monthly email statistics for a single subuser -// GET /subusers/{subuser_name}/stats/monthly - - -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.method = Method.GET; - request.endpoint = "subusers/{subuser_name}/stats/monthly"; - Map queryParams = new HashMap(); - queryParams.put("date", "test_string"); - queryParams.put("sort_by_direction", "asc"); - queryParams.put("limit", "1"); - queryParams.put("sort_by_metric", "test_string"); - queryParams.put("offset", "1"); - request.queryParams = queryParams; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } catch (IOException ex) { - throw ex; - } - } -} - diff --git a/examples/suppression/DeleteBlocks.java b/examples/suppression/DeleteBlocks.java new file mode 100644 index 00000000..484ddc67 --- /dev/null +++ b/examples/suppression/DeleteBlocks.java @@ -0,0 +1,30 @@ +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; + +////////////////////////////////////////////////////////////////// +// Delete blocks +// DELETE /suppression/blocks + +public class DeleteBlocks { + 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.DELETE); + request.setEndpoint("suppression/blocks"); + request.setBody("{\"emails\":[\"example1@example.com\",\"example2@example.com\"],\"delete_all\":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/suppression/DeleteBounce.java b/examples/suppression/DeleteBounce.java new file mode 100644 index 00000000..a8a9270d --- /dev/null +++ b/examples/suppression/DeleteBounce.java @@ -0,0 +1,30 @@ +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; + +////////////////////////////////////////////////////////////////// +// Delete a bounce +// DELETE /suppression/bounces/{email} + +public class DeleteBounce { + 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.DELETE); + request.setEndpoint("suppression/bounces/{email}"); + request.addQueryParam("email_address", "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/suppression/DeleteBounces.java b/examples/suppression/DeleteBounces.java new file mode 100644 index 00000000..ec286aec --- /dev/null +++ b/examples/suppression/DeleteBounces.java @@ -0,0 +1,30 @@ +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; + +////////////////////////////////////////////////////////////////// +// Delete bounces +// DELETE /suppression/bounces + +public class DeleteBounces { + 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.DELETE); + request.setEndpoint("suppression/bounces"); + request.setBody("{\"emails\":[\"example@example.com\",\"example2@example.com\"],\"delete_all\":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/suppression/DeleteInvalidEmails.java b/examples/suppression/DeleteInvalidEmails.java new file mode 100644 index 00000000..56e3e25e --- /dev/null +++ b/examples/suppression/DeleteInvalidEmails.java @@ -0,0 +1,30 @@ +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; + +////////////////////////////////////////////////////////////////// +// Delete invalid emails +// DELETE /suppression/invalid_emails + +public class DeleteInvalidEmails { + 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.DELETE); + request.setEndpoint("suppression/invalid_emails"); + request.setBody("{\"emails\":[\"example1@example.com\",\"example2@example.com\"],\"delete_all\":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/suppression/DeleteSpamReports.java b/examples/suppression/DeleteSpamReports.java new file mode 100644 index 00000000..c4adb4b3 --- /dev/null +++ b/examples/suppression/DeleteSpamReports.java @@ -0,0 +1,30 @@ +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; + +////////////////////////////////////////////////////////////////// +// Delete spam reports +// DELETE /suppression/spam_reports + +public class DeleteSpamReports { + 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.DELETE); + request.setEndpoint("suppression/spam_reports"); + request.setBody("{\"emails\":[\"example1@example.com\",\"example2@example.com\"],\"delete_all\":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/suppression/DeleteSpecificBlock.java b/examples/suppression/DeleteSpecificBlock.java new file mode 100644 index 00000000..4e252c3f --- /dev/null +++ b/examples/suppression/DeleteSpecificBlock.java @@ -0,0 +1,29 @@ +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; + +////////////////////////////////////////////////////////////////// +// Delete a specific block +// DELETE /suppression/blocks/{email} + +public class DeleteSpecificBlock { + 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.DELETE); + request.setEndpoint("suppression/blocks/{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/suppression/DeleteSpecificInvalidEmail.java b/examples/suppression/DeleteSpecificInvalidEmail.java new file mode 100644 index 00000000..03def455 --- /dev/null +++ b/examples/suppression/DeleteSpecificInvalidEmail.java @@ -0,0 +1,29 @@ +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; + +////////////////////////////////////////////////////////////////// +// Delete a specific invalid email +// DELETE /suppression/invalid_emails/{email} + +public class DeleteSpecificInvalidEmail { + 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.DELETE); + request.setEndpoint("suppression/invalid_emails/{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/suppression/DeleteSpecificSpamReport.java b/examples/suppression/DeleteSpecificSpamReport.java new file mode 100644 index 00000000..fcad75bf --- /dev/null +++ b/examples/suppression/DeleteSpecificSpamReport.java @@ -0,0 +1,29 @@ +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; + +////////////////////////////////////////////////////////////////// +// Delete a specific spam report +// DELETE /suppression/spam_report/{email} + +public class DeleteSpecificSpamReport { + 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.DELETE); + request.setEndpoint("suppression/spam_report/{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/suppression/GetAllBlocks.java b/examples/suppression/GetAllBlocks.java new file mode 100644 index 00000000..c653c9be --- /dev/null +++ b/examples/suppression/GetAllBlocks.java @@ -0,0 +1,33 @@ +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 blocks +// GET /suppression/blocks + +public class GetAllBlocks { + 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("suppression/blocks"); + request.addQueryParam("start_time", "1"); + request.addQueryParam("limit", "1"); + request.addQueryParam("end_time", "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; + } + } +} \ No newline at end of file diff --git a/examples/suppression/GetAllBounces.java b/examples/suppression/GetAllBounces.java new file mode 100644 index 00000000..6c98010d --- /dev/null +++ b/examples/suppression/GetAllBounces.java @@ -0,0 +1,31 @@ +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 bounces +// GET /suppression/bounces + +public class GetAllBounces { + 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("suppression/bounces"); + request.addQueryParam("start_time", "1"); + request.addQueryParam("end_time", "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; + } + } +} \ No newline at end of file diff --git a/examples/suppression/GetAllGlobalSuppressions.java b/examples/suppression/GetAllGlobalSuppressions.java new file mode 100644 index 00000000..f714b2c9 --- /dev/null +++ b/examples/suppression/GetAllGlobalSuppressions.java @@ -0,0 +1,33 @@ +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 global suppressions +// GET /suppression/unsubscribes + +public class GetAllGlobalSuppressions { + 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("suppression/unsubscribes"); + request.addQueryParam("start_time", "1"); + request.addQueryParam("limit", "1"); + request.addQueryParam("end_time", "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; + } + } +} \ No newline at end of file diff --git a/examples/suppression/GetAllInvalidEmails.java b/examples/suppression/GetAllInvalidEmails.java new file mode 100644 index 00000000..d2b2028b --- /dev/null +++ b/examples/suppression/GetAllInvalidEmails.java @@ -0,0 +1,33 @@ +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 invalid emails +// GET /suppression/invalid_emails + +public class GetAllInvalidEmails { + 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("suppression/invalid_emails"); + request.addQueryParam("start_time", "1"); + request.addQueryParam("limit", "1"); + request.addQueryParam("end_time", "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; + } + } +} \ No newline at end of file diff --git a/examples/suppression/GetAllSpamReports.java b/examples/suppression/GetAllSpamReports.java new file mode 100644 index 00000000..03795c45 --- /dev/null +++ b/examples/suppression/GetAllSpamReports.java @@ -0,0 +1,33 @@ +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 spam reports +// GET /suppression/spam_reports + +public class GetAllSpamReports { + 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("suppression/spam_reports"); + request.addQueryParam("start_time", "1"); + request.addQueryParam("limit", "1"); + request.addQueryParam("end_time", "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; + } + } +} \ No newline at end of file diff --git a/examples/suppression/GetBounce.java b/examples/suppression/GetBounce.java new file mode 100644 index 00000000..fe3259f5 --- /dev/null +++ b/examples/suppression/GetBounce.java @@ -0,0 +1,29 @@ +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 a Bounce +// GET /suppression/bounces/{email} + +public class GetBounce { + 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("suppression/bounces/{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/suppression/GetSpecificBlock.java b/examples/suppression/GetSpecificBlock.java new file mode 100644 index 00000000..1c9b8dee --- /dev/null +++ b/examples/suppression/GetSpecificBlock.java @@ -0,0 +1,29 @@ +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 a specific block +// GET /suppression/blocks/{email} + +public class GetSpecificBlock { + 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("suppression/blocks/{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/suppression/GetSpecificInvalidEmail.java b/examples/suppression/GetSpecificInvalidEmail.java new file mode 100644 index 00000000..54f8f8a4 --- /dev/null +++ b/examples/suppression/GetSpecificInvalidEmail.java @@ -0,0 +1,29 @@ +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 a specific invalid email +// GET /suppression/invalid_emails/{email} + +public class GetSpecificInvalidEmail { + 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("suppression/invalid_emails/{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/suppression/GetSpecificSpamReport.java b/examples/suppression/GetSpecificSpamReport.java new file mode 100644 index 00000000..bd5d3826 --- /dev/null +++ b/examples/suppression/GetSpecificSpamReport.java @@ -0,0 +1,29 @@ +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 a specific spam report +// GET /suppression/spam_report/{email} + +public class GetSpecificSpamReport { + 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("suppression/spam_report/{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/suppression/README.md b/examples/suppression/README.md new file mode 100644 index 00000000..ca686a4b --- /dev/null +++ b/examples/suppression/README.md @@ -0,0 +1,21 @@ +![SendGrid Logo](https://uiux.s3.amazonaws.com/2016-logos/email-logo%402x.png) + +This folder contains various examples on using the SUPPRESSION endpoint of SendGrid with Java: + +* [Retrieve all blocks (GET /suppression/blocks)](GetAllBlocks.java) +* [Delete blocks (DELETE /suppression/blocks)](DeleteBlocks.java) +* [Retrieve a specific block (GET /suppression/blocks/{email})](GetSpecificBlock.java) +* [Delete a specific block (DELETE /suppression/blocks/{email})](DeleteSpecificBlock.java) +* [Retrieve all bounces (GET /suppression/bounces)](GetAllBounces.java) +* [Delete bounces (DELETE /suppression/bounces)](DeleteBounces.java) +* [Retrieve a Bounce (GET /suppression/bounces/{email})](GetBounce.java) +* [Delete a bounce (DELETE /suppression/bounces/{email})](DeleteBounce.java) +* [Retrieve all invalid emails (GET /suppression/invalid_emails)](GetAllInvalidEmails.java) +* [Delete invalid emails (DELETE /suppression/invalid_emails)](DeleteInvalidEmails.java) +* [Retrieve a specific invalid email (GET /suppression/invalid_emails/{email})](GetSpecificInvalidEmail.java) +* [Delete a specific invalid email (DELETE /suppression/invalid_emails/{email})](DeleteSpecificInvalidEmail.java) +* [Retrieve a specific spam report (GET /suppression/spam_report/{email})](GetSpecificSpamReport.java) +* [Delete a specific spam report (DELETE /suppression/spam_report/{email})](DeleteSpecificSpamReport.java) +* [Retrieve all spam reports (GET /suppression/spam_reports)](GetAllSpamReports.java) +* [Delete spam reports (DELETE /suppression/spam_reports)](DeleteSpamReports.java) +* [Retrieve all global suppressions (GET /suppression/unsubscribes)](GetAllGlobalSuppressions.java) \ No newline at end of file diff --git a/examples/suppression/suppression.java b/examples/suppression/suppression.java deleted file mode 100644 index c5dbeaaa..00000000 --- a/examples/suppression/suppression.java +++ /dev/null @@ -1,418 +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 blocks -// GET /suppression/blocks - - -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.method = Method.GET; - request.endpoint = "suppression/blocks"; - Map queryParams = new HashMap(); - queryParams.put("start_time", "1"); - queryParams.put("limit", "1"); - queryParams.put("end_time", "1"); - queryParams.put("offset", "1"); - request.queryParams = queryParams; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Delete blocks -// DELETE /suppression/blocks - - -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.method = Method.DELETE; - request.endpoint = "suppression/blocks"; - request.body = "{\"emails\":[\"example1@example.com\",\"example2@example.com\"],\"delete_all\":false}"; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Retrieve a specific block -// GET /suppression/blocks/{email} - - -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.method = Method.GET; - request.endpoint = "suppression/blocks/{email}"; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Delete a specific block -// DELETE /suppression/blocks/{email} - - -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.method = Method.DELETE; - request.endpoint = "suppression/blocks/{email}"; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Retrieve all bounces -// GET /suppression/bounces - - -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.method = Method.GET; - request.endpoint = "suppression/bounces"; - Map queryParams = new HashMap(); - queryParams.put("start_time", "1"); - queryParams.put("end_time", "1"); - request.queryParams = queryParams; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Delete bounces -// DELETE /suppression/bounces - - -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.method = Method.DELETE; - request.endpoint = "suppression/bounces"; - request.body = "{\"emails\":[\"example@example.com\",\"example2@example.com\"],\"delete_all\":true}"; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Retrieve a Bounce -// GET /suppression/bounces/{email} - - -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.method = Method.GET; - request.endpoint = "suppression/bounces/{email}"; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Delete a bounce -// DELETE /suppression/bounces/{email} - - -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.method = Method.DELETE; - request.endpoint = "suppression/bounces/{email}"; - Map queryParams = new HashMap(); - queryParams.put("email_address", "example@example.com"); - request.queryParams = queryParams; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Retrieve all invalid emails -// GET /suppression/invalid_emails - - -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.method = Method.GET; - request.endpoint = "suppression/invalid_emails"; - Map queryParams = new HashMap(); - queryParams.put("start_time", "1"); - queryParams.put("limit", "1"); - queryParams.put("end_time", "1"); - queryParams.put("offset", "1"); - request.queryParams = queryParams; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Delete invalid emails -// DELETE /suppression/invalid_emails - - -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.method = Method.DELETE; - request.endpoint = "suppression/invalid_emails"; - request.body = "{\"emails\":[\"example1@example.com\",\"example2@example.com\"],\"delete_all\":false}"; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Retrieve a specific invalid email -// GET /suppression/invalid_emails/{email} - - -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.method = Method.GET; - request.endpoint = "suppression/invalid_emails/{email}"; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Delete a specific invalid email -// DELETE /suppression/invalid_emails/{email} - - -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.method = Method.DELETE; - request.endpoint = "suppression/invalid_emails/{email}"; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Retrieve a specific spam report -// GET /suppression/spam_report/{email} - - -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.method = Method.GET; - request.endpoint = "suppression/spam_report/{email}"; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Delete a specific spam report -// DELETE /suppression/spam_report/{email} - - -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.method = Method.DELETE; - request.endpoint = "suppression/spam_report/{email}"; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Retrieve all spam reports -// GET /suppression/spam_reports - - -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.method = Method.GET; - request.endpoint = "suppression/spam_reports"; - Map queryParams = new HashMap(); - queryParams.put("start_time", "1"); - queryParams.put("limit", "1"); - queryParams.put("end_time", "1"); - queryParams.put("offset", "1"); - request.queryParams = queryParams; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Delete spam reports -// DELETE /suppression/spam_reports - - -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.method = Method.DELETE; - request.endpoint = "suppression/spam_reports"; - request.body = "{\"emails\":[\"example1@example.com\",\"example2@example.com\"],\"delete_all\":false}"; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Retrieve all global suppressions -// GET /suppression/unsubscribes - - -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.method = Method.GET; - request.endpoint = "suppression/unsubscribes"; - Map queryParams = new HashMap(); - queryParams.put("start_time", "1"); - queryParams.put("limit", "1"); - queryParams.put("end_time", "1"); - queryParams.put("offset", "1"); - request.queryParams = queryParams; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } catch (IOException ex) { - throw ex; - } - } -} - diff --git a/examples/templates/templates.java b/examples/templates/templates.java index c5ff8879..a16c4bed 100644 --- a/examples/templates/templates.java +++ b/examples/templates/templates.java @@ -17,13 +17,13 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.POST; - request.endpoint = "templates"; - request.body = "{\"name\":\"example_name\"}"; + request.setMethod(Method.POST); + request.setEndpoint("templates"); + request.setBody("{\"name\":\"example_name\"}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -40,12 +40,12 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "templates"; + request.setMethod(Method.GET); + request.setEndpoint("templates"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -62,13 +62,13 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.PATCH; - request.endpoint = "templates/{template_id}"; - request.body = "{\"name\":\"new_example_name\"}"; + request.setMethod(Method.PATCH); + request.setEndpoint("templates/{template_id}"); + request.setBody("{\"name\":\"new_example_name\"}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -85,12 +85,12 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "templates/{template_id}"; + request.setMethod(Method.GET); + request.setEndpoint("templates/{template_id}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -107,12 +107,12 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.DELETE; - request.endpoint = "templates/{template_id}"; + request.setMethod(Method.DELETE); + request.setEndpoint("templates/{template_id}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -129,13 +129,13 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.POST; - request.endpoint = "templates/{template_id}/versions"; - request.body = "{\"name\":\"example_version_name\",\"html_content\":\"<%body%>\",\"plain_content\":\"<%body%>\",\"active\":1,\"template_id\":\"ddb96bbc-9b92-425e-8979-99464621b543\",\"subject\":\"<%subject%>\"}"; + request.setMethod(Method.POST); + request.setEndpoint("templates/{template_id}/versions"); + request.setBody("{\"name\":\"example_version_name\",\"html_content\":\"<%body%>\",\"plain_content\":\"<%body%>\",\"active\":1,\"template_id\":\"ddb96bbc-9b92-425e-8979-99464621b543\",\"subject\":\"<%subject%>\"}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -152,13 +152,13 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.PATCH; - request.endpoint = "templates/{template_id}/versions/{version_id}"; - request.body = "{\"active\":1,\"html_content\":\"<%body%>\",\"subject\":\"<%subject%>\",\"name\":\"updated_example_name\",\"plain_content\":\"<%body%>\"}"; + request.setMethod(Method.PATCH); + request.setEndpoint("templates/{template_id}/versions/{version_id}"); + request.setBody("{\"active\":1,\"html_content\":\"<%body%>\",\"subject\":\"<%subject%>\",\"name\":\"updated_example_name\",\"plain_content\":\"<%body%>\"}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -175,12 +175,12 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "templates/{template_id}/versions/{version_id}"; + request.setMethod(Method.GET); + request.setEndpoint("templates/{template_id}/versions/{version_id}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -197,12 +197,12 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.DELETE; - request.endpoint = "templates/{template_id}/versions/{version_id}"; + request.setMethod(Method.DELETE); + request.setEndpoint("templates/{template_id}/versions/{version_id}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -219,12 +219,12 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.POST; - request.endpoint = "templates/{template_id}/versions/{version_id}/activate"; + request.setMethod(Method.POST); + request.setEndpoint("templates/{template_id}/versions/{version_id}/activate"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } diff --git a/examples/trackingsettings/trackingsettings.java b/examples/trackingsettings/trackingsettings.java index 82deebe4..17b8d0d0 100644 --- a/examples/trackingsettings/trackingsettings.java +++ b/examples/trackingsettings/trackingsettings.java @@ -17,16 +17,14 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "tracking_settings"; - Map queryParams = new HashMap(); - queryParams.put("limit", "1"); - queryParams.put("offset", "1"); - request.queryParams = queryParams; + request.setMethod(Method.GET); + request.setEndpoint("tracking_settings"); + request.addQueryParam("limit", "1"); + request.addQueryParam("offset", "1"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -43,13 +41,13 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.PATCH; - request.endpoint = "tracking_settings/click"; - request.body = "{\"enabled\":true}"; + request.setMethod(Method.PATCH); + request.setEndpoint("tracking_settings/click"); + request.setBody("{\"enabled\":true}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -66,12 +64,12 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "tracking_settings/click"; + request.setMethod(Method.GET); + request.setEndpoint("tracking_settings/click"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -88,13 +86,13 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.PATCH; - request.endpoint = "tracking_settings/google_analytics"; - request.body = "{\"utm_campaign\":\"website\",\"utm_term\":\"\",\"utm_content\":\"\",\"enabled\":true,\"utm_source\":\"sendgrid.com\",\"utm_medium\":\"email\"}"; + request.setMethod(Method.PATCH); + request.setEndpoint("tracking_settings/google_analytics"); + request.setBody("{\"utm_campaign\":\"website\",\"utm_term\":\"\",\"utm_content\":\"\",\"enabled\":true,\"utm_source\":\"sendgrid.com\",\"utm_medium\":\"email\"}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -111,12 +109,12 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "tracking_settings/google_analytics"; + request.setMethod(Method.GET); + request.setEndpoint("tracking_settings/google_analytics"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -133,13 +131,13 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.PATCH; - request.endpoint = "tracking_settings/open"; - request.body = "{\"enabled\":true}"; + request.setMethod(Method.PATCH); + request.setEndpoint("tracking_settings/open"); + request.setBody("{\"enabled\":true}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -156,12 +154,12 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "tracking_settings/open"; + request.setMethod(Method.GET); + request.setEndpoint("tracking_settings/open"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -178,13 +176,13 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.PATCH; - request.endpoint = "tracking_settings/subscription"; - request.body = "{\"url\":\"url\",\"html_content\":\"html content\",\"enabled\":true,\"landing\":\"landing page html\",\"replace\":\"replacement tag\",\"plain_content\":\"text content\"}"; + request.setMethod(Method.PATCH); + request.setEndpoint("tracking_settings/subscription"); + request.setBody("{\"url\":\"url\",\"html_content\":\"html content\",\"enabled\":true,\"landing\":\"landing page html\",\"replace\":\"replacement tag\",\"plain_content\":\"text content\"}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -201,12 +199,12 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "tracking_settings/subscription"; + request.setMethod(Method.GET); + request.setEndpoint("tracking_settings/subscription"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } diff --git a/examples/user/user.java b/examples/user/user.java index 03c23df1..9c5ff95c 100644 --- a/examples/user/user.java +++ b/examples/user/user.java @@ -17,12 +17,12 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "user/account"; + request.setMethod(Method.GET); + request.setEndpoint("user/account"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -39,12 +39,12 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "user/credits"; + request.setMethod(Method.GET); + request.setEndpoint("user/credits"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -61,13 +61,13 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.PUT; - request.endpoint = "user/email"; - request.body = "{\"email\":\"example@example.com\"}"; + request.setMethod(Method.PUT); + request.setEndpoint("user/email"); + request.setBody("{\"email\":\"example@example.com\"}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -84,12 +84,12 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "user/email"; + request.setMethod(Method.GET); + request.setEndpoint("user/email"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -106,13 +106,13 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.PUT; - request.endpoint = "user/password"; - request.body = "{\"new_password\":\"new_password\",\"old_password\":\"old_password\"}"; + request.setMethod(Method.PUT); + request.setEndpoint("user/password"); + request.setBody("{\"new_password\":\"new_password\",\"old_password\":\"old_password\"}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -129,13 +129,13 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.PATCH; - request.endpoint = "user/profile"; - request.body = "{\"city\":\"Orange\",\"first_name\":\"Example\",\"last_name\":\"User\"}"; + request.setMethod(Method.PATCH); + request.setEndpoint("user/profile"); + request.setBody("{\"city\":\"Orange\",\"first_name\":\"Example\",\"last_name\":\"User\"}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -152,12 +152,12 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "user/profile"; + request.setMethod(Method.GET); + request.setEndpoint("user/profile"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -174,13 +174,13 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.POST; - request.endpoint = "user/scheduled_sends"; - request.body = "{\"batch_id\":\"YOUR_BATCH_ID\",\"status\":\"pause\"}"; + request.setMethod(Method.POST); + request.setEndpoint("user/scheduled_sends"); + request.setBody("{\"batch_id\":\"YOUR_BATCH_ID\",\"status\":\"pause\"}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -197,12 +197,12 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "user/scheduled_sends"; + request.setMethod(Method.GET); + request.setEndpoint("user/scheduled_sends"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -219,13 +219,13 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.PATCH; - request.endpoint = "user/scheduled_sends/{batch_id}"; - request.body = "{\"status\":\"pause\"}"; + request.setMethod(Method.PATCH); + request.setEndpoint("user/scheduled_sends/{batch_id}"); + request.setBody("{\"status\":\"pause\"}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -242,12 +242,12 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "user/scheduled_sends/{batch_id}"; + request.setMethod(Method.GET); + request.setEndpoint("user/scheduled_sends/{batch_id}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -264,12 +264,12 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.DELETE; - request.endpoint = "user/scheduled_sends/{batch_id}"; + request.setMethod(Method.DELETE); + request.setEndpoint("user/scheduled_sends/{batch_id}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -286,13 +286,13 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.PATCH; - request.endpoint = "user/settings/enforced_tls"; - request.body = "{\"require_tls\":true,\"require_valid_cert\":false}"; + request.setMethod(Method.PATCH); + request.setEndpoint("user/settings/enforced_tls"); + request.setBody("{\"require_tls\":true,\"require_valid_cert\":false}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -309,12 +309,12 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "user/settings/enforced_tls"; + request.setMethod(Method.GET); + request.setEndpoint("user/settings/enforced_tls"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -331,13 +331,13 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.PUT; - request.endpoint = "user/username"; - request.body = "{\"username\":\"test_username\"}"; + request.setMethod(Method.PUT); + request.setBody("user/username"); + request.setBody("{\"username\":\"test_username\"}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -354,12 +354,12 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "user/username"; + request.setMethod(Method.GET); + request.setEndpoint("user/username"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -376,13 +376,13 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.PATCH; - request.endpoint = "user/webhooks/event/settings"; - request.body = "{\"group_resubscribe\":true,\"delivered\":true,\"group_unsubscribe\":true,\"spam_report\":true,\"url\":\"url\",\"enabled\":true,\"bounce\":true,\"deferred\":true,\"unsubscribe\":true,\"dropped\":true,\"open\":true,\"click\":true,\"processed\":true}"; + request.setMethod(Method.PATCH); + request.setEndpoint("user/webhooks/event/settings"); + request.setBody("{\"group_resubscribe\":true,\"delivered\":true,\"group_unsubscribe\":true,\"spam_report\":true,\"url\":\"url\",\"enabled\":true,\"bounce\":true,\"deferred\":true,\"unsubscribe\":true,\"dropped\":true,\"open\":true,\"click\":true,\"processed\":true}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -399,12 +399,12 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "user/webhooks/event/settings"; + request.setMethod(Method.GET); + request.setEndpoint("user/webhooks/event/settings"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -421,13 +421,13 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.POST; - request.endpoint = "user/webhooks/event/test"; - request.body = "{\"url\":\"url\"}"; + request.setMethod(Method.POST); + request.setEndpoint("user/webhooks/event/test"); + request.setBody("{\"url\":\"url\"}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -444,13 +444,13 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.POST; - request.endpoint = "user/webhooks/parse/settings"; - request.body = "{\"url\":\"http://email.myhosthame.com\",\"send_raw\":false,\"hostname\":\"myhostname.com\",\"spam_check\":true}"; + request.setMethod(Method.POST); + request.setEndpoint("user/webhooks/parse/settings"); + request.setBody("{\"url\":\"http://email.myhosthame.com\",\"send_raw\":false,\"hostname\":\"myhostname.com\",\"spam_check\":true}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -467,12 +467,12 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "user/webhooks/parse/settings"; + request.setMethod(Method.GET); + request.setEndpoint("user/webhooks/parse/settings"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -489,13 +489,13 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.PATCH; - request.endpoint = "user/webhooks/parse/settings/{hostname}"; - request.body = "{\"url\":\"http://newdomain.com/parse\",\"send_raw\":true,\"spam_check\":false}"; + request.setMethod(Method.PATCH); + request.setEndpoint("user/webhooks/parse/settings/{hostname}"); + request.setBody("{\"url\":\"http://newdomain.com/parse\",\"send_raw\":true,\"spam_check\":false}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -512,12 +512,12 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "user/webhooks/parse/settings/{hostname}"; + request.setMethod(Method.GET); + request.setEndpoint("user/webhooks/parse/settings/{hostname}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -534,12 +534,12 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.DELETE; - request.endpoint = "user/webhooks/parse/settings/{hostname}"; + request.setMethod(Method.DELETE); + request.setEndpoint("user/webhooks/parse/settings/{hostname}"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } @@ -556,19 +556,17 @@ public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "user/webhooks/parse/stats"; - Map queryParams = new HashMap(); - queryParams.put("aggregated_by", "day"); - queryParams.put("limit", "test_string"); - queryParams.put("start_date", "2016-01-01"); - queryParams.put("end_date", "2016-04-01"); - queryParams.put("offset", "test_string"); - request.queryParams = queryParams; + request.setMethod(Method.GET); + request.setEndpoint("user/webhooks/parse/stats"); + request.addQueryParam("aggregated_by", "day"); + request.addQueryParam("limit", "test_string"); + request.addQueryParam("start_date", "2016-01-01"); + request.addQueryParam("end_date", "2016-04-01"); + request.addQueryParam("offset", "test_string"); Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } diff --git a/examples/whitelabel/domains.java b/examples/whitelabel/domains.java new file mode 100644 index 00000000..26a0d0a2 --- /dev/null +++ b/examples/whitelabel/domains.java @@ -0,0 +1,281 @@ +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; + +////////////////////////////////////////////////////////////////// +// Create a domain whitelabel. +// POST /whitelabel/domains + + +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.POST); + request.setEndpoint("whitelabel/domains"); + request.setBody("{\"automatic_security\":false,\"username\":\"john@example.com\",\"domain\":\"example.com\",\"default\":true,\"custom_spf\":true,\"ips\":[\"192.168.1.1\",\"192.168.1.2\"],\"subdomain\":\"news\"}"); + 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; + } + } +} + +////////////////////////////////////////////////////////////////// +// List all domain whitelabels. +// GET /whitelabel/domains + + +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("whitelabel/domains"); + request.addQueryParam("username", "test_string"); + request.addQueryParam("domain", "test_string"); + request.addQueryParam("exclude_subusers", "true"); + 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; + } + } +} + +////////////////////////////////////////////////////////////////// +// Get the default domain whitelabel. +// GET /whitelabel/domains/default + + +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("whitelabel/domains/default"); + 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; + } + } +} + +////////////////////////////////////////////////////////////////// +// List the domain whitelabel associated with the given user. +// GET /whitelabel/domains/subuser + + +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("whitelabel/domains/subuser"); + 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; + } + } +} + +////////////////////////////////////////////////////////////////// +// Disassociate a domain whitelabel from a given user. +// DELETE /whitelabel/domains/subuser + + +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.DELETE); + request.setEndpoint("whitelabel/domains/subuser"); + 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 a domain whitelabel. +// PATCH /whitelabel/domains/{domain_id} + + +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("whitelabel/domains/{domain_id}"); + request.setBody("{\"default\":false,\"custom_spf\":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 a domain whitelabel. +// GET /whitelabel/domains/{domain_id} + + +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("whitelabel/domains/{domain_id}"); + 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; + } + } +} + +////////////////////////////////////////////////////////////////// +// Delete a domain whitelabel. +// DELETE /whitelabel/domains/{domain_id} + + +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.DELETE); + request.setEndpoint("whitelabel/domains/{domain_id}"); + 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; + } + } +} + +////////////////////////////////////////////////////////////////// +// Associate a domain whitelabel with a given user. +// POST /whitelabel/domains/{domain_id}/subuser + + +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.POST); + request.setEndpoint("whitelabel/domains/{domain_id}/subuser"); + request.setBody("{\"username\":\"jane@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; + } + } +} + +////////////////////////////////////////////////////////////////// +// Add an IP to a domain whitelabel. +// POST /whitelabel/domains/{id}/ips + + +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.POST); + request.setEndpoint("whitelabel/domains/{id}/ips"); + request.setBody("{\"ip\":\"192.168.0.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; + } + } +} + +////////////////////////////////////////////////////////////////// +// Remove an IP from a domain whitelabel. +// DELETE /whitelabel/domains/{id}/ips/{ip} + + +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.DELETE); + request.setEndpoint("whitelabel/domains/{id}/ips/{ip}"); + 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; + } + } +} + +////////////////////////////////////////////////////////////////// +// Validate a domain whitelabel. +// POST /whitelabel/domains/{id}/validate + + +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.POST); + request.setEndpoint("whitelabel/domains/{id}/validate"); + 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/whitelabel/ips.java b/examples/whitelabel/ips.java new file mode 100644 index 00000000..22836d99 --- /dev/null +++ b/examples/whitelabel/ips.java @@ -0,0 +1,127 @@ +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; + +public class CommonExample { + protected SendGrid sg; + protected Request request; + + protected static void init() { + this.sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + this.request = new Request(); + } +} + +////////////////////////////////////////////////////////////////// +// Create an IP whitelabel +// POST /whitelabel/ips + + +public class Example extends CommonExample { + public static void main(String[] args) throws IOException { + try { + init(); + request.setMethod(Method.POST); + request.setEndpoint("whitelabel/ips"); + request.setBody("{\"ip\":\"192.168.1.1\",\"domain\":\"example.com\",\"subdomain\":\"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 all IP whitelabels +// GET /whitelabel/ips + + +public class Example extends CommonExample { + public static void main(String[] args) throws IOException { + try { + init(); + request.setMethod(Method.GET); + request.setEndpoint("whitelabel/ips"); + request.addQueryParam("ip", "test_string"); + 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; + } + } +} + +////////////////////////////////////////////////////////////////// +// Retrieve an IP whitelabel +// GET /whitelabel/ips/{id} + + +public class Example extends CommonExample { + public static void main(String[] args) throws IOException { + try { + init(); + request.setMethod(Method.GET); + request.setEndpoint("whitelabel/ips/{id}"); + 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; + } + } +} + +////////////////////////////////////////////////////////////////// +// Delete an IP whitelabel +// DELETE /whitelabel/ips/{id} + + +public class Example extends CommonExample { + public static void main(String[] args) throws IOException { + try { + init(); + request.setMethod(Method.DELETE); + request.setEndpoint("whitelabel/ips/{id}"); + 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; + } + } +} + +////////////////////////////////////////////////////////////////// +// Validate an IP whitelabel +// POST /whitelabel/ips/{id}/validate + + +public class Example extends CommonExample { + public static void main(String[] args) throws IOException { + try { + init(); + request.setMethod(Method.POST); + request.setEndpoint("whitelabel/ips/{id}/validate"); + 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/whitelabel/links.java b/examples/whitelabel/links.java new file mode 100644 index 00000000..ca7218ff --- /dev/null +++ b/examples/whitelabel/links.java @@ -0,0 +1,238 @@ +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; + +////////////////////////////////////////////////////////////////// +// Create a Link Whitelabel +// POST /whitelabel/links + + +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.POST); + request.setEndpoint("whitelabel/links"); + request.setBody("{\"default\":true,\"domain\":\"example.com\",\"subdomain\":\"mail\"}"); + 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; + } + } +} + +////////////////////////////////////////////////////////////////// +// Retrieve all link whitelabels +// GET /whitelabel/links + + +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("whitelabel/links"); + request.addQueryParam("limit", "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; + } + } +} + +////////////////////////////////////////////////////////////////// +// Retrieve a Default Link Whitelabel +// GET /whitelabel/links/default + + +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("whitelabel/links/default"); + request.addQueryParam("domain", "test_string"); + 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 Associated Link Whitelabel +// GET /whitelabel/links/subuser + + +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("whitelabel/links/subuser"); + request.addQueryParam("username", "test_string"); + 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; + } + } +} + +////////////////////////////////////////////////////////////////// +// Disassociate a Link Whitelabel +// DELETE /whitelabel/links/subuser + + +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.DELETE); + request.setEndpoint("whitelabel/links/subuser"); + request.addQueryParam("username", "test_string"); + 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 a Link Whitelabel +// PATCH /whitelabel/links/{id} + + +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("whitelabel/links/{id}"); + request.setBody("{\"default\":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 a Link Whitelabel +// GET /whitelabel/links/{id} + + +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("whitelabel/links/{id}"); + 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; + } + } +} + +////////////////////////////////////////////////////////////////// +// Delete a Link Whitelabel +// DELETE /whitelabel/links/{id} + + +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.DELETE); + request.setEndpoint("whitelabel/links/{id}"); + 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; + } + } +} + +////////////////////////////////////////////////////////////////// +// Validate a Link Whitelabel +// POST /whitelabel/links/{id}/validate + + +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.POST); + request.setEndpoint("whitelabel/links/{id}/validate"); + 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; + } + } +} + +////////////////////////////////////////////////////////////////// +// Associate a Link Whitelabel +// POST /whitelabel/links/{link_id}/subuser + + +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.POST); + request.setEndpoint("whitelabel/links/{link_id}/subuser"); + request.setBody("{\"username\":\"jane@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; + } + } +} + diff --git a/examples/whitelabel/whitelabel.java b/examples/whitelabel/whitelabel.java deleted file mode 100644 index baabe3b7..00000000 --- a/examples/whitelabel/whitelabel.java +++ /dev/null @@ -1,639 +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; - -////////////////////////////////////////////////////////////////// -// Create a domain whitelabel. -// POST /whitelabel/domains - - -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.method = Method.POST; - request.endpoint = "whitelabel/domains"; - request.body = "{\"automatic_security\":false,\"username\":\"john@example.com\",\"domain\":\"example.com\",\"default\":true,\"custom_spf\":true,\"ips\":[\"192.168.1.1\",\"192.168.1.2\"],\"subdomain\":\"news\"}"; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// List all domain whitelabels. -// GET /whitelabel/domains - - -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.method = Method.GET; - request.endpoint = "whitelabel/domains"; - Map queryParams = new HashMap(); - queryParams.put("username", "test_string"); - queryParams.put("domain", "test_string"); - queryParams.put("exclude_subusers", "true"); - queryParams.put("limit", "1"); - queryParams.put("offset", "1"); - request.queryParams = queryParams; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Get the default domain whitelabel. -// GET /whitelabel/domains/default - - -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.method = Method.GET; - request.endpoint = "whitelabel/domains/default"; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// List the domain whitelabel associated with the given user. -// GET /whitelabel/domains/subuser - - -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.method = Method.GET; - request.endpoint = "whitelabel/domains/subuser"; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Disassociate a domain whitelabel from a given user. -// DELETE /whitelabel/domains/subuser - - -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.method = Method.DELETE; - request.endpoint = "whitelabel/domains/subuser"; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Update a domain whitelabel. -// PATCH /whitelabel/domains/{domain_id} - - -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.method = Method.PATCH; - request.endpoint = "whitelabel/domains/{domain_id}"; - request.body = "{\"default\":false,\"custom_spf\":true}"; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Retrieve a domain whitelabel. -// GET /whitelabel/domains/{domain_id} - - -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.method = Method.GET; - request.endpoint = "whitelabel/domains/{domain_id}"; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Delete a domain whitelabel. -// DELETE /whitelabel/domains/{domain_id} - - -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.method = Method.DELETE; - request.endpoint = "whitelabel/domains/{domain_id}"; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Associate a domain whitelabel with a given user. -// POST /whitelabel/domains/{domain_id}/subuser - - -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.method = Method.POST; - request.endpoint = "whitelabel/domains/{domain_id}/subuser"; - request.body = "{\"username\":\"jane@example.com\"}"; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Add an IP to a domain whitelabel. -// POST /whitelabel/domains/{id}/ips - - -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.method = Method.POST; - request.endpoint = "whitelabel/domains/{id}/ips"; - request.body = "{\"ip\":\"192.168.0.1\"}"; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Remove an IP from a domain whitelabel. -// DELETE /whitelabel/domains/{id}/ips/{ip} - - -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.method = Method.DELETE; - request.endpoint = "whitelabel/domains/{id}/ips/{ip}"; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Validate a domain whitelabel. -// POST /whitelabel/domains/{id}/validate - - -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.method = Method.POST; - request.endpoint = "whitelabel/domains/{id}/validate"; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Create an IP whitelabel -// POST /whitelabel/ips - - -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.method = Method.POST; - request.endpoint = "whitelabel/ips"; - request.body = "{\"ip\":\"192.168.1.1\",\"domain\":\"example.com\",\"subdomain\":\"email\"}"; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Retrieve all IP whitelabels -// GET /whitelabel/ips - - -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.method = Method.GET; - request.endpoint = "whitelabel/ips"; - Map queryParams = new HashMap(); - queryParams.put("ip", "test_string"); - queryParams.put("limit", "1"); - queryParams.put("offset", "1"); - request.queryParams = queryParams; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Retrieve an IP whitelabel -// GET /whitelabel/ips/{id} - - -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.method = Method.GET; - request.endpoint = "whitelabel/ips/{id}"; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Delete an IP whitelabel -// DELETE /whitelabel/ips/{id} - - -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.method = Method.DELETE; - request.endpoint = "whitelabel/ips/{id}"; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Validate an IP whitelabel -// POST /whitelabel/ips/{id}/validate - - -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.method = Method.POST; - request.endpoint = "whitelabel/ips/{id}/validate"; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Create a Link Whitelabel -// POST /whitelabel/links - - -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.method = Method.POST; - request.endpoint = "whitelabel/links"; - request.body = "{\"default\":true,\"domain\":\"example.com\",\"subdomain\":\"mail\"}"; - Map queryParams = new HashMap(); - queryParams.put("limit", "1"); - queryParams.put("offset", "1"); - request.queryParams = queryParams; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Retrieve all link whitelabels -// GET /whitelabel/links - - -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.method = Method.GET; - request.endpoint = "whitelabel/links"; - Map queryParams = new HashMap(); - queryParams.put("limit", "1"); - request.queryParams = queryParams; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Retrieve a Default Link Whitelabel -// GET /whitelabel/links/default - - -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.method = Method.GET; - request.endpoint = "whitelabel/links/default"; - Map queryParams = new HashMap(); - queryParams.put("domain", "test_string"); - request.queryParams = queryParams; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Retrieve Associated Link Whitelabel -// GET /whitelabel/links/subuser - - -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.method = Method.GET; - request.endpoint = "whitelabel/links/subuser"; - Map queryParams = new HashMap(); - queryParams.put("username", "test_string"); - request.queryParams = queryParams; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Disassociate a Link Whitelabel -// DELETE /whitelabel/links/subuser - - -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.method = Method.DELETE; - request.endpoint = "whitelabel/links/subuser"; - Map queryParams = new HashMap(); - queryParams.put("username", "test_string"); - request.queryParams = queryParams; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Update a Link Whitelabel -// PATCH /whitelabel/links/{id} - - -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.method = Method.PATCH; - request.endpoint = "whitelabel/links/{id}"; - request.body = "{\"default\":true}"; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Retrieve a Link Whitelabel -// GET /whitelabel/links/{id} - - -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.method = Method.GET; - request.endpoint = "whitelabel/links/{id}"; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Delete a Link Whitelabel -// DELETE /whitelabel/links/{id} - - -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.method = Method.DELETE; - request.endpoint = "whitelabel/links/{id}"; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Validate a Link Whitelabel -// POST /whitelabel/links/{id}/validate - - -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.method = Method.POST; - request.endpoint = "whitelabel/links/{id}/validate"; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } catch (IOException ex) { - throw ex; - } - } -} - -////////////////////////////////////////////////////////////////// -// Associate a Link Whitelabel -// POST /whitelabel/links/{link_id}/subuser - - -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.method = Method.POST; - request.endpoint = "whitelabel/links/{link_id}/subuser"; - request.body = "{\"username\":\"jane@example.com\"}"; - Response response = sg.api(request); - System.out.println(response.statusCode); - System.out.println(response.body); - System.out.println(response.headers); - } catch (IOException ex) { - throw ex; - } - } -} - diff --git a/pom.xml b/pom.xml index 4cbc150f..6a6619fa 100644 --- a/pom.xml +++ b/pom.xml @@ -9,7 +9,7 @@ com.sendgrid sendgrid-java SendGrid Java helper library - 3.0.3 + 4.3.0 This Java module allows you to quickly and easily send emails through SendGrid using Java. https://github.com/sendgrid/sendgrid-java @@ -19,13 +19,24 @@ repo + + 2.9.5 + https://github.com/sendgrid/sendgrid-java scm:git:git@github.com:sendgrid/sendgrid-java.git scm:git:git@github.com:sendgrid/sendgrid-java.git HEAD - + + + + ${basedir} + + LICENSE.txt + + + org.apache.maven.plugins @@ -89,28 +100,35 @@ com.sendgrid java-http-client - 2.3.2 + 4.1.0 com.fasterxml.jackson.core jackson-core - 2.5.3 + ${jackson.version} com.fasterxml.jackson.core jackson-annotations - 2.5.3 + ${jackson.version} com.fasterxml.jackson.core jackson-databind - 2.5.3 + ${jackson.version} junit junit-dep - 4.10 + 4.11 + test + + + org.mockito + mockito-core + 2.1.0 test + diff --git a/proposals/mail-helper-refactor.md b/proposals/mail-helper-refactor.md new file mode 100644 index 00000000..b06d2f1e --- /dev/null +++ b/proposals/mail-helper-refactor.md @@ -0,0 +1,465 @@ +# Send a Single Email to a Single Recipient + +The following code assumes you are storing the API key in an environment variable (recommended). + +This is the minimum code needed to send an email. + +```java +import com.sendgrid.*; +import com.sendgrid.helpers.mail.*; + +public class SendGridExample { + public static void main(String[] args) throws SendGridException { + From from = new From("test@example.com", "Example User"); + To to = new To("test@example.com", "Example User"); + Subject subject = new Subject("Sending with SendGrid is Fun"); + PlainTextContent plainTextContent = new PlainTextContent("and easy to do anywhere, even with Java"); + HtmlContent htmlContent = new HtmlContent("and easy to do anywhere, even with Java"); + SendGridMessage email = new SendGridMessage(from, + to, + subject, + plainTextContent, + htmlContent); + + SendGrid sendgrid = new SendGrid(System.getenv("SENDGRID_API_KEY")); + try { + SendGridResponse response = sendgrid.send(email); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); + } catch (SendGridException ex) { + System.err.println(ex); + throw ex; + } + } +} +``` + +# Send a Single Email to Multiple Recipients + +The following code assumes you are storing the API key in an environment variable (recommended). + +```java +import com.sendgrid.*; +import com.sendgrid.helpers.mail.*; +import java.util.ArrayList; + +public class SendGridExample { + public static void main(String[] args) throws SendGridException { + From from = new From("test@example.com", "Example User"); + ArrayList tos = new ArrayList(); + tos.add(new To("test1@example.com", "Example User1")); + tos.add(new To("test2@example.com", "Example User2")); + tos.add(new To("test3@example.com", "Example User3")); + Subject subject = new Subject("Sending with SendGrid is Fun"); + PlainTextContent plainTextContent = new PlainTextContent("and easy to do anywhere, even with Java"); + HtmlContent htmlContent = new HtmlContent("and easy to do anywhere, even with Java"); + SendGridMessage email = new SendGridMessage(from, + tos, + subject, + plainTextContent, + htmlContent); + + SendGrid sendgrid = new SendGrid(System.getenv("SENDGRID_API_KEY")); + try { + SendGridResponse response = sendgrid.send(email); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); + } catch (SendGridException ex) { + System.err.println(ex); + throw ex; + } + } +} +``` + +# Send Multiple Emails to Multiple Recipients + +The following code assumes you are storing the API key in an environment variable (recommended). + + +```java +import com.sendgrid.*; +import com.sendgrid.helpers.mail.*; +import java.util.ArrayList; + +public class SendGridExample { + public static void main(String[] args) throws SendGridException { + From from = new From("test@example.com", "Example User"); + ArrayList tos = new ArrayList(); + ArrayList sub = new ArrayList(); + sub.add("-name-", "Alain"); + sub.add("-github-", "http://github.com/ninsuo"); + tos.add(new To("test1@example.com", "Example User1"), sub); + sub.clear(); + sub.add("-name-", "Elmer"); + sub.add("-github-", "http://github.com/thinkingserious"); + tos.add(new To("test2@example.com", "Example User2"), sub); + sub.clear(); + sub.add("-name-", "Casey"); + sub.add("-github-", "http://github.com/caseyw"); + tos.add(new To("test3@example.com", "Example User3"), sub); + // Alternatively, you can pass in a collection of subjects OR add a subject to the `To` object + Subject subject = new Subject("Hi -name-!"); + Substitution globalSubstitution = new Substitution("-time-", ""); + PlainTextContent plainTextContent = new PlainTextContent("Hello -name-, your github is -github-, email sent at -time-"); + HtmlContent htmlContent = new HtmlContent("Hello -name-, your github is here email sent at -time-"); + SendGridMessage email = new SendGridMessage(from, + subject, // or subjects, + tos, + plainTextContent, + htmlContent, + globalSubstitution); // or globalSubstitutions + + SendGrid sendgrid = new SendGrid(System.getenv("SENDGRID_API_KEY")); + try { + SendGridResponse response = sendgrid.send(email); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); + } catch (SendGridException ex) { + System.err.println(ex); + throw ex; + } + } +} +``` + +# Kitchen Sink - an example with all settings used + +The following code assumes you are storing the API key in an environment variable (recommended). + + +```java +import com.sendgrid.*; +import com.sendgrid.helpers.mail.*; +import java.util.ArrayList; + +public class SendGridExample { + public static void main(String[] args) throws SendGridException { + From from = new From("test@example.com", "Example User"); + To to = new To("test@example.com", "Example User"); + Subject subject = new Subject("Sending with SendGrid is Fun"); + PlainTextContent plainTextContent = new PlainTextContent("and easy to do anywhere, even with Java"); + HtmlContent htmlContent = new HtmlContent("and easy to do anywhere, even with Java"); + SendGridMessage email = new SendGridMessage(from, + to, // or tos + subject, // or subjects + plainTextContent, + htmlContent); + + // For a detailed description of each of these settings, please see the [documentation](https://sendgrid.com/docs/API_Reference/api_v3.html). + email.addTo("test1@example.com", "Example User1") + ArrayList tos = new ArrayList(); + tos.add("test2@example.com", "Example User2"); + tos.add("test3@example.com", "Example User3"); + email.addTos(tos); + + email.addCc("test4@example.com", "Example User4") + ArrayList ccs = new ArrayList(); + ccs.add("test5@example.com", "Example User5"); + ccs.add("test6@example.com", "Example User6"); + email.addCcs(ccs); + + email.addBcc("test7@example.com", "Example User7") + ArrayList bccs = new ArrayList(); + bccs.add("test8@example.com", "Example User8"); + bccs.add("test9@example.com", "Example User9"); + email.addBccs(bccs); + + email.addHeader("X-Test1", "Test1"); + email.addHeader("X-Test2", "Test2"); + ArrayList
headers = new ArrayList
(); + headers.add("X-Test3", "Test3"); + headers.add("X-Test4", "Test4"); + email.addHeaders(headers) + + email.addSubstitution("%name1%", "Example Name 1"); + email.addSubstitution("%city1%", "Denver"); + ArrayList substitutions = new ArrayList(); + substitutions.add("%name2%", "Example Name 2"); + substitutions.add("%city2%", "Orange" ); + email.addSubstitutions(substitutions); + + email.addCustomArg("marketing1", "false"); + email.addCustomArg("transactional1", "true"); + ArrayList customArgs = new ArrayList(); + customArgs.add("marketing2", "true"); + customArgs.add("transactional2", "false"); + email.addCustomArgs(customArgs); + + email.setSendAt(1461775051); + + // If you need to add more [Personalizations](https://sendgrid.com/docs/Classroom/Send/v3_Mail_Send/personalizations.html), here is an example of adding another Personalization by passing in a personalization index + + + email.addTo("test10@example.com", "Example User 10", 1); + ArrayList tos1 = new ArrayList(); + tos1.add("test11@example.com", "Example User11"); + tos1.add("test12@example.com", "Example User12"); + email.addTos(tos1, 1); + + email.addCc("test13@example.com", "Example User 13", 1); + ArrayList ccs1 = new ArrayList(); + ccs1.add("test14@example.com", "Example User14"); + ccs1.add("test15@example.com", "Example User15"); + email.addCcs(ccs1, 1); + + email.addBcc("test16@example.com", "Example User 16", 1); + ArrayList bccs1 = new ArrayList(); + bccs1.add("test17@example.com", "Example User17"); + bccs1.add("test18@example.com", "Example User18"); + email.addBccs(bccs1, 1); + + email.addHeader("X-Test5", "Test5", 1); + email.addHeader("X-Test6", "Test6", 1); + ArrayList
headers1 = new ArrayList
(); + headers1.add("X-Test7", "Test7"); + headers1.add("X-Test8", "Test8"); + email.addHeaders(headers1, 1); + + email.addSubstitution("%name3%", "Example Name 3", 1); + email.addSubstitution("%city3%", "Redwood City", 1); + ArrayList substitutions1 = new ArrayList(); + substitutions1.add("%name4%", "Example Name 4"); + substitutions1.add("%city4%", "London"); + var substitutions1 = new Dictionary() + email.addSubstitutions(substitutions1, 1); + + email.addCustomArg("marketing3", "true", 1); + email.addCustomArg("transactional3", "false", 1); + ArrayList customArgs1 = new ArrayList(); + customArgs1.add("marketing4", "false"); + customArgs1.add("transactional4", "true"); + email.addCustomArgs(customArgs1, 1); + + email.setSendAt(1461775052, 1); + + // The values below this comment are global to entire message + + email.setFrom("test@example.com", "Example User 0"); + + email.setSubject("this subject overrides the Global Subject"); + + email.setGlobalSubject("Sending with SendGrid is Fun"); + + email.addContent(MimeType.TEXT, "and easy to do anywhere, even with C#"); + email.addContent(MimeType.HTML, "and easy to do anywhere, even with C#"); + ArrayList contents = new ArrayList(); + contents.add("text/calendar", "Party Time!!"); + contents.add("text/calendar2", "Party Time2!!"); + email.addContents(contents); + + email.addAttachment("balance_001.pdf", + "base64 encoded string", + "application/pdf", + "attachment", + "Balance Sheet"); + ArrayList attachments = new ArrayList(); + attachments.add("banner.png", + "base64 encoded string", + "image/png", + "inline", + "Banner"); + attachments.add("banner2.png", + "base64 encoded string", + "image/png", + "inline", + "Banner2"); + email.addAttachments(attachments); + + email.setTemplateId("13b8f94f-bcae-4ec6-b752-70d6cb59f932"); + + email.addGlobalHeader("X-Day", "Monday"); + ArrayList
globalHeaders = new ArrayList
(); + globalHeaders.add("X-Month", "January" ); + globalHeaders.add("X-Year", "2017"); + email.addGlobalHeaders(globalHeaders); + + email.addSection("%section1", "Substitution for Section 1 Tag"); + ArrayList
sections = new ArrayList
(); + sections.add("%section2%", "Substitution for Section 2 Tag"); + sections.add("%section3%", "Substitution for Section 3 Tag"); + email.addSections(sections); + + email.addCategory("customer"); + ArrayList categories = new ArrayList(); + categories.add("vip"); + categories.add("new_account"); + email.addCategories(categories); + + email.addGlobalCustomArg("campaign", "welcome"); + ArrayList globalCustomArgs = new ArrayList(); + globalCustomArgs.add("sequence2", "2"); + globalCustomArgs.add("sequence3", "3"); + email.addGlobalCustomArgs(globalCustomArgs); + + ArrayList asmGroups = new ArrayList(); + asmGroups.add(1); + asmGroups.add(4); + asmGroups.add(5); + email.setAsm(3, asmGroups); + + email.setGlobalSendAt(1461775051); + + email.setIpPoolName("23"); + + // This must be a valid [batch ID](https://sendgrid.com/docs/API_Reference/SMTP_API/scheduling_parameters.html) + //email.setBatchId("some_batch_id"); + + email.setBccSetting(true, "test@example.com"); + + email.setBypassListManagement(true); + + email.setFooterSetting(true, "Some Footer HTML", "Some Footer Text"); + + email.setSandBoxMode(true); + + email.setSpamCheck(true, 1, "https://gotchya.example.com"); + + email.setClickTracking(true, false); + + email.setOpenTracking(true, "Optional tag to replace with the open image in the body of the message"); + + email.setSubscriptionTracking(true, + "HTML to insert into the text / html portion of the message", + "text to insert into the text/plain portion of the message", + "substitution tag"); + + email.setGoogleAnalytics(true, + "some campaign", + "some content", + "some medium", + "some source", + "some term"); + + email.setReplyTo("test+reply@example.com", "Reply To Me"); + + SendGrid sendgrid = new SendGrid(System.getenv("SENDGRID_API_KEY")); + try { + SendGridResponse response = sendgrid.send(email); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); + } catch (SendGridException ex) { + System.err.println(ex); + throw ex; + } + } +} +``` + +# Attachments + +The following code assumes you are storing the API key in an environment variable (recommended). + +```java +import com.sendgrid.*; +import com.sendgrid.helpers.mail.*; + +public class SendGridExample { + public static void main(String[] args) throws SendGridException { + From from = new From("test@example.com", "Example User"); + To to = new To("test@example.com", "Example User"); + Subject subject = new Subject("Sending with SendGrid is Fun"); + PlainTextContent plainTextContent = new PlainTextContent("and easy to do anywhere, even with Java"); + HtmlContent htmlContent = new HtmlContent("and easy to do anywhere, even with Java"); + SendGridMessage email = new SendGridMessage(from, + to, + subject, + plainTextContent, + htmlContent); + email.addAttachment("balance_001.pdf", + "base64 encoded string", + "application/pdf", + "attachment", + "Balance Sheet"); + + SendGrid sendgrid = new SendGrid(System.getenv("SENDGRID_API_KEY")); + try { + SendGridResponse response = sendgrid.send(email); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); + } catch (SendGridException ex) { + System.err.println(ex); + throw ex; + } + } +} +``` + +# Transactional Templates + +The following code assumes you are storing the API key in an environment variable (recommended). + +For this example, we assume you have created a [transactional template](https://sendgrid.com/docs/User_Guide/Transactional_Templates/index.html). Following is the template content we used for testing. + +Template ID (replace with your own): + +```text +13b8f94f-bcae-4ec6-b752-70d6cb59f932 +``` + +Email Subject: + +```text +<%subject%> +``` + +Template Body: + +```html + + + + + +Hello -name-, +

+I'm glad you are trying out the template feature! +

+<%body%> +

+I hope you are having a great day in -city- :) +

+ + +``` + + +```java +import com.sendgrid.*; +import com.sendgrid.helpers.mail.*; + +public class SendGridExample { + public static void main(String[] args) throws SendGridException { + From from = new From("test@example.com", "Example User"); + To to = new To("test@example.com", "Example User"); + Subject subject = new Subject("Sending with SendGrid is Fun"); + PlainTextContent plainTextContent = new PlainTextContent("and easy to do anywhere, even with Java"); + HtmlContent htmlContent = new HtmlContent("and easy to do anywhere, even with Java"); + SendGridMessage email = new SendGridMessage(from, + to, + subject, + plainTextContent, + htmlContent); + // See `Send Multiple Emails to Multiple Recipients` for additional methods for adding substitutions + email.addSubstitution("-name-", "Example User"); + email.addSubstitution("-city-", "Denver"); + email.setTemplateId("13b8f94f-bcae-4ec6-b752-70d6cb59f932"); + + SendGrid sendgrid = new SendGrid(System.getenv("SENDGRID_API_KEY")); + try { + SendGridResponse response = sendgrid.send(email); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); + } catch (SendGridException ex) { + System.err.println(ex); + throw ex; + } + } +} +``` diff --git a/scripts/generate_upload_policy.php b/scripts/generate_upload_policy.php deleted file mode 100755 index 18fdf829..00000000 --- a/scripts/generate_upload_policy.php +++ /dev/null @@ -1,62 +0,0 @@ -#!/usr/bin/env php -$blocksize) - $key=pack('H*', $hashfunc($key)); - $key=str_pad($key,$blocksize,chr(0x00)); - $ipad=str_repeat(chr(0x36),$blocksize); - $opad=str_repeat(chr(0x5c),$blocksize); - $hmac = pack( - 'H*',$hashfunc( - ($key^$opad).pack( - 'H*',$hashfunc( - ($key^$ipad).$data - ) - ) - ) - ); - return bin2hex($hmac); -} - -/* - * Used to encode a field for Amazon Auth - * (taken from the Amazon S3 PHP example library) - */ -function hex2b64($str) -{ - $raw = ''; - for ($i=0; $i < strlen($str); $i+=2) - { - $raw .= chr(hexdec(substr($str, $i, 2))); - } - return base64_encode($raw); -} - -if (count($argv) != 3) { - echo "Usage: " . $argv[0] . " \n"; - exit(1); -} - -$policy = file_get_contents($argv[1]); -$secret = $argv[2]; - -/* - * Base64 encode the Policy Document and then - * create HMAC SHA-1 signature of the base64 encoded policy - * using the secret key. Finally, encode it for Amazon Authentication. - */ -$base64_policy = base64_encode($policy); -$signature = hex2b64(hmacsha1($secret, $base64_policy)); -echo "S3_POLICY=\"" . $base64_policy . "\"\nS3_SIGNATURE=\"" . $signature . "\"\n" -?> diff --git a/scripts/s3policy.json b/scripts/s3policy.json deleted file mode 100755 index 01c8108e..00000000 --- a/scripts/s3policy.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "expiration": "2100-01-01T12:00:00.000Z", - "conditions": [ - {"acl": "public-read" }, - {"bucket": "sendgrid-open-source" }, - ["starts-with", "$key", "sendgrid-java/"], - ["content-length-range", 2048, 268435456], - ["eq", "$Content-Type", "application/zip"] - ] -} diff --git a/scripts/s3upload.sh b/scripts/s3upload.sh deleted file mode 100755 index 420580a5..00000000 --- a/scripts/s3upload.sh +++ /dev/null @@ -1,31 +0,0 @@ -#!/bin/bash - -# From: -# http://raamdev.com/2008/using-curl-to-upload-files-via-post-to-amazon-s3/ - -GIT_VERSION=`git rev-parse --short HEAD` - -curl -X POST \ - -F "key=sendgrid-java/versions/sendgrid-java-$GIT_VERSION.jar" \ - -F "acl=public-read" \ - -F "AWSAccessKeyId=$S3_ACCESS_KEY" \ - -F "Policy=$S3_POLICY" \ - -F "Signature=$S3_SIGNATURE" \ - -F "Content-Type=application/zip" \ - -F "file=@./repo/com/sendgrid/sendgrid-jar.jar" \ - https://s3.amazonaws.com/$S3_BUCKET - -if [ "$TRAVIS_BRANCH" = "master" ] -then - curl -X POST \ - -F "key=sendgrid-java/sendgrid-java.jar" \ - -F "acl=public-read" \ - -F "AWSAccessKeyId=$S3_ACCESS_KEY" \ - -F "Policy=$S3_POLICY" \ - -F "Signature=$S3_SIGNATURE" \ - -F "Content-Type=application/zip" \ - -F "file=@./repo/com/sendgrid/sendgrid-jar.jar" \ - https://s3.amazonaws.com/$S3_BUCKET -fi - -exit 0 diff --git a/scripts/startPrism.sh b/scripts/startPrism.sh new file mode 100755 index 00000000..53923593 --- /dev/null +++ b/scripts/startPrism.sh @@ -0,0 +1,58 @@ +#!/bin/bash + +set -eu + +install () { + +echo "Installing Prism..." + +UNAME=$(uname) +ARCH=$(uname -m) +if [ "$UNAME" != "Linux" ] && [ "$UNAME" != "Darwin" ] && [ "$ARCH" != "x86_64" ] && [ "$ARCH" != "i686" ]; then + echo "Sorry, OS/Architecture not supported: ${UNAME}/${ARCH}. Download binary from https://github.com/stoplightio/prism/releases" + exit 1 +fi + +if [ "$UNAME" = "Darwin" ] ; then + OSX_ARCH=$(uname -m) + if [ "${OSX_ARCH}" = "x86_64" ] ; then + PLATFORM="darwin_amd64" + fi +elif [ "$UNAME" = "Linux" ] ; then + LINUX_ARCH=$(uname -m) + if [ "${LINUX_ARCH}" = "i686" ] ; then + PLATFORM="linux_386" + elif [ "${LINUX_ARCH}" = "x86_64" ] ; then + PLATFORM="linux_amd64" + fi +fi + +mkdir -p ../prism/bin +#LATEST=$(curl -s https://api.github.com/repos/stoplightio/prism/tags | grep -Eo '"name":.*?[^\\]",' | head -n 1 | sed 's/[," ]//g' | cut -d ':' -f 2) +LATEST="v0.6.21" +URL="https://github.com/stoplightio/prism/releases/download/$LATEST/prism_$PLATFORM" +DEST=../prism/bin/prism + +if [ -z $LATEST ] ; then + echo "Error requesting. Download binary from ${URL}" + exit 1 +else + curl -L $URL -o $DEST + chmod +x $DEST +fi +} + +run () { + echo "Running prism..." + cd ../prism/bin + ./prism run --mock --spec https://raw.githubusercontent.com/sendgrid/sendgrid-oai/master/oai_stoplight.json +} + +if [ -f ../prism/bin/prism ]; then + echo "Prism is already installed." + run +else + echo "Prism is not installed." + install + run +fi diff --git a/scripts/upload.sh b/scripts/upload.sh new file mode 100755 index 00000000..fb719838 --- /dev/null +++ b/scripts/upload.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +curl \ + -F "sdk=@./repo/com/sendgrid/sendgrid-java-latest.jar" \ + -H "X-Key: $UPLOAD_SECRET" \ + https://dx.sendgrid.com/upload + +exit 0 diff --git a/src/main/java/com/sendgrid/APICallback.java b/src/main/java/com/sendgrid/APICallback.java new file mode 100644 index 00000000..fde54f9d --- /dev/null +++ b/src/main/java/com/sendgrid/APICallback.java @@ -0,0 +1,19 @@ +package com.sendgrid; + +/** + * An interface describing a callback mechanism for the + * asynchronous, rate limit aware API connection. + */ +public interface APICallback { + /** + * Callback method in case of an error. + * @param ex the error that was thrown. + */ + public void error(Exception ex); + + /** + * Callback method in case of a valid response. + * @param response the valid response. + */ + public void response(Response response); +} diff --git a/src/main/java/com/sendgrid/RateLimitException.java b/src/main/java/com/sendgrid/RateLimitException.java new file mode 100644 index 00000000..4912ac92 --- /dev/null +++ b/src/main/java/com/sendgrid/RateLimitException.java @@ -0,0 +1,36 @@ +package com.sendgrid; + +/** + * An exception thrown when the maximum number of retries + * have occurred, and the API calls are still rate limited. + */ +public class RateLimitException extends Exception { + private final Request request; + private final int retryCount; + + /** + * Construct a new exception. + * @param request the originating request object. + * @param retryCount the number of times a retry was attempted. + */ + public RateLimitException(Request request, int retryCount) { + this.request = request; + this.retryCount = retryCount; + } + + /** + * Get the originating request object. + * @return the request object. + */ + public Request getRequest() { + return this.request; + } + + /** + * Get the number of times the action was attemted. + * @return the retry count. + */ + public int getRetryCount() { + return this.retryCount; + } +} diff --git a/src/main/java/com/sendgrid/SendGrid.java b/src/main/java/com/sendgrid/SendGrid.java index 4f0ded91..4bcdadc5 100644 --- a/src/main/java/com/sendgrid/SendGrid.java +++ b/src/main/java/com/sendgrid/SendGrid.java @@ -1,44 +1,79 @@ package com.sendgrid; -import com.sendgrid.Client; -import com.sendgrid.Method; -import com.sendgrid.Request; -import com.sendgrid.Response; - import java.io.IOException; import java.util.HashMap; import java.util.Map; +import java.util.concurrent.Executors; +import java.util.concurrent.ExecutorService; /** * Class SendGrid allows for quick and easy access to the SendGrid API. */ -public class SendGrid { +public class SendGrid implements SendGridAPI { + private static final String VERSION = "3.0.0"; + + /** The user agent string to return to SendGrid. */ private static final String USER_AGENT = "sendgrid/" + VERSION + ";java"; + private static final int RATE_LIMIT_RESPONSE_CODE = 429; + private static final int THREAD_POOL_SIZE = 8; + + private ExecutorService pool; + /** The user's API key. */ private String apiKey; + + /** The SendGrid host to which to connect. */ private String host; + + /** The API version. */ private String version; + + /** The HTTP client. */ private Client client; - private Map requestHeaders; + + /** The request headers container. */ + private Map requestHeaders; + + /** The number of times to try after a rate limit. */ + private int rateLimitRetry; + + /** The number of milliseconds to sleep between retries. */ + private int rateLimitSleep; /** - * @param apiKey is your SendGrid API Key: https://app.sendgrid.com/settings/api_keys - */ + * Construct a new SendGrid API wrapper. + * @param apiKey is your SendGrid API Key: https://app.sendgrid.com/settings/api_keys + */ public SendGrid(String apiKey) { this.client = new Client(); initializeSendGrid(apiKey); } /** - * @param apiKey is your SendGrid API Key: https://app.sendgrid.com/settings/api_keys - * @param test is true if you are unit testing - */ + * Construct a new SendGrid API wrapper. + * @param apiKey is your SendGrid API Key: https://app.sendgrid.com/settings/api_keys + * @param test is true if you are unit testing + */ public SendGrid(String apiKey, Boolean test) { this.client = new Client(test); initializeSendGrid(apiKey); } + /** + * Construct a new SendGrid API wrapper. + * @param apiKey is your SendGrid API Key: https://app.sendgrid.com/settings/api_keys + * @param client the Client to use (allows to customize its configuration) + */ + public SendGrid(String apiKey, Client client) { + this.client = client; + initializeSendGrid(apiKey); + } + + /** + * Initialize the client. + * @param apiKey the user's API key. + */ public void initializeSendGrid(String apiKey) { this.apiKey = apiKey; this.host = "api.sendgrid.com"; @@ -47,67 +82,206 @@ public void initializeSendGrid(String apiKey) { this.requestHeaders.put("Authorization", "Bearer " + apiKey); this.requestHeaders.put("User-agent", USER_AGENT); this.requestHeaders.put("Accept", "application/json"); + this.rateLimitRetry = 5; + this.rateLimitSleep = 1100; + + this.pool = Executors.newFixedThreadPool(THREAD_POOL_SIZE); } + /** + * Retrieve the current library version. + * @return the current version. + */ public String getLibraryVersion() { return this.VERSION; } + /** + * Get the API version. + * @return the current API versioin (v3 by default). + */ public String getVersion() { return this.version; } + /** + * Set the API version. + * @param version the new version. + */ public void setVersion(String version) { this.version = version; } - public Map getRequestHeaders() { + /** + * Obtain the request headers. + * @return the request headers. + */ + public Map getRequestHeaders() { return this.requestHeaders; } - public Map addRequestHeader(String key, String value) { + /** + * Add a new request header. + * @param key the header key. + * @param value the header value. + * @return the new set of request headers. + */ + public Map addRequestHeader(String key, String value) { this.requestHeaders.put(key, value); return getRequestHeaders(); } - public Map removeRequestHeader(String key) { + /** + * Remove a request header. + * @param key the header key to remove. + * @return the new set of request headers. + */ + public Map removeRequestHeader(String key) { this.requestHeaders.remove(key); return getRequestHeaders(); } + /** + * Get the SendGrid host (api.sendgrid.com by default). + * @return the SendGrid host. + */ public String getHost() { return this.host; } + /** + * Set the SendGrid host. + * @param host the new SendGrid host. + */ public void setHost(String host) { this.host = host; } /** - * Class makeCall makes the call to the SendGrid API, override this method for testing. - */ + * Get the maximum number of retries on a rate limit response. + * The default is 5. + * @return the number of retries on a rate limit. + */ + public int getRateLimitRetry() { + return this.rateLimitRetry; + } + + /** + * Set the maximum number of retries on a rate limit response. + * @param rateLimitRetry the maximum retry count. + */ + public void setRateLimitRetry(int rateLimitRetry) { + this.rateLimitRetry = rateLimitRetry; + } + + /** + * Get the duration of time (in milliseconds) to sleep between + * consecutive rate limit retries. The SendGrid API enforces + * the rate limit to the second. The default value is 1.1 seconds. + * @return the sleep duration. + */ + public int getRateLimitSleep() { + return this.rateLimitSleep; + } + + /** + * Set the duration of time (in milliseconds) to sleep between + * consecutive rate limit retries. + * @param rateLimitSleep the sleep duration. + */ + public void setRateLimitSleep(int rateLimitSleep) { + this.rateLimitSleep = rateLimitSleep; + } + + /** + * Makes the call to the SendGrid API, override this method for testing. + * @param request the request to make. + * @return the response object. + * @throws IOException in case of a network error. + */ public Response makeCall(Request request) throws IOException { - Response response = new Response(); - try { - response = client.api(request); - } catch (IOException ex) { - throw ex; - } - return response; + return client.api(request); } /** - * Class api sets up the request to the SendGrid API, this is main interface. - */ + * Class api sets up the request to the SendGrid API, this is main interface. + * @param request the request object. + * @return the response object. + * @throws IOException in case of a network error. + */ public Response api(Request request) throws IOException { Request req = new Request(); - req.method = request.method; - req.baseUri = this.host; - req.endpoint = "/" + version + "/" + request.endpoint; - req.body = request.body; - req.headers = this.requestHeaders; - req.queryParams = request.queryParams; + req.setMethod(request.getMethod()); + req.setBaseUri(this.host); + req.setEndpoint("/" + version + "/" + request.getEndpoint()); + req.setBody(request.getBody()); + for (Map.Entry header : this.requestHeaders.entrySet()) { + req.addHeader(header.getKey(), header.getValue()); + } + for (Map.Entry queryParam : request.getQueryParams().entrySet()) { + req.addQueryParam(queryParam.getKey(), queryParam.getValue()); + } return makeCall(req); } + + /** + * Attempt an API call. This method executes the API call asynchronously + * on an internal thread pool. If the call is rate limited, the thread + * will retry up to the maximum configured time. + * @param request the API request. + */ + public void attempt(Request request) { + this.attempt(request, new APICallback() { + @Override + public void error(Exception ex) { + } + + public void response(Response r) { + } + }); + } + + /** + * Attempt an API call. This method executes the API call asynchronously + * on an internal thread pool. If the call is rate limited, the thread + * will retry up to the maximum configured time. The supplied callback + * will be called in the event of an error, or a successful response. + * @param request the API request. + * @param callback the callback. + */ + public void attempt(final Request request, final APICallback callback) { + this.pool.execute(new Runnable() { + @Override + public void run() { + Response response; + + // Retry until the retry limit has been reached. + for (int i = 0; i < rateLimitRetry; ++i) { + try { + response = api(request); + } catch (IOException ex) { + // Stop retrying if there is a network error. + callback.error(ex); + return; + } + + // We have been rate limited. + if (response.getStatusCode() == RATE_LIMIT_RESPONSE_CODE) { + try { + Thread.sleep(rateLimitSleep); + } catch (InterruptedException ex) { + // Can safely ignore this exception and retry. + } + } else { + callback.response(response); + return; + } + } + + // Retries exhausted. Return error. + callback.error(new RateLimitException(request, rateLimitRetry)); + } + }); + } } diff --git a/src/main/java/com/sendgrid/SendGridAPI.java b/src/main/java/com/sendgrid/SendGridAPI.java new file mode 100644 index 00000000..34599a7d --- /dev/null +++ b/src/main/java/com/sendgrid/SendGridAPI.java @@ -0,0 +1,91 @@ +package com.sendgrid; + +import java.io.IOException; +import java.util.Map; + +public interface SendGridAPI { + + /** + * Initializes SendGrid + * + * @param apiKey is your SendGrid API Key: https://app.sendgrid.com/settings/api_keys + */ + public void initializeSendGrid(String apiKey); + + /** + * Returns the library version + * + * @return the library version. + */ + public String getLibraryVersion(); + + /** + * Gets the version. + * + * @return returns the version. + */ + public String getVersion(); + + /** + * Sets the version. + * + * @param version the SendGrid version. + */ + public void setVersion(String version); + + /** + * Gets the request headers. + * @return returns a map of request headers. + */ + public Map getRequestHeaders(); + + /** + * Adds a request headers. + * + * @param key the key + * @param value the value + * @return returns a map of request headers. + */ + public Map addRequestHeader(String key, String value); + + /** + * Removes a request headers. + * + * @param key the key + * @return returns a map of request headers. + */ + public Map removeRequestHeader(String key); + + /** + * Gets the host. + * + * @return returns the host. + */ + public String getHost(); + + /** + * Sets the host. + * + * @param host the host to set + */ + public void setHost(String host); + + /** + * Class makeCall makes the call to the SendGrid API, override this method for + * testing. + * + * @param request the request + * @return returns a response. + * @throws IOException in case of network or marshal error. + */ + public Response makeCall(Request request) throws IOException; + + /** + * Class api sets up the request to the SendGrid API, this is main interface. + * + * @param request the request + * @return returns a response. + * @throws IOException in case of network or marshal error. + */ + public Response api(Request request) throws IOException; +} diff --git a/src/main/java/com/sendgrid/helpers/README.md b/src/main/java/com/sendgrid/helpers/README.md index 1bd745a4..8a2b905d 100644 --- a/src/main/java/com/sendgrid/helpers/README.md +++ b/src/main/java/com/sendgrid/helpers/README.md @@ -10,7 +10,7 @@ Run the [example](https://github.com/sendgrid/sendgrid-java/tree/master/examples ```bash cd examples/mail -javac -classpath ../examples/jackson-annotations-2.7.0.jar:../examples/jackson-databind-2.7.3.jar:../examples/jackson-core-2.7.3.jar:../../build/libs/sendgrid-3.0.0-jar.jar:. Example.java && java -classpath ../examples/jackson-annotations-2.7.0.jar:../examples/jackson-databind-2.7.3.jar:../examples/jackson-core-2.7.3.jar:../../build/libs/sendgrid-3.0.0-jar.jar:. Example +javac -classpath ../../build/libs/sendgrid-4.2.1-jar.jar:. Example.java && java -classpath ../examples/jackson-core-2.9.5.jar:../../build/libs/sendgrid-4.1.0-jar.jar:. Example ``` ## Usage diff --git a/src/main/java/com/sendgrid/helpers/mail/Mail.java b/src/main/java/com/sendgrid/helpers/mail/Mail.java index db4c5134..ef874193 100644 --- a/src/main/java/com/sendgrid/helpers/mail/Mail.java +++ b/src/main/java/com/sendgrid/helpers/mail/Mail.java @@ -1,16 +1,11 @@ -package com.sendgrid; +package com.sendgrid.helpers.mail; -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; - import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.ObjectWriter; import com.fasterxml.jackson.databind.SerializationFeature; +import com.sendgrid.helpers.mail.objects.*; import java.io.IOException; import java.util.ArrayList; @@ -19,26 +14,92 @@ import java.util.Map; /** - * Class Mail builds an object that sends an email through SendGrid. - */ + * Class Mail builds an object that sends an email through SendGrid. + * Note that this object is not thread safe. + */ @JsonInclude(Include.NON_DEFAULT) public class Mail { + + /** The email's from field. */ @JsonProperty("from") public Email from; + + /** The email's subject line. This is the global, or + * “message level”, subject of your email. This may + * be overridden by personalizations[x].subject. + */ @JsonProperty("subject") public String subject; + + /** + * The email's personalization. Each object within + * personalizations can be thought of as an envelope + * - it defines who should receive an individual message + * and how that message should be handled. + */ @JsonProperty("personalizations") public List personalization; + + /** The email's content. */ @JsonProperty("content") public List content; + + /** The email's attachments. */ @JsonProperty("attachments") public List attachments; + + /** The email's template ID. */ @JsonProperty("template_id") public String templateId; + + /** + * The email's sections. An object of key/value pairs that + * define block sections of code to be used as substitutions. + */ @JsonProperty("sections") public Map sections; + + /** The email's headers. */ @JsonProperty("headers") public Map headers; + + /** The email's categories. */ @JsonProperty("categories") public List categories; + + /** + * The email's custom arguments. Values that are specific to + * the entire send that will be carried along with the email + * and its activity data. Substitutions will not be made on + * custom arguments, so any string that is entered into this + * parameter will be assumed to be the custom argument that + * you would like to be used. This parameter is overridden by + * personalizations[x].custom_args if that parameter has been + * defined. Total custom args size may not exceed 10,000 bytes. + */ @JsonProperty("custom_args") public Map customArgs; + + /** + * A unix timestamp allowing you to specify when you want + * your email to be delivered. This may be overridden by + * the personalizations[x].send_at parameter. Scheduling + * more than 72 hours in advance is forbidden. + */ @JsonProperty("send_at") public long sendAt; + + /** + * This ID represents a batch of emails to be sent at the + * same time. Including a batch_id in your request allows + * you include this email in that batch, and also enables + * you to cancel or pause the delivery of that batch. For + * more information, see https://sendgrid.com/docs/API_Reference/Web_API_v3/cancel_schedule_send. + */ @JsonProperty("batch_id") public String batchId; + + /** The email's unsubscribe handling object. */ @JsonProperty("asm") public ASM asm; + + /** The email's IP pool name. */ @JsonProperty("ip_pool_name") public String ipPoolId; + + /** The email's mail settings. */ @JsonProperty("mail_settings") public MailSettings mailSettings; + + /** The email's tracking settings. */ @JsonProperty("tracking_settings") public TrackingSettings trackingSettings; + + /** The email's reply to address. */ @JsonProperty("reply_to") public Email replyTo; private static final ObjectMapper SORTED_MAPPER = new ObjectMapper(); @@ -46,10 +107,40 @@ public class Mail { SORTED_MAPPER.configure(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS, true); } + private List addToList(T element, List defaultList) { + if (defaultList != null) { + defaultList.add(element); + return defaultList; + } else { + List list = new ArrayList(); + list.add(element); + return list; + } + } + + private Map addToMap(K key, V value, Map defaultMap) { + if (defaultMap != null) { + defaultMap.put(key, value); + return defaultMap; + } else { + Map map = new HashMap(); + map.put(key, value); + return map; + } + } + + /** Construct a new Mail object. */ public Mail() { return; } + /** + * Construct a new Mail object. + * @param from the email's from address. + * @param subject the email's subject line. + * @param to the email's recipient. + * @param content the email's content. + */ public Mail(Email from, String subject, Email to, Content content) { this.setFrom(from); @@ -60,69 +151,110 @@ public Mail(Email from, String subject, Email to, Content content) this.addContent(content); } + /** + * Get the email's from address. + * @return the email's from address. + */ @JsonProperty("from") - public Email getFrom(Email from) { - return from; + public Email getFrom() { + return this.from; } + /** + * Set the email's from address. + * @param from the email's from address. + */ public void setFrom(Email from) { this.from = from; } + /** + * Get the email's subject line. + * @return the email's subject line. + */ @JsonProperty("subject") public String getSubject() { return subject; } + /** + * Set the email's subject line. + * @param subject the email's subject line. + */ public void setSubject(String subject) { this.subject = subject; } + /** + * Get the email's unsubscribe handling object (ASM). + * @return the email's ASM. + */ @JsonProperty("asm") public ASM getASM() { return asm; } + /** + * Set the email's unsubscribe handling object (ASM). + * @param asm the email's ASM. + */ public void setASM(ASM asm) { this.asm = asm; } + /** + * Get the email's personalizations. Content added to the returned + * list will be included when sent. + * @return the email's personalizations. + */ @JsonProperty("personalizations") public List getPersonalization() { return personalization; } + /** + * Add a personalizaton to the email. + * @param personalization a personalization. + */ public void addPersonalization(Personalization personalization) { - if (this.personalization == null) { - this.personalization = new ArrayList(); - this.personalization.add(personalization); - } else { - this.personalization.add(personalization); - } + this.personalization = addToList(personalization, this.personalization); } + /** + * Get the email's content. Content added to the returned list + * will be included when sent. + * @return the email's content. + */ @JsonProperty("content") public List getContent() { return content; } + /** + * Add content to this email. + * @param content content to add to this email. + */ public void addContent(Content content) { Content newContent = new Content(); newContent.setType(content.getType()); newContent.setValue(content.getValue()); - if (this.content == null) { - this.content = new ArrayList(); - this.content.add(newContent); - } else { - this.content.add(newContent); - } + this.content = addToList(newContent, this.content); } + /** + * Get the email's attachments. Attachments added to the returned + * list will be included when sent. + * @return the email's attachments. + */ @JsonProperty("attachments") public List getAttachments() { return attachments; } + /** + * Add attachments to the email. + * @param attachments attachments to add. + */ public void addAttachments(Attachments attachments) { Attachments newAttachment = new Attachments(); newAttachment.setContent(attachments.getContent()); @@ -130,137 +262,208 @@ public void addAttachments(Attachments attachments) { newAttachment.setFilename(attachments.getFilename()); newAttachment.setDisposition(attachments.getDisposition()); newAttachment.setContentId(attachments.getContentId()); - if (this.attachments == null) { - this.attachments = new ArrayList(); - this.attachments.add(newAttachment); - } else { - this.attachments.add(newAttachment); - } + this.attachments = addToList(newAttachment, this.attachments); } + /** + * Get the email's template ID. + * @return the email's template ID. + */ @JsonProperty("template_id") public String getTemplateId() { return this.templateId; } + /** + * Set the email's template ID. + * @param templateId the email's template ID. + */ public void setTemplateId(String templateId) { this.templateId = templateId; } + /** + * Get the email's sections. Sections added to the returned list + * will be included when sent. + * @return the email's sections. + */ @JsonProperty("sections") public Map getSections() { return sections; } + /** + * Add a section to the email. + * @param key the section's key. + * @param value the section's value. + */ public void addSection(String key, String value) { - if (sections == null) { - sections = new HashMap(); - sections.put(key, value); - } else { - sections.put(key, value); - } + this.sections = addToMap(key, value, this.sections); } + /** + * Get the email's headers. Headers added to the returned list + * will be included when sent. + * @return the email's headers. + */ @JsonProperty("headers") public Map getHeaders() { return headers; } - + /** + * Add a header to the email. + * @param key the header's key. + * @param value the header's value. + */ public void addHeader(String key, String value) { - if (headers == null) { - headers = new HashMap(); - headers.put(key, value); - } else { - headers.put(key, value); - } + this.headers = addToMap(key, value, this.headers); } + /** + * Get the email's categories. Categories added to the returned list + * will be included when sent. + * @return the email's categories. + */ @JsonProperty("categories") public List getCategories() { return categories; } + /** + * Add a category to the email. + * @param category the category. + */ public void addCategory(String category) { - if (categories == null) { - categories = new ArrayList(); - categories.add(category); - } else { - categories.add(category); - } + this.categories = addToList(category, this.categories); } + /** + * Get the email's custom arguments. Custom arguments added to the returned list + * will be included when sent. + * @return the email's custom arguments. + */ @JsonProperty("custom_args") public Map getCustomArgs() { return customArgs; } + /** + * Add a custom argument to the email. + * @param key argument's key. + * @param value the argument's value. + */ public void addCustomArg(String key, String value) { - if (customArgs == null) { - customArgs = new HashMap(); - customArgs.put(key, value); - } else { - customArgs.put(key, value); - } + this.customArgs = addToMap(key, value, this.customArgs); } + /** + * Get the email's send at time (Unix timestamp). + * @return the email's send at time. + */ @JsonProperty("send_at") public long sendAt() { return sendAt; } + /** + * Set the email's send at time (Unix timestamp). + * @param sendAt the send at time. + */ public void setSendAt(long sendAt) { this.sendAt = sendAt; } + /** + * Get the email's batch ID. + * @return the batch ID. + */ @JsonProperty("batch_id") public String getBatchId() { return batchId; } + /** + * Set the email's batch ID. + * @param batchId the batch ID. + */ public void setBatchId(String batchId) { this.batchId = batchId; } + /** + * Get the email's IP pool ID. + * @return the IP pool ID. + */ @JsonProperty("ip_pool_name") public String getIpPoolId() { return ipPoolId; } + /** + * Set the email's IP pool ID. + * @param ipPoolId the IP pool ID. + */ public void setIpPoolId(String ipPoolId) { this.ipPoolId = ipPoolId; } + /** + * Get the email's settings. + * @return the settings. + */ @JsonProperty("mail_settings") public MailSettings getMailSettings() { return mailSettings; } + /** + * Set the email's settings. + * @param mailSettings the settings. + */ public void setMailSettings(MailSettings mailSettings) { this.mailSettings = mailSettings; } + /** + * Get the email's tracking settings. + * @return the tracking settings. + */ @JsonProperty("tracking_settings") public TrackingSettings getTrackingSettings() { return trackingSettings; } + /** + * Set the email's tracking settings. + * @param trackingSettings the tracking settings. + */ public void setTrackingSettings(TrackingSettings trackingSettings) { this.trackingSettings = trackingSettings; } + /** + * Get the email's reply to address. + * @return the reply to address. + */ @JsonProperty("reply_to") public Email getReplyto() { return replyTo; } + /** + * Set the email's reply to address. + * @param replyTo the reply to address. + */ public void setReplyTo(Email replyTo) { this.replyTo = replyTo; } /** - * Create a string represenation of the Mail object JSON. - */ + * Create a string represenation of the Mail object JSON. + * @return a JSON string. + * @throws IOException in case of a JSON marshal error. + */ public String build() throws IOException { try { //ObjectMapper mapper = new ObjectMapper(); @@ -271,8 +474,10 @@ public String build() throws IOException { } /** - * Create a string represenation of the Mail object JSON and pretty print it. - */ + * Create a string represenation of the Mail object JSON and pretty print it. + * @return a pretty JSON string. + * @throws IOException in case of a JSON marshal error. + */ public String buildPretty() throws IOException { try { ObjectMapper mapper = new ObjectMapper(); @@ -281,4 +486,74 @@ public String buildPretty() throws IOException { throw ex; } } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((batchId == null) ? 0 : batchId.hashCode()); + result = prime * result + ((categories == null) ? 0 : categories.hashCode()); + result = prime * result + ((customArgs == null) ? 0 : customArgs.hashCode()); + result = prime * result + ((headers == null) ? 0 : headers.hashCode()); + result = prime * result + ((ipPoolId == null) ? 0 : ipPoolId.hashCode()); + result = prime * result + ((sections == null) ? 0 : sections.hashCode()); + result = prime * result + (int) (sendAt ^ (sendAt >>> 32)); + result = prime * result + ((subject == null) ? 0 : subject.hashCode()); + result = prime * result + ((templateId == null) ? 0 : templateId.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Mail other = (Mail) obj; + if (batchId == null) { + if (other.batchId != null) + return false; + } else if (!batchId.equals(other.batchId)) + return false; + if (categories == null) { + if (other.categories != null) + return false; + } else if (!categories.equals(other.categories)) + return false; + if (customArgs == null) { + if (other.customArgs != null) + return false; + } else if (!customArgs.equals(other.customArgs)) + return false; + if (headers == null) { + if (other.headers != null) + return false; + } else if (!headers.equals(other.headers)) + return false; + if (ipPoolId == null) { + if (other.ipPoolId != null) + return false; + } else if (!ipPoolId.equals(other.ipPoolId)) + return false; + if (sections == null) { + if (other.sections != null) + return false; + } else if (!sections.equals(other.sections)) + return false; + if (sendAt != other.sendAt) + return false; + if (subject == null) { + if (other.subject != null) + return false; + } else if (!subject.equals(other.subject)) + return false; + if (templateId == null) { + if (other.templateId != null) + return false; + } else if (!templateId.equals(other.templateId)) + return false; + return true; + } } \ No newline at end of file diff --git a/src/main/java/com/sendgrid/helpers/mail/objects/ASM.java b/src/main/java/com/sendgrid/helpers/mail/objects/ASM.java index 1a65a65d..a34895f2 100644 --- a/src/main/java/com/sendgrid/helpers/mail/objects/ASM.java +++ b/src/main/java/com/sendgrid/helpers/mail/objects/ASM.java @@ -1,4 +1,4 @@ -package com.sendgrid; +package com.sendgrid.helpers.mail.objects; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; @@ -28,4 +28,29 @@ public int[] getGroupsToDisplay() { public void setGroupsToDisplay(int[] groupsToDisplay) { this.groupsToDisplay = Arrays.copyOf(groupsToDisplay, groupsToDisplay.length); } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + groupId; + result = prime * result + Arrays.hashCode(groupsToDisplay); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + ASM other = (ASM) obj; + if (groupId != other.groupId) + return false; + if (!Arrays.equals(groupsToDisplay, other.groupsToDisplay)) + return false; + return true; + } } \ No newline at end of file diff --git a/src/main/java/com/sendgrid/helpers/mail/objects/Attachments.java b/src/main/java/com/sendgrid/helpers/mail/objects/Attachments.java index 46c779f4..969c1630 100644 --- a/src/main/java/com/sendgrid/helpers/mail/objects/Attachments.java +++ b/src/main/java/com/sendgrid/helpers/mail/objects/Attachments.java @@ -1,59 +1,290 @@ -package com.sendgrid; +package com.sendgrid.helpers.mail.objects; +import com.fasterxml.jackson.annotation.JsonIgnoreType; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.annotation.JsonProperty; +import org.apache.commons.codec.binary.Base64; +import java.io.*; + +/** + * An attachment object. + */ @JsonInclude(Include.NON_DEFAULT) public class Attachments { + + /** The attachment content. */ @JsonProperty("content") private String content; + + /** + * The mime type of the content you are attaching. For example, + * “text/plain” or “text/html”. + */ @JsonProperty("type") private String type; + + /** The attachment file name. */ @JsonProperty("filename") private String filename; + + /** The attachment disposition. */ @JsonProperty("disposition") private String disposition; + + /** + * The attachment content ID. This is used when the + * disposition is set to “inline” and the attachment + * is an image, allowing the file to be displayed within + * the body of your email. + */ @JsonProperty("content_id") private String contentId; + /** + * Get the attachment's content. + * @return the content. + */ @JsonProperty("content") public String getContent() { return content; } + /** + * Set the attachment's content. + * @param content the content. + */ public void setContent(String content) { this.content = content; } + /** + * Get the mime type of the content you are attaching. For example, + * “text/plain” or “text/html”. + * @return the mime type. + */ @JsonProperty("type") public String getType() { return type; } + /** + * Set the mime type of the content. + * @param type the mime type. + */ public void setType(String type) { this.type = type; } + /** + * Get the filename for this attachment. + * @return the file name. + */ @JsonProperty("filename") public String getFilename() { return filename; } + /** + * Set the filename for this attachment. + * @param filename the filename. + */ public void setFilename(String filename) { this.filename = filename; } + /** + * Get the content-disposition of the attachment specifying + * how you would like the attachment to be displayed. + * For example, “inline” results in the attached file + * being displayed automatically within the message + * while “attachment” results in the attached file + * requiring some action to be taken before it is + * displayed (e.g. opening or downloading the file). + * @return the disposition. + */ @JsonProperty("disposition") public String getDisposition() { return disposition; } + /** + * Set the content-disposition of the attachment. + * @param disposition the disposition. + */ public void setDisposition(String disposition) { this.disposition = disposition; } + /** + * Get the attachment content ID. This is used when the + * disposition is set to “inline” and the attachment + * is an image, allowing the file to be displayed within + * the body of your email. + * @return the content ID. + */ @JsonProperty("content_id") public String getContentId() { return contentId; } + /** + * Set the content ID. + * @param contentId the content ID. + */ public void setContentId(String contentId) { this.contentId = contentId; } + + /** + * A helper object to construct usable attachments. + */ + @JsonIgnoreType + public static class Builder { + + private static final int BYTE_BUFFER_SIZE = 4096; + + private String fileName; + private String content; + private String type; + private String disposition; + private String contentId; + + /** + * Construct a new attachment builder. + * @param fileName the filename to include. + * @param content an input stream for the content. + * @throws IllegalArgumentException in case either the fileName or the content is null. + */ + public Builder(String fileName, InputStream content) { + if (fileName == null) { + throw new IllegalArgumentException("File name mustn't be null"); + } + + if (content == null) { + throw new IllegalArgumentException("Content mustn't be null"); + } + + this.fileName = fileName; + this.content = encodeToBase64(content); + } + + /** + * Construct a new attachment builder. + * @param fileName the filename to include. + * @param content an input string for the content. + * @throws IllegalArgumentException in case either the fileName or the content is null. + */ + public Builder(String fileName, String content) { + if (fileName == null) { + throw new IllegalArgumentException("File name mustn't be null"); + } + + if (content == null) { + throw new IllegalArgumentException("Content mustn't be null"); + } + + this.fileName = fileName; + this.content = content; + } + + private String encodeToBase64(InputStream content) { + int read = 0; + byte[] bytes = new byte[BYTE_BUFFER_SIZE]; + try(ByteArrayOutputStream baos = new ByteArrayOutputStream()) { + while ((read = content.read(bytes)) != -1) { + baos.write(bytes, 0, read); + } + + return Base64.encodeBase64String(baos.toByteArray()); + } catch (IOException e) { + throw new RuntimeException("Unable to convert content stream to base 64 encoded string", e); + } + } + + /** + * Set the type of this attachment builder. + * @param type the attachment type. + */ + public Builder withType(String type) { + this.type = type; + return this; + } + + /** + * Set the disposition of this attachment builder. + * @param disposition the disposition. + */ + public Builder withDisposition(String disposition) { + this.disposition = disposition; + return this; + } + + /** + * Set the content ID of this attachment builder. + * @param contentId the content ID. + */ + public Builder withContentId(String contentId) { + this.contentId = contentId; + return this; + } + + /** + * Construct the attachments object. + */ + public Attachments build() { + Attachments attachments = new Attachments(); + attachments.setContent(content); + attachments.setFilename(fileName); + attachments.setDisposition(disposition); + attachments.setContentId(contentId); + attachments.setType(type); + return attachments; + } + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((content == null) ? 0 : content.hashCode()); + result = prime * result + ((contentId == null) ? 0 : contentId.hashCode()); + result = prime * result + ((disposition == null) ? 0 : disposition.hashCode()); + result = prime * result + ((filename == null) ? 0 : filename.hashCode()); + result = prime * result + ((type == null) ? 0 : type.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Attachments other = (Attachments) obj; + if (content == null) { + if (other.content != null) + return false; + } else if (!content.equals(other.content)) + return false; + if (contentId == null) { + if (other.contentId != null) + return false; + } else if (!contentId.equals(other.contentId)) + return false; + if (disposition == null) { + if (other.disposition != null) + return false; + } else if (!disposition.equals(other.disposition)) + return false; + if (filename == null) { + if (other.filename != null) + return false; + } else if (!filename.equals(other.filename)) + return false; + if (type == null) { + if (other.type != null) + return false; + } else if (!type.equals(other.type)) + return false; + return true; + } } 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 176387fa..f43803f1 100644 --- a/src/main/java/com/sendgrid/helpers/mail/objects/BccSettings.java +++ b/src/main/java/com/sendgrid/helpers/mail/objects/BccSettings.java @@ -1,10 +1,15 @@ -package com.sendgrid; +package com.sendgrid.helpers.mail.objects; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.annotation.JsonProperty; -@JsonInclude(Include.NON_DEFAULT) +/** + * This object allows you to have a blind carbon copy + * automatically sent to the specified email address + * for every email that is sent. + */ +@JsonInclude(Include.NON_EMPTY) public class BccSettings { @JsonProperty("enable") private boolean enable; @JsonProperty("email") private String email; @@ -26,4 +31,32 @@ public String getEmail() { public void setEmail(String email) { this.email = email; } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((email == null) ? 0 : email.hashCode()); + result = prime * result + (enable ? 1231 : 1237); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + BccSettings other = (BccSettings) obj; + if (email == null) { + if (other.email != null) + return false; + } else if (!email.equals(other.email)) + return false; + if (enable != other.enable) + return false; + return true; + } } \ No newline at end of file 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 839c8fbf..ee12fc07 100644 --- a/src/main/java/com/sendgrid/helpers/mail/objects/ClickTrackingSetting.java +++ b/src/main/java/com/sendgrid/helpers/mail/objects/ClickTrackingSetting.java @@ -1,10 +1,14 @@ -package com.sendgrid; +package com.sendgrid.helpers.mail.objects; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.annotation.JsonProperty; -@JsonInclude(Include.NON_DEFAULT) +/** + * 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; @@ -26,4 +30,29 @@ public boolean getEnableText() { public void setEnableText(boolean enableText) { this.enableText = enableText; } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + (enable ? 1231 : 1237); + result = prime * result + (enableText ? 1231 : 1237); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + ClickTrackingSetting other = (ClickTrackingSetting) obj; + if (enable != other.enable) + return false; + if (enableText != other.enableText) + return false; + return true; + } } \ No newline at end of file diff --git a/src/main/java/com/sendgrid/helpers/mail/objects/Content.java b/src/main/java/com/sendgrid/helpers/mail/objects/Content.java index b00f9566..0a7a6557 100644 --- a/src/main/java/com/sendgrid/helpers/mail/objects/Content.java +++ b/src/main/java/com/sendgrid/helpers/mail/objects/Content.java @@ -1,9 +1,20 @@ -package com.sendgrid; +package com.sendgrid.helpers.mail.objects; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.regex.Pattern; +import java.lang.IllegalArgumentException; + +/** + * An object in which you may specify the content of your email. + */ @JsonInclude(Include.NON_DEFAULT) public class Content { @JsonProperty("type") private String type; @@ -33,6 +44,52 @@ public String getValue() { } public void setValue(String value) { + ContentVerifier.verifyContent(value); this.value = value; } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((type == null) ? 0 : type.hashCode()); + result = prime * result + ((value == null) ? 0 : value.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Content other = (Content) obj; + if (type == null) { + if (other.type != null) + return false; + } else if (!type.equals(other.type)) + return false; + if (value == null) { + if (other.value != null) + return false; + } else if (!value.equals(other.value)) + return false; + return true; + } +} + +class ContentVerifier { + private static final List FORBIDDEN_PATTERNS = Collections.singletonList( + Pattern.compile(".*SG\\.[a-zA-Z0-9(-|_)]*\\.[a-zA-Z0-9(-|_)]*.*") + ); + + static void verifyContent(String content) { + for (Pattern pattern: FORBIDDEN_PATTERNS) { + if (pattern.matcher(content).matches()) { + throw new IllegalArgumentException("Found a Forbidden Pattern in the content of the email"); + } + } + } } \ No newline at end of file diff --git a/src/main/java/com/sendgrid/helpers/mail/objects/Email.java b/src/main/java/com/sendgrid/helpers/mail/objects/Email.java index 43396a85..537b27b6 100644 --- a/src/main/java/com/sendgrid/helpers/mail/objects/Email.java +++ b/src/main/java/com/sendgrid/helpers/mail/objects/Email.java @@ -1,4 +1,4 @@ -package com.sendgrid; +package com.sendgrid.helpers.mail.objects; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; @@ -39,4 +39,35 @@ public String getEmail() { public void setEmail(String email) { this.email = email; } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((email == null) ? 0 : email.hashCode()); + result = prime * result + ((name == null) ? 0 : name.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Email other = (Email) obj; + if (email == null) { + if (other.email != null) + return false; + } else if (!email.equals(other.email)) + return false; + if (name == null) { + if (other.name != null) + return false; + } else if (!name.equals(other.name)) + return false; + return true; + } } \ No newline at end of file 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 8e542c7f..905436ed 100644 --- a/src/main/java/com/sendgrid/helpers/mail/objects/FooterSetting.java +++ b/src/main/java/com/sendgrid/helpers/mail/objects/FooterSetting.java @@ -1,10 +1,14 @@ -package com.sendgrid; +package com.sendgrid.helpers.mail.objects; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.annotation.JsonProperty; -@JsonInclude(Include.NON_DEFAULT) +/** + * An object representing the default footer + * that you would like included on every email. + */ +@JsonInclude(Include.NON_EMPTY) public class FooterSetting { @JsonProperty("enable") private boolean enable; @JsonProperty("text") private String text; @@ -36,4 +40,38 @@ public String getHtml() { public void setHtml(String html) { this.html = html; } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + (enable ? 1231 : 1237); + result = prime * result + ((html == null) ? 0 : html.hashCode()); + result = prime * result + ((text == null) ? 0 : text.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + FooterSetting other = (FooterSetting) obj; + if (enable != other.enable) + return false; + if (html == null) { + if (other.html != null) + return false; + } else if (!html.equals(other.html)) + return false; + if (text == null) { + if (other.text != null) + return false; + } else if (!text.equals(other.text)) + return false; + return true; + } } \ No newline at end of file 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 ce30edbc..a01d4df6 100644 --- a/src/main/java/com/sendgrid/helpers/mail/objects/GoogleAnalyticsSetting.java +++ b/src/main/java/com/sendgrid/helpers/mail/objects/GoogleAnalyticsSetting.java @@ -1,10 +1,13 @@ -package com.sendgrid; +package com.sendgrid.helpers.mail.objects; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.annotation.JsonProperty; -@JsonInclude(Include.NON_DEFAULT) +/** + * An object configuring the tracking provided by Google Analytics. + */ +@JsonInclude(Include.NON_EMPTY) public class GoogleAnalyticsSetting { @JsonProperty("enable") private boolean enable; @JsonProperty("utm_source") private String campaignSource; @@ -66,4 +69,56 @@ public String getCampaignMedium() { public void setCampaignMedium(String campaignMedium) { this.campaignMedium = campaignMedium; } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((campaignContent == null) ? 0 : campaignContent.hashCode()); + result = prime * result + ((campaignMedium == null) ? 0 : campaignMedium.hashCode()); + result = prime * result + ((campaignName == null) ? 0 : campaignName.hashCode()); + result = prime * result + ((campaignSource == null) ? 0 : campaignSource.hashCode()); + result = prime * result + ((campaignTerm == null) ? 0 : campaignTerm.hashCode()); + result = prime * result + (enable ? 1231 : 1237); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + GoogleAnalyticsSetting other = (GoogleAnalyticsSetting) obj; + if (campaignContent == null) { + if (other.campaignContent != null) + return false; + } else if (!campaignContent.equals(other.campaignContent)) + return false; + if (campaignMedium == null) { + if (other.campaignMedium != null) + return false; + } else if (!campaignMedium.equals(other.campaignMedium)) + return false; + if (campaignName == null) { + if (other.campaignName != null) + return false; + } else if (!campaignName.equals(other.campaignName)) + return false; + if (campaignSource == null) { + if (other.campaignSource != null) + return false; + } else if (!campaignSource.equals(other.campaignSource)) + return false; + if (campaignTerm == null) { + if (other.campaignTerm != null) + return false; + } else if (!campaignTerm.equals(other.campaignTerm)) + return false; + if (enable != other.enable) + return false; + return true; + } } \ No newline at end of file diff --git a/src/main/java/com/sendgrid/helpers/mail/objects/MailSettings.java b/src/main/java/com/sendgrid/helpers/mail/objects/MailSettings.java index 63580458..5175642c 100644 --- a/src/main/java/com/sendgrid/helpers/mail/objects/MailSettings.java +++ b/src/main/java/com/sendgrid/helpers/mail/objects/MailSettings.java @@ -1,9 +1,15 @@ -package com.sendgrid; +package com.sendgrid.helpers.mail.objects; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.annotation.JsonProperty; +/** + * An object representing a collection of different mail + * settings that you can use to specify how you would + * like this email to be handled. + */ + @JsonInclude(Include.NON_DEFAULT) public class MailSettings { @JsonProperty("bcc") private BccSettings bccSettings; @@ -16,11 +22,24 @@ public class MailSettings { public BccSettings getBccSettings() { return bccSettings; } - + + /** + * Set the BCC settings. + * @param bccSettings the BCC settings. + */ public void setBccSettings(BccSettings bccSettings) { this.bccSettings = bccSettings; } - + + /** + * A setting that allows you to bypass all unsubscribe + * groups and suppressions to ensure that the email is + * delivered to every single recipient. This should only + * be used in emergencies when it is absolutely necessary + * that every recipient receives your email. + * @return the bypass list setting. + */ + @JsonProperty("bypass_list_management") public Setting getBypassListManagement() { return bypassListManagement; @@ -29,31 +48,112 @@ public Setting getBypassListManagement() { public void setBypassListManagement(Setting bypassListManagement) { this.bypassListManagement = bypassListManagement; } - + + /** + * Get the the footer settings that you would like included on every email. + * @return the setting. + */ + @JsonProperty("footer") public FooterSetting getFooterSetting() { return footerSetting; } - + + /** + * Set the the footer settings that you would like included on every email. + * @param footerSetting the setting. + */ public void setFooterSetting(FooterSetting footerSetting) { this.footerSetting = footerSetting; } - + + /** + * Get sandbox mode. This allows you to send a test email to + * ensure that your request body is valid and formatted correctly. + * @return the sandbox mode setting. + */ + @JsonProperty("sandbox_mode") public Setting getSandBoxMode() { return sandBoxMode; } - + + /** + * Set sandbox mode. + * @param sandBoxMode the sandbox mode setting. + */ + @JsonProperty("sandbox_mode") public void setSandboxMode(Setting sandBoxMode) { this.sandBoxMode = sandBoxMode; } - + + /** + * Get the spam check setting. This allows you to test the + * content of your email for spam. + * @return the spam check setting. + */ + @JsonProperty("spam_check") public SpamCheckSetting getSpamCheck() { return spamCheckSetting; } - + + /** + * Set the spam check setting. This allows you to test the + * content of your email for spam. + * @param spamCheckSetting the spam check setting. + */ + public void setSpamCheckSetting(SpamCheckSetting spamCheckSetting) { this.spamCheckSetting = spamCheckSetting; } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((bccSettings == null) ? 0 : bccSettings.hashCode()); + result = prime * result + ((bypassListManagement == null) ? 0 : bypassListManagement.hashCode()); + result = prime * result + ((footerSetting == null) ? 0 : footerSetting.hashCode()); + result = prime * result + ((sandBoxMode == null) ? 0 : sandBoxMode.hashCode()); + result = prime * result + ((spamCheckSetting == null) ? 0 : spamCheckSetting.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + MailSettings other = (MailSettings) obj; + if (bccSettings == null) { + if (other.bccSettings != null) + return false; + } else if (!bccSettings.equals(other.bccSettings)) + return false; + if (bypassListManagement == null) { + if (other.bypassListManagement != null) + return false; + } else if (!bypassListManagement.equals(other.bypassListManagement)) + return false; + if (footerSetting == null) { + if (other.footerSetting != null) + return false; + } else if (!footerSetting.equals(other.footerSetting)) + return false; + if (sandBoxMode == null) { + if (other.sandBoxMode != null) + return false; + } else if (!sandBoxMode.equals(other.sandBoxMode)) + return false; + if (spamCheckSetting == null) { + if (other.spamCheckSetting != null) + return false; + } else if (!spamCheckSetting.equals(other.spamCheckSetting)) + return false; + return true; + } } \ No newline at end of file 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 aeb7ede1..e4497d9c 100644 --- a/src/main/java/com/sendgrid/helpers/mail/objects/OpenTrackingSetting.java +++ b/src/main/java/com/sendgrid/helpers/mail/objects/OpenTrackingSetting.java @@ -1,10 +1,16 @@ -package com.sendgrid; +package com.sendgrid.helpers.mail.objects; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.annotation.JsonProperty; -@JsonInclude(Include.NON_DEFAULT) +/** + * An open tracking settings object. This allows you to track + * whether the email was opened or not, but including a single + * pixel image in the body of the content. When the pixel is + * loaded, we can log that the email was opened. + */ +@JsonInclude(Include.NON_EMPTY) public class OpenTrackingSetting { @JsonProperty("enable") private boolean enable; @JsonProperty("substitution_tag") private String substitutionTag; @@ -26,4 +32,33 @@ public String getSubstitutionTag() { public void setSubstitutionTag(String substitutionTag) { this.substitutionTag = substitutionTag; } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + (enable ? 1231 : 1237); + result = prime * result + ((substitutionTag == null) ? 0 : substitutionTag.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + OpenTrackingSetting other = (OpenTrackingSetting) obj; + if (enable != other.enable) + return false; + if (substitutionTag == null) { + if (other.substitutionTag != null) + return false; + } else if (!substitutionTag.equals(other.substitutionTag)) + return false; + return true; + } + } \ No newline at end of file diff --git a/src/main/java/com/sendgrid/helpers/mail/objects/Personalization.java b/src/main/java/com/sendgrid/helpers/mail/objects/Personalization.java index 50dcafc5..9a91db5d 100644 --- a/src/main/java/com/sendgrid/helpers/mail/objects/Personalization.java +++ b/src/main/java/com/sendgrid/helpers/mail/objects/Personalization.java @@ -1,9 +1,10 @@ -package com.sendgrid; +package com.sendgrid.helpers.mail.objects; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.Collections; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -18,10 +19,13 @@ public class Personalization { @JsonProperty("headers") private Map headers; @JsonProperty("substitutions") private Map substitutions; @JsonProperty("custom_args") private Map customArgs; + @JsonProperty("dynamic_template_data") private Map dynamicTemplateData; @JsonProperty("send_at") private long sendAt; @JsonProperty("to") public List getTos() { + if(tos == null) + return Collections.emptyList(); return tos; } @@ -39,6 +43,8 @@ public void addTo(Email email) { @JsonProperty("cc") public List getCcs() { + if(ccs == null) + return Collections.emptyList(); return ccs; } @@ -56,6 +62,8 @@ public void addCc(Email email) { @JsonProperty("bcc") public List getBccs() { + if(bccs == null) + return Collections.emptyList(); return bccs; } @@ -82,6 +90,8 @@ public void setSubject(String subject) { @JsonProperty("headers") public Map getHeaders() { + if(headers == null) + return Collections.emptyMap(); return headers; } @@ -96,6 +106,8 @@ public void addHeader(String key, String value) { @JsonProperty("substitutions") public Map getSubstitutions() { + if(substitutions == null) + return Collections.emptyMap(); return substitutions; } @@ -110,6 +122,8 @@ public void addSubstitution(String key, String value) { @JsonProperty("custom_args") public Map getCustomArgs() { + if(customArgs == null) + return Collections.emptyMap(); return customArgs; } @@ -130,4 +144,81 @@ public long sendAt() { public void setSendAt(long sendAt) { this.sendAt = sendAt; } -} \ No newline at end of file + + @JsonProperty("dynamic_template_data") + public Map getDynamicTemplateData() { + return dynamicTemplateData == null + ? Collections.emptyMap() : dynamicTemplateData; + } + + public void addDynamicTemplateData(String key, Object value) { + if (dynamicTemplateData == null) { + dynamicTemplateData = new HashMap(); + } + dynamicTemplateData.put(key, value); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((bccs == null) ? 0 : bccs.hashCode()); + result = prime * result + ((ccs == null) ? 0 : ccs.hashCode()); + result = prime * result + ((customArgs == null) ? 0 : customArgs.hashCode()); + result = prime * result + ((headers == null) ? 0 : headers.hashCode()); + result = prime * result + (int) (sendAt ^ (sendAt >>> 32)); + result = prime * result + ((subject == null) ? 0 : subject.hashCode()); + result = prime * result + ((substitutions == null) ? 0 : substitutions.hashCode()); + result = prime * result + ((tos == null) ? 0 : tos.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Personalization other = (Personalization) obj; + if (bccs == null) { + if (other.bccs != null) + return false; + } else if (!bccs.equals(other.bccs)) + return false; + if (ccs == null) { + if (other.ccs != null) + return false; + } else if (!ccs.equals(other.ccs)) + return false; + if (customArgs == null) { + if (other.customArgs != null) + return false; + } else if (!customArgs.equals(other.customArgs)) + return false; + if (headers == null) { + if (other.headers != null) + return false; + } else if (!headers.equals(other.headers)) + return false; + if (sendAt != other.sendAt) + return false; + if (subject == null) { + if (other.subject != null) + return false; + } else if (!subject.equals(other.subject)) + return false; + if (substitutions == null) { + if (other.substitutions != null) + return false; + } else if (!substitutions.equals(other.substitutions)) + return false; + if (tos == null) { + if (other.tos != null) + return false; + } else if (!tos.equals(other.tos)) + return false; + return true; + } +} diff --git a/src/main/java/com/sendgrid/helpers/mail/objects/Setting.java b/src/main/java/com/sendgrid/helpers/mail/objects/Setting.java index 5818a145..45bef3bb 100644 --- a/src/main/java/com/sendgrid/helpers/mail/objects/Setting.java +++ b/src/main/java/com/sendgrid/helpers/mail/objects/Setting.java @@ -1,4 +1,4 @@ -package com.sendgrid; +package com.sendgrid.helpers.mail.objects; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; @@ -16,4 +16,26 @@ public boolean getEnable() { public void setEnable(boolean enable) { this.enable = enable; } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + (enable ? 1231 : 1237); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Setting other = (Setting) obj; + if (enable != other.enable) + return false; + return true; + } } \ No newline at end of file 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 85d1dc10..d2cd79c1 100644 --- a/src/main/java/com/sendgrid/helpers/mail/objects/SpamCheckSetting.java +++ b/src/main/java/com/sendgrid/helpers/mail/objects/SpamCheckSetting.java @@ -1,10 +1,14 @@ -package com.sendgrid; +package com.sendgrid.helpers.mail.objects; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.annotation.JsonProperty; -@JsonInclude(Include.NON_DEFAULT) +/** + * A setting object that allows you to test the content of + * your email for spam. + */ +@JsonInclude(Include.NON_EMPTY) public class SpamCheckSetting { @JsonProperty("enable") private boolean enable; @JsonProperty("threshold") private int spamThreshold; @@ -36,4 +40,35 @@ public String getPostToUrl() { public void setPostToUrl(String postToUrl) { this.postToUrl = postToUrl; } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + (enable ? 1231 : 1237); + result = prime * result + ((postToUrl == null) ? 0 : postToUrl.hashCode()); + result = prime * result + spamThreshold; + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + SpamCheckSetting other = (SpamCheckSetting) obj; + if (enable != other.enable) + return false; + if (postToUrl == null) { + if (other.postToUrl != null) + return false; + } else if (!postToUrl.equals(other.postToUrl)) + return false; + if (spamThreshold != other.spamThreshold) + return false; + return true; + } } \ No newline at end of file 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 ad1121c2..6c438cc9 100644 --- a/src/main/java/com/sendgrid/helpers/mail/objects/SubscriptionTrackingSetting.java +++ b/src/main/java/com/sendgrid/helpers/mail/objects/SubscriptionTrackingSetting.java @@ -1,10 +1,17 @@ -package com.sendgrid; +package com.sendgrid.helpers.mail.objects; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.annotation.JsonProperty; -@JsonInclude(Include.NON_DEFAULT) +/** + * A subscription tracking setting object. Subscription tracking + * allows you to insert a subscription management link at the + * bottom of the text and html bodies of your email. If you + * would like to specify the location of the link within your + * email, you may use the substitution_tag. + */ +@JsonInclude(Include.NON_EMPTY) public class SubscriptionTrackingSetting { @JsonProperty("enable") private boolean enable; @JsonProperty("text") private String text; @@ -46,4 +53,44 @@ public String getSubstitutionTag() { public void setSubstitutionTag(String substitutionTag) { this.substitutionTag = substitutionTag; } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + (enable ? 1231 : 1237); + result = prime * result + ((html == null) ? 0 : html.hashCode()); + result = prime * result + ((substitutionTag == null) ? 0 : substitutionTag.hashCode()); + result = prime * result + ((text == null) ? 0 : text.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + SubscriptionTrackingSetting other = (SubscriptionTrackingSetting) obj; + if (enable != other.enable) + return false; + if (html == null) { + if (other.html != null) + return false; + } else if (!html.equals(other.html)) + return false; + if (substitutionTag == null) { + if (other.substitutionTag != null) + return false; + } else if (!substitutionTag.equals(other.substitutionTag)) + return false; + if (text == null) { + if (other.text != null) + return false; + } else if (!text.equals(other.text)) + return false; + return true; + } } \ No newline at end of file diff --git a/src/main/java/com/sendgrid/helpers/mail/objects/TrackingSettings.java b/src/main/java/com/sendgrid/helpers/mail/objects/TrackingSettings.java index 4da565d5..981875c8 100644 --- a/src/main/java/com/sendgrid/helpers/mail/objects/TrackingSettings.java +++ b/src/main/java/com/sendgrid/helpers/mail/objects/TrackingSettings.java @@ -1,4 +1,4 @@ -package com.sendgrid; +package com.sendgrid.helpers.mail.objects; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; @@ -46,4 +46,47 @@ public GoogleAnalyticsSetting getGoogleAnalyticsSetting() { public void setGoogleAnalyticsSetting(GoogleAnalyticsSetting googleAnalyticsSetting) { this.googleAnalyticsSetting = googleAnalyticsSetting; } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((clickTrackingSetting == null) ? 0 : clickTrackingSetting.hashCode()); + result = prime * result + ((googleAnalyticsSetting == null) ? 0 : googleAnalyticsSetting.hashCode()); + result = prime * result + ((openTrackingSetting == null) ? 0 : openTrackingSetting.hashCode()); + result = prime * result + ((subscriptionTrackingSetting == null) ? 0 : subscriptionTrackingSetting.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + TrackingSettings other = (TrackingSettings) obj; + if (clickTrackingSetting == null) { + if (other.clickTrackingSetting != null) + return false; + } else if (!clickTrackingSetting.equals(other.clickTrackingSetting)) + return false; + if (googleAnalyticsSetting == null) { + if (other.googleAnalyticsSetting != null) + return false; + } else if (!googleAnalyticsSetting.equals(other.googleAnalyticsSetting)) + return false; + if (openTrackingSetting == null) { + if (other.openTrackingSetting != null) + return false; + } else if (!openTrackingSetting.equals(other.openTrackingSetting)) + return false; + if (subscriptionTrackingSetting == null) { + if (other.subscriptionTrackingSetting != null) + return false; + } else if (!subscriptionTrackingSetting.equals(other.subscriptionTrackingSetting)) + return false; + return true; + } } \ No newline at end of file diff --git a/src/test/java/com/sendgrid/LicenseTest.java b/src/test/java/com/sendgrid/LicenseTest.java new file mode 100644 index 00000000..1e06bf71 --- /dev/null +++ b/src/test/java/com/sendgrid/LicenseTest.java @@ -0,0 +1,27 @@ +package com.sendgrid; + +import org.junit.Assert; +import org.junit.Test; + +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; +import java.util.Calendar; + +public class LicenseTest { + + @Test + public void testLicenseShouldHaveCorrectYear() throws IOException { + String copyrightText = null; + try (BufferedReader br = new BufferedReader(new FileReader("./LICENSE.md"))) { + for (String line; (line = br.readLine()) != null; ) { + if (line.startsWith("Copyright")) { + copyrightText = line; + break; + } + } + } + String expectedCopyright = String.format("Copyright (c) 2013-%d SendGrid, Inc.", Calendar.getInstance().get(Calendar.YEAR)); + Assert.assertEquals("License has incorrect year", copyrightText, expectedCopyright); + } +} diff --git a/src/test/java/com/sendgrid/MockSendGrid.java b/src/test/java/com/sendgrid/MockSendGrid.java index 006b27c7..35f65ae1 100644 --- a/src/test/java/com/sendgrid/MockSendGrid.java +++ b/src/test/java/com/sendgrid/MockSendGrid.java @@ -2,6 +2,7 @@ import java.io.IOException; import java.util.HashMap; +import java.util.Map; public class MockSendGrid extends SendGrid { Request request; @@ -13,10 +14,11 @@ public MockSendGrid(String apiKey) { public Response makeCall(Request request) throws IOException { this.request = request; Response response = new Response(); - response.statusCode = 200; - response.body = "{\"message\":\"success\"}"; - response.headers = new HashMap(); - response.headers.put("Test", "Header"); + response.setStatusCode(200); + response.setBody("{\"message\":\"success\"}"); + Map headers = new HashMap<>(); + headers.put("Test", "Header"); + response.setHeaders(headers); return response; } diff --git a/src/test/java/com/sendgrid/SendGridTest.java b/src/test/java/com/sendgrid/SendGridTest.java index a7856fda..7a3e9b22 100644 --- a/src/test/java/com/sendgrid/SendGridTest.java +++ b/src/test/java/com/sendgrid/SendGridTest.java @@ -1,15 +1,12 @@ package com.sendgrid; import org.junit.Assert; -import org.junit.Before; import org.junit.Test; -import java.io.BufferedReader; -import java.io.FileNotFoundException; -import java.io.FileReader; import java.io.IOException; import java.util.HashMap; import java.util.Map; +import static org.mockito.Mockito.*; public class SendGridTest { @@ -34,6 +31,15 @@ public void testInitialization() { Assert.assertEquals(sg.getRequestHeaders(), requestHeaders); } + @Test + public void testConstructWithClient() throws IOException { + Client client = mock(Client.class); + SendGrid sg = new SendGrid(SENDGRID_API_KEY, client); + Request request = new Request(); + sg.makeCall(request); + verify(client).api(request); + } + @Test public void testLibraryVersion() { SendGrid sg = new SendGrid(SENDGRID_API_KEY); @@ -68,9 +74,24 @@ public void testHost() { Assert.assertEquals(sg.getHost(), "api.new.com"); } + @Test + public void testRateLimitRetry() { + SendGrid sg = new SendGrid(SENDGRID_API_KEY); + sg.setRateLimitRetry(100); + Assert.assertEquals(sg.getRateLimitRetry(), 100); + } @Test - public void test_access_settings_activity_get() throws IOException { + public void testRateLimitSleep() { + SendGrid sg = new SendGrid(SENDGRID_API_KEY); + sg.setRateLimitSleep(999); + Assert.assertEquals(sg.getRateLimitSleep(), 999); + } + + + @Test + public void test_async() { + final Object sync = new Object(); SendGrid sg = null; if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { sg = new SendGrid("SENDGRID_API_KEY"); @@ -82,17 +103,40 @@ public void test_access_settings_activity_get() throws IOException { sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "access_settings/activity"; - Map queryParams = new HashMap(); - queryParams.put("limit", "1"); - request.queryParams = queryParams; - Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + + request.setMethod(Method.GET); + request.setEndpoint("access_settings/activity"); + request.addQueryParam("limit", "1"); + sg.attempt(request, new APICallback() { + @Override + public void error(Exception e) { + Assert.fail(); + synchronized(sync) { + sync.notify(); + } + } + + @Override + public void response(Response response) { + Assert.assertEquals(200, response.getStatusCode()); + synchronized(sync) { + sync.notify(); + } + } + }); + + try { + synchronized(sync) { + sync.wait(2000); + } + } catch(InterruptedException ex) { + Assert.fail(ex.toString()); + } } @Test - public void test_access_settings_whitelist_post() throws IOException { + public void test_async_rate_limit() { + final Object sync = new Object(); SendGrid sg = null; if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { sg = new SendGrid("SENDGRID_API_KEY"); @@ -101,4687 +145,3265 @@ public void test_access_settings_whitelist_post() throws IOException { sg = new SendGrid("SENDGRID_API_KEY", true); sg.setHost("localhost:4010"); } + sg.addRequestHeader("X-Mock", "429"); + + Request request = new Request(); + + request.setMethod(Method.GET); + request.setEndpoint("access_settings/activity"); + request.addQueryParam("limit", "1"); + sg.attempt(request, new APICallback() { + @Override + public void error(Exception e) { + Assert.assertEquals(e.getClass(), RateLimitException.class); + sync.notify(); + } + + @Override + public void response(Response response) { + Assert.fail(); + sync.notify(); + } + }); + + try { + synchronized(sync) { + sync.wait(2000); + } + } catch(InterruptedException ex) { + Assert.fail(ex.toString()); + } + } + + @Test + public void test_access_settings_activity_get() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("access_settings/activity"); + request.addQueryParam("limit", "1"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_access_settings_whitelist_post() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "201"); Request request = new Request(); - request.method = Method.POST; - request.endpoint = "access_settings/whitelist"; - request.body = "{\"ips\":[{\"ip\":\"192.168.1.1\"},{\"ip\":\"192.*.*.*\"},{\"ip\":\"192.168.1.3/32\"}]}"; + request.setMethod(Method.POST); + request.setEndpoint("access_settings/whitelist"); + request.setBody("{\"ips\":[{\"ip\":\"192.168.1.1\"},{\"ip\":\"192.*.*.*\"},{\"ip\":\"192.168.1.3/32\"}]}"); Response response = sg.api(request); - Assert.assertEquals(201, response.statusCode); + Assert.assertEquals(201, response.getStatusCode()); } @Test public void test_access_settings_whitelist_get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "access_settings/whitelist"; + request.setMethod(Method.GET); + request.setEndpoint("access_settings/whitelist"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_access_settings_whitelist_delete() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "204"); Request request = new Request(); - request.method = Method.DELETE; - request.endpoint = "access_settings/whitelist"; - request.body = "{\"ids\":[1,2,3]}"; + request.setMethod(Method.DELETE); + request.setEndpoint("access_settings/whitelist"); + request.setBody("{\"ids\":[1,2,3]}"); Response response = sg.api(request); - Assert.assertEquals(204, response.statusCode); + Assert.assertEquals(204, response.getStatusCode()); } @Test public void test_access_settings_whitelist__rule_id__get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "access_settings/whitelist/{rule_id}"; + request.setMethod(Method.GET); + request.setEndpoint("access_settings/whitelist/{rule_id}"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_access_settings_whitelist__rule_id__delete() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "204"); Request request = new Request(); - request.method = Method.DELETE; - request.endpoint = "access_settings/whitelist/{rule_id}"; + request.setMethod(Method.DELETE); + request.setEndpoint("access_settings/whitelist/{rule_id}"); Response response = sg.api(request); - Assert.assertEquals(204, response.statusCode); + Assert.assertEquals(204, response.getStatusCode()); } @Test public void test_alerts_post() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "201"); Request request = new Request(); - request.method = Method.POST; - request.endpoint = "alerts"; - request.body = "{\"type\":\"stats_notification\",\"frequency\":\"daily\",\"email_to\":\"example@example.com\"}"; + request.setMethod(Method.POST); + request.setEndpoint("alerts"); + request.setBody("{\"type\":\"stats_notification\",\"frequency\":\"daily\",\"email_to\":\"example@example.com\"}"); Response response = sg.api(request); - Assert.assertEquals(201, response.statusCode); + Assert.assertEquals(201, response.getStatusCode()); } @Test public void test_alerts_get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "alerts"; + request.setMethod(Method.GET); + request.setEndpoint("alerts"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_alerts__alert_id__patch() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.PATCH; - request.endpoint = "alerts/{alert_id}"; - request.body = "{\"email_to\":\"example@example.com\"}"; + request.setMethod(Method.PATCH); + request.setEndpoint("alerts/{alert_id}"); + request.setBody("{\"email_to\":\"example@example.com\"}"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_alerts__alert_id__get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "alerts/{alert_id}"; + request.setMethod(Method.GET); + request.setEndpoint("alerts/{alert_id}"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_alerts__alert_id__delete() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "204"); Request request = new Request(); - request.method = Method.DELETE; - request.endpoint = "alerts/{alert_id}"; + request.setMethod(Method.DELETE); + request.setEndpoint("alerts/{alert_id}"); Response response = sg.api(request); - Assert.assertEquals(204, response.statusCode); + Assert.assertEquals(204, response.getStatusCode()); } @Test public void test_api_keys_post() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "201"); Request request = new Request(); - request.method = Method.POST; - request.endpoint = "api_keys"; - request.body = "{\"sample\":\"data\",\"scopes\":[\"mail.send\",\"alerts.create\",\"alerts.read\"],\"name\":\"My API Key\"}"; + request.setMethod(Method.POST); + request.setEndpoint("api_keys"); + request.setBody("{\"sample\":\"data\",\"scopes\":[\"mail.send\",\"alerts.create\",\"alerts.read\"],\"name\":\"My API Key\"}"); Response response = sg.api(request); - Assert.assertEquals(201, response.statusCode); + Assert.assertEquals(201, response.getStatusCode()); } @Test public void test_api_keys_get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "api_keys"; - Map queryParams = new HashMap(); - queryParams.put("limit", "1"); - request.queryParams = queryParams; + request.setMethod(Method.GET); + request.setEndpoint("api_keys"); + request.addQueryParam("limit", "1"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_api_keys__api_key_id__put() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.PUT; - request.endpoint = "api_keys/{api_key_id}"; - request.body = "{\"scopes\":[\"user.profile.read\",\"user.profile.update\"],\"name\":\"A New Hope\"}"; + request.setMethod(Method.PUT); + request.setEndpoint("api_keys/{api_key_id}"); + request.setBody("{\"scopes\":[\"user.profile.read\",\"user.profile.update\"],\"name\":\"A New Hope\"}"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_api_keys__api_key_id__patch() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.PATCH; - request.endpoint = "api_keys/{api_key_id}"; - request.body = "{\"name\":\"A New Hope\"}"; + request.setMethod(Method.PATCH); + request.setEndpoint("api_keys/{api_key_id}"); + request.setBody("{\"name\":\"A New Hope\"}"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_api_keys__api_key_id__get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "api_keys/{api_key_id}"; + request.setMethod(Method.GET); + request.setEndpoint("api_keys/{api_key_id}"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_api_keys__api_key_id__delete() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "204"); Request request = new Request(); - request.method = Method.DELETE; - request.endpoint = "api_keys/{api_key_id}"; + request.setMethod(Method.DELETE); + request.setEndpoint("api_keys/{api_key_id}"); Response response = sg.api(request); - Assert.assertEquals(204, response.statusCode); + Assert.assertEquals(204, response.getStatusCode()); } @Test public void test_asm_groups_post() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "201"); Request request = new Request(); - request.method = Method.POST; - request.endpoint = "asm/groups"; - request.body = "{\"is_default\":true,\"description\":\"Suggestions for products our users might like.\",\"name\":\"Product Suggestions\"}"; + request.setMethod(Method.POST); + request.setEndpoint("asm/groups"); + request.setBody("{\"is_default\":true,\"description\":\"Suggestions for products our users might like.\",\"name\":\"Product Suggestions\"}"); Response response = sg.api(request); - Assert.assertEquals(201, response.statusCode); + Assert.assertEquals(201, response.getStatusCode()); } @Test public void test_asm_groups_get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "asm/groups"; - Map queryParams = new HashMap(); - queryParams.put("id", "1"); - request.queryParams = queryParams; + request.setMethod(Method.GET); + request.setEndpoint("asm/groups"); + request.addQueryParam("id", "1"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_asm_groups__group_id__patch() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "201"); Request request = new Request(); - request.method = Method.PATCH; - request.endpoint = "asm/groups/{group_id}"; - request.body = "{\"description\":\"Suggestions for items our users might like.\",\"name\":\"Item Suggestions\",\"id\":103}"; + request.setMethod(Method.PATCH); + request.setEndpoint("asm/groups/{group_id}"); + request.setBody("{\"description\":\"Suggestions for items our users might like.\",\"name\":\"Item Suggestions\",\"id\":103}"); Response response = sg.api(request); - Assert.assertEquals(201, response.statusCode); + Assert.assertEquals(201, response.getStatusCode()); } @Test public void test_asm_groups__group_id__get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "asm/groups/{group_id}"; + request.setMethod(Method.GET); + request.setEndpoint("asm/groups/{group_id}"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_asm_groups__group_id__delete() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "204"); Request request = new Request(); - request.method = Method.DELETE; - request.endpoint = "asm/groups/{group_id}"; + request.setMethod(Method.DELETE); + request.setEndpoint("asm/groups/{group_id}"); Response response = sg.api(request); - Assert.assertEquals(204, response.statusCode); + Assert.assertEquals(204, response.getStatusCode()); } @Test public void test_asm_groups__group_id__suppressions_post() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "201"); Request request = new Request(); - request.method = Method.POST; - request.endpoint = "asm/groups/{group_id}/suppressions"; - request.body = "{\"recipient_emails\":[\"test1@example.com\",\"test2@example.com\"]}"; + request.setMethod(Method.POST); + request.setEndpoint("asm/groups/{group_id}/suppressions"); + request.setBody("{\"recipient_emails\":[\"test1@example.com\",\"test2@example.com\"]}"); Response response = sg.api(request); - Assert.assertEquals(201, response.statusCode); + Assert.assertEquals(201, response.getStatusCode()); } @Test public void test_asm_groups__group_id__suppressions_get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "asm/groups/{group_id}/suppressions"; + request.setMethod(Method.GET); + request.setEndpoint("asm/groups/{group_id}/suppressions"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_asm_groups__group_id__suppressions_search_post() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.POST; - request.endpoint = "asm/groups/{group_id}/suppressions/search"; - request.body = "{\"recipient_emails\":[\"exists1@example.com\",\"exists2@example.com\",\"doesnotexists@example.com\"]}"; + request.setMethod(Method.POST); + request.setEndpoint("asm/groups/{group_id}/suppressions/search"); + request.setBody("{\"recipient_emails\":[\"exists1@example.com\",\"exists2@example.com\",\"doesnotexists@example.com\"]}"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_asm_groups__group_id__suppressions__email__delete() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "204"); Request request = new Request(); - request.method = Method.DELETE; - request.endpoint = "asm/groups/{group_id}/suppressions/{email}"; + request.setMethod(Method.DELETE); + request.setEndpoint("asm/groups/{group_id}/suppressions/{email}"); Response response = sg.api(request); - Assert.assertEquals(204, response.statusCode); + Assert.assertEquals(204, response.getStatusCode()); } @Test public void test_asm_suppressions_get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "asm/suppressions"; + request.setMethod(Method.GET); + request.setEndpoint("asm/suppressions"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_asm_suppressions_global_post() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "201"); Request request = new Request(); - request.method = Method.POST; - request.endpoint = "asm/suppressions/global"; - request.body = "{\"recipient_emails\":[\"test1@example.com\",\"test2@example.com\"]}"; + request.setMethod(Method.POST); + request.setEndpoint("asm/suppressions/global"); + request.setBody("{\"recipient_emails\":[\"test1@example.com\",\"test2@example.com\"]}"); Response response = sg.api(request); - Assert.assertEquals(201, response.statusCode); + Assert.assertEquals(201, response.getStatusCode()); } @Test public void test_asm_suppressions_global__email__get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "asm/suppressions/global/{email}"; + request.setMethod(Method.GET); + request.setEndpoint("asm/suppressions/global/{email}"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_asm_suppressions_global__email__delete() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "204"); Request request = new Request(); - request.method = Method.DELETE; - request.endpoint = "asm/suppressions/global/{email}"; + request.setMethod(Method.DELETE); + request.setEndpoint("asm/suppressions/global/{email}"); Response response = sg.api(request); - Assert.assertEquals(204, response.statusCode); + Assert.assertEquals(204, response.getStatusCode()); } @Test public void test_asm_suppressions__email__get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "asm/suppressions/{email}"; + request.setMethod(Method.GET); + request.setEndpoint("asm/suppressions/{email}"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_browsers_stats_get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "browsers/stats"; - Map queryParams = new HashMap(); - queryParams.put("end_date", "2016-04-01"); - queryParams.put("aggregated_by", "day"); - queryParams.put("browsers", "test_string"); - queryParams.put("limit", "test_string"); - queryParams.put("offset", "test_string"); - queryParams.put("start_date", "2016-01-01"); - request.queryParams = queryParams; + request.setMethod(Method.GET); + request.setEndpoint("browsers/stats"); + request.addQueryParam("end_date", "2016-04-01"); + request.addQueryParam("aggregated_by", "day"); + request.addQueryParam("browsers", "test_string"); + request.addQueryParam("limit", "test_string"); + request.addQueryParam("offset", "test_string"); + request.addQueryParam("start_date", "2016-01-01"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_campaigns_post() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "201"); Request request = new Request(); - request.method = Method.POST; - request.endpoint = "campaigns"; - request.body = "{\"custom_unsubscribe_url\":\"\",\"html_content\":\"

Check out our spring line!

\",\"list_ids\":[110,124],\"sender_id\":124451,\"subject\":\"New Products for Spring!\",\"plain_content\":\"Check out our spring line!\",\"suppression_group_id\":42,\"title\":\"March Newsletter\",\"segment_ids\":[110],\"categories\":[\"spring line\"],\"ip_pool\":\"marketing\"}"; + request.setMethod(Method.POST); + request.setEndpoint("campaigns"); + request.setBody("{\"custom_unsubscribe_url\":\"\",\"html_content\":\"

Check out our spring line!

\",\"list_ids\":[110,124],\"sender_id\":124451,\"subject\":\"New Products for Spring!\",\"plain_content\":\"Check out our spring line!\",\"suppression_group_id\":42,\"title\":\"March Newsletter\",\"segment_ids\":[110],\"categories\":[\"spring line\"],\"ip_pool\":\"marketing\"}"); Response response = sg.api(request); - Assert.assertEquals(201, response.statusCode); + Assert.assertEquals(201, response.getStatusCode()); } @Test public void test_campaigns_get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "campaigns"; - Map queryParams = new HashMap(); - queryParams.put("limit", "1"); - queryParams.put("offset", "1"); - request.queryParams = queryParams; + request.setMethod(Method.GET); + request.setEndpoint("campaigns"); + request.addQueryParam("limit", "1"); + request.addQueryParam("offset", "1"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_campaigns__campaign_id__patch() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.PATCH; - request.endpoint = "campaigns/{campaign_id}"; - request.body = "{\"html_content\":\"

Check out our summer line!

\",\"subject\":\"New Products for Summer!\",\"title\":\"May Newsletter\",\"categories\":[\"summer line\"],\"plain_content\":\"Check out our summer line!\"}"; + request.setMethod(Method.PATCH); + request.setEndpoint("campaigns/{campaign_id}"); + request.setBody("{\"html_content\":\"

Check out our summer line!

\",\"subject\":\"New Products for Summer!\",\"title\":\"May Newsletter\",\"categories\":[\"summer line\"],\"plain_content\":\"Check out our summer line!\"}"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_campaigns__campaign_id__get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "campaigns/{campaign_id}"; + request.setMethod(Method.GET); + request.setEndpoint("campaigns/{campaign_id}"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_campaigns__campaign_id__delete() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "204"); Request request = new Request(); - request.method = Method.DELETE; - request.endpoint = "campaigns/{campaign_id}"; + request.setMethod(Method.DELETE); + request.setEndpoint("campaigns/{campaign_id}"); Response response = sg.api(request); - Assert.assertEquals(204, response.statusCode); + Assert.assertEquals(204, response.getStatusCode()); } @Test public void test_campaigns__campaign_id__schedules_patch() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.PATCH; - request.endpoint = "campaigns/{campaign_id}/schedules"; - request.body = "{\"send_at\":1489451436}"; + request.setMethod(Method.PATCH); + request.setEndpoint("campaigns/{campaign_id}/schedules"); + request.setBody("{\"send_at\":1489451436}"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_campaigns__campaign_id__schedules_post() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "201"); Request request = new Request(); - request.method = Method.POST; - request.endpoint = "campaigns/{campaign_id}/schedules"; - request.body = "{\"send_at\":1489771528}"; + request.setMethod(Method.POST); + request.setEndpoint("campaigns/{campaign_id}/schedules"); + request.setBody("{\"send_at\":1489771528}"); Response response = sg.api(request); - Assert.assertEquals(201, response.statusCode); + Assert.assertEquals(201, response.getStatusCode()); } @Test public void test_campaigns__campaign_id__schedules_get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "campaigns/{campaign_id}/schedules"; + request.setMethod(Method.GET); + request.setEndpoint("campaigns/{campaign_id}/schedules"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_campaigns__campaign_id__schedules_delete() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "204"); Request request = new Request(); - request.method = Method.DELETE; - request.endpoint = "campaigns/{campaign_id}/schedules"; + request.setMethod(Method.DELETE); + request.setEndpoint("campaigns/{campaign_id}/schedules"); Response response = sg.api(request); - Assert.assertEquals(204, response.statusCode); + Assert.assertEquals(204, response.getStatusCode()); } @Test public void test_campaigns__campaign_id__schedules_now_post() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "201"); Request request = new Request(); - request.method = Method.POST; - request.endpoint = "campaigns/{campaign_id}/schedules/now"; + request.setMethod(Method.POST); + request.setEndpoint("campaigns/{campaign_id}/schedules/now"); Response response = sg.api(request); - Assert.assertEquals(201, response.statusCode); + Assert.assertEquals(201, response.getStatusCode()); } @Test public void test_campaigns__campaign_id__schedules_test_post() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "204"); Request request = new Request(); - request.method = Method.POST; - request.endpoint = "campaigns/{campaign_id}/schedules/test"; - request.body = "{\"to\":\"your.email@example.com\"}"; + request.setMethod(Method.POST); + request.setEndpoint("campaigns/{campaign_id}/schedules/test"); + request.setBody("{\"to\":\"your.email@example.com\"}"); Response response = sg.api(request); - Assert.assertEquals(204, response.statusCode); + Assert.assertEquals(204, response.getStatusCode()); } @Test public void test_categories_get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "categories"; - Map queryParams = new HashMap(); - queryParams.put("category", "test_string"); - queryParams.put("limit", "1"); - queryParams.put("offset", "1"); - request.queryParams = queryParams; + request.setMethod(Method.GET); + request.setEndpoint("categories"); + request.addQueryParam("category", "test_string"); + request.addQueryParam("limit", "1"); + request.addQueryParam("offset", "1"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_categories_stats_get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "categories/stats"; - Map queryParams = new HashMap(); - queryParams.put("end_date", "2016-04-01"); - queryParams.put("aggregated_by", "day"); - queryParams.put("limit", "1"); - queryParams.put("offset", "1"); - queryParams.put("start_date", "2016-01-01"); - queryParams.put("categories", "test_string"); - request.queryParams = queryParams; + request.setMethod(Method.GET); + request.setEndpoint("categories/stats"); + request.addQueryParam("end_date", "2016-04-01"); + request.addQueryParam("aggregated_by", "day"); + request.addQueryParam("limit", "1"); + request.addQueryParam("offset", "1"); + request.addQueryParam("start_date", "2016-01-01"); + request.addQueryParam("categories", "test_string"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_categories_stats_sums_get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "categories/stats/sums"; - Map queryParams = new HashMap(); - queryParams.put("end_date", "2016-04-01"); - queryParams.put("aggregated_by", "day"); - queryParams.put("limit", "1"); - queryParams.put("sort_by_metric", "test_string"); - queryParams.put("offset", "1"); - queryParams.put("start_date", "2016-01-01"); - queryParams.put("sort_by_direction", "asc"); - request.queryParams = queryParams; + request.setMethod(Method.GET); + request.setEndpoint("categories/stats/sums"); + request.addQueryParam("end_date", "2016-04-01"); + request.addQueryParam("aggregated_by", "day"); + request.addQueryParam("limit", "1"); + request.addQueryParam("sort_by_metric", "test_string"); + request.addQueryParam("offset", "1"); + request.addQueryParam("start_date", "2016-01-01"); + request.addQueryParam("sort_by_direction", "asc"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_clients_stats_get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "clients/stats"; - Map queryParams = new HashMap(); - queryParams.put("aggregated_by", "day"); - queryParams.put("start_date", "2016-01-01"); - queryParams.put("end_date", "2016-04-01"); - request.queryParams = queryParams; + request.setMethod(Method.GET); + request.setEndpoint("clients/stats"); + request.addQueryParam("aggregated_by", "day"); + request.addQueryParam("start_date", "2016-01-01"); + request.addQueryParam("end_date", "2016-04-01"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_clients__client_type__stats_get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "clients/{client_type}/stats"; - Map queryParams = new HashMap(); - queryParams.put("aggregated_by", "day"); - queryParams.put("start_date", "2016-01-01"); - queryParams.put("end_date", "2016-04-01"); - request.queryParams = queryParams; + request.setMethod(Method.GET); + request.setEndpoint("clients/{client_type}/stats"); + request.addQueryParam("aggregated_by", "day"); + request.addQueryParam("start_date", "2016-01-01"); + request.addQueryParam("end_date", "2016-04-01"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_contactdb_custom_fields_post() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "201"); Request request = new Request(); - request.method = Method.POST; - request.endpoint = "contactdb/custom_fields"; - request.body = "{\"type\":\"text\",\"name\":\"pet\"}"; + request.setMethod(Method.POST); + request.setEndpoint("contactdb/custom_fields"); + request.setBody("{\"type\":\"text\",\"name\":\"pet\"}"); Response response = sg.api(request); - Assert.assertEquals(201, response.statusCode); + Assert.assertEquals(201, response.getStatusCode()); } @Test public void test_contactdb_custom_fields_get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "contactdb/custom_fields"; + request.setMethod(Method.GET); + request.setEndpoint("contactdb/custom_fields"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_contactdb_custom_fields__custom_field_id__get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "contactdb/custom_fields/{custom_field_id}"; + request.setMethod(Method.GET); + request.setEndpoint("contactdb/custom_fields/{custom_field_id}"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_contactdb_custom_fields__custom_field_id__delete() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "202"); Request request = new Request(); - request.method = Method.DELETE; - request.endpoint = "contactdb/custom_fields/{custom_field_id}"; + request.setMethod(Method.DELETE); + request.setEndpoint("contactdb/custom_fields/{custom_field_id}"); Response response = sg.api(request); - Assert.assertEquals(202, response.statusCode); + Assert.assertEquals(202, response.getStatusCode()); } @Test public void test_contactdb_lists_post() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "201"); Request request = new Request(); - request.method = Method.POST; - request.endpoint = "contactdb/lists"; - request.body = "{\"name\":\"your list name\"}"; + request.setMethod(Method.POST); + request.setEndpoint("contactdb/lists"); + request.setBody("{\"name\":\"your list name\"}"); Response response = sg.api(request); - Assert.assertEquals(201, response.statusCode); + Assert.assertEquals(201, response.getStatusCode()); } @Test public void test_contactdb_lists_get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "contactdb/lists"; + request.setMethod(Method.GET); + request.setEndpoint("contactdb/lists"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_contactdb_lists_delete() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "204"); Request request = new Request(); - request.method = Method.DELETE; - request.endpoint = "contactdb/lists"; - request.body = "[1,2,3,4]"; + request.setMethod(Method.DELETE); + request.setEndpoint("contactdb/lists"); + request.setBody("[1,2,3,4]"); Response response = sg.api(request); - Assert.assertEquals(204, response.statusCode); + Assert.assertEquals(204, response.getStatusCode()); } @Test public void test_contactdb_lists__list_id__patch() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.PATCH; - request.endpoint = "contactdb/lists/{list_id}"; - request.body = "{\"name\":\"newlistname\"}"; - Map queryParams = new HashMap(); - queryParams.put("list_id", "1"); - request.queryParams = queryParams; + request.setMethod(Method.PATCH); + request.setEndpoint("contactdb/lists/{list_id}"); + request.setBody("{\"name\":\"newlistname\"}"); + request.addQueryParam("list_id", "1"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_contactdb_lists__list_id__get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "contactdb/lists/{list_id}"; - Map queryParams = new HashMap(); - queryParams.put("list_id", "1"); - request.queryParams = queryParams; + request.setMethod(Method.GET); + request.setEndpoint("contactdb/lists/{list_id}"); + request.addQueryParam("list_id", "1"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_contactdb_lists__list_id__delete() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "202"); Request request = new Request(); - request.method = Method.DELETE; - request.endpoint = "contactdb/lists/{list_id}"; - Map queryParams = new HashMap(); - queryParams.put("delete_contacts", "true"); - request.queryParams = queryParams; + request.setMethod(Method.DELETE); + request.setEndpoint("contactdb/lists/{list_id}"); + request.addQueryParam("delete_contacts", "true"); Response response = sg.api(request); - Assert.assertEquals(202, response.statusCode); + Assert.assertEquals(202, response.getStatusCode()); } @Test public void test_contactdb_lists__list_id__recipients_post() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "201"); Request request = new Request(); - request.method = Method.POST; - request.endpoint = "contactdb/lists/{list_id}/recipients"; - request.body = "[\"recipient_id1\",\"recipient_id2\"]"; + request.setMethod(Method.POST); + request.setEndpoint("contactdb/lists/{list_id}/recipients"); + request.setBody("[\"recipient_id1\",\"recipient_id2\"]"); Response response = sg.api(request); - Assert.assertEquals(201, response.statusCode); + Assert.assertEquals(201, response.getStatusCode()); } @Test public void test_contactdb_lists__list_id__recipients_get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "contactdb/lists/{list_id}/recipients"; - Map queryParams = new HashMap(); - queryParams.put("page", "1"); - queryParams.put("page_size", "1"); - queryParams.put("list_id", "1"); - request.queryParams = queryParams; + request.setMethod(Method.GET); + request.setEndpoint("contactdb/lists/{list_id}/recipients"); + request.addQueryParam("page", "1"); + request.addQueryParam("page_size", "1"); + request.addQueryParam("list_id", "1"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_contactdb_lists__list_id__recipients__recipient_id__post() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "201"); Request request = new Request(); - request.method = Method.POST; - request.endpoint = "contactdb/lists/{list_id}/recipients/{recipient_id}"; + request.setMethod(Method.POST); + request.setEndpoint("contactdb/lists/{list_id}/recipients/{recipient_id}"); Response response = sg.api(request); - Assert.assertEquals(201, response.statusCode); + Assert.assertEquals(201, response.getStatusCode()); } @Test public void test_contactdb_lists__list_id__recipients__recipient_id__delete() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "204"); Request request = new Request(); - request.method = Method.DELETE; - request.endpoint = "contactdb/lists/{list_id}/recipients/{recipient_id}"; - Map queryParams = new HashMap(); - queryParams.put("recipient_id", "1"); - queryParams.put("list_id", "1"); - request.queryParams = queryParams; + request.setMethod(Method.DELETE); + request.setEndpoint("contactdb/lists/{list_id}/recipients/{recipient_id}"); + request.addQueryParam("recipient_id", "1"); + request.addQueryParam("list_id", "1"); Response response = sg.api(request); - Assert.assertEquals(204, response.statusCode); + Assert.assertEquals(204, response.getStatusCode()); } @Test public void test_contactdb_recipients_patch() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "201"); Request request = new Request(); - request.method = Method.PATCH; - request.endpoint = "contactdb/recipients"; - request.body = "[{\"first_name\":\"Guy\",\"last_name\":\"Jones\",\"email\":\"jones@example.com\"}]"; + request.setMethod(Method.PATCH); + request.setEndpoint("contactdb/recipients"); + request.setBody("[{\"first_name\":\"Guy\",\"last_name\":\"Jones\",\"email\":\"jones@example.com\"}]"); Response response = sg.api(request); - Assert.assertEquals(201, response.statusCode); + Assert.assertEquals(201, response.getStatusCode()); } @Test public void test_contactdb_recipients_post() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "201"); Request request = new Request(); - request.method = Method.POST; - request.endpoint = "contactdb/recipients"; - request.body = "[{\"age\":25,\"last_name\":\"User\",\"email\":\"example@example.com\",\"first_name\":\"\"},{\"age\":25,\"last_name\":\"User\",\"email\":\"example2@example.com\",\"first_name\":\"Example\"}]"; + request.setMethod(Method.POST); + request.setEndpoint("contactdb/recipients"); + request.setBody("[{\"age\":25,\"last_name\":\"User\",\"email\":\"example@example.com\",\"first_name\":\"\"},{\"age\":25,\"last_name\":\"User\",\"email\":\"example2@example.com\",\"first_name\":\"Example\"}]"); Response response = sg.api(request); - Assert.assertEquals(201, response.statusCode); + Assert.assertEquals(201, response.getStatusCode()); } @Test public void test_contactdb_recipients_get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "contactdb/recipients"; - Map queryParams = new HashMap(); - queryParams.put("page", "1"); - queryParams.put("page_size", "1"); - request.queryParams = queryParams; + request.setMethod(Method.GET); + request.setEndpoint("contactdb/recipients"); + request.addQueryParam("page", "1"); + request.addQueryParam("page_size", "1"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_contactdb_recipients_delete() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.DELETE; - request.endpoint = "contactdb/recipients"; - request.body = "[\"recipient_id1\",\"recipient_id2\"]"; + request.setMethod(Method.DELETE); + request.setEndpoint("contactdb/recipients"); + request.setBody("[\"recipient_id1\",\"recipient_id2\"]"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_contactdb_recipients_billable_count_get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "contactdb/recipients/billable_count"; + request.setMethod(Method.GET); + request.setEndpoint("contactdb/recipients/billable_count"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_contactdb_recipients_count_get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "contactdb/recipients/count"; + request.setMethod(Method.GET); + request.setEndpoint("contactdb/recipients/count"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_contactdb_recipients_search_get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "contactdb/recipients/search"; - Map queryParams = new HashMap(); - queryParams.put("{field_name}", "test_string"); - request.queryParams = queryParams; + request.setMethod(Method.GET); + request.setEndpoint("contactdb/recipients/search"); + request.addQueryParam("{field_name}", "test_string"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_contactdb_recipients__recipient_id__get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "contactdb/recipients/{recipient_id}"; + request.setMethod(Method.GET); + request.setEndpoint("contactdb/recipients/{recipient_id}"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_contactdb_recipients__recipient_id__delete() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "204"); Request request = new Request(); - request.method = Method.DELETE; - request.endpoint = "contactdb/recipients/{recipient_id}"; + request.setMethod(Method.DELETE); + request.setEndpoint("contactdb/recipients/{recipient_id}"); Response response = sg.api(request); - Assert.assertEquals(204, response.statusCode); + Assert.assertEquals(204, response.getStatusCode()); } @Test public void test_contactdb_recipients__recipient_id__lists_get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "contactdb/recipients/{recipient_id}/lists"; + request.setMethod(Method.GET); + request.setEndpoint("contactdb/recipients/{recipient_id}/lists"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_contactdb_reserved_fields_get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "contactdb/reserved_fields"; + request.setMethod(Method.GET); + request.setEndpoint("contactdb/reserved_fields"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_contactdb_segments_post() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.POST; - request.endpoint = "contactdb/segments"; - request.body = "{\"conditions\":[{\"operator\":\"eq\",\"field\":\"last_name\",\"and_or\":\"\",\"value\":\"Miller\"},{\"operator\":\"gt\",\"field\":\"last_clicked\",\"and_or\":\"and\",\"value\":\"01/02/2015\"},{\"operator\":\"eq\",\"field\":\"clicks.campaign_identifier\",\"and_or\":\"or\",\"value\":\"513\"}],\"name\":\"Last Name Miller\",\"list_id\":4}"; + request.setMethod(Method.POST); + request.setEndpoint("contactdb/segments"); + request.setBody("{\"conditions\":[{\"operator\":\"eq\",\"field\":\"last_name\",\"and_or\":\"\",\"value\":\"Miller\"},{\"operator\":\"gt\",\"field\":\"last_clicked\",\"and_or\":\"and\",\"value\":\"01/02/2015\"},{\"operator\":\"eq\",\"field\":\"clicks.campaign_identifier\",\"and_or\":\"or\",\"value\":\"513\"}],\"name\":\"Last Name Miller\",\"list_id\":4}"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_contactdb_segments_get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "contactdb/segments"; + request.setMethod(Method.GET); + request.setEndpoint("contactdb/segments"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_contactdb_segments__segment_id__patch() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.PATCH; - request.endpoint = "contactdb/segments/{segment_id}"; - request.body = "{\"conditions\":[{\"operator\":\"eq\",\"field\":\"last_name\",\"and_or\":\"\",\"value\":\"Miller\"}],\"name\":\"The Millers\",\"list_id\":5}"; - Map queryParams = new HashMap(); - queryParams.put("segment_id", "test_string"); - request.queryParams = queryParams; + request.setMethod(Method.PATCH); + request.setEndpoint("contactdb/segments/{segment_id}"); + request.setBody("{\"conditions\":[{\"operator\":\"eq\",\"field\":\"last_name\",\"and_or\":\"\",\"value\":\"Miller\"}],\"name\":\"The Millers\",\"list_id\":5}"); + request.addQueryParam("segment_id", "test_string"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_contactdb_segments__segment_id__get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "contactdb/segments/{segment_id}"; - Map queryParams = new HashMap(); - queryParams.put("segment_id", "1"); - request.queryParams = queryParams; + request.setMethod(Method.GET); + request.setEndpoint("contactdb/segments/{segment_id}"); + request.addQueryParam("segment_id", "1"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_contactdb_segments__segment_id__delete() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "204"); Request request = new Request(); - request.method = Method.DELETE; - request.endpoint = "contactdb/segments/{segment_id}"; - Map queryParams = new HashMap(); - queryParams.put("delete_contacts", "true"); - request.queryParams = queryParams; + request.setMethod(Method.DELETE); + request.setEndpoint("contactdb/segments/{segment_id}"); + request.addQueryParam("delete_contacts", "true"); Response response = sg.api(request); - Assert.assertEquals(204, response.statusCode); + Assert.assertEquals(204, response.getStatusCode()); } @Test public void test_contactdb_segments__segment_id__recipients_get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "contactdb/segments/{segment_id}/recipients"; - Map queryParams = new HashMap(); - queryParams.put("page", "1"); - queryParams.put("page_size", "1"); - request.queryParams = queryParams; + request.setMethod(Method.GET); + request.setEndpoint("contactdb/segments/{segment_id}/recipients"); + request.addQueryParam("page", "1"); + request.addQueryParam("page_size", "1"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_devices_stats_get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "devices/stats"; - Map queryParams = new HashMap(); - queryParams.put("aggregated_by", "day"); - queryParams.put("limit", "1"); - queryParams.put("start_date", "2016-01-01"); - queryParams.put("end_date", "2016-04-01"); - queryParams.put("offset", "1"); - request.queryParams = queryParams; + request.setMethod(Method.GET); + request.setEndpoint("devices/stats"); + request.addQueryParam("aggregated_by", "day"); + request.addQueryParam("limit", "1"); + request.addQueryParam("start_date", "2016-01-01"); + request.addQueryParam("end_date", "2016-04-01"); + request.addQueryParam("offset", "1"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_geo_stats_get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "geo/stats"; - Map queryParams = new HashMap(); - queryParams.put("end_date", "2016-04-01"); - queryParams.put("country", "US"); - queryParams.put("aggregated_by", "day"); - queryParams.put("limit", "1"); - queryParams.put("offset", "1"); - queryParams.put("start_date", "2016-01-01"); - request.queryParams = queryParams; + request.setMethod(Method.GET); + request.setEndpoint("geo/stats"); + request.addQueryParam("end_date", "2016-04-01"); + request.addQueryParam("country", "US"); + request.addQueryParam("aggregated_by", "day"); + request.addQueryParam("limit", "1"); + request.addQueryParam("offset", "1"); + request.addQueryParam("start_date", "2016-01-01"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_ips_get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "ips"; - Map queryParams = new HashMap(); - queryParams.put("subuser", "test_string"); - queryParams.put("ip", "test_string"); - queryParams.put("limit", "1"); - queryParams.put("exclude_whitelabels", "true"); - queryParams.put("offset", "1"); - request.queryParams = queryParams; + request.setMethod(Method.GET); + request.setEndpoint("ips"); + request.addQueryParam("subuser", "test_string"); + request.addQueryParam("ip", "test_string"); + request.addQueryParam("limit", "1"); + request.addQueryParam("exclude_whitelabels", "true"); + request.addQueryParam("offset", "1"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_ips_assigned_get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "ips/assigned"; + request.setMethod(Method.GET); + request.setEndpoint("ips/assigned"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_ips_pools_post() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.POST; - request.endpoint = "ips/pools"; - request.body = "{\"name\":\"marketing\"}"; + request.setMethod(Method.POST); + request.setEndpoint("ips/pools"); + request.setBody("{\"name\":\"marketing\"}"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_ips_pools_get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "ips/pools"; + request.setMethod(Method.GET); + request.setEndpoint("ips/pools"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_ips_pools__pool_name__put() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.PUT; - request.endpoint = "ips/pools/{pool_name}"; - request.body = "{\"name\":\"new_pool_name\"}"; + request.setMethod(Method.PUT); + request.setEndpoint("ips/pools/{pool_name}"); + request.setBody("{\"name\":\"new_pool_name\"}"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_ips_pools__pool_name__get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "ips/pools/{pool_name}"; + request.setMethod(Method.GET); + request.setEndpoint("ips/pools/{pool_name}"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_ips_pools__pool_name__delete() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "204"); Request request = new Request(); - request.method = Method.DELETE; - request.endpoint = "ips/pools/{pool_name}"; + request.setMethod(Method.DELETE); + request.setEndpoint("ips/pools/{pool_name}"); Response response = sg.api(request); - Assert.assertEquals(204, response.statusCode); + Assert.assertEquals(204, response.getStatusCode()); } @Test public void test_ips_pools__pool_name__ips_post() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "201"); Request request = new Request(); - request.method = Method.POST; - request.endpoint = "ips/pools/{pool_name}/ips"; - request.body = "{\"ip\":\"0.0.0.0\"}"; + request.setMethod(Method.POST); + request.setEndpoint("ips/pools/{pool_name}/ips"); + request.setBody("{\"ip\":\"0.0.0.0\"}"); Response response = sg.api(request); - Assert.assertEquals(201, response.statusCode); + Assert.assertEquals(201, response.getStatusCode()); } @Test public void test_ips_pools__pool_name__ips__ip__delete() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "204"); Request request = new Request(); - request.method = Method.DELETE; - request.endpoint = "ips/pools/{pool_name}/ips/{ip}"; + request.setMethod(Method.DELETE); + request.setEndpoint("ips/pools/{pool_name}/ips/{ip}"); Response response = sg.api(request); - Assert.assertEquals(204, response.statusCode); + Assert.assertEquals(204, response.getStatusCode()); } @Test public void test_ips_warmup_post() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.POST; - request.endpoint = "ips/warmup"; - request.body = "{\"ip\":\"0.0.0.0\"}"; + request.setMethod(Method.POST); + request.setEndpoint("ips/warmup"); + request.setBody("{\"ip\":\"0.0.0.0\"}"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_ips_warmup_get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "ips/warmup"; + request.setMethod(Method.GET); + request.setEndpoint("ips/warmup"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_ips_warmup__ip_address__get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "ips/warmup/{ip_address}"; + request.setMethod(Method.GET); + request.setEndpoint("ips/warmup/{ip_address}"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_ips_warmup__ip_address__delete() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "204"); Request request = new Request(); - request.method = Method.DELETE; - request.endpoint = "ips/warmup/{ip_address}"; + request.setMethod(Method.DELETE); + request.setEndpoint("ips/warmup/{ip_address}"); Response response = sg.api(request); - Assert.assertEquals(204, response.statusCode); + Assert.assertEquals(204, response.getStatusCode()); } @Test public void test_ips__ip_address__get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "ips/{ip_address}"; + request.setMethod(Method.GET); + request.setEndpoint("ips/{ip_address}"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_mail_batch_post() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "201"); Request request = new Request(); - request.method = Method.POST; - request.endpoint = "mail/batch"; + request.setMethod(Method.POST); + request.setEndpoint("mail/batch"); Response response = sg.api(request); - Assert.assertEquals(201, response.statusCode); + Assert.assertEquals(201, response.getStatusCode()); } @Test public void test_mail_batch__batch_id__get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "mail/batch/{batch_id}"; + request.setMethod(Method.GET); + request.setEndpoint("mail/batch/{batch_id}"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_mail_send_post() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "202"); Request request = new Request(); - request.method = Method.POST; - request.endpoint = "mail/send"; - request.body = "{\"custom_args\":{\"New Argument 1\":\"New Value 1\",\"activationAttempt\":\"1\",\"customerAccountNumber\":\"[CUSTOMER ACCOUNT NUMBER GOES HERE]\"},\"from\":{\"email\":\"sam.smith@example.com\",\"name\":\"Sam Smith\"},\"attachments\":[{\"name\":\"file1\",\"filename\":\"file1.jpg\",\"content\":\"[BASE64 encoded content block here]\",\"disposition\":\"inline\",\"content_id\":\"ii_139db99fdb5c3704\",\"type\":\"jpg\"}],\"personalizations\":[{\"to\":[{\"email\":\"john.doe@example.com\",\"name\":\"John Doe\"}],\"cc\":[{\"email\":\"jane.doe@example.com\",\"name\":\"Jane Doe\"}],\"bcc\":[{\"email\":\"sam.doe@example.com\",\"name\":\"Sam Doe\"}],\"custom_args\":{\"New Argument 1\":\"New Value 1\",\"activationAttempt\":\"1\",\"customerAccountNumber\":\"[CUSTOMER ACCOUNT NUMBER GOES HERE]\"},\"headers\":{\"X-Accept-Language\":\"en\",\"X-Mailer\":\"MyApp\"},\"send_at\":1409348513,\"substitutions\":{\"type\":\"object\",\"id\":\"substitutions\"},\"subject\":\"Hello, World!\"}],\"subject\":\"Hello, World!\",\"ip_pool_name\":\"[YOUR POOL NAME GOES HERE]\",\"content\":[{\"type\":\"text/html\",\"value\":\"

Hello, world!

\"}],\"headers\":{},\"asm\":{\"groups_to_display\":[1,2,3],\"group_id\":1},\"batch_id\":\"[YOUR BATCH ID GOES HERE]\",\"tracking_settings\":{\"subscription_tracking\":{\"text\":\"If you would like to unsubscribe and stop receiveing these emails <% click here %>.\",\"enable\":true,\"html\":\"If you would like to unsubscribe and stop receiving these emails <% clickhere %>.\",\"substitution_tag\":\"<%click here%>\"},\"open_tracking\":{\"enable\":true,\"substitution_tag\":\"%opentrack\"},\"click_tracking\":{\"enable\":true,\"enable_text\":true},\"ganalytics\":{\"utm_campaign\":\"[NAME OF YOUR REFERRER SOURCE]\",\"enable\":true,\"utm_name\":\"[NAME OF YOUR CAMPAIGN]\",\"utm_term\":\"[IDENTIFY PAID KEYWORDS HERE]\",\"utm_content\":\"[USE THIS SPACE TO DIFFERENTIATE YOUR EMAIL FROM ADS]\",\"utm_medium\":\"[NAME OF YOUR MARKETING MEDIUM e.g. email]\"}},\"mail_settings\":{\"footer\":{\"text\":\"Thanks,/n The SendGrid Team\",\"enable\":true,\"html\":\"

Thanks
The SendGrid Team

\"},\"spam_check\":{\"threshold\":3,\"post_to_url\":\"http://example.com/compliance\",\"enable\":true},\"bypass_list_management\":{\"enable\":true},\"sandbox_mode\":{\"enable\":false},\"bcc\":{\"enable\":true,\"email\":\"ben.doe@example.com\"}},\"reply_to\":{\"email\":\"sam.smith@example.com\",\"name\":\"Sam Smith\"},\"sections\":{\"section\":{\":sectionName2\":\"section 2 text\",\":sectionName1\":\"section 1 text\"}},\"template_id\":\"[YOUR TEMPLATE ID GOES HERE]\",\"categories\":[\"category1\",\"category2\"],\"send_at\":1409348513}"; + request.setMethod(Method.POST); + request.setEndpoint("mail/send"); + request.setBody("{\"custom_args\":{\"New Argument 1\":\"New Value 1\",\"activationAttempt\":\"1\",\"customerAccountNumber\":\"[CUSTOMER ACCOUNT NUMBER GOES HERE]\"},\"from\":{\"email\":\"sam.smith@example.com\",\"name\":\"Sam Smith\"},\"attachments\":[{\"name\":\"file1\",\"filename\":\"file1.jpg\",\"content\":\"[BASE64 encoded content block here]\",\"disposition\":\"inline\",\"content_id\":\"ii_139db99fdb5c3704\",\"type\":\"jpg\"}],\"personalizations\":[{\"to\":[{\"email\":\"john.doe@example.com\",\"name\":\"John Doe\"}],\"cc\":[{\"email\":\"jane.doe@example.com\",\"name\":\"Jane Doe\"}],\"bcc\":[{\"email\":\"sam.doe@example.com\",\"name\":\"Sam Doe\"}],\"custom_args\":{\"New Argument 1\":\"New Value 1\",\"activationAttempt\":\"1\",\"customerAccountNumber\":\"[CUSTOMER ACCOUNT NUMBER GOES HERE]\"},\"headers\":{\"X-Accept-Language\":\"en\",\"X-Mailer\":\"MyApp\"},\"send_at\":1409348513,\"substitutions\":{\"type\":\"object\",\"id\":\"substitutions\"},\"subject\":\"Hello, World!\"}],\"subject\":\"Hello, World!\",\"ip_pool_name\":\"[YOUR POOL NAME GOES HERE]\",\"content\":[{\"type\":\"text/html\",\"value\":\"

Hello, world!

\"}],\"headers\":{},\"asm\":{\"groups_to_display\":[1,2,3],\"group_id\":1},\"batch_id\":\"[YOUR BATCH ID GOES HERE]\",\"tracking_settings\":{\"subscription_tracking\":{\"text\":\"If you would like to unsubscribe and stop receiveing these emails <% click here %>.\",\"enable\":true,\"html\":\"If you would like to unsubscribe and stop receiving these emails <% clickhere %>.\",\"substitution_tag\":\"<%click here%>\"},\"open_tracking\":{\"enable\":true,\"substitution_tag\":\"%opentrack\"},\"click_tracking\":{\"enable\":true,\"enable_text\":true},\"ganalytics\":{\"utm_campaign\":\"[NAME OF YOUR REFERRER SOURCE]\",\"enable\":true,\"utm_name\":\"[NAME OF YOUR CAMPAIGN]\",\"utm_term\":\"[IDENTIFY PAID KEYWORDS HERE]\",\"utm_content\":\"[USE THIS SPACE TO DIFFERENTIATE YOUR EMAIL FROM ADS]\",\"utm_medium\":\"[NAME OF YOUR MARKETING MEDIUM e.g. email]\"}},\"mail_settings\":{\"footer\":{\"text\":\"Thanks,/n The SendGrid Team\",\"enable\":true,\"html\":\"

Thanks
The SendGrid Team

\"},\"spam_check\":{\"threshold\":3,\"post_to_url\":\"http://example.com/compliance\",\"enable\":true},\"bypass_list_management\":{\"enable\":true},\"sandbox_mode\":{\"enable\":false},\"bcc\":{\"enable\":true,\"email\":\"ben.doe@example.com\"}},\"reply_to\":{\"email\":\"sam.smith@example.com\",\"name\":\"Sam Smith\"},\"sections\":{\"section\":{\":sectionName2\":\"section 2 text\",\":sectionName1\":\"section 1 text\"}},\"template_id\":\"[YOUR TEMPLATE ID GOES HERE]\",\"categories\":[\"category1\",\"category2\"],\"send_at\":1409348513}"); Response response = sg.api(request); - Assert.assertEquals(202, response.statusCode); + Assert.assertEquals(202, response.getStatusCode()); } @Test public void test_mail_settings_get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "mail_settings"; - Map queryParams = new HashMap(); - queryParams.put("limit", "1"); - queryParams.put("offset", "1"); - request.queryParams = queryParams; + request.setMethod(Method.GET); + request.setEndpoint("mail_settings"); + request.addQueryParam("limit", "1"); + request.addQueryParam("offset", "1"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_mail_settings_address_whitelist_patch() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.PATCH; - request.endpoint = "mail_settings/address_whitelist"; - request.body = "{\"list\":[\"email1@example.com\",\"example.com\"],\"enabled\":true}"; + 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); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_mail_settings_address_whitelist_get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "mail_settings/address_whitelist"; + request.setMethod(Method.GET); + request.setEndpoint("mail_settings/address_whitelist"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_mail_settings_bcc_patch() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.PATCH; - request.endpoint = "mail_settings/bcc"; - request.body = "{\"enabled\":false,\"email\":\"email@example.com\"}"; + request.setMethod(Method.PATCH); + request.setEndpoint("mail_settings/bcc"); + request.setBody("{\"enabled\":false,\"email\":\"email@example.com\"}"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_mail_settings_bcc_get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "mail_settings/bcc"; + request.setMethod(Method.GET); + request.setEndpoint("mail_settings/bcc"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_mail_settings_bounce_purge_patch() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.PATCH; - request.endpoint = "mail_settings/bounce_purge"; - request.body = "{\"hard_bounces\":5,\"soft_bounces\":5,\"enabled\":true}"; + 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); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_mail_settings_bounce_purge_get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "mail_settings/bounce_purge"; + request.setMethod(Method.GET); + request.setEndpoint("mail_settings/bounce_purge"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_mail_settings_footer_patch() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.PATCH; - request.endpoint = "mail_settings/footer"; - request.body = "{\"html_content\":\"...\",\"enabled\":true,\"plain_content\":\"...\"}"; + request.setMethod(Method.PATCH); + request.setEndpoint("mail_settings/footer"); + request.setBody("{\"html_content\":\"...\",\"enabled\":true,\"plain_content\":\"...\"}"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_mail_settings_footer_get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "mail_settings/footer"; + request.setMethod(Method.GET); + request.setEndpoint("mail_settings/footer"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_mail_settings_forward_bounce_patch() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.PATCH; - request.endpoint = "mail_settings/forward_bounce"; - request.body = "{\"enabled\":true,\"email\":\"example@example.com\"}"; + request.setMethod(Method.PATCH); + request.setEndpoint("mail_settings/forward_bounce"); + request.setBody("{\"enabled\":true,\"email\":\"example@example.com\"}"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_mail_settings_forward_bounce_get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "mail_settings/forward_bounce"; + request.setMethod(Method.GET); + request.setEndpoint("mail_settings/forward_bounce"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_mail_settings_forward_spam_patch() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.PATCH; - request.endpoint = "mail_settings/forward_spam"; - request.body = "{\"enabled\":false,\"email\":\"\"}"; + request.setMethod(Method.PATCH); + request.setEndpoint("mail_settings/forward_spam"); + request.setBody("{\"enabled\":false,\"email\":\"\"}"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_mail_settings_forward_spam_get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "mail_settings/forward_spam"; + request.setMethod(Method.GET); + request.setEndpoint("mail_settings/forward_spam"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_mail_settings_plain_content_patch() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.PATCH; - request.endpoint = "mail_settings/plain_content"; - request.body = "{\"enabled\":false}"; + request.setMethod(Method.PATCH); + request.setEndpoint("mail_settings/plain_content"); + request.setBody("{\"enabled\":false}"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_mail_settings_plain_content_get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "mail_settings/plain_content"; + request.setMethod(Method.GET); + request.setEndpoint("mail_settings/plain_content"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_mail_settings_spam_check_patch() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.PATCH; - request.endpoint = "mail_settings/spam_check"; - request.body = "{\"url\":\"url\",\"max_score\":5,\"enabled\":true}"; + request.setMethod(Method.PATCH); + request.setEndpoint("mail_settings/spam_check"); + request.setBody("{\"url\":\"url\",\"max_score\":5,\"enabled\":true}"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_mail_settings_spam_check_get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "mail_settings/spam_check"; + request.setMethod(Method.GET); + request.setEndpoint("mail_settings/spam_check"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_mail_settings_template_patch() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.PATCH; - request.endpoint = "mail_settings/template"; - request.body = "{\"html_content\":\"<% body %>\",\"enabled\":true}"; + request.setMethod(Method.PATCH); + request.setEndpoint("mail_settings/template"); + request.setBody("{\"html_content\":\"<% body %>\",\"enabled\":true}"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_mail_settings_template_get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "mail_settings/template"; + request.setMethod(Method.GET); + request.setEndpoint("mail_settings/template"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_mailbox_providers_stats_get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "mailbox_providers/stats"; - Map queryParams = new HashMap(); - queryParams.put("end_date", "2016-04-01"); - queryParams.put("mailbox_providers", "test_string"); - queryParams.put("aggregated_by", "day"); - queryParams.put("limit", "1"); - queryParams.put("offset", "1"); - queryParams.put("start_date", "2016-01-01"); - request.queryParams = queryParams; + request.setMethod(Method.GET); + request.setEndpoint("mailbox_providers/stats"); + request.addQueryParam("end_date", "2016-04-01"); + request.addQueryParam("mailbox_providers", "test_string"); + request.addQueryParam("aggregated_by", "day"); + request.addQueryParam("limit", "1"); + request.addQueryParam("offset", "1"); + request.addQueryParam("start_date", "2016-01-01"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_partner_settings_get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "partner_settings"; - Map queryParams = new HashMap(); - queryParams.put("limit", "1"); - queryParams.put("offset", "1"); - request.queryParams = queryParams; + request.setMethod(Method.GET); + request.setEndpoint("partner_settings"); + request.addQueryParam("limit", "1"); + request.addQueryParam("offset", "1"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_partner_settings_new_relic_patch() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.PATCH; - request.endpoint = "partner_settings/new_relic"; - request.body = "{\"enable_subuser_statistics\":true,\"enabled\":true,\"license_key\":\"\"}"; + request.setMethod(Method.PATCH); + request.setEndpoint("partner_settings/new_relic"); + request.setBody("{\"enable_subuser_statistics\":true,\"enabled\":true,\"license_key\":\"\"}"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_partner_settings_new_relic_get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "partner_settings/new_relic"; + request.setMethod(Method.GET); + request.setEndpoint("partner_settings/new_relic"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_scopes_get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "scopes"; + request.setMethod(Method.GET); + request.setEndpoint("scopes"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_senders_post() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "201"); Request request = new Request(); - request.method = Method.POST; - request.endpoint = "senders"; - request.body = "{\"city\":\"Denver\",\"from\":{\"email\":\"from@example.com\",\"name\":\"Example INC\"},\"zip\":\"80202\",\"country\":\"United States\",\"state\":\"Colorado\",\"address_2\":\"Apt. 456\",\"address\":\"123 Elm St.\",\"reply_to\":{\"email\":\"replyto@example.com\",\"name\":\"Example INC\"},\"nickname\":\"My Sender ID\"}"; + request.setMethod(Method.POST); + request.setEndpoint("senders"); + request.setBody("{\"city\":\"Denver\",\"from\":{\"email\":\"from@example.com\",\"name\":\"Example INC\"},\"zip\":\"80202\",\"country\":\"United States\",\"state\":\"Colorado\",\"address_2\":\"Apt. 456\",\"address\":\"123 Elm St.\",\"reply_to\":{\"email\":\"replyto@example.com\",\"name\":\"Example INC\"},\"nickname\":\"My Sender ID\"}"); Response response = sg.api(request); - Assert.assertEquals(201, response.statusCode); + Assert.assertEquals(201, response.getStatusCode()); } @Test public void test_senders_get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "senders"; + request.setMethod(Method.GET); + request.setEndpoint("senders"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_senders__sender_id__patch() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.PATCH; - request.endpoint = "senders/{sender_id}"; - request.body = "{\"city\":\"Denver\",\"from\":{\"email\":\"from@example.com\",\"name\":\"Example INC\"},\"zip\":\"80202\",\"country\":\"United States\",\"state\":\"Colorado\",\"address_2\":\"Apt. 456\",\"address\":\"123 Elm St.\",\"reply_to\":{\"email\":\"replyto@example.com\",\"name\":\"Example INC\"},\"nickname\":\"My Sender ID\"}"; + request.setMethod(Method.PATCH); + request.setEndpoint("senders/{sender_id}"); + request.setBody("{\"city\":\"Denver\",\"from\":{\"email\":\"from@example.com\",\"name\":\"Example INC\"},\"zip\":\"80202\",\"country\":\"United States\",\"state\":\"Colorado\",\"address_2\":\"Apt. 456\",\"address\":\"123 Elm St.\",\"reply_to\":{\"email\":\"replyto@example.com\",\"name\":\"Example INC\"},\"nickname\":\"My Sender ID\"}"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_senders__sender_id__get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "senders/{sender_id}"; + request.setMethod(Method.GET); + request.setEndpoint("senders/{sender_id}"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_senders__sender_id__delete() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "204"); Request request = new Request(); - request.method = Method.DELETE; - request.endpoint = "senders/{sender_id}"; + request.setMethod(Method.DELETE); + request.setEndpoint("senders/{sender_id}"); Response response = sg.api(request); - Assert.assertEquals(204, response.statusCode); + Assert.assertEquals(204, response.getStatusCode()); } @Test public void test_senders__sender_id__resend_verification_post() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "204"); Request request = new Request(); - request.method = Method.POST; - request.endpoint = "senders/{sender_id}/resend_verification"; + request.setMethod(Method.POST); + request.setEndpoint("senders/{sender_id}/resend_verification"); Response response = sg.api(request); - Assert.assertEquals(204, response.statusCode); + Assert.assertEquals(204, response.getStatusCode()); } @Test public void test_stats_get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "stats"; - Map queryParams = new HashMap(); - queryParams.put("aggregated_by", "day"); - queryParams.put("limit", "1"); - queryParams.put("start_date", "2016-01-01"); - queryParams.put("end_date", "2016-04-01"); - queryParams.put("offset", "1"); - request.queryParams = queryParams; + request.setMethod(Method.GET); + request.setEndpoint("stats"); + request.addQueryParam("aggregated_by", "day"); + request.addQueryParam("limit", "1"); + request.addQueryParam("start_date", "2016-01-01"); + request.addQueryParam("end_date", "2016-04-01"); + request.addQueryParam("offset", "1"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_subusers_post() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.POST; - request.endpoint = "subusers"; - request.body = "{\"username\":\"John@example.com\",\"ips\":[\"1.1.1.1\",\"2.2.2.2\"],\"password\":\"johns_password\",\"email\":\"John@example.com\"}"; + request.setMethod(Method.POST); + request.setEndpoint("subusers"); + request.setBody("{\"username\":\"John@example.com\",\"ips\":[\"1.1.1.1\",\"2.2.2.2\"],\"password\":\"johns_password\",\"email\":\"John@example.com\"}"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_subusers_get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "subusers"; - Map queryParams = new HashMap(); - queryParams.put("username", "test_string"); - queryParams.put("limit", "1"); - queryParams.put("offset", "1"); - request.queryParams = queryParams; + request.setMethod(Method.GET); + request.setEndpoint("subusers"); + request.addQueryParam("username", "test_string"); + request.addQueryParam("limit", "1"); + request.addQueryParam("offset", "1"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_subusers_reputations_get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "subusers/reputations"; - Map queryParams = new HashMap(); - queryParams.put("usernames", "test_string"); - request.queryParams = queryParams; + request.setMethod(Method.GET); + request.setEndpoint("subusers/reputations"); + request.addQueryParam("usernames", "test_string"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_subusers_stats_get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "subusers/stats"; - Map queryParams = new HashMap(); - queryParams.put("end_date", "2016-04-01"); - queryParams.put("aggregated_by", "day"); - queryParams.put("limit", "1"); - queryParams.put("offset", "1"); - queryParams.put("start_date", "2016-01-01"); - queryParams.put("subusers", "test_string"); - request.queryParams = queryParams; + request.setMethod(Method.GET); + request.setEndpoint("subusers/stats"); + request.addQueryParam("end_date", "2016-04-01"); + request.addQueryParam("aggregated_by", "day"); + request.addQueryParam("limit", "1"); + request.addQueryParam("offset", "1"); + request.addQueryParam("start_date", "2016-01-01"); + request.addQueryParam("subusers", "test_string"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_subusers_stats_monthly_get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "subusers/stats/monthly"; - Map queryParams = new HashMap(); - queryParams.put("subuser", "test_string"); - queryParams.put("limit", "1"); - queryParams.put("sort_by_metric", "test_string"); - queryParams.put("offset", "1"); - queryParams.put("date", "test_string"); - queryParams.put("sort_by_direction", "asc"); - request.queryParams = queryParams; + request.setMethod(Method.GET); + request.setEndpoint("subusers/stats/monthly"); + request.addQueryParam("subuser", "test_string"); + request.addQueryParam("limit", "1"); + request.addQueryParam("sort_by_metric", "test_string"); + request.addQueryParam("offset", "1"); + request.addQueryParam("date", "test_string"); + request.addQueryParam("sort_by_direction", "asc"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_subusers_stats_sums_get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "subusers/stats/sums"; - Map queryParams = new HashMap(); - queryParams.put("end_date", "2016-04-01"); - queryParams.put("aggregated_by", "day"); - queryParams.put("limit", "1"); - queryParams.put("sort_by_metric", "test_string"); - queryParams.put("offset", "1"); - queryParams.put("start_date", "2016-01-01"); - queryParams.put("sort_by_direction", "asc"); - request.queryParams = queryParams; + request.setMethod(Method.GET); + request.setEndpoint("subusers/stats/sums"); + request.addQueryParam("end_date", "2016-04-01"); + request.addQueryParam("aggregated_by", "day"); + request.addQueryParam("limit", "1"); + request.addQueryParam("sort_by_metric", "test_string"); + request.addQueryParam("offset", "1"); + request.addQueryParam("start_date", "2016-01-01"); + request.addQueryParam("sort_by_direction", "asc"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_subusers__subuser_name__patch() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "204"); Request request = new Request(); - request.method = Method.PATCH; - request.endpoint = "subusers/{subuser_name}"; - request.body = "{\"disabled\":false}"; + request.setMethod(Method.PATCH); + request.setEndpoint("subusers/{subuser_name}"); + request.setBody("{\"disabled\":false}"); Response response = sg.api(request); - Assert.assertEquals(204, response.statusCode); + Assert.assertEquals(204, response.getStatusCode()); } @Test public void test_subusers__subuser_name__delete() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "204"); Request request = new Request(); - request.method = Method.DELETE; - request.endpoint = "subusers/{subuser_name}"; + request.setMethod(Method.DELETE); + request.setEndpoint("subusers/{subuser_name}"); Response response = sg.api(request); - Assert.assertEquals(204, response.statusCode); + Assert.assertEquals(204, response.getStatusCode()); } @Test public void test_subusers__subuser_name__ips_put() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.PUT; - request.endpoint = "subusers/{subuser_name}/ips"; - request.body = "[\"127.0.0.1\"]"; + request.setMethod(Method.PUT); + request.setEndpoint("subusers/{subuser_name}/ips"); + request.setBody("[\"127.0.0.1\"]"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_subusers__subuser_name__monitor_put() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.PUT; - request.endpoint = "subusers/{subuser_name}/monitor"; - request.body = "{\"frequency\":500,\"email\":\"example@example.com\"}"; + request.setMethod(Method.PUT); + request.setEndpoint("subusers/{subuser_name}/monitor"); + request.setBody("{\"frequency\":500,\"email\":\"example@example.com\"}"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_subusers__subuser_name__monitor_post() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.POST; - request.endpoint = "subusers/{subuser_name}/monitor"; - request.body = "{\"frequency\":50000,\"email\":\"example@example.com\"}"; + request.setMethod(Method.POST); + request.setEndpoint("subusers/{subuser_name}/monitor"); + request.setBody("{\"frequency\":50000,\"email\":\"example@example.com\"}"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_subusers__subuser_name__monitor_get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "subusers/{subuser_name}/monitor"; + request.setMethod(Method.GET); + request.setEndpoint("subusers/{subuser_name}/monitor"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_subusers__subuser_name__monitor_delete() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "204"); Request request = new Request(); - request.method = Method.DELETE; - request.endpoint = "subusers/{subuser_name}/monitor"; + request.setMethod(Method.DELETE); + request.setEndpoint("subusers/{subuser_name}/monitor"); Response response = sg.api(request); - Assert.assertEquals(204, response.statusCode); + Assert.assertEquals(204, response.getStatusCode()); } @Test public void test_subusers__subuser_name__stats_monthly_get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "subusers/{subuser_name}/stats/monthly"; - Map queryParams = new HashMap(); - queryParams.put("date", "test_string"); - queryParams.put("sort_by_direction", "asc"); - queryParams.put("limit", "1"); - queryParams.put("sort_by_metric", "test_string"); - queryParams.put("offset", "1"); - request.queryParams = queryParams; + request.setMethod(Method.GET); + request.setEndpoint("subusers/{subuser_name}/stats/monthly"); + request.addQueryParam("date", "test_string"); + request.addQueryParam("sort_by_direction", "asc"); + request.addQueryParam("limit", "1"); + request.addQueryParam("sort_by_metric", "test_string"); + request.addQueryParam("offset", "1"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_suppression_blocks_get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "suppression/blocks"; - Map queryParams = new HashMap(); - queryParams.put("start_time", "1"); - queryParams.put("limit", "1"); - queryParams.put("end_time", "1"); - queryParams.put("offset", "1"); - request.queryParams = queryParams; + request.setMethod(Method.GET); + request.setEndpoint("suppression/blocks"); + request.addQueryParam("start_time", "1"); + request.addQueryParam("limit", "1"); + request.addQueryParam("end_time", "1"); + request.addQueryParam("offset", "1"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_suppression_blocks_delete() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "204"); Request request = new Request(); - request.method = Method.DELETE; - request.endpoint = "suppression/blocks"; - request.body = "{\"emails\":[\"example1@example.com\",\"example2@example.com\"],\"delete_all\":false}"; + request.setMethod(Method.DELETE); + request.setEndpoint("suppression/blocks"); + request.setBody("{\"emails\":[\"example1@example.com\",\"example2@example.com\"],\"delete_all\":false}"); Response response = sg.api(request); - Assert.assertEquals(204, response.statusCode); + Assert.assertEquals(204, response.getStatusCode()); } @Test public void test_suppression_blocks__email__get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "suppression/blocks/{email}"; + request.setMethod(Method.GET); + request.setEndpoint("suppression/blocks/{email}"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_suppression_blocks__email__delete() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "204"); Request request = new Request(); - request.method = Method.DELETE; - request.endpoint = "suppression/blocks/{email}"; + request.setMethod(Method.DELETE); + request.setEndpoint("suppression/blocks/{email}"); Response response = sg.api(request); - Assert.assertEquals(204, response.statusCode); + Assert.assertEquals(204, response.getStatusCode()); } @Test public void test_suppression_bounces_get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "suppression/bounces"; - Map queryParams = new HashMap(); - queryParams.put("start_time", "1"); - queryParams.put("end_time", "1"); - request.queryParams = queryParams; + request.setMethod(Method.GET); + request.setEndpoint("suppression/bounces"); + request.addQueryParam("start_time", "1"); + request.addQueryParam("end_time", "1"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_suppression_bounces_delete() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "204"); Request request = new Request(); - request.method = Method.DELETE; - request.endpoint = "suppression/bounces"; - request.body = "{\"emails\":[\"example@example.com\",\"example2@example.com\"],\"delete_all\":true}"; + request.setMethod(Method.DELETE); + request.setEndpoint("suppression/bounces"); + request.setBody("{\"emails\":[\"example@example.com\",\"example2@example.com\"],\"delete_all\":true}"); Response response = sg.api(request); - Assert.assertEquals(204, response.statusCode); + Assert.assertEquals(204, response.getStatusCode()); } @Test public void test_suppression_bounces__email__get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "suppression/bounces/{email}"; + request.setMethod(Method.GET); + request.setEndpoint("suppression/bounces/{email}"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_suppression_bounces__email__delete() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "204"); Request request = new Request(); - request.method = Method.DELETE; - request.endpoint = "suppression/bounces/{email}"; - Map queryParams = new HashMap(); - queryParams.put("email_address", "example@example.com"); - request.queryParams = queryParams; + request.setMethod(Method.DELETE); + request.setEndpoint("suppression/bounces/{email}"); + request.addQueryParam("email_address", "example@example.com"); Response response = sg.api(request); - Assert.assertEquals(204, response.statusCode); + Assert.assertEquals(204, response.getStatusCode()); } @Test public void test_suppression_invalid_emails_get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "suppression/invalid_emails"; - Map queryParams = new HashMap(); - queryParams.put("start_time", "1"); - queryParams.put("limit", "1"); - queryParams.put("end_time", "1"); - queryParams.put("offset", "1"); - request.queryParams = queryParams; + request.setMethod(Method.GET); + request.setEndpoint("suppression/invalid_emails"); + request.addQueryParam("start_time", "1"); + request.addQueryParam("limit", "1"); + request.addQueryParam("end_time", "1"); + request.addQueryParam("offset", "1"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_suppression_invalid_emails_delete() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "204"); Request request = new Request(); - request.method = Method.DELETE; - request.endpoint = "suppression/invalid_emails"; - request.body = "{\"emails\":[\"example1@example.com\",\"example2@example.com\"],\"delete_all\":false}"; + request.setMethod(Method.DELETE); + request.setEndpoint("suppression/invalid_emails"); + request.setBody("{\"emails\":[\"example1@example.com\",\"example2@example.com\"],\"delete_all\":false}"); Response response = sg.api(request); - Assert.assertEquals(204, response.statusCode); + Assert.assertEquals(204, response.getStatusCode()); } @Test public void test_suppression_invalid_emails__email__get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "suppression/invalid_emails/{email}"; + request.setMethod(Method.GET); + request.setEndpoint("suppression/invalid_emails/{email}"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_suppression_invalid_emails__email__delete() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "204"); Request request = new Request(); - request.method = Method.DELETE; - request.endpoint = "suppression/invalid_emails/{email}"; + request.setMethod(Method.DELETE); + request.setEndpoint("suppression/invalid_emails/{email}"); Response response = sg.api(request); - Assert.assertEquals(204, response.statusCode); + Assert.assertEquals(204, response.getStatusCode()); } @Test public void test_suppression_spam_report__email__get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "suppression/spam_report/{email}"; + request.setMethod(Method.GET); + request.setEndpoint("suppression/spam_report/{email}"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_suppression_spam_report__email__delete() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "204"); Request request = new Request(); - request.method = Method.DELETE; - request.endpoint = "suppression/spam_report/{email}"; + request.setMethod(Method.DELETE); + request.setEndpoint("suppression/spam_report/{email}"); Response response = sg.api(request); - Assert.assertEquals(204, response.statusCode); + Assert.assertEquals(204, response.getStatusCode()); } @Test public void test_suppression_spam_reports_get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "suppression/spam_reports"; - Map queryParams = new HashMap(); - queryParams.put("start_time", "1"); - queryParams.put("limit", "1"); - queryParams.put("end_time", "1"); - queryParams.put("offset", "1"); - request.queryParams = queryParams; + request.setMethod(Method.GET); + request.setEndpoint("suppression/spam_reports"); + request.addQueryParam("start_time", "1"); + request.addQueryParam("limit", "1"); + request.addQueryParam("end_time", "1"); + request.addQueryParam("offset", "1"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_suppression_spam_reports_delete() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "204"); Request request = new Request(); - request.method = Method.DELETE; - request.endpoint = "suppression/spam_reports"; - request.body = "{\"emails\":[\"example1@example.com\",\"example2@example.com\"],\"delete_all\":false}"; + request.setMethod(Method.DELETE); + request.setEndpoint("suppression/spam_reports"); + request.setBody("{\"emails\":[\"example1@example.com\",\"example2@example.com\"],\"delete_all\":false}"); Response response = sg.api(request); - Assert.assertEquals(204, response.statusCode); + Assert.assertEquals(204, response.getStatusCode()); } @Test public void test_suppression_unsubscribes_get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "suppression/unsubscribes"; - Map queryParams = new HashMap(); - queryParams.put("start_time", "1"); - queryParams.put("limit", "1"); - queryParams.put("end_time", "1"); - queryParams.put("offset", "1"); - request.queryParams = queryParams; + request.setMethod(Method.GET); + request.setEndpoint("suppression/unsubscribes"); + request.addQueryParam("start_time", "1"); + request.addQueryParam("limit", "1"); + request.addQueryParam("end_time", "1"); + request.addQueryParam("offset", "1"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_templates_post() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "201"); Request request = new Request(); - request.method = Method.POST; - request.endpoint = "templates"; - request.body = "{\"name\":\"example_name\"}"; + request.setMethod(Method.POST); + request.setEndpoint("templates"); + request.setBody("{\"name\":\"example_name\"}"); Response response = sg.api(request); - Assert.assertEquals(201, response.statusCode); + Assert.assertEquals(201, response.getStatusCode()); } @Test public void test_templates_get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "templates"; + request.setMethod(Method.GET); + request.setEndpoint("templates"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_templates__template_id__patch() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.PATCH; - request.endpoint = "templates/{template_id}"; - request.body = "{\"name\":\"new_example_name\"}"; + request.setMethod(Method.PATCH); + request.setEndpoint("templates/{template_id}"); + request.setBody("{\"name\":\"new_example_name\"}"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_templates__template_id__get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "templates/{template_id}"; + request.setMethod(Method.GET); + request.setEndpoint("templates/{template_id}"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_templates__template_id__delete() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "204"); Request request = new Request(); - request.method = Method.DELETE; - request.endpoint = "templates/{template_id}"; + request.setMethod(Method.DELETE); + request.setEndpoint("templates/{template_id}"); Response response = sg.api(request); - Assert.assertEquals(204, response.statusCode); + Assert.assertEquals(204, response.getStatusCode()); } @Test public void test_templates__template_id__versions_post() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "201"); Request request = new Request(); - request.method = Method.POST; - request.endpoint = "templates/{template_id}/versions"; - request.body = "{\"name\":\"example_version_name\",\"html_content\":\"<%body%>\",\"plain_content\":\"<%body%>\",\"active\":1,\"template_id\":\"ddb96bbc-9b92-425e-8979-99464621b543\",\"subject\":\"<%subject%>\"}"; + request.setMethod(Method.POST); + request.setEndpoint("templates/{template_id}/versions"); + request.setBody("{\"name\":\"example_version_name\",\"html_content\":\"<%body%>\",\"plain_content\":\"<%body%>\",\"active\":1,\"template_id\":\"ddb96bbc-9b92-425e-8979-99464621b543\",\"subject\":\"<%subject%>\"}"); Response response = sg.api(request); - Assert.assertEquals(201, response.statusCode); + Assert.assertEquals(201, response.getStatusCode()); } @Test public void test_templates__template_id__versions__version_id__patch() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.PATCH; - request.endpoint = "templates/{template_id}/versions/{version_id}"; - request.body = "{\"active\":1,\"html_content\":\"<%body%>\",\"subject\":\"<%subject%>\",\"name\":\"updated_example_name\",\"plain_content\":\"<%body%>\"}"; + request.setMethod(Method.PATCH); + request.setEndpoint("templates/{template_id}/versions/{version_id}"); + request.setBody("{\"active\":1,\"html_content\":\"<%body%>\",\"subject\":\"<%subject%>\",\"name\":\"updated_example_name\",\"plain_content\":\"<%body%>\"}"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_templates__template_id__versions__version_id__get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "templates/{template_id}/versions/{version_id}"; + request.setMethod(Method.GET); + request.setEndpoint("templates/{template_id}/versions/{version_id}"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_templates__template_id__versions__version_id__delete() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "204"); Request request = new Request(); - request.method = Method.DELETE; - request.endpoint = "templates/{template_id}/versions/{version_id}"; + request.setMethod(Method.DELETE); + request.setEndpoint("templates/{template_id}/versions/{version_id}"); Response response = sg.api(request); - Assert.assertEquals(204, response.statusCode); + Assert.assertEquals(204, response.getStatusCode()); } @Test public void test_templates__template_id__versions__version_id__activate_post() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.POST; - request.endpoint = "templates/{template_id}/versions/{version_id}/activate"; + request.setMethod(Method.POST); + request.setEndpoint("templates/{template_id}/versions/{version_id}/activate"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_tracking_settings_get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "tracking_settings"; - Map queryParams = new HashMap(); - queryParams.put("limit", "1"); - queryParams.put("offset", "1"); - request.queryParams = queryParams; + request.setMethod(Method.GET); + request.setEndpoint("tracking_settings"); + request.addQueryParam("limit", "1"); + request.addQueryParam("offset", "1"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_tracking_settings_click_patch() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.PATCH; - request.endpoint = "tracking_settings/click"; - request.body = "{\"enabled\":true}"; + request.setMethod(Method.PATCH); + request.setEndpoint("tracking_settings/click"); + request.setBody("{\"enabled\":true}"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_tracking_settings_click_get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "tracking_settings/click"; + request.setMethod(Method.GET); + request.setEndpoint("tracking_settings/click"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_tracking_settings_google_analytics_patch() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.PATCH; - request.endpoint = "tracking_settings/google_analytics"; - request.body = "{\"utm_campaign\":\"website\",\"utm_term\":\"\",\"utm_content\":\"\",\"enabled\":true,\"utm_source\":\"sendgrid.com\",\"utm_medium\":\"email\"}"; + request.setMethod(Method.PATCH); + request.setEndpoint("tracking_settings/google_analytics"); + request.setBody("{\"utm_campaign\":\"website\",\"utm_term\":\"\",\"utm_content\":\"\",\"enabled\":true,\"utm_source\":\"sendgrid.com\",\"utm_medium\":\"email\"}"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_tracking_settings_google_analytics_get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "tracking_settings/google_analytics"; + request.setMethod(Method.GET); + request.setEndpoint("tracking_settings/google_analytics"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_tracking_settings_open_patch() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.PATCH; - request.endpoint = "tracking_settings/open"; - request.body = "{\"enabled\":true}"; + request.setMethod(Method.PATCH); + request.setEndpoint("tracking_settings/open"); + request.setBody("{\"enabled\":true}"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_tracking_settings_open_get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "tracking_settings/open"; + request.setMethod(Method.GET); + request.setEndpoint("tracking_settings/open"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_tracking_settings_subscription_patch() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.PATCH; - request.endpoint = "tracking_settings/subscription"; - request.body = "{\"url\":\"url\",\"html_content\":\"html content\",\"enabled\":true,\"landing\":\"landing page html\",\"replace\":\"replacement tag\",\"plain_content\":\"text content\"}"; + request.setMethod(Method.PATCH); + request.setEndpoint("tracking_settings/subscription"); + request.setBody("{\"url\":\"url\",\"html_content\":\"html content\",\"enabled\":true,\"landing\":\"landing page html\",\"replace\":\"replacement tag\",\"plain_content\":\"text content\"}"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_tracking_settings_subscription_get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "tracking_settings/subscription"; + request.setMethod(Method.GET); + request.setEndpoint("tracking_settings/subscription"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_user_account_get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "user/account"; + request.setMethod(Method.GET); + request.setEndpoint("user/account"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_user_credits_get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "user/credits"; + request.setMethod(Method.GET); + request.setEndpoint("user/credits"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_user_email_put() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.PUT; - request.endpoint = "user/email"; - request.body = "{\"email\":\"example@example.com\"}"; + request.setMethod(Method.PUT); + request.setEndpoint("user/email"); + request.setBody("{\"email\":\"example@example.com\"}"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_user_email_get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "user/email"; + request.setMethod(Method.GET); + request.setEndpoint("user/email"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_user_password_put() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.PUT; - request.endpoint = "user/password"; - request.body = "{\"new_password\":\"new_password\",\"old_password\":\"old_password\"}"; + request.setMethod(Method.PUT); + request.setEndpoint("user/password"); + request.setBody("{\"new_password\":\"new_password\",\"old_password\":\"old_password\"}"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_user_profile_patch() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.PATCH; - request.endpoint = "user/profile"; - request.body = "{\"city\":\"Orange\",\"first_name\":\"Example\",\"last_name\":\"User\"}"; + request.setMethod(Method.PATCH); + request.setEndpoint("user/profile"); + request.setBody("{\"city\":\"Orange\",\"first_name\":\"Example\",\"last_name\":\"User\"}"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_user_profile_get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "user/profile"; + request.setMethod(Method.GET); + request.setEndpoint("user/profile"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_user_scheduled_sends_post() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "201"); Request request = new Request(); - request.method = Method.POST; - request.endpoint = "user/scheduled_sends"; - request.body = "{\"batch_id\":\"YOUR_BATCH_ID\",\"status\":\"pause\"}"; + request.setMethod(Method.POST); + request.setEndpoint("user/scheduled_sends"); + request.setBody("{\"batch_id\":\"YOUR_BATCH_ID\",\"status\":\"pause\"}"); Response response = sg.api(request); - Assert.assertEquals(201, response.statusCode); + Assert.assertEquals(201, response.getStatusCode()); } @Test public void test_user_scheduled_sends_get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "user/scheduled_sends"; + request.setMethod(Method.GET); + request.setEndpoint("user/scheduled_sends"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_user_scheduled_sends__batch_id__patch() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "204"); Request request = new Request(); - request.method = Method.PATCH; - request.endpoint = "user/scheduled_sends/{batch_id}"; - request.body = "{\"status\":\"pause\"}"; + request.setMethod(Method.PATCH); + request.setEndpoint("user/scheduled_sends/{batch_id}"); + request.setBody("{\"status\":\"pause\"}"); Response response = sg.api(request); - Assert.assertEquals(204, response.statusCode); + Assert.assertEquals(204, response.getStatusCode()); } @Test public void test_user_scheduled_sends__batch_id__get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "user/scheduled_sends/{batch_id}"; + request.setMethod(Method.GET); + request.setEndpoint("user/scheduled_sends/{batch_id}"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_user_scheduled_sends__batch_id__delete() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "204"); Request request = new Request(); - request.method = Method.DELETE; - request.endpoint = "user/scheduled_sends/{batch_id}"; + request.setMethod(Method.DELETE); + request.setEndpoint("user/scheduled_sends/{batch_id}"); Response response = sg.api(request); - Assert.assertEquals(204, response.statusCode); + Assert.assertEquals(204, response.getStatusCode()); } @Test public void test_user_settings_enforced_tls_patch() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.PATCH; - request.endpoint = "user/settings/enforced_tls"; - request.body = "{\"require_tls\":true,\"require_valid_cert\":false}"; + request.setMethod(Method.PATCH); + request.setEndpoint("user/settings/enforced_tls"); + request.setBody("{\"require_tls\":true,\"require_valid_cert\":false}"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_user_settings_enforced_tls_get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "user/settings/enforced_tls"; + request.setMethod(Method.GET); + request.setEndpoint("user/settings/enforced_tls"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_user_username_put() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.PUT; - request.endpoint = "user/username"; - request.body = "{\"username\":\"test_username\"}"; + request.setMethod(Method.PUT); + request.setEndpoint("user/username"); + request.setBody("{\"username\":\"test_username\"}"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_user_username_get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "user/username"; + request.setMethod(Method.GET); + request.setEndpoint("user/username"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_user_webhooks_event_settings_patch() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.PATCH; - request.endpoint = "user/webhooks/event/settings"; - request.body = "{\"group_resubscribe\":true,\"delivered\":true,\"group_unsubscribe\":true,\"spam_report\":true,\"url\":\"url\",\"enabled\":true,\"bounce\":true,\"deferred\":true,\"unsubscribe\":true,\"dropped\":true,\"open\":true,\"click\":true,\"processed\":true}"; + request.setMethod(Method.PATCH); + request.setEndpoint("user/webhooks/event/settings"); + request.setBody("{\"group_resubscribe\":true,\"delivered\":true,\"group_unsubscribe\":true,\"spam_report\":true,\"url\":\"url\",\"enabled\":true,\"bounce\":true,\"deferred\":true,\"unsubscribe\":true,\"dropped\":true,\"open\":true,\"click\":true,\"processed\":true}"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_user_webhooks_event_settings_get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "user/webhooks/event/settings"; + request.setMethod(Method.GET); + request.setEndpoint("user/webhooks/event/settings"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_user_webhooks_event_test_post() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "204"); Request request = new Request(); - request.method = Method.POST; - request.endpoint = "user/webhooks/event/test"; - request.body = "{\"url\":\"url\"}"; + request.setMethod(Method.POST); + request.setEndpoint("user/webhooks/event/test"); + request.setBody("{\"url\":\"url\"}"); Response response = sg.api(request); - Assert.assertEquals(204, response.statusCode); + Assert.assertEquals(204, response.getStatusCode()); } @Test public void test_user_webhooks_parse_settings_post() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "201"); Request request = new Request(); - request.method = Method.POST; - request.endpoint = "user/webhooks/parse/settings"; - request.body = "{\"url\":\"http://email.myhosthame.com\",\"send_raw\":false,\"hostname\":\"myhostname.com\",\"spam_check\":true}"; + request.setMethod(Method.POST); + request.setEndpoint("user/webhooks/parse/settings"); + request.setBody("{\"url\":\"http://email.myhosthame.com\",\"send_raw\":false,\"hostname\":\"myhostname.com\",\"spam_check\":true}"); Response response = sg.api(request); - Assert.assertEquals(201, response.statusCode); + Assert.assertEquals(201, response.getStatusCode()); } @Test public void test_user_webhooks_parse_settings_get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "user/webhooks/parse/settings"; + request.setMethod(Method.GET); + request.setEndpoint("user/webhooks/parse/settings"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_user_webhooks_parse_settings__hostname__patch() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.PATCH; - request.endpoint = "user/webhooks/parse/settings/{hostname}"; - request.body = "{\"url\":\"http://newdomain.com/parse\",\"send_raw\":true,\"spam_check\":false}"; + request.setMethod(Method.PATCH); + request.setEndpoint("user/webhooks/parse/settings/{hostname}"); + request.setBody("{\"url\":\"http://newdomain.com/parse\",\"send_raw\":true,\"spam_check\":false}"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_user_webhooks_parse_settings__hostname__get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "user/webhooks/parse/settings/{hostname}"; + request.setMethod(Method.GET); + request.setEndpoint("user/webhooks/parse/settings/{hostname}"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_user_webhooks_parse_settings__hostname__delete() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "204"); Request request = new Request(); - request.method = Method.DELETE; - request.endpoint = "user/webhooks/parse/settings/{hostname}"; + request.setMethod(Method.DELETE); + request.setEndpoint("user/webhooks/parse/settings/{hostname}"); Response response = sg.api(request); - Assert.assertEquals(204, response.statusCode); + Assert.assertEquals(204, response.getStatusCode()); } @Test public void test_user_webhooks_parse_stats_get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "user/webhooks/parse/stats"; - Map queryParams = new HashMap(); - queryParams.put("aggregated_by", "day"); - queryParams.put("limit", "test_string"); - queryParams.put("start_date", "2016-01-01"); - queryParams.put("end_date", "2016-04-01"); - queryParams.put("offset", "test_string"); - request.queryParams = queryParams; + request.setMethod(Method.GET); + request.setEndpoint("user/webhooks/parse/stats"); + request.addQueryParam("aggregated_by", "day"); + request.addQueryParam("limit", "test_string"); + request.addQueryParam("start_date", "2016-01-01"); + request.addQueryParam("end_date", "2016-04-01"); + request.addQueryParam("offset", "test_string"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_whitelabel_domains_post() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "201"); Request request = new Request(); - request.method = Method.POST; - request.endpoint = "whitelabel/domains"; - request.body = "{\"automatic_security\":false,\"username\":\"john@example.com\",\"domain\":\"example.com\",\"default\":true,\"custom_spf\":true,\"ips\":[\"192.168.1.1\",\"192.168.1.2\"],\"subdomain\":\"news\"}"; + request.setMethod(Method.POST); + request.setEndpoint("whitelabel/domains"); + request.setBody("{\"automatic_security\":false,\"username\":\"john@example.com\",\"domain\":\"example.com\",\"default\":true,\"custom_spf\":true,\"ips\":[\"192.168.1.1\",\"192.168.1.2\"],\"subdomain\":\"news\"}"); Response response = sg.api(request); - Assert.assertEquals(201, response.statusCode); + Assert.assertEquals(201, response.getStatusCode()); } @Test public void test_whitelabel_domains_get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "whitelabel/domains"; - Map queryParams = new HashMap(); - queryParams.put("username", "test_string"); - queryParams.put("domain", "test_string"); - queryParams.put("exclude_subusers", "true"); - queryParams.put("limit", "1"); - queryParams.put("offset", "1"); - request.queryParams = queryParams; + request.setMethod(Method.GET); + request.setEndpoint("whitelabel/domains"); + request.addQueryParam("username", "test_string"); + request.addQueryParam("domain", "test_string"); + request.addQueryParam("exclude_subusers", "true"); + request.addQueryParam("limit", "1"); + request.addQueryParam("offset", "1"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_whitelabel_domains_default_get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "whitelabel/domains/default"; + request.setMethod(Method.GET); + request.setEndpoint("whitelabel/domains/default"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_whitelabel_domains_subuser_get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "whitelabel/domains/subuser"; + request.setMethod(Method.GET); + request.setEndpoint("whitelabel/domains/subuser"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_whitelabel_domains_subuser_delete() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "204"); Request request = new Request(); - request.method = Method.DELETE; - request.endpoint = "whitelabel/domains/subuser"; + request.setMethod(Method.DELETE); + request.setEndpoint("whitelabel/domains/subuser"); Response response = sg.api(request); - Assert.assertEquals(204, response.statusCode); + Assert.assertEquals(204, response.getStatusCode()); } @Test public void test_whitelabel_domains__domain_id__patch() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.PATCH; - request.endpoint = "whitelabel/domains/{domain_id}"; - request.body = "{\"default\":false,\"custom_spf\":true}"; + request.setMethod(Method.PATCH); + request.setEndpoint("whitelabel/domains/{domain_id}"); + request.setBody("{\"default\":false,\"custom_spf\":true}"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_whitelabel_domains__domain_id__get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "whitelabel/domains/{domain_id}"; + request.setMethod(Method.GET); + request.setEndpoint("whitelabel/domains/{domain_id}"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_whitelabel_domains__domain_id__delete() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "204"); Request request = new Request(); - request.method = Method.DELETE; - request.endpoint = "whitelabel/domains/{domain_id}"; + request.setMethod(Method.DELETE); + request.setEndpoint("whitelabel/domains/{domain_id}"); Response response = sg.api(request); - Assert.assertEquals(204, response.statusCode); + Assert.assertEquals(204, response.getStatusCode()); } @Test public void test_whitelabel_domains__domain_id__subuser_post() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "201"); Request request = new Request(); - request.method = Method.POST; - request.endpoint = "whitelabel/domains/{domain_id}/subuser"; - request.body = "{\"username\":\"jane@example.com\"}"; + request.setMethod(Method.POST); + request.setEndpoint("whitelabel/domains/{domain_id}/subuser"); + request.setBody("{\"username\":\"jane@example.com\"}"); Response response = sg.api(request); - Assert.assertEquals(201, response.statusCode); + Assert.assertEquals(201, response.getStatusCode()); } @Test public void test_whitelabel_domains__id__ips_post() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.POST; - request.endpoint = "whitelabel/domains/{id}/ips"; - request.body = "{\"ip\":\"192.168.0.1\"}"; + request.setMethod(Method.POST); + request.setEndpoint("whitelabel/domains/{id}/ips"); + request.setBody("{\"ip\":\"192.168.0.1\"}"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_whitelabel_domains__id__ips__ip__delete() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.DELETE; - request.endpoint = "whitelabel/domains/{id}/ips/{ip}"; + request.setMethod(Method.DELETE); + request.setEndpoint("whitelabel/domains/{id}/ips/{ip}"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_whitelabel_domains__id__validate_post() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.POST; - request.endpoint = "whitelabel/domains/{id}/validate"; + request.setMethod(Method.POST); + request.setEndpoint("whitelabel/domains/{id}/validate"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_whitelabel_ips_post() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "201"); Request request = new Request(); - request.method = Method.POST; - request.endpoint = "whitelabel/ips"; - request.body = "{\"ip\":\"192.168.1.1\",\"domain\":\"example.com\",\"subdomain\":\"email\"}"; + request.setMethod(Method.POST); + request.setEndpoint("whitelabel/ips"); + request.setBody("{\"ip\":\"192.168.1.1\",\"domain\":\"example.com\",\"subdomain\":\"email\"}"); Response response = sg.api(request); - Assert.assertEquals(201, response.statusCode); + Assert.assertEquals(201, response.getStatusCode()); } @Test public void test_whitelabel_ips_get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "whitelabel/ips"; - Map queryParams = new HashMap(); - queryParams.put("ip", "test_string"); - queryParams.put("limit", "1"); - queryParams.put("offset", "1"); - request.queryParams = queryParams; + request.setMethod(Method.GET); + request.setEndpoint("whitelabel/ips"); + request.addQueryParam("ip", "test_string"); + request.addQueryParam("limit", "1"); + request.addQueryParam("offset", "1"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_whitelabel_ips__id__get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "whitelabel/ips/{id}"; + request.setMethod(Method.GET); + request.setEndpoint("whitelabel/ips/{id}"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_whitelabel_ips__id__delete() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "204"); Request request = new Request(); - request.method = Method.DELETE; - request.endpoint = "whitelabel/ips/{id}"; + request.setMethod(Method.DELETE); + request.setEndpoint("whitelabel/ips/{id}"); Response response = sg.api(request); - Assert.assertEquals(204, response.statusCode); + Assert.assertEquals(204, response.getStatusCode()); } @Test public void test_whitelabel_ips__id__validate_post() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.POST; - request.endpoint = "whitelabel/ips/{id}/validate"; + request.setMethod(Method.POST); + request.setEndpoint("whitelabel/ips/{id}/validate"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_whitelabel_links_post() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "201"); Request request = new Request(); - request.method = Method.POST; - request.endpoint = "whitelabel/links"; - request.body = "{\"default\":true,\"domain\":\"example.com\",\"subdomain\":\"mail\"}"; - Map queryParams = new HashMap(); - queryParams.put("limit", "1"); - queryParams.put("offset", "1"); - request.queryParams = queryParams; + request.setMethod(Method.POST); + request.setEndpoint("whitelabel/links"); + request.setBody("{\"default\":true,\"domain\":\"example.com\",\"subdomain\":\"mail\"}"); + request.addQueryParam("limit", "1"); + request.addQueryParam("offset", "1"); Response response = sg.api(request); - Assert.assertEquals(201, response.statusCode); + Assert.assertEquals(201, response.getStatusCode()); } @Test public void test_whitelabel_links_get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "whitelabel/links"; - Map queryParams = new HashMap(); - queryParams.put("limit", "1"); - request.queryParams = queryParams; + request.setMethod(Method.GET); + request.setEndpoint("whitelabel/links"); + request.addQueryParam("limit", "1"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_whitelabel_links_default_get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "whitelabel/links/default"; - Map queryParams = new HashMap(); - queryParams.put("domain", "test_string"); - request.queryParams = queryParams; + request.setMethod(Method.GET); + request.setEndpoint("whitelabel/links/default"); + request.addQueryParam("domain", "test_string"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_whitelabel_links_subuser_get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "whitelabel/links/subuser"; - Map queryParams = new HashMap(); - queryParams.put("username", "test_string"); - request.queryParams = queryParams; + request.setMethod(Method.GET); + request.setEndpoint("whitelabel/links/subuser"); + request.addQueryParam("username", "test_string"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_whitelabel_links_subuser_delete() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "204"); Request request = new Request(); - request.method = Method.DELETE; - request.endpoint = "whitelabel/links/subuser"; - Map queryParams = new HashMap(); - queryParams.put("username", "test_string"); - request.queryParams = queryParams; + request.setMethod(Method.DELETE); + request.setEndpoint("whitelabel/links/subuser"); + request.addQueryParam("username", "test_string"); Response response = sg.api(request); - Assert.assertEquals(204, response.statusCode); + Assert.assertEquals(204, response.getStatusCode()); } @Test public void test_whitelabel_links__id__patch() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.PATCH; - request.endpoint = "whitelabel/links/{id}"; - request.body = "{\"default\":true}"; + request.setMethod(Method.PATCH); + request.setEndpoint("whitelabel/links/{id}"); + request.setBody("{\"default\":true}"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_whitelabel_links__id__get() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.GET; - request.endpoint = "whitelabel/links/{id}"; + request.setMethod(Method.GET); + request.setEndpoint("whitelabel/links/{id}"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_whitelabel_links__id__delete() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "204"); Request request = new Request(); - request.method = Method.DELETE; - request.endpoint = "whitelabel/links/{id}"; + request.setMethod(Method.DELETE); + request.setEndpoint("whitelabel/links/{id}"); Response response = sg.api(request); - Assert.assertEquals(204, response.statusCode); + Assert.assertEquals(204, response.getStatusCode()); } @Test public void test_whitelabel_links__id__validate_post() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.POST; - request.endpoint = "whitelabel/links/{id}/validate"; + request.setMethod(Method.POST); + request.setEndpoint("whitelabel/links/{id}/validate"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } @Test public void test_whitelabel_links__link_id__subuser_post() throws IOException { - SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { - sg = new SendGrid("SENDGRID_API_KEY"); - sg.setHost(System.getenv("MOCK_HOST")); - } else { - sg = new SendGrid("SENDGRID_API_KEY", true); - sg.setHost("localhost:4010"); - } + SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); + sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); Request request = new Request(); - request.method = Method.POST; - request.endpoint = "whitelabel/links/{link_id}/subuser"; - request.body = "{\"username\":\"jane@example.com\"}"; + request.setMethod(Method.POST); + request.setEndpoint("whitelabel/links/{link_id}/subuser"); + request.setBody("{\"username\":\"jane@example.com\"}"); Response response = sg.api(request); - Assert.assertEquals(200, response.statusCode); + Assert.assertEquals(200, response.getStatusCode()); } } diff --git a/src/test/java/com/sendgrid/TestRequiredFilesExist.java b/src/test/java/com/sendgrid/TestRequiredFilesExist.java new file mode 100644 index 00000000..928758b9 --- /dev/null +++ b/src/test/java/com/sendgrid/TestRequiredFilesExist.java @@ -0,0 +1,94 @@ +package com.sendgrid; + +import org.junit.Test; + +import java.io.File; + +import static org.junit.Assert.assertTrue; + +public class TestRequiredFilesExist { + + // ./Docker or docker/Docker + @Test public void checkDockerExists() { + boolean dockerExists = new File("./Dockerfile").exists() || + new File("./docker/Dockerfile").exists(); + assertTrue(dockerExists); + } + + // // ./docker-compose.yml or ./docker/docker-compose.yml + // @Test public void checkDockerComposeExists() { + // boolean dockerComposeExists = new File("./docker-compose.yml").exists() || + // new File("./docker/docker-compose.yml").exists(); + // assertTrue(dockerComposeExists); + // } + + // ./.env_sample + @Test public void checkEnvSampleExists() { + assertTrue(new File("./.env_sample").exists()); + } + + // ./.gitignore + @Test public void checkGitIgnoreExists() { + assertTrue(new File("./.gitignore").exists()); + } + + // ./.travis.yml + @Test public void checkTravisExists() { + assertTrue(new File("./.travis.yml").exists()); + } + + // ./.codeclimate.yml + @Test public void checkCodeClimateExists() { + assertTrue(new File("./.codeclimate.yml").exists()); + } + + // ./CHANGELOG.md + @Test public void checkChangelogExists() { + assertTrue(new File("./CHANGELOG.md").exists()); + } + + // ./CODE_OF_CONDUCT.md + @Test public void checkCodeOfConductExists() { + assertTrue(new File("./CODE_OF_CONDUCT.md").exists()); + } + + // ./CONTRIBUTING.md + @Test public void checkContributingGuideExists() { + assertTrue(new File("./CONTRIBUTING.md").exists()); + } + + // ./.github/ISSUE_TEMPLATE + @Test public void checkIssuesTemplateExists() { + assertTrue(new File("./.github/ISSUE_TEMPLATE").exists()); + } + + // ./LICENSE.md + @Test public void checkLicenseExists() { + assertTrue(new File("./LICENSE.md").exists()); + } + + // ./.github/PULL_REQUEST_TEMPLATE + @Test public void checkPullRequestExists() { + assertTrue(new File("./.github/PULL_REQUEST_TEMPLATE").exists()); + } + + // ./README.md + @Test public void checkReadMeExists() { + assertTrue(new File("./README.md").exists()); + } + + // ./TROUBLESHOOTING.md + @Test public void checkTroubleShootingGuideExists() { + assertTrue(new File("./TROUBLESHOOTING.md").exists()); + } + + // ./USAGE.md + @Test public void checkUsageGuideExists() { + assertTrue(new File("./USAGE.md").exists()); + } + + // ./USE_CASES.md + @Test public void checkUseCases() { + assertTrue(new File("./USE_CASES.md").exists()); + } +} diff --git a/src/test/java/com/sendgrid/helpers/AttachmentBuilderTest.java b/src/test/java/com/sendgrid/helpers/AttachmentBuilderTest.java new file mode 100644 index 00000000..3ea3f379 --- /dev/null +++ b/src/test/java/com/sendgrid/helpers/AttachmentBuilderTest.java @@ -0,0 +1,49 @@ +package com.sendgrid.helpers; + +import com.sendgrid.helpers.mail.objects.Attachments; +import org.apache.commons.codec.binary.Base64; +import org.junit.Assert; +import org.junit.Test; + +import java.io.ByteArrayInputStream; +import java.io.InputStream; +import java.nio.charset.Charset; + +public class AttachmentBuilderTest { + + @Test + public void testCreateAttachments() { + String fileName = "book.txt"; + String type = "text/plain"; + String content = "This test checks if the builder works fine"; + InputStream contentStream = new ByteArrayInputStream(content.getBytes(Charset.forName("UTF-8"))); + String contentId = "someId"; + String dispositon = "someDisposition"; + + Attachments attachments = new Attachments.Builder(fileName, contentStream) + .withType(type) + .withContentId(contentId) + .withDisposition(dispositon) + .build(); + + Assert.assertEquals(attachments.getType(), type); + Assert.assertEquals(attachments.getFilename(), fileName); + Assert.assertEquals(attachments.getContentId(), contentId); + Assert.assertEquals(attachments.getDisposition(), dispositon); + Assert.assertEquals(attachments.getContent(), Base64.encodeBase64String(content.getBytes(Charset.forName("UTF-8")))); + } + + @Test(expected = IllegalArgumentException.class) + public void testCreateAttachmentsMissingRequiredFileNameParam() { + String content = "This test checks if the builder works fine"; + InputStream contentStream = new ByteArrayInputStream(content.getBytes(Charset.forName("UTF-8"))); + Attachments attachments = new Attachments.Builder(null, contentStream).build(); + } + + @Test(expected = IllegalArgumentException.class) + public void testCreateAttachmentsMissingRequiredContentParam() { + String type = "text"; + String content = null; + Attachments attachments = new Attachments.Builder(type, content).build(); + } +} diff --git a/src/test/java/com/sendgrid/helpers/ContentTest.java b/src/test/java/com/sendgrid/helpers/ContentTest.java new file mode 100644 index 00000000..c83b0d2e --- /dev/null +++ b/src/test/java/com/sendgrid/helpers/ContentTest.java @@ -0,0 +1,48 @@ +package com.sendgrid.helpers; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import com.sendgrid.helpers.mail.objects.Content; +import org.junit.rules.ExpectedException; + +import java.util.ArrayList; +import java.util.Arrays; + +public class ContentTest { + private Content content; + + @Before + public void setUp() { + this.content = new Content(); + } + + @Rule + public final ExpectedException exception = ExpectedException.none(); + + @Test + public void testForbiddenContentIsRejected() { + + ArrayList sampleApiKeys = new ArrayList<>( + Arrays.asList( + "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", + "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" + ) + + ); + + for (String apiKey: sampleApiKeys) { + exception.expect(IllegalArgumentException.class); + this.content.setValue("My api key is: " + apiKey); + } + } + + @Test + public void testNormalContentIsAllowed() { + String message = "I will not send you my api key!"; + this.content.setValue(message); + Assert.assertEquals(message, this.content.getValue()); + } + +} diff --git a/src/test/java/com/sendgrid/helpers/MailTest.java b/src/test/java/com/sendgrid/helpers/MailTest.java index 21f709c0..bc49a197 100644 --- a/src/test/java/com/sendgrid/helpers/MailTest.java +++ b/src/test/java/com/sendgrid/helpers/MailTest.java @@ -1,39 +1,30 @@ -package com.sendgrid; +package com.sendgrid.helpers; + +import com.sendgrid.helpers.mail.Mail; +import com.sendgrid.helpers.mail.objects.*; +import com.fasterxml.jackson.databind.ObjectMapper; import org.junit.Assert; -import org.junit.Before; import org.junit.Test; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + import java.io.IOException; public class MailTest { @Test public void testHelloWorld() throws IOException { - Mail mail = new Mail(); - - Email fromEmail = new Email(); - fromEmail.setEmail("test@example.com"); - mail.setFrom(fromEmail); - - Personalization personalization = new Personalization(); - Email to = new Email(); - to.setEmail("test@example.com"); - personalization.addTo(to); - - mail.addPersonalization(personalization); + Email from = new Email("test@example.com"); + String subject = "Sending with SendGrid is Fun"; + Email to = new Email("test@example.com"); + Content content = new Content("text/plain", "and easy to do anywhere, even with Java"); + Mail mail = new Mail(from, subject, to, content); - mail.setSubject("Hello World from the SendGrid Java Library"); - - Content content = new Content(); - content.setType("text/plain"); - content.setValue("some text here"); - mail.addContent(content); - content.setType("text/html"); - content.setValue("some text here"); - mail.addContent(content); - - Assert.assertEquals(mail.build(), "{\"from\":{\"email\":\"test@example.com\"},\"subject\":\"Hello World from the SendGrid Java Library\",\"personalizations\":[{\"to\":[{\"email\":\"test@example.com\"}]}],\"content\":[{\"type\":\"text/plain\",\"value\":\"some text here\"},{\"type\":\"text/html\",\"value\":\"some text here\"}]}"); + Assert.assertEquals(mail.build(), "{\"from\":{\"email\":\"test@example.com\"},\"subject\":\"Sending with SendGrid is Fun\",\"personalizations\":[{\"to\":[{\"email\":\"test@example.com\"}]}],\"content\":[{\"type\":\"text/plain\",\"value\":\"and easy to do anywhere, even with Java\"}]}"); } @Test @@ -111,6 +102,48 @@ public void testKitchenSink() throws IOException { personalization2.setSendAt(1443636843); mail.addPersonalization(personalization2); + Personalization personalization3 = new Personalization(); + Email to3 = new Email(); + to3.setName("Example User"); + to3.setEmail("test@example.com"); + personalization3.addTo(to3); + to3.setName("Example User"); + to3.setEmail("test@example.com"); + personalization3.addTo(to3); + Email cc3 = new Email(); + cc3.setName("Example User"); + cc3.setEmail("test@example.com"); + personalization3.addCc(cc3); + cc3.setName("Example User"); + cc3.setEmail("test@example.com"); + personalization3.addCc(cc3); + Email bcc3 = new Email(); + bcc3.setName("Example User"); + bcc3.setEmail("test@example.com"); + personalization3.addBcc(bcc3); + bcc3.setName("Example User"); + bcc3.setEmail("test@example.com"); + personalization3.addBcc(bcc3); + personalization3.setSubject("Hello World from the Personalized SendGrid Java Library"); + personalization3.addHeader("X-Test", "test"); + personalization3.addHeader("X-Mock", "true"); + List> items = new ArrayList<>(); + Map item1 = new HashMap<>(); + item1.put("text", "New Line Sneakers"); + item1.put("price", "$ 79.95"); + items.add(item1); + Map item2 = new HashMap<>(); + item2.put("text", "Old Line Sneakers"); + item1.put("price", "$ 59.95"); + items.add(item2); + personalization3.addDynamicTemplateData("name", "Example User"); + personalization3.addDynamicTemplateData("city", "Denver"); + personalization3.addDynamicTemplateData("items", items); + personalization3.addCustomArg("user_id", "343"); + personalization3.addCustomArg("type", "marketing"); + personalization3.setSendAt(1443636843); + mail.addPersonalization(personalization3); + Content content = new Content(); content.setType("text/plain"); content.setValue("some text here"); @@ -187,7 +220,7 @@ public void testKitchenSink() throws IOException { TrackingSettings trackingSettings = new TrackingSettings(); ClickTrackingSetting clickTrackingSetting = new ClickTrackingSetting(); clickTrackingSetting.setEnable(true); - clickTrackingSetting.setEnableText(true); + clickTrackingSetting.setEnableText(false); trackingSettings.setClickTrackingSetting(clickTrackingSetting); OpenTrackingSetting openTrackingSetting = new OpenTrackingSetting(); openTrackingSetting.setEnable(true); @@ -214,6 +247,29 @@ public void testKitchenSink() throws IOException { replyTo.setEmail("test@example.com"); mail.setReplyTo(replyTo); - Assert.assertEquals(mail.build(), "{\"from\":{\"name\":\"Example User\",\"email\":\"test@example.com\"},\"subject\":\"Hello World from the SendGrid Java Library\",\"personalizations\":[{\"to\":[{\"name\":\"Example User\",\"email\":\"test@example.com\"},{\"name\":\"Example User\",\"email\":\"test@example.com\"}],\"cc\":[{\"name\":\"Example User\",\"email\":\"test@example.com\"},{\"name\":\"Example User\",\"email\":\"test@example.com\"}],\"bcc\":[{\"name\":\"Example User\",\"email\":\"test@example.com\"},{\"name\":\"Example User\",\"email\":\"test@example.com\"}],\"subject\":\"Hello World from the Personalized SendGrid Java Library\",\"headers\":{\"X-Mock\":\"true\",\"X-Test\":\"test\"},\"substitutions\":{\"%city%\":\"Denver\",\"%name%\":\"Example User\"},\"custom_args\":{\"type\":\"marketing\",\"user_id\":\"343\"},\"send_at\":1443636843},{\"to\":[{\"name\":\"Example User\",\"email\":\"test@example.com\"},{\"name\":\"Example User\",\"email\":\"test@example.com\"}],\"cc\":[{\"name\":\"Example User\",\"email\":\"test@example.com\"},{\"name\":\"Example User\",\"email\":\"test@example.com\"}],\"bcc\":[{\"name\":\"Example User\",\"email\":\"test@example.com\"},{\"name\":\"Example User\",\"email\":\"test@example.com\"}],\"subject\":\"Hello World from the Personalized SendGrid Java Library\",\"headers\":{\"X-Mock\":\"true\",\"X-Test\":\"test\"},\"substitutions\":{\"%city%\":\"Denver\",\"%name%\":\"Example User\"},\"custom_args\":{\"type\":\"marketing\",\"user_id\":\"343\"},\"send_at\":1443636843}],\"content\":[{\"type\":\"text/plain\",\"value\":\"some text here\"},{\"type\":\"text/html\",\"value\":\"some text here\"}],\"attachments\":[{\"content\":\"TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIGFkaXBpc2NpbmcgZWxpdC4gQ3JhcyBwdW12\",\"type\":\"application/pdf\",\"filename\":\"balance_001.pdf\",\"disposition\":\"attachment\",\"content_id\":\"Balance Sheet\"},{\"content\":\"BwdW\",\"type\":\"image/png\",\"filename\":\"banner.png\",\"disposition\":\"inline\",\"content_id\":\"Banner\"}],\"template_id\":\"13b8f94f-bcae-4ec6-b752-70d6cb59f932\",\"sections\":{\"%section1%\":\"Substitution Text for Section 1\",\"%section2%\":\"Substitution Text for Section 2\"},\"headers\":{\"X-Test1\":\"1\",\"X-Test2\":\"2\"},\"categories\":[\"May\",\"2016\"],\"custom_args\":{\"campaign\":\"welcome\",\"weekday\":\"morning\"},\"send_at\":1443636842,\"asm\":{\"group_id\":99,\"groups_to_display\":[4,5,6,7,8]},\"ip_pool_name\":\"23\",\"mail_settings\":{\"bcc\":{\"enable\":true,\"email\":\"test@example.com\"},\"bypass_list_management\":{\"enable\":true},\"footer\":{\"enable\":true,\"text\":\"Footer Text\",\"html\":\"Footer Text\"},\"sandbox_mode\":{\"enable\":true},\"spam_check\":{\"enable\":true,\"threshold\":1,\"post_to_url\":\"https://spamcatcher.sendgrid.com\"}},\"tracking_settings\":{\"click_tracking\":{\"enable\":true,\"enable_text\":true},\"open_tracking\":{\"enable\":true,\"substitution_tag\":\"Optional tag to replace with the open image in the body of the message\"},\"subscription_tracking\":{\"enable\":true,\"text\":\"text to insert into the text/plain portion of the message\",\"html\":\"html to insert into the text/html portion of the message\",\"substitution_tag\":\"Optional tag to replace with the open image in the body of the message\"},\"ganalytics\":{\"enable\":true,\"utm_source\":\"some source\",\"utm_term\":\"some term\",\"utm_content\":\"some content\",\"utm_campaign\":\"some name\",\"utm_medium\":\"some medium\"}},\"reply_to\":{\"name\":\"Example User\",\"email\":\"test@example.com\"}}"); + Assert.assertEquals(mail.build(), "{\"from\":{\"name\":\"Example User\",\"email\":\"test@example.com\"},\"subject\":\"Hello World from the SendGrid Java Library\",\"personalizations\":[{\"to\":[{\"name\":\"Example User\",\"email\":\"test@example.com\"},{\"name\":\"Example User\",\"email\":\"test@example.com\"}],\"cc\":[{\"name\":\"Example User\",\"email\":\"test@example.com\"},{\"name\":\"Example User\",\"email\":\"test@example.com\"}],\"bcc\":[{\"name\":\"Example User\",\"email\":\"test@example.com\"},{\"name\":\"Example User\",\"email\":\"test@example.com\"}],\"subject\":\"Hello World from the Personalized SendGrid Java Library\",\"headers\":{\"X-Mock\":\"true\",\"X-Test\":\"test\"},\"substitutions\":{\"%city%\":\"Denver\",\"%name%\":\"Example User\"},\"custom_args\":{\"type\":\"marketing\",\"user_id\":\"343\"},\"send_at\":1443636843},{\"to\":[{\"name\":\"Example User\",\"email\":\"test@example.com\"},{\"name\":\"Example User\",\"email\":\"test@example.com\"}],\"cc\":[{\"name\":\"Example User\",\"email\":\"test@example.com\"},{\"name\":\"Example User\",\"email\":\"test@example.com\"}],\"bcc\":[{\"name\":\"Example User\",\"email\":\"test@example.com\"},{\"name\":\"Example User\",\"email\":\"test@example.com\"}],\"subject\":\"Hello World from the Personalized SendGrid Java Library\",\"headers\":{\"X-Mock\":\"true\",\"X-Test\":\"test\"},\"substitutions\":{\"%city%\":\"Denver\",\"%name%\":\"Example User\"},\"custom_args\":{\"type\":\"marketing\",\"user_id\":\"343\"},\"send_at\":1443636843},{\"to\":[{\"name\":\"Example User\",\"email\":\"test@example.com\"},{\"name\":\"Example User\",\"email\":\"test@example.com\"}],\"cc\":[{\"name\":\"Example User\",\"email\":\"test@example.com\"},{\"name\":\"Example User\",\"email\":\"test@example.com\"}],\"bcc\":[{\"name\":\"Example User\",\"email\":\"test@example.com\"},{\"name\":\"Example User\",\"email\":\"test@example.com\"}],\"subject\":\"Hello World from the Personalized SendGrid Java Library\",\"headers\":{\"X-Mock\":\"true\",\"X-Test\":\"test\"},\"custom_args\":{\"type\":\"marketing\",\"user_id\":\"343\"},\"dynamic_template_data\":{\"city\":\"Denver\",\"items\":[{\"price\":\"$ 59.95\",\"text\":\"New Line Sneakers\"},{\"text\":\"Old Line Sneakers\"}],\"name\":\"Example User\"},\"send_at\":1443636843}],\"content\":[{\"type\":\"text/plain\",\"value\":\"some text here\"},{\"type\":\"text/html\",\"value\":\"some text here\"}],\"attachments\":[{\"content\":\"TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIGFkaXBpc2NpbmcgZWxpdC4gQ3JhcyBwdW12\",\"type\":\"application/pdf\",\"filename\":\"balance_001.pdf\",\"disposition\":\"attachment\",\"content_id\":\"Balance Sheet\"},{\"content\":\"BwdW\",\"type\":\"image/png\",\"filename\":\"banner.png\",\"disposition\":\"inline\",\"content_id\":\"Banner\"}],\"template_id\":\"13b8f94f-bcae-4ec6-b752-70d6cb59f932\",\"sections\":{\"%section1%\":\"Substitution Text for Section 1\",\"%section2%\":\"Substitution Text for Section 2\"},\"headers\":{\"X-Test1\":\"1\",\"X-Test2\":\"2\"},\"categories\":[\"May\",\"2016\"],\"custom_args\":{\"campaign\":\"welcome\",\"weekday\":\"morning\"},\"send_at\":1443636842,\"asm\":{\"group_id\":99,\"groups_to_display\":[4,5,6,7,8]},\"ip_pool_name\":\"23\",\"mail_settings\":{\"bcc\":{\"enable\":true,\"email\":\"test@example.com\"},\"bypass_list_management\":{\"enable\":true},\"footer\":{\"enable\":true,\"text\":\"Footer Text\",\"html\":\"Footer Text\"},\"sandbox_mode\":{\"enable\":true},\"spam_check\":{\"enable\":true,\"threshold\":1,\"post_to_url\":\"https://spamcatcher.sendgrid.com\"}},\"tracking_settings\":{\"click_tracking\":{\"enable\":true,\"enable_text\":false},\"open_tracking\":{\"enable\":true,\"substitution_tag\":\"Optional tag to replace with the open image in the body of the message\"},\"subscription_tracking\":{\"enable\":true,\"text\":\"text to insert into the text/plain portion of the message\",\"html\":\"html to insert into the text/html portion of the message\",\"substitution_tag\":\"Optional tag to replace with the open image in the body of the message\"},\"ganalytics\":{\"enable\":true,\"utm_source\":\"some source\",\"utm_term\":\"some term\",\"utm_content\":\"some content\",\"utm_campaign\":\"some name\",\"utm_medium\":\"some medium\"}},\"reply_to\":{\"name\":\"Example User\",\"email\":\"test@example.com\"}}"); + } + + @Test + public void fromShouldReturnCorrectFrom() { + Mail mail = new Mail(); + Email from = new Email(); + mail.setFrom(from); + + Assert.assertSame(from, mail.getFrom()); + } + + @Test + public void mailDeserialization() throws IOException { + Email to = new Email("foo@bar.com"); + Content content = new Content("text/plain", "test"); + Email from = new Email("no-reply@bar.com"); + Mail mail = new Mail(from, "subject", to, content); + + ObjectMapper mapper = new ObjectMapper(); + String json = mapper.writeValueAsString(mail); + Mail deserialized = mapper.readValue(json, Mail.class); + + Assert.assertEquals(deserialized, mail); } -} \ No newline at end of file +} 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..27878162 --- /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.helpers.mail.objects.BccSettings; +import com.sendgrid.helpers.mail.objects.ClickTrackingSetting; +import com.sendgrid.helpers.mail.objects.FooterSetting; +import com.sendgrid.helpers.mail.objects.GoogleAnalyticsSetting; +import com.sendgrid.helpers.mail.objects.OpenTrackingSetting; +import com.sendgrid.helpers.mail.objects.SpamCheckSetting; +import com.sendgrid.helpers.mail.objects.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}"); + } +} diff --git a/test/prism.sh b/test/prism.sh new file mode 100755 index 00000000..d6e0f251 --- /dev/null +++ b/test/prism.sh @@ -0,0 +1,42 @@ +#!/bin/bash + +install () { + +set -eu + +UNAME=$(uname) +ARCH=$(uname -m) +if [ "$UNAME" != "Linux" ] && [ "$UNAME" != "Darwin" ] && [ "$ARCH" != "x86_64" ] && [ "$ARCH" != "i686" ]; then + echo "Sorry, OS/Architecture not supported: ${UNAME}/${ARCH}. Download binary from https://github.com/stoplightio/prism/releases" + exit 1 +fi + +if [ "$UNAME" = "Darwin" ] ; then + OSX_ARCH=$(uname -m) + if [ "${OSX_ARCH}" = "x86_64" ] ; then + PLATFORM="darwin_amd64" + fi +elif [ "$UNAME" = "Linux" ] ; then + LINUX_ARCH=$(uname -m) + if [ "${LINUX_ARCH}" = "i686" ] ; then + PLATFORM="linux_386" + elif [ "${LINUX_ARCH}" = "x86_64" ] ; then + PLATFORM="linux_amd64" + fi +fi + +#LATEST=$(curl -s https://api.github.com/repos/stoplightio/prism/tags | grep -Eo '"name":.*?[^\\]",' | head -n 1 | sed 's/[," ]//g' | cut -d ':' -f 2) +LATEST="v0.1.5" +URL="https://github.com/stoplightio/prism/releases/download/$LATEST/prism_$PLATFORM" +DEST=./prism/bin/prism + +if [ -z $LATEST ] ; then + echo "Error requesting. Download binary from ${URL}" + exit 1 +else + curl -L $URL -o $DEST + chmod +x $DEST +fi +} + +install