summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorElmer Thomas <elmer@thinkingserious.com>2016-06-14 10:16:47 -0700
committerElmer Thomas <elmer@thinkingserious.com>2016-06-14 10:16:47 -0700
commit9fb94f6a068a6bd887fed665fc33efcd301db486 (patch)
treeb12805a79484522f0ff5d75f1c5fa9e02d64208d
parente5835712fe079bff77943c5e480e9a654bc5d17f (diff)
parent8ff2669dd3f53dad6b4808ec9c28d70f166c9b13 (diff)
downloadsendgrid-php-9fb94f6a068a6bd887fed665fc33efcd301db486.zip
sendgrid-php-9fb94f6a068a6bd887fed665fc33efcd301db486.tar.gz
sendgrid-php-9fb94f6a068a6bd887fed665fc33efcd301db486.tar.bz2
Merge branch 'v3release'v5.0.0
-rw-r--r--.github/ISSUE_TEMPLATE17
-rw-r--r--.gitignore4
-rw-r--r--.travis.yml13
-rw-r--r--CHANGELOG.md7
-rw-r--r--CONTRIBUTING.md193
-rw-r--r--LICENSE.txt (renamed from MIT.LICENSE)2
-rw-r--r--README.md1092
-rw-r--r--USAGE.md4654
-rw-r--r--composer.json12
-rw-r--r--example_v2.php26
-rw-r--r--example_v2_template.php33
-rwxr-xr-xexample_v3.php87
-rw-r--r--examples/accesssettings/accesssettings.php78
-rw-r--r--examples/apikeys/apikeys.php84
-rw-r--r--examples/asm/asm.php158
-rw-r--r--examples/browsers/browsers.php18
-rw-r--r--examples/campaigns/campaigns.php156
-rw-r--r--examples/categories/categories.php38
-rw-r--r--examples/clients/clients.php29
-rw-r--r--examples/contactdb/contactdb.php388
-rw-r--r--examples/devices/devices.php18
-rw-r--r--examples/geo/geo.php18
-rw-r--r--examples/helpers/mail/example.php207
-rw-r--r--examples/ips/ips.php156
-rw-r--r--examples/mail/mail.php181
-rw-r--r--examples/mailboxproviders/mailboxproviders.php18
-rw-r--r--examples/mailsettings/mailsettings.php221
-rw-r--r--examples/partnersettings/partnersettings.php41
-rw-r--r--examples/scopes/scopes.php17
-rw-r--r--examples/stats/stats.php18
-rw-r--r--examples/subusers/subusers.php171
-rw-r--r--examples/suppression/suppression.php175
-rw-r--r--examples/templates/templates.php132
-rw-r--r--examples/trackingsettings/trackingsettings.php112
-rw-r--r--examples/user/user.php245
-rw-r--r--examples/whitelabel/whitelabel.php315
-rw-r--r--lib/Client.php145
-rw-r--r--lib/SendGrid.php178
-rw-r--r--lib/SendGrid/Email.php692
-rw-r--r--lib/SendGrid/Exception.php14
-rw-r--r--lib/SendGrid/Response.php40
-rw-r--r--lib/helpers/mail/Mail.php1125
-rw-r--r--lib/helpers/mail/README.md14
-rw-r--r--lib/resources/api_keys.php76
-rw-r--r--lib/resources/asm_groups.php33
-rw-r--r--lib/resources/asm_suppressions.php51
-rw-r--r--lib/resources/global_stats.php40
-rw-r--r--test/unit/SendGrid/EmailTest.php839
-rw-r--r--test/unit/SendGrid/ExceptionTest.php28
-rw-r--r--test/unit/SendGrid/ResponseTest.php34
-rw-r--r--test/unit/SendGridTest.php2251
-rw-r--r--test/unit/bootstrap.php25
-rw-r--r--test/unit/gif.gifbin646258 -> 0 bytes
-rw-r--r--test/unit/helpers/mail/MailTest.php184
-rw-r--r--test/unit/phpunit.xml.dist4
-rw-r--r--test/unit/resources/api_keysTest.php99
-rw-r--r--test/unit/resources/asm_groupsTest.php17
-rw-r--r--test/unit/resources/asm_suppressionsTest.php48
-rw-r--r--test/unit/resources/baseTest.php20
-rw-r--r--test/unit/resources/global_statsTest.php82
-rw-r--r--test/unit/text1
61 files changed, 11487 insertions, 3687 deletions
diff --git a/.github/ISSUE_TEMPLATE b/.github/ISSUE_TEMPLATE
new file mode 100644
index 0000000..8e2d043
--- /dev/null
+++ b/.github/ISSUE_TEMPLATE
@@ -0,0 +1,17 @@
+#### Issue Summary
+
+A summary of the issue and the environment in which it occurs. If suitable, include the steps required to reproduce the bug. Please feel free to include screenshots, screencasts, code examples.
+
+
+#### Steps to Reproduce
+
+1. This is the first step
+2. This is the second step
+3. Further steps, etc.
+
+Any other information you want to share that is relevant to the issue being reported. Especially, why do you consider this to be a bug? What do you expect to happen instead?
+
+#### Technical details:
+
+* sendgrid-php Version: master (latest commit: [commit number])
+* PHP Version: 5.x \ No newline at end of file
diff --git a/.gitignore b/.gitignore
index 134b41b..068e135 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,9 +1,9 @@
test/coverage/*
-examples/*
dist/
composer.lock
vendor
.env*
sendgrid-php.php
composer.phar
-example.php
+.editorconfig
+test.php
diff --git a/.travis.yml b/.travis.yml
index ccf717a..20821d1 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,18 +1,16 @@
language: php
before_script:
- phpenv local 5.4
-- composer install --dev --no-interaction
+- composer install
- phpenv local --unset
- cd test/unit
script:
-- ../../vendor/bin/phpunit . --bootstrap bootstrap.php --filter test* --coverage-clover clover.xml
+- "../../vendor/bin/phpunit . --bootstrap bootstrap.php --filter test*"
after_script:
- cd ..
- phpenv local 5.4
- phpenv local --unset
-- "./scripts/s3upload.sh"
php:
-- 5.3
- 5.4
- 5.5
- 5.6
@@ -23,13 +21,14 @@ env:
- secure: j38xzMNmzYXR/JJdVumPmDoDVxb6FUDF497AuVPHowGh0egFW8XHWCOMeQWqWZI4Gg17pViQNIJ3xC6WBvob70AF8fsNm0+vxF2s7abXDMcbq5flLTS6ydKLgNu+na/RAkOBbTwxJAGIH/fQh8BH8iGKerCwoqf8sDErAge4NMw=
- secure: h3HlxBOsNXBDrIJ0yl467ST6Q8R2TmbL7PltlPcRoHy5gAxn5UiDv5W2+6DSXrwQrTjOUunZ+O9ckcaQGQy1JNhGMwgIkJpyWAHDIHhTYGU289uUIDTHQW/soX0qHJSHSx3iMgDOIc7XnfTz6W7Nv1gYKZFedOMsZ5uBMeGyiXE=
- secure: SKSl/RHFQNhGT7OUj7E0AbrQnuDhhCRI/4jC76mmzvy8EJBDgUNevAKJGtug+LVilHrlbk9fLC8rayPW6SGv0s3PowTGm8NMOc48aRBLOr7QRo/sMikJCmRuU6HWptr0NKuf2fq6lV94WDm/pDdyOSNyLga9/eaIDs/Sacp78sw=
+ - secure: TWensopm9VbcvfIGh4bkzrGIRrnJ/XCRqCGq95HU9LDBtlXOeV6yJ+cmbr/FsaZ6QIBFuvsnYZeDUhJYuVLF0WWVfNHLCrAn9ai9/yc7qkkszCpGfsMq7tqTsl8MRF8wc0JpNwEafW2gQvkwSunqhciqxx9B73z3cd4I7JCkTjs=
notifications:
hipchat:
rooms:
secure: l4RUOBY44kVhSxx54NU3cmvn598rRMB7Y272Ct/W0fBm1tdGncp42A/rwg7JkiZH9EWXs3tKtoSjqw5xT6QeScUGQDdykS5QVO8lEIkDRGD4WwQ3VDJmRy1+04WtgqFEK8SyYTCcCl4ZJ0rtOcJZgDMvigkOJuLxwGXTDuvfu1k=
template:
- - '<a href="https://travis-ci.org/%{repository}/builds/%{build_id}">%{repository}
- Build %{build_number}</a> on branch <i>%{branch}</i> by %{author}: <strong>%{message}</strong>
- <a href="https://github.com/%{repository}/commits/%{commit}">View on GitHub</a>'
+ - '<a href="https://travis-ci.org/%{repository}/builds/%{build_id}">%{repository}
+ Build %{build_number}</a> on branch <i>%{branch}</i> by %{author}: <strong>%{message}</strong>
+ <a href="https://github.com/%{repository}/commits/%{commit}">View on GitHub</a>'
format: html
notify: true
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 695037e..9c82bc7 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,7 +1,14 @@
# Change Log
All notable changes to this project will be documented in this file.
+
This project adheres to [Semantic Versioning](http://semver.org/).
+## [5.0.0] - 2016-06-13 ##
+### Added
+- Breaking change to support the v3 Web API
+- New HTTP client
+- v3 Mail Send helper
+
## [v4.0.4] - (2016-02-18) ##
### Added
- Ability to add scopes to API Keys endpoint [POST]
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
new file mode 100644
index 0000000..07c5b38
--- /dev/null
+++ b/CONTRIBUTING.md
@@ -0,0 +1,193 @@
+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)
+- [Testing](#testing)
+- [Style Guidelines & Naming Conventions](#style_guidelines_and_naming_conventions)
+- [Creating a Pull Request](#creating_a_pull_request)
+
+<a name="roadmap"></a>
+We use [Milestones](https://github.com/sendgrid/sendgrid-php/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.
+
+<a name="cla"></a>
+## 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.
+
+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.
+
+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).
+
+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.
+
+There are a few ways to contribute, which we'll enumerate below:
+
+<a name="feature_request"></a>
+## Feature Request
+
+If you'd like to make a feature request, please read this section.
+
+The GitHub issue tracker is the preferred channel for library feature requests, but please respect the following restrictions:
+
+- 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
+
+<a name="submit_a_bug_report"></a>
+## Submit a Bug Report
+
+Note: DO NOT include your credentials in ANY code examples, descriptions, or media you make public.
+
+A software bug is a demonstrable issue in the code base. In order for us to diagnose the issue and respond as quickly as possible, please add as much detail as possible into your bug report.
+
+Before you decide to create a new issue, please try the following:
+
+1. Check the Github issues tab if the identified issue has already been reported, if so, please add a +1 to the existing post.
+2. Update to the latest version of this code and check if issue has already been fixed
+3. Copy and fill in the Bug Report Template we have provided below
+
+### 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-php/.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.
+
+<a name="improvements_to_the_codebase"></a>
+## Improvements to the Codebase
+
+We welcome direct contributions to the sendgrid-php code base. Thank you!
+
+### Development Environment ###
+
+#### Install and Run Locally ####
+
+##### Prerequisites #####
+
+- PHP 5.4 or greater
+- [php-http-client](https://github.com/sendgrid/php-http-client)
+
+##### Initial setup: #####
+
+```bash
+git clone https://github.com/sendgrid/sendgrid-php.git
+cd sendgrid-php
+composer install
+```
+
+## Environment Variables
+
+First, get your free SendGrid account [here](https://sendgrid.com/free?source=sendgrid-php).
+
+Next, update your environment with your [SENDGRID_API_KEY](https://app.sendgrid.com/settings/api_keys).
+
+```bash
+echo "export SENDGRID_API_KEY='YOUR_API_KEY'" > sendgrid.env
+echo "sendgrid.env" >> .gitignore
+source ./sendgrid.env
+```
+
+##### Execute: #####
+
+See the [examples folder](https://github.com/sendgrid/sendgrid-php/tree/master/examples) to get started quickly.
+
+If you are using composer, replace <PATH_TO> with the path to your `vendor/autoload.php`. Otherwise, include lib/SendGrid.php and lib/helpers/mail/Mail.php.
+
+<a name="understanding_the_codebase"></a>
+## Understanding the Code Base
+
+**/examples**
+
+Working examples that demonstrate usage.
+
+```bash
+php examples/example.php
+```
+
+**/test/unit**
+
+Unit tests for the HTTP client.
+
+**/lib**
+
+The interface to the SendGrid API.
+
+<a name="testing"></a>
+## Testing
+
+All PRs require passing tests before the PR will be reviewed.
+
+All test files are in the [`/test/unit`](https://github.com/sendgrid/sendgrid-php/tree/master/test/unit) directory.
+
+For the purposes of contributing to this repo, please update the [`SendGridTest.php`](https://github.com/sendgrid/sendgrid-php/tree/master/test/unit/SendGridTest.php) file with unit tests as you modify the code.
+
+```bash
+cd test/unit
+../../vendor/bin/phpunit . --bootstrap bootstrap.php --filter test*
+```
+
+<a name="style_guidelines_and_naming_conventions"></a>
+## 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.
+
+- [pear coding standards](https://pear.php.net/manual/en/standards.php)
+
+Please run your code through:
+
+- [PHP Code Sniffer](https://github.com/squizlabs/PHP_CodeSniffer)
+
+## Creating a Pull Request<a name="creating_a_pull_request"></a>
+
+1. [Fork](https://help.github.com/fork-a-repo/) the project, clone your fork,
+ and configure the remotes:
+
+ ```bash
+ # Clone your fork of the repo into the current directory
+ git clone https://github.com/sendgrid/sendgrid-php
+ # Navigate to the newly cloned directory
+ cd sendgrid-python
+ # Assign the original repo to a remote called "upstream"
+ git remote add upstream https://github.com/sendgrid/sendgrid-php
+ ```
+
+2. If you cloned a while ago, get the latest changes from upstream:
+
+ ```bash
+ git checkout <dev-branch>
+ git pull upstream <dev-branch>
+ ```
+
+3. Create a new topic branch (off the main project development branch) to
+ contain your feature, change, or fix:
+
+ ```bash
+ git checkout -b <topic-branch-name>
+ ```
+
+4. Commit your changes in logical chunks. Please adhere to these [git commit
+ message guidelines](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html)
+ or your code is unlikely be merged into the main project. Use Git's
+ [interactive rebase](https://help.github.com/articles/interactive-rebase)
+ feature to tidy up your commits before making them public.
+
+4a. Create tests.
+
+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:
+
+ ```bash
+ git pull [--rebase] upstream master
+ ```
+
+6. Push your topic branch up to your fork:
+
+ ```bash
+ git push origin <topic-branch-name>
+ ```
+
+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.
+
+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
diff --git a/MIT.LICENSE b/LICENSE.txt
index a5e93d2..7f9d537 100644
--- a/MIT.LICENSE
+++ b/LICENSE.txt
@@ -1,6 +1,6 @@
The MIT License (MIT)
-Copyright (c) 2016 SendGrid
+Copyright (c) 2012-2016 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 92f62ca..d54ad59 100644
--- a/README.md
+++ b/README.md
@@ -1,79 +1,49 @@
-# Special Announcement
-
-We have released a [v3 beta branch](https://github.com/sendgrid/sendgrid-php/tree/v3beta) for this library that supports our new v3 Mail Send endpoint which is in open beta. The v3/mail/send/beta endpoint is not a production endpoint, so you should not integrate with it for your production email sending. However, when we make this an officially released feature it will be available at v3/mail//send.
-
-Please try it out and let us know what you think about the endpoint and the library in the [issues area of this repo](https://github.com/sendgrid/sendgrid-php/issues), all of your feedback will be taken into account to influence the endpoint and this library.
-
-Beginning with v3/mail/send/beta, the new version of our library will only support v3 endpoints.. Once this endpoint is out of beta, we will update the endpoint, removing the “/beta” from the URI. At this point, the v3 beta branch will be merged to master and will be our official library going forward. This means that we will no longer formally support the v2 mail.send.json endpoint in any of our libraries.
-
-So long as you are not automatically pulling new versions of the library into your production code base, your integration will not break regardless of which endpoint you’re using. By the way, don't pull new versions into your production code base, because breaking changes break things.
-
-The /api/mail.send.json endpoint, known as v2 mail send, is NOT going away. It will continue to work as it always has, happily sending your emails along as if nothing happened.
-
-# SendGrid-PHP
-
-This library allows you to quickly and easily send emails through SendGrid using PHP.
+[![BuildStatus](https://travis-ci.org/sendgrid/sendgrid-php.svg?branch=master)](https://travis-ci.org/sendgrid/sendgrid-php)
-WARNING: This module was recently upgraded from [2.2.x](https://github.com/sendgrid/sendgrid-php/tree/v2.2.1) to 3.X. There were API breaking changes for various method names. See [usage](https://github.com/sendgrid/sendgrid-php#usage) for up to date method names.
+**This library allows you to quickly and easily use the SendGrid Web API via PHP.**
-## PLEASE READ THIS
+# Announcements
-**TLDR: If you upgrade and don't change your code appropriately, things *WILL* break.**
+**BREAKING CHANGE as of 2016.06.14**
-One of the most notable changes is how `addTo()` behaves. We are now using our Web API parameters instead of the X-SMTPAPI header. What this means is that if you call `addTo()` multiple times for an email, **ONE** email will be sent with each email address visible to everyone. To utilize the original behavior of having an individual personalized email sent to each recipient you must now use `addSmtpapiTo()`. **This will break substitutions if there is more than one To address added unless you update to use `addSmtpapiTo()`.**
+Version `5.0.0` is a breaking change for the entire library.
-Smtpapi addressing methods cannot be mixed with non Smtpapi addressing methods. Meaning you cannot currently use Cc and Bcc with `addSmtpapiTo()`.
+Version 5.0.0 brings you full support for all Web API v3 endpoints. We
+have the following resources to get you started quickly:
-The `send()` method now raises a `\SendGrid\Exception` by default if the response code is not 200 and returns an instance of `\SendGrid\Response`.
+- [SendGrid
+ Documentation](https://sendgrid.com/docs/API_Reference/Web_API_v3/index.html)
+- [Usage
+ Documentation](https://github.com/sendgrid/sendgrid-php/tree/master/USAGE.md)
+- [Example
+ Code](https://github.com/sendgrid/sendgrid-php/tree/master/examples)
----
+Thank you for your continued support!
-Important: This library requires PHP 5.3 or higher.
+All updates to this library is documented in our [CHANGELOG](https://github.com/sendgrid/sendgrid-php/blob/master/CHANGELOG.md).
-[![BuildStatus](https://travis-ci.org/sendgrid/sendgrid-php.svg?branch=master)](https://travis-ci.org/sendgrid/sendgrid-php)
-[![Latest Stable Version](https://poser.pugx.org/sendgrid/sendgrid/version.svg)](https://packagist.org/packages/sendgrid/sendgrid)
+# Installation
-```php
-$sendgrid = new SendGrid('YOUR_SENDGRID_APIKEY');
-$email = new SendGrid\Email();
-$email
- ->addTo('foo@bar.com')
- ->setFrom('me@bar.com')
- ->setSubject('Subject goes here')
- ->setText('Hello World!')
- ->setHtml('<strong>Hello World!</strong>')
-;
+## Setup Environment Variables
-$sendgrid->send($email);
+First, get your free SendGrid account [here](https://sendgrid.com/free?source=sendgrid-php).
-// Or catch the error
+Next, update your environment with your [SENDGRID_API_KEY](https://app.sendgrid.com/settings/api_keys).
-try {
- $sendgrid->send($email);
-} catch(\SendGrid\Exception $e) {
- echo $e->getCode();
- foreach($e->getErrors() as $er) {
- echo $er;
- }
-}
+```bash
+echo "export SENDGRID_API_KEY='YOUR_API_KEY'" > sendgrid.env
+echo "sendgrid.env" >> .gitignore
+source ./sendgrid.env
```
-## Announcements ##
+## Install Package
-For users of our [Web API v3 endpoints](https://sendgrid.com/docs/API_Reference/Web_API_v3/API_Keys/index.html), we have begun integrating v3 endpoints into this library. We are also updating and enhancing the core library code.
-
-In no particular order, we have implemented a [few of the v3](#webapiv3) endpoints already and would appreciate your feedback.
-
-Thank you for your continued support!
-
-## Installation ##
-
-Add SendGrid to your `composer.json` file. If you are not using [Composer](http://getcomposer.org), you should be. It's an excellent way to manage dependencies in your PHP application.
+Add SendGrid to your `composer.json` file. If you are not using [Composer](http://getcomposer.org), you should be. It's an excellent way to manage dependencies in your PHP application.
```json
-{
+{
"require": {
- "sendgrid/sendgrid": "~4.0"
+ "sendgrid/sendgrid": "~5.0"
}
}
```
@@ -84,9 +54,9 @@ Then at the top of your PHP script require the autoloader:
require 'vendor/autoload.php';
```
-#### Alternative: Install from zip
+#### Alternative: Install package from zip
-If you are not using Composer, simply download and install the **[latest packaged release of the library as a zip](https://sendgrid-open-source.s3.amazonaws.com/sendgrid-php/sendgrid-php.zip)**.
+If you are not using Composer, simply download and install the **[latest packaged release of the library as a zip](https://sendgrid-open-source.s3.amazonaws.com/sendgrid-php/sendgrid-php.zip)**.
[**⬇︎ Download Packaged Library ⬇︎**](https://sendgrid-open-source.s3.amazonaws.com/sendgrid-php/sendgrid-php.zip)
@@ -98,993 +68,79 @@ require("path/to/sendgrid-php/sendgrid-php.php");
Previous versions of the library can be found in the [version index](https://sendgrid-open-source.s3.amazonaws.com/index.html).
-## Example App
-
-There is a [sendgrid-php-example app](https://github.com/sendgrid/sendgrid-php-example) to help jumpstart your development.
-
-## Usage
-
-To begin using this library, initialize the SendGrid object with your SendGrid [API Key](https://sendgrid.com/docs/Classroom/Send/api_keys.html). To configure API keys, visit https://app.sendgrid.com/settings/api_keys.
-
-```php
-$sendgrid = new SendGrid('YOUR_SENDGRID_APIKEY');
-```
-
-Create a new SendGrid Email object and add your message details.
-
-```php
-$email = new SendGrid\Email();
-$email
- ->addTo('foo@bar.com')
- //->addTo('bar@foo.com') //One of the most notable changes is how `addTo()` behaves. We are now using our Web API parameters instead of the X-SMTPAPI header. What this means is that if you call `addTo()` multiple times for an email, **ONE** email will be sent with each email address visible to everyone.
- ->setFrom('me@bar.com')
- ->setSubject('Subject goes here')
- ->setText('Hello World!')
- ->setHtml('<strong>Hello World!</strong>')
-;
-```
-
-Send it.
-
-```php
-$sendgrid->send($email);
-```
-
-NOTE: The total message size is limited to 20,480,000 bytes, or approximately 19.5MB. This includes all the headers, body, and attachments. [Reference](https://sendgrid.com/docs/Classroom/Build/attachments.html)
-
-### Exceptions
-
-A `SendGrid\Exception` is raised by default if the response is not 200 OK.
-
-To disable exceptions, pass in the `raise_exceptions => false` option when creating a `SendGrid\Client`.
-
-```php
-$client = new SendGrid('YOUR_SENDGRID_APIKEY', array('raise_exceptions' => false));
-```
-
-### Options
-Options may be passed to the library when initializing the SendGrid object:
-
-```php
-$options = array(
- 'turn_off_ssl_verification' => false,
- 'protocol' => 'https',
- 'host' => 'api.sendgrid.com',
- 'endpoint' => '/api/mail.send.json',
- 'port' => null,
- 'url' => null,
- 'raise_exceptions' => false
-);
-$sendgrid = new SendGrid('YOUR_SENDGRID_APIKEY', $options);
-```
-
-#### Changing URL
-You may change the URL sendgrid-php uses to send email by supplying various parameters to `options`, all parameters are optional:
-
-```php
-$sendgrid = new SendGrid(
- 'YOUR_SENDGRID_APIKEY',
- array(
- 'protocol' => 'http',
- 'host' => 'sendgrid.org',
- 'endpoint' => '/send',
- 'port' => '80'
- )
-);
-```
-
-A full URL may also be provided:
-
-```php
-$sendgrid = new SendGrid(
- 'YOUR_SENDGRID_APIKEY',
- array( 'url' => 'http://sendgrid.org:80/send')
-);
-```
-
-#### Ignoring SSL certificate verification
-
-You can optionally ignore verification of SSL certificate when using the Web API.
-
-```php
-$sendgrid = new SendGrid(
- 'YOUR_SENDGRID_APIKEY',
- array("turn_off_ssl_verification" => true)
-);
-```
-
-#### Response ####
-
-An instance of `\SendGrid\Response` is returned from the `send()` method.
-
-```php
-$email = new SendGrid\Email();
-$email
- ->addTo('foo@bar.com')
- ->setFrom('me@bar.com')
- ->setSubject('Subject goes here')
- ->setText('Hello World!');
-$res = $sendgrid->send($email);
-
-var_dump($res);
-
-// Output
-object(SendGrid\Response)#31 (4) {
- ["code"]=>
- int(200)
- ["headers"]=>
- object(Guzzle\Http\Message\Header\HeaderCollection)#48 (1) {
- ["headers":protected]=>
- array(6) {
- ...
- ["content-type"]=>
- object(Guzzle\Http\Message\Header)#41 (3) {
- ["values":protected]=>
- array(1) {
- [0]=>
- string(16) "application/json"
- }
- ["header":protected]=>
- string(12) "Content-Type"
- ["glue":protected]=>
- string(1) ","
- }
- ...
- }
- }
- ["raw_body"]=>
- string(21) "{"message":"success"}"
- ["body"]=>
- array(1) {
- ["message"]=>
- string(7) "success"
- }
-}
-```
-
-#### getCode ####
-
-Returns the status code of the response.
-
-```php
-$res = $sendgrid->send($email);
-echo $res->getCode()
-```
-
-#### getHeaders ####
-
-Returns the headers of the response as a [Guzzle\Http\Message\Header\HeaderCollection object](https://docs.aws.amazon.com/aws-sdk-php/v2/api/class-Guzzle.Http.Message.Header.HeaderCollection.html).
-
-```php
-$res = $sendgrid->send($email);
-$guzzle = $res->getHeaders();
-echo var_dump($guzzle);
-```
-
-#### getRawBody ####
-
-Returns the unparsed JSON response from SendGrid.
-
-```php
-$res = $sendgrid->send($email);
-echo $res->getRawBody()
-```
-
-#### getBody ####
-
-Returns the parsed JSON from SendGrid.
-
-```php
-$res = $sendgrid->send($email);
-echo var_dump($res->getBody());
-```
-
-### Exception ###
-
-A `\SendGrid\Exception` is raised if the response code is not 200. Catching it is optional but highly recommended.
-
-```php
-try {
- $sendgrid->send($email);
-} catch(\SendGrid\Exception $e) {
- echo $e->getCode() . "\n";
- foreach($e->getErrors() as $er) {
- echo $er;
- }
-}
-
-// Output
-400
-Permission denied, wrong credentials
-```
+## Dependencies
-### <a name="webapiv3"></a>WEB API v3 ###
+- The SendGrid Service, starting at the [free level](https://sendgrid.com/free?source=sendgrid-php)
+- [php-HTTP-Client](https://github.com/sendgrid/php-http-client)
-[APIKeys](https://sendgrid.com/docs/API_Reference/Web_API_v3/API_Keys/index.html)
+# Quick Start
-List all API Keys belonging to the authenticated user. [GET]
+## Hello Email
```php
+// If you are using Composer
require 'vendor/autoload.php';
-Dotenv::load(__DIR__);
-$sendgrid_apikey = getenv('SG_KEY');
-$sendgrid = new Client($sendgrid_apikey);
-$response = $sendgrid->api_keys->get();
-print("Status Code: " . $response->getStatusCode() . "\n");
-print("Body: " . $response->getBody() . "\n");
-```
-
-Generate a new API Key for the authenticated user. [POST]
-
-```php
-Dotenv::load(__DIR__);
-$sendgrid_apikey = getenv('SG_KEY');
-$sendgrid = new Client($sendgrid_apikey);
-$api_key = "My API Key";
-$scopes = array("mail.send", "alerts.create", "alerts.read"); // optional
-$response = $sendgrid->api_keys->post($api_key, $scopes);
-print("Status Code: " . $response->getStatusCode() . "\n");
-print("Body: " . $response->getBody() . "\n");
-```
-
-Update the name of an existing API Key [PATCH]
-```php
-require 'vendor/autoload.php';
-Dotenv::load(__DIR__);
-$sendgrid_apikey = getenv('SG_KEY');
-$sendgrid = new Client($sendgrid_apikey);
-$api_key_id = "Q5xdErWiSO6b8fYUgtYY8g";
-$response = $sendgrid->api_keys->patch($api_key_id, "Updated API Key Name");
-print("Status Code: " . $response->getStatusCode() . "\n");
-print("Body: " . $response->getBody() . "\n");
-```
+$from = new Email(null, "test@example.com");
+$subject = "Hello World from the SendGrid PHP Library";
+$to = new Email(null, "test@example.com");
+$content = new Content("text/plain", "some text here");
+$mail = new Mail($from, $subject, $to, $content);
-Update the name & scopes of an API Key [PUT]
+$apiKey = getenv('SENDGRID_API_KEY');
+$sg = new \SendGrid($apiKey);
-```php
-require 'vendor/autoload.php';
-Dotenv::load(__DIR__);
-$sendgrid_apikey = getenv('SG_KEY');
-$sendgrid = new Client($sendgrid_apikey);
-$api_key_id = "Q5xdErWiSO6b8fYUgtYY8g";
-$name = "Updated API Key Name";
-$scopes = array("user.profile.read", "user.profile.update");
-$response = $sendgrid->api_keys->put($api_key_id, $name, $scopes);
-print("Status Code: " . $response->getStatusCode() . "\n");
-print("Body: " . $response->getBody() . "\n");
+$response = $sg->client->mail()->send()->post($mail);
+echo $response->statusCode();
+echo $response->headers();
+echo $response->body();
```
-Revoke an existing API Key [DELETE]
-
-```php
-require 'vendor/autoload.php';
-Dotenv::load(__DIR__);
-$sendgrid_apikey = getenv('SG_KEY');
-$sendgrid = new Client($sendgrid_apikey);
-$api_key_id = "Q5xdErWiSO6b8fYUgtYY8g";
-$response = $sendgrid->api_keys->delete($api_key_id);
-print("Status Code: " . $response->getStatusCode() . "\n");
-print("Body: " . $response->getBody() . "\n");
-```
-
-[ASMGroups](https://sendgrid.com/docs/API_Reference/Web_API_v3/Suppression_Management/groups.html)
-
-Retrieve all suppression groups associated with the user.
-
-```php
-require 'vendor/autoload.php';
-Dotenv::load(__DIR__);
-$sendgrid_apikey = getenv('SG_KEY');
-$sendgrid = new Client($sendgrid_apikey);
-$response = $sendgrid->asm_groups->get();
-print("Status Code: " . $response->getStatusCode() . "\n");
-print("Body: " . $response->getBody() . "\n");
-```
-
-[ASMSuppressions](https://sendgrid.com/docs/API_Reference/Web_API_v3/Suppression_Management/suppressions.html)
-
-Get suppressed addresses for a given group.
+## General v3 Web API Usage
```php
+// If you are using Composer
require 'vendor/autoload.php';
-Dotenv::load(__DIR__);
-$sendgrid_apikey = getenv('SG_KEY');
-$sendgrid = new Client($sendgrid_apikey);
-$group_id = 70;
-$response = $sendgrid->asm_suppressions->get($group_id);
-print("Status Code: " . $response->getStatusCode() . "\n");
-print("Body: " . $response->getBody() . "\n");
-```
-
-Add recipient addresses to the suppressions list for a given group.
-
-```php
-$group_id = 70;
-$email = 'elmer.thomas+test1@gmail.com';
-$response = $sendgrid->asm_suppressions->post($group_id, $email);
-print("Status Code: " . $response->getStatusCode() . "\n");
-print("Body: " . $response->getBody() . "\n");
-
-$email = array('elmer.thomas+test5@gmail.com', 'elmer.thomas+test6@gmail.com');
-$response = $sendgrid->asm_suppressions->post($group_id, $email);
-print("Status Code: " . $response->getStatusCode() . "\n");
-print("Body: " . $response->getBody() . "\n");
-```
-
-Delete a recipient email from the suppressions list for a group.
-
-```php
-$group_id = 70;
-$email = 'elmer.thomas+test1@gmail.com';
-$response = $sendgrid->asm_suppressions->delete($group_id, $email);
-print("Status Code: " . $response->getStatusCode() . "\n");
-print("Body: " . $response->getBody() . "\n");
-```
-
-### SMTPAPI ###
-
-This library makes use of [sendgrid/smtpapi-php](https://github.com/sendgrid/smtpapi-php/) for all things related to the [X-SMTPAPI Header](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html).
-
----
-
-### Library Methods ###
-
-#### addTo
-
-You can add one or multiple TO addresses using `addTo` along with an optional TO name. Note: If using TO names, each address needs a name.
-
-```php
-$email = new SendGrid\Email();
-$email
- ->addTo('foo@bar.com')
- ->addTo('another@another.com')
-;
-$sendgrid->send($email);
-
-// With names
-$email = new SendGrid\Email();
-$email
- ->addTo('foo@bar.com', 'Frank Foo')
- ->addTo('another@another.com', 'Joe Bar')
-;
-$sendgrid->send($email);
-
-// As an array
-$email = new SendGrid\Email();
-$email
- ->addTo(array('foo@bar.com', 'bar@example'), array('Frank Foo', 'Brian Bar'))
-;
-$sendgrid->send($email);
-```
-
-#### addSmtpapiTo
-Add a TO address to the smtpapi header along with an optional name.
+$apiKey = getenv('SENDGRID_API_KEY');
+$sg = new \SendGrid($apiKey);
-```php
-$email = new SendGrid\Email();
-$email
- ->addSmtpapiTo('foo@bar.com')
- ->addSmtpapiTo('another@another.com', 'Mike Bar')
-;
-$sendgrid->send($email);
-```
-
-#### setTos
+$response = $sg->client->api_keys()->get();
-If you prefer, you can add multiple TO addresses as an array using the `setTos` method. This will unset any previous `addTo`s you appended.
-
-```php
-$email = new SendGrid\Email();
-$emails = array("foo@bar.com", "another@another.com", "other@other.com");
-$email->setTos($emails);
-$sendgrid->send($email);
+print $response->statusCode();
+print $response->headers();
+print $response->body();
```
-#### setSmtpapiTos
+# Usage
-```php
-$email = new SendGrid\Email();
-$emails = array("foo@bar.com", "Brian Bar <bar@example.com>", "other@example.com");
-$email->setSmtpapiTos($emails);
-$sendgrid->send($email);
-```
+- [SendGrid Docs](https://sendgrid.com/docs/API_Reference/index.html)
+- [Usage
+ Documentation](https://github.com/sendgrid/sendgrid-php/tree/master/USAGE.md)
+- [Example Code](https://github.com/sendgrid/sendgrid-php/tree/master/examples)
+- [v3 Web API Mail Send Helper](https://github.com/sendgrid/sendgrid-php/tree/master/lib/helpers/mail/README.md) - build a request object payload for a v3 /mail/send API call.
-#### setFrom
+## Roadmap
-```php
-$email = new SendGrid\Email();
-$email->setFrom('foo@bar.com');
-$sendgrid->send($email);
-```
+If you are intersted in the future direction of this project, please take a look at our [milestones](https://github.com/sendgrid/sendgrid-php/milestones). We would love to hear your feedback.
-#### setFromName
+## How to Contribute
-```php
-$email = new SendGrid\Email();
-$email
- ->setFrom('foo@bar.com')
- ->setFromName('Foo Bar')
-;
-$sendgrid->send($email);
-```
+We encourage contribution to our libraries, please see our [CONTRIBUTING](https://github.com/sendgrid/sendgrid-php/blob/master/CONTRIBUTING.md) guide for details.
-#### setReplyTo
+Quick links:
-```php
-$email = new SendGrid\Email();
-$email
- ->addTo('foo@bar.com')
- ->setReplyTo('someone.else@example.com')
- ->setFromName('John Doe')
- ...
-;
-```
-
-### Cc
-
-#### addCc
+- [Feature Request](https://github.com/sendgrid/sendgrid-php/blob/master/CONTRIBUTING.md#feature_request)
+- [Bug Reports](https://github.com/sendgrid/sendgrid-php/blob/master/CONTRIBUTING.md#submit_a_bug_report)
+- [Sign the CLA to Create a Pull Request](https://github.com/sendgrid/sendgrid-php/blob/master/CONTRIBUTING.md#cla)
+- [Improvements to the Codebase](https://github.com/sendgrid/sendgrid-php/blob/master/CONTRIBUTING.md#improvements_to_the_codebase)
-```php
-$email = new SendGrid\Email();
-$email->addCc('foo@bar.com');
-$sendgrid->send($email);
-```
+# About
-#### setCc
+sendgrid-php is guided and supported by the SendGrid [Developer Experience Team](mailto:dx@sendgrid.com).
-```php
-$email = new SendGrid\Email();
-$email->setCc('foo@bar.com');
-$sendgrid->send($email);
-```
-
-#### setCcs
-
-```php
-$email = new SendGrid\Email();
-$emails = array("foo@bar.com", "another@another.com", "other@other.com");
-$email->setCcs($emails);
-$sendgrid->send($email);
-```
-
-#### removeCc
-
-```php
-$email->removeCc('foo@bar.com');
-```
-
-### Bcc
-
-Use multiple `addSmtpapiTo`s as a superior alternative to `setBcc`.
-
-```php
-$email = new SendGrid\Email();
-$email
- ->addSmtpapiTo('foo@bar.com')
- ->addSmtpapiTo('someotheraddress@bar.com')
- ->addSmtpapiTo('another@another.com')
- ...
-;
-```
-
-But if you do still have a need for Bcc you can do the following:
-
-#### addBcc
-
-```php
-$email = new SendGrid\Email();
-$email->addTo('bar@example.com');
-$email->addBcc('foo@bar.com');
-$sendgrid->send($email);
-```
-
-#### setBcc
-
-```php
-$email = new SendGrid\Email();
-$email->setBcc('foo@bar.com');
-$sendgrid->send($email);
-```
-
-#### setBccs
-
-```php
-$email = new SendGrid\Email();
-$emails = array("foo@bar.com", "another@another.com", "other@other.com");
-$email->setBccs($emails);
-$sendgrid->send($email);
-```
+sendgrid-php is maintained and funded by SendGrid, Inc. The names and logos for sendgrid-php are trademarks of SendGrid, Inc.
-#### removeBcc
+![SendGrid Logo]
+(https://uiux.s3.amazonaws.com/2016-logos/email-logo%402x.png)
-```php
-$email->removeBcc('foo@bar.com');
-```
-
-**Important Gotcha**: Using multiple `addSmtpapiTo`s is recommended over bcc whenever possible. Each user will receive their own personalized email with that setup, and only see their own email.
-
-Standard `setBcc` will hide who the email is addressed to. If you use multiple `addSmtpapiTo`'s, each user will receive a personalized email showing *only* their email. This is more friendly and more personal.
-
-#### setSubject
-
-```php
-$email = new SendGrid\Email();
-$email->setSubject('This is a subject');
-$sendgrid->send($email);
-```
-
-#### setText
-
-```php
-$email = new SendGrid\Email();
-$email->setText('This is some text');
-$sendgrid->send($email);
-```
-
-#### setHtml
-
-```php
-$email = new SendGrid\Email();
-$email->setHtml('<h1>This is an html email</h1>');
-$sendgrid->send($email);
-```
-
-#### setDate
-
-```php
-$email = new SendGrid\Email();
-$email->setDate('Wed, 17 Dec 2014 19:21:16 +0000');
-$sendgrid->send($email);
-```
-
-#### setSendAt
-
-```php
-$email = new SendGrid\Email();
-$email->setSendAt(1409348513);
-$sendgrid->send($email);
-```
-
-#### setSendEachAt
-
-```php
-$email = new SendGrid\Email();
-$email->setSendEachAt(array(1409348513, 1409348514, 1409348515));
-$sendgrid->send($email);
-```
-
-#### addSendEachAt
-
-```php
-$email = new SendGrid\Email();
-$email
- ->addSendEachAt(1409348513)
- ->addSendEachAt(1409348514)
- ->addSendEachAt(1409348515)
-;
-$sendgrid->send($email);
-```
-
-### Categories ###
-
-Categories are used to group email statistics provided by SendGrid.
-
-To use a category, simply set the category name. Note: there is a maximum of 10 categories per email.
-
-#### addCategory
-
-```php
-$email = new SendGrid\Email();
-$email
- ->addTo('foo@bar.com')
- ...
- ->addCategory("Category 1")
- ->addCategory("Category 2")
-;
-```
-
-#### setCategory
-
-```php
-$email = new SendGrid\Email();
-$email
- ->addTo('foo@bar.com')
- ...
- ->setCategory("Category 1")
-;
-```
-
-#### setCategories
-
-```php
-$email = new SendGrid\Email();
-$categories = array("Category 1", "Category 2", "Category 3");
-$email->setCategories($categories);
-```
-
-#### removeCategory
-
-```php
-$email = new SendGrid\Email();
-$email
- ->addTo('foo@bar.com')
- ...
- ->removeCategory("Category 1")
-;
-```
-
-### Attachments ###
-
-Attachments are currently file based only, with future plans for an in memory implementation as well.
-
-File attachments are limited to 7 MB per file.
-
-#### addAttachment
-
-```php
-$email = new SendGrid\Email();
-$email
- ->addTo('foo@bar.com')
- ...
- ->addAttachment("../path/to/file.txt")
-;
-```
-
-#### setAttachment
-
-```php
-$email = new SendGrid\Email();
-$email
- ->addTo('foo@bar.com')
- ...
- ->setAttachment("../path/to/file.txt")
-;
-```
-
-#### setAttachments
-
-```php
-$email = new SendGrid\Email();
-$attachments = array("../path/to/file1.txt", "../path/to/file2.txt");
-$email
- ->addTo('foo@bar.com')
- ...
- ->setAttachments($attachments)
-;
-```
-
-#### removeAttachment
-
-```php
-$email = new SendGrid\Email();
-$email
- ->addTo('foo@bar.com')
- ...
- ->addAttachment("../path/to/file.txt")
- ->removeAttachment("../path/to/file.txt")
-;
-```
-
-You can tag files for use as inline HTML content. It will mark the file for inline disposition using the specified "cid".
-
-```php
-$email = new SendGrid\Email();
-$email
- ->addTo('foo@bar.com')
- ->setHtml('<div>Our logo:<img src="cid:file-cid"></div>')
- ->addAttachment("../path/to/file.png", "super_file.png", "file-cid")
-;
-```
-
-### Substitutions ###
-
-Substitutions can be used to customize multi-recipient emails, and tailor them for the user.
-
-Unless you are only sending to one recipient, please make sure to use `addSmtpapiTo()`.
-
-#### addSubstitution
-
-```php
-$email = new SendGrid\Email();
-$email
- ->addSmtpapiTo('john@somewhere.com')
- ->addSmtpapiTo('harry@somewhere.com')
- ->addSmtpapiTo('Bob@somewhere.com')
- ...
- ->setHtml("Hey %name%, we've seen that you've been gone for a while")
- ->addSubstitution('%name%', array('John', 'Harry', 'Bob'))
-;
-```
-
-Substitutions can also be used to customize multi-recipient subjects.
-
-```php
-$email = new SendGrid\Email();
-$email
- ->addSmtpapiTo(array('john@somewhere.com', 'harry@somewhere.com', 'bob@somewhere.com'))
- ->setSubject('%subject%')
- ->addSubstitution(
- '%subject%',
- array('Subject to John', 'Subject to Harry', 'Subject to Bob')
- )
- ...
-;
-```
-
-#### setSubstitutions
-
-```php
-$email = new SendGrid\Email();
-$email
- ->addSmtpapiTo(array('john@somewhere.com', 'harry@somewhere.com', 'bob@somewhere.com'))
- ->setSubject('%subject%')
- ->setSubstitutions(array(
- '%name%' => array('John', 'Harry', 'Bob'),
- '%subject%' => array('Subject to John', 'Subject to Harry', 'Subject to Bob')
- ))
- ...
-;
-```
-
-### Sections ###
-
-Sections can be used to further customize messages for the end users. A section is only useful in conjunction with a substitution value.
-
-#### addSection
-
-```php
-$email = new SendGrid\Email();
-$email
- ->addSmtpapiTo('john@somewhere.com')
- ->addSmtpapiTo("harry@somewhere.com")
- ->addSmtpapiTo("Bob@somewhere.com")
- ...
- ->setHtml("Hey %name%, you work at %place%")
- ->addSubstitution("%name%", array("John", "Harry", "Bob"))
- ->addSubstitution("%place%", array("%office%", "%office%", "%home%"))
- ->addSection("%office%", "an office")
- ->addSection("%home%", "your house")
-;
-```
-
-#### setSections
-
-```php
-$email = new SendGrid\Email();
-$email
- ->addSmtpapiTo('john@somewhere.com')
- ->addSmtpapiTo("harry@somewhere.com")
- ->addSmtpapiTo("Bob@somewhere.com")
- ...
- ->setHtml("Hey %name%, you work at %place%")
- ->addSubstitution("%name%", array("John", "Harry", "Bob"))
- ->addSubstitution("%place%", array("%office%", "%office%", "%home%"))
- ->setSections(array("%office%" => "an office", "%home%" => "your house"))
-;
-```
-
-### Unique Arguments ###
-
-[Unique Arguments](https://sendgrid.com/docs/API_Reference/SMTP_API/unique_arguments.html) are used for tracking purposes.
-
-NOTE: While you can attach an unlimited number of unique arguments to your email, there is an upper bound of 10,000 bytes. Before passing an email into the `send` function, you should do the following:
-
-```
-if (mb_strlen($myEmail->smtpapi->jsonString(), 'UTF-8') > 10000) {
- // throw Exception
-}
-```
-
-#### addUniqueArg / addUniqueArgument
-
-```php
-$email = new SendGrid\Email();
-$email
- ->addTo('foo@bar.com')
- ...
- ->addUniqueArg("Customer", "Someone")
- ->addUniqueArg("location", "Somewhere")
-;
-```
-
-#### setUniqueArgs / setUniqueArguments
-
-```php
-$email = new SendGrid\Email();
-$email
- ->addTo('foo@bar.com')
- ...
- ->setUniqueArgs(array('cow' => 'chicken'))
-;
-```
-
-### Filter Settings ###
-
-[Filter Settings](https://sendgrid.com/docs/API_Reference/SMTP_API/apps.html) are used to enable and disable apps, and to pass parameters to those apps.
-
-#### addFilter / addFilterSetting
-
-```php
-$email = new SendGrid\Email();
-$email
- ->addTo('foo@bar.com')
- ...
- addFilter("gravatar", "enable", 1)
- ->addFilter("footer", "enable", 1)
- ->addFilter("footer", "text/plain", "Here is a plain text footer")
- ->addFilter(
- "footer",
- "text/html",
- "<p style='color:red;'>Here is an HTML footer</p>"
- )
-;
-```
-
-#### setFilters / setFilterSettings
-
-```php
-$email = new SendGrid\Email();
-$email
- ->addTo('foo@bar.com')
- ...
- setFilters(array("gravatar" => array("settings" => array("enable" => 1))))
-;
-```
-
-### Templates ###
-
-You can easily use SendGrid's [template engine](https://sendgrid.com/docs/User_Guide/Apps/template_engine.html) by applying filters.
-
-#### setTemplateId
-
-```php
-$email = new SendGrid\Email();
-$email
- ->addTo('someone@example.com')
- ->setFrom('support@example.com')
- ->setFromName('Support')
- ->setSubject('Subject goes here')
- // set html or text to an empty space (see http://git.io/hCNy)
- ->setHtml(' ') // <-- triggers the html version of the template
- // AND / OR
- ->setText(' ') // <-- triggers the plaintext version of the template
- ->setTemplateId($templateId);
-```
-
-This is simply a convenience method for:
-
-```php
-$email = new SendGrid\Email();
-$email
- ->addFilter('templates', 'enabled', 1)
- ->addFilter('templates', 'template_id', $templateId)
-;
-```
-
-### Advanced Suppression Manager ###
-
-[ASM](https://sendgrid.com/docs/User_Guide/advanced_suppression_manager.html) is used to handle suppression groups.
-
-#### setAsmGroupId ####
-
-```php
-$email = new SendGrid\Email();
-$email->setAsmGroupId('my_group_id');
-```
-
-### Headers ###
-
-You can add standard email message headers as necessary.
-
-#### addHeader
-
-```php
-$email = new SendGrid\Email();
-$email
- ->addTo('foo@bar.com')
- ...
- ->addHeader('X-Sent-Using', 'SendGrid-API')
- ->addHeader('X-Transport', 'web')
-;
-```
-
-#### setHeaders
-
-```php
-$email = new SendGrid\Email();
-$email
- ->addTo('foo@bar.com')
- ...
- ->setHeaders(array('X-Sent-Using' => 'SendGrid-API', 'X-Transport' => 'web'))
-;
-```
-
-#### removeHeader
-
-```php
-$email = new SendGrid\Email();
-$email
- ->addTo('foo@bar.com')
- ...
- ->addHeader('X-Sent-Using', 'SendGrid-API')
- ->addHeader('X-Transport', 'web')
-;
-$email->removeHeader('X-Transport');
-```
-
-### Sending to 1,000s of emails in one batch
-
-Sometimes you might want to send 1,000s of emails in one request. You can do that. It is recommended you break each batch up in 1,000 increments. So if you need to send to 5,000 emails, then you'd break this into a loop of 1,000 emails at a time.
-
-```php
-$sendgrid = new SendGrid('YOUR_SENDGRID_APIKEY');
-$email = new SendGrid\Email();
-
-$recipients = array(
- "alpha@mailinator.com",
- "beta@mailinator.com",
- "zeta@mailinator.com"
-);
-$names = array("Alpha", "Beta", "Zeta");
-
-$email
- ->setFrom("from@mailinator.com")
- ->setSubject('[sendgrid-php-batch-email]')
- ->setSmtpapiTos($recipients)
- ->addSubstitution("%name%", $names)
- ->setText("Hey %name%, we have an email for you")
- ->setHtml("<h1>Hey %name%, we have an email for you</h1>")
-;
-
-$result = $sendgrid->send($email);
-```
-
-## Contributing
-
-1. Fork it
-2. Create your feature branch (`git checkout -b my-new-feature`)
-3. Commit your changes (`git commit -am 'Added some feature'`)
-4. Push to the branch (`git push origin my-new-feature`)
-5. Create new Pull Request
-
-## Running Tests
-
-The existing tests in the `test` directory can be run using [PHPUnit](https://github.com/sebastianbergmann/phpunit/) with the following command:
-
-````bash
-composer update --dev
-./vendor/bin/phpunit --bootstrap test/unit/bootstrap.php --filter test* test/unit
-```
-
-or if you already have PHPUnit installed globally.
-
-```bash
-phpunit --bootstrap test/unit/bootstrap.php --filter test* test/unit
-```
-
-## Releasing
-
-To release a new version of this library, update the version in all locations, tag the version, and then push the tag up. Packagist.org takes care of the rest.
-
-1. Confirm tests pass
-2. Bump the version in composer.json, lib/Client.php, lib/SendGrid.php, test/unit/SendGridTest.php
-3. Update CHANGELOG.md
-4. Confirm tests pass
-5. Commit Version bump vX.X.X
-6. Push changes to GitHub
-7. Release tag on GitHub vX.X.X
-8. Packagist.org takes care of the rest
-
-#### Testing uploading to Amazon S3
-
-If you want to test uploading the zipped file to Amazon S3 (SendGrid employees only), do the following.
-
-```
-export S3_SIGNATURE="secret_signature"
-export S3_POLICY="secret_policy"
-export S3_BUCKET="sendgrid-open-source"
-export S3_ACCESS_KEY="secret_access_key"
-./scripts/s3upload.sh
-```
diff --git a/USAGE.md b/USAGE.md
new file mode 100644
index 0000000..e5d625c
--- /dev/null
+++ b/USAGE.md
@@ -0,0 +1,4654 @@
+This documentation is based on our [OAI specification](https://github.com/sendgrid/sendgrid-oai).
+
+# INITIALIZATION
+
+```php
+// If you are using Composer
+require 'vendor/autoload.php';
+
+
+$apiKey = getenv('SENDGRID_API_KEY');
+$sg = new \SendGrid($apiKey);
+```
+
+# Table of Contents
+
+* [ACCESS SETTINGS](#access_settings)
+* [API KEYS](#api_keys)
+* [ASM](#asm)
+* [BROWSERS](#browsers)
+* [CAMPAIGNS](#campaigns)
+* [CATEGORIES](#categories)
+* [CLIENTS](#clients)
+* [CONTACTDB](#contactdb)
+* [DEVICES](#devices)
+* [GEO](#geo)
+* [IPS](#ips)
+* [MAIL](#mail)
+* [MAIL SETTINGS](#mail_settings)
+* [MAILBOX PROVIDERS](#mailbox_providers)
+* [PARTNER SETTINGS](#partner_settings)
+* [SCOPES](#scopes)
+* [STATS](#stats)
+* [SUBUSERS](#subusers)
+* [SUPPRESSION](#suppression)
+* [TEMPLATES](#templates)
+* [TRACKING SETTINGS](#tracking_settings)
+* [USER](#user)
+* [WHITELABEL](#whitelabel)
+
+
+<a name="access_settings"></a>
+# ACCESS SETTINGS
+
+## Retrieve all recent access attempts
+
+**This endpoint allows you to retrieve a list of all of the IP addresses that recently attempted to access your account either through the User Interface or the API.**
+
+IP Access Management allows you to control which IP addresses can be used to access your account, either through the User Interface or the API. There is no limit to the number of IP addresses that you can add to your whitelist. It is possible to remove your own IP address from the whitelist, thus preventing yourself from accessing your account.
+
+For more information, please see our [User Guide](http://sendgrid.com/docs/User_Guide/Settings/ip_access_management.html).
+
+### GET /access_settings/activity
+
+
+```php
+$query_params = json_decode('{"limit": 1}');
+$response = $sg->client->access_settings()->activity()->get(null, $query_params);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Add one or more IPs to the whitelist
+
+**This endpoint allows you to add one or more IP addresses to your IP whitelist.**
+
+When adding an IP to your whitelist, include the IP address in an array. You can whitelist one IP at a time, or you can whitelist multiple IPs at once.
+
+IP Access Management allows you to control which IP addresses can be used to access your account, either through the User Interface or the API. There is no limit to the number of IP addresses that you can add to your whitelist. It is possible to remove your own IP address from the whitelist, thus preventing yourself from accessing your account.
+
+For more information, please see our [User Guide](http://sendgrid.com/docs/User_Guide/Settings/ip_access_management.html).
+
+### POST /access_settings/whitelist
+
+
+```php
+$request_body = json_decode('{
+ "ips": [
+ {
+ "ip": "192.168.1.1"
+ },
+ {
+ "ip": "192.*.*.*"
+ },
+ {
+ "ip": "192.168.1.3/32"
+ }
+ ]
+}');
+$response = $sg->client->access_settings()->whitelist()->post($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Retrieve a list of currently whitelisted IPs
+
+**This endpoint allows you to retrieve a list of IP addresses that are currently whitelisted.**
+
+IP Access Management allows you to control which IP addresses can be used to access your account, either through the User Interface or the API. There is no limit to the number of IP addresses that you can add to your whitelist. It is possible to remove your own IP address from the whitelist, thus preventing yourself from accessing your account.
+
+For more information, please see our [User Guide](http://sendgrid.com/docs/User_Guide/Settings/ip_access_management.html).
+
+### GET /access_settings/whitelist
+
+
+```php
+$response = $sg->client->access_settings()->whitelist()->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Remove one or more IPs from the whitelist
+
+**This endpoint allows you to remove one or more IPs from your IP whitelist.**
+
+You can remove one IP at a time, or you can remove multiple IP addresses.
+
+IP Access Management allows you to control which IP addresses can be used to access your account, either through the User Interface or the API. There is no limit to the number of IP addresses that you can add to your whitelist. It is possible to remove your own IP address from the whitelist, thus preventing yourself from accessing your account.
+
+For more information, please see our [User Guide](http://sendgrid.com/docs/User_Guide/Settings/ip_access_management.html).
+
+### DELETE /access_settings/whitelist
+
+
+```php
+$response = $sg->client->access_settings()->whitelist()->delete($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Retrieve a specific whitelisted IP
+
+**This endpoint allows you to retreive 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.
+
+IP Access Management allows you to control which IP addresses can be used to access your account, either through the User Interface or the API. There is no limit to the number of IP addresses that you can add to your whitelist. It is possible to remove your own IP address from the whitelist, thus preventing yourself from accessing your account.
+
+For more information, please see our [User Guide](http://sendgrid.com/docs/User_Guide/Settings/ip_access_management.html).
+
+### GET /access_settings/whitelist/{rule_id}
+
+
+```php
+$rule_id = "test_url_param";
+$response = $sg->client->access_settings()->whitelist()->_($rule_id)->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Remove a specific IP from the whitelist
+
+**This endpoint allows you to remove a specific IP address from your IP whitelist.**
+
+When removing a specific IP address from your whitelist, you must include the ID in your call.
+
+IP Access Management allows you to control which IP addresses can be used to access your account, either through the User Interface or the API. There is no limit to the number of IP addresses that you can add to your whitelist. It is possible to remove your own IP address from the whitelist, thus preventing yourself from accessing your account.
+
+For more information, please see our [User Guide](http://sendgrid.com/docs/User_Guide/Settings/ip_access_management.html).
+
+### DELETE /access_settings/whitelist/{rule_id}
+
+
+```php
+$rule_id = "test_url_param";
+$response = $sg->client->access_settings()->whitelist()->_($rule_id)->delete($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+<a name="api_keys"></a>
+# API KEYS
+
+## Create API keys
+
+**This enpoint 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.
+
+There is a limit of 100 API Keys on your account.
+
+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).
+
+See the [API Key Permissions List](https://sendgrid.com/docs/API_Reference/Web_API_v3/API_Keys/api_key_permissions_list.html) for a list of all available scopes.
+
+### POST /api_keys
+
+
+```php
+$request_body = json_decode('{
+ "name": "My API Key",
+ "scopes": [
+ "mail.send",
+ "alerts.create",
+ "alerts.read"
+ ]
+}');
+$response = $sg->client->api_keys()->post($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Retrieve all API Keys belonging to the authenticated user
+
+**This endpoint allows you to retrieve all API Keys that belong to the authenticated user.**
+
+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).
+
+### GET /api_keys
+
+
+```php
+$response = $sg->client->api_keys()->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Update the name & scopes of an API Key
+
+**This endpoint allows you to update the name and scopes of a given API key.**
+
+A JSON request body with a "name" property is required.
+Most provide the list of all the scopes an api key should have.
+
+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).
+
+
+### PUT /api_keys/{api_key_id}
+
+
+```php
+$request_body = json_decode('{
+ "name": "A New Hope",
+ "scopes": [
+ "user.profile.read",
+ "user.profile.update"
+ ]
+}');
+$api_key_id = "test_url_param";
+$response = $sg->client->api_keys()->_($api_key_id)->put($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Update API keys
+
+**This endpoint allows you to update the name of an existing API Key.**
+
+A JSON request body with a "name" property is required.
+
+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).
+
+## URI Parameters
+
+| URI Parameter | Type | Required? | Description |
+|---|---|---|---|
+|api_key_id |string | required | The ID of the API Key you are updating.|
+
+### PATCH /api_keys/{api_key_id}
+
+
+```php
+$request_body = json_decode('{
+ "name": "A New Hope"
+}');
+$api_key_id = "test_url_param";
+$response = $sg->client->api_keys()->_($api_key_id)->patch($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Retrieve an existing API Key
+
+**This endpoint allows you to retrieve a single api key.**
+
+If the API Key ID does not exist an HTTP 404 will be returned.
+
+### GET /api_keys/{api_key_id}
+
+
+```php
+$api_key_id = "test_url_param";
+$response = $sg->client->api_keys()->_($api_key_id)->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Delete API keys
+
+**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.
+
+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).
+
+## URI Parameters
+
+| URI Parameter | Type | Required? | Description |
+|---|---|---|---|
+|api_key_id |string | required | The ID of the API Key you are deleting.|
+
+### DELETE /api_keys/{api_key_id}
+
+
+```php
+$api_key_id = "test_url_param";
+$response = $sg->client->api_keys()->_($api_key_id)->delete($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+<a name="asm"></a>
+# ASM
+
+## Create a new suppression group
+
+**This endpoint allows you to create a new suppression group.**
+
+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.
+
+Each user can create up to 25 different suppression groups.
+
+### POST /asm/groups
+
+
+```php
+$request_body = json_decode('{
+ "description": "Suggestions for products our users might like.",
+ "is_default": true,
+ "name": "Product Suggestions"
+}');
+$response = $sg->client->asm()->groups()->post($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Retrieve information about multiple suppression groups
+
+**This endpoint allows you to retrieve information about multiple suppression groups.**
+
+This endpoint will return information for each group ID that you include in your request. To add a group ID to your request, simply append `&id=` followed by the group ID.
+
+### GET /asm/groups
+
+
+```php
+$query_params = json_decode('{"id": 1}');
+$response = $sg->client->asm()->groups()->get(null, $query_params);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Update a suppression group.
+
+**This endpoint allows you to update or change a suppression group.**
+
+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.
+
+Each user can create up to 25 different suppression groups.
+
+### PATCH /asm/groups/{group_id}
+
+
+```php
+$request_body = json_decode('{
+ "description": "Suggestions for items our users might like.",
+ "id": 103,
+ "name": "Item Suggestions"
+}');
+$group_id = "test_url_param";
+$response = $sg->client->asm()->groups()->_($group_id)->patch($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Get information on a single suppression group.
+
+**This endpoint allows you to retrieve a single suppression group.**
+
+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.
+
+Each user can create up to 25 different suppression groups.
+
+### GET /asm/groups/{group_id}
+
+
+```php
+$group_id = "test_url_param";
+$response = $sg->client->asm()->groups()->_($group_id)->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Delete a suppression group.
+
+**This endpoint allows you to delete a suppression group.**
+
+You can only delete groups that have not been attached to sent mail in the last 60 days. If a recipient uses the "one-click unsubscribe" option on an email associated with a deleted group, that recipient will be added to the global suppression list.
+
+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.
+
+Each user can create up to 25 different suppression groups.
+
+### DELETE /asm/groups/{group_id}
+
+
+```php
+$group_id = "test_url_param";
+$response = $sg->client->asm()->groups()->_($group_id)->delete($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Add suppressions to a suppression group
+
+**This endpoint allows you to add email addresses to an unsubscribe group.**
+
+If you attempt to add suppressions to a group that has been deleted or does not exist, the suppressions will be added to the global suppressions list.
+
+Suppressions are recipient email addresses that are added to [unsubscribe groups](https://sendgrid.com/docs/API_Reference/Web_API_v3/Suppression_Management/groups.html). Once a recipient's address is on the suppressions list for an unsubscribe group, they will not receive any emails that are tagged with that unsubscribe group.
+
+### POST /asm/groups/{group_id}/suppressions
+
+
+```php
+$request_body = json_decode('{
+ "recipient_emails": [
+ "test1@example.com",
+ "test2@example.com"
+ ]
+}');
+$group_id = "test_url_param";
+$response = $sg->client->asm()->groups()->_($group_id)->suppressions()->post($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Retrieve all suppressions for a suppression group
+
+**This endpoint allows you to retrieve all suppressed email addresses belonging to the given group.**
+
+Suppressions are recipient email addresses that are added to [unsubscribe groups](https://sendgrid.com/docs/API_Reference/Web_API_v3/Suppression_Management/groups.html). Once a recipient's address is on the suppressions list for an unsubscribe group, they will not receive any emails that are tagged with that unsubscribe group.
+
+### GET /asm/groups/{group_id}/suppressions
+
+
+```php
+$group_id = "test_url_param";
+$response = $sg->client->asm()->groups()->_($group_id)->suppressions()->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Delete a suppression from a suppression group
+
+**This endpoint allows you to remove a suppressed email address from the given suppression group.**
+
+Suppressions are recipient email addresses that are added to [unsubscribe groups](https://sendgrid.com/docs/API_Reference/Web_API_v3/Suppression_Management/groups.html). Once a recipient's address is on the suppressions list for an unsubscribe group, they will not receive any emails that are tagged with that unsubscribe group.
+
+### DELETE /asm/groups/{group_id}/suppressions/{email}
+
+
+```php
+$group_id = "test_url_param";
+$email = "test_url_param";
+$response = $sg->client->asm()->groups()->_($group_id)->suppressions()->_($email)->delete($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Retrieve all suppressions
+
+**This endpoint allows you to retrieve a list of all suppressions.**
+
+Suppressions are email addresses that can be added to [groups](https://sendgrid.com/docs/API_Reference/Web_API_v3/Suppression_Management/groups.html) to prevent certain types of emails from being delivered to those addresses.
+
+### GET /asm/suppressions
+
+
+```php
+$response = $sg->client->asm()->suppressions()->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Add recipient addresses to the global suppression group.
+
+**This endpoint allows you to add one or more email addresses to the global suppressions group.**
+
+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).
+
+### POST /asm/suppressions/global
+
+
+```php
+$request_body = json_decode('{
+ "recipient_emails": [
+ "test1@example.com",
+ "test2@example.com"
+ ]
+}');
+$response = $sg->client->asm()->suppressions()->global()->post($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## 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.**
+
+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.
+
+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).
+
+### GET /asm/suppressions/global/{email}
+
+
+```php
+$email = "test_url_param";
+$response = $sg->client->asm()->suppressions()->global()->_($email)->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Delete a Global Suppression
+
+**This endpoint allows you to remove an email address from the global suppressions group.**
+
+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).
+
+### DELETE /asm/suppressions/global/{email}
+
+
+```php
+$email = "test_url_param";
+$response = $sg->client->asm()->suppressions()->global()->_($email)->delete($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Retrieve all suppression groups for an email address
+
+**This endpoint will return a list of all suppression groups, indicating if the given email address is suppressed for each group.**
+
+Suppressions are email addresses that can be added to [groups](https://sendgrid.com/docs/API_Reference/Web_API_v3/Suppression_Management/groups.html) to prevent certain types of emails from being delivered to those addresses.
+
+### GET /asm/suppressions/{email}
+
+
+```php
+$email = "test_url_param";
+$response = $sg->client->asm()->suppressions()->_($email)->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+<a name="browsers"></a>
+# BROWSERS
+
+## Retrieve email statistics by browser.
+
+**This endpoint allows you to retrieve your email statistics segmented by browser type.**
+
+**We only store up to 7 days of email activity in our database.** By default, 500 items will be returned per request via the Advanced Stats API endpoints.
+
+Advanced Stats provide a more in-depth view of your email statistics and the actions taken by your recipients. You can segment these statistics by geographic location, device type, client type, browser, and mailbox provider. For more information about statistics, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Statistics/index.html).
+
+### GET /browsers/stats
+
+
+```php
+$query_params = json_decode('{"end_date": "2016-04-01", "aggregated_by": "day", "browsers": "test_string", "limit": "test_string", "offset": "test_string", "start_date": "2016-01-01"}');
+$response = $sg->client->browsers()->stats()->get(null, $query_params);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+<a name="campaigns"></a>
+# CAMPAIGNS
+
+## Create a Campaign
+
+**This endpoint allows you to create a campaign.**
+
+Our Marketing Campaigns API lets you create, manage, send, and schedule campaigns.
+
+Note: In order to send or schedule the campaign, you will be required to provide a subject, sender ID, content (we suggest both html and plain text), and at least one list or segment ID. This information is not required when you create a campaign.
+
+For more information:
+
+* [User Guide > Marketing Campaigns](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/index.html)
+
+### POST /campaigns
+
+
+```php
+$request_body = json_decode('{
+ "categories": [
+ "spring line"
+ ],
+ "custom_unsubscribe_url": "",
+ "html_content": "<html><head><title></title></head><body><p>Check out our spring line!</p></body></html>",
+ "ip_pool": "marketing",
+ "list_ids": [
+ 110,
+ 124
+ ],
+ "plain_content": "Check out our spring line!",
+ "segment_ids": [
+ 110
+ ],
+ "sender_id": 124451,
+ "subject": "New Products for Spring!",
+ "suppression_group_id": 42,
+ "title": "March Newsletter"
+}');
+$response = $sg->client->campaigns()->post($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Retrieve all Campaigns
+
+**This endpoint allows you to retrieve a list of all of your campaigns.**
+
+Returns campaigns in reverse order they were created (newest first).
+
+Returns an empty array if no campaigns exist.
+
+For more information:
+
+* [User Guide > Marketing Campaigns](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/index.html)
+
+### GET /campaigns
+
+
+```php
+$query_params = json_decode('{"limit": 0, "offset": 0}');
+$response = $sg->client->campaigns()->get(null, $query_params);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Update a Campaign
+
+Update a campaign. This is especially useful if you only set up the campaign using POST /campaigns, but didn't set many of the parameters.
+
+For more information:
+
+* [User Guide > Marketing Campaigns](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/index.html)
+
+### PATCH /campaigns/{campaign_id}
+
+
+```php
+$request_body = json_decode('{
+ "categories": [
+ "summer line"
+ ],
+ "html_content": "<html><head><title></title></head><body><p>Check out our summer line!</p></body></html>",
+ "plain_content": "Check out our summer line!",
+ "subject": "New Products for Summer!",
+ "title": "May Newsletter"
+}');
+$campaign_id = "test_url_param";
+$response = $sg->client->campaigns()->_($campaign_id)->patch($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Retrieve a single campaign
+
+**This endpoint allows you to retrieve a specific campaign.**
+
+Our Marketing Campaigns API lets you create, manage, send, and schedule campaigns.
+
+For more information:
+
+* [User Guide > Marketing Campaigns](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/index.html)
+
+### GET /campaigns/{campaign_id}
+
+
+```php
+$campaign_id = "test_url_param";
+$response = $sg->client->campaigns()->_($campaign_id)->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Delete a Campaign
+
+**This endpoint allows you to delete a specific campaign.**
+
+Our Marketing Campaigns API lets you create, manage, send, and schedule campaigns.
+
+For more information:
+
+* [User Guide > Marketing Campaigns](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/index.html)
+
+### DELETE /campaigns/{campaign_id}
+
+
+```php
+$campaign_id = "test_url_param";
+$response = $sg->client->campaigns()->_($campaign_id)->delete($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Update a Scheduled Campaign
+
+**This endpoint allows to you change the scheduled time and date for a campaign to be sent.**
+
+For more information:
+
+* [User Guide > Marketing Campaigns](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/index.html)
+
+### PATCH /campaigns/{campaign_id}/schedules
+
+
+```php
+$request_body = json_decode('{
+ "send_at": 1489451436
+}');
+$campaign_id = "test_url_param";
+$response = $sg->client->campaigns()->_($campaign_id)->schedules()->patch($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Schedule a Campaign
+
+**This endpoint allows you to schedule a specific date and time for your campaign to be sent.**
+
+For more information:
+
+* [User Guide > Marketing Campaigns](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/index.html)
+
+### POST /campaigns/{campaign_id}/schedules
+
+
+```php
+$request_body = json_decode('{
+ "send_at": 1489771528
+}');
+$campaign_id = "test_url_param";
+$response = $sg->client->campaigns()->_($campaign_id)->schedules()->post($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## View Scheduled Time of a Campaign
+
+**This endpoint allows you to retrieve the date and time that the given campaign has been scheduled to be sent.**
+
+For more information:
+
+* [User Guide > Marketing Campaigns](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/index.html)
+
+### GET /campaigns/{campaign_id}/schedules
+
+
+```php
+$campaign_id = "test_url_param";
+$response = $sg->client->campaigns()->_($campaign_id)->schedules()->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Unschedule a Scheduled Campaign
+
+**This endpoint allows you to unschedule a campaign that has already been scheduled to be sent.**
+
+A successful unschedule will return a 204.
+If the specified campaign is in the process of being sent, the only option is to cancel (a different method).
+
+For more information:
+
+* [User Guide > Marketing Campaigns](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/index.html)
+
+### DELETE /campaigns/{campaign_id}/schedules
+
+
+```php
+$campaign_id = "test_url_param";
+$response = $sg->client->campaigns()->_($campaign_id)->schedules()->delete($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Send a Campaign
+
+**This endpoint allows you to immediately send a campaign at the time you make the API call.**
+
+Normally a POST would have a request body, but since this endpoint is telling us to send a resource that is already created, a request body is not needed.
+
+For more information:
+
+* [User Guide > Marketing Campaigns](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/index.html)
+
+### POST /campaigns/{campaign_id}/schedules/now
+
+
+```php
+$request_body = json_decode('null');
+$campaign_id = "test_url_param";
+$response = $sg->client->campaigns()->_($campaign_id)->schedules()->now()->post($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Send a Test Campaign
+
+**This endpoint allows you to send a test campaign.**
+
+To send to multiple addresses, use an array for the JSON "to" value ["one@address","two@address"]
+
+For more information:
+
+* [User Guide > Marketing Campaigns](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/index.html)
+
+### POST /campaigns/{campaign_id}/schedules/test
+
+
+```php
+$request_body = json_decode('{
+ "to": "your.email@example.com"
+}');
+$campaign_id = "test_url_param";
+$response = $sg->client->campaigns()->_($campaign_id)->schedules()->test()->post($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+<a name="categories"></a>
+# CATEGORIES
+
+## Retrieve all categories
+
+**This endpoint allows you to retrieve a list of all of your categories.**
+
+Categories can help organize your email analytics by enabling you to tag emails by type or broad topic. You can define your own custom categories. For more information, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Statistics/categories.html).
+
+### GET /categories
+
+
+```php
+$query_params = json_decode('{"category": "test_string", "limit": 1, "offset": 1}');
+$response = $sg->client->categories()->get(null, $query_params);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Retrieve Email Statistics for Categories
+
+**This endpoint allows you to retrieve all of your email statistics for each of your categories.**
+
+If you do not define any query parameters, this endpoint will return a sum for each category in groups of 10.
+
+Categories allow you to group your emails together according to broad topics that you define. For more information, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Statistics/categories.html).
+
+### GET /categories/stats
+
+
+```php
+$query_params = json_decode('{"end_date": "2016-04-01", "aggregated_by": "day", "limit": 1, "offset": 1, "start_date": "2016-01-01", "categories": "test_string"}');
+$response = $sg->client->categories()->stats()->get(null, $query_params);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Retrieve sums of email stats for each category [Needs: Stats object defined, has category ID?]
+
+**This endpoint allows you to retrieve the total sum of each email statistic for every category over the given date range.**
+
+If you do not define any query parameters, this endpoint will return a sum for each category in groups of 10.
+
+Categories allow you to group your emails together according to broad topics that you define. For more information, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Statistics/categories.html).
+
+### GET /categories/stats/sums
+
+
+```php
+$query_params = json_decode('{"end_date": "2016-04-01", "aggregated_by": "day", "limit": 1, "sort_by_metric": "test_string", "offset": 1, "start_date": "2016-01-01", "sort_by_direction": "asc"}');
+$response = $sg->client->categories()->stats()->sums()->get(null, $query_params);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+<a name="clients"></a>
+# CLIENTS
+
+## Retrieve email statistics by client type.
+
+**This endpoint allows you to retrieve your email statistics segmented by client type.**
+
+**We only store up to 7 days of email activity in our database.** By default, 500 items will be returned per request via the Advanced Stats API endpoints.
+
+Advanced Stats provide a more in-depth view of your email statistics and the actions taken by your recipients. You can segment these statistics by geographic location, device type, client type, browser, and mailbox provider. For more information about statistics, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Statistics/index.html).
+
+### GET /clients/stats
+
+
+```php
+$query_params = json_decode('{"aggregated_by": "day", "start_date": "2016-01-01", "end_date": "2016-04-01"}');
+$response = $sg->client->clients()->stats()->get(null, $query_params);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Retrieve stats by a specific client type.
+
+**This endpoint allows you to retrieve your email statistics segmented by a specific client type.**
+
+**We only store up to 7 days of email activity in our database.** By default, 500 items will be returned per request via the Advanced Stats API endpoints.
+
+## Available Client Types
+- phone
+- tablet
+- webmail
+- desktop
+
+Advanced Stats provide a more in-depth view of your email statistics and the actions taken by your recipients. You can segment these statistics by geographic location, device type, client type, browser, and mailbox provider. For more information about statistics, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Statistics/index.html).
+
+### GET /clients/{client_type}/stats
+
+
+```php
+$query_params = json_decode('{"aggregated_by": "day", "start_date": "2016-01-01", "end_date": "2016-04-01"}');
+$client_type = "test_url_param";
+$response = $sg->client->clients()->_($client_type)->stats()->get(null, $query_params);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+<a name="contactdb"></a>
+# CONTACTDB
+
+## Create a Custom Field
+
+**This endpoint allows you to create a custom field.**
+
+The contactdb is a database of your contacts for [SendGrid Marketing Campaigns](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/index.html).
+
+### POST /contactdb/custom_fields
+
+
+```php
+$request_body = json_decode('{
+ "name": "pet",
+ "type": "text"
+}');
+$response = $sg->client->contactdb()->custom_fields()->post($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Retrieve all custom fields
+
+**This endpoint allows you to retrieve all custom fields.**
+
+The contactdb is a database of your contacts for [SendGrid Marketing Campaigns](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/index.html).
+
+### GET /contactdb/custom_fields
+
+
+```php
+$response = $sg->client->contactdb()->custom_fields()->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Retrieve a Custom Field
+
+**This endpoint allows you to retrieve a custom field by ID.**
+
+The contactdb is a database of your contacts for [SendGrid Marketing Campaigns](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/index.html).
+
+### GET /contactdb/custom_fields/{custom_field_id}
+
+
+```php
+$custom_field_id = "test_url_param";
+$response = $sg->client->contactdb()->custom_fields()->_($custom_field_id)->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Delete a Custom Field
+
+**This endpoint allows you to delete a custom field by ID.**
+
+The contactdb is a database of your contacts for [SendGrid Marketing Campaigns](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/index.html).
+
+### DELETE /contactdb/custom_fields/{custom_field_id}
+
+
+```php
+$custom_field_id = "test_url_param";
+$response = $sg->client->contactdb()->custom_fields()->_($custom_field_id)->delete($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Create a List
+
+**This endpoint allows you to create a list for your recipients.**
+
+The Contacts API helps you manage your [Marketing Campaigns](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/index.html) recipients.
+
+### POST /contactdb/lists
+
+
+```php
+$request_body = json_decode('{
+ "name": "your list name"
+}');
+$response = $sg->client->contactdb()->lists()->post($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Retrieve all lists
+
+**This endpoint allows you to retrieve all of your recipient lists. If you don't have any lists, an empty array will be returned.**
+
+The Contacts API helps you manage your [Marketing Campaigns](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/index.html) recipients.
+
+### GET /contactdb/lists
+
+
+```php
+$response = $sg->client->contactdb()->lists()->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Delete Multiple lists
+
+**This endpoint allows you to delete multiple recipient lists.**
+
+The Contacts API helps you manage your [Marketing Campaigns](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/index.html) recipients.
+
+### DELETE /contactdb/lists
+
+
+```php
+$response = $sg->client->contactdb()->lists()->delete($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Update a List
+
+**This endpoint allows you to update the name of one of your recipient lists.**
+
+
+The Contacts API helps you manage your [Marketing Campaigns](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/index.html) recipients.
+
+### PATCH /contactdb/lists/{list_id}
+
+
+```php
+$request_body = json_decode('{
+ "name": "newlistname"
+}');
+$query_params = json_decode('{"list_id": 0}');
+$list_id = "test_url_param";
+$response = $sg->client->contactdb()->lists()->_($list_id)->patch($request_body, $query_params);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Retrieve a single list
+
+This endpoint allows you to retrieve a single recipient list.
+
+The Contacts API helps you manage your [Marketing Campaigns](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/index.html) recipients.
+
+### GET /contactdb/lists/{list_id}
+
+
+```php
+$query_params = json_decode('{"list_id": 0}');
+$list_id = "test_url_param";
+$response = $sg->client->contactdb()->lists()->_($list_id)->get(null, $query_params);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Delete a List
+
+**This endpoint allows you to delete a specific recipient list with the given ID.**
+
+The Contacts API helps you manage your [Marketing Campaigns](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/index.html) recipients.
+
+### DELETE /contactdb/lists/{list_id}
+
+
+```php
+$query_params = json_decode('{"delete_contacts": "true"}');
+$list_id = "test_url_param";
+$response = $sg->client->contactdb()->lists()->_($list_id)->delete($request_body, $query_params);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Add Multiple Recipients to a List
+
+**This endpoint allows you to add multiple recipients to a list.**
+
+Adds existing recipients to a list, passing in the recipient IDs to add. Recipient IDs should be passed exactly as they are returned from recipient endpoints.
+
+The Contacts API helps you manage your [Marketing Campaigns](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/index.html) recipients.
+
+### POST /contactdb/lists/{list_id}/recipients
+
+
+```php
+$request_body = json_decode('[
+ "recipient_id1",
+ "recipient_id2"
+]');
+$list_id = "test_url_param";
+$response = $sg->client->contactdb()->lists()->_($list_id)->recipients()->post($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Retrieve all recipients on a List
+
+**This endpoint allows you to retrieve all recipients on the list with the given ID.**
+
+The Contacts API helps you manage your [Marketing Campaigns](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/index.html) recipients.
+
+### GET /contactdb/lists/{list_id}/recipients
+
+
+```php
+$query_params = json_decode('{"page": 1, "page_size": 1, "list_id": 0}');
+$list_id = "test_url_param";
+$response = $sg->client->contactdb()->lists()->_($list_id)->recipients()->get(null, $query_params);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Add a Single Recipient to a List
+
+**This endpoint allows you to add a single recipient to a list.**
+
+The Contacts API helps you manage your [Marketing Campaigns](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/index.html) recipients.
+
+### POST /contactdb/lists/{list_id}/recipients/{recipient_id}
+
+
+```php
+$request_body = json_decode('null');
+$list_id = "test_url_param";
+$recipient_id = "test_url_param";
+$response = $sg->client->contactdb()->lists()->_($list_id)->recipients()->_($recipient_id)->post($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Delete a Single Recipient from a Single List
+
+**This endpoint allows you to delete a single recipient from a list.**
+
+The Contacts API helps you manage your [Marketing Campaigns](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/index.html) recipients.
+
+### DELETE /contactdb/lists/{list_id}/recipients/{recipient_id}
+
+
+```php
+$query_params = json_decode('{"recipient_id": 0, "list_id": 0}');
+$list_id = "test_url_param";
+$recipient_id = "test_url_param";
+$response = $sg->client->contactdb()->lists()->_($list_id)->recipients()->_($recipient_id)->delete($request_body, $query_params);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Update Recipient
+
+**This endpoint allows you to update one or more recipients.**
+
+The body of an API call to this endpoint must include an array of one or more recipient objects.
+
+It is of note that you can add custom field data as parameters on recipient objects. We have provided an example using some of the default custom fields SendGrid provides.
+
+The contactdb is a database of your contacts for [SendGrid Marketing Campaigns](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/index.html).
+
+### PATCH /contactdb/recipients
+
+
+```php
+$request_body = json_decode('[
+ {
+ "email": "jones@example.com",
+ "first_name": "Guy",
+ "last_name": "Jones"
+ }
+]');
+$response = $sg->client->contactdb()->recipients()->patch($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Add recipients
+
+**This endpoint allows you to add a Marketing Campaigns recipient.**
+
+It is of note that you can add custom field data as a parameter on this endpoint. We have provided an example using some of the default custom fields SendGrid provides.
+
+The Contacts API helps you manage your [Marketing Campaigns](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/index.html) recipients.
+
+### POST /contactdb/recipients
+
+
+```php
+$request_body = json_decode('[
+ {
+ "age": 25,
+ "email": "example@example.com",
+ "first_name": "",
+ "last_name": "User"
+ },
+ {
+ "age": 25,
+ "email": "example2@example.com",
+ "first_name": "Example",
+ "last_name": "User"
+ }
+]');
+$response = $sg->client->contactdb()->recipients()->post($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Retrieve recipients
+
+**This endpoint allows you to retrieve all of your Marketing Campaigns recipients.**
+
+Batch deletion of a page makes it possible to receive an empty page of recipients before reaching the end of
+the list of recipients. To avoid this issue; iterate over pages until a 404 is retrieved.
+
+The Contacts API helps you manage your [Marketing Campaigns](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/index.html) recipients.
+
+### GET /contactdb/recipients
+
+
+```php
+$query_params = json_decode('{"page": 1, "page_size": 1}');
+$response = $sg->client->contactdb()->recipients()->get(null, $query_params);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Delete Recipient
+
+**This endpoint allows you to deletes one or more recipients.**
+
+The body of an API call to this endpoint must include an array of recipient IDs of the recipients you want to delete.
+
+The contactdb is a database of your contacts for [SendGrid Marketing Campaigns](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/index.html).
+
+### DELETE /contactdb/recipients
+
+
+```php
+$response = $sg->client->contactdb()->recipients()->delete($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Retrieve the count of billable recipients
+
+**This endpoint allows you to retrieve the number of Marketing Campaigns recipients that you will be billed for.**
+
+You are billed for marketing campaigns based on the highest number of recipients you have had in your account at one time. This endpoint will allow you to know the current billable count value.
+
+The Contacts API helps you manage your [Marketing Campaigns](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/index.html) recipients.
+
+### GET /contactdb/recipients/billable_count
+
+
+```php
+$response = $sg->client->contactdb()->recipients()->billable_count()->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Retrieve a Count of Recipients
+
+**This endpoint allows you to retrieve the total number of Marketing Campaigns recipients.**
+
+The contactdb is a database of your contacts for [SendGrid Marketing Campaigns](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/index.html).
+
+### GET /contactdb/recipients/count
+
+
+```php
+$response = $sg->client->contactdb()->recipients()->count()->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Retrieve recipients matching search criteria
+
+**This endpoint allows you to perform a search on all of your Marketing Campaigns recipients.**
+
+field_name:
+
+* is a variable that is substituted for your actual custom field name from your recipient.
+* Text fields must be url-encoded. Date fields are searchable only by unix timestamp (e.g. 2/2/2015 becomes 1422835200)
+* If field_name is a 'reserved' date field, such as created_at or updated_at, the system will internally convert
+your epoch time to a date range encompassing the entire day. For example, an epoch time of 1422835600 converts to
+Mon, 02 Feb 2015 00:06:40 GMT, but internally the system will search from Mon, 02 Feb 2015 00:00:00 GMT through
+Mon, 02 Feb 2015 23:59:59 GMT.
+
+The contactdb is a database of your contacts for [SendGrid Marketing Campaigns](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/index.html).
+
+### GET /contactdb/recipients/search
+
+
+```php
+$query_params = json_decode('{"{field_name}": "test_string"}');
+$response = $sg->client->contactdb()->recipients()->search()->get(null, $query_params);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Retrieve a single recipient
+
+**This endpoint allows you to retrieve a single recipient by ID from your contact database.**
+
+The Contacts API helps you manage your [Marketing Campaigns](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/index.html) recipients.
+
+### GET /contactdb/recipients/{recipient_id}
+
+
+```php
+$recipient_id = "test_url_param";
+$response = $sg->client->contactdb()->recipients()->_($recipient_id)->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Delete a Recipient
+
+**This endpoint allows you to delete a single recipient with the given ID from your contact database.**
+
+The Contacts API helps you manage your [Marketing Campaigns](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/index.html) recipients.
+
+### DELETE /contactdb/recipients/{recipient_id}
+
+
+```php
+$recipient_id = "test_url_param";
+$response = $sg->client->contactdb()->recipients()->_($recipient_id)->delete($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Retrieve the lists that a recipient is on
+
+**This endpoint allows you to retrieve the lists that a given recipient belongs to.**
+
+Each recipient can be on many lists. This endpoint gives you all of the lists that any one recipient has been added to.
+
+The Contacts API helps you manage your [Marketing Campaigns](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/index.html) recipients.
+
+### GET /contactdb/recipients/{recipient_id}/lists
+
+
+```php
+$recipient_id = "test_url_param";
+$response = $sg->client->contactdb()->recipients()->_($recipient_id)->lists()->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Retrieve reserved fields
+
+**This endpoint allows you to list all fields that are reserved and can't be used for custom field names.**
+
+The contactdb is a database of your contacts for [SendGrid Marketing Campaigns](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/index.html).
+
+### GET /contactdb/reserved_fields
+
+
+```php
+$response = $sg->client->contactdb()->reserved_fields()->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Create a Segment
+
+**This endpoint allows you to create a segment.**
+
+All recipients in your contactdb will be added or removed automatically depending on whether they match the criteria for this segment.
+
+List Id:
+
+* Send this to segment from an existing list
+* Don't send this in order to segment from your entire contactdb.
+
+Valid operators for create and update depend on the type of the field you are segmenting:
+
+* **Dates:** "eq", "ne", "lt" (before), "gt" (after)
+* **Text:** "contains", "eq" (is - matches the full field), "ne" (is not - matches any field where the entire field is not the condition value)
+* **Numbers:** "eq", "lt", "gt"
+* **Email Clicks and Opens:** "eq" (opened), "ne" (not opened)
+
+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".
+
+The Contacts API helps you manage your [Marketing Campaigns](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/index.html) recipients.
+
+For more information about segments in Marketing Campaigns, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/lists.html#-Create-a-Segment).
+
+### POST /contactdb/segments
+
+
+```php
+$request_body = json_decode('{
+ "conditions": [
+ {
+ "and_or": "",
+ "field": "last_name",
+ "operator": "eq",
+ "value": "Miller"
+ },
+ {
+ "and_or": "and",
+ "field": "last_clicked",
+ "operator": "gt",
+ "value": "01/02/2015"
+ },
+ {
+ "and_or": "or",
+ "field": "clicks.campaign_identifier",
+ "operator": "eq",
+ "value": "513"
+ }
+ ],
+ "list_id": 4,
+ "name": "Last Name Miller"
+}');
+$response = $sg->client->contactdb()->segments()->post($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Retrieve all segments
+
+**This endpoint allows you to retrieve all of your segments.**
+
+The Contacts API helps you manage your [Marketing Campaigns](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/index.html) recipients.
+
+For more information about segments in Marketing Campaigns, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/lists.html#-Create-a-Segment).
+
+### GET /contactdb/segments
+
+
+```php
+$response = $sg->client->contactdb()->segments()->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Update a segment
+
+**This endpoint allows you to update a segment.**
+
+The Contacts API helps you manage your [Marketing Campaigns](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/index.html) recipients.
+
+For more information about segments in Marketing Campaigns, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/lists.html#-Create-a-Segment).
+
+### PATCH /contactdb/segments/{segment_id}
+
+
+```php
+$request_body = json_decode('{
+ "conditions": [
+ {
+ "and_or": "",
+ "field": "last_name",
+ "operator": "eq",
+ "value": "Miller"
+ }
+ ],
+ "list_id": 5,
+ "name": "The Millers"
+}');
+$query_params = json_decode('{"segment_id": "test_string"}');
+$segment_id = "test_url_param";
+$response = $sg->client->contactdb()->segments()->_($segment_id)->patch($request_body, $query_params);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Retrieve a segment
+
+**This endpoint allows you to retrieve a single segment with the given ID.**
+
+The Contacts API helps you manage your [Marketing Campaigns](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/index.html) recipients.
+
+For more information about segments in Marketing Campaigns, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/lists.html#-Create-a-Segment).
+
+### GET /contactdb/segments/{segment_id}
+
+
+```php
+$query_params = json_decode('{"segment_id": 0}');
+$segment_id = "test_url_param";
+$response = $sg->client->contactdb()->segments()->_($segment_id)->get(null, $query_params);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Delete a segment
+
+**This endpoint allows you to delete a segment from your recipients database.**
+
+You also have the option to delete all the contacts from your Marketing Campaigns recipient database who were in this segment.
+
+The Contacts API helps you manage your [Marketing Campaigns](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/index.html) recipients.
+
+For more information about segments in Marketing Campaigns, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/lists.html#-Create-a-Segment).
+
+### DELETE /contactdb/segments/{segment_id}
+
+
+```php
+$query_params = json_decode('{"delete_contacts": "true"}');
+$segment_id = "test_url_param";
+$response = $sg->client->contactdb()->segments()->_($segment_id)->delete($request_body, $query_params);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Retrieve recipients on a segment
+
+**This endpoint allows you to retrieve all of the recipients in a segment with the given ID.**
+
+The Contacts API helps you manage your [Marketing Campaigns](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/index.html) recipients.
+
+For more information about segments in Marketing Campaigns, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/lists.html#-Create-a-Segment).
+
+### GET /contactdb/segments/{segment_id}/recipients
+
+
+```php
+$query_params = json_decode('{"page": 1, "page_size": 1}');
+$segment_id = "test_url_param";
+$response = $sg->client->contactdb()->segments()->_($segment_id)->recipients()->get(null, $query_params);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+<a name="devices"></a>
+# DEVICES
+
+## Retrieve email statistics by device type.
+
+**This endpoint allows you to retrieve your email statistics segmented by the device type.**
+
+**We only store up to 7 days of email activity in our database.** By default, 500 items will be returned per request via the Advanced Stats API endpoints.
+
+## Available Device Types
+| **Device** | **Description** | **Example** |
+|---|---|---|
+| Desktop | Email software on desktop computer. | I.E., Outlook, Sparrow, or Apple Mail. |
+| Webmail | A web-based email client. | I.E., Yahoo, Google, AOL, or Outlook.com. |
+| Phone | A smart phone. | iPhone, Android, Blackberry, etc.
+| Tablet | A tablet computer. | iPad, android based tablet, etc. |
+| Other | An unrecognized device. |
+
+Advanced Stats provide a more in-depth view of your email statistics and the actions taken by your recipients. You can segment these statistics by geographic location, device type, client type, browser, and mailbox provider. For more information about statistics, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Statistics/index.html).
+
+### GET /devices/stats
+
+
+```php
+$query_params = json_decode('{"aggregated_by": "day", "limit": 1, "start_date": "2016-01-01", "end_date": "2016-04-01", "offset": 1}');
+$response = $sg->client->devices()->stats()->get(null, $query_params);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+<a name="geo"></a>
+# GEO
+
+## Retrieve email statistics by country and state/province.
+
+**This endpoint allows you to retrieve your email statistics segmented by country and state/province.**
+
+**We only store up to 7 days of email activity in our database.** By default, 500 items will be returned per request via the Advanced Stats API endpoints.
+
+Advanced Stats provide a more in-depth view of your email statistics and the actions taken by your recipients. You can segment these statistics by geographic location, device type, client type, browser, and mailbox provider. For more information about statistics, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Statistics/index.html).
+
+### GET /geo/stats
+
+
+```php
+$query_params = json_decode('{"end_date": "2016-04-01", "country": "US", "aggregated_by": "day", "limit": 1, "offset": 1, "start_date": "2016-01-01"}');
+$response = $sg->client->geo()->stats()->get(null, $query_params);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+<a name="ips"></a>
+# IPS
+
+## Retrieve all IP addresses
+
+**This endpoint allows you to retrieve a list of all assigned and unassigned IPs.**
+
+Response includes warm up status, pools, assigned subusers, and whitelabel info. The start_date field corresponds to when warmup started for that IP.
+
+A single IP address or a range of IP addresses may be dedicated to an account in order to send email for multiple domains. The reputation of this IP is based on the aggregate performance of all the senders who use it.
+
+### GET /ips
+
+
+```php
+$query_params = json_decode('{"subuser": "test_string", "ip": "test_string", "limit": 1, "exclude_whitelabels": "true", "offset": 1}');
+$response = $sg->client->ips()->get(null, $query_params);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Retrieve all assigned IPs
+
+**This endpoint allows you to retrieve only assigned IP addresses.**
+
+A single IP address or a range of IP addresses may be dedicated to an account in order to send email for multiple domains. The reputation of this IP is based on the aggregate performance of all the senders who use it.
+
+### GET /ips/assigned
+
+
+```php
+$response = $sg->client->ips()->assigned()->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Create an IP pool.
+
+**This endpoint allows you to create an IP pool.**
+
+**Each user can create up to 10 different 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.
+
+IP pools can only be used with whitelabeled IP addresses.
+
+If an IP pool is NOT specified for an email, it will use any IP available, including ones in pools.
+
+### POST /ips/pools
+
+
+```php
+$request_body = json_decode('{
+ "name": "marketing"
+}');
+$response = $sg->client->ips()->pools()->post($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Retrieve all IP pools.
+
+**This endpoint allows you to retreive 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.
+
+IP pools can only be used with whitelabeled IP addresses.
+
+If an IP pool is NOT specified for an email, it will use any IP available, including ones in pools.
+
+### GET /ips/pools
+
+
+```php
+$response = $sg->client->ips()->pools()->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Update an IP pools name.
+
+**This endpoint allows you to update the name of an IP pool.**
+
+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.
+
+IP pools can only be used with whitelabeled IP addresses.
+
+If an IP pool is NOT specified for an email, it will use any IP available, including ones in pools.
+
+### PUT /ips/pools/{pool_name}
+
+
+```php
+$request_body = json_decode('{
+ "name": "new_pool_name"
+}');
+$pool_name = "test_url_param";
+$response = $sg->client->ips()->pools()->_($pool_name)->put($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Retrieve all IPs in a specified pool.
+
+**This endpoint allows you to list all of the IP addresses that are in a specific IP pool.**
+
+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.
+
+IP pools can only be used with whitelabeled IP addresses.
+
+If an IP pool is NOT specified for an email, it will use any IP available, including ones in pools.
+
+### GET /ips/pools/{pool_name}
+
+
+```php
+$pool_name = "test_url_param";
+$response = $sg->client->ips()->pools()->_($pool_name)->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Delete an IP pool.
+
+**This endpoint allows you to delete an IP pool.**
+
+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.
+
+IP pools can only be used with whitelabeled IP addresses.
+
+If an IP pool is NOT specified for an email, it will use any IP available, including ones in pools.
+
+### DELETE /ips/pools/{pool_name}
+
+
+```php
+$pool_name = "test_url_param";
+$response = $sg->client->ips()->pools()->_($pool_name)->delete($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Add an IP address to a pool
+
+**This endpoint allows you to add an IP address to an IP pool.**
+
+You can add the same IP address to multiple pools. It may take up to 60 seconds for your IP address to be added to a pool after your request is made.
+
+A single IP address or a range of IP addresses may be dedicated to an account in order to send email for multiple domains. The reputation of this IP is based on the aggregate performance of all the senders who use it.
+
+### POST /ips/pools/{pool_name}/ips
+
+
+```php
+$request_body = json_decode('{
+ "ip": "0.0.0.0"
+}');
+$pool_name = "test_url_param";
+$response = $sg->client->ips()->pools()->_($pool_name)->ips()->post($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Remove an IP address from a pool.
+
+**This endpoint allows you to remove an IP address from an IP pool.**
+
+The same IP address can be added to multiple IP pools.
+
+A single IP address or a range of IP addresses may be dedicated to an account in order to send email for multiple domains. The reputation of this IP is based on the aggregate performance of all the senders who use it.
+
+### DELETE /ips/pools/{pool_name}/ips/{ip}
+
+
+```php
+$pool_name = "test_url_param";
+$ip = "test_url_param";
+$response = $sg->client->ips()->pools()->_($pool_name)->ips()->_($ip)->delete($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Add an IP to warmup
+
+**This endpoint allows you to enter an IP address into warmup mode.**
+
+SendGrid can automatically warm up dedicated IP addresses by limiting the amount of mail that can be sent through them per hour, with the limit determined by how long the IP address has been in warmup. See the [warmup schedule](https://sendgrid.com/docs/API_Reference/Web_API_v3/IP_Management/ip_warmup_schedule.html) for more details on how SendGrid limits your email traffic for IPs in warmup.
+
+For more general information about warming up IPs, please see our [Classroom](https://sendgrid.com/docs/Classroom/Deliver/Delivery_Introduction/warming_up_ips.html).
+
+### POST /ips/warmup
+
+
+```php
+$request_body = json_decode('{
+ "ip": "0.0.0.0"
+}');
+$response = $sg->client->ips()->warmup()->post($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Retrieve all IPs currently in warmup
+
+**This endpoint allows you to retrieve all of your IP addresses that are currently warming up.**
+
+SendGrid can automatically warm up dedicated IP addresses by limiting the amount of mail that can be sent through them per hour, with the limit determined by how long the IP address has been in warmup. See the [warmup schedule](https://sendgrid.com/docs/API_Reference/Web_API_v3/IP_Management/ip_warmup_schedule.html) for more details on how SendGrid limits your email traffic for IPs in warmup.
+
+For more general information about warming up IPs, please see our [Classroom](https://sendgrid.com/docs/Classroom/Deliver/Delivery_Introduction/warming_up_ips.html).
+
+### GET /ips/warmup
+
+
+```php
+$response = $sg->client->ips()->warmup()->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Retrieve warmup status for a specific IP address
+
+**This endpoint allows you to retrieve the warmup status for a specific IP address.**
+
+SendGrid can automatically warm up dedicated IP addresses by limiting the amount of mail that can be sent through them per hour, with the limit determined by how long the IP address has been in warmup. See the [warmup schedule](https://sendgrid.com/docs/API_Reference/Web_API_v3/IP_Management/ip_warmup_schedule.html) for more details on how SendGrid limits your email traffic for IPs in warmup.
+
+For more general information about warming up IPs, please see our [Classroom](https://sendgrid.com/docs/Classroom/Deliver/Delivery_Introduction/warming_up_ips.html).
+
+### GET /ips/warmup/{ip_address}
+
+
+```php
+$ip_address = "test_url_param";
+$response = $sg->client->ips()->warmup()->_($ip_address)->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Remove an IP from warmup
+
+**This endpoint allows you to remove an IP address from warmup mode.**
+
+SendGrid can automatically warm up dedicated IP addresses by limiting the amount of mail that can be sent through them per hour, with the limit determined by how long the IP address has been in warmup. See the [warmup schedule](https://sendgrid.com/docs/API_Reference/Web_API_v3/IP_Management/ip_warmup_schedule.html) for more details on how SendGrid limits your email traffic for IPs in warmup.
+
+For more general information about warming up IPs, please see our [Classroom](https://sendgrid.com/docs/Classroom/Deliver/Delivery_Introduction/warming_up_ips.html).
+
+### DELETE /ips/warmup/{ip_address}
+
+
+```php
+$ip_address = "test_url_param";
+$response = $sg->client->ips()->warmup()->_($ip_address)->delete($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Retrieve all IP pools an IP address belongs to
+
+**This endpoint allows you to see which IP pools a particular IP address has been added to.**
+
+The same IP address can be added to multiple IP pools.
+
+A single IP address or a range of IP addresses may be dedicated to an account in order to send email for multiple domains. The reputation of this IP is based on the aggregate performance of all the senders who use it.
+
+### GET /ips/{ip_address}
+
+
+```php
+$ip_address = "test_url_param";
+$response = $sg->client->ips()->_($ip_address)->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+<a name="mail"></a>
+# MAIL
+
+## Create a batch ID
+
+**This endpoint allows you to generate a new batch ID. This batch ID can be associated with scheduled sends via the mail/send endpoint.**
+
+If you set the SMTPAPI header `batch_id`, it allows you to then associate multiple scheduled mail/send requests together with the same ID. Then at anytime up to 10 minutes before the schedule date, you can cancel all of the mail/send requests that have this batch ID by calling the Cancel Scheduled Send endpoint.
+
+More Information:
+
+* [Scheduling Parameters > Batch ID](https://sendgrid.com/docs/API_Reference/SMTP_API/scheduling_parameters.html)
+
+### POST /mail/batch
+
+
+```php
+$request_body = json_decode('null');
+$response = $sg->client->mail()->batch()->post($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Validate batch ID
+
+**This endpoint allows you to validate a batch ID.**
+
+If you set the SMTPAPI header `batch_id`, it allows you to then associate multiple scheduled mail/send requests together with the same ID. Then at anytime up to 10 minutes before the schedule date, you can cancel all of the mail/send requests that have this batch ID by calling the Cancel Scheduled Send endpoint.
+
+More Information:
+
+* [Scheduling Parameters > Batch ID](https://sendgrid.com/docs/API_Reference/SMTP_API/scheduling_parameters.html)
+
+### GET /mail/batch/{batch_id}
+
+
+```php
+$batch_id = "test_url_param";
+$response = $sg->client->mail()->batch()->_($batch_id)->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## v3 Mail Send
+
+This endpoint allows you to send email over SendGrids v3 Web API, the most recent version of our API. If you are looking for documentation about the v2 Mail Send endpoint, please see our [v2 API Reference](https://sendgrid.com/docs/API_Reference/Web_API/mail.html).
+
+* Top level parameters are referred to as "global".
+* Individual fields within the personalizations array will override any other global, or message level, parameters that are defined outside of personalizations.
+
+For an overview of the v3 Mail Send endpoint, please visit our [v3 API Reference](https://sendgrid.com/docs/API_Reference/Web_API_v3/Mail/index.html)
+
+For more detailed information about how to use the v3 Mail Send endpoint, please visit our [Classroom](https://sendgrid.com/docs/Classroom/Send/v3_Mail_Send/index.html).
+
+### POST /mail/send
+
+This endpoint has a helper, check it out [here](https://github.com/sendgrid/sendgrid-php/blob/master/lib/helpers/mail/README.md).
+
+```php
+$request_body = json_decode('{
+ "asm": {
+ "group_id": 1,
+ "groups_to_display": [
+ 1,
+ 2,
+ 3
+ ]
+ },
+ "attachments": [
+ {
+ "content": "[BASE64 encoded content block here]",
+ "content_id": "ii_139db99fdb5c3704",
+ "disposition": "inline",
+ "filename": "file1.jpg",
+ "name": "file1",
+ "type": "jpg"
+ }
+ ],
+ "batch_id": "[YOUR BATCH ID GOES HERE]",
+ "categories": [
+ "category1",
+ "category2"
+ ],
+ "content": [
+ {
+ "type": "text/html",
+ "value": "<html><p>Hello, world!</p><img src=[CID GOES HERE]></img></html>"
+ }
+ ],
+ "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"
+ },
+ "headers": {},
+ "ip_pool_name": "[YOUR POOL NAME GOES HERE]",
+ "mail_settings": {
+ "bcc": {
+ "email": "ben.doe@example.com",
+ "enable": true
+ },
+ "bypass_list_management": {
+ "enable": true
+ },
+ "footer": {
+ "enable": true,
+ "html": "<p>Thanks</br>The SendGrid Team</p>",
+ "text": "Thanks,/n The SendGrid Team"
+ },
+ "sandbox_mode": {
+ "enable": false
+ },
+ "spam_check": {
+ "enable": true,
+ "post_to_url": "http://example.com/compliance",
+ "threshold": 3
+ }
+ },
+ "personalizations": [
+ {
+ "bcc": [
+ {
+ "email": "sam.doe@example.com",
+ "name": "Sam Doe"
+ }
+ ],
+ "cc": [
+ {
+ "email": "jane.doe@example.com",
+ "name": "Jane 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,
+ "subject": "Hello, World!",
+ "substitutions": {
+ "sub": {
+ "%name%": [
+ "John",
+ "Jane",
+ "Sam"
+ ]
+ }
+ },
+ "to": [
+ {
+ "email": "john.doe@example.com",
+ "name": "John Doe"
+ }
+ ]
+ }
+ ],
+ "reply_to": {
+ "email": "sam.smith@example.com",
+ "name": "Sam Smith"
+ },
+ "sections": {
+ "section": {
+ ":sectionName1": "section 1 text",
+ ":sectionName2": "section 2 text"
+ }
+ },
+ "send_at": 1409348513,
+ "subject": "Hello, World!",
+ "template_id": "[YOUR TEMPLATE ID GOES HERE]",
+ "tracking_settings": {
+ "click_tracking": {
+ "enable": true,
+ "enable_text": true
+ },
+ "ganalytics": {
+ "enable": true,
+ "utm_campaign": "[NAME OF YOUR REFERRER SOURCE]",
+ "utm_content": "[USE THIS SPACE TO DIFFERENTIATE YOUR EMAIL FROM ADS]",
+ "utm_medium": "[NAME OF YOUR MARKETING MEDIUM e.g. email]",
+ "utm_name": "[NAME OF YOUR CAMPAIGN]",
+ "utm_term": "[IDENTIFY PAID KEYWORDS HERE]"
+ },
+ "open_tracking": {
+ "enable": true,
+ "substitution_tag": "%opentrack"
+ },
+ "subscription_tracking": {
+ "enable": true,
+ "html": "If you would like to unsubscribe and stop receiving these emails <% clickhere %>.",
+ "substitution_tag": "<%click here%>",
+ "text": "If you would like to unsubscribe and stop receiveing these emails <% click here %>."
+ }
+ }
+}');
+$response = $sg->client->mail()->send()->post($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+<a name="mail_settings"></a>
+# MAIL SETTINGS
+
+## Retrieve all mail settings
+
+**This endpoint allows you to retrieve a list of all mail settings.**
+
+Mail settings allow you to tell SendGrid specific things to do to every email that you send to your recipients over SendGrids [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html).
+
+### GET /mail_settings
+
+
+```php
+$query_params = json_decode('{"limit": 1, "offset": 1}');
+$response = $sg->client->mail_settings()->get(null, $query_params);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Update address whitelist mail settings
+
+**This endpoint allows you to update your current email address whitelist settings.**
+
+The address whitelist setting whitelists a specified email address or domain for which mail should never be suppressed. For example, you own the domain example.com, and one or more of your recipients use email@example.com addresses, by placing example.com in the address whitelist setting, all bounces, blocks, and unsubscribes logged for that domain will be ignored and sent as if under normal sending conditions.
+
+Mail settings allow you to tell SendGrid specific things to do to every email that you send to your recipients over SendGrids [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html).
+
+### PATCH /mail_settings/address_whitelist
+
+
+```php
+$request_body = json_decode('{
+ "enabled": true,
+ "list": [
+ "email1@example.com",
+ "example.com"
+ ]
+}');
+$response = $sg->client->mail_settings()->address_whitelist()->patch($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Retrieve address whitelist mail settings
+
+**This endpoint allows you to retrieve your current email address whitelist settings.**
+
+The address whitelist setting whitelists a specified email address or domain for which mail should never be suppressed. For example, you own the domain example.com, and one or more of your recipients use email@example.com addresses, by placing example.com in the address whitelist setting, all bounces, blocks, and unsubscribes logged for that domain will be ignored and sent as if under normal sending conditions.
+
+Mail settings allow you to tell SendGrid specific things to do to every email that you send to your recipients over SendGrids [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html).
+
+### GET /mail_settings/address_whitelist
+
+
+```php
+$response = $sg->client->mail_settings()->address_whitelist()->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Update BCC mail settings
+
+**This endpoint allows you to update your current BCC mail settings.**
+
+When the BCC mail setting is enabled, SendGrid will automatically send a blind carbon copy (BCC) to an address for every email sent without adding that address to the header. Please note that only one email address may be entered in this field, if you wish to distribute BCCs to multiple addresses you will need to create a distribution group or use forwarding rules.
+
+Mail settings allow you to tell SendGrid specific things to do to every email that you send to your recipients over SendGrids [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html).
+
+### PATCH /mail_settings/bcc
+
+
+```php
+$request_body = json_decode('{
+ "email": "email@example.com",
+ "enabled": false
+}');
+$response = $sg->client->mail_settings()->bcc()->patch($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Retrieve all BCC mail settings
+
+**This endpoint allows you to retrieve your current BCC mail settings.**
+
+When the BCC mail setting is enabled, SendGrid will automatically send a blind carbon copy (BCC) to an address for every email sent without adding that address to the header. Please note that only one email address may be entered in this field, if you wish to distribute BCCs to multiple addresses you will need to create a distribution group or use forwarding rules.
+
+Mail settings allow you to tell SendGrid specific things to do to every email that you send to your recipients over SendGrids [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html).
+
+### GET /mail_settings/bcc
+
+
+```php
+$response = $sg->client->mail_settings()->bcc()->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Update bounce purge mail settings
+
+**This endpoint allows you to update your current bounce purge settings.**
+
+This setting allows you to set a schedule for SendGrid to automatically delete contacts from your soft and hard bounce suppression lists.
+
+Mail settings allow you to tell SendGrid specific things to do to every email that you send to your recipients over SendGrids [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html).
+
+### PATCH /mail_settings/bounce_purge
+
+
+```php
+$request_body = json_decode('{
+ "enabled": true,
+ "hard_bounces": 5,
+ "soft_bounces": 5
+}');
+$response = $sg->client->mail_settings()->bounce_purge()->patch($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Retrieve bounce purge mail settings
+
+**This endpoint allows you to retrieve your current bounce purge settings.**
+
+This setting allows you to set a schedule for SendGrid to automatically delete contacts from your soft and hard bounce suppression lists.
+
+Mail settings allow you to tell SendGrid specific things to do to every email that you send to your recipients over SendGrids [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html).
+
+### GET /mail_settings/bounce_purge
+
+
+```php
+$response = $sg->client->mail_settings()->bounce_purge()->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Update footer mail settings
+
+**This endpoint allows you to update your current Footer mail settings.**
+
+The footer setting will insert a custom footer at the bottom of the text and HTML bodies. Use the embedded HTML editor and plain text entry fields to create the content of the footers to be inserted into your emails.
+
+Mail settings allow you to tell SendGrid specific things to do to every email that you send to your recipients over SendGrids [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html).
+
+### PATCH /mail_settings/footer
+
+
+```php
+$request_body = json_decode('{
+ "enabled": true,
+ "html_content": "...",
+ "plain_content": "..."
+}');
+$response = $sg->client->mail_settings()->footer()->patch($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Retrieve footer mail settings
+
+**This endpoint allows you to retrieve your current Footer mail settings.**
+
+The footer setting will insert a custom footer at the bottom of the text and HTML bodies. Use the embedded HTML editor and plain text entry fields to create the content of the footers to be inserted into your emails.
+
+Mail settings allow you to tell SendGrid specific things to do to every email that you send to your recipients over SendGrids [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html).
+
+### GET /mail_settings/footer
+
+
+```php
+$response = $sg->client->mail_settings()->footer()->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Update forward bounce mail settings
+
+**This endpoint allows you to update your current bounce forwarding mail settings.**
+
+Activating this setting allows you to specify an email address to which bounce reports are forwarded.
+
+Mail settings allow you to tell SendGrid specific things to do to every email that you send to your recipients over SendGrids [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html).
+
+### PATCH /mail_settings/forward_bounce
+
+
+```php
+$request_body = json_decode('{
+ "email": "example@example.com",
+ "enabled": true
+}');
+$response = $sg->client->mail_settings()->forward_bounce()->patch($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Retrieve forward bounce mail settings
+
+**This endpoint allows you to retrieve your current bounce forwarding mail settings.**
+
+Activating this setting allows you to specify an email address to which bounce reports are forwarded.
+
+Mail settings allow you to tell SendGrid specific things to do to every email that you send to your recipients over SendGrids [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html).
+
+### GET /mail_settings/forward_bounce
+
+
+```php
+$response = $sg->client->mail_settings()->forward_bounce()->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Update forward spam mail settings
+
+**This endpoint allows you to update your current Forward Spam mail settings.**
+
+Enabling the forward spam setting allows you to specify an email address to which spam reports will be forwarded.
+
+Mail settings allow you to tell SendGrid specific things to do to every email that you send to your recipients over SendGrids [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html).
+
+### PATCH /mail_settings/forward_spam
+
+
+```php
+$request_body = json_decode('{
+ "email": "",
+ "enabled": false
+}');
+$response = $sg->client->mail_settings()->forward_spam()->patch($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Retrieve forward spam mail settings
+
+**This endpoint allows you to retrieve your current Forward Spam mail settings.**
+
+Enabling the forward spam setting allows you to specify an email address to which spam reports will be forwarded.
+
+Mail settings allow you to tell SendGrid specific things to do to every email that you send to your recipients over SendGrids [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html).
+
+### GET /mail_settings/forward_spam
+
+
+```php
+$response = $sg->client->mail_settings()->forward_spam()->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Update plain content mail settings
+
+**This endpoint allows you to update your current Plain Content mail settings.**
+
+The plain content setting will automatically convert any plain text emails that you send to HTML before sending.
+
+Mail settings allow you to tell SendGrid specific things to do to every email that you send to your recipients over SendGrids [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html).
+
+### PATCH /mail_settings/plain_content
+
+
+```php
+$request_body = json_decode('{
+ "enabled": false
+}');
+$response = $sg->client->mail_settings()->plain_content()->patch($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Retrieve plain content mail settings
+
+**This endpoint allows you to retrieve your current Plain Content mail settings.**
+
+The plain content setting will automatically convert any plain text emails that you send to HTML before sending.
+
+Mail settings allow you to tell SendGrid specific things to do to every email that you send to your recipients over SendGrids [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html).
+
+### GET /mail_settings/plain_content
+
+
+```php
+$response = $sg->client->mail_settings()->plain_content()->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Update spam check mail settings
+
+**This endpoint allows you to update your current spam checker mail settings.**
+
+The spam checker filter notifies you when emails are detected that exceed a predefined spam threshold.
+
+Mail settings allow you to tell SendGrid specific things to do to every email that you send to your recipients over SendGrids [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html).
+
+### PATCH /mail_settings/spam_check
+
+
+```php
+$request_body = json_decode('{
+ "enabled": true,
+ "max_score": 5,
+ "url": "url"
+}');
+$response = $sg->client->mail_settings()->spam_check()->patch($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Retrieve spam check mail settings
+
+**This endpoint allows you to retrieve your current Spam Checker mail settings.**
+
+The spam checker filter notifies you when emails are detected that exceed a predefined spam threshold.
+
+Mail settings allow you to tell SendGrid specific things to do to every email that you send to your recipients over SendGrids [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html).
+
+### GET /mail_settings/spam_check
+
+
+```php
+$response = $sg->client->mail_settings()->spam_check()->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Update template mail settings
+
+**This endpoint allows you to update your current legacy email template settings.**
+
+This setting refers to our original email templates. We currently support more fully featured [transactional templates](https://sendgrid.com/docs/User_Guide/Transactional_Templates/index.html).
+
+The legacy email template setting wraps an HTML template around your email content. This can be useful for sending out marketing email and/or other HTML formatted messages.
+
+Mail settings allow you to tell SendGrid specific things to do to every email that you send to your recipients over SendGrids [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html).
+
+### PATCH /mail_settings/template
+
+
+```php
+$request_body = json_decode('{
+ "enabled": true,
+ "html_content": "<% body %>"
+}');
+$response = $sg->client->mail_settings()->template()->patch($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Retrieve legacy template mail settings
+
+**This endpoint allows you to retrieve your current legacy email template settings.**
+
+This setting refers to our original email templates. We currently support more fully featured [transactional templates](https://sendgrid.com/docs/User_Guide/Transactional_Templates/index.html).
+
+The legacy email template setting wraps an HTML template around your email content. This can be useful for sending out marketing email and/or other HTML formatted messages.
+
+Mail settings allow you to tell SendGrid specific things to do to every email that you send to your recipients over SendGrids [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html).
+
+### GET /mail_settings/template
+
+
+```php
+$response = $sg->client->mail_settings()->template()->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+<a name="mailbox_providers"></a>
+# MAILBOX PROVIDERS
+
+## Retrieve email statistics by mailbox provider.
+
+**This endpoint allows you to retrieve your email statistics segmented by recipient mailbox provider.**
+
+**We only store up to 7 days of email activity in our database.** By default, 500 items will be returned per request via the Advanced Stats API endpoints.
+
+Advanced Stats provide a more in-depth view of your email statistics and the actions taken by your recipients. You can segment these statistics by geographic location, device type, client type, browser, and mailbox provider. For more information about statistics, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Statistics/index.html).
+
+### GET /mailbox_providers/stats
+
+
+```php
+$query_params = json_decode('{"end_date": "2016-04-01", "mailbox_providers": "test_string", "aggregated_by": "day", "limit": 1, "offset": 1, "start_date": "2016-01-01"}');
+$response = $sg->client->mailbox_providers()->stats()->get(null, $query_params);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+<a name="partner_settings"></a>
+# PARTNER SETTINGS
+
+## Returns a list of all partner settings.
+
+**This endpoint allows you to retrieve a list of all partner settings that you can enable.**
+
+Our partner settings allow you to integrate your SendGrid account with our partners to increase your SendGrid experience and functionality. For more information about our partners, and how you can begin integrating with them, please visit our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/partners.html).
+
+### GET /partner_settings
+
+
+```php
+$query_params = json_decode('{"limit": 1, "offset": 1}');
+$response = $sg->client->partner_settings()->get(null, $query_params);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Updates New Relic partner settings.
+
+**This endpoint allows you to update or change your New Relic partner settings.**
+
+Our partner settings allow you to integrate your SendGrid account with our partners to increase your SendGrid experience and functionality. For more information about our partners, and how you can begin integrating with them, please visit our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/partners.html).
+
+By integrating with New Relic, you can send your SendGrid email statistics to your New Relic Dashboard. If you enable this setting, your stats will be sent to New Relic every 5 minutes. You will need your New Relic License Key to enable this setting. For more information, please see our [Classroom](https://sendgrid.com/docs/Classroom/Track/Collecting_Data/new_relic.html).
+
+### PATCH /partner_settings/new_relic
+
+
+```php
+$request_body = json_decode('{
+ "enable_subuser_statistics": true,
+ "enabled": true,
+ "license_key": ""
+}');
+$response = $sg->client->partner_settings()->new_relic()->patch($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Returns all New Relic partner settings.
+
+**This endpoint allows you to retrieve your current New Relic partner settings.**
+
+Our partner settings allow you to integrate your SendGrid account with our partners to increase your SendGrid experience and functionality. For more information about our partners, and how you can begin integrating with them, please visit our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/partners.html).
+
+By integrating with New Relic, you can send your SendGrid email statistics to your New Relic Dashboard. If you enable this setting, your stats will be sent to New Relic every 5 minutes. You will need your New Relic License Key to enable this setting. For more information, please see our [Classroom](https://sendgrid.com/docs/Classroom/Track/Collecting_Data/new_relic.html).
+
+### GET /partner_settings/new_relic
+
+
+```php
+$response = $sg->client->partner_settings()->new_relic()->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+<a name="scopes"></a>
+# SCOPES
+
+## Retrieve a list of scopes for which this user has access.
+
+**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).
+
+### GET /scopes
+
+
+```php
+$response = $sg->client->scopes()->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+<a name="stats"></a>
+# STATS
+
+## Retrieve global email statistics
+
+**This endpoint allows you to retrieve all of your global email statistics between a given date range.**
+
+Parent accounts will see aggregated stats for their account and all subuser accounts. Subuser accounts will only see their own stats.
+
+### GET /stats
+
+
+```php
+$query_params = json_decode('{"aggregated_by": "day", "limit": 1, "start_date": "2016-01-01", "end_date": "2016-04-01", "offset": 1}');
+$response = $sg->client->stats()->get(null, $query_params);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+<a name="subusers"></a>
+# SUBUSERS
+
+## Create Subuser
+
+This endpoint allows you to retrieve a list of all of your subusers. You can choose to retrieve specific subusers as well as limit the results that come back from the API.
+
+For more information about Subusers:
+
+* [User Guide > Subusers](https://sendgrid.com/docs/User_Guide/Settings/Subusers/index.html)
+* [Classroom > How do I add more subusers to my account?](https://sendgrid.com/docs/Classroom/Basics/Account/how_do_i_add_more_subusers_to_my_account.html)
+
+### POST /subusers
+
+
+```php
+$request_body = json_decode('{
+ "email": "John@example.com",
+ "ips": [
+ "1.1.1.1",
+ "2.2.2.2"
+ ],
+ "password": "johns_password",
+ "username": "John@example.com"
+}');
+$response = $sg->client->subusers()->post($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## List all Subusers
+
+This endpoint allows you to retrieve a list of all of your subusers. You can choose to retrieve specific subusers as well as limit the results that come back from the API.
+
+For more information about Subusers:
+
+* [User Guide > Subusers](https://sendgrid.com/docs/User_Guide/Settings/Subusers/index.html)
+* [Classroom > How do I add more subusers to my account?](https://sendgrid.com/docs/Classroom/Basics/Account/how_do_i_add_more_subusers_to_my_account.html)
+
+### GET /subusers
+
+
+```php
+$query_params = json_decode('{"username": "test_string", "limit": 0, "offset": 0}');
+$response = $sg->client->subusers()->get(null, $query_params);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Retrieve Subuser Reputations
+
+Subuser sender reputations give a good idea how well a sender is doing with regards to how recipients and recipient servers react to the mail that is being received. When a bounce, spam report, or other negative action happens on a sent email, it will effect your sender rating.
+
+This endpoint allows you to request the reputations for your subusers.
+
+### GET /subusers/reputations
+
+
+```php
+$query_params = json_decode('{"usernames": "test_string"}');
+$response = $sg->client->subusers()->reputations()->get(null, $query_params);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Retrieve email statistics for your subusers.
+
+**This endpoint allows you to retrieve the email statistics for the given subusers.**
+
+You may retrieve statistics for up to 10 different subusers by including an additional _subusers_ parameter for each additional 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. Emails sent, bounces, and spam reports are always tracked for subusers. Unsubscribes, clicks, and opens are tracked if you have enabled the required settings.
+
+For more information, see our [User Guide](https://sendgrid.com/docs/User_Guide/Statistics/subuser.html).
+
+### GET /subusers/stats
+
+
+```php
+$query_params = json_decode('{"end_date": "2016-04-01", "aggregated_by": "day", "limit": 1, "offset": 1, "start_date": "2016-01-01", "subusers": "test_string"}');
+$response = $sg->client->subusers()->stats()->get(null, $query_params);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Retrieve monthly stats for all subusers
+
+**This endpoint allows you to retrieve the monthly email statistics for all subusers over the given date range.**
+
+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.
+
+When using the `sort_by_metric` to sort your stats by a specific metric, you can not sort by the following metrics:
+`bounce_drops`, `deferred`, `invalid_emails`, `processed`, `spam_report_drops`, `spam_reports`, or `unsubscribe_drops`.
+
+For more information, see our [User Guide](https://sendgrid.com/docs/User_Guide/Statistics/subuser.html).
+
+### GET /subusers/stats/monthly
+
+
+```php
+$query_params = json_decode('{"subuser": "test_string", "limit": 1, "sort_by_metric": "test_string", "offset": 1, "date": "test_string", "sort_by_direction": "asc"}');
+$response = $sg->client->subusers()->stats()->monthly()->get(null, $query_params);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Retrieve the totals for each email statistic metric for all subusers.
+
+**This endpoint allows you to retrieve the total sums of each email statistic metric for all subusers over the given date range.**
+
+
+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. Emails sent, bounces, and spam reports are always tracked for subusers. Unsubscribes, clicks, and opens are tracked if you have enabled the required settings.
+
+For more information, see our [User Guide](https://sendgrid.com/docs/User_Guide/Statistics/subuser.html).
+
+### GET /subusers/stats/sums
+
+
+```php
+$query_params = json_decode('{"end_date": "2016-04-01", "aggregated_by": "day", "limit": 1, "sort_by_metric": "test_string", "offset": 1, "start_date": "2016-01-01", "sort_by_direction": "asc"}');
+$response = $sg->client->subusers()->stats()->sums()->get(null, $query_params);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Enable/disable a subuser
+
+This endpoint allows you to enable or disable a subuser.
+
+For more information about Subusers:
+
+* [User Guide > Subusers](https://sendgrid.com/docs/User_Guide/Settings/Subusers/index.html)
+* [Classroom > How do I add more subusers to my account?](https://sendgrid.com/docs/Classroom/Basics/Account/how_do_i_add_more_subusers_to_my_account.html)
+
+### PATCH /subusers/{subuser_name}
+
+
+```php
+$request_body = json_decode('{
+ "disabled": false
+}');
+$subuser_name = "test_url_param";
+$response = $sg->client->subusers()->_($subuser_name)->patch($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Delete a subuser
+
+This endpoint allows you to delete a subuser. This is a permanent action, once deleted a subuser cannot be retrieved.
+
+For more information about Subusers:
+
+* [User Guide > Subusers](https://sendgrid.com/docs/User_Guide/Settings/Subusers/index.html)
+* [Classroom > How do I add more subusers to my account?](https://sendgrid.com/docs/Classroom/Basics/Account/how_do_i_add_more_subusers_to_my_account.html)
+
+### DELETE /subusers/{subuser_name}
+
+
+```php
+$subuser_name = "test_url_param";
+$response = $sg->client->subusers()->_($subuser_name)->delete($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Update IPs assigned to a subuser
+
+Each subuser should be assigned to an IP address, from which all of this subuser's mail will be sent. Often, this is the same IP as the parent account, but each subuser can have their own, or multiple, IP addresses as well.
+
+More information:
+
+* [How to request more IPs](https://sendgrid.com/docs/Classroom/Basics/Account/adding_an_additional_dedicated_ip_to_your_account.html)
+* [IPs can be whitelabeled](https://sendgrid.com/docs/User_Guide/Settings/Whitelabel/ips.html)
+
+### PUT /subusers/{subuser_name}/ips
+
+
+```php
+$request_body = json_decode('[
+ "127.0.0.1"
+]');
+$subuser_name = "test_url_param";
+$response = $sg->client->subusers()->_($subuser_name)->ips()->put($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Update Monitor Settings for a subuser
+
+Subuser monitor settings allow you to receive a sample of an outgoing message by a specific customer at a specific frequency of emails.
+
+### PUT /subusers/{subuser_name}/monitor
+
+
+```php
+$request_body = json_decode('{
+ "email": "example@example.com",
+ "frequency": 500
+}');
+$subuser_name = "test_url_param";
+$response = $sg->client->subusers()->_($subuser_name)->monitor()->put($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Create monitor settings
+
+Subuser monitor settings allow you to receive a sample of an outgoing message by a specific customer at a specific frequency of emails.
+
+### POST /subusers/{subuser_name}/monitor
+
+
+```php
+$request_body = json_decode('{
+ "email": "example@example.com",
+ "frequency": 50000
+}');
+$subuser_name = "test_url_param";
+$response = $sg->client->subusers()->_($subuser_name)->monitor()->post($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Retrieve monitor settings for a subuser
+
+Subuser monitor settings allow you to receive a sample of an outgoing message by a specific customer at a specific frequency of emails.
+
+### GET /subusers/{subuser_name}/monitor
+
+
+```php
+$subuser_name = "test_url_param";
+$response = $sg->client->subusers()->_($subuser_name)->monitor()->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Delete monitor settings
+
+Subuser monitor settings allow you to receive a sample of an outgoing message by a specific customer at a specific frequency of emails.
+
+### DELETE /subusers/{subuser_name}/monitor
+
+
+```php
+$subuser_name = "test_url_param";
+$response = $sg->client->subusers()->_($subuser_name)->monitor()->delete($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Retrieve the monthly email statistics for a single subuser
+
+**This endpoint allows you to retrive 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.
+
+When using the `sort_by_metric` to sort your stats by a specific metric, you can not sort by the following metrics:
+`bounce_drops`, `deferred`, `invalid_emails`, `processed`, `spam_report_drops`, `spam_reports`, or `unsubscribe_drops`.
+
+For more information, see our [User Guide](https://sendgrid.com/docs/User_Guide/Statistics/subuser.html).
+
+### GET /subusers/{subuser_name}/stats/monthly
+
+
+```php
+$query_params = json_decode('{"date": "test_string", "sort_by_direction": "asc", "limit": 0, "sort_by_metric": "test_string", "offset": 1}');
+$subuser_name = "test_url_param";
+$response = $sg->client->subusers()->_($subuser_name)->stats()->monthly()->get(null, $query_params);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+<a name="suppression"></a>
+# SUPPRESSION
+
+## Retrieve all blocks
+
+**This endpoint allows you to retrieve a list of all email addresses that are currently on your blocks list.**
+
+[Blocks](https://sendgrid.com/docs/Glossary/blocks.html) happen when your message was rejected for a reason related to the message, not the recipient address. This can happen when your mail server IP address has been added to a blacklist or blocked by an ISP, or if the message content is flagged by a filter on the receiving server.
+
+For more information, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Suppressions/blocks.html).
+
+### GET /suppression/blocks
+
+
+```php
+$query_params = json_decode('{"start_time": 1, "limit": 1, "end_time": 1, "offset": 1}');
+$response = $sg->client->suppression()->blocks()->get(null, $query_params);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Delete blocks
+
+**This endpoint allows you to delete all email addresses on your blocks list.**
+
+There are two options for deleting blocked emails:
+
+1. You can delete all blocked emails by setting `delete_all` to true in the request body.
+2. You can delete some blocked emails by specifying the email addresses in an array in the request body.
+
+[Blocks](https://sendgrid.com/docs/Glossary/blocks.html) happen when your message was rejected for a reason related to the message, not the recipient address. This can happen when your mail server IP address has been added to a blacklist or blocked by an ISP, or if the message content is flagged by a filter on the receiving server.
+
+For more information, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Suppressions/blocks.html).
+
+### DELETE /suppression/blocks
+
+
+```php
+$response = $sg->client->suppression()->blocks()->delete($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Retrieve a specific block
+
+**This endpoint allows you to retrieve a specific email address from your blocks list.**
+
+[Blocks](https://sendgrid.com/docs/Glossary/blocks.html) happen when your message was rejected for a reason related to the message, not the recipient address. This can happen when your mail server IP address has been added to a blacklist or blocked by an ISP, or if the message content is flagged by a filter on the receiving server.
+
+For more information, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Suppressions/blocks.html).
+
+### GET /suppression/blocks/{email}
+
+
+```php
+$email = "test_url_param";
+$response = $sg->client->suppression()->blocks()->_($email)->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Delete a specific block
+
+**This endpoint allows you to delete a specific email address from your blocks list.**
+
+[Blocks](https://sendgrid.com/docs/Glossary/blocks.html) happen when your message was rejected for a reason related to the message, not the recipient address. This can happen when your mail server IP address has been added to a blacklist or blocked by an ISP, or if the message content is flagged by a filter on the receiving server.
+
+For more information, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Suppressions/blocks.html).
+
+### DELETE /suppression/blocks/{email}
+
+
+```php
+$email = "test_url_param";
+$response = $sg->client->suppression()->blocks()->_($email)->delete($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Retrieve all bounces
+
+**This endpoint allows you to retrieve all of your bounces.**
+
+Bounces are messages that are returned to the server that sent it.
+
+For more information see:
+
+* [User Guide > Bounces](https://sendgrid.com/docs/User_Guide/Suppressions/bounces.html) for more information
+* [Glossary > Bounces](https://sendgrid.com/docs/Glossary/Bounces.html)
+
+### GET /suppression/bounces
+
+
+```php
+$query_params = json_decode('{"start_time": 0, "end_time": 0}');
+$response = $sg->client->suppression()->bounces()->get(null, $query_params);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Delete bounces
+
+**This endpoint allows you to delete all of your bounces. You can also use this endpoint to remove a specific email address from your bounce list.**
+
+Bounces are messages that are returned to the server that sent it.
+
+For more information see:
+
+* [User Guide > Bounces](https://sendgrid.com/docs/User_Guide/Suppressions/bounces.html) for more information
+* [Glossary > Bounces](https://sendgrid.com/docs/Glossary/Bounces.html)
+* [Classroom > List Scrubbing Guide](https://sendgrid.com/docs/Classroom/Deliver/list_scrubbing.html)
+
+Note: the `delete_all` and `emails` parameters should be used independently of each other as they have different purposes.
+
+### DELETE /suppression/bounces
+
+
+```php
+$response = $sg->client->suppression()->bounces()->delete($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Retrieve a Bounce
+
+**This endpoint allows you to retrieve a specific bounce for a given email address.**
+
+Bounces are messages that are returned to the server that sent it.
+
+For more information see:
+
+* [User Guide > Bounces](https://sendgrid.com/docs/User_Guide/Suppressions/bounces.html) for more information
+* [Glossary > Bounces](https://sendgrid.com/docs/Glossary/Bounces.html)
+* [Classroom > List Scrubbing Guide](https://sendgrid.com/docs/Classroom/Deliver/list_scrubbing.html)
+
+### GET /suppression/bounces/{email}
+
+
+```php
+$email = "test_url_param";
+$response = $sg->client->suppression()->bounces()->_($email)->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Delete a bounce
+
+**This endpoint allows you to remove an email address from your bounce list.**
+
+Bounces are messages that are returned to the server that sent it. This endpoint allows you to delete a single email addresses from your bounce list.
+
+For more information see:
+
+* [User Guide > Bounces](https://sendgrid.com/docs/User_Guide/Suppressions/bounces.html) for more information
+* [Glossary > Bounces](https://sendgrid.com/docs/Glossary/Bounces.html)
+* [Classroom > List Scrubbing Guide](https://sendgrid.com/docs/Classroom/Deliver/list_scrubbing.html)
+
+### DELETE /suppression/bounces/{email}
+
+
+```php
+$query_params = json_decode('{"email_address": "example@example.com"}');
+$email = "test_url_param";
+$response = $sg->client->suppression()->bounces()->_($email)->delete($request_body, $query_params);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Retrieve all invalid emails
+
+**This endpoint allows you to retrieve a list of all invalid email addresses.**
+
+An invalid email occurs when you attempt to send email to an address that is formatted in a manner that does not meet internet email format standards or the email does not exist at the recipients mail server.
+
+Examples include addresses without the @ sign or addresses that include certain special characters and/or spaces. This response can come from our own server or the recipient mail server.
+
+For more information, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Suppressions/invalid_emails.html).
+
+### GET /suppression/invalid_emails
+
+
+```php
+$query_params = json_decode('{"start_time": 1, "limit": 1, "end_time": 1, "offset": 1}');
+$response = $sg->client->suppression()->invalid_emails()->get(null, $query_params);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Delete invalid emails
+
+**This endpoint allows you to remove email addresses from your invalid email address list.**
+
+There are two options for deleting invalid email addresses:
+
+1) You can delete all invalid email addresses by setting `delete_all` to true in the request body.
+2) You can delete some invalid email addresses by specifying certain addresses in an array in the request body.
+
+An invalid email occurs when you attempt to send email to an address that is formatted in a manner that does not meet internet email format standards or the email does not exist at the recipients mail server.
+
+Examples include addresses without the @ sign or addresses that include certain special characters and/or spaces. This response can come from our own server or the recipient mail server.
+
+For more information, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Suppressions/invalid_emails.html).
+
+### DELETE /suppression/invalid_emails
+
+
+```php
+$response = $sg->client->suppression()->invalid_emails()->delete($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Retrieve a specific invalid email
+
+**This endpoint allows you to retrieve a specific invalid email addresses.**
+
+An invalid email occurs when you attempt to send email to an address that is formatted in a manner that does not meet internet email format standards or the email does not exist at the recipients mail server.
+
+Examples include addresses without the @ sign or addresses that include certain special characters and/or spaces. This response can come from our own server or the recipient mail server.
+
+For more information, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Suppressions/invalid_emails.html).
+
+### GET /suppression/invalid_emails/{email}
+
+
+```php
+$email = "test_url_param";
+$response = $sg->client->suppression()->invalid_emails()->_($email)->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Delete a specific invalid email
+
+**This endpoint allows you to remove a specific email address from the invalid email address list.**
+
+An invalid email occurs when you attempt to send email to an address that is formatted in a manner that does not meet internet email format standards or the email does not exist at the recipients mail server.
+
+Examples include addresses without the @ sign or addresses that include certain special characters and/or spaces. This response can come from our own server or the recipient mail server.
+
+For more information, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Suppressions/invalid_emails.html).
+
+### DELETE /suppression/invalid_emails/{email}
+
+
+```php
+$email = "test_url_param";
+$response = $sg->client->suppression()->invalid_emails()->_($email)->delete($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Retrieve a specific spam report
+
+**This endpoint allows you to retrieve a specific spam report.**
+
+[Spam reports](https://sendgrid.com/docs/Glossary/spam_reports.html) happen when a recipient indicates that they think your email is [spam](https://sendgrid.com/docs/Glossary/spam.html) and then their email provider reports this to SendGrid.
+
+For more information, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Suppressions/spam_reports.html).
+
+### GET /suppression/spam_report/{email}
+
+
+```php
+$email = "test_url_param";
+$response = $sg->client->suppression()->spam_report()->_($email)->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Delete a specific spam report
+
+**This endpoint allows you to delete a specific spam report.**
+
+[Spam reports](https://sendgrid.com/docs/Glossary/spam_reports.html) happen when a recipient indicates that they think your email is [spam](https://sendgrid.com/docs/Glossary/spam.html) and then their email provider reports this to SendGrid.
+
+For more information, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Suppressions/spam_reports.html).
+
+### DELETE /suppression/spam_report/{email}
+
+
+```php
+$email = "test_url_param";
+$response = $sg->client->suppression()->spam_report()->_($email)->delete($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Retrieve all spam reports
+
+**This endpoint allows you to retrieve all spam reports.**
+
+[Spam reports](https://sendgrid.com/docs/Glossary/spam_reports.html) happen when a recipient indicates that they think your email is [spam](https://sendgrid.com/docs/Glossary/spam.html) and then their email provider reports this to SendGrid.
+
+For more information, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Suppressions/spam_reports.html).
+
+### GET /suppression/spam_reports
+
+
+```php
+$query_params = json_decode('{"start_time": 1, "limit": 1, "end_time": 1, "offset": 1}');
+$response = $sg->client->suppression()->spam_reports()->get(null, $query_params);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Delete spam reports
+
+**This endpoint allows you to delete your spam reports.**
+
+There are two options for deleting spam reports:
+
+1) You can delete all spam reports by setting "delete_all" to true in the request body.
+2) You can delete some spam reports by specifying the email addresses in an array in the request body.
+
+[Spam reports](https://sendgrid.com/docs/Glossary/spam_reports.html) happen when a recipient indicates that they think your email is [spam](https://sendgrid.com/docs/Glossary/spam.html) and then their email provider reports this to SendGrid.
+
+For more information, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Suppressions/spam_reports.html).
+
+### DELETE /suppression/spam_reports
+
+
+```php
+$response = $sg->client->suppression()->spam_reports()->delete($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Retrieve all global suppressions
+
+**This endpoint allows you to retrieve a list of all email address that are globally suppressed.**
+
+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).
+
+### GET /suppression/unsubscribes
+
+
+```php
+$query_params = json_decode('{"start_time": 1, "limit": 1, "end_time": 1, "offset": 1}');
+$response = $sg->client->suppression()->unsubscribes()->get(null, $query_params);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+<a name="templates"></a>
+# TEMPLATES
+
+## Create a transactional template.
+
+**This endpoint allows you to create a transactional template.**
+
+Each user can create up to 300 different transactional templates. Transactional templates are specific to accounts and subusers. Templates created on a parent account will not be accessible from the subuser accounts.
+
+Transactional templates are templates created specifically for transactional email and are not to be confused with [Marketing Campaigns templates](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/templates.html). For more information about transactional templates, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Transactional_Templates/index.html).
+
+### POST /templates
+
+
+```php
+$request_body = json_decode('{
+ "name": "example_name"
+}');
+$response = $sg->client->templates()->post($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Retrieve all transactional templates.
+
+**This endpoint allows you to retrieve all transactional templates.**
+
+Each user can create up to 300 different transactional templates. Transactional templates are specific to accounts and subusers. Templates created on a parent account will not be accessible from the subuser accounts.
+
+Transactional templates are templates created specifically for transactional email and are not to be confused with [Marketing Campaigns templates](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/templates.html). For more information about transactional templates, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Transactional_Templates/index.html).
+
+### GET /templates
+
+
+```php
+$response = $sg->client->templates()->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Edit a transactional template.
+
+**This endpoint allows you to edit a transactional template.**
+
+Each user can create up to 300 different transactional templates. Transactional templates are specific to accounts and subusers. Templates created on a parent account will not be accessible from the subuser accounts.
+
+Transactional templates are templates created specifically for transactional email and are not to be confused with [Marketing Campaigns templates](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/templates.html). For more information about transactional templates, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Transactional_Templates/index.html).
+
+
+### PATCH /templates/{template_id}
+
+
+```php
+$request_body = json_decode('{
+ "name": "new_example_name"
+}');
+$template_id = "test_url_param";
+$response = $sg->client->templates()->_($template_id)->patch($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Retrieve a single transactional template.
+
+**This endpoint allows you to retrieve a single transactional template.**
+
+Each user can create up to 300 different transactional templates. Transactional templates are specific to accounts and subusers. Templates created on a parent account will not be accessible from the subuser accounts.
+
+Transactional templates are templates created specifically for transactional email and are not to be confused with [Marketing Campaigns templates](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/templates.html). For more information about transactional templates, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Transactional_Templates/index.html).
+
+
+### GET /templates/{template_id}
+
+
+```php
+$template_id = "test_url_param";
+$response = $sg->client->templates()->_($template_id)->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Delete a template.
+
+**This endpoint allows you to delete a transactional template.**
+
+Each user can create up to 300 different transactional templates. Transactional templates are specific to accounts and subusers. Templates created on a parent account will not be accessible from the subuser accounts.
+
+Transactional templates are templates created specifically for transactional email and are not to be confused with [Marketing Campaigns templates](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/templates.html). For more information about transactional templates, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Transactional_Templates/index.html).
+
+
+### DELETE /templates/{template_id}
+
+
+```php
+$template_id = "test_url_param";
+$response = $sg->client->templates()->_($template_id)->delete($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Create a new transactional template version.
+
+**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.
+
+For more information about transactional templates, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Transactional_Templates/index.html).
+
+
+### POST /templates/{template_id}/versions
+
+
+```php
+$request_body = json_decode('{
+ "active": 1,
+ "html_content": "<%body%>",
+ "name": "example_version_name",
+ "plain_content": "<%body%>",
+ "subject": "<%subject%>",
+ "template_id": "ddb96bbc-9b92-425e-8979-99464621b543"
+}');
+$template_id = "test_url_param";
+$response = $sg->client->templates()->_($template_id)->versions()->post($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Edit a transactional template version.
+
+**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.
+
+For more information about transactional templates, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Transactional_Templates/index.html).
+
+## URI Parameters
+| URI Parameter | Type | Description |
+|---|---|---|
+| template_id | string | The ID of the original template |
+| version_id | string | The ID of the template version |
+
+### PATCH /templates/{template_id}/versions/{version_id}
+
+
+```php
+$request_body = json_decode('{
+ "active": 1,
+ "html_content": "<%body%>",
+ "name": "updated_example_name",
+ "plain_content": "<%body%>",
+ "subject": "<%subject%>"
+}');
+$template_id = "test_url_param";
+$version_id = "test_url_param";
+$response = $sg->client->templates()->_($template_id)->versions()->_($version_id)->patch($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Retrieve a specific transactional template version.
+
+**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.
+
+For more information about transactional templates, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Transactional_Templates/index.html).
+
+## URI Parameters
+| URI Parameter | Type | Description |
+|---|---|---|
+| template_id | string | The ID of the original template |
+| version_id | string | The ID of the template version |
+
+### GET /templates/{template_id}/versions/{version_id}
+
+
+```php
+$template_id = "test_url_param";
+$version_id = "test_url_param";
+$response = $sg->client->templates()->_($template_id)->versions()->_($version_id)->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Delete a transactional template version.
+
+**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.
+
+For more information about transactional templates, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Transactional_Templates/index.html).
+
+## URI Parameters
+| URI Parameter | Type | Description |
+|---|---|---|
+| template_id | string | The ID of the original template |
+| version_id | string | The ID of the template version |
+
+### DELETE /templates/{template_id}/versions/{version_id}
+
+
+```php
+$template_id = "test_url_param";
+$version_id = "test_url_param";
+$response = $sg->client->templates()->_($template_id)->versions()->_($version_id)->delete($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Activate a transactional template version.
+
+**This endpoint allows you to activate a version of one of your 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.
+
+
+For more information about transactional templates, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Transactional_Templates/index.html).
+
+## URI Parameters
+| URI Parameter | Type | Description |
+|---|---|---|
+| template_id | string | The ID of the original template |
+| version_id | string | The ID of the template version |
+
+### POST /templates/{template_id}/versions/{version_id}/activate
+
+
+```php
+$request_body = json_decode('null');
+$template_id = "test_url_param";
+$version_id = "test_url_param";
+$response = $sg->client->templates()->_($template_id)->versions()->_($version_id)->activate()->post($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+<a name="tracking_settings"></a>
+# TRACKING SETTINGS
+
+## Retrieve Tracking Settings
+
+**This endpoint allows you to retrieve a list of all tracking settings that you can enable on your account.**
+
+You can track a variety of the actions your recipients may take when interacting with your emails including opening your emails, clicking on links in your emails, and subscribing to (or unsubscribing from) your emails.
+
+For more information about tracking, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/tracking.html).
+
+### GET /tracking_settings
+
+
+```php
+$query_params = json_decode('{"limit": 1, "offset": 1}');
+$response = $sg->client->tracking_settings()->get(null, $query_params);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Update Click Tracking Settings
+
+**This endpoint allows you to change your current click tracking setting. You can enable, or disable, click tracking using this endpoint.**
+
+You can track a variety of the actions your recipients may take when interacting with your emails including opening your emails, clicking on links in your emails, and subscribing to (or unsubscribing from) your emails.
+
+For more information about tracking, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/tracking.html).
+
+### PATCH /tracking_settings/click
+
+
+```php
+$request_body = json_decode('{
+ "enabled": true
+}');
+$response = $sg->client->tracking_settings()->click()->patch($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Retrieve Click Track Settings
+
+**This endpoint allows you to retrieve your current click tracking setting.**
+
+You can track a variety of the actions your recipients may take when interacting with your emails including opening your emails, clicking on links in your emails, and subscribing to (or unsubscribing from) your emails.
+
+For more information about tracking, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/tracking.html).
+
+### GET /tracking_settings/click
+
+
+```php
+$response = $sg->client->tracking_settings()->click()->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Update Google Analytics Settings
+
+**This endpoint allows you to update your current setting for Google Analytics.**
+
+For more information about using Google Analytics, please refer to [Googles URL Builder](https://support.google.com/analytics/answer/1033867?hl=en) and their article on ["Best Practices for Campaign Building"](https://support.google.com/analytics/answer/1037445).
+
+We default the settings to Googles recommendations. For more information, see [Google Analytics Demystified](https://sendgrid.com/docs/Classroom/Track/Collecting_Data/google_analytics_demystified_ga_statistics_vs_sg_statistics.html).
+
+You can track a variety of the actions your recipients may take when interacting with your emails including opening your emails, clicking on links in your emails, and subscribing to (or unsubscribing from) your emails.
+
+For more information about tracking, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/tracking.html).
+
+### PATCH /tracking_settings/google_analytics
+
+
+```php
+$request_body = json_decode('{
+ "enabled": true,
+ "utm_campaign": "website",
+ "utm_content": "",
+ "utm_medium": "email",
+ "utm_source": "sendgrid.com",
+ "utm_term": ""
+}');
+$response = $sg->client->tracking_settings()->google_analytics()->patch($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Retrieve Google Analytics Settings
+
+**This endpoint allows you to retrieve your current setting for Google Analytics.**
+
+For more information about using Google Analytics, please refer to [Googles URL Builder](https://support.google.com/analytics/answer/1033867?hl=en) and their article on ["Best Practices for Campaign Building"](https://support.google.com/analytics/answer/1037445).
+
+We default the settings to Googles recommendations. For more information, see [Google Analytics Demystified](https://sendgrid.com/docs/Classroom/Track/Collecting_Data/google_analytics_demystified_ga_statistics_vs_sg_statistics.html).
+
+You can track a variety of the actions your recipients may take when interacting with your emails including opening your emails, clicking on links in your emails, and subscribing to (or unsubscribing from) your emails.
+
+For more information about tracking, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/tracking.html).
+
+### GET /tracking_settings/google_analytics
+
+
+```php
+$response = $sg->client->tracking_settings()->google_analytics()->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Update Open Tracking Settings
+
+**This endpoint allows you to update your current settings for open tracking.**
+
+Open Tracking adds an invisible image at the end of the email which can track email opens. If the email recipient has images enabled on their email client, a request to SendGrids server for the invisible image is executed and an open event is logged. These events are logged in the Statistics portal, Email Activity interface, and are reported by the Event Webhook.
+
+You can track a variety of the actions your recipients may take when interacting with your emails including opening your emails, clicking on links in your emails, and subscribing to (or unsubscribing from) your emails.
+
+For more information about tracking, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/tracking.html).
+
+### PATCH /tracking_settings/open
+
+
+```php
+$request_body = json_decode('{
+ "enabled": true
+}');
+$response = $sg->client->tracking_settings()->open()->patch($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Get Open Tracking Settings
+
+**This endpoint allows you to retrieve your current settings for open tracking.**
+
+Open Tracking adds an invisible image at the end of the email which can track email opens. If the email recipient has images enabled on their email client, a request to SendGrids server for the invisible image is executed and an open event is logged. These events are logged in the Statistics portal, Email Activity interface, and are reported by the Event Webhook.
+
+You can track a variety of the actions your recipients may take when interacting with your emails including opening your emails, clicking on links in your emails, and subscribing to (or unsubscribing from) your emails.
+
+For more information about tracking, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/tracking.html).
+
+### GET /tracking_settings/open
+
+
+```php
+$response = $sg->client->tracking_settings()->open()->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Update Subscription Tracking Settings
+
+**This endpoint allows you to update your current settings for subscription tracking.**
+
+Subscription tracking adds links to the bottom of your emails that allows your recipients to subscribe to, or unsubscribe from, your emails.
+
+You can track a variety of the actions your recipients may take when interacting with your emails including opening your emails, clicking on links in your emails, and subscribing to (or unsubscribing from) your emails.
+
+For more information about tracking, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/tracking.html).
+
+### PATCH /tracking_settings/subscription
+
+
+```php
+$request_body = json_decode('{
+ "enabled": true,
+ "html_content": "html content",
+ "landing": "landing page html",
+ "plain_content": "text content",
+ "replace": "replacement tag",
+ "url": "url"
+}');
+$response = $sg->client->tracking_settings()->subscription()->patch($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Retrieve Subscription Tracking Settings
+
+**This endpoint allows you to retrieve your current settings for subscription tracking.**
+
+Subscription tracking adds links to the bottom of your emails that allows your recipients to subscribe to, or unsubscribe from, your emails.
+
+You can track a variety of the actions your recipients may take when interacting with your emails including opening your emails, clicking on links in your emails, and subscribing to (or unsubscribing from) your emails.
+
+For more information about tracking, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/tracking.html).
+
+### GET /tracking_settings/subscription
+
+
+```php
+$response = $sg->client->tracking_settings()->subscription()->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+<a name="user"></a>
+# USER
+
+## Get a user's account information.
+
+**This endpoint allows you to retrieve your user account details.**
+
+Your user's account information includes the user's account type and reputation.
+
+Keeping your user profile up to date is important. This will help SendGrid to verify who you are as well as contact you should we need to.
+
+For more information about your user profile:
+
+* [SendGrid Account Settings](https://sendgrid.com/docs/User_Guide/Settings/account.html)
+
+### GET /user/account
+
+
+```php
+$response = $sg->client->user()->account()->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Retrieve your credit balance
+
+**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).
+
+### GET /user/credits
+
+
+```php
+$response = $sg->client->user()->credits()->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Update your account email address
+
+**This endpoint allows you to update the email address currently on file for your account.**
+
+Keeping your user profile up to date is important. This will help SendGrid to verify who you are as well as contact you should we need to.
+
+For more information about your user profile:
+
+* [SendGrid Account Settings](https://sendgrid.com/docs/User_Guide/Settings/account.html)
+
+### PUT /user/email
+
+
+```php
+$request_body = json_decode('{
+ "email": "example@example.com"
+}');
+$response = $sg->client->user()->email()->put($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Retrieve your account email address
+
+**This endpoint allows you to retrieve the email address currently on file for your account.**
+
+Keeping your user profile up to date is important. This will help SendGrid to verify who you are as well as contact you should we need to.
+
+For more information about your user profile:
+
+* [SendGrid Account Settings](https://sendgrid.com/docs/User_Guide/Settings/account.html)
+
+### GET /user/email
+
+
+```php
+$response = $sg->client->user()->email()->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Update your password
+
+**This endpoint allows you to update your password.**
+
+Keeping your user profile up to date is important. This will help SendGrid to verify who you are as well as contact you should we need to.
+
+For more information about your user profile:
+
+* [SendGrid Account Settings](https://sendgrid.com/docs/User_Guide/Settings/account.html)
+
+### PUT /user/password
+
+
+```php
+$request_body = json_decode('{
+ "new_password": "new_password",
+ "old_password": "old_password"
+}');
+$response = $sg->client->user()->password()->put($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Update a user's profile
+
+**This endpoint allows you to update your current profile details.**
+
+Keeping your user profile up to date is important. This will help SendGrid to verify who you are as well as contact you should we need to.
+
+For more information about your user profile:
+
+* [SendGrid Account Settings](https://sendgrid.com/docs/User_Guide/Settings/account.html)
+
+It should be noted that any one or more of the parameters can be updated via the PATCH /user/profile endpoint. The only requirement is that you include at least one when you PATCH.
+
+### PATCH /user/profile
+
+
+```php
+$request_body = json_decode('{
+ "city": "Orange",
+ "first_name": "Example",
+ "last_name": "User"
+}');
+$response = $sg->client->user()->profile()->patch($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Get a user's profile
+
+Keeping your user profile up to date is important. This will help SendGrid to verify who you are as well as contact you should we need to.
+
+For more information about your user profile:
+
+* [SendGrid Account Settings](https://sendgrid.com/docs/User_Guide/Settings/account.html)
+
+### GET /user/profile
+
+
+```php
+$response = $sg->client->user()->profile()->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Cancel or pause a scheduled send
+
+**This endpoint allows you to cancel or pause an email that has been scheduled to be sent.**
+
+If the maximum number of cancellations/pauses are added, HTTP 400 will
+be returned.
+
+The Cancel Scheduled Sends feature allows the customer to cancel a scheduled send based on a Batch ID included in the SMTPAPI header.Scheduled sends cancelled less than 10 minutes before the scheduled time are not guaranteed to be cancelled.
+
+### POST /user/scheduled_sends
+
+
+```php
+$request_body = json_decode('{
+ "batch_id": "YOUR_BATCH_ID",
+ "status": "pause"
+}');
+$response = $sg->client->user()->scheduled_sends()->post($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Retrieve all scheduled sends
+
+**This endpoint allows you to retrieve all cancel/paused scheduled send information.**
+
+The Cancel Scheduled Sends feature allows the customer to cancel a scheduled send based on a Batch ID included in the SMTPAPI header.Scheduled sends cancelled less than 10 minutes before the scheduled time are not guaranteed to be cancelled.
+
+### GET /user/scheduled_sends
+
+
+```php
+$response = $sg->client->user()->scheduled_sends()->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Update user scheduled send information
+
+**This endpoint allows you to update the status of a scheduled send for the given `batch_id`.**
+
+The Cancel Scheduled Sends feature allows the customer to cancel a scheduled send based on a Batch ID included in the SMTPAPI header.Scheduled sends cancelled less than 10 minutes before the scheduled time are not guaranteed to be cancelled.
+
+### PATCH /user/scheduled_sends/{batch_id}
+
+
+```php
+$request_body = json_decode('{
+ "status": "pause"
+}');
+$batch_id = "test_url_param";
+$response = $sg->client->user()->scheduled_sends()->_($batch_id)->patch($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Retrieve scheduled send
+
+**This endpoint allows you to retrieve the cancel/paused scheduled send information for a specific `batch_id`.**
+
+The Cancel Scheduled Sends feature allows the customer to cancel a scheduled send based on a Batch ID included in the SMTPAPI header.Scheduled sends cancelled less than 10 minutes before the scheduled time are not guaranteed to be cancelled.
+
+### GET /user/scheduled_sends/{batch_id}
+
+
+```php
+$batch_id = "test_url_param";
+$response = $sg->client->user()->scheduled_sends()->_($batch_id)->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Delete a cancellation or pause of a scheduled send
+
+**This endpoint allows you to delete the cancellation/pause of a scheduled send.**
+
+The Cancel Scheduled Sends feature allows the customer to cancel a scheduled send based on a Batch ID included in the SMTPAPI header.Scheduled sends cancelled less than 10 minutes before the scheduled time are not guaranteed to be cancelled.
+
+### DELETE /user/scheduled_sends/{batch_id}
+
+
+```php
+$batch_id = "test_url_param";
+$response = $sg->client->user()->scheduled_sends()->_($batch_id)->delete($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Update Enforced TLS settings
+
+**This endpoint allows you to update your current Enforced TLS settings.**
+
+The Enforced TLS settings specify whether or not the recipient is required to support TLS or have a valid certificate. See the [SMTP Ports User Guide](https://sendgrid.com/docs/Classroom/Basics/Email_Infrastructure/smtp_ports.html) for more information on opportunistic TLS.
+
+**Note:** If either setting is enabled and the recipient does not support TLS or have a valid certificate, we drop the message and send a block event with TLS required but not supported as the description.
+
+### PATCH /user/settings/enforced_tls
+
+
+```php
+$request_body = json_decode('{
+ "require_tls": true,
+ "require_valid_cert": false
+}');
+$response = $sg->client->user()->settings()->enforced_tls()->patch($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Retrieve current Enforced TLS settings.
+
+**This endpoint allows you to retrieve your current Enforced TLS settings.**
+
+The Enforced TLS settings specify whether or not the recipient is required to support TLS or have a valid certificate. See the [SMTP Ports User Guide](https://sendgrid.com/docs/Classroom/Basics/Email_Infrastructure/smtp_ports.html) for more information on opportunistic TLS.
+
+**Note:** If either setting is enabled and the recipient does not support TLS or have a valid certificate, we drop the message and send a block event with TLS required but not supported as the description.
+
+### GET /user/settings/enforced_tls
+
+
+```php
+$response = $sg->client->user()->settings()->enforced_tls()->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Update your username
+
+**This endpoint allows you to update the username for your account.**
+
+Keeping your user profile up to date is important. This will help SendGrid to verify who you are as well as contact you should we need to.
+
+For more information about your user profile:
+
+* [SendGrid Account Settings](https://sendgrid.com/docs/User_Guide/Settings/account.html)
+
+### PUT /user/username
+
+
+```php
+$request_body = json_decode('{
+ "username": "test_username"
+}');
+$response = $sg->client->user()->username()->put($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Retrieve your username
+
+**This endpoint allows you to retrieve your current account username.**
+
+Keeping your user profile up to date is important. This will help SendGrid to verify who you are as well as contact you should we need to.
+
+For more information about your user profile:
+
+* [SendGrid Account Settings](https://sendgrid.com/docs/User_Guide/Settings/account.html)
+
+### GET /user/username
+
+
+```php
+$response = $sg->client->user()->username()->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Update Event Notification Settings
+
+**This endpoint allows you to update your current event webhook settings.**
+
+If an event type is marked as `true`, then the event webhook will include information about that event.
+
+SendGrids Event Webhook will notify a URL of your choice via HTTP POST with information about events that occur as SendGrid processes your email.
+
+Common uses of this data are to remove unsubscribes, react to spam reports, determine unengaged recipients, identify bounced email addresses, or create advanced analytics of your email program.
+
+### PATCH /user/webhooks/event/settings
+
+
+```php
+$request_body = json_decode('{
+ "bounce": true,
+ "click": true,
+ "deferred": true,
+ "delivered": true,
+ "dropped": true,
+ "enabled": true,
+ "group_resubscribe": true,
+ "group_unsubscribe": true,
+ "open": true,
+ "processed": true,
+ "spam_report": true,
+ "unsubscribe": true,
+ "url": "url"
+}');
+$response = $sg->client->user()->webhooks()->event()->settings()->patch($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Retrieve Event Webhook settings
+
+**This endpoint allows you to retrieve your current event webhook settings.**
+
+If an event type is marked as `true`, then the event webhook will include information about that event.
+
+SendGrids Event Webhook will notify a URL of your choice via HTTP POST with information about events that occur as SendGrid processes your email.
+
+Common uses of this data are to remove unsubscribes, react to spam reports, determine unengaged recipients, identify bounced email addresses, or create advanced analytics of your email program.
+
+### GET /user/webhooks/event/settings
+
+
+```php
+$response = $sg->client->user()->webhooks()->event()->settings()->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Test Event Notification Settings
+
+**This endpoint allows you to test your event webhook by sending a fake event notification post to the provided URL.**
+
+SendGrids Event Webhook will notify a URL of your choice via HTTP POST with information about events that occur as SendGrid processes your email.
+
+Common uses of this data are to remove unsubscribes, react to spam reports, determine unengaged recipients, identify bounced email addresses, or create advanced analytics of your email program.
+
+### POST /user/webhooks/event/test
+
+
+```php
+$request_body = json_decode('{
+ "url": "url"
+}');
+$response = $sg->client->user()->webhooks()->event()->test()->post($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Retrieve Parse Webhook settings
+
+**This endpoint allows you to retrieve your current inbound parse webhook settings.**
+
+SendGrid can parse the attachments and contents of incoming emails. The Parse API will POST the parsed email to a URL that you specify. For more information, see our Inbound [Parse Webhook documentation](https://sendgrid.com/docs/API_Reference/Webhooks/parse.html).
+
+### GET /user/webhooks/parse/settings
+
+
+```php
+$response = $sg->client->user()->webhooks()->parse()->settings()->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Retrieves Inbound Parse Webhook statistics.
+
+**This endpoint allows you to retrieve the statistics for your Parse Webhook useage.**
+
+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.
+
+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).
+
+### GET /user/webhooks/parse/stats
+
+
+```php
+$query_params = json_decode('{"aggregated_by": "day", "limit": "test_string", "start_date": "2016-01-01", "end_date": "2016-04-01", "offset": "test_string"}');
+$response = $sg->client->user()->webhooks()->parse()->stats()->get(null, $query_params);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+<a name="whitelabel"></a>
+# WHITELABEL
+
+## Create a domain whitelabel.
+
+**This endpoint allows you to create a whitelabel for one of your domains.**
+
+If you are creating a domain whitelabel that you would like a subuser to use, you have two options:
+1. Use the "username" parameter. This allows you to create a whitelabel on behalf of your subuser. This means the subuser is able to see and modify the created whitelabel.
+2. Use the Association workflow (see Associate Domain section). This allows you to assign a whitelabel created by the parent to a subuser. This means the subuser will default to the assigned whitelabel, but will not be able to see or modify that whitelabel. However, if the subuser creates their own whitelabel it will overwrite the assigned whitelabel.
+
+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.
+
+For more information on whitelabeling, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/Whitelabel/index.html)
+
+### POST /whitelabel/domains
+
+
+```php
+$request_body = json_decode('{
+ "automatic_security": false,
+ "custom_spf": true,
+ "default": true,
+ "domain": "example.com",
+ "ips": [
+ "192.168.1.1",
+ "192.168.1.2"
+ ],
+ "subdomain": "news",
+ "username": "john@example.com"
+}');
+$response = $sg->client->whitelabel()->domains()->post($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## List all domain whitelabels.
+
+**This endpoint allows you to retrieve a list of all domain whitelabels you have created.**
+
+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.
+
+For more information on whitelabeling, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/Whitelabel/index.html)
+
+
+### GET /whitelabel/domains
+
+
+```php
+$query_params = json_decode('{"username": "test_string", "domain": "test_string", "exclude_subusers": "true", "limit": 1, "offset": 1}');
+$response = $sg->client->whitelabel()->domains()->get(null, $query_params);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Get the default domain whitelabel.
+
+**This endpoint allows you to retrieve the default whitelabel for a domain.**
+
+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.
+
+For more information on whitelabeling, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/Whitelabel/index.html)
+
+## URI Parameters
+| URI Parameter | Type | Description |
+|---|---|---|
+| domain | string |The domain to find a default domain whitelabel for. |
+
+### GET /whitelabel/domains/default
+
+
+```php
+$response = $sg->client->whitelabel()->domains()->default()->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## List the domain whitelabel associated with the given user.
+
+**This endpoint allows you to retrieve all of the whitelabels that have been assigned to a specific subuser.**
+
+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.
+
+For more information on whitelabeling, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/Whitelabel/index.html)
+
+## URI Parameters
+| URI Parameter | Type | Description |
+|---|---|---|
+| username | string | Username of the subuser to find associated whitelabels for. |
+
+### GET /whitelabel/domains/subuser
+
+
+```php
+$response = $sg->client->whitelabel()->domains()->subuser()->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Disassociate a domain whitelabel from a given user.
+
+**This endpoint allows you to disassociate a specific whitelabel from a subuser.**
+
+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.
+
+For more information on whitelabeling, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/Whitelabel/index.html)
+
+## URI Parameters
+| URI Parameter | Type | Required? | Description |
+|---|---|---|---|
+| username | string | required | Username for the subuser to find associated whitelabels for. |
+
+### DELETE /whitelabel/domains/subuser
+
+
+```php
+$response = $sg->client->whitelabel()->domains()->subuser()->delete($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Update a domain whitelabel.
+
+**This endpoint allows you to update the settings for a domain whitelabel.**
+
+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.
+
+For more information on whitelabeling, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/Whitelabel/index.html)
+
+### PATCH /whitelabel/domains/{domain_id}
+
+
+```php
+$request_body = json_decode('{
+ "custom_spf": true,
+ "default": false
+}');
+$domain_id = "test_url_param";
+$response = $sg->client->whitelabel()->domains()->_($domain_id)->patch($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Retrieve a domain whitelabel.
+
+**This endpoint allows you to retrieve a specific domain whitelabel.**
+
+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.
+
+For more information on whitelabeling, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/Whitelabel/index.html)
+
+
+### GET /whitelabel/domains/{domain_id}
+
+
+```php
+$domain_id = "test_url_param";
+$response = $sg->client->whitelabel()->domains()->_($domain_id)->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Delete a domain whitelabel.
+
+**This endpoint allows you to delete a domain whitelabel.**
+
+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.
+
+For more information on whitelabeling, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/Whitelabel/index.html)
+
+### DELETE /whitelabel/domains/{domain_id}
+
+
+```php
+$domain_id = "test_url_param";
+$response = $sg->client->whitelabel()->domains()->_($domain_id)->delete($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Associate a domain whitelabel with a given user.
+
+**This endpoint allows you to associate a specific domain whitelabel with a subuser.**
+
+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.
+
+For more information on whitelabeling, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/Whitelabel/index.html)
+
+## URI Parameters
+| URI Parameter | Type | Description |
+|---|---|---|
+| domain_id | integer | ID of the domain whitelabel to associate with the subuser. |
+
+### POST /whitelabel/domains/{domain_id}/subuser
+
+
+```php
+$request_body = json_decode('{
+ "username": "jane@example.com"
+}');
+$domain_id = "test_url_param";
+$response = $sg->client->whitelabel()->domains()->_($domain_id)->subuser()->post($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Add an IP to a domain whitelabel.
+
+**This endpoint allows you to add an IP address to a domain whitelabel.**
+
+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.
+
+For more information on whitelabeling, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/Whitelabel/index.html)
+
+## URI Parameters
+| URI Parameter | Type | Description |
+|---|---|---|
+| id | integer | ID of the domain to which you are adding an IP |
+
+### POST /whitelabel/domains/{id}/ips
+
+
+```php
+$request_body = json_decode('{
+ "ip": "192.168.0.1"
+}');
+$id = "test_url_param";
+$response = $sg->client->whitelabel()->domains()->_($id)->ips()->post($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Remove an IP from a domain whitelabel.
+
+**This endpoint allows you to remove a domain's IP address from that domain's whitelabel.**
+
+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.
+
+For more information on whitelabeling, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/Whitelabel/index.html)
+
+## URI Parameters
+| URI Parameter | Type | Description |
+|---|---|---|
+| id | integer | ID of the domain whitelabel to delete the IP from. |
+| ip | string | IP to remove from the domain whitelabel. |
+
+### DELETE /whitelabel/domains/{id}/ips/{ip}
+
+
+```php
+$id = "test_url_param";
+$ip = "test_url_param";
+$response = $sg->client->whitelabel()->domains()->_($id)->ips()->_($ip)->delete($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Validate a domain whitelabel.
+
+**This endpoint allows you to validate a domain whitelabel. If it fails, it will return an error message describing why the whitelabel could not be validated.**
+
+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.
+
+For more information on whitelabeling, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/Whitelabel/index.html)
+
+## URI Parameters
+| URI Parameter | Type | Description |
+|---|---|---|
+| id | integer |ID of the domain whitelabel to validate. |
+
+### POST /whitelabel/domains/{id}/validate
+
+
+```php
+$request_body = json_decode('null');
+$id = "test_url_param";
+$response = $sg->client->whitelabel()->domains()->_($id)->validate()->post($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Create an IP whitelabel
+
+**This endpoint allows you to create an IP whitelabel.**
+
+When creating an IP whitelable, you should use the same subdomain that you used when you created a domain whitelabel.
+
+A IP whitelabel consists of a subdomain and domain that will be used to generate a reverse DNS record for a given IP. Once SendGrid has verified that the appropriate A record for the IP has been created, the appropriate reverse DNS record for the IP is generated.
+
+For more information, please see our [User Guide](https://sendgrid.com/docs/API_Reference/Web_API_v3/Whitelabel/ips.html).
+
+### POST /whitelabel/ips
+
+
+```php
+$request_body = json_decode('{
+ "domain": "example.com",
+ "ip": "192.168.1.1",
+ "subdomain": "email"
+}');
+$response = $sg->client->whitelabel()->ips()->post($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Retrieve all IP whitelabels
+
+**This endpoint allows you to retrieve all of the IP whitelabels that have been createdy 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.").
+
+A IP whitelabel consists of a subdomain and domain that will be used to generate a reverse DNS record for a given IP. Once SendGrid has verified that the appropriate A record for the IP has been created, the appropriate reverse DNS record for the IP is generated.
+
+For more information, please see our [User Guide](https://sendgrid.com/docs/API_Reference/Web_API_v3/Whitelabel/ips.html).
+
+### GET /whitelabel/ips
+
+
+```php
+$query_params = json_decode('{"ip": "test_string", "limit": 1, "offset": 1}');
+$response = $sg->client->whitelabel()->ips()->get(null, $query_params);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Retrieve an IP whitelabel
+
+**This endpoint allows you to retrieve an IP whitelabel.**
+
+A IP whitelabel consists of a subdomain and domain that will be used to generate a reverse DNS record for a given IP. Once SendGrid has verified that the appropriate A record for the IP has been created, the appropriate reverse DNS record for the IP is generated.
+
+For more information, please see our [User Guide](https://sendgrid.com/docs/API_Reference/Web_API_v3/Whitelabel/ips.html).
+
+### GET /whitelabel/ips/{id}
+
+
+```php
+$id = "test_url_param";
+$response = $sg->client->whitelabel()->ips()->_($id)->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Delete an IP whitelabel
+
+**This endpoint allows you to delete an IP whitelabel.**
+
+A IP whitelabel consists of a subdomain and domain that will be used to generate a reverse DNS record for a given IP. Once SendGrid has verified that the appropriate A record for the IP has been created, the appropriate reverse DNS record for the IP is generated.
+
+For more information, please see our [User Guide](https://sendgrid.com/docs/API_Reference/Web_API_v3/Whitelabel/ips.html).
+
+### DELETE /whitelabel/ips/{id}
+
+
+```php
+$id = "test_url_param";
+$response = $sg->client->whitelabel()->ips()->_($id)->delete($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Validate an IP whitelabel
+
+**This endpoint allows you to validate an IP whitelabel.**
+
+A IP whitelabel consists of a subdomain and domain that will be used to generate a reverse DNS record for a given IP. Once SendGrid has verified that the appropriate A record for the IP has been created, the appropriate reverse DNS record for the IP is generated.
+
+For more information, please see our [User Guide](https://sendgrid.com/docs/API_Reference/Web_API_v3/Whitelabel/ips.html).
+
+### POST /whitelabel/ips/{id}/validate
+
+
+```php
+$request_body = json_decode('null');
+$id = "test_url_param";
+$response = $sg->client->whitelabel()->ips()->_($id)->validate()->post($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Create a Link Whitelabel
+
+**This endpoint allows you to create a new link whitelabel.**
+
+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.
+
+For more information, please see our [User Guide](https://sendgrid.com/docs/API_Reference/Web_API_v3/Whitelabel/links.html).
+
+### POST /whitelabel/links
+
+
+```php
+$request_body = json_decode('{
+ "default": true,
+ "domain": "example.com",
+ "subdomain": "mail"
+}');
+$query_params = json_decode('{"limit": 1, "offset": 1}');
+$response = $sg->client->whitelabel()->links()->post($request_body, $query_params);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Retrieve all link whitelabels
+
+**This endpoint allows you to retrieve all link whitelabels.**
+
+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.
+
+For more information, please see our [User Guide](https://sendgrid.com/docs/API_Reference/Web_API_v3/Whitelabel/links.html).
+
+### GET /whitelabel/links
+
+
+```php
+$query_params = json_decode('{"limit": 1}');
+$response = $sg->client->whitelabel()->links()->get(null, $query_params);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Retrieve a Default Link Whitelabel
+
+**This endpoint allows you to retrieve the default link whitelabel.**
+
+Default link whitelabel is the actual link whitelabel to be used when sending messages. If there are multiple link whitelabels, the default is determined by the following order:
+<ul>
+ <li>Validated link whitelabels marked as "default"</li>
+ <li>Legacy link whitelabels (migrated from the whitelabel wizard)</li>
+ <li>Default SendGrid link whitelabel (i.e. 100.ct.sendgrid.net)</li>
+</ul>
+
+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.
+
+For more information, please see our [User Guide](https://sendgrid.com/docs/API_Reference/Web_API_v3/Whitelabel/links.html).
+
+### GET /whitelabel/links/default
+
+
+```php
+$query_params = json_decode('{"domain": "test_string"}');
+$response = $sg->client->whitelabel()->links()->default()->get(null, $query_params);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Retrieve Associated Link Whitelabel
+
+**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
+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.
+
+For more information, please see our [User Guide](https://sendgrid.com/docs/API_Reference/Web_API_v3/Whitelabel/links.html).
+
+### GET /whitelabel/links/subuser
+
+
+```php
+$query_params = json_decode('{"username": "test_string"}');
+$response = $sg->client->whitelabel()->links()->subuser()->get(null, $query_params);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Disassociate a Link Whitelabel
+
+**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
+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.
+
+For more information, please see our [User Guide](https://sendgrid.com/docs/API_Reference/Web_API_v3/Whitelabel/links.html).
+
+### DELETE /whitelabel/links/subuser
+
+
+```php
+$query_params = json_decode('{"username": "test_string"}');
+$response = $sg->client->whitelabel()->links()->subuser()->delete($request_body, $query_params);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Update a Link Whitelabel
+
+**This endpoint allows you to update a specific link whitelabel. You can use this endpoint to change a link whitelabel's default status.**
+
+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.
+
+For more information, please see our [User Guide](https://sendgrid.com/docs/API_Reference/Web_API_v3/Whitelabel/links.html).
+
+### PATCH /whitelabel/links/{id}
+
+
+```php
+$request_body = json_decode('{
+ "default": true
+}');
+$id = "test_url_param";
+$response = $sg->client->whitelabel()->links()->_($id)->patch($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Retrieve a Link Whitelabel
+
+**This endpoint allows you to retrieve a specific link whitelabel.**
+
+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.
+
+For more information, please see our [User Guide](https://sendgrid.com/docs/API_Reference/Web_API_v3/Whitelabel/links.html).
+
+### GET /whitelabel/links/{id}
+
+
+```php
+$id = "test_url_param";
+$response = $sg->client->whitelabel()->links()->_($id)->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Delete a Link Whitelabel
+
+**This endpoint allows you to delete a link whitelabel.**
+
+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.
+
+For more information, please see our [User Guide](https://sendgrid.com/docs/API_Reference/Web_API_v3/Whitelabel/links.html).
+
+### DELETE /whitelabel/links/{id}
+
+
+```php
+$id = "test_url_param";
+$response = $sg->client->whitelabel()->links()->_($id)->delete($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Validate a Link Whitelabel
+
+**This endpoint allows you to validate a link whitelabel.**
+
+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.
+
+For more information, please see our [User Guide](https://sendgrid.com/docs/API_Reference/Web_API_v3/Whitelabel/links.html).
+
+### POST /whitelabel/links/{id}/validate
+
+
+```php
+$request_body = json_decode('null');
+$id = "test_url_param";
+$response = $sg->client->whitelabel()->links()->_($id)->validate()->post($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+## Associate a Link Whitelabel
+
+**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
+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.
+
+For more information, please see our [User Guide](https://sendgrid.com/docs/API_Reference/Web_API_v3/Whitelabel/links.html).
+
+### POST /whitelabel/links/{link_id}/subuser
+
+
+```php
+$request_body = json_decode('{
+ "username": "jane@example.com"
+}');
+$link_id = "test_url_param";
+$response = $sg->client->whitelabel()->links()->_($link_id)->subuser()->post($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+```
+
diff --git a/composer.json b/composer.json
index e2beeb4..81b6e17 100644
--- a/composer.json
+++ b/composer.json
@@ -1,25 +1,23 @@
{
"name": "sendgrid/sendgrid",
"description": "This library allows you to quickly and easily send emails through SendGrid using PHP.",
- "version": "4.0.4",
+ "version": "5.0.0",
"homepage": "http://github.com/sendgrid/sendgrid-php",
"license": "MIT",
"keywords": ["SendGrid", "sendgrid", "email", "send", "grid"],
"require": {
"php": ">=5.3",
- "sendgrid/smtpapi": "~0.5",
- "guzzle/guzzle": "~3.9"
+ "sendgrid/php-http-client": "3.1.0"
},
"require-dev": {
- "mockery/mockery": "~0.9",
- "phpunit/phpunit": "~4.4",
- "vlucas/phpdotenv": "~1.0"
+ "phpunit/phpunit": "4.*",
+ "squizlabs/php_codesniffer": "2.*"
},
"replace": {
"sendgrid/sendgrid-php": "*"
},
"type": "library",
"autoload": {
- "psr-0": {"SendGrid": "lib/"}
+ "files": ["lib/SendGrid.php", "lib/helpers/mail/Mail.php"]
}
}
diff --git a/example_v2.php b/example_v2.php
deleted file mode 100644
index 3fb4205..0000000
--- a/example_v2.php
+++ /dev/null
@@ -1,26 +0,0 @@
-<?php
-require 'vendor/autoload.php';
-require 'lib/SendGrid.php';
-require 'lib/Client.php';
-
-Dotenv::load(__DIR__);
-$sendgrid_apikey = getenv('SG_KEY');
-$sendgrid = new SendGrid($sendgrid_apikey);
-
-$email = new SendGrid\Email();
-
-$templateId = '<template_id>';
-$name = array('Elmer');
-
-$email
- ->addTo('example@example.com')
- ->setFrom('example@example.com')
- ->setSubject('Testing the PHP Library')
- ->setText('I\'m text!')
- ->setHtml('<strong>I\'m HTML!</strong>')
- ->addFilter('templates', 'enabled', 1)
- ->addFilter('templates', 'template_id', $templateId)
- ->addSubstitution(":name", $name)
-;
-
-$sendgrid->send($email); \ No newline at end of file
diff --git a/example_v2_template.php b/example_v2_template.php
deleted file mode 100644
index 7f83028..0000000
--- a/example_v2_template.php
+++ /dev/null
@@ -1,33 +0,0 @@
-<?php
-require 'vendor/autoload.php';
-Dotenv::load(__DIR__);
-$sendgrid_apikey = getenv('SG_KEY');
-$sendgrid = new SendGrid($sendgrid_apikey);
-$url = 'https://api.sendgrid.com/';
-$template_id = '<template_id>';
-$js = array(
- 'sub' => array(':name' => array('Elmer')),
- 'filters' => array('templates' => array('settings' => array('enable' => 1, 'template_id' => $template_id)))
-);
-echo json_encode($js);
-$params = array(
- 'to' => "elmer.thomas@sendgrid.com",
- 'toname' => "Elmer Thomas",
- 'from' => "dx@sendrid.com",
- 'fromname' => "DX Team",
- 'subject' => "PHP Test",
- 'text' => "I'm text!",
- 'html' => "<strong>I'm HTML!</strong>",
- 'x-smtpapi' => json_encode($js),
- );
-$request = $url.'api/mail.send.json';
-$session = curl_init($request);
-curl_setopt($session, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_2);
-curl_setopt($session, CURLOPT_HTTPHEADER, array('Authorization: Bearer ' . $sendgrid_apikey));
-curl_setopt ($session, CURLOPT_POST, true);
-curl_setopt ($session, CURLOPT_POSTFIELDS, $params);
-curl_setopt($session, CURLOPT_HEADER, false);
-curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
-$response = curl_exec($session);
-curl_close($session);
-print_r($response); \ No newline at end of file
diff --git a/example_v3.php b/example_v3.php
deleted file mode 100755
index 813a2e2..0000000
--- a/example_v3.php
+++ /dev/null
@@ -1,87 +0,0 @@
-<?php
-require 'vendor/autoload.php';
-require 'lib/SendGrid.php';
-require 'lib/Client.php';
-
-Dotenv::load(__DIR__);
-$sendgrid_apikey = getenv('SG_KEY');
-$sendgrid = new Client($sendgrid_apikey);
-
-$api_key = "My API Key";
-$scopes = array("mail.send", "alerts.create", "alerts.read");
-$response = $sendgrid->api_keys->post($api_key, $scopes);
-print("Status Code: " . $response->getStatusCode() . "\n");
-print("Body: " . $response->getBody() . "\n");
-
-/*
-
-$start_date = "2015-12-01";
-$response = $sendgrid->global_stats->get($start_date);
-print("Status Code: " . $response->getStatusCode() . "\n");
-print("Body: " . $response->getBody() . "\n\n");
-
-$end_date = "2015-12-14";
-$response = $sendgrid->global_stats->get($start_date, $end_date);
-print("Status Code: " . $response->getStatusCode() . "\n");
-print("Body: " . $response->getBody() . "\n\n");
-
-$aggregated_by = "day";
-$response = $sendgrid->global_stats->get($start_date, $end_date, $aggregated_by);
-print("Status Code: " . $response->getStatusCode() . "\n");
-print("Body: " . $response->getBody() . "\n\n");
-
-$aggregated_by = "week";
-$response = $sendgrid->global_stats->get($start_date, $end_date, $aggregated_by);
-print("Status Code: " . $response->getStatusCode() . "\n");
-print("Body: " . $response->getBody() . "\n\n");
-
-$aggregated_by = "month";
-$response = $sendgrid->global_stats->get($start_date, $end_date, $aggregated_by);
-print("Status Code: " . $response->getStatusCode() . "\n");
-print("Body: " . $response->getBody() . "\n\n");
-
-$group_id = 70;
-$email = 'example@example.com';
-$response = $sendgrid->asm_suppressions->delete($group_id, $email);
-print("Status Code: " . $response->getStatusCode() . "\n");
-
-$group_id = 70;
-$email = 'example@example.com';
-$response = $sendgrid->asm_suppressions->post($group_id, $email);
-print("Status Code: " . $response->getStatusCode() . "\n");
-print("Body: " . $response->getBody() . "\n");
-
-$group_id = 70;
-$email = array('example@example.com', 'example@example.com');
-$response = $sendgrid->asm_suppressions->post($group_id, $email);
-print("Status Code: " . $response->getStatusCode() . "\n");
-print("Body: " . $response->getBody() . "\n");
-
-$response = $sendgrid->asm_groups->get();
-print("Status Code: " . $response->getStatusCode() . "\n");
-print("Body: " . $response->getBody() . "\n");
-
-$response = $sendgrid->api_keys->post("Magic Key");
-print("Status Code: " . $response->getStatusCode() . "\n");
-print("Body: " . $response->getBody() . "\n");
-
-$api_key_id = "Q5xdErWiSO6b8fYUgtYY8g";
-$name = "My API Key 2";
-$scopes = array("user.profile.read", "user.profile.update");
-$response = $sendgrid->api_keys->put($api_key_id, $name, $scopes);
-print("Status Code: " . $response->getStatusCode() . "\n");
-print("Body: " . $response->getBody() . "\n");
-
-$response = $sendgrid->api_keys->patch("<API Key ID>", "Magic Key Updated");
-print("Status Code: " . $response->getStatusCode() . "\n");
-print("Body: " . $response->getBody() . "\n");
-
-$response = $sendgrid->api_keys->delete("<API Key ID>");
-print("Status Code: " . $response->getStatusCode() . "\n");
-print("Body: " . $response->getBody() . "\n");
-
-$response = $sendgrid->api_keys->get();
-print("Status Code: " . $response->getStatusCode() . "\n");
-print("Body: " . $response->getBody() . "\n");
-
-*/ \ No newline at end of file
diff --git a/examples/accesssettings/accesssettings.php b/examples/accesssettings/accesssettings.php
new file mode 100644
index 0000000..13c12ac
--- /dev/null
+++ b/examples/accesssettings/accesssettings.php
@@ -0,0 +1,78 @@
+<?php
+// If you are using Composer
+require 'vendor/autoload.php';
+
+
+$apiKey = getenv('SENDGRID_API_KEY');
+$sg = new \SendGrid($apiKey);
+
+////////////////////////////////////////////////////
+// Retrieve all recent access attempts #
+// GET /access_settings/activity #
+
+$query_params = json_decode('{"limit": 1}');
+$response = $sg->client->access_settings()->activity()->get(null, $query_params);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Add one or more IPs to the whitelist #
+// POST /access_settings/whitelist #
+
+$request_body = json_decode('{
+ "ips": [
+ {
+ "ip": "192.168.1.1"
+ },
+ {
+ "ip": "192.*.*.*"
+ },
+ {
+ "ip": "192.168.1.3/32"
+ }
+ ]
+}');
+$response = $sg->client->access_settings()->whitelist()->post($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Retrieve a list of currently whitelisted IPs #
+// GET /access_settings/whitelist #
+
+$response = $sg->client->access_settings()->whitelist()->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Remove one or more IPs from the whitelist #
+// DELETE /access_settings/whitelist #
+
+$response = $sg->client->access_settings()->whitelist()->delete($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Retrieve a specific whitelisted IP #
+// GET /access_settings/whitelist/{rule_id} #
+
+$rule_id = "test_url_param";
+$response = $sg->client->access_settings()->whitelist()->_($rule_id)->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Remove a specific IP from the whitelist #
+// DELETE /access_settings/whitelist/{rule_id} #
+
+$rule_id = "test_url_param";
+$response = $sg->client->access_settings()->whitelist()->_($rule_id)->delete($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
diff --git a/examples/apikeys/apikeys.php b/examples/apikeys/apikeys.php
new file mode 100644
index 0000000..2e02c5d
--- /dev/null
+++ b/examples/apikeys/apikeys.php
@@ -0,0 +1,84 @@
+<?php
+// If you are using Composer
+require 'vendor/autoload.php';
+
+
+$apiKey = getenv('SENDGRID_API_KEY');
+$sg = new \SendGrid($apiKey);
+
+////////////////////////////////////////////////////
+// Create API keys #
+// POST /api_keys #
+
+$request_body = json_decode('{
+ "name": "My API Key",
+ "scopes": [
+ "mail.send",
+ "alerts.create",
+ "alerts.read"
+ ]
+}');
+$response = $sg->client->api_keys()->post($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Retrieve all API Keys belonging to the authenticated user #
+// GET /api_keys #
+
+$response = $sg->client->api_keys()->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Update the name & scopes of an API Key #
+// PUT /api_keys/{api_key_id} #
+
+$request_body = json_decode('{
+ "name": "A New Hope",
+ "scopes": [
+ "user.profile.read",
+ "user.profile.update"
+ ]
+}');
+$api_key_id = "test_url_param";
+$response = $sg->client->api_keys()->_($api_key_id)->put($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Update API keys #
+// PATCH /api_keys/{api_key_id} #
+
+$request_body = json_decode('{
+ "name": "A New Hope"
+}');
+$api_key_id = "test_url_param";
+$response = $sg->client->api_keys()->_($api_key_id)->patch($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Retrieve an existing API Key #
+// GET /api_keys/{api_key_id} #
+
+$api_key_id = "test_url_param";
+$response = $sg->client->api_keys()->_($api_key_id)->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Delete API keys #
+// DELETE /api_keys/{api_key_id} #
+
+$api_key_id = "test_url_param";
+$response = $sg->client->api_keys()->_($api_key_id)->delete($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
diff --git a/examples/asm/asm.php b/examples/asm/asm.php
new file mode 100644
index 0000000..e175509
--- /dev/null
+++ b/examples/asm/asm.php
@@ -0,0 +1,158 @@
+<?php
+// If you are using Composer
+require 'vendor/autoload.php';
+
+
+$apiKey = getenv('SENDGRID_API_KEY');
+$sg = new \SendGrid($apiKey);
+
+////////////////////////////////////////////////////
+// Create a new suppression group #
+// POST /asm/groups #
+
+$request_body = json_decode('{
+ "description": "Suggestions for products our users might like.",
+ "is_default": true,
+ "name": "Product Suggestions"
+}');
+$response = $sg->client->asm()->groups()->post($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Retrieve information about multiple suppression groups #
+// GET /asm/groups #
+
+$query_params = json_decode('{"id": 1}');
+$response = $sg->client->asm()->groups()->get(null, $query_params);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Update a suppression group. #
+// PATCH /asm/groups/{group_id} #
+
+$request_body = json_decode('{
+ "description": "Suggestions for items our users might like.",
+ "id": 103,
+ "name": "Item Suggestions"
+}');
+$group_id = "test_url_param";
+$response = $sg->client->asm()->groups()->_($group_id)->patch($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Get information on a single suppression group. #
+// GET /asm/groups/{group_id} #
+
+$group_id = "test_url_param";
+$response = $sg->client->asm()->groups()->_($group_id)->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Delete a suppression group. #
+// DELETE /asm/groups/{group_id} #
+
+$group_id = "test_url_param";
+$response = $sg->client->asm()->groups()->_($group_id)->delete($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Add suppressions to a suppression group #
+// POST /asm/groups/{group_id}/suppressions #
+
+$request_body = json_decode('{
+ "recipient_emails": [
+ "test1@example.com",
+ "test2@example.com"
+ ]
+}');
+$group_id = "test_url_param";
+$response = $sg->client->asm()->groups()->_($group_id)->suppressions()->post($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Retrieve all suppressions for a suppression group #
+// GET /asm/groups/{group_id}/suppressions #
+
+$group_id = "test_url_param";
+$response = $sg->client->asm()->groups()->_($group_id)->suppressions()->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Delete a suppression from a suppression group #
+// DELETE /asm/groups/{group_id}/suppressions/{email} #
+
+$group_id = "test_url_param";
+$email = "test_url_param";
+$response = $sg->client->asm()->groups()->_($group_id)->suppressions()->_($email)->delete($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Retrieve all suppressions #
+// GET /asm/suppressions #
+
+$response = $sg->client->asm()->suppressions()->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Add recipient addresses to the global suppression group. #
+// POST /asm/suppressions/global #
+
+$request_body = json_decode('{
+ "recipient_emails": [
+ "test1@example.com",
+ "test2@example.com"
+ ]
+}');
+$response = $sg->client->asm()->suppressions()->global()->post($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Retrieve a Global Suppression #
+// GET /asm/suppressions/global/{email} #
+
+$email = "test_url_param";
+$response = $sg->client->asm()->suppressions()->global()->_($email)->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Delete a Global Suppression #
+// DELETE /asm/suppressions/global/{email} #
+
+$email = "test_url_param";
+$response = $sg->client->asm()->suppressions()->global()->_($email)->delete($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Retrieve all suppression groups for an email address #
+// GET /asm/suppressions/{email} #
+
+$email = "test_url_param";
+$response = $sg->client->asm()->suppressions()->_($email)->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
diff --git a/examples/browsers/browsers.php b/examples/browsers/browsers.php
new file mode 100644
index 0000000..c412160
--- /dev/null
+++ b/examples/browsers/browsers.php
@@ -0,0 +1,18 @@
+<?php
+// If you are using Composer
+require 'vendor/autoload.php';
+
+
+$apiKey = getenv('SENDGRID_API_KEY');
+$sg = new \SendGrid($apiKey);
+
+////////////////////////////////////////////////////
+// Retrieve email statistics by browser. #
+// GET /browsers/stats #
+
+$query_params = json_decode('{"end_date": "2016-04-01", "aggregated_by": "day", "browsers": "test_string", "limit": "test_string", "offset": "test_string", "start_date": "2016-01-01"}');
+$response = $sg->client->browsers()->stats()->get(null, $query_params);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
diff --git a/examples/campaigns/campaigns.php b/examples/campaigns/campaigns.php
new file mode 100644
index 0000000..184e850
--- /dev/null
+++ b/examples/campaigns/campaigns.php
@@ -0,0 +1,156 @@
+<?php
+// If you are using Composer
+require 'vendor/autoload.php';
+
+
+$apiKey = getenv('SENDGRID_API_KEY');
+$sg = new \SendGrid($apiKey);
+
+////////////////////////////////////////////////////
+// Create a Campaign #
+// POST /campaigns #
+
+$request_body = json_decode('{
+ "categories": [
+ "spring line"
+ ],
+ "custom_unsubscribe_url": "",
+ "html_content": "<html><head><title></title></head><body><p>Check out our spring line!</p></body></html>",
+ "ip_pool": "marketing",
+ "list_ids": [
+ 110,
+ 124
+ ],
+ "plain_content": "Check out our spring line!",
+ "segment_ids": [
+ 110
+ ],
+ "sender_id": 124451,
+ "subject": "New Products for Spring!",
+ "suppression_group_id": 42,
+ "title": "March Newsletter"
+}');
+$response = $sg->client->campaigns()->post($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Retrieve all Campaigns #
+// GET /campaigns #
+
+$query_params = json_decode('{"limit": 0, "offset": 0}');
+$response = $sg->client->campaigns()->get(null, $query_params);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Update a Campaign #
+// PATCH /campaigns/{campaign_id} #
+
+$request_body = json_decode('{
+ "categories": [
+ "summer line"
+ ],
+ "html_content": "<html><head><title></title></head><body><p>Check out our summer line!</p></body></html>",
+ "plain_content": "Check out our summer line!",
+ "subject": "New Products for Summer!",
+ "title": "May Newsletter"
+}');
+$campaign_id = "test_url_param";
+$response = $sg->client->campaigns()->_($campaign_id)->patch($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Retrieve a single campaign #
+// GET /campaigns/{campaign_id} #
+
+$campaign_id = "test_url_param";
+$response = $sg->client->campaigns()->_($campaign_id)->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Delete a Campaign #
+// DELETE /campaigns/{campaign_id} #
+
+$campaign_id = "test_url_param";
+$response = $sg->client->campaigns()->_($campaign_id)->delete($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Update a Scheduled Campaign #
+// PATCH /campaigns/{campaign_id}/schedules #
+
+$request_body = json_decode('{
+ "send_at": 1489451436
+}');
+$campaign_id = "test_url_param";
+$response = $sg->client->campaigns()->_($campaign_id)->schedules()->patch($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Schedule a Campaign #
+// POST /campaigns/{campaign_id}/schedules #
+
+$request_body = json_decode('{
+ "send_at": 1489771528
+}');
+$campaign_id = "test_url_param";
+$response = $sg->client->campaigns()->_($campaign_id)->schedules()->post($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// View Scheduled Time of a Campaign #
+// GET /campaigns/{campaign_id}/schedules #
+
+$campaign_id = "test_url_param";
+$response = $sg->client->campaigns()->_($campaign_id)->schedules()->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Unschedule a Scheduled Campaign #
+// DELETE /campaigns/{campaign_id}/schedules #
+
+$campaign_id = "test_url_param";
+$response = $sg->client->campaigns()->_($campaign_id)->schedules()->delete($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Send a Campaign #
+// POST /campaigns/{campaign_id}/schedules/now #
+
+$request_body = json_decode('null');
+$campaign_id = "test_url_param";
+$response = $sg->client->campaigns()->_($campaign_id)->schedules()->now()->post($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Send a Test Campaign #
+// POST /campaigns/{campaign_id}/schedules/test #
+
+$request_body = json_decode('{
+ "to": "your.email@example.com"
+}');
+$campaign_id = "test_url_param";
+$response = $sg->client->campaigns()->_($campaign_id)->schedules()->test()->post($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
diff --git a/examples/categories/categories.php b/examples/categories/categories.php
new file mode 100644
index 0000000..7fa9b1e
--- /dev/null
+++ b/examples/categories/categories.php
@@ -0,0 +1,38 @@
+<?php
+// If you are using Composer
+require 'vendor/autoload.php';
+
+
+$apiKey = getenv('SENDGRID_API_KEY');
+$sg = new \SendGrid($apiKey);
+
+////////////////////////////////////////////////////
+// Retrieve all categories #
+// GET /categories #
+
+$query_params = json_decode('{"category": "test_string", "limit": 1, "offset": 1}');
+$response = $sg->client->categories()->get(null, $query_params);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Retrieve Email Statistics for Categories #
+// GET /categories/stats #
+
+$query_params = json_decode('{"end_date": "2016-04-01", "aggregated_by": "day", "limit": 1, "offset": 1, "start_date": "2016-01-01", "categories": "test_string"}');
+$response = $sg->client->categories()->stats()->get(null, $query_params);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Retrieve sums of email stats for each category [Needs: Stats object defined, has category ID?] #
+// GET /categories/stats/sums #
+
+$query_params = json_decode('{"end_date": "2016-04-01", "aggregated_by": "day", "limit": 1, "sort_by_metric": "test_string", "offset": 1, "start_date": "2016-01-01", "sort_by_direction": "asc"}');
+$response = $sg->client->categories()->stats()->sums()->get(null, $query_params);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
diff --git a/examples/clients/clients.php b/examples/clients/clients.php
new file mode 100644
index 0000000..ae09b7b
--- /dev/null
+++ b/examples/clients/clients.php
@@ -0,0 +1,29 @@
+<?php
+// If you are using Composer
+require 'vendor/autoload.php';
+
+
+$apiKey = getenv('SENDGRID_API_KEY');
+$sg = new \SendGrid($apiKey);
+
+////////////////////////////////////////////////////
+// Retrieve email statistics by client type. #
+// GET /clients/stats #
+
+$query_params = json_decode('{"aggregated_by": "day", "start_date": "2016-01-01", "end_date": "2016-04-01"}');
+$response = $sg->client->clients()->stats()->get(null, $query_params);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Retrieve stats by a specific client type. #
+// GET /clients/{client_type}/stats #
+
+$query_params = json_decode('{"aggregated_by": "day", "start_date": "2016-01-01", "end_date": "2016-04-01"}');
+$client_type = "test_url_param";
+$response = $sg->client->clients()->_($client_type)->stats()->get(null, $query_params);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
diff --git a/examples/contactdb/contactdb.php b/examples/contactdb/contactdb.php
new file mode 100644
index 0000000..4d0eb4a
--- /dev/null
+++ b/examples/contactdb/contactdb.php
@@ -0,0 +1,388 @@
+<?php
+// If you are using Composer
+require 'vendor/autoload.php';
+
+
+$apiKey = getenv('SENDGRID_API_KEY');
+$sg = new \SendGrid($apiKey);
+
+////////////////////////////////////////////////////
+// Create a Custom Field #
+// POST /contactdb/custom_fields #
+
+$request_body = json_decode('{
+ "name": "pet",
+ "type": "text"
+}');
+$response = $sg->client->contactdb()->custom_fields()->post($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Retrieve all custom fields #
+// GET /contactdb/custom_fields #
+
+$response = $sg->client->contactdb()->custom_fields()->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Retrieve a Custom Field #
+// GET /contactdb/custom_fields/{custom_field_id} #
+
+$custom_field_id = "test_url_param";
+$response = $sg->client->contactdb()->custom_fields()->_($custom_field_id)->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Delete a Custom Field #
+// DELETE /contactdb/custom_fields/{custom_field_id} #
+
+$custom_field_id = "test_url_param";
+$response = $sg->client->contactdb()->custom_fields()->_($custom_field_id)->delete($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Create a List #
+// POST /contactdb/lists #
+
+$request_body = json_decode('{
+ "name": "your list name"
+}');
+$response = $sg->client->contactdb()->lists()->post($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Retrieve all lists #
+// GET /contactdb/lists #
+
+$response = $sg->client->contactdb()->lists()->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Delete Multiple lists #
+// DELETE /contactdb/lists #
+
+$response = $sg->client->contactdb()->lists()->delete($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Update a List #
+// PATCH /contactdb/lists/{list_id} #
+
+$request_body = json_decode('{
+ "name": "newlistname"
+}');
+$query_params = json_decode('{"list_id": 0}');
+$list_id = "test_url_param";
+$response = $sg->client->contactdb()->lists()->_($list_id)->patch($request_body, $query_params);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Retrieve a single list #
+// GET /contactdb/lists/{list_id} #
+
+$query_params = json_decode('{"list_id": 0}');
+$list_id = "test_url_param";
+$response = $sg->client->contactdb()->lists()->_($list_id)->get(null, $query_params);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Delete a List #
+// DELETE /contactdb/lists/{list_id} #
+
+$query_params = json_decode('{"delete_contacts": "true"}');
+$list_id = "test_url_param";
+$response = $sg->client->contactdb()->lists()->_($list_id)->delete($request_body, $query_params);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Add Multiple Recipients to a List #
+// POST /contactdb/lists/{list_id}/recipients #
+
+$request_body = json_decode('[
+ "recipient_id1",
+ "recipient_id2"
+]');
+$list_id = "test_url_param";
+$response = $sg->client->contactdb()->lists()->_($list_id)->recipients()->post($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Retrieve all recipients on a List #
+// GET /contactdb/lists/{list_id}/recipients #
+
+$query_params = json_decode('{"page": 1, "page_size": 1, "list_id": 0}');
+$list_id = "test_url_param";
+$response = $sg->client->contactdb()->lists()->_($list_id)->recipients()->get(null, $query_params);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Add a Single Recipient to a List #
+// POST /contactdb/lists/{list_id}/recipients/{recipient_id} #
+
+$request_body = json_decode('null');
+$list_id = "test_url_param";
+$recipient_id = "test_url_param";
+$response = $sg->client->contactdb()->lists()->_($list_id)->recipients()->_($recipient_id)->post($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Delete a Single Recipient from a Single List #
+// DELETE /contactdb/lists/{list_id}/recipients/{recipient_id} #
+
+$query_params = json_decode('{"recipient_id": 0, "list_id": 0}');
+$list_id = "test_url_param";
+$recipient_id = "test_url_param";
+$response = $sg->client->contactdb()->lists()->_($list_id)->recipients()->_($recipient_id)->delete($request_body, $query_params);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Update Recipient #
+// PATCH /contactdb/recipients #
+
+$request_body = json_decode('[
+ {
+ "email": "jones@example.com",
+ "first_name": "Guy",
+ "last_name": "Jones"
+ }
+]');
+$response = $sg->client->contactdb()->recipients()->patch($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Add recipients #
+// POST /contactdb/recipients #
+
+$request_body = json_decode('[
+ {
+ "age": 25,
+ "email": "example@example.com",
+ "first_name": "",
+ "last_name": "User"
+ },
+ {
+ "age": 25,
+ "email": "example2@example.com",
+ "first_name": "Example",
+ "last_name": "User"
+ }
+]');
+$response = $sg->client->contactdb()->recipients()->post($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Retrieve recipients #
+// GET /contactdb/recipients #
+
+$query_params = json_decode('{"page": 1, "page_size": 1}');
+$response = $sg->client->contactdb()->recipients()->get(null, $query_params);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Delete Recipient #
+// DELETE /contactdb/recipients #
+
+$response = $sg->client->contactdb()->recipients()->delete($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Retrieve the count of billable recipients #
+// GET /contactdb/recipients/billable_count #
+
+$response = $sg->client->contactdb()->recipients()->billable_count()->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Retrieve a Count of Recipients #
+// GET /contactdb/recipients/count #
+
+$response = $sg->client->contactdb()->recipients()->count()->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Retrieve recipients matching search criteria #
+// GET /contactdb/recipients/search #
+
+$query_params = json_decode('{"{field_name}": "test_string"}');
+$response = $sg->client->contactdb()->recipients()->search()->get(null, $query_params);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Retrieve a single recipient #
+// GET /contactdb/recipients/{recipient_id} #
+
+$recipient_id = "test_url_param";
+$response = $sg->client->contactdb()->recipients()->_($recipient_id)->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Delete a Recipient #
+// DELETE /contactdb/recipients/{recipient_id} #
+
+$recipient_id = "test_url_param";
+$response = $sg->client->contactdb()->recipients()->_($recipient_id)->delete($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Retrieve the lists that a recipient is on #
+// GET /contactdb/recipients/{recipient_id}/lists #
+
+$recipient_id = "test_url_param";
+$response = $sg->client->contactdb()->recipients()->_($recipient_id)->lists()->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Retrieve reserved fields #
+// GET /contactdb/reserved_fields #
+
+$response = $sg->client->contactdb()->reserved_fields()->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Create a Segment #
+// POST /contactdb/segments #
+
+$request_body = json_decode('{
+ "conditions": [
+ {
+ "and_or": "",
+ "field": "last_name",
+ "operator": "eq",
+ "value": "Miller"
+ },
+ {
+ "and_or": "and",
+ "field": "last_clicked",
+ "operator": "gt",
+ "value": "01/02/2015"
+ },
+ {
+ "and_or": "or",
+ "field": "clicks.campaign_identifier",
+ "operator": "eq",
+ "value": "513"
+ }
+ ],
+ "list_id": 4,
+ "name": "Last Name Miller"
+}');
+$response = $sg->client->contactdb()->segments()->post($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Retrieve all segments #
+// GET /contactdb/segments #
+
+$response = $sg->client->contactdb()->segments()->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Update a segment #
+// PATCH /contactdb/segments/{segment_id} #
+
+$request_body = json_decode('{
+ "conditions": [
+ {
+ "and_or": "",
+ "field": "last_name",
+ "operator": "eq",
+ "value": "Miller"
+ }
+ ],
+ "list_id": 5,
+ "name": "The Millers"
+}');
+$query_params = json_decode('{"segment_id": "test_string"}');
+$segment_id = "test_url_param";
+$response = $sg->client->contactdb()->segments()->_($segment_id)->patch($request_body, $query_params);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Retrieve a segment #
+// GET /contactdb/segments/{segment_id} #
+
+$query_params = json_decode('{"segment_id": 0}');
+$segment_id = "test_url_param";
+$response = $sg->client->contactdb()->segments()->_($segment_id)->get(null, $query_params);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Delete a segment #
+// DELETE /contactdb/segments/{segment_id} #
+
+$query_params = json_decode('{"delete_contacts": "true"}');
+$segment_id = "test_url_param";
+$response = $sg->client->contactdb()->segments()->_($segment_id)->delete($request_body, $query_params);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Retrieve recipients on a segment #
+// GET /contactdb/segments/{segment_id}/recipients #
+
+$query_params = json_decode('{"page": 1, "page_size": 1}');
+$segment_id = "test_url_param";
+$response = $sg->client->contactdb()->segments()->_($segment_id)->recipients()->get(null, $query_params);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
diff --git a/examples/devices/devices.php b/examples/devices/devices.php
new file mode 100644
index 0000000..308684f
--- /dev/null
+++ b/examples/devices/devices.php
@@ -0,0 +1,18 @@
+<?php
+// If you are using Composer
+require 'vendor/autoload.php';
+
+
+$apiKey = getenv('SENDGRID_API_KEY');
+$sg = new \SendGrid($apiKey);
+
+////////////////////////////////////////////////////
+// Retrieve email statistics by device type. #
+// GET /devices/stats #
+
+$query_params = json_decode('{"aggregated_by": "day", "limit": 1, "start_date": "2016-01-01", "end_date": "2016-04-01", "offset": 1}');
+$response = $sg->client->devices()->stats()->get(null, $query_params);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
diff --git a/examples/geo/geo.php b/examples/geo/geo.php
new file mode 100644
index 0000000..ab4c470
--- /dev/null
+++ b/examples/geo/geo.php
@@ -0,0 +1,18 @@
+<?php
+// If you are using Composer
+require 'vendor/autoload.php';
+
+
+$apiKey = getenv('SENDGRID_API_KEY');
+$sg = new \SendGrid($apiKey);
+
+////////////////////////////////////////////////////
+// Retrieve email statistics by country and state/province. #
+// GET /geo/stats #
+
+$query_params = json_decode('{"end_date": "2016-04-01", "country": "US", "aggregated_by": "day", "limit": 1, "offset": 1, "start_date": "2016-01-01"}');
+$response = $sg->client->geo()->stats()->get(null, $query_params);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
diff --git a/examples/helpers/mail/example.php b/examples/helpers/mail/example.php
new file mode 100644
index 0000000..678302d
--- /dev/null
+++ b/examples/helpers/mail/example.php
@@ -0,0 +1,207 @@
+<?php
+namespace SendGrid;
+
+// If you are using Composer
+require __DIR__ . '<PATH_TO>/vendor/autoload.php';
+
+
+function helloEmail()
+{
+ $from = new Email(null, "test@example.com");
+ $subject = "Hello World from the SendGrid PHP Library";
+ $to = new Email(null, "test@example.com");
+ $content = new Content("text/plain", "some text here");
+ $mail = new Mail($from, $subject, $to, $content);
+ $to = new Email(null, "test2@example.com");
+ $mail->personalization[0]->addTo($to);
+
+ //echo json_encode($mail, JSON_PRETTY_PRINT), "\n";
+ return $mail;
+}
+
+function kitchenSink()
+{
+ $mail = new Mail();
+
+ $email = new Email("DX", "test@example.com");
+ $mail->setFrom($email);
+
+ $mail->setSubject("Hello World from the SendGrid PHP Library");
+
+ $personalization = new Personalization();
+ $email = new Email("Example User", "test1@example.com");
+ $personalization->addTo($email);
+ $email = new Email("Example User", "test2@example.com");
+ $personalization->addTo($email);
+ $email = new Email("Example User", "test3@example.com");
+ $personalization->addCc($email);
+ $email = new Email("Example User", "test4@example.com");
+ $personalization->addCc($email);
+ $email = new Email("Example User", "test5@example.com");
+ $personalization->addBcc($email);
+ $email = new Email("Example User", "test6@example.com");
+ $personalization->addBcc($email);
+ $personalization->setSubject("Hello World from the SendGrid PHP Library");
+ $personalization->addHeader("X-Test", "test");
+ $personalization->addHeader("X-Mock", "true");
+ $personalization->addSubstitution("%name%", "Example User");
+ $personalization->addSubstitution("%city%", "Denver");
+ $personalization->addCustomArg("user_id", "343");
+ $personalization->addCustomArg("type", "marketing");
+ $personalization->setSendAt(1443636843);
+ $mail->addPersonalization($personalization);
+
+ $personalization2 = new Personalization();
+ $email = new Email("Example User", "test1@example.com");
+ $personalization2->addTo($email);
+ $email = new Email("Example User", "test2@example.com");
+ $personalization2->addTo($email);
+ $email = new Email("Example User", "test3@example.com");
+ $personalization2->addCc($email);
+ $email = new Email("Example User", "test4@example.com");
+ $personalization2->addCc($email);
+ $email = new Email("Example User", "test5@example.com");
+ $personalization2->addBcc($email);
+ $email = new Email("Example User", "test6@example.com");
+ $personalization2->addBcc($email);
+ $personalization2->setSubject("Hello World from the SendGrid PHP Library");
+ $personalization2->addHeader("X-Test", "test");
+ $personalization2->addHeader("X-Mock", "true");
+ $personalization2->addSubstitution("%name%", "Example User");
+ $personalization2->addSubstitution("%city%", "Denver");
+ $personalization2->addCustomArg("user_id", "343");
+ $personalization2->addCustomArg("type", "marketing");
+ $personalization2->setSendAt(1443636843);
+ $mail->addPersonalization($personalization2);
+
+ $content = new Content("text/plain", "some text here");
+ $mail->addContent($content);
+ $content = new Content("text/html", "<html><body>some text here</body></html>");
+ $mail->addContent($content);
+
+ $attachment = new Attachment();
+ $attachment->setContent("TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIGFkaXBpc2NpbmcgZWxpdC4gQ3JhcyBwdW12");
+ $attachment->setType("application/pdf");
+ $attachment->setFilename("balance_001.pdf");
+ $attachment->setDisposition("attachment");
+ $attachment->setContentId("Balance Sheet");
+ $mail->addAttachment($attachment);
+
+ $attachment2 = new Attachment();
+ $attachment2->setContent("BwdW");
+ $attachment2->setType("image/png");
+ $attachment2->setFilename("banner.png");
+ $attachment2->setDisposition("inline");
+ $attachment2->setContentId("Banner");
+ $mail->addAttachment($attachment2);
+
+ $mail->setTemplateId("439b6d66-4408-4ead-83de-5c83c2ee313a");
+
+ # This must be a valid [batch ID](https://sendgrid.com/docs/API_Reference/SMTP_API/scheduling_parameters.html) to work
+ # $mail->setBatchID("sengrid_batch_id");
+
+ $mail->addSection("%section1%", "Substitution Text for Section 1");
+ $mail->addSection("%section2%", "Substitution Text for Section 2");
+
+ $mail->addHeader("X-Test1", "1");
+ $mail->addHeader("X-Test2", "2");
+
+ $mail->addCategory("May");
+ $mail->addCategory("2016");
+
+ $mail->addCustomArg("campaign", "welcome");
+ $mail->addCustomArg("weekday", "morning");
+
+ $mail->setSendAt(1443636842);
+
+ $asm = new ASM();
+ $asm->setGroupId(99);
+ $asm->setGroupsToDisplay([4,5,6,7,8]);
+ $mail->setASM($asm);
+
+ $mail->setIpPoolName("23");
+
+ $mail_settings = new MailSettings();
+ $bcc_settings = new BccSettings();
+ $bcc_settings->setEnable(true);
+ $bcc_settings->setEmail("test@example.com");
+ $mail_settings->setBccSettings($bcc_settings);
+ $sandbox_mode = new SandBoxMode();
+ $sandbox_mode->setEnable(true);
+ $mail_settings->setSandboxMode($sandbox_mode);
+ $bypass_list_management = new BypassListManagement();
+ $bypass_list_management->setEnable(true);
+ $mail_settings->setBypassListManagement($bypass_list_management);
+ $footer = new Footer();
+ $footer->setEnable(true);
+ $footer->setText("Footer Text");
+ $footer->setHtml("<html><body>Footer Text</body></html>");
+ $mail_settings->setFooter($footer);
+ $spam_check = new SpamCheck();
+ $spam_check->setEnable(true);
+ $spam_check->setThreshold(1);
+ $spam_check->setPostToUrl("https://spamcatcher.sendgrid.com");
+ $mail_settings->setSpamCheck($spam_check);
+ $mail->setMailSettings($mail_settings);
+
+ $tracking_settings = new TrackingSettings();
+ $click_tracking = new ClickTracking();
+ $click_tracking->setEnable(true);
+ $click_tracking->setEnableText(true);
+ $tracking_settings->setClickTracking($click_tracking);
+ $open_tracking = new OpenTracking();
+ $open_tracking->setEnable(true);
+ $open_tracking->setSubstitutionTag("Optional tag to replace with the open image in the body of the message");
+ $tracking_settings->setOpenTracking($open_tracking);
+ $subscription_tracking = new SubscriptionTracking();
+ $subscription_tracking->setEnable(true);
+ $subscription_tracking->setText("text to insert into the text/plain portion of the message");
+ $subscription_tracking->setHtml("<html><body>html to insert into the text/html portion of the message</body></html>");
+ $subscription_tracking->setSubstitutionTag("Optional tag to replace with the open image in the body of the message");
+ $tracking_settings->setSubscriptionTracking($subscription_tracking);
+ $ganalytics = new Ganalytics();
+ $ganalytics->setEnable(true);
+ $ganalytics->setCampaignSource("some source");
+ $ganalytics->setCampaignTerm("some term");
+ $ganalytics->setCampaignContent("some content");
+ $ganalytics->setCampaignName("some name");
+ $ganalytics->setCampaignMedium("some medium");
+ $tracking_settings->setGanalytics($ganalytics);
+ $mail->setTrackingSettings($tracking_settings);
+
+ $reply_to = new ReplyTo("test@example.com");
+ $mail->setReplyTo($reply_to);
+
+ //echo json_encode($mail, JSON_PRETTY_PRINT), "\n";
+ return $mail;
+}
+
+function sendHelloEmail()
+{
+ $apiKey = getenv('SENDGRID_API_KEY');
+ $sg = new \SendGrid($apiKey);
+
+ $request_body = helloEmail();
+ $response = $sg->client->mail()->send()->post($request_body);
+ echo $response->statusCode();
+ echo $response->body();
+ echo $response->headers();
+}
+
+function sendKitchenSink()
+{
+ $apiKey = getenv('SENDGRID_API_KEY');
+ $sg = new \SendGrid($apiKey);
+
+ $request_body = kitchenSink();
+ $response = $sg->client->mail()->send()->post($request_body);
+ echo $response->statusCode();
+ echo $response->body();
+ echo $response->headers();
+}
+
+sendHelloEmail(); // this will actually send an email
+sendKitchenSink(); // this will only send an email if you set SandBox Mode to false
+?>
+
+
diff --git a/examples/ips/ips.php b/examples/ips/ips.php
new file mode 100644
index 0000000..19957d8
--- /dev/null
+++ b/examples/ips/ips.php
@@ -0,0 +1,156 @@
+<?php
+// If you are using Composer
+require 'vendor/autoload.php';
+
+
+$apiKey = getenv('SENDGRID_API_KEY');
+$sg = new \SendGrid($apiKey);
+
+////////////////////////////////////////////////////
+// Retrieve all IP addresses #
+// GET /ips #
+
+$query_params = json_decode('{"subuser": "test_string", "ip": "test_string", "limit": 1, "exclude_whitelabels": "true", "offset": 1}');
+$response = $sg->client->ips()->get(null, $query_params);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Retrieve all assigned IPs #
+// GET /ips/assigned #
+
+$response = $sg->client->ips()->assigned()->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Create an IP pool. #
+// POST /ips/pools #
+
+$request_body = json_decode('{
+ "name": "marketing"
+}');
+$response = $sg->client->ips()->pools()->post($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Retrieve all IP pools. #
+// GET /ips/pools #
+
+$response = $sg->client->ips()->pools()->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Update an IP pools name. #
+// PUT /ips/pools/{pool_name} #
+
+$request_body = json_decode('{
+ "name": "new_pool_name"
+}');
+$pool_name = "test_url_param";
+$response = $sg->client->ips()->pools()->_($pool_name)->put($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Retrieve all IPs in a specified pool. #
+// GET /ips/pools/{pool_name} #
+
+$pool_name = "test_url_param";
+$response = $sg->client->ips()->pools()->_($pool_name)->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Delete an IP pool. #
+// DELETE /ips/pools/{pool_name} #
+
+$pool_name = "test_url_param";
+$response = $sg->client->ips()->pools()->_($pool_name)->delete($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Add an IP address to a pool #
+// POST /ips/pools/{pool_name}/ips #
+
+$request_body = json_decode('{
+ "ip": "0.0.0.0"
+}');
+$pool_name = "test_url_param";
+$response = $sg->client->ips()->pools()->_($pool_name)->ips()->post($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Remove an IP address from a pool. #
+// DELETE /ips/pools/{pool_name}/ips/{ip} #
+
+$pool_name = "test_url_param";
+$ip = "test_url_param";
+$response = $sg->client->ips()->pools()->_($pool_name)->ips()->_($ip)->delete($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Add an IP to warmup #
+// POST /ips/warmup #
+
+$request_body = json_decode('{
+ "ip": "0.0.0.0"
+}');
+$response = $sg->client->ips()->warmup()->post($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Retrieve all IPs currently in warmup #
+// GET /ips/warmup #
+
+$response = $sg->client->ips()->warmup()->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Retrieve warmup status for a specific IP address #
+// GET /ips/warmup/{ip_address} #
+
+$ip_address = "test_url_param";
+$response = $sg->client->ips()->warmup()->_($ip_address)->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Remove an IP from warmup #
+// DELETE /ips/warmup/{ip_address} #
+
+$ip_address = "test_url_param";
+$response = $sg->client->ips()->warmup()->_($ip_address)->delete($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Retrieve all IP pools an IP address belongs to #
+// GET /ips/{ip_address} #
+
+$ip_address = "test_url_param";
+$response = $sg->client->ips()->_($ip_address)->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
diff --git a/examples/mail/mail.php b/examples/mail/mail.php
new file mode 100644
index 0000000..a65368d
--- /dev/null
+++ b/examples/mail/mail.php
@@ -0,0 +1,181 @@
+<?php
+// If you are using Composer
+require 'vendor/autoload.php';
+
+
+$apiKey = getenv('SENDGRID_API_KEY');
+$sg = new \SendGrid($apiKey);
+
+////////////////////////////////////////////////////
+// Create a batch ID #
+// POST /mail/batch #
+
+$request_body = json_decode('null');
+$response = $sg->client->mail()->batch()->post($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Validate batch ID #
+// GET /mail/batch/{batch_id} #
+
+$batch_id = "test_url_param";
+$response = $sg->client->mail()->batch()->_($batch_id)->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// v3 Mail Send #
+// POST /mail/send #
+// This endpoint has a helper, check it out [here](https://github.com/sendgrid/sendgrid-php/blob/master/lib/helpers/mail/README.md).
+
+$request_body = json_decode('{
+ "asm": {
+ "group_id": 1,
+ "groups_to_display": [
+ 1,
+ 2,
+ 3
+ ]
+ },
+ "attachments": [
+ {
+ "content": "[BASE64 encoded content block here]",
+ "content_id": "ii_139db99fdb5c3704",
+ "disposition": "inline",
+ "filename": "file1.jpg",
+ "name": "file1",
+ "type": "jpg"
+ }
+ ],
+ "batch_id": "[YOUR BATCH ID GOES HERE]",
+ "categories": [
+ "category1",
+ "category2"
+ ],
+ "content": [
+ {
+ "type": "text/html",
+ "value": "<html><p>Hello, world!</p><img src=[CID GOES HERE]></img></html>"
+ }
+ ],
+ "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"
+ },
+ "headers": {},
+ "ip_pool_name": "[YOUR POOL NAME GOES HERE]",
+ "mail_settings": {
+ "bcc": {
+ "email": "ben.doe@example.com",
+ "enable": true
+ },
+ "bypass_list_management": {
+ "enable": true
+ },
+ "footer": {
+ "enable": true,
+ "html": "<p>Thanks</br>The SendGrid Team</p>",
+ "text": "Thanks,/n The SendGrid Team"
+ },
+ "sandbox_mode": {
+ "enable": false
+ },
+ "spam_check": {
+ "enable": true,
+ "post_to_url": "http://example.com/compliance",
+ "threshold": 3
+ }
+ },
+ "personalizations": [
+ {
+ "bcc": [
+ {
+ "email": "sam.doe@example.com",
+ "name": "Sam Doe"
+ }
+ ],
+ "cc": [
+ {
+ "email": "jane.doe@example.com",
+ "name": "Jane 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,
+ "subject": "Hello, World!",
+ "substitutions": {
+ "sub": {
+ "%name%": [
+ "John",
+ "Jane",
+ "Sam"
+ ]
+ }
+ },
+ "to": [
+ {
+ "email": "john.doe@example.com",
+ "name": "John Doe"
+ }
+ ]
+ }
+ ],
+ "reply_to": {
+ "email": "sam.smith@example.com",
+ "name": "Sam Smith"
+ },
+ "sections": {
+ "section": {
+ ":sectionName1": "section 1 text",
+ ":sectionName2": "section 2 text"
+ }
+ },
+ "send_at": 1409348513,
+ "subject": "Hello, World!",
+ "template_id": "[YOUR TEMPLATE ID GOES HERE]",
+ "tracking_settings": {
+ "click_tracking": {
+ "enable": true,
+ "enable_text": true
+ },
+ "ganalytics": {
+ "enable": true,
+ "utm_campaign": "[NAME OF YOUR REFERRER SOURCE]",
+ "utm_content": "[USE THIS SPACE TO DIFFERENTIATE YOUR EMAIL FROM ADS]",
+ "utm_medium": "[NAME OF YOUR MARKETING MEDIUM e.g. email]",
+ "utm_name": "[NAME OF YOUR CAMPAIGN]",
+ "utm_term": "[IDENTIFY PAID KEYWORDS HERE]"
+ },
+ "open_tracking": {
+ "enable": true,
+ "substitution_tag": "%opentrack"
+ },
+ "subscription_tracking": {
+ "enable": true,
+ "html": "If you would like to unsubscribe and stop receiving these emails <% clickhere %>.",
+ "substitution_tag": "<%click here%>",
+ "text": "If you would like to unsubscribe and stop receiveing these emails <% click here %>."
+ }
+ }
+}');
+$response = $sg->client->mail()->send()->post($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
diff --git a/examples/mailboxproviders/mailboxproviders.php b/examples/mailboxproviders/mailboxproviders.php
new file mode 100644
index 0000000..5b1f3cc
--- /dev/null
+++ b/examples/mailboxproviders/mailboxproviders.php
@@ -0,0 +1,18 @@
+<?php
+// If you are using Composer
+require 'vendor/autoload.php';
+
+
+$apiKey = getenv('SENDGRID_API_KEY');
+$sg = new \SendGrid($apiKey);
+
+////////////////////////////////////////////////////
+// Retrieve email statistics by mailbox provider. #
+// GET /mailbox_providers/stats #
+
+$query_params = json_decode('{"end_date": "2016-04-01", "mailbox_providers": "test_string", "aggregated_by": "day", "limit": 1, "offset": 1, "start_date": "2016-01-01"}');
+$response = $sg->client->mailbox_providers()->stats()->get(null, $query_params);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
diff --git a/examples/mailsettings/mailsettings.php b/examples/mailsettings/mailsettings.php
new file mode 100644
index 0000000..3e9f75b
--- /dev/null
+++ b/examples/mailsettings/mailsettings.php
@@ -0,0 +1,221 @@
+<?php
+// If you are using Composer
+require 'vendor/autoload.php';
+
+
+$apiKey = getenv('SENDGRID_API_KEY');
+$sg = new \SendGrid($apiKey);
+
+////////////////////////////////////////////////////
+// Retrieve all mail settings #
+// GET /mail_settings #
+
+$query_params = json_decode('{"limit": 1, "offset": 1}');
+$response = $sg->client->mail_settings()->get(null, $query_params);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Update address whitelist mail settings #
+// PATCH /mail_settings/address_whitelist #
+
+$request_body = json_decode('{
+ "enabled": true,
+ "list": [
+ "email1@example.com",
+ "example.com"
+ ]
+}');
+$response = $sg->client->mail_settings()->address_whitelist()->patch($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Retrieve address whitelist mail settings #
+// GET /mail_settings/address_whitelist #
+
+$response = $sg->client->mail_settings()->address_whitelist()->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Update BCC mail settings #
+// PATCH /mail_settings/bcc #
+
+$request_body = json_decode('{
+ "email": "email@example.com",
+ "enabled": false
+}');
+$response = $sg->client->mail_settings()->bcc()->patch($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Retrieve all BCC mail settings #
+// GET /mail_settings/bcc #
+
+$response = $sg->client->mail_settings()->bcc()->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Update bounce purge mail settings #
+// PATCH /mail_settings/bounce_purge #
+
+$request_body = json_decode('{
+ "enabled": true,
+ "hard_bounces": 5,
+ "soft_bounces": 5
+}');
+$response = $sg->client->mail_settings()->bounce_purge()->patch($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Retrieve bounce purge mail settings #
+// GET /mail_settings/bounce_purge #
+
+$response = $sg->client->mail_settings()->bounce_purge()->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Update footer mail settings #
+// PATCH /mail_settings/footer #
+
+$request_body = json_decode('{
+ "enabled": true,
+ "html_content": "...",
+ "plain_content": "..."
+}');
+$response = $sg->client->mail_settings()->footer()->patch($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Retrieve footer mail settings #
+// GET /mail_settings/footer #
+
+$response = $sg->client->mail_settings()->footer()->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Update forward bounce mail settings #
+// PATCH /mail_settings/forward_bounce #
+
+$request_body = json_decode('{
+ "email": "example@example.com",
+ "enabled": true
+}');
+$response = $sg->client->mail_settings()->forward_bounce()->patch($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Retrieve forward bounce mail settings #
+// GET /mail_settings/forward_bounce #
+
+$response = $sg->client->mail_settings()->forward_bounce()->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Update forward spam mail settings #
+// PATCH /mail_settings/forward_spam #
+
+$request_body = json_decode('{
+ "email": "",
+ "enabled": false
+}');
+$response = $sg->client->mail_settings()->forward_spam()->patch($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Retrieve forward spam mail settings #
+// GET /mail_settings/forward_spam #
+
+$response = $sg->client->mail_settings()->forward_spam()->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Update plain content mail settings #
+// PATCH /mail_settings/plain_content #
+
+$request_body = json_decode('{
+ "enabled": false
+}');
+$response = $sg->client->mail_settings()->plain_content()->patch($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Retrieve plain content mail settings #
+// GET /mail_settings/plain_content #
+
+$response = $sg->client->mail_settings()->plain_content()->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Update spam check mail settings #
+// PATCH /mail_settings/spam_check #
+
+$request_body = json_decode('{
+ "enabled": true,
+ "max_score": 5,
+ "url": "url"
+}');
+$response = $sg->client->mail_settings()->spam_check()->patch($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Retrieve spam check mail settings #
+// GET /mail_settings/spam_check #
+
+$response = $sg->client->mail_settings()->spam_check()->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Update template mail settings #
+// PATCH /mail_settings/template #
+
+$request_body = json_decode('{
+ "enabled": true,
+ "html_content": "<% body %>"
+}');
+$response = $sg->client->mail_settings()->template()->patch($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Retrieve legacy template mail settings #
+// GET /mail_settings/template #
+
+$response = $sg->client->mail_settings()->template()->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
diff --git a/examples/partnersettings/partnersettings.php b/examples/partnersettings/partnersettings.php
new file mode 100644
index 0000000..79a652e
--- /dev/null
+++ b/examples/partnersettings/partnersettings.php
@@ -0,0 +1,41 @@
+<?php
+// If you are using Composer
+require 'vendor/autoload.php';
+
+
+$apiKey = getenv('SENDGRID_API_KEY');
+$sg = new \SendGrid($apiKey);
+
+////////////////////////////////////////////////////
+// Returns a list of all partner settings. #
+// GET /partner_settings #
+
+$query_params = json_decode('{"limit": 1, "offset": 1}');
+$response = $sg->client->partner_settings()->get(null, $query_params);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Updates New Relic partner settings. #
+// PATCH /partner_settings/new_relic #
+
+$request_body = json_decode('{
+ "enable_subuser_statistics": true,
+ "enabled": true,
+ "license_key": ""
+}');
+$response = $sg->client->partner_settings()->new_relic()->patch($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Returns all New Relic partner settings. #
+// GET /partner_settings/new_relic #
+
+$response = $sg->client->partner_settings()->new_relic()->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
diff --git a/examples/scopes/scopes.php b/examples/scopes/scopes.php
new file mode 100644
index 0000000..ff2c066
--- /dev/null
+++ b/examples/scopes/scopes.php
@@ -0,0 +1,17 @@
+<?php
+// If you are using Composer
+require 'vendor/autoload.php';
+
+
+$apiKey = getenv('SENDGRID_API_KEY');
+$sg = new \SendGrid($apiKey);
+
+////////////////////////////////////////////////////
+// Retrieve a list of scopes for which this user has access. #
+// GET /scopes #
+
+$response = $sg->client->scopes()->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
diff --git a/examples/stats/stats.php b/examples/stats/stats.php
new file mode 100644
index 0000000..a5bbf60
--- /dev/null
+++ b/examples/stats/stats.php
@@ -0,0 +1,18 @@
+<?php
+// If you are using Composer
+require 'vendor/autoload.php';
+
+
+$apiKey = getenv('SENDGRID_API_KEY');
+$sg = new \SendGrid($apiKey);
+
+////////////////////////////////////////////////////
+// Retrieve global email statistics #
+// GET /stats #
+
+$query_params = json_decode('{"aggregated_by": "day", "limit": 1, "start_date": "2016-01-01", "end_date": "2016-04-01", "offset": 1}');
+$response = $sg->client->stats()->get(null, $query_params);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
diff --git a/examples/subusers/subusers.php b/examples/subusers/subusers.php
new file mode 100644
index 0000000..6ef2090
--- /dev/null
+++ b/examples/subusers/subusers.php
@@ -0,0 +1,171 @@
+<?php
+// If you are using Composer
+require 'vendor/autoload.php';
+
+
+$apiKey = getenv('SENDGRID_API_KEY');
+$sg = new \SendGrid($apiKey);
+
+////////////////////////////////////////////////////
+// Create Subuser #
+// POST /subusers #
+
+$request_body = json_decode('{
+ "email": "John@example.com",
+ "ips": [
+ "1.1.1.1",
+ "2.2.2.2"
+ ],
+ "password": "johns_password",
+ "username": "John@example.com"
+}');
+$response = $sg->client->subusers()->post($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// List all Subusers #
+// GET /subusers #
+
+$query_params = json_decode('{"username": "test_string", "limit": 0, "offset": 0}');
+$response = $sg->client->subusers()->get(null, $query_params);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Retrieve Subuser Reputations #
+// GET /subusers/reputations #
+
+$query_params = json_decode('{"usernames": "test_string"}');
+$response = $sg->client->subusers()->reputations()->get(null, $query_params);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Retrieve email statistics for your subusers. #
+// GET /subusers/stats #
+
+$query_params = json_decode('{"end_date": "2016-04-01", "aggregated_by": "day", "limit": 1, "offset": 1, "start_date": "2016-01-01", "subusers": "test_string"}');
+$response = $sg->client->subusers()->stats()->get(null, $query_params);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Retrieve monthly stats for all subusers #
+// GET /subusers/stats/monthly #
+
+$query_params = json_decode('{"subuser": "test_string", "limit": 1, "sort_by_metric": "test_string", "offset": 1, "date": "test_string", "sort_by_direction": "asc"}');
+$response = $sg->client->subusers()->stats()->monthly()->get(null, $query_params);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Retrieve the totals for each email statistic metric for all subusers. #
+// GET /subusers/stats/sums #
+
+$query_params = json_decode('{"end_date": "2016-04-01", "aggregated_by": "day", "limit": 1, "sort_by_metric": "test_string", "offset": 1, "start_date": "2016-01-01", "sort_by_direction": "asc"}');
+$response = $sg->client->subusers()->stats()->sums()->get(null, $query_params);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Enable/disable a subuser #
+// PATCH /subusers/{subuser_name} #
+
+$request_body = json_decode('{
+ "disabled": false
+}');
+$subuser_name = "test_url_param";
+$response = $sg->client->subusers()->_($subuser_name)->patch($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Delete a subuser #
+// DELETE /subusers/{subuser_name} #
+
+$subuser_name = "test_url_param";
+$response = $sg->client->subusers()->_($subuser_name)->delete($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Update IPs assigned to a subuser #
+// PUT /subusers/{subuser_name}/ips #
+
+$request_body = json_decode('[
+ "127.0.0.1"
+]');
+$subuser_name = "test_url_param";
+$response = $sg->client->subusers()->_($subuser_name)->ips()->put($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Update Monitor Settings for a subuser #
+// PUT /subusers/{subuser_name}/monitor #
+
+$request_body = json_decode('{
+ "email": "example@example.com",
+ "frequency": 500
+}');
+$subuser_name = "test_url_param";
+$response = $sg->client->subusers()->_($subuser_name)->monitor()->put($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Create monitor settings #
+// POST /subusers/{subuser_name}/monitor #
+
+$request_body = json_decode('{
+ "email": "example@example.com",
+ "frequency": 50000
+}');
+$subuser_name = "test_url_param";
+$response = $sg->client->subusers()->_($subuser_name)->monitor()->post($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Retrieve monitor settings for a subuser #
+// GET /subusers/{subuser_name}/monitor #
+
+$subuser_name = "test_url_param";
+$response = $sg->client->subusers()->_($subuser_name)->monitor()->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Delete monitor settings #
+// DELETE /subusers/{subuser_name}/monitor #
+
+$subuser_name = "test_url_param";
+$response = $sg->client->subusers()->_($subuser_name)->monitor()->delete($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Retrieve the monthly email statistics for a single subuser #
+// GET /subusers/{subuser_name}/stats/monthly #
+
+$query_params = json_decode('{"date": "test_string", "sort_by_direction": "asc", "limit": 0, "sort_by_metric": "test_string", "offset": 1}');
+$subuser_name = "test_url_param";
+$response = $sg->client->subusers()->_($subuser_name)->stats()->monthly()->get(null, $query_params);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
diff --git a/examples/suppression/suppression.php b/examples/suppression/suppression.php
new file mode 100644
index 0000000..16d1a38
--- /dev/null
+++ b/examples/suppression/suppression.php
@@ -0,0 +1,175 @@
+<?php
+// If you are using Composer
+require 'vendor/autoload.php';
+
+
+$apiKey = getenv('SENDGRID_API_KEY');
+$sg = new \SendGrid($apiKey);
+
+////////////////////////////////////////////////////
+// Retrieve all blocks #
+// GET /suppression/blocks #
+
+$query_params = json_decode('{"start_time": 1, "limit": 1, "end_time": 1, "offset": 1}');
+$response = $sg->client->suppression()->blocks()->get(null, $query_params);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Delete blocks #
+// DELETE /suppression/blocks #
+
+$response = $sg->client->suppression()->blocks()->delete($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Retrieve a specific block #
+// GET /suppression/blocks/{email} #
+
+$email = "test_url_param";
+$response = $sg->client->suppression()->blocks()->_($email)->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Delete a specific block #
+// DELETE /suppression/blocks/{email} #
+
+$email = "test_url_param";
+$response = $sg->client->suppression()->blocks()->_($email)->delete($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Retrieve all bounces #
+// GET /suppression/bounces #
+
+$query_params = json_decode('{"start_time": 0, "end_time": 0}');
+$response = $sg->client->suppression()->bounces()->get(null, $query_params);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Delete bounces #
+// DELETE /suppression/bounces #
+
+$response = $sg->client->suppression()->bounces()->delete($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Retrieve a Bounce #
+// GET /suppression/bounces/{email} #
+
+$email = "test_url_param";
+$response = $sg->client->suppression()->bounces()->_($email)->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Delete a bounce #
+// DELETE /suppression/bounces/{email} #
+
+$query_params = json_decode('{"email_address": "example@example.com"}');
+$email = "test_url_param";
+$response = $sg->client->suppression()->bounces()->_($email)->delete($request_body, $query_params);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Retrieve all invalid emails #
+// GET /suppression/invalid_emails #
+
+$query_params = json_decode('{"start_time": 1, "limit": 1, "end_time": 1, "offset": 1}');
+$response = $sg->client->suppression()->invalid_emails()->get(null, $query_params);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Delete invalid emails #
+// DELETE /suppression/invalid_emails #
+
+$response = $sg->client->suppression()->invalid_emails()->delete($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Retrieve a specific invalid email #
+// GET /suppression/invalid_emails/{email} #
+
+$email = "test_url_param";
+$response = $sg->client->suppression()->invalid_emails()->_($email)->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Delete a specific invalid email #
+// DELETE /suppression/invalid_emails/{email} #
+
+$email = "test_url_param";
+$response = $sg->client->suppression()->invalid_emails()->_($email)->delete($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Retrieve a specific spam report #
+// GET /suppression/spam_report/{email} #
+
+$email = "test_url_param";
+$response = $sg->client->suppression()->spam_report()->_($email)->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Delete a specific spam report #
+// DELETE /suppression/spam_report/{email} #
+
+$email = "test_url_param";
+$response = $sg->client->suppression()->spam_report()->_($email)->delete($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Retrieve all spam reports #
+// GET /suppression/spam_reports #
+
+$query_params = json_decode('{"start_time": 1, "limit": 1, "end_time": 1, "offset": 1}');
+$response = $sg->client->suppression()->spam_reports()->get(null, $query_params);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Delete spam reports #
+// DELETE /suppression/spam_reports #
+
+$response = $sg->client->suppression()->spam_reports()->delete($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Retrieve all global suppressions #
+// GET /suppression/unsubscribes #
+
+$query_params = json_decode('{"start_time": 1, "limit": 1, "end_time": 1, "offset": 1}');
+$response = $sg->client->suppression()->unsubscribes()->get(null, $query_params);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
diff --git a/examples/templates/templates.php b/examples/templates/templates.php
new file mode 100644
index 0000000..4a6e366
--- /dev/null
+++ b/examples/templates/templates.php
@@ -0,0 +1,132 @@
+<?php
+// If you are using Composer
+require 'vendor/autoload.php';
+
+
+$apiKey = getenv('SENDGRID_API_KEY');
+$sg = new \SendGrid($apiKey);
+
+////////////////////////////////////////////////////
+// Create a transactional template. #
+// POST /templates #
+
+$request_body = json_decode('{
+ "name": "example_name"
+}');
+$response = $sg->client->templates()->post($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Retrieve all transactional templates. #
+// GET /templates #
+
+$response = $sg->client->templates()->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Edit a transactional template. #
+// PATCH /templates/{template_id} #
+
+$request_body = json_decode('{
+ "name": "new_example_name"
+}');
+$template_id = "test_url_param";
+$response = $sg->client->templates()->_($template_id)->patch($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Retrieve a single transactional template. #
+// GET /templates/{template_id} #
+
+$template_id = "test_url_param";
+$response = $sg->client->templates()->_($template_id)->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Delete a template. #
+// DELETE /templates/{template_id} #
+
+$template_id = "test_url_param";
+$response = $sg->client->templates()->_($template_id)->delete($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Create a new transactional template version. #
+// POST /templates/{template_id}/versions #
+
+$request_body = json_decode('{
+ "active": 1,
+ "html_content": "<%body%>",
+ "name": "example_version_name",
+ "plain_content": "<%body%>",
+ "subject": "<%subject%>",
+ "template_id": "ddb96bbc-9b92-425e-8979-99464621b543"
+}');
+$template_id = "test_url_param";
+$response = $sg->client->templates()->_($template_id)->versions()->post($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Edit a transactional template version. #
+// PATCH /templates/{template_id}/versions/{version_id} #
+
+$request_body = json_decode('{
+ "active": 1,
+ "html_content": "<%body%>",
+ "name": "updated_example_name",
+ "plain_content": "<%body%>",
+ "subject": "<%subject%>"
+}');
+$template_id = "test_url_param";
+$version_id = "test_url_param";
+$response = $sg->client->templates()->_($template_id)->versions()->_($version_id)->patch($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Retrieve a specific transactional template version. #
+// GET /templates/{template_id}/versions/{version_id} #
+
+$template_id = "test_url_param";
+$version_id = "test_url_param";
+$response = $sg->client->templates()->_($template_id)->versions()->_($version_id)->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Delete a transactional template version. #
+// DELETE /templates/{template_id}/versions/{version_id} #
+
+$template_id = "test_url_param";
+$version_id = "test_url_param";
+$response = $sg->client->templates()->_($template_id)->versions()->_($version_id)->delete($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Activate a transactional template version. #
+// POST /templates/{template_id}/versions/{version_id}/activate #
+
+$request_body = json_decode('null');
+$template_id = "test_url_param";
+$version_id = "test_url_param";
+$response = $sg->client->templates()->_($template_id)->versions()->_($version_id)->activate()->post($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
diff --git a/examples/trackingsettings/trackingsettings.php b/examples/trackingsettings/trackingsettings.php
new file mode 100644
index 0000000..f6e5605
--- /dev/null
+++ b/examples/trackingsettings/trackingsettings.php
@@ -0,0 +1,112 @@
+<?php
+// If you are using Composer
+require 'vendor/autoload.php';
+
+
+$apiKey = getenv('SENDGRID_API_KEY');
+$sg = new \SendGrid($apiKey);
+
+////////////////////////////////////////////////////
+// Retrieve Tracking Settings #
+// GET /tracking_settings #
+
+$query_params = json_decode('{"limit": 1, "offset": 1}');
+$response = $sg->client->tracking_settings()->get(null, $query_params);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Update Click Tracking Settings #
+// PATCH /tracking_settings/click #
+
+$request_body = json_decode('{
+ "enabled": true
+}');
+$response = $sg->client->tracking_settings()->click()->patch($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Retrieve Click Track Settings #
+// GET /tracking_settings/click #
+
+$response = $sg->client->tracking_settings()->click()->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Update Google Analytics Settings #
+// PATCH /tracking_settings/google_analytics #
+
+$request_body = json_decode('{
+ "enabled": true,
+ "utm_campaign": "website",
+ "utm_content": "",
+ "utm_medium": "email",
+ "utm_source": "sendgrid.com",
+ "utm_term": ""
+}');
+$response = $sg->client->tracking_settings()->google_analytics()->patch($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Retrieve Google Analytics Settings #
+// GET /tracking_settings/google_analytics #
+
+$response = $sg->client->tracking_settings()->google_analytics()->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Update Open Tracking Settings #
+// PATCH /tracking_settings/open #
+
+$request_body = json_decode('{
+ "enabled": true
+}');
+$response = $sg->client->tracking_settings()->open()->patch($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Get Open Tracking Settings #
+// GET /tracking_settings/open #
+
+$response = $sg->client->tracking_settings()->open()->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Update Subscription Tracking Settings #
+// PATCH /tracking_settings/subscription #
+
+$request_body = json_decode('{
+ "enabled": true,
+ "html_content": "html content",
+ "landing": "landing page html",
+ "plain_content": "text content",
+ "replace": "replacement tag",
+ "url": "url"
+}');
+$response = $sg->client->tracking_settings()->subscription()->patch($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Retrieve Subscription Tracking Settings #
+// GET /tracking_settings/subscription #
+
+$response = $sg->client->tracking_settings()->subscription()->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
diff --git a/examples/user/user.php b/examples/user/user.php
new file mode 100644
index 0000000..a043fef
--- /dev/null
+++ b/examples/user/user.php
@@ -0,0 +1,245 @@
+<?php
+// If you are using Composer
+require 'vendor/autoload.php';
+
+
+$apiKey = getenv('SENDGRID_API_KEY');
+$sg = new \SendGrid($apiKey);
+
+////////////////////////////////////////////////////
+// Get a user's account information. #
+// GET /user/account #
+
+$response = $sg->client->user()->account()->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Retrieve your credit balance #
+// GET /user/credits #
+
+$response = $sg->client->user()->credits()->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Update your account email address #
+// PUT /user/email #
+
+$request_body = json_decode('{
+ "email": "example@example.com"
+}');
+$response = $sg->client->user()->email()->put($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Retrieve your account email address #
+// GET /user/email #
+
+$response = $sg->client->user()->email()->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Update your password #
+// PUT /user/password #
+
+$request_body = json_decode('{
+ "new_password": "new_password",
+ "old_password": "old_password"
+}');
+$response = $sg->client->user()->password()->put($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Update a user's profile #
+// PATCH /user/profile #
+
+$request_body = json_decode('{
+ "city": "Orange",
+ "first_name": "Example",
+ "last_name": "User"
+}');
+$response = $sg->client->user()->profile()->patch($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Get a user's profile #
+// GET /user/profile #
+
+$response = $sg->client->user()->profile()->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Cancel or pause a scheduled send #
+// POST /user/scheduled_sends #
+
+$request_body = json_decode('{
+ "batch_id": "YOUR_BATCH_ID",
+ "status": "pause"
+}');
+$response = $sg->client->user()->scheduled_sends()->post($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Retrieve all scheduled sends #
+// GET /user/scheduled_sends #
+
+$response = $sg->client->user()->scheduled_sends()->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Update user scheduled send information #
+// PATCH /user/scheduled_sends/{batch_id} #
+
+$request_body = json_decode('{
+ "status": "pause"
+}');
+$batch_id = "test_url_param";
+$response = $sg->client->user()->scheduled_sends()->_($batch_id)->patch($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Retrieve scheduled send #
+// GET /user/scheduled_sends/{batch_id} #
+
+$batch_id = "test_url_param";
+$response = $sg->client->user()->scheduled_sends()->_($batch_id)->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Delete a cancellation or pause of a scheduled send #
+// DELETE /user/scheduled_sends/{batch_id} #
+
+$batch_id = "test_url_param";
+$response = $sg->client->user()->scheduled_sends()->_($batch_id)->delete($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Update Enforced TLS settings #
+// PATCH /user/settings/enforced_tls #
+
+$request_body = json_decode('{
+ "require_tls": true,
+ "require_valid_cert": false
+}');
+$response = $sg->client->user()->settings()->enforced_tls()->patch($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Retrieve current Enforced TLS settings. #
+// GET /user/settings/enforced_tls #
+
+$response = $sg->client->user()->settings()->enforced_tls()->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Update your username #
+// PUT /user/username #
+
+$request_body = json_decode('{
+ "username": "test_username"
+}');
+$response = $sg->client->user()->username()->put($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Retrieve your username #
+// GET /user/username #
+
+$response = $sg->client->user()->username()->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Update Event Notification Settings #
+// PATCH /user/webhooks/event/settings #
+
+$request_body = json_decode('{
+ "bounce": true,
+ "click": true,
+ "deferred": true,
+ "delivered": true,
+ "dropped": true,
+ "enabled": true,
+ "group_resubscribe": true,
+ "group_unsubscribe": true,
+ "open": true,
+ "processed": true,
+ "spam_report": true,
+ "unsubscribe": true,
+ "url": "url"
+}');
+$response = $sg->client->user()->webhooks()->event()->settings()->patch($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Retrieve Event Webhook settings #
+// GET /user/webhooks/event/settings #
+
+$response = $sg->client->user()->webhooks()->event()->settings()->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Test Event Notification Settings #
+// POST /user/webhooks/event/test #
+
+$request_body = json_decode('{
+ "url": "url"
+}');
+$response = $sg->client->user()->webhooks()->event()->test()->post($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Retrieve Parse Webhook settings #
+// GET /user/webhooks/parse/settings #
+
+$response = $sg->client->user()->webhooks()->parse()->settings()->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Retrieves Inbound Parse Webhook statistics. #
+// GET /user/webhooks/parse/stats #
+
+$query_params = json_decode('{"aggregated_by": "day", "limit": "test_string", "start_date": "2016-01-01", "end_date": "2016-04-01", "offset": "test_string"}');
+$response = $sg->client->user()->webhooks()->parse()->stats()->get(null, $query_params);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
diff --git a/examples/whitelabel/whitelabel.php b/examples/whitelabel/whitelabel.php
new file mode 100644
index 0000000..c0ab694
--- /dev/null
+++ b/examples/whitelabel/whitelabel.php
@@ -0,0 +1,315 @@
+<?php
+// If you are using Composer
+require 'vendor/autoload.php';
+
+
+$apiKey = getenv('SENDGRID_API_KEY');
+$sg = new \SendGrid($apiKey);
+
+////////////////////////////////////////////////////
+// Create a domain whitelabel. #
+// POST /whitelabel/domains #
+
+$request_body = json_decode('{
+ "automatic_security": false,
+ "custom_spf": true,
+ "default": true,
+ "domain": "example.com",
+ "ips": [
+ "192.168.1.1",
+ "192.168.1.2"
+ ],
+ "subdomain": "news",
+ "username": "john@example.com"
+}');
+$response = $sg->client->whitelabel()->domains()->post($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// List all domain whitelabels. #
+// GET /whitelabel/domains #
+
+$query_params = json_decode('{"username": "test_string", "domain": "test_string", "exclude_subusers": "true", "limit": 1, "offset": 1}');
+$response = $sg->client->whitelabel()->domains()->get(null, $query_params);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Get the default domain whitelabel. #
+// GET /whitelabel/domains/default #
+
+$response = $sg->client->whitelabel()->domains()->default()->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// List the domain whitelabel associated with the given user. #
+// GET /whitelabel/domains/subuser #
+
+$response = $sg->client->whitelabel()->domains()->subuser()->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Disassociate a domain whitelabel from a given user. #
+// DELETE /whitelabel/domains/subuser #
+
+$response = $sg->client->whitelabel()->domains()->subuser()->delete($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Update a domain whitelabel. #
+// PATCH /whitelabel/domains/{domain_id} #
+
+$request_body = json_decode('{
+ "custom_spf": true,
+ "default": false
+}');
+$domain_id = "test_url_param";
+$response = $sg->client->whitelabel()->domains()->_($domain_id)->patch($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Retrieve a domain whitelabel. #
+// GET /whitelabel/domains/{domain_id} #
+
+$domain_id = "test_url_param";
+$response = $sg->client->whitelabel()->domains()->_($domain_id)->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Delete a domain whitelabel. #
+// DELETE /whitelabel/domains/{domain_id} #
+
+$domain_id = "test_url_param";
+$response = $sg->client->whitelabel()->domains()->_($domain_id)->delete($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Associate a domain whitelabel with a given user. #
+// POST /whitelabel/domains/{domain_id}/subuser #
+
+$request_body = json_decode('{
+ "username": "jane@example.com"
+}');
+$domain_id = "test_url_param";
+$response = $sg->client->whitelabel()->domains()->_($domain_id)->subuser()->post($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Add an IP to a domain whitelabel. #
+// POST /whitelabel/domains/{id}/ips #
+
+$request_body = json_decode('{
+ "ip": "192.168.0.1"
+}');
+$id = "test_url_param";
+$response = $sg->client->whitelabel()->domains()->_($id)->ips()->post($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Remove an IP from a domain whitelabel. #
+// DELETE /whitelabel/domains/{id}/ips/{ip} #
+
+$id = "test_url_param";
+$ip = "test_url_param";
+$response = $sg->client->whitelabel()->domains()->_($id)->ips()->_($ip)->delete($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Validate a domain whitelabel. #
+// POST /whitelabel/domains/{id}/validate #
+
+$request_body = json_decode('null');
+$id = "test_url_param";
+$response = $sg->client->whitelabel()->domains()->_($id)->validate()->post($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Create an IP whitelabel #
+// POST /whitelabel/ips #
+
+$request_body = json_decode('{
+ "domain": "example.com",
+ "ip": "192.168.1.1",
+ "subdomain": "email"
+}');
+$response = $sg->client->whitelabel()->ips()->post($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Retrieve all IP whitelabels #
+// GET /whitelabel/ips #
+
+$query_params = json_decode('{"ip": "test_string", "limit": 1, "offset": 1}');
+$response = $sg->client->whitelabel()->ips()->get(null, $query_params);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Retrieve an IP whitelabel #
+// GET /whitelabel/ips/{id} #
+
+$id = "test_url_param";
+$response = $sg->client->whitelabel()->ips()->_($id)->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Delete an IP whitelabel #
+// DELETE /whitelabel/ips/{id} #
+
+$id = "test_url_param";
+$response = $sg->client->whitelabel()->ips()->_($id)->delete($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Validate an IP whitelabel #
+// POST /whitelabel/ips/{id}/validate #
+
+$request_body = json_decode('null');
+$id = "test_url_param";
+$response = $sg->client->whitelabel()->ips()->_($id)->validate()->post($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Create a Link Whitelabel #
+// POST /whitelabel/links #
+
+$request_body = json_decode('{
+ "default": true,
+ "domain": "example.com",
+ "subdomain": "mail"
+}');
+$query_params = json_decode('{"limit": 1, "offset": 1}');
+$response = $sg->client->whitelabel()->links()->post($request_body, $query_params);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Retrieve all link whitelabels #
+// GET /whitelabel/links #
+
+$query_params = json_decode('{"limit": 1}');
+$response = $sg->client->whitelabel()->links()->get(null, $query_params);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Retrieve a Default Link Whitelabel #
+// GET /whitelabel/links/default #
+
+$query_params = json_decode('{"domain": "test_string"}');
+$response = $sg->client->whitelabel()->links()->default()->get(null, $query_params);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Retrieve Associated Link Whitelabel #
+// GET /whitelabel/links/subuser #
+
+$query_params = json_decode('{"username": "test_string"}');
+$response = $sg->client->whitelabel()->links()->subuser()->get(null, $query_params);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Disassociate a Link Whitelabel #
+// DELETE /whitelabel/links/subuser #
+
+$query_params = json_decode('{"username": "test_string"}');
+$response = $sg->client->whitelabel()->links()->subuser()->delete($request_body, $query_params);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Update a Link Whitelabel #
+// PATCH /whitelabel/links/{id} #
+
+$request_body = json_decode('{
+ "default": true
+}');
+$id = "test_url_param";
+$response = $sg->client->whitelabel()->links()->_($id)->patch($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Retrieve a Link Whitelabel #
+// GET /whitelabel/links/{id} #
+
+$id = "test_url_param";
+$response = $sg->client->whitelabel()->links()->_($id)->get();
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Delete a Link Whitelabel #
+// DELETE /whitelabel/links/{id} #
+
+$id = "test_url_param";
+$response = $sg->client->whitelabel()->links()->_($id)->delete($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Validate a Link Whitelabel #
+// POST /whitelabel/links/{id}/validate #
+
+$request_body = json_decode('null');
+$id = "test_url_param";
+$response = $sg->client->whitelabel()->links()->_($id)->validate()->post($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
+////////////////////////////////////////////////////
+// Associate a Link Whitelabel #
+// POST /whitelabel/links/{link_id}/subuser #
+
+$request_body = json_decode('{
+ "username": "jane@example.com"
+}');
+$link_id = "test_url_param";
+$response = $sg->client->whitelabel()->links()->_($link_id)->subuser()->post($request_body);
+echo $response->statusCode();
+echo $response->body();
+echo $response->headers();
+
diff --git a/lib/Client.php b/lib/Client.php
deleted file mode 100644
index 5567703..0000000
--- a/lib/Client.php
+++ /dev/null
@@ -1,145 +0,0 @@
-<?php
-
-require 'resources/api_keys.php';
-require 'resources/asm_groups.php';
-require 'resources/asm_suppressions.php';
-require 'resources/global_stats.php';
-
-class Client
-{
- const VERSION = '4.0.4';
-
- protected
- $namespace = 'SendGrid',
- $client,
- $options;
-
- public
- $apiKey,
- $url,
- $endpoint,
- $api_keys,
- $asm_groups,
- $asm_suppressions,
- $version = self::VERSION;
-
- public function __construct($apiKey, $options = array())
- {
- // Check if api key is present
- if (is_string($apiKey)) {
- $this->apiKey = $apiKey;
- $this->options = $options;
- } else {
- throw new InvalidArgumentException('Need an api key!');
- }
-
- $this->options['turn_off_ssl_verification'] = (isset($this->options['turn_off_ssl_verification']) && $this->options['turn_off_ssl_verification'] == true);
- if (!isset($this->options['raise_exceptions'])) {
- $this->options['raise_exceptions'] = true;
- }
- $protocol = isset($this->options['protocol']) ? $this->options['protocol'] : 'https';
- $host = isset($this->options['host']) ? $this->options['host'] : 'api.sendgrid.com';
- $port = isset($this->options['port']) ? $this->options['port'] : '';
-
- $this->url = isset($this->options['url']) ? $this->options['url'] : $protocol . '://' . $host . ($port ? ':' . $port : '');
- if (isset($this->options['endpoint'])) {
- $this->endpoint = $this->options['endpoint'];
- }
- $this->client = $this->prepareHttpClient();
- $this->api_keys = new APIKeys($this);
- $this->asm_groups = new ASMGroups($this);
- $this->asm_suppressions = new ASMSuppressions($this);
- $this->global_stats = new GlobalStats($this);
- }
-
- /**
- * Prepares the HTTP client
- *
- * @return \Guzzle\Http\Client
- */
- private function prepareHttpClient()
- {
- $guzzleOption = array(
- 'request.options' => array(
- 'verify' => !$this->options['turn_off_ssl_verification'],
- 'exceptions' => (isset($this->options['enable_guzzle_exceptions']) && $this->options['enable_guzzle_exceptions'] == true)
- )
- );
-
- $guzzleOption['request.options']['headers'] = array('Authorization' => 'Bearer ' . $this->apiKey, 'Content-Type' => 'application/json', 'Accept'=> '*/*');
-
- // Using http proxy
- if (isset($this->options['proxy'])) {
- $guzzleOption['request.options']['proxy'] = $this->options['proxy'];
- }
-
- $client = new \Guzzle\Http\Client($this->url, $guzzleOption);
- $client->setUserAgent('sendgrid/' . $this->version . ';php');
-
- return $client;
- }
-
- public function setClient($client)
- {
- $this->client = $client;
- }
-
- /**
- * The following *Request functions make the HTTP API requests to SendGrid
- *
- * @param $api is an endpoint object defined in the resources
- * @param $data is array of parameters
- *
- * @return Guzzle Response object: http://guzzle3.readthedocs.org/http-client/response.html
- */
-
- public function postRequest($api, $data)
- {
- $url = $this->url . $api->getEndpoint();
- $response = $this->client->post($url, null, json_encode($data))->send();
- return $response;
- }
-
- public function putRequest($api, $data)
- {
- $url = $this->url . $api->getEndpoint();
- $response = $this->client->put($url, null, json_encode($data))->send();
- return $response;
- }
-
- public function patchRequest($api, $data)
- {
- $url = $this->url . $api->getEndpoint();
- $response = $this->client->patch($url, null, json_encode($data))->send();
- return $response;
- }
-
- public function getRequest($api){
- $url = $this->url . $api->getEndpoint();
- $response = $this->client->get($url)->send();
- return $response;
- }
-
- public function deleteRequest($api){
- $url = $this->url . $api->getEndpoint();
- $response = $this->client->delete($url)->send();
- return $response;
- }
-
- public static function register_autoloader()
- {
- spl_autoload_register(array('Client', 'autoloader'));
- }
-
- public static function autoloader($class)
- {
- // Check that the class starts with 'Client'
- if ($class == 'Client' || stripos($class, 'Client\\') === 0) {
- $file = str_replace('\\', '/', $class);
-
- if (file_exists(dirname(__FILE__) . '/' . $file . '.php')) {
- require_once(dirname(__FILE__) . '/' . $file . '.php');
- }
- }
- }
-}
diff --git a/lib/SendGrid.php b/lib/SendGrid.php
index 72b189b..1f6bdc4 100644
--- a/lib/SendGrid.php
+++ b/lib/SendGrid.php
@@ -1,161 +1,43 @@
<?php
-
+/**
+ * This library allows you to quickly and easily send emails through SendGrid using PHP.
+ *
+ * PHP version 5.3
+ *
+ * @author Elmer Thomas <dx@sendgrid.com>
+ * @copyright 2016 SendGrid
+ * @license https://opensource.org/licenses/MIT The MIT License
+ * @version GIT: <git_id>
+ * @link http://packagist.org/packages/sendgrid/sendgrid
+ */
+
+/**
+ * Interface to the SendGrid Web API
+ */
class SendGrid
{
- const VERSION = '4.0.4';
+ const VERSION = '5.0.0';
protected
- $namespace = 'SendGrid',
- $headers = array('Content-Type' => 'application/json', 'Accept'=> '*/*'),
- $client,
- $options;
+ $namespace = 'SendGrid';
public
- $apiUser,
- $apiKey,
- $url,
- $endpoint,
+ $client,
$version = self::VERSION;
- public function __construct($apiUserOrKey, $apiKeyOrOptions = null, $options = array())
- {
- // Check if given a username + password or api key
- if (is_string($apiKeyOrOptions)) {
- // Username and password
- $this->apiUser = $apiUserOrKey;
- $this->apiKey = $apiKeyOrOptions;
- $this->options = $options;
- } elseif (is_array($apiKeyOrOptions) || $apiKeyOrOptions === null) {
- // API key
- $this->apiKey = $apiUserOrKey;
- $this->apiUser = null;
-
- // With options
- if (is_array($apiKeyOrOptions)) {
- $this->options = $apiKeyOrOptions;
- }
- } else {
- // Won't be thrown?
- throw new InvalidArgumentException('Need a username + password or api key!');
- }
-
- $this->options['turn_off_ssl_verification'] = (isset($this->options['turn_off_ssl_verification']) && $this->options['turn_off_ssl_verification'] == true);
- if (!isset($this->options['raise_exceptions'])) {
- $this->options['raise_exceptions'] = true;
- }
- $protocol = isset($this->options['protocol']) ? $this->options['protocol'] : 'https';
- $host = isset($this->options['host']) ? $this->options['host'] : 'api.sendgrid.com';
- $port = isset($this->options['port']) ? $this->options['port'] : '';
-
- $this->url = isset($this->options['url']) ? $this->options['url'] : $protocol . '://' . $host . ($port ? ':' . $port : '');
- $this->endpoint = isset($this->options['endpoint']) ? $this->options['endpoint'] : '/api/mail.send.json';
-
- $this->client = $this->prepareHttpClient();
- }
-
/**
- * Prepares the HTTP client
- *
- * @return \Guzzle\Http\Client
- */
- private function prepareHttpClient()
+ * Setup the HTTP Client
+ *
+ * @param string $apiKey your SendGrid API Key.
+ * @param array $options an array of options, currenlty only "host" is implemented.
+ */
+ public function __construct($apiKey, $options = array())
{
- $guzzleOption = array(
- 'request.options' => array(
- 'verify' => !$this->options['turn_off_ssl_verification'],
- 'exceptions' => (isset($this->options['enable_guzzle_exceptions']) && $this->options['enable_guzzle_exceptions'] == true)
- )
- );
-
- // Using api key
- if ($this->apiUser === null) {
- $guzzleOption['request.options']['headers'] = array('Authorization' => 'Bearer ' . $this->apiKey);
- }
-
- // Using http proxy
- if (isset($this->options['proxy'])) {
- $guzzleOption['request.options']['proxy'] = $this->options['proxy'];
- }
-
- // Using timeout
- if (isset($this->options['timeout'])) {
- $guzzleOption['request.options']['timeout'] = $this->options['timeout'];
- }
-
- $client = new \Guzzle\Http\Client($this->url, $guzzleOption);
- $client->setUserAgent('sendgrid/' . $this->version . ';php');
-
- return $client;
- }
-
- /**
- * @return array The protected options array
- */
- public function getOptions()
- {
- return $this->options;
- }
-
- /**
- * Makes a post request to SendGrid to send an email
- *
- * @param SendGrid\Email $email Email object built
- *
- * @throws SendGrid\Exception if the response code is not 200
- * @return stdClass SendGrid response object
- */
- public function send(SendGrid\Email $email)
- {
- $form = $email->toWebFormat();
-
- // Using username password
- if ($this->apiUser !== null) {
- $form['api_user'] = $this->apiUser;
- $form['api_key'] = $this->apiKey;
- }
-
- $response = $this->postRequest($this->endpoint, $form);
-
- if ($response->code != 200 && $this->options['raise_exceptions']) {
- throw new SendGrid\Exception($response->raw_body, $response->code);
- }
-
- return $response;
- }
-
- /**
- * Makes the actual HTTP request to SendGrid
- *
- * @param $endpoint string endpoint to post to
- * @param $form array web ready version of SendGrid\Email
- *
- * @return SendGrid\Response
- */
- public function postRequest($endpoint, $form)
- {
- $req = $this->client->post($endpoint, null, $form);
-
- $res = $req->send();
-
- $response = new SendGrid\Response($res->getStatusCode(), $res->getHeaders(), $res->getBody(true), $res->json());
-
- return $response;
- }
-
- public static function register_autoloader()
- {
- spl_autoload_register(array('SendGrid', 'autoloader'));
- }
-
- public static function autoloader($class)
- {
- // Check that the class starts with 'SendGrid'
- if ($class == 'SendGrid' || stripos($class, 'SendGrid\\') === 0) {
- $file = str_replace('\\', '/', $class);
-
- if (file_exists(dirname(__FILE__) . '/' . $file . '.php')) {
- require_once(dirname(__FILE__) . '/' . $file . '.php');
- }
- }
+ $headers = array(
+ 'Authorization: Bearer '.$apiKey,
+ 'User-Agent: sendgrid/' . $this->version . ';php'
+ );
+ $host = isset($options['host']) ? $options['host'] : 'https://api.sendgrid.com';
+ $this->client = new \SendGrid\Client($host, $headers, '/v3', null);
}
}
diff --git a/lib/SendGrid/Email.php b/lib/SendGrid/Email.php
deleted file mode 100644
index 6c6451a..0000000
--- a/lib/SendGrid/Email.php
+++ /dev/null
@@ -1,692 +0,0 @@
-<?php
-
-namespace SendGrid;
-
-class Email
-{
- public
- $to,
- $toName,
- $from,
- $fromName,
- $replyTo,
- $cc,
- $ccName,
- $bcc,
- $bccName,
- $subject,
- $text,
- $html,
- $date,
- $content,
- $headers,
- $smtpapi,
- $attachments;
-
- public function __construct()
- {
- $this->fromName = false;
- $this->replyTo = false;
- $this->smtpapi = new \Smtpapi\Header();
- }
-
- /**
- * _removeFromList
- * Given a list of key/value pairs, removes the associated keys
- * where a value matches the given string ($item)
- *
- * @param Array $list - the list of key/value pairs
- * @param String $item - the value to be removed
- */
- private function _removeFromList(&$list, $item, $key_field = null)
- {
- foreach ($list as $key => $val) {
- if ($key_field) {
- if ($val[$key_field] == $item) {
- unset($list[$key]);
- }
- } else {
- if ($val == $item) {
- unset($list[$key]);
- }
- }
- }
- //repack the indices
- $list = array_values($list);
- }
-
- public function addTo($email, $name = null)
- {
- if ($this->to == null) {
- $this->to = array();
- }
-
- if (is_array($email)) {
- foreach ($email as $e) {
- $this->to[] = $e;
- }
- } else {
- $this->to[] = $email;
- }
-
- if (is_array($name)) {
- foreach ($name as $n) {
- $this->addToName($n);
- }
- } elseif ($name) {
- $this->addToName($name);
- }
-
- return $this;
- }
-
- public function addSmtpapiTo($email, $name = null)
- {
- $this->smtpapi->addTo($email, $name);
-
- return $this;
- }
-
- public function setTos(array $emails)
- {
- $this->to = $emails;
-
- return $this;
- }
-
- public function setSmtpapiTos(array $emails)
- {
- $this->smtpapi->setTos($emails);
-
- return $this;
- }
-
- public function addToName($name)
- {
- if ($this->toName == null) {
- $this->toName = array();
- }
-
- $this->toName[] = $name;
-
- return $this;
- }
-
- public function getToNames()
- {
- return $this->toName;
- }
-
- public function setFrom($email)
- {
- $this->from = $email;
-
- return $this;
- }
-
- public function getFrom($as_array = false)
- {
- if ($as_array && ($name = $this->getFromName())) {
- return array("$this->from" => $name);
- } else {
- return $this->from;
- }
- }
-
- public function setFromName($name)
- {
- $this->fromName = $name;
-
- return $this;
- }
-
- public function getFromName()
- {
- return $this->fromName;
- }
-
- public function setReplyTo($email)
- {
- $this->replyTo = $email;
-
- return $this;
- }
-
- public function getReplyTo()
- {
- return $this->replyTo;
- }
-
- public function setCc($email)
- {
- $this->cc = array($email);
-
- return $this;
- }
-
- public function setCcs(array $email_list)
- {
- $this->cc = $email_list;
-
- return $this;
- }
-
- public function addCc($email, $name = null)
- {
- if ($this->cc == null) {
- $this->cc = array();
- }
-
- if (is_array($email)) {
- foreach ($email as $e) {
- $this->cc[] = $e;
- }
- } else {
- $this->cc[] = $email;
- }
-
- if (is_array($name)) {
- foreach ($name as $n) {
- $this->addCcName($n);
- }
- } elseif ($name) {
- $this->addCcName($name);
- }
-
- return $this;
- }
-
- public function addCcName($name)
- {
- if ($this->ccName == null) {
- $this->ccName = array();
- }
-
- $this->ccName[] = $name;
-
- return $this;
- }
-
- public function removeCc($email)
- {
- $this->_removeFromList($this->cc, $email);
-
- return $this;
- }
-
- public function getCcs()
- {
- return $this->cc;
- }
-
- public function getCcNames()
- {
- return $this->ccName;
- }
-
- public function setBcc($email)
- {
- $this->bcc = array($email);
-
- return $this;
- }
-
- public function setBccs($email_list)
- {
- $this->bcc = $email_list;
-
- return $this;
- }
-
- public function addBcc($email, $name = null)
- {
- if ($this->bcc == null) {
- $this->bcc = array();
- }
-
- if (is_array($email)) {
- foreach ($email as $e) {
- $this->bcc[] = $e;
- }
- } else {
- $this->bcc[] = $email;
- }
-
- if (is_array($name)) {
- foreach ($name as $n) {
- $this->addBccName($n);
- }
- } elseif ($name) {
- $this->addBccName($name);
- }
-
- return $this;
- }
-
- public function addBccName($name)
- {
- if ($this->bccName == null) {
- $this->bccName = array();
- }
-
- $this->bccName[] = $name;
-
- return $this;
- }
-
- public function getBccNames()
- {
- return $this->bccName;
- }
-
- public function removeBcc($email)
- {
- $this->_removeFromList($this->bcc, $email);
-
- return $this;
- }
-
- public function getBccs()
- {
- return $this->bcc;
- }
-
- public function setSubject($subject)
- {
- $this->subject = $subject;
-
- return $this;
- }
-
- public function getSubject()
- {
- return $this->subject;
- }
-
- public function setDate($date)
- {
- $this->date = $date;
-
- return $this;
- }
-
- public function getDate()
- {
- return $this->date;
- }
-
- public function setText($text)
- {
- $this->text = $text;
-
- return $this;
- }
-
- public function getText()
- {
- return $this->text;
- }
-
- public function setHtml($html)
- {
- $this->html = $html;
-
- return $this;
- }
-
- public function getHtml()
- {
- return $this->html;
- }
-
- public function setSendAt($timestamp)
- {
- $this->smtpapi->setSendAt($timestamp);
-
- return $this;
- }
-
- public function setSendEachAt(array $timestamps)
- {
- $this->smtpapi->setSendEachAt($timestamps);
-
- return $this;
- }
-
- public function addSendEachAt($timestamp)
- {
- $this->smtpapi->addSendEachAt($timestamp);
-
- return $this;
- }
-
- /**
- * Convenience method to add template
- *
- * @param string The id of the template
- *
- * @return $this
- */
- public function setTemplateId($templateId)
- {
- $this->addFilter('templates', 'enabled', 1);
- $this->addFilter('templates', 'template_id', $templateId);
-
- return $this;
- }
-
- /** Convenience method to set asm group id
- *
- * @param string the group id
- *
- * @return $this
- */
- public function setAsmGroupId($groupId)
- {
- $this->smtpapi->setASMGroupID($groupId);
-
- return $this;
- }
-
- public function setAttachments(array $files)
- {
- $this->attachments = array();
-
- foreach ($files as $filename => $file) {
- if (is_string($filename)) {
- $this->addAttachment($file, $filename);
- } else {
- $this->addAttachment($file);
- }
- }
-
- return $this;
- }
-
- public function setAttachment($file, $custom_filename = null, $cid = null)
- {
- $this->attachments = array($this->getAttachmentInfo($file, $custom_filename, $cid));
-
- return $this;
- }
-
- public function addAttachment($file, $custom_filename = null, $cid = null)
- {
- $this->attachments[] = $this->getAttachmentInfo($file, $custom_filename, $cid);
-
- return $this;
- }
-
- public function getAttachments()
- {
- return $this->attachments;
- }
-
- public function removeAttachment($file)
- {
- $this->_removeFromList($this->attachments, $file, "file");
-
- return $this;
- }
-
- private function getAttachmentInfo($file, $custom_filename = null, $cid = null)
- {
- $info = pathinfo($file);
- $info['file'] = $file;
- if (!is_null($custom_filename)) {
- $info['custom_filename'] = $custom_filename;
- }
- if ($cid !== null) {
- $info['cid'] = $cid;
- }
-
- return $info;
- }
-
- public function setCategories($categories)
- {
- $this->smtpapi->setCategories($categories);
-
- return $this;
- }
-
- public function setCategory($category)
- {
- $this->smtpapi->setCategory($category);
-
- return $this;
- }
-
- public function addCategory($category)
- {
- $this->smtpapi->addCategory($category);
-
- return $this;
- }
-
- public function removeCategory($category)
- {
- $this->smtpapi->removeCategory($category);
-
- return $this;
- }
-
- public function setSubstitutions($key_value_pairs)
- {
- $this->smtpapi->setSubstitutions($key_value_pairs);
-
- return $this;
- }
-
- public function addSubstitution($from_value, array $to_values)
- {
- $this->smtpapi->addSubstitution($from_value, $to_values);
-
- return $this;
- }
-
- public function setSections(array $key_value_pairs)
- {
- $this->smtpapi->setSections($key_value_pairs);
-
- return $this;
- }
-
- public function addSection($from_value, $to_value)
- {
- $this->smtpapi->addSection($from_value, $to_value);
-
- return $this;
- }
-
- public function setUniqueArgs(array $key_value_pairs)
- {
- $this->smtpapi->setUniqueArgs($key_value_pairs);
-
- return $this;
- }
-
- ## synonym method
- public function setUniqueArguments(array $key_value_pairs)
- {
- $this->smtpapi->setUniqueArgs($key_value_pairs);
-
- return $this;
- }
-
- public function addUniqueArg($key, $value)
- {
- $this->smtpapi->addUniqueArg($key, $value);
-
- return $this;
- }
-
- ## synonym method
- public function addUniqueArgument($key, $value)
- {
- $this->smtpapi->addUniqueArg($key, $value);
-
- return $this;
- }
-
- public function setFilters($filter_settings)
- {
- $this->smtpapi->setFilters($filter_settings);
-
- return $this;
- }
-
- ## synonym method
- public function setFilterSettings($filter_settings)
- {
- $this->smtpapi->setFilters($filter_settings);
-
- return $this;
- }
-
- public function addFilter($filter_name, $parameter_name, $parameter_value)
- {
- $this->smtpapi->addFilter($filter_name, $parameter_name, $parameter_value);
-
- return $this;
- }
-
- ## synonym method
- public function addFilterSetting($filter_name, $parameter_name, $parameter_value)
- {
- $this->smtpapi->addFilter($filter_name, $parameter_name, $parameter_value);
-
- return $this;
- }
-
- public function getHeaders()
- {
- return $this->headers;
- }
-
- public function getHeadersJson()
- {
- if (count($this->getHeaders()) <= 0) {
- return "{}";
- }
-
- return json_encode($this->getHeaders(), JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP);
- }
-
- public function setHeaders($key_value_pairs)
- {
- $this->headers = $key_value_pairs;
-
- return $this;
- }
-
- public function addHeader($key, $value)
- {
- $this->headers[$key] = $value;
-
- return $this;
- }
-
- public function removeHeader($key)
- {
- unset($this->headers[$key]);
-
- return $this;
- }
-
- public function getSmtpapi()
- {
- return $this->smtpapi;
- }
-
- public function toWebFormat()
- {
- $web = array(
- 'to' => $this->to,
- 'from' => $this->getFrom(),
- 'x-smtpapi' => $this->smtpapi->jsonString(),
- 'subject' => $this->getSubject(),
- 'text' => $this->getText(),
- 'html' => $this->getHtml(),
- 'headers' => $this->getHeadersJson(),
- );
-
- if ($this->getToNames()) {
- $web['toname'] = $this->getToNames();
- }
- if ($this->getCcs()) {
- $web['cc'] = $this->getCcs();
- }
- if ($this->getCcNames()) {
- $web['ccname'] = $this->getCcNames();
- }
- if ($this->getBccs()) {
- $web['bcc'] = $this->getBccs();
- }
- if ($this->getBccNames()) {
- $web['bccname'] = $this->getBccNames();
- }
- if ($this->getFromName()) {
- $web['fromname'] = $this->getFromName();
- }
- if ($this->getReplyTo()) {
- $web['replyto'] = $this->getReplyTo();
- }
- if ($this->getDate()) {
- $web['date'] = $this->getDate();
- }
- if ($this->smtpapi->to && (count($this->smtpapi->to) > 0)) {
- $web['to'] = "";
- }
-
- $web = $this->updateMissingTo($web);
-
- if ($this->getAttachments()) {
- foreach ($this->getAttachments() as $f) {
- $file = $f['file'];
- $extension = null;
- if (array_key_exists('extension', $f)) {
- $extension = $f['extension'];
- };
- $filename = $f['filename'];
- $full_filename = $filename;
-
- if (isset($extension)) {
- $full_filename = $filename . '.' . $extension;
- }
- if (array_key_exists('custom_filename', $f)) {
- $full_filename = $f['custom_filename'];
- }
-
- if (array_key_exists('cid', $f)) {
- $web['content[' . $full_filename . ']'] = $f['cid'];
- }
-
- $contents = '@' . $file;
-
- // Guzzle handles this for us.
- // http://guzzle3.readthedocs.org/en/latest/http-client/request.html#post-requests
- // if (class_exists('CurlFile', false)) { // php >= 5.5
- // $contents = new \CurlFile($file, $extension, $filename);
- // }
-
- $web['files[' . $full_filename . ']'] = $contents;
- };
- }
-
- return $web;
- }
-
- /**
- * There needs to be at least 1 to address, or else the mail won't send.
- * This method modifies the data that will be sent via either Rest
- */
- public function updateMissingTo($data)
- {
- if ($this->smtpapi->to && (count($this->smtpapi->to) > 0)) {
- $data['to'] = $this->getFrom();
- }
-
- return $data;
- }
-}
diff --git a/lib/SendGrid/Exception.php b/lib/SendGrid/Exception.php
deleted file mode 100644
index 9fc26e2..0000000
--- a/lib/SendGrid/Exception.php
+++ /dev/null
@@ -1,14 +0,0 @@
-<?php
-
-namespace SendGrid;
-
-/**
- * An exception thrown when SendGrid does not return a 200
- */
-class Exception extends \Exception
-{
- public function getErrors()
- {
- return json_decode($this->message)->errors;
- }
-}
diff --git a/lib/SendGrid/Response.php b/lib/SendGrid/Response.php
deleted file mode 100644
index 077238e..0000000
--- a/lib/SendGrid/Response.php
+++ /dev/null
@@ -1,40 +0,0 @@
-<?php
-
-namespace SendGrid;
-
-class Response
-{
- public
- $code,
- $headers,
- $raw_body,
- $body;
-
- public function __construct($code, $headers, $raw_body, $body)
- {
- $this->code = $code;
- $this->headers = $headers;
- $this->raw_body = $raw_body;
- $this->body = $body;
- }
-
- public function getCode()
- {
- return $this->code;
- }
-
- public function getHeaders()
- {
- return $this->headers;
- }
-
- public function getRawBody()
- {
- return $this->raw_body;
- }
-
- public function getBody()
- {
- return $this->body;
- }
-}
diff --git a/lib/helpers/mail/Mail.php b/lib/helpers/mail/Mail.php
new file mode 100644
index 0000000..8d176b5
--- /dev/null
+++ b/lib/helpers/mail/Mail.php
@@ -0,0 +1,1125 @@
+<?php
+/**
+ * This helper builds the request body for a /mail/send API call.
+ *
+ * PHP version 5.3
+ *
+ * @author Elmer Thomas <dx@sendgrid.com>
+ * @copyright 2016 SendGrid
+ * @license https://opensource.org/licenses/MIT The MIT License
+ * @version GIT: <git_id>
+ * @link http://packagist.org/packages/sendgrid/sendgrid
+ */
+namespace SendGrid;
+
+class ReplyTo implements \jsonSerializable
+{
+ private
+ $email;
+
+ public function __construct($email)
+ {
+ $this->email = $email;
+ }
+
+ public function setEmail($email)
+ {
+ $this->email = $email;
+ }
+
+ public function getEmail()
+ {
+ return $this->email;
+ }
+
+ public function jsonSerialize()
+ {
+ return array_filter(
+ [
+ 'email' => $this->getEmail()
+ ]
+ );
+ }
+}
+
+class ClickTracking implements \jsonSerializable
+{
+ private
+ $enable,
+ $enable_text;
+
+ public function setEnable($enable)
+ {
+ $this->enable = $enable;
+ }
+
+ public function getEnable()
+ {
+ return $this->enable;
+ }
+
+ public function setEnableText($enable_text)
+ {
+ $this->enable_text = $enable_text;
+ }
+
+ public function getEnableText()
+ {
+ return $this->enable_text;
+ }
+
+ public function jsonSerialize()
+ {
+ return array_filter(
+ [
+ 'enable' => $this->getEnable(),
+ 'enable_text' => $this->getEnableText()
+ ]
+ );
+ }
+}
+
+class OpenTracking implements \jsonSerializable
+{
+ private
+ $enable,
+ $substitution_tag;
+
+ public function setEnable($enable)
+ {
+ $this->enable = $enable;
+ }
+
+ public function getEnable()
+ {
+ return $this->enable;
+ }
+
+ public function setSubstitutionTag($substitution_tag)
+ {
+ $this->substitution_tag = $substitution_tag;
+ }
+
+ public function getSubstitutionTag()
+ {
+ return $this->substitution_tag;
+ }
+
+ public function jsonSerialize()
+ {
+ return array_filter(
+ [
+ 'enable' => $this->getEnable(),
+ 'substitution_tag' => $this->getSubstitutionTag()
+ ]
+ );
+ }
+}
+
+class SubscriptionTracking implements \jsonSerializable
+{
+ private
+ $enable,
+ $text,
+ $html,
+ $substitution_tag;
+
+ public function setEnable($enable)
+ {
+ $this->enable = $enable;
+ }
+
+ public function getEnable()
+ {
+ return $this->enable;
+ }
+
+ public function setText($text)
+ {
+ $this->text = $text;
+ }
+
+ public function getText()
+ {
+ return $this->text;
+ }
+
+ public function setHtml($html)
+ {
+ $this->html = $html;
+ }
+
+ public function getHtml()
+ {
+ return $this->html;
+ }
+
+ public function setSubstitutionTag($substitution_tag)
+ {
+ $this->substitution_tag = $substitution_tag;
+ }
+
+ public function getSubstitutionTag()
+ {
+ return $this->substitution_tag;
+ }
+
+ public function jsonSerialize()
+ {
+ return array_filter(
+ [
+ 'enable' => $this->getEnable(),
+ 'text' => $this->getText(),
+ 'html' => $this->getHtml(),
+ 'substitution_tag' => $this->getSubstitutionTag()
+ ]
+ );
+ }
+}
+
+class Ganalytics implements \jsonSerializable
+{
+ private
+ $enable,
+ $utm_source,
+ $utm_medium,
+ $utm_term,
+ $utm_content,
+ $utm_campaign;
+
+ public function setEnable($enable)
+ {
+ $this->enable = $enable;
+ }
+
+ public function getEnable()
+ {
+ return $this->enable;
+ }
+
+ public function setCampaignSource($utm_source)
+ {
+ $this->utm_source = $utm_source;
+ }
+
+ public function getCampaignSource()
+ {
+ return $this->utm_source;
+ }
+
+ public function setCampaignMedium($utm_medium)
+ {
+ $this->utm_medium = $utm_medium;
+ }
+
+ public function getCampaignMedium()
+ {
+ return $this->utm_medium;
+ }
+
+ public function setCampaignTerm($utm_term)
+ {
+ $this->utm_term = $utm_term;
+ }
+
+ public function getCampaignTerm()
+ {
+ return $this->utm_term;
+ }
+
+ public function setCampaignContent($utm_content)
+ {
+ $this->utm_content = $utm_content;
+ }
+
+ public function getCampaignContent()
+ {
+ return $this->utm_content;
+ }
+
+ public function setCampaignName($utm_campaign)
+ {
+ $this->utm_campaign = $utm_campaign;
+ }
+
+ public function getCampaignName()
+ {
+ return $this->utm_campaign;
+ }
+
+ public function jsonSerialize()
+ {
+ return array_filter(
+ [
+ 'enable' => $this->getEnable(),
+ 'utm_source' => $this->getCampaignSource(),
+ 'utm_medium' => $this->getCampaignMedium(),
+ 'utm_term' => $this->getCampaignTerm(),
+ 'utm_content' => $this->getCampaignContent(),
+ 'utm_campaign' => $this->getCampaignName()
+ ]
+ );
+ }
+}
+
+class TrackingSettings implements \jsonSerializable
+{
+ private
+ $click_tracking,
+ $open_tracking,
+ $subscription_tracking,
+ $ganalytics;
+
+ public function setClickTracking($click_tracking)
+ {
+ $this->click_tracking = $click_tracking;
+ }
+
+ public function getClickTracking()
+ {
+ return $this->click_tracking;
+ }
+
+ public function setOpenTracking($open_tracking)
+ {
+ $this->open_tracking = $open_tracking;
+ }
+
+ public function getOpenTracking()
+ {
+ return $this->open_tracking;
+ }
+
+ public function setSubscriptionTracking($subscription_tracking)
+ {
+ $this->subscription_tracking = $subscription_tracking;
+ }
+
+ public function getSubscriptionTracking()
+ {
+ return $this->subscription_tracking;
+ }
+
+ public function setGanalytics($ganalytics)
+ {
+ $this->ganalytics = $ganalytics;
+ }
+
+ public function getGanalytics()
+ {
+ return $this->ganalytics;
+ }
+
+ public function jsonSerialize()
+ {
+ return array_filter(
+ [
+ 'click_tracking' => $this->getClickTracking(),
+ 'open_tracking' => $this->getOpenTracking(),
+ 'subscription_tracking' => $this->getSubscriptionTracking(),
+ 'ganalytics' => $this->getGanalytics()
+ ]
+ );
+ }
+}
+
+class BccSettings implements \jsonSerializable
+{
+ private
+ $enable,
+ $email;
+
+ public function setEnable($enable)
+ {
+ $this->enable = $enable;
+ }
+
+ public function getEnable()
+ {
+ return $this->enable;
+ }
+
+ public function setEmail($email)
+ {
+ $this->email = $email;
+ }
+
+ public function getEmail()
+ {
+ return $this->email;
+ }
+
+ public function jsonSerialize()
+ {
+ return array_filter(
+ [
+ 'enable' => $this->getEnable(),
+ 'email' => $this->getEmail()
+ ]
+ );
+ }
+}
+
+class BypassListManagement implements \jsonSerializable
+{
+ private
+ $enable;
+
+ public function setEnable($enable)
+ {
+ $this->enable = $enable;
+ }
+
+ public function getEnable()
+ {
+ return $this->enable;
+ }
+
+ public function jsonSerialize()
+ {
+ return array_filter(
+ [
+ 'enable' => $this->getEnable()
+ ]
+ );
+ }
+}
+
+class Footer implements \jsonSerializable
+{
+ private
+ $enable,
+ $text,
+ $html;
+
+ public function setEnable($enable)
+ {
+ $this->enable = $enable;
+ }
+
+ public function getEnable()
+ {
+ return $this->enable;
+ }
+
+ public function setText($text)
+ {
+ $this->text = $text;
+ }
+
+ public function getText()
+ {
+ return $this->text;
+ }
+
+ public function setHtml($html)
+ {
+ $this->html = $html;
+ }
+
+ public function getHtml()
+ {
+ return $this->html;
+ }
+
+ public function jsonSerialize()
+ {
+ return array_filter(
+ [
+ 'enable' => $this->getEnable(),
+ 'text' => $this->getText(),
+ 'html' => $this->getHtml()
+ ]
+ );
+ }
+}
+
+class SandBoxMode implements \jsonSerializable
+{
+ private
+ $enable;
+
+ public function setEnable($enable)
+ {
+ $this->enable = $enable;
+ }
+
+ public function getEnable()
+ {
+ return $this->enable;
+ }
+ public function jsonSerialize()
+ {
+ return array_filter(
+ [
+ 'enable' => $this->getEnable()
+ ]
+ );
+ }
+}
+
+class SpamCheck implements \jsonSerializable
+{
+ private
+ $enable,
+ $threshold,
+ $post_to_url;
+
+ public function setEnable($enable)
+ {
+ $this->enable = $enable;
+ }
+
+ public function getEnable()
+ {
+ return $this->enable;
+ }
+
+ public function setThreshold($threshold)
+ {
+ $this->threshold = $threshold;
+ }
+
+ public function getThreshold()
+ {
+ return $this->threshold;
+ }
+
+ public function setPostToUrl($post_to_url)
+ {
+ $this->post_to_url = $post_to_url;
+ }
+
+ public function getPostToUrl()
+ {
+ return $this->post_to_url;
+ }
+
+ public function jsonSerialize()
+ {
+ return array_filter(
+ [
+ 'enable' => $this->getEnable(),
+ 'threshold' => $this->getThreshold(),
+ 'post_to_url' => $this->getPostToUrl()
+ ]
+ );
+ }
+}
+
+class MailSettings implements \jsonSerializable
+{
+ private
+ $bcc,
+ $bypass_list_management,
+ $footer,
+ $sandbox_mode,
+ $spam_check;
+
+ public function setBccSettings($bcc)
+ {
+ $this->bcc = $bcc;
+ }
+
+ public function getBccSettings()
+ {
+ return $this->bcc;
+ }
+
+ public function setBypassListManagement($bypass_list_management)
+ {
+ $this->bypass_list_management = $bypass_list_management;
+ }
+
+ public function getBypassListManagement()
+ {
+ return $this->bypass_list_management;
+ }
+
+ public function setFooter($footer)
+ {
+ $this->footer = $footer;
+ }
+
+ public function getFooter()
+ {
+ return $this->footer;
+ }
+
+ public function setSandboxMode($sandbox_mode)
+ {
+ $this->sandbox_mode = $sandbox_mode;
+ }
+
+ public function getSandboxMode()
+ {
+ return $this->sandbox_mode;
+ }
+
+ public function setSpamCheck($spam_check)
+ {
+ $this->spam_check = $spam_check;
+ }
+
+ public function getSpamCheck()
+ {
+ return $this->spam_check;
+ }
+
+ public function jsonSerialize()
+ {
+ return array_filter(
+ [
+ 'bcc' => $this->getBccSettings(),
+ 'bypass_list_management' => $this->getBypassListManagement(),
+ 'footer' => $this->getFooter(),
+ 'sandbox_mode' => $this->getSandboxMode(),
+ 'spam_check' => $this->getSpamCheck()
+ ]
+ );
+ }
+}
+
+class ASM implements \jsonSerializable
+{
+ private
+ $group_id,
+ $groups_to_display;
+
+ public function setGroupId($group_id)
+ {
+ $this->group_id = $group_id;
+ }
+
+ public function getGroupId()
+ {
+ return $this->group_id;
+ }
+
+ public function setGroupsToDisplay($group_ids)
+ {
+ $this->groups_to_display = $group_ids;
+ }
+
+ public function getGroupsToDisplay()
+ {
+ return $this->groups_to_display;
+ }
+
+ public function jsonSerialize()
+ {
+ return array_filter(
+ [
+ 'group_id' => $this->getGroupId(),
+ 'groups_to_display' => $this->getGroupsToDisplay()
+ ]
+ );
+ }
+}
+
+class Attachment implements \jsonSerializable
+{
+ private
+ $content,
+ $type,
+ $filename,
+ $disposition,
+ $content_id;
+
+ public function setContent($content)
+ {
+ $this->content = $content;
+ }
+
+ public function getContent()
+ {
+ return $this->content;
+ }
+
+ public function setType($type)
+ {
+ $this->type = $type;
+ }
+
+ public function getType()
+ {
+ return $this->type;
+ }
+
+ public function setFilename($filename)
+ {
+ $this->filename = $filename;
+ }
+
+ public function getFilename()
+ {
+ return $this->filename;
+ }
+
+ public function setDisposition($disposition)
+ {
+ $this->disposition = $disposition;
+ }
+
+ public function getDisposition()
+ {
+ return $this->disposition;
+ }
+
+ public function setContentID($content_id)
+ {
+ $this->content_id = $content_id;
+ }
+
+ public function getContentID()
+ {
+ return $this->content_id;
+ }
+
+ public function jsonSerialize()
+ {
+ return array_filter(
+ [
+ 'content' => $this->getContent(),
+ 'type' => $this->getType(),
+ 'filename' => $this->getFilename(),
+ 'disposition' => $this->getDisposition(),
+ 'content_id' => $this->getContentID()
+ ]
+ );
+ }
+}
+
+class Content implements \jsonSerializable
+{
+ private
+ $type,
+ $value;
+
+ public function __construct($type, $value)
+ {
+ $this->type = $type;
+ $this->value = $value;
+ }
+
+ public function setType($type)
+ {
+ $this->type = $type;
+ }
+
+ public function getType()
+ {
+ return $this->type;
+ }
+
+ public function setValue($value)
+ {
+ $this->value = $value;
+ }
+
+ public function getValue()
+ {
+ return $this->value;
+ }
+
+ public function jsonSerialize()
+ {
+ return array_filter(
+ [
+ 'type' => $this->getType(),
+ 'value' => $this->getValue()
+ ]
+ );
+ }
+}
+
+class Personalization implements \jsonSerializable
+{
+ private
+ $tos,
+ $ccs,
+ $bccs,
+ $subject,
+ $headers,
+ $substitutions,
+ $custom_args,
+ $send_at;
+
+ public function addTo($email)
+ {
+ $this->tos[] = $email;
+ }
+
+ public function getTos()
+ {
+ return $this->tos;
+ }
+
+ public function addCc($email)
+ {
+ $this->ccs[] = $email;
+ }
+
+ public function getCcs()
+ {
+ return $this->ccs;
+ }
+
+ public function addBcc($email)
+ {
+ $this->bccs[] = $email;
+ }
+
+ public function getBccs()
+ {
+ return $this->bccs;
+ }
+
+ public function setSubject($subject)
+ {
+ $this->subject = $subject;
+ }
+
+ public function getSubject()
+ {
+ return $this->subject;
+ }
+
+ public function addHeader($key, $value)
+ {
+ $this->headers[$key] = $value;
+ }
+
+ public function getHeaders()
+ {
+ return $this->headers;
+ }
+
+ public function addSubstitution($key, $value)
+ {
+ $this->substitutions[$key] = $value;
+ }
+
+ public function getSubstitutions()
+ {
+ return $this->substitutions;
+ }
+
+ public function addCustomArg($key, $value)
+ {
+ $this->custom_args[$key] = $value;
+ }
+
+ public function getCustomArgs()
+ {
+ return $this->custom_args;
+ }
+
+ public function setSendAt($send_at)
+ {
+ $this->send_at = $send_at;
+ }
+
+ public function getSendAt()
+ {
+ return $this->send_at;
+ }
+
+ public function jsonSerialize()
+ {
+ return array_filter(
+ [
+ 'to' => $this->getTos(),
+ 'cc' => $this->getCcs(),
+ 'bcc' => $this->getBccs(),
+ 'subject' => $this->subject,
+ 'headers' => $this->getHeaders(),
+ 'substitutions' => $this->getSubstitutions(),
+ 'custom_args' => $this->getCustomArgs(),
+ 'send_at' => $this->getSendAt()
+ ]
+ );
+ }
+}
+
+class Email implements \jsonSerializable
+{
+ private
+ $name,
+ $email;
+
+ public function __construct($name, $email)
+ {
+ $this->name = $name;
+ $this->email = $email;
+ }
+
+ public function setName($name)
+ {
+ $this->name = $name;
+ }
+
+ public function getName()
+ {
+ return $this->name;
+ }
+
+ public function setEmail($email)
+ {
+ $this->email = $email;
+ }
+
+ public function getEmail()
+ {
+ return $this->email;
+ }
+
+ public function jsonSerialize()
+ {
+ return array_filter(
+ [
+ 'name' => $this->getName(),
+ 'email' => $this->getEmail()
+ ]
+ );
+ }
+}
+
+/**
+ * The final request body object
+ */
+class Mail implements \jsonSerializable
+{
+ const VERSION = '1.0.0';
+
+ protected
+ $namespace = 'SendGrid';
+
+ public
+ $from,
+ $personalization,
+ $subject,
+ $contents,
+ $attachments,
+ $template_id,
+ $sections,
+ $headers,
+ $categories,
+ $custom_args,
+ $send_at,
+ $batch_id,
+ $asm,
+ $ip_pool_name,
+ $mail_settings,
+ $tracking_settings,
+ $reply_to;
+
+ public function __construct($from = null, $subject = null, $to = null, $content = null)
+ {
+ if (!empty($from) && !empty($subject) && !empty($to) && !empty($content))
+ {
+ $this->setFrom($from);
+ $personalization = new Personalization();
+ $personalization->addTo($to);
+ $this->addPersonalization($personalization);
+ $this->setSubject($subject);
+ $this->addContent($content);
+ }
+
+ }
+
+ public function setFrom($email)
+ {
+ $this->from = $email;
+ }
+
+ public function getFrom()
+ {
+ return $this->from;
+ }
+
+ public function addPersonalization($personalization)
+ {
+ $this->personalization[] = $personalization;
+ }
+
+ public function getPersonalizations()
+ {
+ return $this->personalization;
+ }
+
+ public function setSubject($subject)
+ {
+ $this->subject = $subject;
+ }
+
+ public function getSubject()
+ {
+ return $this->subject;
+ }
+
+ public function addContent($content)
+ {
+ $this->contents[] = $content;
+ }
+
+ public function getContents()
+ {
+ return $this->contents;
+ }
+
+ public function addAttachment($attachment)
+ {
+ $this->attachments[] = $attachment;
+ }
+
+ public function getAttachments()
+ {
+ return $this->attachments;
+ }
+
+ public function setTemplateId($template_id)
+ {
+ $this->template_id = $template_id;
+ }
+
+ public function getTemplateId()
+ {
+ return $this->template_id;
+ }
+
+ public function addSection($key, $value)
+ {
+ $this->sections[$key] = $value;
+ }
+
+ public function getSections()
+ {
+ return $this->sections;
+ }
+
+ public function addHeader($key, $value)
+ {
+ $this->headers[$key] = $value;
+ }
+
+ public function getHeaders()
+ {
+ return $this->headers;
+ }
+
+ public function addCategory($category)
+ {
+ $this->categories[] = $category;
+ }
+
+ public function getCategories()
+ {
+ return $this->categories;
+ }
+
+ public function addCustomArg($key, $value)
+ {
+ $this->custom_args[$key] = $value;
+ }
+
+ public function getCustomArgs()
+ {
+ return $this->custom_args;
+ }
+
+ public function setSendAt($send_at)
+ {
+ $this->send_at = $send_at;
+ }
+
+ public function getSendAt()
+ {
+ return $this->send_at;
+ }
+
+ public function setBatchId($batch_id)
+ {
+ $this->batch_id = $batch_id;
+ }
+
+ public function getBatchId()
+ {
+ return $this->batch_id;
+ }
+
+ public function setASM($asm)
+ {
+ $this->asm = $asm;
+ }
+
+ public function getASM()
+ {
+ return $this->asm;
+ }
+
+ public function setIpPoolName($ip_pool_name)
+ {
+ $this->ip_pool_name = $ip_pool_name;
+ }
+
+ public function getIpPoolName()
+ {
+ return $this->ip_pool_name;
+ }
+
+ public function setMailSettings($mail_settings)
+ {
+ $this->mail_settings = $mail_settings;
+ }
+
+ public function getMailSettings()
+ {
+ return $this->mail_settings;
+ }
+
+ public function setTrackingSettings($tracking_settings)
+ {
+ $this->tracking_settings = $tracking_settings;
+ }
+
+ public function getTrackingSettings()
+ {
+ return $this->tracking_settings;
+ }
+
+ public function setReplyTo($reply_to)
+ {
+ $this->reply_to = $reply_to;
+ }
+
+ public function getReplyTo()
+ {
+ return $this->reply_to;
+ }
+
+ public function jsonSerialize()
+ {
+ return array_filter(
+ [
+ 'from' => $this->getFrom(),
+ 'personalizations' => $this->getPersonalizations(),
+ 'subject' => $this->getSubject(),
+ 'content' => $this->getContents(),
+ 'attachments' => $this->getAttachments(),
+ 'template_id' => $this->getTemplateId(),
+ 'sections' => $this->getSections(),
+ 'headers' => $this->getHeaders(),
+ 'categories' => $this->getCategories(),
+ 'custom_args' => $this->getCustomArgs(),
+ 'send_at' => $this->getSendAt(),
+ 'batch_id' => $this->getBatchId(),
+ 'asm' => $this->getASM(),
+ 'ip_pool_name' => $this->getIpPoolName(),
+ 'mail_settings' => $this->getMailSettings(),
+ 'tracking_settings' => $this->getTrackingSettings(),
+ 'reply_to' => $this->getReplyTo()
+ ]
+ );
+ }
+}
diff --git a/lib/helpers/mail/README.md b/lib/helpers/mail/README.md
new file mode 100644
index 0000000..f0e4746
--- /dev/null
+++ b/lib/helpers/mail/README.md
@@ -0,0 +1,14 @@
+**This helper allows you to quickly and easily build a Mail object for sending email through SendGrid.**
+
+# Quick Start
+
+Run the [example](https://github.com/sendgrid/sendgrid-php/tree/master/examples/helpers/mail) (make sure you have set your environment variable to include your SENDGRID_API_KEY).
+
+```bash
+php examples/helpers/mail/example.php
+```
+
+## Usage
+
+- See the [example](https://github.com/sendgrid/sendgrid-php/tree/master/examples) 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/lib/resources/api_keys.php b/lib/resources/api_keys.php
deleted file mode 100644
index e984f85..0000000
--- a/lib/resources/api_keys.php
+++ /dev/null
@@ -1,76 +0,0 @@
-<?php
-
-class APIKeys
-{
- protected
- $name,
- $scopes,
- $base_endpoint,
- $endpoint,
- $client;
-
- public function __construct($client, $options=NULL)
- {
- $this->name = NULL;
- $this->base_endpoint = "/v3/api_keys";
- $this->endpoint = "/v3/api_keys";
- $this->client = $client;
- }
-
- public function getBaseEndpoint(){
- return $this->base_endpoint;
- }
-
- public function getEndpoint(){
- return $this->endpoint;
- }
-
- public function getName(){
- return $this->name;
- }
-
- public function setEndpoint($endpoint){
- $this->endpoint = $endpoint;
- }
-
- public function get(){
- $this->endpoint = $this->base_endpoint;
- return $this->client->getRequest($this);
- }
-
- public function post($name, $scopes = NULL){
- $this->endpoint = $this->base_endpoint;
- $data = array(
- 'name' => $name,
- );
- if ($scopes)
- $data["scopes"] = $scopes;
-
- return $this->client->postRequest($this, $data);
- }
-
- public function put($api_key_id, $name, $scopes){
- $this->endpoint = $this->base_endpoint;
- $data = array(
- 'name' => $name,
- 'scopes' => $scopes
- );
- $this->endpoint = $this->base_endpoint . "/" . $api_key_id;
- return $this->client->putRequest($this, $data);
- }
-
- public function patch($api_key_id, $name){
- $this->endpoint = $this->base_endpoint;
- $data = array(
- 'name' => $name,
- );
- $this->endpoint = $this->base_endpoint . "/" . $api_key_id;
- return $this->client->patchRequest($this, $data);
- }
-
- public function delete($api_key_id){
- $this->endpoint = $this->base_endpoint;
- $this->endpoint = $this->base_endpoint . "/" . $api_key_id;
- return $this->client->deleteRequest($this);
- }
-} \ No newline at end of file
diff --git a/lib/resources/asm_groups.php b/lib/resources/asm_groups.php
deleted file mode 100644
index c74b1f8..0000000
--- a/lib/resources/asm_groups.php
+++ /dev/null
@@ -1,33 +0,0 @@
-<?php
-
-class ASMGroups
-{
- protected
- $base_endpoint,
- $endpoint,
- $client;
-
- public function __construct($client, $options=NULL)
- {
- $this->name = NULL;
- $this->base_endpoint = "/v3/asm/groups";
- $this->endpoint = "/v3/asm/groups";
- $this->client = $client;
- }
-
- public function getBaseEndpoint(){
- return $this->base_endpoint;
- }
-
- public function getEndpoint(){
- return $this->endpoint;
- }
-
- public function setEndpoint($endpoint){
- $this->endpoint = $endpoint;
- }
-
- public function get(){
- return $this->client->getRequest($this);
- }
-} \ No newline at end of file
diff --git a/lib/resources/asm_suppressions.php b/lib/resources/asm_suppressions.php
deleted file mode 100644
index 30d55ef..0000000
--- a/lib/resources/asm_suppressions.php
+++ /dev/null
@@ -1,51 +0,0 @@
-<?php
-
-class ASMSuppressions
-{
- protected
- $base_endpoint,
- $endpoint,
- $client;
-
- public function __construct($client, $options=NULL)
- {
- $this->base_endpoint = "/v3/asm";
- $this->endpoint = "/v3/asm";
- $this->client = $client;
- }
-
- public function getBaseEndpoint(){
- return $this->base_endpoint;
- }
-
- public function getEndpoint(){
- return $this->endpoint;
- }
-
- public function setEndpoint($endpoint){
- $this->endpoint = $endpoint;
- }
-
- public function get($group_id=Null){
- if ( $group_id != Null ) {
- $this->endpoint = $this->base_endpoint . "/groups/" . $group_id . "/suppressions";
- }
- return $this->client->getRequest($this);
- }
-
- public function post($group_id=Null, $email=Null){
- if ( !is_array($email) ) {
- $email = array($email);
- }
- $this->endpoint = $this->base_endpoint . "/groups/" . $group_id . "/suppressions";
- $data = array(
- 'recipient_emails' => $email,
- );
- return $this->client->postRequest($this, $data);
- }
-
- public function delete($group_id=Null, $email=Null){
- $this->endpoint = $this->base_endpoint . "/groups/" . $group_id . "/suppressions/" . $email;
- return $this->client->deleteRequest($this);
- }
-} \ No newline at end of file
diff --git a/lib/resources/global_stats.php b/lib/resources/global_stats.php
deleted file mode 100644
index b139767..0000000
--- a/lib/resources/global_stats.php
+++ /dev/null
@@ -1,40 +0,0 @@
-<?php
-
-class GlobalStats
-{
- protected
- $base_endpoint,
- $endpoint,
- $client;
-
- public function __construct($client, $options=NULL)
- {
- $this->name = NULL;
- $this->base_endpoint = "/v3/stats";
- $this->endpoint = "/v3/stats";
- $this->client = $client;
- }
-
- public function getBaseEndpoint(){
- return $this->base_endpoint;
- }
-
- public function getEndpoint(){
- return $this->endpoint;
- }
-
- public function setEndpoint($endpoint){
- $this->endpoint = $endpoint;
- }
-
- public function get($start_date, $end_date=Null, $aggregated_by=Null){
- $this->endpoint = $this->base_endpoint . "?start_date=" . $start_date;
- if($end_date != Null){
- $this->endpoint = $this->endpoint . "&end_date=" . $end_date;
- }
- if($aggregated_by != Null){
- $this->endpoint = $this->endpoint . "&aggregated_by=" . $aggregated_by;
- }
- return $this->client->getRequest($this);
- }
-} \ No newline at end of file
diff --git a/test/unit/SendGrid/EmailTest.php b/test/unit/SendGrid/EmailTest.php
deleted file mode 100644
index eb6096b..0000000
--- a/test/unit/SendGrid/EmailTest.php
+++ /dev/null
@@ -1,839 +0,0 @@
-<?php
-
-class SendGridTest_Email extends PHPUnit_Framework_TestCase
-{
-
- public function testConstructionEmail()
- {
- $email = new SendGrid\Email();
- $this->assertEquals(get_class($email), "SendGrid\Email");
- }
-
- public function testConstructionEmailIsSendGridEmail()
- {
- $email = new SendGrid\Email();
- $this->assertEquals(get_class($email), "SendGrid\Email");
- }
-
- public function testAddToWithDeprectedEmailClass()
- {
- $mail = new SendGrid\Email();
-
- $mail->addSmtpapiTo('p1@mailinator.com');
- $this->assertEquals(array('p1@mailinator.com'), $mail->getSmtpapi()->to);
-
- $mail->addSmtpapiTo('p2@mailinator.com');
- $this->assertEquals(array('p1@mailinator.com', 'p2@mailinator.com'), $mail->getSmtpapi()->to);
- }
-
- public function testAddTo()
- {
- $email = new SendGrid\Email();
-
- $email->addTo('p1@mailinator.com');
- $this->assertEquals(array('p1@mailinator.com'), $email->to);
-
- $email->addTo('p2@mailinator.com');
- $this->assertEquals(array('p1@mailinator.com', 'p2@mailinator.com'), $email->to);
- }
-
- public function testAddSmtpapiTo()
- {
- $email = new SendGrid\Email();
-
- $email->addSmtpapiTo('p1@mailinator.com');
- $this->assertEquals(array('p1@mailinator.com'), $email->getSmtpapi()->to);
-
- $email->addSmtpapiTo('p2@mailinator.com');
- $this->assertEquals(array('p1@mailinator.com', 'p2@mailinator.com'), $email->getSmtpapi()->to);
- }
-
- public function testAddToWithName()
- {
- $email = new SendGrid\Email();
-
- $email->addTo('p1@mailinator.com', 'Person One');
- $this->assertEquals(array('p1@mailinator.com'), $email->to);
- $this->assertEquals(array('Person One'), $email->toName);
-
- $email->addTo('p2@mailinator.com');
- $this->assertEquals(array('p1@mailinator.com', 'p2@mailinator.com'), $email->to);
- $this->assertEquals(array('Person One'), $email->toName);
- }
-
- public function testAddSmtpapiToWithName()
- {
- $email = new SendGrid\Email();
-
- $email->addSmtpapiTo('p1@mailinator.com', 'Person One');
- $this->assertEquals(array('Person One <p1@mailinator.com>'), $email->getSmtpapi()->to);
-
- $email->addSmtpapiTo('p2@mailinator.com');
- $this->assertEquals(array('Person One <p1@mailinator.com>', 'p2@mailinator.com'), $email->getSmtpapi()->to);
- }
-
- public function testAddToWithArray()
- {
- $email = new SendGrid\Email();
-
- $email->addTo(array('foo@bar.com', 'bar@bar.com'));
- $this->assertEquals(array('foo@bar.com', 'bar@bar.com'), $email->to);
-
- $email->addTo('baz@bar.com');
- $this->assertEquals(array('foo@bar.com', 'bar@bar.com', 'baz@bar.com'), $email->to);
- }
-
- public function testAddToWithArrayAndName()
- {
- $email = new SendGrid\Email();
-
- $email->addTo(array('foo@bar.com', 'bar@bar.com'), array('Mike Foo', 'Joe Bar'));
- $this->assertEquals(array('Mike Foo', 'Joe Bar'), $email->toName);
-
- $email->addTo('baz@bar.com', 'Ben Baz');
- $this->assertEquals(array('Mike Foo', 'Joe Bar', 'Ben Baz'), $email->toName);
- }
-
- public function testAddToName()
- {
- $email = new SendGrid\Email();
-
- $email->addToName('Foo Bar');
- $this->assertEquals(array('Foo Bar'), $email->toName);
-
- $email->addToName('Baz Bar');
- $this->assertEquals(array('Foo Bar', 'Baz Bar'), $email->toName);
- }
-
-
- public function testSetTos()
- {
- $email = new SendGrid\Email();
-
- $email->setTos(array('foo@bar.com', 'baz@bar.com'));
- $this->assertEquals(array('foo@bar.com', 'baz@bar.com'), $email->to);
- }
-
- public function testSetSmtpapiTo()
- {
- $email = new SendGrid\Email();
-
- $email->setSmtpapiTos(array('p1@mailinator.com'));
- $this->assertEquals(array('p1@mailinator.com'), $email->getSmtpapi()->to);
- }
-
- public function testSetSmtpapiTos()
- {
- $email = new SendGrid\Email();
-
- $email->setSmtpapiTos(array('p1@mailinator.com'));
- $this->assertEquals(array('p1@mailinator.com'), $email->getSmtpapi()->to);
- }
-
- public function testRemoveTo()
- {
- $email = new SendGrid\Email();
-
- $email->addSmtpapiTo('p1@mailinator.com');
- $this->assertEquals(array('p1@mailinator.com'), $email->getSmtpapi()->to);
- }
-
- public function testSetFrom()
- {
- $email = new SendGrid\Email();
-
- $email->setFrom("foo@bar.com");
- $email->setFromName("John Doe");
-
- $this->assertEquals("foo@bar.com", $email->getFrom());
- $this->assertEquals(array("foo@bar.com" => "John Doe"), $email->getFrom(true));
- }
-
- public function testSetFromName()
- {
- $email = new SendGrid\Email();
-
- $this->assertFalse($email->getFromName());
- $email->setFromName("Swift");
- $this->assertEquals("Swift", $email->getFromName());
- }
-
- public function testSetReplyTo()
- {
- $email = new SendGrid\Email();
-
- $this->assertFalse($email->getReplyTo());
- $email->setReplyTo("swift@sendgrid.com");
- $this->assertEquals("swift@sendgrid.com", $email->getReplyTo());
- }
-
- public function testSetCc()
- {
- $email = new SendGrid\Email();
-
- $email->setCc('p1@mailinator.com');
- $email->setCc('p2@mailinator.com');
-
- $this->assertEquals(1, count($email->getCcs()));
- $cc = $email->getCcs();
- $this->assertEquals('p2@mailinator.com', $cc[0]);
- }
-
- public function testSetCcs()
- {
- $email = new SendGrid\Email();
-
- $email->setCcs(array('raz@mailinator.com', 'ber@mailinator.com'));
-
- $this->assertEquals(2, count($email->getCcs()));
-
- $cc = $email->getCcs();
-
- $this->assertEquals('raz@mailinator.com', $cc[0]);
- $this->assertEquals('ber@mailinator.com', $cc[1]);
- }
-
- public function testAddCc()
- {
- $email = new SendGrid\Email();
-
- $email->addCc('foo@bar.com');
- $email->addCc('raz@bar.com');
-
- $this->assertEquals(2, count($email->getCcs()));
-
- $cc = $email->getCcs();
-
- $this->assertEquals('foo@bar.com', $cc[0]);
- $this->assertEquals('raz@bar.com', $cc[1]);
-
- // removeCc removes all occurences of data
- $email->removeCc('raz@bar.com');
-
- $this->assertEquals(1, count($email->getCcs()));
-
- $cc = $email->getCcs();
-
- $this->assertEquals('foo@bar.com', $cc[0]);
- }
-
- public function testAddCcWithName()
- {
- $email = new SendGrid\Email();
-
- $email->addCc('p1@mailinator.com', 'Person One');
- $this->assertEquals(array('p1@mailinator.com'), $email->cc);
- $this->assertEquals(array('Person One'), $email->ccName);
-
- $email->addCc('p2@mailinator.com');
- $this->assertEquals(array('p1@mailinator.com', 'p2@mailinator.com'), $email->cc);
- $this->assertEquals(array('Person One'), $email->ccName);
- }
-
- public function testAddCcName()
- {
- $email = new SendGrid\Email();
-
- $email->addCcName('Foo Bar');
- $this->assertEquals(array('Foo Bar'), $email->ccName);
-
- $email->addCcName('Baz Bar');
- $this->assertEquals(array('Foo Bar', 'Baz Bar'), $email->ccName);
- }
-
- public function testSetBcc()
- {
- $email = new SendGrid\Email();
-
- $email->setBcc('bar');
- $email->setBcc('foo');
- $this->assertEquals(1, count($email->getBccs()));
-
- $bcc = $email->getBccs();
- $this->assertEquals('foo', $bcc[0]);
- }
-
- public function testSetBccs()
- {
- $email = new SendGrid\Email();
-
- $email->setBccs(array('raz', 'ber'));
- $this->assertEquals(2, count($email->getBccs()));
-
- $bcc = $email->getBccs();
- $this->assertEquals('raz', $bcc[0]);
- $this->assertEquals('ber', $bcc[1]);
- }
-
- public function testAddBcc()
- {
- $email = new SendGrid\Email();
-
- $email->addBcc('foo');
- $email->addBcc('raz');
- $this->assertEquals(2, count($email->getBccs()));
-
- $bcc = $email->getBccs();
- $this->assertEquals('foo', $bcc[0]);
- $this->assertEquals('raz', $bcc[1]);
-
- $email->removeBcc('raz');
-
- $this->assertEquals(1, count($email->getBccs()));
- $bcc = $email->getBccs();
- $this->assertEquals('foo', $bcc[0]);
- }
-
- public function testAddBccWithName()
- {
- $email = new SendGrid\Email();
-
- $email->addBcc('p1@mailinator.com', 'Person One');
- $this->assertEquals(array('p1@mailinator.com'), $email->bcc);
- $this->assertEquals(array('Person One'), $email->bccName);
-
- $email->addBcc('p2@mailinator.com');
- $this->assertEquals(array('p1@mailinator.com', 'p2@mailinator.com'), $email->bcc);
- $this->assertEquals(array('Person One'), $email->bccName);
- }
-
- public function testAddBccName()
- {
- $email = new SendGrid\Email();
-
- $email->addBccName('Foo Bar');
- $this->assertEquals(array('Foo Bar'), $email->bccName);
-
- $email->addBccName('Baz Bar');
- $this->assertEquals(array('Foo Bar', 'Baz Bar'), $email->bccName);
- }
-
- public function testSetSubject()
- {
- $email = new SendGrid\Email();
-
- $email->setSubject("Test Subject");
- $this->assertEquals("Test Subject", $email->getSubject());
- }
-
- public function testSetDate()
- {
- $email = new SendGrid\Email();
-
- date_default_timezone_set('America/Los_Angeles');
- $date = date('r');
- $email->setDate($date);
- $this->assertEquals($date, $email->getDate());
- }
-
- public function testSetSendAt()
- {
- $email = new SendGrid\Email();
-
- $email->setSendAt(1409348513);
- $this->assertEquals("{\"send_at\":1409348513}", $email->getSmtpapi()->jsonString());
- }
-
- public function testSetSendEachAt()
- {
- $email = new SendGrid\Email();
-
- $email->setSendEachAt(array(1409348513, 1409348514, 1409348515));
- $this->assertEquals("{\"send_each_at\":[1409348513,1409348514,1409348515]}", $email->getSmtpapi()->jsonString());
- }
-
- public function testAddSendEachAt()
- {
- $email = new SendGrid\Email();
- $email->addSendEachAt(1409348513);
- $email->addSendEachAt(1409348514);
- $email->addSendEachAt(1409348515);
- $this->assertEquals("{\"send_each_at\":[1409348513,1409348514,1409348515]}", $email->getSmtpapi()->jsonString());
- }
-
- public function testSetTemplateId()
- {
- $email = new SendGrid\Email();
- $email->setTemplateId('123-456');
- $filter = array('templates' => array('settings' => array('enabled' => 1, 'template_id' => '123-456')));
- $this->assertEquals($email->smtpapi->getFilters(), $filter);
- }
-
- public function testSetAsmGroupId()
- {
- $email = new SendGrid\Email();
- $email->setAsmGroupId('my_id');
- $this->assertEquals('my_id', $email->smtpapi->asm_group_id);
- }
-
- public function testSetText()
- {
- $email = new SendGrid\Email();
-
- $text = "sample plain text";
- $email->setText($text);
- $this->assertEquals($text, $email->getText());
- }
-
- public function testSetHtml()
- {
- $email = new SendGrid\Email();
-
- $html = "<p style = 'color:red;'>Sample HTML text</p>";
- $email->setHtml($html);
- $this->assertEquals($html, $email->getHtml());
- }
-
- public function testSetAttachments()
- {
- $email = new SendGrid\Email();
-
- $attachments =
- array(
- "path/to/file/file_1.txt",
- "../file_2.txt",
- "../file_3.txt"
- );
-
- $email->setAttachments($attachments);
- $msg_attachments = $email->getAttachments();
- $this->assertEquals(count($attachments), count($msg_attachments));
-
- for($i = 0; $i < count($attachments); $i++) {
- $this->assertEquals($attachments[$i], $msg_attachments[$i]['file']);
- }
- }
-
- public function testSetAttachmentsWithCustomFilename()
- {
- $email = new SendGrid\Email();
-
- $array_of_attachments =
- array(
- "customName.txt" => "path/to/file/file_1.txt",
- 'another_name_|.txt' => "../file_2.txt",
- 'custom_name_2.zip' => "../file_3.txt"
- );
-
- $email->setAttachments($array_of_attachments);
- $attachments = $email->getAttachments();
-
- $this->assertEquals($attachments[0]['custom_filename'], 'customName.txt');
- $this->assertEquals($attachments[1]['custom_filename'], 'another_name_|.txt');
- $this->assertEquals($attachments[2]['custom_filename'], 'custom_name_2.zip');
- }
-
- public function testAddAttachment()
- {
- $email = new SendGrid\Email();
-
- //ensure that addAttachment appends to the list of attachments
- $email->addAttachment("../file_4.png");
-
- $attachments[] = "../file_4.png";
-
- $msg_attachments = $email->getAttachments();
- $this->assertEquals($attachments[count($attachments) - 1], $msg_attachments[count($msg_attachments) - 1]['file']);
- }
-
- public function testAddAttachmentCustomFilename()
- {
- $email = new SendGrid\Email();
-
- $email->addAttachment("../file_4.png", "different.png");
-
- $attachments = $email->getAttachments();
- $this->assertEquals($attachments[0]['custom_filename'], 'different.png');
- $this->assertEquals($attachments[0]['filename'], 'file_4');
- }
-
-
- public function testSetAttachment()
- {
- $email = new SendGrid\Email();
-
- //Setting an attachment removes all other files
- $email->setAttachment("only_attachment.sad");
-
- $this->assertEquals(1, count($email->getAttachments()));
-
- //Remove an attachment
- $email->removeAttachment("only_attachment.sad");
- $this->assertEquals(0, count($email->getAttachments()));
- }
-
- public function testSetAttachmentCustomFilename()
- {
- $email = new SendGrid\Email();
-
- //Setting an attachment removes all other files
- $email->setAttachment("only_attachment.sad", "different");
-
- $attachments = $email->getAttachments();
- $this->assertEquals(1, count($attachments));
- $this->assertEquals($attachments[0]['custom_filename'], 'different');
-
- //Remove an attachment
- $email->removeAttachment("only_attachment.sad");
- $this->assertEquals(0, count($email->getAttachments()));
- }
-
- public function testAddAttachmentWithoutExtension()
- {
- $email = new SendGrid\Email();
-
- //ensure that addAttachment appends to the list of attachments
- $email->addAttachment("../file_4");
-
- $attachments[] = "../file_4";
-
- $msg_attachments = $email->getAttachments();
- $this->assertEquals($attachments[count($attachments) - 1], $msg_attachments[count($msg_attachments) - 1]['file']);
- }
-
- public function testCategoryAccessors()
- {
- $email = new SendGrid\Email();
-
- $email->setCategories(array('category_0'));
- $this->assertEquals("{\"category\":[\"category_0\"]}", $email->getSmtpapi()->jsonString());
-
- $categories = array(
- "category_1",
- "category_2",
- "category_3",
- "category_4"
- );
-
- $email->setCategories($categories);
-
- // uses valid json
- $this->assertEquals("{\"category\":[\"category_1\",\"category_2\",\"category_3\",\"category_4\"]}", $email->getSmtpapi()->jsonString());
- }
-
- public function testSubstitutionAccessors()
- {
- $email = new SendGrid\Email();
-
- $substitutions = array(
- "sub_1" => array("val_1.1", "val_1.2", "val_1.3"),
- "sub_2" => array("val_2.1", "val_2.2"),
- "sub_3" => array("val_3.1", "val_3.2", "val_3.3", "val_3.4"),
- "sub_4" => array("val_4.1", "val_4.2", "val_4.3")
- );
-
- $email->setSubstitutions($substitutions);
-
- $this->assertEquals("{\"sub\":{\"sub_1\":[\"val_1.1\",\"val_1.2\",\"val_1.3\"],\"sub_2\":[\"val_2.1\",\"val_2.2\"],\"sub_3\":[\"val_3.1\",\"val_3.2\",\"val_3.3\",\"val_3.4\"],\"sub_4\":[\"val_4.1\",\"val_4.2\",\"val_4.3\"]}}", $email->getSmtpapi()->jsonString());
- }
-
- public function testSectionAccessors()
- {
- $email = new SendGrid\Email();
-
- $sections = array(
- "sub_1" => array("val_1.1", "val_1.2", "val_1.3"),
- "sub_2" => array("val_2.1", "val_2.2"),
- "sub_3" => array("val_3.1", "val_3.2", "val_3.3", "val_3.4"),
- "sub_4" => array("val_4.1", "val_4.2", "val_4.3")
- );
-
- $email->setSections($sections);
-
- $this->assertEquals("{\"section\":{\"sub_1\":[\"val_1.1\",\"val_1.2\",\"val_1.3\"],\"sub_2\":[\"val_2.1\",\"val_2.2\"],\"sub_3\":[\"val_3.1\",\"val_3.2\",\"val_3.3\",\"val_3.4\"],\"sub_4\":[\"val_4.1\",\"val_4.2\",\"val_4.3\"]}}", $email->getSmtpapi()->jsonString());
- }
-
- public function testUniqueArgsAccessors()
- {
- $email = new SendGrid\Email();
-
- $unique_arguments = array(
- "sub_1" => array("val_1.1", "val_1.2", "val_1.3"),
- "sub_2" => array("val_2.1", "val_2.2"),
- "sub_3" => array("val_3.1", "val_3.2", "val_3.3", "val_3.4"),
- "sub_4" => array("val_4.1", "val_4.2", "val_4.3")
- );
-
- $email->setUniqueArgs($unique_arguments);
-
- $this->assertEquals("{\"unique_args\":{\"sub_1\":[\"val_1.1\",\"val_1.2\",\"val_1.3\"],\"sub_2\":[\"val_2.1\",\"val_2.2\"],\"sub_3\":[\"val_3.1\",\"val_3.2\",\"val_3.3\",\"val_3.4\"],\"sub_4\":[\"val_4.1\",\"val_4.2\",\"val_4.3\"]}}", $email->getSmtpapi()->jsonString());
-
- $email->addUniqueArg('uncle', 'bob');
-
- $this->assertEquals("{\"unique_args\":{\"sub_1\":[\"val_1.1\",\"val_1.2\",\"val_1.3\"],\"sub_2\":[\"val_2.1\",\"val_2.2\"],\"sub_3\":[\"val_3.1\",\"val_3.2\",\"val_3.3\",\"val_3.4\"],\"sub_4\":[\"val_4.1\",\"val_4.2\",\"val_4.3\"],\"uncle\":\"bob\"}}", $email->getSmtpapi()->jsonString());
- }
-
- public function testHeaderAccessors()
- {
- // A new message shouldn't have any RFC-822 headers set
- $message = new SendGrid\Email();
- $this->assertEquals('{}', $message->getSmtpapi()->jsonString());
-
- // Add some message headers, check they are correctly stored
- $headers = array(
- 'X-Sent-Using' => 'SendGrid-API',
- 'X-Transport' => 'web',
- );
- $message->setHeaders($headers);
- $this->assertEquals($headers, $message->getHeaders());
-
- // Add another header, check if it is stored
- $message->addHeader('X-Another-Header', 'first_value');
- $headers['X-Another-Header'] = 'first_value';
- $this->assertEquals($headers, $message->getHeaders());
-
- // Replace a header
- $message->addHeader('X-Another-Header', 'second_value');
- $headers['X-Another-Header'] = 'second_value';
- $this->assertEquals($headers, $message->getHeaders());
-
- // Get the encoded headers; they must be a valid JSON
- $json = $message->getHeadersJson();
- $decoded = json_decode($json, TRUE);
- $this->assertInternalType('array', $decoded);
- // Test we get the same message headers we put in the message
- $this->assertEquals($headers, $decoded);
-
- // Remove a header
- $message->removeHeader('X-Transport');
- unset($headers['X-Transport']);
- $this->assertEquals($headers, $message->getHeaders());
- }
-
- public function testToWebFormatWithDate()
- {
- $email = new SendGrid\Email();
- date_default_timezone_set('America/Los_Angeles');
- $date = date('r');
- $email->setDate($date);
- $json = $email->toWebFormat();
-
- $this->assertEquals($json['date'], $date);
- }
-
- public function testToWebFormatWithSetSendAt()
- {
- $email = new SendGrid\Email();
- $email->setSendAt(1409348513);
- $json = $email->toWebFormat();
- $xsmtpapi = json_decode($json["x-smtpapi"]);
-
- $this->assertEquals(1409348513, $xsmtpapi->send_at);
- }
-
- public function testToWebFormatWithSetSendEachAt()
- {
- $email = new SendGrid\Email();
- $email->setSendEachAt(array(1409348513, 1409348514));
- $json = $email->toWebFormat();
- $xsmtpapi = json_decode($json["x-smtpapi"]);
-
- $this->assertEquals(array(1409348513, 1409348514), $xsmtpapi->send_each_at);
- }
-
- public function testToWebFormatWithAddSendEachAt()
- {
- $email = new SendGrid\Email();
- $email->addSendEachAt(1409348513);
- $email->addSendEachAt(1409348514);
- $json = $email->toWebFormat();
- $xsmtpapi = json_decode($json["x-smtpapi"]);
-
- $this->assertEquals(array(1409348513, 1409348514), $xsmtpapi->send_each_at);
- }
-
- public function testToWebFormatWithToName()
- {
- $email = new SendGrid\Email();
- $email->addTo('foo@bar.com', 'Frank Foo');
- $email->setFrom('from@site.com');
- $json = $email->toWebFormat();
-
- $this->assertEquals($json['toname'], array('Frank Foo'));
- }
-
- public function testToWebFormatWithSmtpapiTo()
- {
- $email = new SendGrid\Email();
- $email->addSmtpapiTo('foo@bar.com');
- $email->setFrom('from@site.com');
- $json = $email->toWebFormat();
- $xsmtpapi = json_decode($json["x-smtpapi"]);
-
- $this->assertEquals($xsmtpapi->to, array('foo@bar.com'));
- $this->assertEquals($json['to'], 'from@site.com');
- }
-
- public function testToWebFormatWithCcName()
- {
- $email = new SendGrid\Email();
- $email->addCc('foo@bar.com', 'Frank Foo');
- $email->setFrom('from@site.com');
- $json = $email->toWebFormat();
-
- $this->assertEquals($json['ccname'], array('Frank Foo'));
- }
-
- public function testToWebFormatWithBccName()
- {
- $email = new SendGrid\Email();
- $email->addBcc('foo@bar.com', 'Frank Foo');
- $email->setFrom('from@site.com');
- $json = $email->toWebFormat();
-
- $this->assertEquals($json['bccname'], array('Frank Foo'));
- }
-
- public function testToWebFormatWithSmtpapiToAndBcc()
- {
- $email = new SendGrid\Email();
- $email->addSmtpapiTo('p1@mailinator.com');
- $email->addBcc('p2@mailinator.com');
- $json = $email->toWebFormat();
-
- $this->assertEquals($json['bcc'], array('p2@mailinator.com'));
- $this->assertEquals($json["x-smtpapi"], '{"to":["p1@mailinator.com"]}');
- }
-
- /*
- * Guzzle handles this for use. Keeping in case we drop guzzle
- *
- public function testToWebFormatWithAttachment()
- {
- $email = new SendGrid\Email();
- $email->addAttachment('./gif.gif');
- $json = $email->toWebFormat();
-
- // php 5.5 works differently. @filename has been deprecated for CurlFile in 5.5
- if (class_exists('CurlFile')) {
- $content = new \CurlFile('./gif.gif', 'gif', 'gif');
- $this->assertEquals($json["files[gif.gif]"], $content);
- } else {
- $this->assertEquals($json["files[gif.gif]"], "@./gif.gif");
- }
- }
- */
-
- public function testToWebFormatWithAttachment()
- {
- $email = new SendGrid\Email();
- $email->addAttachment('./gif.gif');
- $json = $email->toWebFormat();
-
- $this->assertEquals($json["files[gif.gif]"], "@./gif.gif");
- }
-
- /*
- * Guzzle handles this for use. Keeping in case we drop guzzle
- *
- public function testToWebFormatWithAttachmentAndCid()
- {
- $email = new SendGrid\Email();
- $email->addAttachment('./gif.gif', null, 'sample-cid');
- $email->addAttachment('./gif.gif', 'gif2.gif', 'sample-cid-2');
- $json = $email->toWebFormat();
-
- // php 5.5 works differently. @filename has been deprecated for CurlFile in 5.5
- if (class_exists('CurlFile')) {
- $content = new \CurlFile('./gif.gif', 'gif', 'gif');
- $this->assertEquals($json["files[gif.gif]"], $content);
- } else {
- $this->assertEquals($json["files[gif.gif]"], "@./gif.gif");
- }
- $this->assertEquals($json["content[gif.gif]"], "sample-cid");
- $this->assertEquals($json["content[gif2.gif]"], "sample-cid-2");
- }
- */
-
- public function testToWebFormatWithAttachmentAndCid()
- {
- $email = new SendGrid\Email();
- $email->addAttachment('./gif.gif', null, 'sample-cid');
- $email->addAttachment('./gif.gif', 'gif2.gif', 'sample-cid-2');
- $json = $email->toWebFormat();
-
- $this->assertEquals($json["files[gif.gif]"], "@./gif.gif");
- $this->assertEquals($json["content[gif.gif]"], "sample-cid");
- $this->assertEquals($json["content[gif2.gif]"], "sample-cid-2");
- }
-
-
- /*
- * Guzzle handles this for use. Keeping in case we drop guzzle
- *
- public function testToWebFormatWithSetAttachmentAndCid()
- {
- $email = new SendGrid\Email();
- $email->setAttachment('./gif.gif', null, 'sample-cid');
- $json = $email->toWebFormat();
-
- // php 5.5 works differently. @filename has been deprecated for CurlFile in 5.5
- if (class_exists('CurlFile')) {
- $content = new \CurlFile('./gif.gif', 'gif', 'gif');
- $this->assertEquals($json["files[gif.gif]"], $content);
- } else {
- $this->assertEquals($json["files[gif.gif]"], "@./gif.gif");
- }
- $this->assertEquals($json["content[gif.gif]"], "sample-cid");
- }
- */
-
- public function testToWebFormatWithSetAttachmentAndCid()
- {
- $email = new SendGrid\Email();
- $email->setAttachment('./gif.gif', null, 'sample-cid');
- $json = $email->toWebFormat();
-
- $this->assertEquals($json["files[gif.gif]"], "@./gif.gif");
- $this->assertEquals($json["content[gif.gif]"], "sample-cid");
- }
-
-
- /*
- * Guzzle handles this for use. Keeping in case we drop guzzle
- *
- public function testToWebFormatWithAttachmentCustomFilename()
- {
- $email = new SendGrid\Email();
- $email->addAttachment('./gif.gif', 'different.jpg');
- $json = $email->toWebFormat();
-
- // php 5.5 works differently. @filename has been deprecated for CurlFile in 5.5
- if (class_exists('CurlFile')) {
- $content = new \CurlFile('./gif.gif', 'gif', 'gif');
- $this->assertEquals($json["files[different.jpg]"], $content);
- } else {
- $this->assertEquals($json["files[different.jpg]"], "@./gif.gif");
- }
- }
- */
-
- public function testToWebFormatWithAttachmentCustomFilename()
- {
- $email = new SendGrid\Email();
- $email->addAttachment('./gif.gif', 'different.jpg');
- $json = $email->toWebFormat();
-
- $this->assertEquals($json["files[different.jpg]"], "@./gif.gif");
- }
-
- public function testToWebFormatWithHeaders()
- {
- $email = new SendGrid\Email();
- $email->addHeader('X-Sent-Using', 'SendGrid-API');
- $json = $email->toWebFormat();
-
- $headers = json_decode($json['headers'], TRUE);
- $this->assertEquals('SendGrid-API', $headers['X-Sent-Using']);
- }
-
- public function testToWebFormatWithFilters()
- {
- $email = new SendGrid\Email();
- $email->addFilter("footer", "text/plain", "Here is a plain text footer");
- $json = $email->toWebFormat();
-
- $xsmtpapi = json_decode($json['x-smtpapi'], TRUE);
- $this->assertEquals('Here is a plain text footer', $xsmtpapi['filters']['footer']['settings']['text/plain']);
- }
-}
diff --git a/test/unit/SendGrid/ExceptionTest.php b/test/unit/SendGrid/ExceptionTest.php
deleted file mode 100644
index bc657c3..0000000
--- a/test/unit/SendGrid/ExceptionTest.php
+++ /dev/null
@@ -1,28 +0,0 @@
-<?php
-
-class SendGridTest_Exception extends PHPUnit_Framework_TestCase
-{
-
- public function tearDown()
- {
- }
-
- public function testConstructionException()
- {
- $err = new SendGrid\Exception();
- $this->assertEquals(get_class($err), 'SendGrid\Exception');
- }
-
- // public function testGetErrors()
- // {
- // $mockResponse = new SendGrid\Response(400, "{'message': 'error', 'errors': ['Bad username / password']}");
- // $res = new SendGrid\Response(200, 'headers', 'raw_body', 'body');
- // try {
- // throw new SendGrid\Exception(json_decode("{'message': 'error', 'errors': ['Bad username / password']}"));
- // } catch (SendGrid\Exception $e) {
- // var_dump($e->getErrors());
- // }
- // // $this->assertEquals($err->getErrors()[0], 'Bad username / password');
- // }
-
-}
diff --git a/test/unit/SendGrid/ResponseTest.php b/test/unit/SendGrid/ResponseTest.php
deleted file mode 100644
index 2241590..0000000
--- a/test/unit/SendGrid/ResponseTest.php
+++ /dev/null
@@ -1,34 +0,0 @@
-<?php
-
-class SendGridTest_Response extends PHPUnit_Framework_TestCase
-{
-
- public function tearDown()
- {
- }
-
- public function testConstructionResponse()
- {
- $res = new SendGrid\Response(200, 'headers', 'raw_body', 'body');
- $this->assertEquals(get_class($res), 'SendGrid\Response');
- }
-
- public function testPublicAttributes()
- {
- $res = new SendGrid\Response(200, 'headers', 'raw_body', 'body');
- $this->assertEquals($res->code, 200);
- $this->assertEquals($res->headers, 'headers');
- $this->assertEquals($res->raw_body, 'raw_body');
- $this->assertEquals($res->body, 'body');
- }
-
- public function testGetters()
- {
- $res = new SendGrid\Response(200, 'headers', 'raw_body', 'body');
- $this->assertEquals($res->getCode(), 200);
- $this->assertEquals($res->getHeaders(), 'headers');
- $this->assertEquals($res->getRawBody(), 'raw_body');
- $this->assertEquals($res->getBody(), 'body');
- }
-
-}
diff --git a/test/unit/SendGridTest.php b/test/unit/SendGridTest.php
index 6109d02..96a348a 100644
--- a/test/unit/SendGridTest.php
+++ b/test/unit/SendGridTest.php
@@ -1,131 +1,2234 @@
<?php
-
-use \Mockery as m;
-
-class SendGridTest_SendGrid extends PHPUnit_Framework_TestCase
+class SendGridTest_SendGrid extends \PHPUnit_Framework_TestCase
{
+ public $apiKey;
+ public $sg;
- public function tearDown()
+ public function setUp()
{
- m::close();
+ $this->apiKey = "SENDGRID_API_KEY";
+ if(getenv('TRAVIS')) {
+ $host = array('host' => getenv('MOCK_HOST'));
+ } else {
+ $host = array('host' => 'http://localhost:4010');
+ }
+ $this->sg = new SendGrid($this->apiKey, $host);
}
public function testVersion()
{
- $this->assertEquals(SendGrid::VERSION, '4.0.4');
+ $this->assertEquals(SendGrid::VERSION, '5.0.0');
$this->assertEquals(json_decode(file_get_contents(__DIR__ . '/../../composer.json'))->version, SendGrid::VERSION);
}
- public function testInitWithUsernamePassword()
+ public function testSendGrid()
{
- $sendgrid = new SendGrid('user', 'pass');
- $this->assertEquals('SendGrid', get_class($sendgrid));
+ $apiKey = "SENDGRID_API_KEY";
+ $sg = new SendGrid($apiKey);
+ $headers = array(
+ 'Authorization: Bearer '.$apiKey,
+ 'User-Agent: sendgrid/' . $sg->version . ';php'
+ );
+ $this->assertEquals($sg->client->host, "https://api.sendgrid.com");
+ $this->assertEquals($sg->client->request_headers, $headers);
+ $this->assertEquals($sg->client->version, "/v3");
+
+ $apiKey = "SENDGRID_API_KEY";
+ $sg2 = new SendGrid($apiKey, array('host' => 'https://api.test.com'));
+ $this->assertEquals($sg2->client->host, "https://api.test.com");
}
- public function testInitWithUsernamePasswordOptions()
+ public function test_access_settings_activity_get()
{
- $sendgrid = new SendGrid('user', 'pass', array('foo' => 'bar'));
- $this->assertEquals('SendGrid', get_class($sendgrid));
+ $query_params = json_decode('{"limit": 1}');
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->access_settings()->activity()->get(null, $query_params, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
}
- public function testInitWithApiKey()
+ public function test_access_settings_whitelist_post()
+ {
+ $request_body = json_decode('{
+ "ips": [
+ {
+ "ip": "192.168.1.1"
+ },
{
- $sendgrid = new SendGrid('token1234');
- $this->assertEquals('SendGrid', get_class($sendgrid));
- $this->assertNull($sendgrid->apiUser);
- $this->assertEquals($sendgrid->apiKey, 'token1234');
+ "ip": "192.*.*.*"
+ },
+ {
+ "ip": "192.168.1.3/32"
+ }
+ ]
+}');
+ $request_headers = array("X-Mock: 201");
+ $response = $this->sg->client->access_settings()->whitelist()->post($request_body, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 201);
}
- public function testInitWithApiKeyOptions()
+ public function test_access_settings_whitelist_get()
{
- $sendgrid = new SendGrid('token1234', array('foo' => 'bar'));
- $this->assertEquals('SendGrid', get_class($sendgrid));
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->access_settings()->whitelist()->get(null, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
}
- public function testInitWithProxyOption()
+ public function test_access_settings_whitelist_delete()
{
- $sendgrid = new SendGrid('user', 'pass', array('proxy' => 'myproxy.net:3128'));
- $this->assertEquals('SendGrid', get_class($sendgrid));
- $options = $sendgrid->getOptions();
- $this->assertTrue(isset($options['proxy']));
+ $request_body = json_decode('{
+ "ids": [
+ 1,
+ 2,
+ 3
+ ]
+}');
+ $request_headers = array("X-Mock: 204");
+ $response = $this->sg->client->access_settings()->whitelist()->delete($request_body, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 204);
}
- public function testDefaultURL()
+ public function test_access_settings_whitelist__rule_id__get()
{
- $sendgrid = new SendGrid('user', 'pass');
- $this->assertEquals('https://api.sendgrid.com', $sendgrid->url);
+ $rule_id = "test_url_param";
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->access_settings()->whitelist()->_($rule_id)->get(null, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
}
- public function testDefaultEndpoint()
+ public function test_access_settings_whitelist__rule_id__delete()
{
- $sendgrid = new SendGrid('user', 'pass');
- $this->assertEquals('/api/mail.send.json', $sendgrid->endpoint);
+ $rule_id = "test_url_param";
+ $request_headers = array("X-Mock: 204");
+ $response = $this->sg->client->access_settings()->whitelist()->_($rule_id)->delete(null, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 204);
+ }
+ public function test_api_keys_post()
+ {
+ $request_body = json_decode('{
+ "name": "My API Key",
+ "scopes": [
+ "mail.send",
+ "alerts.create",
+ "alerts.read"
+ ]
+}');
+ $request_headers = array("X-Mock: 201");
+ $response = $this->sg->client->api_keys()->post($request_body, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 201);
}
- public function testCustomURL()
+ public function test_api_keys_get()
{
- $options = array( 'protocol' => 'http', 'host' => 'sendgrid.org', 'endpoint' => '/send', 'port' => '80' );
- $sendgrid = new SendGrid('user', 'pass', $options);
- $this->assertEquals('http://sendgrid.org:80', $sendgrid->url);
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->api_keys()->get(null, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
}
- public function testSwitchOffSSLVerification()
+ public function test_api_keys__api_key_id__put()
{
- $sendgrid = new SendGrid('foo', 'bar', array('turn_off_ssl_verification' => true));
- $options = $sendgrid->getOptions();
- $this->assertTrue(isset($options['turn_off_ssl_verification']));
+ $request_body = json_decode('{
+ "name": "A New Hope",
+ "scopes": [
+ "user.profile.read",
+ "user.profile.update"
+ ]
+}');
+ $api_key_id = "test_url_param";
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->api_keys()->_($api_key_id)->put($request_body, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
}
- /**
- * @expectedException SendGrid\Exception
- */
- public function testSendGridExceptionThrownWhenNot200()
+ public function test_api_keys__api_key_id__patch()
{
- $mockResponse = (object)array('code' => 400, 'raw_body' => "{'message': 'error', 'errors': ['Bad username / password']}");
+ $request_body = json_decode('{
+ "name": "A New Hope"
+}');
+ $api_key_id = "test_url_param";
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->api_keys()->_($api_key_id)->patch($request_body, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
- $sendgrid = m::mock('SendGrid[postRequest]', array('foo', 'bar'));
- $sendgrid->shouldReceive('postRequest')->once()->andReturn($mockResponse);
+ public function test_api_keys__api_key_id__get()
+ {
+ $api_key_id = "test_url_param";
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->api_keys()->_($api_key_id)->get(null, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
- $email = new SendGrid\Email();
- $email->setFrom('bar@foo.com')
- ->setSubject('foobar subject')
- ->setText('foobar text')
- ->addTo('foo@bar.com');
+ public function test_api_keys__api_key_id__delete()
+ {
+ $api_key_id = "test_url_param";
+ $request_headers = array("X-Mock: 204");
+ $response = $this->sg->client->api_keys()->_($api_key_id)->delete(null, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 204);
+ }
- $response = $sendgrid->send($email);
+ public function test_asm_groups_post()
+ {
+ $request_body = json_decode('{
+ "description": "A group description",
+ "is_default": false,
+ "name": "A group name"
+}');
+ $request_headers = array("X-Mock: 201");
+ $response = $this->sg->client->asm()->groups()->post($request_body, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 201);
}
- public function testDisableSendGridException()
+ public function test_asm_groups_get()
{
- $mockResponse = (object)array('code' => 400, 'raw_body' => "{'message': 'error', 'errors': ['Bad username / password']}");
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->asm()->groups()->get(null, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
- $sendgrid = m::mock('SendGrid[postRequest]', array('foo', 'bar', array('raise_exceptions' => false)));
- $sendgrid->shouldReceive('postRequest')->once()->andReturn($mockResponse);
+ public function test_asm_groups__group_id__patch()
+ {
+ $request_body = json_decode('{
+ "description": "Suggestions for items our users might like.",
+ "id": 103,
+ "name": "Item Suggestions"
+}');
+ $group_id = "test_url_param";
+ $request_headers = array("X-Mock: 201");
+ $response = $this->sg->client->asm()->groups()->_($group_id)->patch($request_body, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 201);
+ }
- $email = new SendGrid\Email();
- $email->setFrom('bar@foo.com')
- ->setSubject('foobar subject')
- ->setText('foobar text')
- ->addTo('foo@bar.com');
+ public function test_asm_groups__group_id__get()
+ {
+ $group_id = "test_url_param";
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->asm()->groups()->_($group_id)->get(null, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
- $response = $sendgrid->send($email);
+ public function test_asm_groups__group_id__delete()
+ {
+ $group_id = "test_url_param";
+ $request_headers = array("X-Mock: 204");
+ $response = $this->sg->client->asm()->groups()->_($group_id)->delete(null, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 204);
}
- public function testSendGridExceptionNotThrownWhen200()
+ public function test_asm_groups__group_id__suppressions_post()
{
- $mockResponse = (object)array('code' => 200, 'body' => (object)array('message' => 'success'));
+ $request_body = json_decode('{
+ "recipient_emails": [
+ "test1@example.com",
+ "test2@example.com"
+ ]
+}');
+ $group_id = "test_url_param";
+ $request_headers = array("X-Mock: 201");
+ $response = $this->sg->client->asm()->groups()->_($group_id)->suppressions()->post($request_body, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 201);
+ }
- $sendgrid = m::mock('SendGrid[postRequest]', array('foo', 'bar'));
- $sendgrid->shouldReceive('postRequest')->once()->andReturn($mockResponse);
+ public function test_asm_groups__group_id__suppressions_get()
+ {
+ $group_id = "test_url_param";
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->asm()->groups()->_($group_id)->suppressions()->get(null, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
- $email = new SendGrid\Email();
- $email->setFrom('bar@foo.com')
- ->setSubject('foobar subject')
- ->setText('foobar text')
- ->addTo('foo@bar.com');
+ public function test_asm_groups__group_id__suppressions__email__delete()
+ {
+ $group_id = "test_url_param";
+ $email = "test_url_param";
+ $request_headers = array("X-Mock: 204");
+ $response = $this->sg->client->asm()->groups()->_($group_id)->suppressions()->_($email)->delete(null, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 204);
+ }
- $response = $sendgrid->send($email);
+ public function test_asm_suppressions_global_post()
+ {
+ $request_body = json_decode('{
+ "recipient_emails": [
+ "test1@example.com",
+ "test2@example.com"
+ ]
+}');
+ $request_headers = array("X-Mock: 201");
+ $response = $this->sg->client->asm()->suppressions()->global()->post($request_body, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 201);
+ }
+
+ public function test_asm_suppressions_global__email__get()
+ {
+ $email = "test_url_param";
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->asm()->suppressions()->global()->_($email)->get(null, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_asm_suppressions_global__email__delete()
+ {
+ $email = "test_url_param";
+ $request_headers = array("X-Mock: 204");
+ $response = $this->sg->client->asm()->suppressions()->global()->_($email)->delete(null, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 204);
+ }
+
+ public function test_browsers_stats_get()
+ {
+ $query_params = json_decode('{"end_date": "2016-04-01", "aggregated_by": "day", "browsers": "test_string", "limit": "test_string", "offset": "test_string", "start_date": "2016-01-01"}');
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->browsers()->stats()->get(null, $query_params, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_campaigns_post()
+ {
+ $request_body = json_decode('{
+ "categories": [
+ "spring line"
+ ],
+ "custom_unsubscribe_url": "",
+ "html_content": "<html><head><title></title></head><body><p>Check out our spring line!</p></body></html>",
+ "ip_pool": "marketing",
+ "list_ids": [
+ 110,
+ 124
+ ],
+ "plain_content": "Check out our spring line!",
+ "segment_ids": [
+ 110
+ ],
+ "sender_id": 124451,
+ "subject": "New Products for Spring!",
+ "suppression_group_id": 42,
+ "title": "March Newsletter"
+}');
+ $request_headers = array("X-Mock: 201");
+ $response = $this->sg->client->campaigns()->post($request_body, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 201);
+ }
+
+ public function test_campaigns_get()
+ {
+ $query_params = json_decode('{"limit": 0, "offset": 0}');
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->campaigns()->get(null, $query_params, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_campaigns__campaign_id__patch()
+ {
+ $request_body = json_decode('{
+ "categories": [
+ "summer line"
+ ],
+ "html_content": "<html><head><title></title></head><body><p>Check out our summer line!</p></body></html>",
+ "plain_content": "Check out our summer line!",
+ "subject": "New Products for Summer!",
+ "title": "May Newsletter"
+}');
+ $campaign_id = "test_url_param";
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->campaigns()->_($campaign_id)->patch($request_body, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_campaigns__campaign_id__get()
+ {
+ $campaign_id = "test_url_param";
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->campaigns()->_($campaign_id)->get(null, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_campaigns__campaign_id__delete()
+ {
+ $campaign_id = "test_url_param";
+ $request_headers = array("X-Mock: 204");
+ $response = $this->sg->client->campaigns()->_($campaign_id)->delete(null, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 204);
+ }
+
+ public function test_campaigns__campaign_id__schedules_patch()
+ {
+ $request_body = json_decode('{
+ "send_at": 1489451436
+}');
+ $campaign_id = "test_url_param";
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->campaigns()->_($campaign_id)->schedules()->patch($request_body, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_campaigns__campaign_id__schedules_post()
+ {
+ $request_body = json_decode('{
+ "send_at": 1489771528
+}');
+ $campaign_id = "test_url_param";
+ $request_headers = array("X-Mock: 201");
+ $response = $this->sg->client->campaigns()->_($campaign_id)->schedules()->post($request_body, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 201);
+ }
+
+ public function test_campaigns__campaign_id__schedules_get()
+ {
+ $campaign_id = "test_url_param";
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->campaigns()->_($campaign_id)->schedules()->get(null, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_campaigns__campaign_id__schedules_delete()
+ {
+ $campaign_id = "test_url_param";
+ $request_headers = array("X-Mock: 204");
+ $response = $this->sg->client->campaigns()->_($campaign_id)->schedules()->delete(null, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 204);
+ }
+
+ public function test_campaigns__campaign_id__schedules_now_post()
+ {
+ $campaign_id = "test_url_param";
+ $request_headers = array("X-Mock: 201");
+ $response = $this->sg->client->campaigns()->_($campaign_id)->schedules()->now()->post(null, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 201);
+ }
+
+ public function test_campaigns__campaign_id__schedules_test_post()
+ {
+ $request_body = json_decode('{
+ "to": "your.email@example.com"
+}');
+ $campaign_id = "test_url_param";
+ $request_headers = array("X-Mock: 204");
+ $response = $this->sg->client->campaigns()->_($campaign_id)->schedules()->test()->post($request_body, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 204);
+ }
+
+ public function test_categories_get()
+ {
+ $query_params = json_decode('{"category": "test_string", "limit": 1, "offset": 1}');
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->categories()->get(null, $query_params, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_categories_stats_get()
+ {
+ $query_params = json_decode('{"end_date": "2016-04-01", "aggregated_by": "day", "limit": 1, "offset": 1, "start_date": "2016-01-01", "categories": "test_string"}');
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->categories()->stats()->get(null, $query_params, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_categories_stats_sums_get()
+ {
+ $query_params = json_decode('{"end_date": "2016-04-01", "aggregated_by": "day", "limit": 1, "sort_by_metric": "test_string", "offset": 1, "start_date": "2016-01-01", "sort_by_direction": "asc"}');
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->categories()->stats()->sums()->get(null, $query_params, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_clients_stats_get()
+ {
+ $query_params = json_decode('{"aggregated_by": "day", "start_date": "2016-01-01", "end_date": "2016-04-01"}');
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->clients()->stats()->get(null, $query_params, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_clients__client_type__stats_get()
+ {
+ $query_params = json_decode('{"aggregated_by": "day", "start_date": "2016-01-01", "end_date": "2016-04-01"}');
+ $client_type = "test_url_param";
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->clients()->_($client_type)->stats()->get(null, $query_params, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_contactdb_custom_fields_post()
+ {
+ $request_body = json_decode('{
+ "name": "pet",
+ "type": "text"
+}');
+ $request_headers = array("X-Mock: 201");
+ $response = $this->sg->client->contactdb()->custom_fields()->post($request_body, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 201);
+ }
+
+ public function test_contactdb_custom_fields_get()
+ {
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->contactdb()->custom_fields()->get(null, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_contactdb_custom_fields__custom_field_id__get()
+ {
+ $custom_field_id = "test_url_param";
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->contactdb()->custom_fields()->_($custom_field_id)->get(null, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_contactdb_custom_fields__custom_field_id__delete()
+ {
+ $custom_field_id = "test_url_param";
+ $request_headers = array("X-Mock: 202");
+ $response = $this->sg->client->contactdb()->custom_fields()->_($custom_field_id)->delete(null, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 202);
+ }
+
+ public function test_contactdb_lists_post()
+ {
+ $request_body = json_decode('{
+ "name": "your list name"
+}');
+ $request_headers = array("X-Mock: 201");
+ $response = $this->sg->client->contactdb()->lists()->post($request_body, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 201);
+ }
+
+ public function test_contactdb_lists_get()
+ {
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->contactdb()->lists()->get(null, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_contactdb_lists_delete()
+ {
+ $request_body = json_decode('[
+ 1,
+ 2,
+ 3,
+ 4
+]');
+ $request_headers = array("X-Mock: 204");
+ $response = $this->sg->client->contactdb()->lists()->delete($request_body, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 204);
+ }
+
+ public function test_contactdb_lists__list_id__patch()
+ {
+ $request_body = json_decode('{
+ "name": "newlistname"
+}');
+ $query_params = json_decode('{"list_id": 0}');
+ $list_id = "test_url_param";
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->contactdb()->lists()->_($list_id)->patch($request_body, $query_params, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_contactdb_lists__list_id__get()
+ {
+ $query_params = json_decode('{"list_id": 0}');
+ $list_id = "test_url_param";
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->contactdb()->lists()->_($list_id)->get(null, $query_params, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_contactdb_lists__list_id__delete()
+ {
+ $query_params = json_decode('{"delete_contacts": "true"}');
+ $list_id = "test_url_param";
+ $request_headers = array("X-Mock: 202");
+ $response = $this->sg->client->contactdb()->lists()->_($list_id)->delete(null, $query_params, $request_headers);
+ $this->assertEquals($response->statusCode(), 202);
+ }
+
+ public function test_contactdb_lists__list_id__recipients_post()
+ {
+ $request_body = json_decode('[
+ "recipient_id1",
+ "recipient_id2"
+]');
+ $list_id = "test_url_param";
+ $request_headers = array("X-Mock: 201");
+ $response = $this->sg->client->contactdb()->lists()->_($list_id)->recipients()->post($request_body, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 201);
+ }
+
+ public function test_contactdb_lists__list_id__recipients_get()
+ {
+ $query_params = json_decode('{"page": 1, "page_size": 1, "list_id": 0}');
+ $list_id = "test_url_param";
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->contactdb()->lists()->_($list_id)->recipients()->get(null, $query_params, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_contactdb_lists__list_id__recipients__recipient_id__post()
+ {
+ $list_id = "test_url_param";
+ $recipient_id = "test_url_param";
+ $request_headers = array("X-Mock: 201");
+ $response = $this->sg->client->contactdb()->lists()->_($list_id)->recipients()->_($recipient_id)->post(null, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 201);
+ }
+
+ public function test_contactdb_lists__list_id__recipients__recipient_id__delete()
+ {
+ $query_params = json_decode('{"recipient_id": 0, "list_id": 0}');
+ $list_id = "test_url_param";
+ $recipient_id = "test_url_param";
+ $request_headers = array("X-Mock: 204");
+ $response = $this->sg->client->contactdb()->lists()->_($list_id)->recipients()->_($recipient_id)->delete(null, $query_params, $request_headers);
+ $this->assertEquals($response->statusCode(), 204);
+ }
+
+ public function test_contactdb_recipients_patch()
+ {
+ $request_body = json_decode('[
+ {
+ "email": "jones@example.com",
+ "first_name": "Guy",
+ "last_name": "Jones"
+ }
+]');
+ $request_headers = array("X-Mock: 201");
+ $response = $this->sg->client->contactdb()->recipients()->patch($request_body, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 201);
+ }
+
+ public function test_contactdb_recipients_post()
+ {
+ $request_body = json_decode('[
+ {
+ "age": 25,
+ "email": "example@example.com",
+ "first_name": "",
+ "last_name": "User"
+ },
+ {
+ "age": 25,
+ "email": "example2@example.com",
+ "first_name": "Example",
+ "last_name": "User"
+ }
+]');
+ $request_headers = array("X-Mock: 201");
+ $response = $this->sg->client->contactdb()->recipients()->post($request_body, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 201);
+ }
+
+ public function test_contactdb_recipients_get()
+ {
+ $query_params = json_decode('{"page": 1, "page_size": 1}');
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->contactdb()->recipients()->get(null, $query_params, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_contactdb_recipients_delete()
+ {
+ $request_body = json_decode('[
+ "recipient_id1",
+ "recipient_id2"
+]');
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->contactdb()->recipients()->delete($request_body, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_contactdb_recipients_billable_count_get()
+ {
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->contactdb()->recipients()->billable_count()->get(null, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_contactdb_recipients_count_get()
+ {
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->contactdb()->recipients()->count()->get(null, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_contactdb_recipients_search_get()
+ {
+ $query_params = json_decode('{"{field_name}": "test_string"}');
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->contactdb()->recipients()->search()->get(null, $query_params, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_contactdb_recipients__recipient_id__get()
+ {
+ $recipient_id = "test_url_param";
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->contactdb()->recipients()->_($recipient_id)->get(null, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_contactdb_recipients__recipient_id__delete()
+ {
+ $recipient_id = "test_url_param";
+ $request_headers = array("X-Mock: 204");
+ $response = $this->sg->client->contactdb()->recipients()->_($recipient_id)->delete(null, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 204);
+ }
+
+ public function test_contactdb_recipients__recipient_id__lists_get()
+ {
+ $recipient_id = "test_url_param";
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->contactdb()->recipients()->_($recipient_id)->lists()->get(null, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_contactdb_reserved_fields_get()
+ {
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->contactdb()->reserved_fields()->get(null, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_contactdb_segments_post()
+ {
+ $request_body = json_decode('{
+ "conditions": [
+ {
+ "and_or": "",
+ "field": "last_name",
+ "operator": "eq",
+ "value": "Miller"
+ },
+ {
+ "and_or": "and",
+ "field": "last_clicked",
+ "operator": "gt",
+ "value": "01/02/2015"
+ },
+ {
+ "and_or": "or",
+ "field": "clicks.campaign_identifier",
+ "operator": "eq",
+ "value": "513"
+ }
+ ],
+ "list_id": 4,
+ "name": "Last Name Miller"
+}');
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->contactdb()->segments()->post($request_body, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_contactdb_segments_get()
+ {
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->contactdb()->segments()->get(null, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_contactdb_segments__segment_id__patch()
+ {
+ $request_body = json_decode('{
+ "conditions": [
+ {
+ "and_or": "",
+ "field": "last_name",
+ "operator": "eq",
+ "value": "Miller"
+ }
+ ],
+ "list_id": 5,
+ "name": "The Millers"
+}');
+ $query_params = json_decode('{"segment_id": "test_string"}');
+ $segment_id = "test_url_param";
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->contactdb()->segments()->_($segment_id)->patch($request_body, $query_params, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_contactdb_segments__segment_id__get()
+ {
+ $query_params = json_decode('{"segment_id": 0}');
+ $segment_id = "test_url_param";
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->contactdb()->segments()->_($segment_id)->get(null, $query_params, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_contactdb_segments__segment_id__delete()
+ {
+ $query_params = json_decode('{"delete_contacts": "true"}');
+ $segment_id = "test_url_param";
+ $request_headers = array("X-Mock: 204");
+ $response = $this->sg->client->contactdb()->segments()->_($segment_id)->delete(null, $query_params, $request_headers);
+ $this->assertEquals($response->statusCode(), 204);
+ }
+
+ public function test_contactdb_segments__segment_id__recipients_get()
+ {
+ $query_params = json_decode('{"page": 1, "page_size": 1}');
+ $segment_id = "test_url_param";
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->contactdb()->segments()->_($segment_id)->recipients()->get(null, $query_params, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_devices_stats_get()
+ {
+ $query_params = json_decode('{"aggregated_by": "day", "limit": 1, "start_date": "2016-01-01", "end_date": "2016-04-01", "offset": 1}');
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->devices()->stats()->get(null, $query_params, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_geo_stats_get()
+ {
+ $query_params = json_decode('{"end_date": "2016-04-01", "country": "US", "aggregated_by": "day", "limit": 1, "offset": 1, "start_date": "2016-01-01"}');
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->geo()->stats()->get(null, $query_params, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_ips_get()
+ {
+ $query_params = json_decode('{"subuser": "test_string", "ip": "test_string", "limit": 1, "exclude_whitelabels": "true", "offset": 1}');
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->ips()->get(null, $query_params, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_ips_assigned_get()
+ {
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->ips()->assigned()->get(null, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_ips_pools_post()
+ {
+ $request_body = json_decode('{
+ "name": "marketing"
+}');
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->ips()->pools()->post($request_body, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_ips_pools_get()
+ {
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->ips()->pools()->get(null, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_ips_pools__pool_name__put()
+ {
+ $request_body = json_decode('{
+ "name": "new_pool_name"
+}');
+ $pool_name = "test_url_param";
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->ips()->pools()->_($pool_name)->put($request_body, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_ips_pools__pool_name__get()
+ {
+ $pool_name = "test_url_param";
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->ips()->pools()->_($pool_name)->get(null, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_ips_pools__pool_name__delete()
+ {
+ $pool_name = "test_url_param";
+ $request_headers = array("X-Mock: 204");
+ $response = $this->sg->client->ips()->pools()->_($pool_name)->delete(null, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 204);
+ }
+
+ public function test_ips_pools__pool_name__ips_post()
+ {
+ $request_body = json_decode('{
+ "ip": "0.0.0.0"
+}');
+ $pool_name = "test_url_param";
+ $request_headers = array("X-Mock: 201");
+ $response = $this->sg->client->ips()->pools()->_($pool_name)->ips()->post($request_body, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 201);
+ }
+
+ public function test_ips_pools__pool_name__ips__ip__delete()
+ {
+ $pool_name = "test_url_param";
+ $ip = "test_url_param";
+ $request_headers = array("X-Mock: 204");
+ $response = $this->sg->client->ips()->pools()->_($pool_name)->ips()->_($ip)->delete(null, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 204);
+ }
+
+ public function test_ips_warmup_post()
+ {
+ $request_body = json_decode('{
+ "ip": "0.0.0.0"
+}');
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->ips()->warmup()->post($request_body, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_ips_warmup_get()
+ {
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->ips()->warmup()->get(null, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_ips_warmup__ip_address__get()
+ {
+ $ip_address = "test_url_param";
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->ips()->warmup()->_($ip_address)->get(null, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_ips_warmup__ip_address__delete()
+ {
+ $ip_address = "test_url_param";
+ $request_headers = array("X-Mock: 204");
+ $response = $this->sg->client->ips()->warmup()->_($ip_address)->delete(null, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 204);
+ }
+
+ public function test_ips__ip_address__get()
+ {
+ $ip_address = "test_url_param";
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->ips()->_($ip_address)->get(null, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_mail_batch_post()
+ {
+ $request_headers = array("X-Mock: 201");
+ $response = $this->sg->client->mail()->batch()->post(null, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 201);
+ }
+
+ public function test_mail_batch__batch_id__get()
+ {
+ $batch_id = "test_url_param";
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->mail()->batch()->_($batch_id)->get(null, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_mail_send_beta_post()
+ {
+ $request_body = json_decode('{
+ "asm": {
+ "group_id": 1,
+ "groups_to_display": [
+ 1,
+ 2,
+ 3
+ ]
+ },
+ "attachments": [
+ {
+ "content": "[BASE64 encoded content block here]",
+ "content_id": "ii_139db99fdb5c3704",
+ "disposition": "inline",
+ "filename": "file1.jpg",
+ "name": "file1",
+ "type": "jpg"
+ }
+ ],
+ "batch_id": "[YOUR BATCH ID GOES HERE]",
+ "categories": [
+ "category1",
+ "category2"
+ ],
+ "content": [
+ {
+ "type": "text/html",
+ "value": "<html><p>Hello, world!</p><img src=[CID GOES HERE]></img></html>"
+ }
+ ],
+ "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"
+ },
+ "headers": {},
+ "ip_pool_name": "[YOUR POOL NAME GOES HERE]",
+ "mail_settings": {
+ "bcc": {
+ "email": "ben.doe@example.com",
+ "enable": true
+ },
+ "bypass_list_management": {
+ "enable": true
+ },
+ "footer": {
+ "enable": true,
+ "html": "<p>Thanks</br>The SendGrid Team</p>",
+ "text": "Thanks,/n The SendGrid Team"
+ },
+ "sandbox_mode": {
+ "enable": false
+ },
+ "spam_check": {
+ "enable": true,
+ "post_to_url": "http://example.com/compliance",
+ "threshold": 3
+ }
+ },
+ "personalizations": [
+ {
+ "bcc": [
+ {
+ "email": "sam.doe@example.com",
+ "name": "Sam Doe"
+ }
+ ],
+ "cc": [
+ {
+ "email": "jane.doe@example.com",
+ "name": "Jane 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,
+ "subject": "Hello, World!",
+ "substitutions": {
+ "sub": {
+ "%name%": [
+ "John",
+ "Jane",
+ "Sam"
+ ]
+ }
+ },
+ "to": [
+ {
+ "email": "john.doe@example.com",
+ "name": "John Doe"
+ }
+ ]
+ }
+ ],
+ "reply_to": {
+ "email": "sam.smith@example.com",
+ "name": "Sam Smith"
+ },
+ "sections": {
+ "section": {
+ ":sectionName1": "section 1 text",
+ ":sectionName2": "section 2 text"
+ }
+ },
+ "send_at": 1409348513,
+ "subject": "Hello, World!",
+ "template_id": "[YOUR TEMPLATE ID GOES HERE]",
+ "tracking_settings": {
+ "click_tracking": {
+ "enable": true,
+ "enable_text": true
+ },
+ "ganalytics": {
+ "enable": true,
+ "utm_campaign": "[NAME OF YOUR REFERRER SOURCE]",
+ "utm_content": "[USE THIS SPACE TO DIFFERENTIATE YOUR EMAIL FROM ADS]",
+ "utm_medium": "[NAME OF YOUR MARKETING MEDIUM e.g. email]",
+ "utm_name": "[NAME OF YOUR CAMPAIGN]",
+ "utm_term": "[IDENTIFY PAID KEYWORDS HERE]"
+ },
+ "open_tracking": {
+ "enable": true,
+ "substitution_tag": "%opentrack"
+ },
+ "subscription_tracking": {
+ "enable": true,
+ "html": "If you would like to unsubscribe and stop receiving these emails <% clickhere %>.",
+ "substitution_tag": "<%click here%>",
+ "text": "If you would like to unsubscribe and stop receiveing these emails <% click here %>."
+ }
+ }
+}');
+ $request_headers = array("X-Mock: 202");
+ $response = $this->sg->client->mail()->send()->beta()->post($request_body, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 202);
+ }
+
+ public function test_mail_settings_get()
+ {
+ $query_params = json_decode('{"limit": 1, "offset": 1}');
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->mail_settings()->get(null, $query_params, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_mail_settings_address_whitelist_patch()
+ {
+ $request_body = json_decode('{
+ "enabled": true,
+ "list": [
+ "email1@example.com",
+ "example.com"
+ ]
+}');
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->mail_settings()->address_whitelist()->patch($request_body, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_mail_settings_address_whitelist_get()
+ {
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->mail_settings()->address_whitelist()->get(null, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_mail_settings_bcc_patch()
+ {
+ $request_body = json_decode('{
+ "email": "email@example.com",
+ "enabled": false
+}');
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->mail_settings()->bcc()->patch($request_body, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_mail_settings_bcc_get()
+ {
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->mail_settings()->bcc()->get(null, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_mail_settings_bounce_purge_patch()
+ {
+ $request_body = json_decode('{
+ "enabled": true,
+ "hard_bounces": 5,
+ "soft_bounces": 5
+}');
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->mail_settings()->bounce_purge()->patch($request_body, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_mail_settings_bounce_purge_get()
+ {
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->mail_settings()->bounce_purge()->get(null, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_mail_settings_footer_patch()
+ {
+ $request_body = json_decode('{
+ "enabled": true,
+ "html_content": "...",
+ "plain_content": "..."
+}');
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->mail_settings()->footer()->patch($request_body, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_mail_settings_footer_get()
+ {
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->mail_settings()->footer()->get(null, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_mail_settings_forward_bounce_patch()
+ {
+ $request_body = json_decode('{
+ "email": "example@example.com",
+ "enabled": true
+}');
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->mail_settings()->forward_bounce()->patch($request_body, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_mail_settings_forward_bounce_get()
+ {
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->mail_settings()->forward_bounce()->get(null, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_mail_settings_forward_spam_patch()
+ {
+ $request_body = json_decode('{
+ "email": "",
+ "enabled": false
+}');
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->mail_settings()->forward_spam()->patch($request_body, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_mail_settings_forward_spam_get()
+ {
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->mail_settings()->forward_spam()->get(null, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_mail_settings_plain_content_patch()
+ {
+ $request_body = json_decode('{
+ "enabled": false
+}');
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->mail_settings()->plain_content()->patch($request_body, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_mail_settings_plain_content_get()
+ {
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->mail_settings()->plain_content()->get(null, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_mail_settings_spam_check_patch()
+ {
+ $request_body = json_decode('{
+ "enabled": true,
+ "max_score": 5,
+ "url": "url"
+}');
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->mail_settings()->spam_check()->patch($request_body, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_mail_settings_spam_check_get()
+ {
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->mail_settings()->spam_check()->get(null, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_mail_settings_template_patch()
+ {
+ $request_body = json_decode('{
+ "enabled": true,
+ "html_content": "<% body %>"
+}');
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->mail_settings()->template()->patch($request_body, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_mail_settings_template_get()
+ {
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->mail_settings()->template()->get(null, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_mailbox_providers_stats_get()
+ {
+ $query_params = json_decode('{"end_date": "2016-04-01", "mailbox_providers": "test_string", "aggregated_by": "day", "limit": 1, "offset": 1, "start_date": "2016-01-01"}');
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->mailbox_providers()->stats()->get(null, $query_params, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
}
-}
+ public function test_partner_settings_get()
+ {
+ $query_params = json_decode('{"limit": 1, "offset": 1}');
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->partner_settings()->get(null, $query_params, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_partner_settings_new_relic_patch()
+ {
+ $request_body = json_decode('{
+ "enable_subuser_statistics": true,
+ "enabled": true,
+ "license_key": ""
+}');
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->partner_settings()->new_relic()->patch($request_body, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_partner_settings_new_relic_get()
+ {
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->partner_settings()->new_relic()->get(null, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_scopes_get()
+ {
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->scopes()->get(null, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_stats_get()
+ {
+ $query_params = json_decode('{"aggregated_by": "day", "limit": 1, "start_date": "2016-01-01", "end_date": "2016-04-01", "offset": 1}');
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->stats()->get(null, $query_params, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_subusers_post()
+ {
+ $request_body = json_decode('{
+ "email": "John@example.com",
+ "ips": [
+ "1.1.1.1",
+ "2.2.2.2"
+ ],
+ "password": "johns_password",
+ "username": "John@example.com"
+}');
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->subusers()->post($request_body, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_subusers_get()
+ {
+ $query_params = json_decode('{"username": "test_string", "limit": 0, "offset": 0}');
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->subusers()->get(null, $query_params, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_subusers_reputations_get()
+ {
+ $query_params = json_decode('{"usernames": "test_string"}');
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->subusers()->reputations()->get(null, $query_params, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_subusers_stats_get()
+ {
+ $query_params = json_decode('{"end_date": "2016-04-01", "aggregated_by": "day", "limit": 1, "offset": 1, "start_date": "2016-01-01", "subusers": "test_string"}');
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->subusers()->stats()->get(null, $query_params, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_subusers_stats_monthly_get()
+ {
+ $query_params = json_decode('{"subuser": "test_string", "limit": 1, "sort_by_metric": "test_string", "offset": 1, "date": "test_string", "sort_by_direction": "asc"}');
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->subusers()->stats()->monthly()->get(null, $query_params, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_subusers_stats_sums_get()
+ {
+ $query_params = json_decode('{"end_date": "2016-04-01", "aggregated_by": "day", "limit": 1, "sort_by_metric": "test_string", "offset": 1, "start_date": "2016-01-01", "sort_by_direction": "asc"}');
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->subusers()->stats()->sums()->get(null, $query_params, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_subusers__subuser_name__patch()
+ {
+ $request_body = json_decode('{
+ "disabled": false
+}');
+ $subuser_name = "test_url_param";
+ $request_headers = array("X-Mock: 204");
+ $response = $this->sg->client->subusers()->_($subuser_name)->patch($request_body, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 204);
+ }
+
+ public function test_subusers__subuser_name__delete()
+ {
+ $subuser_name = "test_url_param";
+ $request_headers = array("X-Mock: 204");
+ $response = $this->sg->client->subusers()->_($subuser_name)->delete(null, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 204);
+ }
+
+ public function test_subusers__subuser_name__ips_put()
+ {
+ $request_body = json_decode('[
+ "127.0.0.1"
+]');
+ $subuser_name = "test_url_param";
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->subusers()->_($subuser_name)->ips()->put($request_body, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_subusers__subuser_name__monitor_put()
+ {
+ $request_body = json_decode('{
+ "email": "example@example.com",
+ "frequency": 500
+}');
+ $subuser_name = "test_url_param";
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->subusers()->_($subuser_name)->monitor()->put($request_body, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_subusers__subuser_name__monitor_post()
+ {
+ $request_body = json_decode('{
+ "email": "example@example.com",
+ "frequency": 50000
+}');
+ $subuser_name = "test_url_param";
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->subusers()->_($subuser_name)->monitor()->post($request_body, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_subusers__subuser_name__monitor_get()
+ {
+ $subuser_name = "test_url_param";
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->subusers()->_($subuser_name)->monitor()->get(null, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_subusers__subuser_name__monitor_delete()
+ {
+ $subuser_name = "test_url_param";
+ $request_headers = array("X-Mock: 204");
+ $response = $this->sg->client->subusers()->_($subuser_name)->monitor()->delete(null, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 204);
+ }
+
+ public function test_subusers__subuser_name__stats_monthly_get()
+ {
+ $query_params = json_decode('{"date": "test_string", "sort_by_direction": "asc", "limit": 0, "sort_by_metric": "test_string", "offset": 1}');
+ $subuser_name = "test_url_param";
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->subusers()->_($subuser_name)->stats()->monthly()->get(null, $query_params, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_suppression_blocks_get()
+ {
+ $query_params = json_decode('{"start_time": 1, "limit": 1, "end_time": 1, "offset": 1}');
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->suppression()->blocks()->get(null, $query_params, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_suppression_blocks_delete()
+ {
+ $request_body = json_decode('{
+ "delete_all": false,
+ "emails": [
+ "example1@example.com",
+ "example2@example.com"
+ ]
+}');
+ $request_headers = array("X-Mock: 204");
+ $response = $this->sg->client->suppression()->blocks()->delete($request_body, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 204);
+ }
+
+ public function test_suppression_blocks__email__get()
+ {
+ $email = "test_url_param";
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->suppression()->blocks()->_($email)->get(null, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_suppression_blocks__email__delete()
+ {
+ $email = "test_url_param";
+ $request_headers = array("X-Mock: 204");
+ $response = $this->sg->client->suppression()->blocks()->_($email)->delete(null, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 204);
+ }
+
+ public function test_suppression_bounces_get()
+ {
+ $query_params = json_decode('{"start_time": 0, "end_time": 0}');
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->suppression()->bounces()->get(null, $query_params, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_suppression_bounces_delete()
+ {
+ $request_body = json_decode('{
+ "delete_all": true,
+ "emails": [
+ "example@example.com",
+ "example2@example.com"
+ ]
+}');
+ $request_headers = array("X-Mock: 204");
+ $response = $this->sg->client->suppression()->bounces()->delete($request_body, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 204);
+ }
+
+ public function test_suppression_bounces__email__get()
+ {
+ $email = "test_url_param";
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->suppression()->bounces()->_($email)->get(null, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_suppression_bounces__email__delete()
+ {
+ $query_params = json_decode('{"email_address": "example@example.com"}');
+ $email = "test_url_param";
+ $request_headers = array("X-Mock: 204");
+ $response = $this->sg->client->suppression()->bounces()->_($email)->delete(null, $query_params, $request_headers);
+ $this->assertEquals($response->statusCode(), 204);
+ }
+
+ public function test_suppression_invalid_emails_get()
+ {
+ $query_params = json_decode('{"start_time": 1, "limit": 1, "end_time": 1, "offset": 1}');
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->suppression()->invalid_emails()->get(null, $query_params, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_suppression_invalid_emails_delete()
+ {
+ $request_body = json_decode('{
+ "delete_all": false,
+ "emails": [
+ "example1@example.com",
+ "example2@example.com"
+ ]
+}');
+ $request_headers = array("X-Mock: 204");
+ $response = $this->sg->client->suppression()->invalid_emails()->delete($request_body, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 204);
+ }
+
+ public function test_suppression_invalid_emails__email__get()
+ {
+ $email = "test_url_param";
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->suppression()->invalid_emails()->_($email)->get(null, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_suppression_invalid_emails__email__delete()
+ {
+ $email = "test_url_param";
+ $request_headers = array("X-Mock: 204");
+ $response = $this->sg->client->suppression()->invalid_emails()->_($email)->delete(null, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 204);
+ }
+
+ public function test_suppression_spam_report__email__get()
+ {
+ $email = "test_url_param";
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->suppression()->spam_report()->_($email)->get(null, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_suppression_spam_report__email__delete()
+ {
+ $email = "test_url_param";
+ $request_headers = array("X-Mock: 204");
+ $response = $this->sg->client->suppression()->spam_report()->_($email)->delete(null, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 204);
+ }
+
+ public function test_suppression_spam_reports_get()
+ {
+ $query_params = json_decode('{"start_time": 1, "limit": 1, "end_time": 1, "offset": 1}');
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->suppression()->spam_reports()->get(null, $query_params, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_suppression_spam_reports_delete()
+ {
+ $request_body = json_decode('{
+ "delete_all": false,
+ "emails": [
+ "example1@example.com",
+ "example2@example.com"
+ ]
+}');
+ $request_headers = array("X-Mock: 204");
+ $response = $this->sg->client->suppression()->spam_reports()->delete($request_body, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 204);
+ }
+
+ public function test_suppression_unsubscribes_get()
+ {
+ $query_params = json_decode('{"start_time": 1, "limit": 1, "end_time": 1, "offset": 1}');
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->suppression()->unsubscribes()->get(null, $query_params, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_templates_post()
+ {
+ $request_body = json_decode('{
+ "name": "example_name"
+}');
+ $request_headers = array("X-Mock: 201");
+ $response = $this->sg->client->templates()->post($request_body, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 201);
+ }
+
+ public function test_templates_get()
+ {
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->templates()->get(null, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_templates__template_id__patch()
+ {
+ $request_body = json_decode('{
+ "name": "new_example_name"
+}');
+ $template_id = "test_url_param";
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->templates()->_($template_id)->patch($request_body, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_templates__template_id__get()
+ {
+ $template_id = "test_url_param";
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->templates()->_($template_id)->get(null, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_templates__template_id__delete()
+ {
+ $template_id = "test_url_param";
+ $request_headers = array("X-Mock: 204");
+ $response = $this->sg->client->templates()->_($template_id)->delete(null, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 204);
+ }
+
+ public function test_templates__template_id__versions_post()
+ {
+ $request_body = json_decode('{
+ "active": 1,
+ "html_content": "<%body%>",
+ "name": "example_version_name",
+ "plain_content": "<%body%>",
+ "subject": "<%subject%>",
+ "template_id": "ddb96bbc-9b92-425e-8979-99464621b543"
+}');
+ $template_id = "test_url_param";
+ $request_headers = array("X-Mock: 201");
+ $response = $this->sg->client->templates()->_($template_id)->versions()->post($request_body, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 201);
+ }
+
+ public function test_templates__template_id__versions__version_id__patch()
+ {
+ $request_body = json_decode('{
+ "active": 1,
+ "html_content": "<%body%>",
+ "name": "updated_example_name",
+ "plain_content": "<%body%>",
+ "subject": "<%subject%>"
+}');
+ $template_id = "test_url_param";
+ $version_id = "test_url_param";
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->templates()->_($template_id)->versions()->_($version_id)->patch($request_body, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_templates__template_id__versions__version_id__get()
+ {
+ $template_id = "test_url_param";
+ $version_id = "test_url_param";
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->templates()->_($template_id)->versions()->_($version_id)->get(null, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_templates__template_id__versions__version_id__delete()
+ {
+ $template_id = "test_url_param";
+ $version_id = "test_url_param";
+ $request_headers = array("X-Mock: 204");
+ $response = $this->sg->client->templates()->_($template_id)->versions()->_($version_id)->delete(null, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 204);
+ }
+
+ public function test_templates__template_id__versions__version_id__activate_post()
+ {
+ $template_id = "test_url_param";
+ $version_id = "test_url_param";
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->templates()->_($template_id)->versions()->_($version_id)->activate()->post(null, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_tracking_settings_get()
+ {
+ $query_params = json_decode('{"limit": 1, "offset": 1}');
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->tracking_settings()->get(null, $query_params, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_tracking_settings_click_patch()
+ {
+ $request_body = json_decode('{
+ "enabled": true
+}');
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->tracking_settings()->click()->patch($request_body, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_tracking_settings_click_get()
+ {
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->tracking_settings()->click()->get(null, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_tracking_settings_google_analytics_patch()
+ {
+ $request_body = json_decode('{
+ "enabled": true,
+ "utm_campaign": "website",
+ "utm_content": "",
+ "utm_medium": "email",
+ "utm_source": "sendgrid.com",
+ "utm_term": ""
+}');
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->tracking_settings()->google_analytics()->patch($request_body, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_tracking_settings_google_analytics_get()
+ {
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->tracking_settings()->google_analytics()->get(null, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_tracking_settings_open_patch()
+ {
+ $request_body = json_decode('{
+ "enabled": true
+}');
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->tracking_settings()->open()->patch($request_body, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_tracking_settings_open_get()
+ {
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->tracking_settings()->open()->get(null, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_tracking_settings_subscription_patch()
+ {
+ $request_body = json_decode('{
+ "enabled": true,
+ "html_content": "html content",
+ "landing": "landing page html",
+ "plain_content": "text content",
+ "replace": "replacement tag",
+ "url": "url"
+}');
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->tracking_settings()->subscription()->patch($request_body, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_tracking_settings_subscription_get()
+ {
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->tracking_settings()->subscription()->get(null, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_user_account_get()
+ {
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->user()->account()->get(null, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_user_credits_get()
+ {
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->user()->credits()->get(null, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_user_email_put()
+ {
+ $request_body = json_decode('{
+ "email": "example@example.com"
+}');
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->user()->email()->put($request_body, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_user_email_get()
+ {
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->user()->email()->get(null, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_user_password_put()
+ {
+ $request_body = json_decode('{
+ "new_password": "new_password",
+ "old_password": "old_password"
+}');
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->user()->password()->put($request_body, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_user_profile_patch()
+ {
+ $request_body = json_decode('{
+ "city": "Orange",
+ "first_name": "Example",
+ "last_name": "User"
+}');
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->user()->profile()->patch($request_body, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_user_profile_get()
+ {
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->user()->profile()->get(null, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_user_scheduled_sends_post()
+ {
+ $request_body = json_decode('{
+ "batch_id": "YOUR_BATCH_ID",
+ "status": "pause"
+}');
+ $request_headers = array("X-Mock: 201");
+ $response = $this->sg->client->user()->scheduled_sends()->post($request_body, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 201);
+ }
+
+ public function test_user_scheduled_sends_get()
+ {
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->user()->scheduled_sends()->get(null, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_user_scheduled_sends__batch_id__patch()
+ {
+ $request_body = json_decode('{
+ "status": "pause"
+}');
+ $batch_id = "test_url_param";
+ $request_headers = array("X-Mock: 204");
+ $response = $this->sg->client->user()->scheduled_sends()->_($batch_id)->patch($request_body, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 204);
+ }
+
+ public function test_user_scheduled_sends__batch_id__get()
+ {
+ $batch_id = "test_url_param";
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->user()->scheduled_sends()->_($batch_id)->get(null, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_user_scheduled_sends__batch_id__delete()
+ {
+ $batch_id = "test_url_param";
+ $request_headers = array("X-Mock: 204");
+ $response = $this->sg->client->user()->scheduled_sends()->_($batch_id)->delete(null, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 204);
+ }
+
+ public function test_user_settings_enforced_tls_patch()
+ {
+ $request_body = json_decode('{
+ "require_tls": true,
+ "require_valid_cert": false
+}');
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->user()->settings()->enforced_tls()->patch($request_body, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_user_settings_enforced_tls_get()
+ {
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->user()->settings()->enforced_tls()->get(null, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_user_username_put()
+ {
+ $request_body = json_decode('{
+ "username": "test_username"
+}');
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->user()->username()->put($request_body, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_user_username_get()
+ {
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->user()->username()->get(null, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_user_webhooks_event_settings_patch()
+ {
+ $request_body = json_decode('{
+ "bounce": true,
+ "click": true,
+ "deferred": true,
+ "delivered": true,
+ "dropped": true,
+ "enabled": true,
+ "group_resubscribe": true,
+ "group_unsubscribe": true,
+ "open": true,
+ "processed": true,
+ "spam_report": true,
+ "unsubscribe": true,
+ "url": "url"
+}');
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->user()->webhooks()->event()->settings()->patch($request_body, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_user_webhooks_event_settings_get()
+ {
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->user()->webhooks()->event()->settings()->get(null, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_user_webhooks_event_test_post()
+ {
+ $request_body = json_decode('{
+ "url": "url"
+}');
+ $request_headers = array("X-Mock: 204");
+ $response = $this->sg->client->user()->webhooks()->event()->test()->post($request_body, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 204);
+ }
+
+ public function test_user_webhooks_parse_settings_get()
+ {
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->user()->webhooks()->parse()->settings()->get(null, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_user_webhooks_parse_stats_get()
+ {
+ $query_params = json_decode('{"aggregated_by": "day", "limit": "test_string", "start_date": "2016-01-01", "end_date": "2016-04-01", "offset": "test_string"}');
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->user()->webhooks()->parse()->stats()->get(null, $query_params, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_whitelabel_domains_post()
+ {
+ $request_body = json_decode('{
+ "automatic_security": false,
+ "custom_spf": true,
+ "default": true,
+ "domain": "example.com",
+ "ips": [
+ "192.168.1.1",
+ "192.168.1.2"
+ ],
+ "subdomain": "news",
+ "username": "john@example.com"
+}');
+ $request_headers = array("X-Mock: 201");
+ $response = $this->sg->client->whitelabel()->domains()->post($request_body, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 201);
+ }
+
+ public function test_whitelabel_domains_get()
+ {
+ $query_params = json_decode('{"username": "test_string", "domain": "test_string", "exclude_subusers": "true", "limit": 1, "offset": 1}');
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->whitelabel()->domains()->get(null, $query_params, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_whitelabel_domains_default_get()
+ {
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->whitelabel()->domains()->default()->get(null, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_whitelabel_domains_subuser_get()
+ {
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->whitelabel()->domains()->subuser()->get(null, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_whitelabel_domains_subuser_delete()
+ {
+ $request_headers = array("X-Mock: 204");
+ $response = $this->sg->client->whitelabel()->domains()->subuser()->delete(null, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 204);
+ }
+
+ public function test_whitelabel_domains__domain_id__patch()
+ {
+ $request_body = json_decode('{
+ "custom_spf": true,
+ "default": false
+}');
+ $domain_id = "test_url_param";
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->whitelabel()->domains()->_($domain_id)->patch($request_body, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_whitelabel_domains__domain_id__get()
+ {
+ $domain_id = "test_url_param";
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->whitelabel()->domains()->_($domain_id)->get(null, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_whitelabel_domains__domain_id__delete()
+ {
+ $domain_id = "test_url_param";
+ $request_headers = array("X-Mock: 204");
+ $response = $this->sg->client->whitelabel()->domains()->_($domain_id)->delete(null, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 204);
+ }
+
+ public function test_whitelabel_domains__domain_id__subuser_post()
+ {
+ $request_body = json_decode('{
+ "username": "jane@example.com"
+}');
+ $domain_id = "test_url_param";
+ $request_headers = array("X-Mock: 201");
+ $response = $this->sg->client->whitelabel()->domains()->_($domain_id)->subuser()->post($request_body, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 201);
+ }
+
+ public function test_whitelabel_domains__id__ips_post()
+ {
+ $request_body = json_decode('{
+ "ip": "192.168.0.1"
+}');
+ $id = "test_url_param";
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->whitelabel()->domains()->_($id)->ips()->post($request_body, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_whitelabel_domains__id__ips__ip__delete()
+ {
+ $id = "test_url_param";
+ $ip = "test_url_param";
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->whitelabel()->domains()->_($id)->ips()->_($ip)->delete(null, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_whitelabel_domains__id__validate_post()
+ {
+ $id = "test_url_param";
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->whitelabel()->domains()->_($id)->validate()->post(null, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_whitelabel_ips_post()
+ {
+ $request_body = json_decode('{
+ "domain": "example.com",
+ "ip": "192.168.1.1",
+ "subdomain": "email"
+}');
+ $request_headers = array("X-Mock: 201");
+ $response = $this->sg->client->whitelabel()->ips()->post($request_body, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 201);
+ }
+
+ public function test_whitelabel_ips_get()
+ {
+ $query_params = json_decode('{"ip": "test_string", "limit": 1, "offset": 1}');
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->whitelabel()->ips()->get(null, $query_params, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_whitelabel_ips__id__get()
+ {
+ $id = "test_url_param";
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->whitelabel()->ips()->_($id)->get(null, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_whitelabel_ips__id__delete()
+ {
+ $id = "test_url_param";
+ $request_headers = array("X-Mock: 204");
+ $response = $this->sg->client->whitelabel()->ips()->_($id)->delete(null, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 204);
+ }
+
+ public function test_whitelabel_ips__id__validate_post()
+ {
+ $id = "test_url_param";
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->whitelabel()->ips()->_($id)->validate()->post(null, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_whitelabel_links_post()
+ {
+ $request_body = json_decode('{
+ "default": true,
+ "domain": "example.com",
+ "subdomain": "mail"
+}');
+ $query_params = json_decode('{"limit": 1, "offset": 1}');
+ $request_headers = array("X-Mock: 201");
+ $response = $this->sg->client->whitelabel()->links()->post($request_body, $query_params, $request_headers);
+ $this->assertEquals($response->statusCode(), 201);
+ }
+
+ public function test_whitelabel_links_get()
+ {
+ $query_params = json_decode('{"limit": 1}');
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->whitelabel()->links()->get(null, $query_params, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_whitelabel_links_default_get()
+ {
+ $query_params = json_decode('{"domain": "test_string"}');
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->whitelabel()->links()->default()->get(null, $query_params, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_whitelabel_links_subuser_get()
+ {
+ $query_params = json_decode('{"username": "test_string"}');
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->whitelabel()->links()->subuser()->get(null, $query_params, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_whitelabel_links_subuser_delete()
+ {
+ $query_params = json_decode('{"username": "test_string"}');
+ $request_headers = array("X-Mock: 204");
+ $response = $this->sg->client->whitelabel()->links()->subuser()->delete(null, $query_params, $request_headers);
+ $this->assertEquals($response->statusCode(), 204);
+ }
+
+ public function test_whitelabel_links__id__patch()
+ {
+ $request_body = json_decode('{
+ "default": true
+}');
+ $id = "test_url_param";
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->whitelabel()->links()->_($id)->patch($request_body, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_whitelabel_links__id__get()
+ {
+ $id = "test_url_param";
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->whitelabel()->links()->_($id)->get(null, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_whitelabel_links__id__delete()
+ {
+ $id = "test_url_param";
+ $request_headers = array("X-Mock: 204");
+ $response = $this->sg->client->whitelabel()->links()->_($id)->delete(null, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 204);
+ }
+
+ public function test_whitelabel_links__id__validate_post()
+ {
+ $id = "test_url_param";
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->whitelabel()->links()->_($id)->validate()->post(null, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+
+ public function test_whitelabel_links__link_id__subuser_post()
+ {
+ $request_body = json_decode('{
+ "username": "jane@example.com"
+}');
+ $link_id = "test_url_param";
+ $request_headers = array("X-Mock: 200");
+ $response = $this->sg->client->whitelabel()->links()->_($link_id)->subuser()->post($request_body, null, $request_headers);
+ $this->assertEquals($response->statusCode(), 200);
+ }
+}
diff --git a/test/unit/bootstrap.php b/test/unit/bootstrap.php
index e5b7ecc..dfd484d 100644
--- a/test/unit/bootstrap.php
+++ b/test/unit/bootstrap.php
@@ -1,23 +1,4 @@
<?php
-
-include(dirname(dirname(__FILE__)) . '/../lib/SendGrid.php');
-include(dirname(dirname(__FILE__)) . '/../lib/Client.php');
-require __DIR__ . '/../../vendor/autoload.php';
-
-SendGrid::register_autoloader();
-
-function autoload_tests($class)
-{
-
- if (strpos($class, 'SendGridTest_') !== 0) {
- return;
- }
-
- $class = substr($class, 13);
- $file = str_replace('_', '/', $class);
- if (file_exists(dirname(__FILE__) . '/' . $file . '.php')) {
- require_once(dirname(__FILE__) . '/' . $file . '.php');
- }
-}
-
-spl_autoload_register('autoload_tests'); \ No newline at end of file
+//include(dirname(dirname(__FILE__)) . '/../lib/SendGrid.php');
+//include(dirname(dirname(__FILE__)) . '/../lib/helpers/mail/Mail.php');
+?> \ No newline at end of file
diff --git a/test/unit/gif.gif b/test/unit/gif.gif
deleted file mode 100644
index e76d4fc..0000000
--- a/test/unit/gif.gif
+++ /dev/null
Binary files differ
diff --git a/test/unit/helpers/mail/MailTest.php b/test/unit/helpers/mail/MailTest.php
new file mode 100644
index 0000000..30b040c
--- /dev/null
+++ b/test/unit/helpers/mail/MailTest.php
@@ -0,0 +1,184 @@
+<?php
+namespace SendGrid;
+
+class MailTest_Mail extends \PHPUnit_Framework_TestCase
+{
+ public function testBaseLineExample()
+ {
+ $mail = new Mail();
+
+ $email = new Email(null, "test@example.com");
+ $mail->setFrom($email);
+
+ $personalization = new Personalization();
+ $email = new Email(null, "test@example.com");
+ $personalization->addTo($email);
+ $mail->addPersonalization($personalization);
+
+ $mail->setSubject("Hello World from the SendGrid PHP Library");
+
+ $content = new Content("text/plain", "some text here");
+ $mail->addContent($content);
+ $content = new Content("text/html", "<html><body>some text here</body></html>");
+ $mail->addContent($content);
+
+ $json = json_encode($mail);
+
+ $this->assertEquals($json, '{"from":{"email":"test@example.com"},"personalizations":[{"to":[{"email":"test@example.com"}]}],"subject":"Hello World from the SendGrid PHP Library","content":[{"type":"text\/plain","value":"some text here"},{"type":"text\/html","value":"<html><body>some text here<\/body><\/html>"}]}');
+ }
+
+ public function testKitchenSinkExample()
+ {
+ $mail = new Mail();
+
+ $email = new Email("DX", "test@example.com");
+ $mail->setFrom($email);
+
+ $mail->setSubject("Hello World from the SendGrid PHP Library");
+
+ $personalization = new Personalization();
+ $email = new Email("Example User", "test@example.com");
+ $personalization->addTo($email);
+ $email = new Email("Example User", "test@example.com");
+ $personalization->addTo($email);
+ $email = new Email("Example User", "test@example.com");
+ $personalization->addCc($email);
+ $email = new Email("Example User", "test@example.com");
+ $personalization->addCc($email);
+ $email = new Email("Example User", "test@example.com");
+ $personalization->addBcc($email);
+ $email = new Email("Example User", "test@example.com");
+ $personalization->addBcc($email);
+ $personalization->setSubject("Hello World from the SendGrid PHP Library");
+ $personalization->addHeader("X-Test", "test");
+ $personalization->addHeader("X-Mock", "true");
+ $personalization->addSubstitution("%name%", "Example User");
+ $personalization->addSubstitution("%city%", "Denver");
+ $personalization->addCustomArg("user_id", "343");
+ $personalization->addCustomArg("type", "marketing");
+ $personalization->setSendAt(1443636843);
+ $mail->addPersonalization($personalization);
+
+ $personalization2 = new Personalization();
+ $email = new Email("Example User", "test@example.com");
+ $personalization2->addTo($email);
+ $email = new Email("Example User", "test@example.com");
+ $personalization2->addTo($email);
+ $email = new Email("Example User", "test@example.com");
+ $personalization2->addCc($email);
+ $email = new Email("Example User", "test@example.com");
+ $personalization2->addCc($email);
+ $email = new Email("Example User", "test@example.com");
+ $personalization2->addBcc($email);
+ $email = new Email("Example User", "test@example.com");
+ $personalization2->addBcc($email);
+ $personalization2->setSubject("Hello World from the SendGrid PHP Library");
+ $personalization2->addHeader("X-Test", "test");
+ $personalization2->addHeader("X-Mock", "true");
+ $personalization2->addSubstitution("%name%", "Example User");
+ $personalization2->addSubstitution("%city%", "Denver");
+ $personalization2->addCustomArg("user_id", "343");
+ $personalization2->addCustomArg("type", "marketing");
+ $personalization2->setSendAt(1443636843);
+ $mail->addPersonalization($personalization2);
+
+ $content = new Content("text/plain", "some text here");
+ $mail->addContent($content);
+ $content = new Content("text/html", "<html><body>some text here</body></html>");
+ $mail->addContent($content);
+
+ $attachment = new Attachment();
+ $attachment->setContent("TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIGFkaXBpc2NpbmcgZWxpdC4gQ3JhcyBwdW12");
+ $attachment->setType("application/pdf");
+ $attachment->setFilename("balance_001.pdf");
+ $attachment->setDisposition("attachment");
+ $attachment->setContentId("Balance Sheet");
+ $mail->addAttachment($attachment);
+
+ $attachment2 = new Attachment();
+ $attachment2->setContent("BwdW");
+ $attachment2->setType("image/png");
+ $attachment2->setFilename("banner.png");
+ $attachment2->setDisposition("inline");
+ $attachment2->setContentId("Banner");
+ $mail->addAttachment($attachment2);
+
+ $mail->setTemplateId("439b6d66-4408-4ead-83de-5c83c2ee313a");
+
+ $mail->addSection("%section1%", "Substitution Text for Section 1");
+ $mail->addSection("%section2%", "Substitution Text for Section 2");
+
+ $mail->addHeader("X-Test1", "1");
+ $mail->addHeader("X-Test2", "2");
+
+ $mail->addCategory("May");
+ $mail->addCategory("2016");
+
+ $mail->addCustomArg("campaign", "welcome");
+ $mail->addCustomArg("weekday", "morning");
+
+ $mail->setSendAt(1443636842);
+
+ $asm = new ASM();
+ $asm->setGroupId(99);
+ $asm->setGroupsToDisplay([4,5,6,7,8]);
+ $mail->setASM($asm);
+
+ $mail->setIpPoolName("23");
+
+ $mail_settings = new MailSettings();
+ $bcc_settings = new BccSettings();
+ $bcc_settings->setEnable(True);
+ $bcc_settings->setEmail("test@example.com");
+ $mail_settings->setBccSettings($bcc_settings);
+ $sandbox_mode = new SandBoxMode();
+ $sandbox_mode->setEnable(True);
+ $mail_settings->setSandboxMode($sandbox_mode);
+ $bypass_list_management = new BypassListManagement();
+ $bypass_list_management->setEnable(True);
+ $mail_settings->setBypassListManagement($bypass_list_management);
+ $footer = new Footer();
+ $footer->setEnable(true);
+ $footer->setText("Footer Text");
+ $footer->setHtml("<html><body>Footer Text</body></html>");
+ $mail_settings->setFooter($footer);
+ $spam_check = new SpamCheck();
+ $spam_check->setEnable(True);
+ $spam_check->setThreshold(1);
+ $spam_check->setPostToUrl("https://spamcatcher.sendgrid.com");
+ $mail_settings->setSpamCheck($spam_check);
+ $mail->setMailSettings($mail_settings);
+
+ $tracking_settings = new TrackingSettings();
+ $click_tracking = new ClickTracking();
+ $click_tracking->setEnable(true);
+ $click_tracking->setEnableText(True);
+ $tracking_settings->setClickTracking($click_tracking);
+ $open_tracking = new OpenTracking();
+ $open_tracking->setEnable(True);
+ $open_tracking->setSubstitutionTag("Optional tag to replace with the open image in the body of the message");
+ $tracking_settings->setOpenTracking($open_tracking);
+ $subscription_tracking = new SubscriptionTracking();
+ $subscription_tracking->setEnable(True);
+ $subscription_tracking->setText("text to insert into the text/plain portion of the message");
+ $subscription_tracking->setHtml("<html><body>html to insert into the text/html portion of the message</body></html>");
+ $subscription_tracking->setSubstitutionTag("Optional tag to replace with the open image in the body of the message");
+ $tracking_settings->setSubscriptionTracking($subscription_tracking);
+ $ganalytics = new Ganalytics();
+ $ganalytics->setEnable(True);
+ $ganalytics->setCampaignSource("some source");
+ $ganalytics->setCampaignTerm("some term");
+ $ganalytics->setCampaignContent("some content");
+ $ganalytics->setCampaignName("some name");
+ $ganalytics->setCampaignMedium("some medium");
+ $tracking_settings->setGanalytics($ganalytics);
+ $mail->setTrackingSettings($tracking_settings);
+
+ $reply_to = new ReplyTo("test@example.com");
+ $mail->setReplyTo($reply_to);
+
+ $json = json_encode($mail);
+
+ $this->assertEquals($json, '{"from":{"name":"DX","email":"test@example.com"},"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 SendGrid PHP Library","headers":{"X-Test":"test","X-Mock":"true"},"substitutions":{"%name%":"Example User","%city%":"Denver"},"custom_args":{"user_id":"343","type":"marketing"},"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 SendGrid PHP Library","headers":{"X-Test":"test","X-Mock":"true"},"substitutions":{"%name%":"Example User","%city%":"Denver"},"custom_args":{"user_id":"343","type":"marketing"},"send_at":1443636843}],"subject":"Hello World from the SendGrid PHP Library","content":[{"type":"text\/plain","value":"some text here"},{"type":"text\/html","value":"<html><body>some text here<\/body><\/html>"}],"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":"439b6d66-4408-4ead-83de-5c83c2ee313a","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":"<html><body>Footer Text<\/body><\/html>"},"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><body>html to insert into the text\/html portion of the message<\/body><\/html>","substitution_tag":"Optional tag to replace with the open image in the body of the message"},"ganalytics":{"enable":true,"utm_source":"some source","utm_medium":"some medium","utm_term":"some term","utm_content":"some content","utm_campaign":"some name"}},"reply_to":{"email":"test@example.com"}}');
+ }
+} \ No newline at end of file
diff --git a/test/unit/phpunit.xml.dist b/test/unit/phpunit.xml.dist
index 7a2cd9b..f216f0f 100644
--- a/test/unit/phpunit.xml.dist
+++ b/test/unit/phpunit.xml.dist
@@ -3,9 +3,7 @@
<testsuites>
<testsuite name="General">
<file>./SendGrid.php</file>
- <file>./SendGrid/Email.php</file>
- <file>./SendGrid/Response.php</file>
- <file>./SendGrid/Exception.php</file>
+ <file>./helpers/mail/Mail.php</file>
</testsuite>
</testsuites>
</phpunit>
diff --git a/test/unit/resources/api_keysTest.php b/test/unit/resources/api_keysTest.php
deleted file mode 100644
index e89ffeb..0000000
--- a/test/unit/resources/api_keysTest.php
+++ /dev/null
@@ -1,99 +0,0 @@
-<?php
-require_once __DIR__.'/baseTest.php';
-
-class SendGridTest_APIKeys extends baseTest
-{
- public function testGET()
- {
- $code = 200;
- $headers = array('Content-Type' => 'application/json');
- $body = '{"result": [{"name": "default", "api_key_id": "XXXXXXXXXX"}]}';
- $sendgrid = $this->buildClient($code, $headers, $body);
- $response = $sendgrid->api_keys->get();
- $this->assertEquals($code, $response->getStatusCode());
- $this->assertEquals($body, $response->getBody());
- }
-
- public function testPOST()
- {
- $code = 200;
- $headers = array('Content-Type' => 'application/json');
- $body = '{
- "api_key": "SG.xxxxxxxx.yyyyyyyy",
- "api_key_id": "xxxxxxxx",
- "name": "My API Key"
- }';
- $sendgrid = $this->buildClient($code, $headers, $body);
- $name = "My API Key";
- $response = $sendgrid->api_keys->post($name);
- $this->assertEquals($code, $response->getStatusCode());
- $this->assertEquals($body, $response->getBody());
- }
-
- public function testPOST_withScope()
- {
- $code = 200;
- $headers = array('Content-Type' => 'application/json');
- $body = '{
- "api_key": "SG.xxxxxxxx.yyyyyyyy",
- "api_key_id": "xxxxxxxx",
- "name": "My API Key",
- "scopes": [
- "mail.send",
- "alerts.create",
- "alerts.read"
- ]
- }';
- $sendgrid = $this->buildClient($code, $headers, $body);
- $name = "My API Key";
- $scopes = array("mail.send", "alerts.create", "alerts.read");
- $response = $sendgrid->api_keys->post($name, $scopes);
- $this->assertEquals($code, $response->getStatusCode());
- $this->assertEquals($body, $response->getBody());
- }
-
- public function testPATCH()
- {
- $code = 200;
- $headers = array('Content-Type' => 'application/json');
- $body = '{
- "api_key_id": "qfTQ6KG0QBiwWdJ0-pCLCA",
- "name": "A New Hope"
- }';
- $sendgrid = $this->buildClient($code, $headers, $body);
- $response = $sendgrid->api_keys->patch("qfTQ6KG0QBiwWdJ0-pCLCA", "Magic Key Updated");
- $this->assertEquals($code, $response->getStatusCode());
- $this->assertEquals($body, $response->getBody());
- }
-
- public function testPUT()
- {
- $code = 200;
- $headers = array('Content-Type' => 'application/json');
- $body = '{
- "api_key_id": "qfTQ6KG0QBiwWdJ0-pCLCA",
- "name": "A New Hope",
- "scopes": [
- "user.profile.read",
- "user.profile.update"
- ]
- }';
- $scopes = array("user.profile.read", "user.profile.update");
- $sendgrid = $this->buildClient($code, $headers, $body);
- $response = $sendgrid->api_keys->put("qfTQ6KG0QBiwWdJ0-pCLCA", "A New Hope", $scopes);
- $this->assertEquals($code, $response->getStatusCode());
- $this->assertEquals($body, $response->getBody());
- }
-
- public function testDELETE()
- {
- $code = 204;
- $headers = '';
- $body = '';
- $sendgrid = $this->buildClient($code, $headers, $body);
- $response = $sendgrid->api_keys->delete("qfTQ6KG0QBiwWdJ0-pCLCA");
- $this->assertEquals($code, $response->getStatusCode());
- $this->assertEquals($body, $response->getBody());
- }
-
-} \ No newline at end of file
diff --git a/test/unit/resources/asm_groupsTest.php b/test/unit/resources/asm_groupsTest.php
deleted file mode 100644
index 255a5a6..0000000
--- a/test/unit/resources/asm_groupsTest.php
+++ /dev/null
@@ -1,17 +0,0 @@
-<?php
-require_once __DIR__.'/baseTest.php';
-
-class SendGridTest_ASMGroups extends baseTest
-{
- public function testGET()
- {
- $code = 200;
- $headers = array('Content-Type' => 'application/json');
- $body = '[{"id":01,"name":"Newsletter","description":"Our monthly newsletter","last_email_sent_at":null,"is_default":true,"unsubscribes":0},{"id":02,"name":"Alert","description":"Daily alerts","last_email_sent_at":null,"is_default":true,"unsubscribes":0},{"id":603,"name":"Announcements","description":"Announcements of events and features.","last_email_sent_at":null,"is_default":true,"unsubscribes":0}]';
- $sendgrid = $this->buildClient($code, $headers, $body);
- $response = $sendgrid->asm_groups->get();
- $this->assertEquals($code, $response->getStatusCode());
- $this->assertEquals($body, $response->getBody());
- }
-}
-
diff --git a/test/unit/resources/asm_suppressionsTest.php b/test/unit/resources/asm_suppressionsTest.php
deleted file mode 100644
index 39ae95e..0000000
--- a/test/unit/resources/asm_suppressionsTest.php
+++ /dev/null
@@ -1,48 +0,0 @@
-<?php
-require_once __DIR__.'/baseTest.php';
-
-class SendGridTest_ASMSuppressions extends baseTest
-{
- public function testGET()
- {
- $code = 200;
- $headers = array('Content-Type' => 'application/json');
- $body = '["elmer.thomas+test-add-unsub@gmail.com","elmer.thomas+test1@gmail.com"]';
- $sendgrid = $this->buildClient($code, $headers, $body);
- $response = $sendgrid->asm_suppressions->get(70);
- $this->assertEquals($code, $response->getStatusCode());
- $this->assertEquals($body, $response->getBody());
- }
-
- public function testPOST()
- {
- $code = 200;
- $headers = array('Content-Type' => 'application/json');
- $body = '{"recipient_emails":["elmer.thomas+test1@gmail.com"]}';
- $sendgrid = $this->buildClient($code, $headers, $body);
- $group_id = 70;
- $email = 'elmer.thomas+test1@gmail.com';
- $response = $sendgrid->asm_suppressions->post($group_id, $email);
- $this->assertEquals($code, $response->getStatusCode());
- $this->assertEquals($body, $response->getBody());
-
- $body = '{"recipient_emails":["elmer.thomas+test1@gmail.com"]}';
- $sendgrid = $this->buildClient($code, $headers, $body);
- $group_id = 70;
- $email = array('elmer.thomas+test2@gmail.com', 'elmer.thomas+test3@gmail.com');
- $response = $sendgrid->asm_suppressions->post($group_id, $email);
- $this->assertEquals($code, $response->getStatusCode());
- $this->assertEquals($body, $response->getBody());
- }
-
- public function testDELETE()
- {
- $code = 204;
- $headers = '';
- $body = '';
- $sendgrid = $this->buildClient($code, $headers, $body);
- $response = $sendgrid->asm_suppressions->delete(70, "elmer.thomas+test1@gmail.com");
- $this->assertEquals($code, $response->getStatusCode());
- $this->assertEquals($body, $response->getBody());
- }
-}
diff --git a/test/unit/resources/baseTest.php b/test/unit/resources/baseTest.php
deleted file mode 100644
index 5011379..0000000
--- a/test/unit/resources/baseTest.php
+++ /dev/null
@@ -1,20 +0,0 @@
-<?php
-require __DIR__.'/../../../vendor/autoload.php';
-use Guzzle\Tests\GuzzleTestCase;
-use Guzzle\Plugin\Mock\MockPlugin;
-use Guzzle\Http\Message\Response;
-use Guzzle\Http\Client as HTTPClient;
-
-class baseTest extends GuzzleTestCase
-{
- public function buildClient($code, $headers, $body){
- $response = new Response($code, $headers, $body);
- $client = new HTTPClient('https://api.sendgrid.com');
- $mock = new MockPlugin();
- $mock->addResponse($response);
- $client->addSubscriber($mock);
- $sendgrid = new Client('sendgrid_apikey');
- $sendgrid->setClient($client);
- return $sendgrid;
- }
-} \ No newline at end of file
diff --git a/test/unit/resources/global_statsTest.php b/test/unit/resources/global_statsTest.php
deleted file mode 100644
index 49f5a3c..0000000
--- a/test/unit/resources/global_statsTest.php
+++ /dev/null
@@ -1,82 +0,0 @@
-<?php
-require_once __DIR__.'/baseTest.php';
-
-class SendGridTest_GlobalStats extends baseTest
-{
- public function testGET()
- {
- $code = 200;
- $headers = array('Content-Type' => 'application/json');
- $body = '[
- {
- "date": "2015-01-01",
- "stats": [
- {
- "metrics": {
- "blocks": 1,
- "bounce_drops": 0,
- "bounces": 0,
- "clicks": 0,
- "deferred": 1,
- "delivered": 1,
- "invalid_emails": 1,
- "opens": 1,
- "processed": 2,
- "requests": 3,
- "spam_report_drops": 0,
- "spam_reports": 0,
- "unique_clicks": 0,
- "unique_opens": 1,
- "unsubscribe_drops": 0,
- "unsubscribes": 0
- }
- }
- ]
- },
- {
- "date": "2015-01-02",
- "stats": [
- {
- "metrics": {
- "blocks": 0,
- "bounce_drops": 0,
- "bounces": 0,
- "clicks": 0,
- "deferred": 0,
- "delivered": 0,
- "invalid_emails": 0,
- "opens": 0,
- "processed": 0,
- "requests": 0,
- "spam_report_drops": 0,
- "spam_reports": 0,
- "unique_clicks": 0,
- "unique_opens": 0,
- "unsubscribe_drops": 0,
- "unsubscribes": 0
- }
- }
- ]
- }
- ]';
-
- $sendgrid = $this->buildClient($code, $headers, $body);
- $start_date = "2015-01-01";
- $response = $sendgrid->global_stats->get($start_date);
- $this->assertEquals($code, $response->getStatusCode());
- $this->assertEquals($body, $response->getBody());
-
- $sendgrid = $this->buildClient($code, $headers, $body);
- $end_date = "2015-01-02";
- $response = $sendgrid->global_stats->get($start_date, $end_date);
- $this->assertEquals($code, $response->getStatusCode());
- $this->assertEquals($body, $response->getBody());
-
- $sendgrid = $this->buildClient($code, $headers, $body);
- $aggregated_by = "day";
- $response = $sendgrid->global_stats->get($start_date, $end_date, $aggregated_by);
- $this->assertEquals($code, $response->getStatusCode());
- $this->assertEquals($body, $response->getBody());
- }
-
-} \ No newline at end of file
diff --git a/test/unit/text b/test/unit/text
deleted file mode 100644
index 6ad4340..0000000
--- a/test/unit/text
+++ /dev/null
@@ -1 +0,0 @@
-This is some text in a text file - missing the .txt extension.