You've already forked openaccounting-server
mirror of
https://github.com/openaccounting/oa-server.git
synced 2025-12-09 00:50:59 +13:00
initial commit
This commit is contained in:
58
vendor/github.com/sendgrid/rest/CHANGELOG.md
generated
vendored
Normal file
58
vendor/github.com/sendgrid/rest/CHANGELOG.md
generated
vendored
Normal file
@@ -0,0 +1,58 @@
|
||||
# Change Log
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
This project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
## [2.4.1] - 2018-4-09
|
||||
### Fixed
|
||||
- Pull #71, Solves #70
|
||||
- Fix Travis CI Build
|
||||
- Special thanks to [Vasko Zdravevski](https://github.com/vaskoz) for the PR!
|
||||
|
||||
## [2.4.0] - 2017-4-10
|
||||
### Added
|
||||
- Pull #18, Solves #17
|
||||
- Add RestError Struct for an error handling
|
||||
- Special thanks to [Takahiro Ikeuchi](https://github.com/iktakahiro) for the PR!
|
||||
|
||||
## [2.3.1] - 2016-10-14
|
||||
### Changed
|
||||
- Pull #15, solves Issue #7
|
||||
- Moved QueryParams processing into BuildRequestObject
|
||||
- Special thanks to [Gábor Lipták](https://github.com/gliptak) for the PR!
|
||||
|
||||
## [2.3.0] - 2016-10-04
|
||||
### Added
|
||||
- Pull [#10] [Allow for custom Content-Types](https://github.com/sendgrid/rest/issues/10)
|
||||
|
||||
## [2.2.0] - 2016-07-28
|
||||
### Added
|
||||
- Pull [#9](https://github.com/sendgrid/rest/pull/9): Allow for setting a custom HTTP client
|
||||
- [Here](https://github.com/sendgrid/rest/blob/master/rest_test.go#L127) is an example of usage
|
||||
- This enables usage of the [sendgrid-go library](https://github.com/sendgrid/sendgrid-go) on [Google App Engine (GAE)](https://cloud.google.com/appengine/)
|
||||
- Special thanks to [Chris Broadfoot](https://github.com/broady) and [Sridhar Venkatakrishnan](https://github.com/sridharv) for providing code and feedback!
|
||||
|
||||
## [2.1.0] - 2016-06-10
|
||||
### Added
|
||||
- Automatically add Content-Type: application/json when there is a request body
|
||||
|
||||
## [2.0.0] - 2016-06-03
|
||||
### Changed
|
||||
- Made the Request and Response variables non-redundant. e.g. request.RequestBody becomes request.Body
|
||||
|
||||
## [1.0.2] - 2016-04-07
|
||||
### Added
|
||||
- these changes are thanks to [deckarep](https://github.com/deckarep). Thanks!
|
||||
- more updates to error naming convention
|
||||
- more error handing on HTTP request
|
||||
|
||||
## [1.0.1] - 2016-04-07
|
||||
### Added
|
||||
- these changes are thanks to [deckarep](https://github.com/deckarep). Thanks!
|
||||
- update error naming convention
|
||||
- explicitly define supported HTTP verbs
|
||||
- better error handing on HTTP request
|
||||
|
||||
## [1.0.0] - 2016-04-05
|
||||
### Added
|
||||
- We are live!
|
||||
41
vendor/github.com/sendgrid/rest/CODE_OF_CONDUCT.md
generated
vendored
Normal file
41
vendor/github.com/sendgrid/rest/CODE_OF_CONDUCT.md
generated
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
# SendGrid Community Code of Conduct
|
||||
|
||||
The SendGrid open source community is made up of members from around the globe with a diverse set of skills, personalities, and experiences. It is through these differences that our community experiences successes and continued growth. When you're working with members of the community, we encourage you to follow these guidelines, which help steer our interactions and strive to maintain a positive, successful and growing community.
|
||||
|
||||
### Be Open
|
||||
Members of the community are open to collaboration, whether it's on pull requests, code reviews, approvals, issues or otherwise. We're receptive to constructive comments and criticism, as the experiences and skill sets of all members contribute to the whole of our efforts. We're accepting of all who wish to take part in our activities, fostering an environment where anyone can participate, and everyone can make a difference.
|
||||
|
||||
### Be Considerate
|
||||
Members of the community are considerate of their peers, which include other contributors and users of SendGrid. We're thoughtful when addressing the efforts of others, keeping in mind that often the labor was completed with the intent of the good of the community. We're attentive in our communications, whether in person or online, and we're tactful when approaching differing views.
|
||||
|
||||
### Be Respectful
|
||||
Members of the community are respectful. We're respectful of others, their positions, their skills, their commitments and their efforts. We're respectful of the volunteer efforts that permeate the SendGrid community. We're respectful of the processes outlined in the community, and we work within them. When we disagree, we are courteous in raising our issues. Overall, we're good to each other. We contribute to this community not because we have to, but because we want to. If we remember that, these guidelines will come naturally.
|
||||
|
||||
## Additional Guidance
|
||||
|
||||
### Disclose Potential Conflicts of Interest
|
||||
Community discussions often involve interested parties. We expect participants to be aware when they are conflicted due to employment or other projects they are involved in and disclose those interests to other project members. When in doubt, over-disclose. Perceived conflicts of interest are important to address so that the community’s decisions are credible even when unpopular, difficult or favorable to the interests of one group over another.
|
||||
|
||||
### Interpretation
|
||||
This Code is not exhaustive or complete. It is not a rulebook; it serves to distill our common understanding of a collaborative, shared environment and goals. We expect it to be followed in spirit as much as in the letter. When in doubt, try to abide by [SendGrid’s cultural values](https://sendgrid.com/blog/employee-engagement-the-4h-way) defined by our “4H’s”: Happy, Hungry, Humble and Honest.
|
||||
|
||||
### Enforcement
|
||||
Most members of the SendGrid community always comply with this Code, not because of the existence of this Code, but because they have long experience participating in open source communities where the conduct described above is normal and expected. However, failure to observe this Code may be grounds for suspension, reporting the user for abuse or changing permissions for outside contributors.
|
||||
|
||||
## If you have concerns about someone’s conduct
|
||||
**Initiate Direct Contact** - It is always appropriate to email a community member (if contact information is available), mention that you think their behavior was out of line, and (if necessary) point them to this Code.
|
||||
|
||||
**Discuss Publicly** - Discussing publicly is always acceptable. Note, though, that approaching the person directly may be better, as it tends to make them less defensive, and it respects the time of other community members, so you probably want to try direct contact first.
|
||||
|
||||
**Contact the Moderators** - You can reach the SendGrid moderators by emailing dx@sendgrid.com.
|
||||
|
||||
## Submission to SendGrid Repositories
|
||||
Finally, just a reminder, changes to the SendGrid repositories will only be accepted upon completion of the [SendGrid Contributor Agreement](https://cla.sendgrid.com).
|
||||
|
||||
## Attribution
|
||||
|
||||
SendGrid thanks the following, on which it draws for content and inspiration:
|
||||
|
||||
* [Python Community Code of Conduct](https://www.python.org/psf/codeofconduct/)
|
||||
* [Open Source Initiative General Code of Conduct](https://opensource.org/codeofconduct)
|
||||
* [Apache Code of Conduct](https://www.apache.org/foundation/policies/conduct.html)
|
||||
185
vendor/github.com/sendgrid/rest/CONTRIBUTING.md
generated
vendored
Normal file
185
vendor/github.com/sendgrid/rest/CONTRIBUTING.md
generated
vendored
Normal file
@@ -0,0 +1,185 @@
|
||||
Hello! Thank you for choosing to help contribute to one of the SendGrid open source projects. 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/rest/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) be filled out by every contributor to a SendGrid open source project.
|
||||
|
||||
Our goal with the CLA is to clarify the rights of our contributors and reduce other risks arising from inappropriate contributions. The CLA also clarifies the rights SendGrid holds in each contribution and helps to avoid misunderstandings over what rights each contributor is required to grant to SendGrid when making a contribution. In this way the CLA encourages broad participation by our open source community and helps us build strong open source projects, free from any individual contributor withholding or revoking rights to any contribution.
|
||||
|
||||
SendGrid does not merge a pull request made against a SendGrid open source project until that pull request is associated with a signed CLA. Copies of the CLA are available [here](https://gist.github.com/SendGridDX/98b42c0a5d500058357b80278fde3be8#file-sendgrid-cla).
|
||||
|
||||
When you create a Pull Request, after a few seconds, a comment will appear with a link to the CLA. Click the link and fill out the brief form and then click the "I agree" button and you are all set. You will not be asked to re-sign the CLA unless we make a change.
|
||||
|
||||
There are a few ways to contribute, which we'll enumerate below:
|
||||
|
||||
<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/rest/.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 rest code base. Thank you!
|
||||
|
||||
### Development Environment ###
|
||||
|
||||
#### Install and Run Locally ####
|
||||
|
||||
##### Prerequisites #####
|
||||
|
||||
- Go version 1.6
|
||||
|
||||
##### Initial setup: #####
|
||||
|
||||
```bash
|
||||
git clone https://github.com/sendgrid/rest.git
|
||||
cd rest
|
||||
```
|
||||
|
||||
##### Execute: #####
|
||||
|
||||
See the [examples folder](https://github.com/sendgrid/rest/tree/master/examples) to get started quickly.
|
||||
|
||||
If you want to try the SendGrid example:
|
||||
|
||||
First, get your free SendGrid account [here](https://sendgrid.com/free?source=rest).
|
||||
|
||||
You will need to setup the following environment to use the SendGrid example:
|
||||
|
||||
```
|
||||
echo "export SENDGRID-API-KEY='YOUR-API-KEY'" > sendgrid.env
|
||||
echo "sendgrid.env" >> .gitignore
|
||||
source ./sendgrid.env
|
||||
go run examples/example.go
|
||||
```
|
||||
|
||||
<a name="understanding-the-codebase"></a>
|
||||
## Understanding the Code Base
|
||||
|
||||
**/examples**
|
||||
|
||||
Working examples that demonstrate usage.
|
||||
|
||||
**rest.go**
|
||||
|
||||
There is a struct to hold both the request and response to the API server.
|
||||
|
||||
The main function that does the heavy lifting (and external entry point) is `API`.
|
||||
|
||||
<a name="testing"></a>
|
||||
## Testing
|
||||
|
||||
All PRs require passing tests before the PR will be reviewed.
|
||||
|
||||
All test files are in [`rest-test.go`](https://github.com/sendgrid/rest/blob/master/rest_test.go).
|
||||
|
||||
For the purposes of contributing to this repo, please update the [`rest-test.go`](https://github.com/sendgrid/rest/blob/master/rest_test.go) file with unit tests as you modify the code.
|
||||
|
||||
Run the test:
|
||||
|
||||
```bash
|
||||
go test -v
|
||||
```
|
||||
|
||||
<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.
|
||||
|
||||
- [Go Code Review Comments](https://github.com/golang/go/wiki/CodeReviewComments)
|
||||
|
||||
Please run your code through:
|
||||
|
||||
- [fmt](https://blog.golang.org/go-fmt-your-code)
|
||||
|
||||
## 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/rest
|
||||
# Navigate to the newly cloned directory
|
||||
cd rest
|
||||
# Assign the original repo to a remote called "upstream"
|
||||
git remote add upstream https://github.com/sendgrid/rest
|
||||
```
|
||||
|
||||
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.
|
||||
21
vendor/github.com/sendgrid/rest/LICENSE.txt
generated
vendored
Normal file
21
vendor/github.com/sendgrid/rest/LICENSE.txt
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2016-2018 SendGrid, Inc.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
162
vendor/github.com/sendgrid/rest/README.md
generated
vendored
Normal file
162
vendor/github.com/sendgrid/rest/README.md
generated
vendored
Normal file
@@ -0,0 +1,162 @@
|
||||

|
||||
|
||||
[](https://travis-ci.org/sendgrid/rest)
|
||||
[](http://godoc.org/github.com/sendgrid/rest)
|
||||
[](https://goreportcard.com/report/github.com/sendgrid/rest)
|
||||
[](https://dx.sendgrid.com/newsletter/go)
|
||||
[](https://twitter.com/sendgrid)
|
||||
[](https://github.com/sendgrid/rest/graphs/contributors)
|
||||
[](./LICENSE.txt)
|
||||
|
||||
**Quickly and easily access any RESTful or RESTful-like API.**
|
||||
|
||||
If you are looking for the SendGrid API client library, please see [this repo](https://github.com/sendgrid/sendgrid-go).
|
||||
|
||||
# Announcements
|
||||
|
||||
All updates to this library is documented in our [CHANGELOG](https://github.com/sendgrid/rest/blob/master/CHANGELOG.md).
|
||||
|
||||
# Table of Contents
|
||||
- [Installation](#installation)
|
||||
- [Quick Start](#quick-start)
|
||||
- [Usage](#usage)
|
||||
- [Roadmap](#roadmap)
|
||||
- [How to Contribute](#contribute)
|
||||
- [About](#about)
|
||||
- [License](#license)
|
||||
|
||||
<a name="installation"></a>
|
||||
# Installation
|
||||
|
||||
## Prerequisites
|
||||
|
||||
- Go version 1.6.X, 1.7.X, 1.8.X, 1.9.X or 1.10.X
|
||||
|
||||
## Install Package
|
||||
|
||||
```bash
|
||||
go get github.com/sendgrid/rest
|
||||
```
|
||||
|
||||
## Setup Environment Variables
|
||||
|
||||
### Initial Setup
|
||||
|
||||
```bash
|
||||
cp .env_sample .env
|
||||
```
|
||||
|
||||
### Environment Variable
|
||||
|
||||
Update the development environment with your [SENDGRID_API_KEY](https://app.sendgrid.com/settings/api_keys), for example:
|
||||
|
||||
```bash
|
||||
echo "export SENDGRID_API_KEY='YOUR_API_KEY'" > sendgrid.env
|
||||
echo "sendgrid.env" >> .gitignore
|
||||
source ./sendgrid.env
|
||||
```
|
||||
|
||||
<a name="quick-start"></a>
|
||||
# Quick Start
|
||||
|
||||
`GET /your/api/{param}/call`
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import "github.com/sendgrid/rest"
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
const host = "https://api.example.com"
|
||||
param := "myparam"
|
||||
endpoint := "/your/api/" + param + "/call"
|
||||
baseURL := host + endpoint
|
||||
method := rest.Get
|
||||
request := rest.Request{
|
||||
Method: method,
|
||||
BaseURL: baseURL,
|
||||
}
|
||||
response, err := rest.Send(request)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
} else {
|
||||
fmt.Println(response.StatusCode)
|
||||
fmt.Println(response.Body)
|
||||
fmt.Println(response.Headers)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
`POST /your/api/{param}/call` with headers, query parameters and a request body.
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import "github.com/sendgrid/rest"
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
const host = "https://api.example.com"
|
||||
param := "myparam"
|
||||
endpoint := "/your/api/" + param + "/call"
|
||||
baseURL := host + endpoint
|
||||
Headers := make(map[string]string)
|
||||
key := os.Getenv("API_KEY")
|
||||
Headers["Authorization"] = "Bearer " + key
|
||||
Headers["X-Test"] = "Test"
|
||||
var Body = []byte(`{"some": 0, "awesome": 1, "data": 3}`)
|
||||
queryParams := make(map[string]string)
|
||||
queryParams["hello"] = "0"
|
||||
queryParams["world"] = "1"
|
||||
method := rest.Post
|
||||
request = rest.Request{
|
||||
Method: method,
|
||||
BaseURL: baseURL,
|
||||
Headers: Headers,
|
||||
QueryParams: queryParams,
|
||||
Body: Body,
|
||||
}
|
||||
response, err := rest.Send(request)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
} else {
|
||||
fmt.Println(response.StatusCode)
|
||||
fmt.Println(response.Body)
|
||||
fmt.Println(response.Headers)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
<a name="usage"></a>
|
||||
# Usage
|
||||
|
||||
- [Usage Examples](USAGE.md)
|
||||
|
||||
<a name="roadmap"></a>
|
||||
# Roadmap
|
||||
|
||||
If you are interested in the future direction of this project, please take a look at our [milestones](https://github.com/sendgrid/rest/milestones). We would love to hear your feedback.
|
||||
|
||||
<a name="contribute"></a>
|
||||
# How to Contribute
|
||||
|
||||
We encourage contribution to our projects, please see our [CONTRIBUTING](https://github.com/sendgrid/rest/blob/master/CONTRIBUTING.md) guide for details.
|
||||
|
||||
Quick links:
|
||||
|
||||
- [Feature Request](https://github.com/sendgrid/rest/blob/master/CONTRIBUTING.md#feature-request)
|
||||
- [Bug Reports](https://github.com/sendgrid/rest/blob/master/CONTRIBUTING.md#submit-a-bug-report)
|
||||
- [Sign the CLA to Create a Pull Request](https://github.com/sendgrid/rest/blob/master/CONTRIBUTING.md#cla)
|
||||
- [Improvements to the Codebase](https://github.com/sendgrid/rest/blob/master/CONTRIBUTING.md#improvements-to-the-codebase)
|
||||
|
||||
<a name="about"></a>
|
||||
# About
|
||||
|
||||
rest is guided and supported by the SendGrid [Developer Experience Team](mailto:dx@sendgrid.com).
|
||||
|
||||
rest is maintained and funded by SendGrid, Inc. The names and logos for rest are trademarks of SendGrid, Inc.
|
||||
|
||||
<a name="license"></a>
|
||||
# License
|
||||
[The MIT License (MIT)](LICENSE.txt)
|
||||
62
vendor/github.com/sendgrid/rest/TROUBLESHOOTING.md
generated
vendored
Normal file
62
vendor/github.com/sendgrid/rest/TROUBLESHOOTING.md
generated
vendored
Normal file
@@ -0,0 +1,62 @@
|
||||
## Table of Contents
|
||||
|
||||
* [Viewing the Request Body](#request-body)
|
||||
|
||||
|
||||
<a name="request-body"></a>
|
||||
## Viewing the Request Body
|
||||
|
||||
When debugging or testing, it may be useful to exampine the raw request body to compare against the [documented format](https://sendgrid.com/docs/API_Reference/api_v3.html).
|
||||
|
||||
Example Code
|
||||
```go
|
||||
package main
|
||||
|
||||
import "github.com/sendgrid/rest"
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
const host = "https://api.example.com"
|
||||
param := "myparam"
|
||||
endpoint := "/your/api/" + param + "/call"
|
||||
baseURL := host + endpoint
|
||||
Headers := make(map[string]string)
|
||||
key := os.Getenv("API_KEY")
|
||||
Headers["Authorization"] = "Bearer " + key
|
||||
Headers["X-Test"] = "Test"
|
||||
var Body = []byte(`{"some": 0, "awesome": 1, "data": 3}`)
|
||||
queryParams := make(map[string]string)
|
||||
queryParams["hello"] = "0"
|
||||
queryParams["world"] = "1"
|
||||
method := rest.Post
|
||||
request = rest.Request{
|
||||
Method: method,
|
||||
BaseURL: baseURL,
|
||||
Headers: Headers,
|
||||
QueryParams: queryParams,
|
||||
Body: Body,
|
||||
}
|
||||
response, err := rest.API(request)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
} else {
|
||||
fmt.Println(response.StatusCode)
|
||||
fmt.Println(response.Body)
|
||||
fmt.Println(response.Headers)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
You can do this right before you call
|
||||
`response, err := rest.API(request)` like so:
|
||||
|
||||
```go
|
||||
fmt.Printf("Request Body: %v \n", string(request.Body))
|
||||
|
||||
req, e := BuildRequestObject(request)
|
||||
requestDump, err := httputil.DumpRequest(req, true)
|
||||
if err != nil {
|
||||
t.Errorf("Error : %v", err)
|
||||
}
|
||||
fmt.Printf("Request : %v \n", string(requestDump))
|
||||
```
|
||||
211
vendor/github.com/sendgrid/rest/USAGE.md
generated
vendored
Normal file
211
vendor/github.com/sendgrid/rest/USAGE.md
generated
vendored
Normal file
@@ -0,0 +1,211 @@
|
||||
# Usage
|
||||
|
||||
Usage examples for SendGrid REST library
|
||||
|
||||
## Initialization
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/sendgrid/rest"
|
||||
)
|
||||
|
||||
// Build the URL
|
||||
const host = "https://api.sendgrid.com"
|
||||
endpoint := "/v3/api_keys"
|
||||
baseURL := host + endpoint
|
||||
|
||||
// Build the request headers
|
||||
key := os.Getenv("SENDGRID_API_KEY")
|
||||
Headers := make(map[string]string)
|
||||
Headers["Authorization"] = "Bearer " + key
|
||||
```
|
||||
|
||||
## Table of Contents
|
||||
|
||||
- [GET](#get)
|
||||
- [DELETE](#delete)
|
||||
- [POST](#post)
|
||||
- [PUT](#put)
|
||||
- [PATCH](#patch)
|
||||
|
||||
<a name="get"></a>
|
||||
## GET
|
||||
|
||||
#### GET Single
|
||||
|
||||
```go
|
||||
method = rest.Get
|
||||
|
||||
// Make the API call
|
||||
request = rest.Request{
|
||||
Method: method,
|
||||
BaseURL: baseURL + "/" + apiKey,
|
||||
Headers: Headers,
|
||||
}
|
||||
response, err = rest.API(request)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
} else {
|
||||
fmt.Println(response.StatusCode)
|
||||
fmt.Println(response.Body)
|
||||
fmt.Println(response.Headers)
|
||||
}
|
||||
```
|
||||
|
||||
#### GET Collection
|
||||
|
||||
```go
|
||||
method := rest.Get
|
||||
|
||||
// Build the query parameters
|
||||
queryParams := make(map[string]string)
|
||||
queryParams["limit"] = "100"
|
||||
queryParams["offset"] = "0"
|
||||
|
||||
// Make the API call
|
||||
request := rest.Request{
|
||||
Method: method,
|
||||
BaseURL: baseURL,
|
||||
Headers: Headers,
|
||||
QueryParams: queryParams,
|
||||
}
|
||||
response, err := rest.API(request)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
} else {
|
||||
fmt.Println(response.StatusCode)
|
||||
fmt.Println(response.Body)
|
||||
fmt.Println(response.Headers)
|
||||
}
|
||||
```
|
||||
<a name="delete"></a>
|
||||
## DELETE
|
||||
|
||||
```go
|
||||
method = rest.Delete
|
||||
|
||||
// Make the API call
|
||||
request = rest.Request{
|
||||
Method: method,
|
||||
BaseURL: baseURL + "/" + apiKey,
|
||||
Headers: Headers,
|
||||
QueryParams: queryParams,
|
||||
}
|
||||
response, err = rest.API(request)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
} else {
|
||||
fmt.Println(response.StatusCode)
|
||||
fmt.Println(response.Headers)
|
||||
}
|
||||
```
|
||||
|
||||
<a name="post"></a>
|
||||
## POST
|
||||
|
||||
```go
|
||||
method = rest.Post
|
||||
|
||||
// Build the request body
|
||||
var Body = []byte(`{
|
||||
"name": "My API Key",
|
||||
"scopes": [
|
||||
"mail.send",
|
||||
"alerts.create",
|
||||
"alerts.read"
|
||||
]
|
||||
}`)
|
||||
|
||||
// Make the API call
|
||||
request = rest.Request{
|
||||
Method: method,
|
||||
BaseURL: baseURL,
|
||||
Headers: Headers,
|
||||
QueryParams: queryParams,
|
||||
Body: Body,
|
||||
}
|
||||
response, err = rest.API(request)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
} else {
|
||||
fmt.Println(response.StatusCode)
|
||||
fmt.Println(response.Body)
|
||||
fmt.Println(response.Headers)
|
||||
}
|
||||
|
||||
// Get a particular return value.
|
||||
// Note that you can unmarshall into a struct if
|
||||
// you know the JSON structure in advance.
|
||||
b := []byte(response.Body)
|
||||
var f interface{}
|
||||
err = json.Unmarshal(b, &f)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
m := f.(map[string]interface{})
|
||||
apiKey := m["api_key_id"].(string)
|
||||
```
|
||||
<a name="put"></a>
|
||||
## PUT
|
||||
|
||||
```go
|
||||
method = rest.Put
|
||||
|
||||
// Build the request body
|
||||
Body = []byte(`{
|
||||
"name": "A New Hope",
|
||||
"scopes": [
|
||||
"user.profile.read",
|
||||
"user.profile.update"
|
||||
]
|
||||
}`)
|
||||
|
||||
// Make the API call
|
||||
request = rest.Request{
|
||||
Method: method,
|
||||
BaseURL: baseURL + "/" + apiKey,
|
||||
Headers: Headers,
|
||||
Body: Body,
|
||||
}
|
||||
response, err = rest.API(request)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
} else {
|
||||
fmt.Println(response.StatusCode)
|
||||
fmt.Println(response.Body)
|
||||
fmt.Println(response.Headers)
|
||||
}
|
||||
```
|
||||
<a name="patch"></a>
|
||||
## PATCH
|
||||
|
||||
```go
|
||||
method = rest.Patch
|
||||
|
||||
// Build the request body
|
||||
Body = []byte(`{
|
||||
"name": "A New Hope"
|
||||
}`)
|
||||
|
||||
// Make the API call
|
||||
request = rest.Request{
|
||||
Method: method,
|
||||
BaseURL: baseURL + "/" + apiKey,
|
||||
Headers: Headers,
|
||||
Body: Body,
|
||||
}
|
||||
response, err = rest.API(request)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
} else {
|
||||
fmt.Println(response.StatusCode)
|
||||
fmt.Println(response.Body)
|
||||
fmt.Println(response.Headers)
|
||||
}
|
||||
```
|
||||
145
vendor/github.com/sendgrid/rest/rest.go
generated
vendored
Normal file
145
vendor/github.com/sendgrid/rest/rest.go
generated
vendored
Normal file
@@ -0,0 +1,145 @@
|
||||
// Package rest allows for quick and easy access any REST or REST-like API.
|
||||
package rest
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
// Method contains the supported HTTP verbs.
|
||||
type Method string
|
||||
|
||||
// Supported HTTP verbs.
|
||||
const (
|
||||
Get Method = "GET"
|
||||
Post Method = "POST"
|
||||
Put Method = "PUT"
|
||||
Patch Method = "PATCH"
|
||||
Delete Method = "DELETE"
|
||||
)
|
||||
|
||||
// Request holds the request to an API Call.
|
||||
type Request struct {
|
||||
Method Method
|
||||
BaseURL string // e.g. https://api.sendgrid.com
|
||||
Headers map[string]string
|
||||
QueryParams map[string]string
|
||||
Body []byte
|
||||
}
|
||||
|
||||
// RestError is a struct for an error handling.
|
||||
type RestError struct {
|
||||
Response *Response
|
||||
}
|
||||
|
||||
// Error is the implementation of the error interface.
|
||||
func (e *RestError) Error() string {
|
||||
return e.Response.Body
|
||||
}
|
||||
|
||||
// DefaultClient is used if no custom HTTP client is defined
|
||||
var DefaultClient = &Client{HTTPClient: http.DefaultClient}
|
||||
|
||||
// Client allows modification of client headers, redirect policy
|
||||
// and other settings
|
||||
// See https://golang.org/pkg/net/http
|
||||
type Client struct {
|
||||
HTTPClient *http.Client
|
||||
}
|
||||
|
||||
// Response holds the response from an API call.
|
||||
type Response struct {
|
||||
StatusCode int // e.g. 200
|
||||
Body string // e.g. {"result: success"}
|
||||
Headers map[string][]string // e.g. map[X-Ratelimit-Limit:[600]]
|
||||
}
|
||||
|
||||
// AddQueryParameters adds query parameters to the URL.
|
||||
func AddQueryParameters(baseURL string, queryParams map[string]string) string {
|
||||
baseURL += "?"
|
||||
params := url.Values{}
|
||||
for key, value := range queryParams {
|
||||
params.Add(key, value)
|
||||
}
|
||||
return baseURL + params.Encode()
|
||||
}
|
||||
|
||||
// BuildRequestObject creates the HTTP request object.
|
||||
func BuildRequestObject(request Request) (*http.Request, error) {
|
||||
// Add any query parameters to the URL.
|
||||
if len(request.QueryParams) != 0 {
|
||||
request.BaseURL = AddQueryParameters(request.BaseURL, request.QueryParams)
|
||||
}
|
||||
req, err := http.NewRequest(string(request.Method), request.BaseURL, bytes.NewBuffer(request.Body))
|
||||
if err != nil {
|
||||
return req, err
|
||||
}
|
||||
for key, value := range request.Headers {
|
||||
req.Header.Set(key, value)
|
||||
}
|
||||
_, exists := req.Header["Content-Type"]
|
||||
if len(request.Body) > 0 && !exists {
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
}
|
||||
return req, err
|
||||
}
|
||||
|
||||
// MakeRequest makes the API call.
|
||||
func MakeRequest(req *http.Request) (*http.Response, error) {
|
||||
return DefaultClient.HTTPClient.Do(req)
|
||||
}
|
||||
|
||||
// BuildResponse builds the response struct.
|
||||
func BuildResponse(res *http.Response) (*Response, error) {
|
||||
body, err := ioutil.ReadAll(res.Body)
|
||||
response := Response{
|
||||
StatusCode: res.StatusCode,
|
||||
Body: string(body),
|
||||
Headers: res.Header,
|
||||
}
|
||||
res.Body.Close() // nolint
|
||||
return &response, err
|
||||
}
|
||||
|
||||
// API supports old implementation (deprecated)
|
||||
func API(request Request) (*Response, error) {
|
||||
return Send(request)
|
||||
}
|
||||
|
||||
// Send uses the DefaultClient to send your request
|
||||
func Send(request Request) (*Response, error) {
|
||||
return DefaultClient.Send(request)
|
||||
}
|
||||
|
||||
// The following functions enable the ability to define a
|
||||
// custom HTTP Client
|
||||
|
||||
// MakeRequest makes the API call.
|
||||
func (c *Client) MakeRequest(req *http.Request) (*http.Response, error) {
|
||||
return c.HTTPClient.Do(req)
|
||||
}
|
||||
|
||||
// API supports old implementation (deprecated)
|
||||
func (c *Client) API(request Request) (*Response, error) {
|
||||
return c.Send(request)
|
||||
}
|
||||
|
||||
// Send will build your request, make the request, and build your response.
|
||||
func (c *Client) Send(request Request) (*Response, error) {
|
||||
// Build the HTTP request object.
|
||||
req, err := BuildRequestObject(request)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Build the HTTP client and make the request.
|
||||
res, err := c.MakeRequest(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Build Response object.
|
||||
return BuildResponse(res)
|
||||
}
|
||||
97
vendor/github.com/sendgrid/sendgrid-go/CHANGELOG.md
generated
vendored
Normal file
97
vendor/github.com/sendgrid/sendgrid-go/CHANGELOG.md
generated
vendored
Normal file
@@ -0,0 +1,97 @@
|
||||
# Change Log
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
## [3.4.1] - 2017-07-03
|
||||
### Added
|
||||
- [Pull #116](https://github.com/sendgrid/sendgrid-go/pull/116): Fixing mimetypes in the NewSingleEmail function
|
||||
- Big thanks to [Depado](https://github.com/Depado) for the pull request!
|
||||
|
||||
## [3.4.0] - 2017-06-14
|
||||
### Added
|
||||
- [Pull #96](https://github.com/sendgrid/sendgrid-go/pull/96): Send a Single Email to a Single Recipient
|
||||
- Big thanks to [Oranagwa Osmond](https://github.com/andela-ooranagwa) for the pull request!
|
||||
|
||||
## [3.3.1] - 2016-10-18
|
||||
### Fixed
|
||||
- [Pull #95](https://github.com/sendgrid/sendgrid-go/pull/95): Use log instead of fmt for printing errors
|
||||
- Big thanks to [Gábor Lipták](https://github.com/gliptak) for the pull request!
|
||||
|
||||
## [3.3.0] - 2016-10-10
|
||||
### Added
|
||||
- [Pull #92](https://github.com/sendgrid/sendgrid-go/pull/92): Inbound Parse Webhook support
|
||||
- Checkout the [README](https://github.com/sendgrid/sendgrid-go/tree/master/helpers/inbound) for details.
|
||||
|
||||
## [3.2.3] - 2016-10-10
|
||||
### Added
|
||||
- [Pull #91](https://github.com/sendgrid/sendgrid-go/pull/91): Simplified code in mail helper
|
||||
- Big thanks to [Roberto Ortega](https://github.com/berto) for the pull request!
|
||||
|
||||
## [3.2.2] - 2016-09-08
|
||||
### Added
|
||||
- Merged pull request: [update prismPath and update prism binary](https://github.com/sendgrid/sendgrid-go/pull/80)
|
||||
- Special thanks to [Tom Pytleski](https://github.com/pytlesk4) for the pull request!
|
||||
|
||||
## [3.2.1] - 2016-08-24
|
||||
### Added
|
||||
- Table of Contents in the README
|
||||
- Added a [USE_CASES.md](https://github.com/sendgrid/sendgrid-go/blob/master/USE_CASES.md) section, with the first use case example for transactional templates
|
||||
|
||||
## [3.2.0] - 2016-08-17
|
||||
### Added
|
||||
- Merged pull request: [make contents var args in NewV3MailInit](https://github.com/sendgrid/sendgrid-go/pull/75)
|
||||
- The `NewV3MailInit` [Mail Helper](https://github.com/sendgrid/sendgrid-go/tree/master/helpers/mail) constructor can now take in multiple content objects.
|
||||
- Thanks to [Adrien Delorme](https://github.com/azr) for the pull request!
|
||||
|
||||
## [3.1.0] - 2016-07-28
|
||||
- Dependency update to v2.2.0 of [sendGrid-rest](https://github.com/sendgrid/rest/releases/tag/v2.2.0)
|
||||
- Pull [#9](https://github.com/sendgrid/rest/pull/9): Allow for setting a custom HTTP client
|
||||
- [Here](https://github.com/sendgrid/rest/blob/master/rest_test.go#L127) is an example of usage
|
||||
- This enables usage of the [sendgrid-go library](https://github.com/sendgrid/sendgrid-go) on [Google App Engine (GAE)](https://cloud.google.com/appengine/)
|
||||
- Special thanks to [Chris Broadfoot](https://github.com/broady) and [Sridhar Venkatakrishnan](https://github.com/sridharv) for providing code and feedback!
|
||||
|
||||
## [3.0.6] - 2016-07-26 ##
|
||||
### Added
|
||||
- [Troubleshooting](https://github.com/sendgrid/sendgrid-go/blob/master/TROUBLESHOOTING.md) section
|
||||
|
||||
## [3.0.5] - 2016-07-20
|
||||
### Added
|
||||
- README updates
|
||||
- Update introduction blurb to include information regarding our forward path
|
||||
- Update the v3 /mail/send example to include non-helper usage
|
||||
- Update the generic v3 example to include non-fluent interface usage
|
||||
|
||||
## [3.0.4] - 2016-07-12
|
||||
### Added
|
||||
- Update docs, unit tests and examples to include Sender ID
|
||||
### Fixed
|
||||
- Missing example query params for the examples
|
||||
|
||||
## [3.0.3] - 2016-07-08
|
||||
### Fixed
|
||||
- [Can't disable subscription tracking #68](https://github.com/sendgrid/sendgrid-go/issues/68)
|
||||
|
||||
## [3.0.2] - 2016-07-07
|
||||
### Added
|
||||
- Tests now mocked automatically against [prism](https://stoplight.io/prism/)
|
||||
|
||||
## [3.0.1] - 2016-07-05
|
||||
### Added
|
||||
- Accept: application/json header per https://sendgrid.com/docs/API_Reference/Web_API_v3/How_To_Use_The_Web_API_v3/requests.html
|
||||
|
||||
### Updated
|
||||
- Content based on our updated [Swagger/OAI doc](https://github.com/sendgrid/sendgrid-oai)
|
||||
|
||||
## [3.0.0] - 2016-06-14
|
||||
### Added
|
||||
- Breaking change to support the v3 Web API
|
||||
- New HTTP client
|
||||
- v3 Mail Send helper
|
||||
|
||||
## [2.0.0] - 2015-05-02
|
||||
### Changed
|
||||
- Fixed a nasty bug with orphaned connections but drops support for Go versions < 1.3. Thanks [trinchan](https://github.com/sendgrid/sendgrid-go/pull/24)
|
||||
|
||||
## [1.2.0] - 2015-04-27
|
||||
### Added
|
||||
- Support for API keys
|
||||
|
||||
41
vendor/github.com/sendgrid/sendgrid-go/CODE_OF_CONDUCT.md
generated
vendored
Normal file
41
vendor/github.com/sendgrid/sendgrid-go/CODE_OF_CONDUCT.md
generated
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
# SendGrid Community Code of Conduct
|
||||
|
||||
The SendGrid open source community is made up of members from around the globe with a diverse set of skills, personalities, and experiences. It is through these differences that our community experiences successes and continued growth. When you're working with members of the community, we encourage you to follow these guidelines, which help steer our interactions and strive to maintain a positive, successful and growing community.
|
||||
|
||||
### Be Open
|
||||
Members of the community are open to collaboration, whether it's on pull requests, code reviews, approvals, issues or otherwise. We're receptive to constructive comments and criticism, as the experiences and skill sets of all members contribute to the whole of our efforts. We're accepting of all who wish to take part in our activities, fostering an environment where anyone can participate, and everyone can make a difference.
|
||||
|
||||
### Be Considerate
|
||||
Members of the community are considerate of their peers, which include other contributors and users of SendGrid. We're thoughtful when addressing the efforts of others, keeping in mind that often the labor was completed with the intent of the good of the community. We're attentive in our communications, whether in person or online, and we're tactful when approaching differing views.
|
||||
|
||||
### Be Respectful
|
||||
Members of the community are respectful. We're respectful of others, their positions, their skills, their commitments and their efforts. We're respectful of the volunteer efforts that permeate the SendGrid community. We're respectful of the processes outlined in the community, and we work within them. When we disagree, we are courteous in raising our issues. Overall, we're good to each other. We contribute to this community not because we have to, but because we want to. If we remember that, these guidelines will come naturally.
|
||||
|
||||
## Additional Guidance
|
||||
|
||||
### Disclose Potential Conflicts of Interest
|
||||
Community discussions often involve interested parties. We expect participants to be aware when they are conflicted due to employment or other projects they are involved in and disclose those interests to other project members. When in doubt, over-disclose. Perceived conflicts of interest are important to address so that the community’s decisions are credible even when unpopular, difficult or favorable to the interests of one group over another.
|
||||
|
||||
### Interpretation
|
||||
This Code is not exhaustive or complete. It is not a rulebook; it serves to distill our common understanding of a collaborative, shared environment and goals. We expect it to be followed in spirit as much as in the letter. When in doubt, try to abide by [SendGrid’s cultural values](https://sendgrid.com/blog/employee-engagement-the-4h-way) defined by our “4H’s”: Happy, Hungry, Humble and Honest.
|
||||
|
||||
### Enforcement
|
||||
Most members of the SendGrid community always comply with this Code, not because of the existence of this Code, but because they have long experience participating in open source communities where the conduct described above is normal and expected. However, failure to observe this Code may be grounds for suspension, reporting the user for abuse or changing permissions for outside contributors.
|
||||
|
||||
## If you have concerns about someone’s conduct
|
||||
**Initiate Direct Contact** - It is always appropriate to email a community member (if contact information is available), mention that you think their behavior was out of line, and (if necessary) point them to this Code.
|
||||
|
||||
**Discuss Publicly** - Discussing publicly is always acceptable. Note, though, that approaching the person directly may be better, as it tends to make them less defensive, and it respects the time of other community members, so you probably want to try direct contact first.
|
||||
|
||||
**Contact the Moderators** - You can reach the SendGrid moderators by emailing dx@sendgrid.com.
|
||||
|
||||
## Submission to SendGrid Repositories
|
||||
Finally, just a reminder, changes to the SendGrid repositories will only be accepted upon completion of the [SendGrid Contributor Agreement](https://cla.sendgrid.com).
|
||||
|
||||
## Attribution
|
||||
|
||||
SendGrid thanks the following, on which it draws for content and inspiration:
|
||||
|
||||
* [Python Community Code of Conduct](https://www.python.org/psf/codeofconduct/)
|
||||
* [Open Source Initiative General Code of Conduct](https://opensource.org/codeofconduct)
|
||||
* [Apache Code of Conduct](https://www.apache.org/foundation/policies/conduct.html)
|
||||
192
vendor/github.com/sendgrid/sendgrid-go/CONTRIBUTING.md
generated
vendored
Normal file
192
vendor/github.com/sendgrid/sendgrid-go/CONTRIBUTING.md
generated
vendored
Normal file
@@ -0,0 +1,192 @@
|
||||
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-go/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) be filled out by every contributor to a SendGrid open source project.
|
||||
|
||||
Our goal with the CLA is to clarify the rights of our contributors and reduce other risks arising from inappropriate contributions. The CLA also clarifies the rights SendGrid holds in each contribution and helps to avoid misunderstandings over what rights each contributor is required to grant to SendGrid when making a contribution. In this way the CLA encourages broad participation by our open source community and helps us build strong open source projects, free from any individual contributor withholding or revoking rights to any contribution.
|
||||
|
||||
SendGrid does not merge a pull request made against a SendGrid open source project until that pull request is associated with a signed CLA. Copies of the CLA are available [here](https://gist.github.com/SendGridDX/98b42c0a5d500058357b80278fde3be8#file-sendgrid_cla).
|
||||
|
||||
When you create a Pull Request, after a few seconds, a comment will appear with a link to the CLA. Click the link and fill out the brief form and then click the "I agree" button and you are all set. You will not be asked to re-sign the CLA unless we make a change.
|
||||
|
||||
There are a few ways to contribute, which we'll enumerate below:
|
||||
|
||||
<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-go/.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-go code base. Thank you!
|
||||
|
||||
### Development Environment ###
|
||||
|
||||
#### Install and Run Locally ####
|
||||
|
||||
##### Prerequisites #####
|
||||
|
||||
- Go 1.6
|
||||
- [rest](https://github.com/sendgrid/rest)
|
||||
|
||||
##### Initial setup: #####
|
||||
|
||||
```bash
|
||||
git clone https://github.com/sendgrid/sendgrid-go.git
|
||||
cd sendgrid-go
|
||||
```
|
||||
|
||||
## Environment Variables
|
||||
|
||||
First, get your free SendGrid account [here](https://sendgrid.com/free?source=sendgrid-go).
|
||||
|
||||
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: #####
|
||||
|
||||
* Check out the documentation for [Web API v3 endpoints](https://sendgrid.com/docs/API_Reference/Web_API_v3/index.html).
|
||||
* Review the corresponding [example](https://github.com/sendgrid/sendgrid-go/blob/master/examples).
|
||||
* Update the file
|
||||
|
||||
```bash
|
||||
go run <Desired File>
|
||||
```
|
||||
|
||||
<a name="understanding-the-codebase"></a>
|
||||
## Understanding the Code Base
|
||||
|
||||
**/examples**
|
||||
|
||||
Working examples that demonstrate usage.
|
||||
|
||||
**sendgrid.go**
|
||||
|
||||
The main function that does the heavy lifting (and external entry point) is `API`.
|
||||
|
||||
<a name="testing"></a>
|
||||
## Testing
|
||||
|
||||
All PRs require passing tests before the PR will be reviewed.
|
||||
|
||||
All test files are in [`sendgrid_test.go`](https://github.com/sendgrid/sendgrid-go/tree/master/sendgrid_test.go).
|
||||
|
||||
For the purposes of contributing to this repo, please update the [`sendgrid_test.go`](https://github.com/sendgrid/sendgrid-go/tree/master/sendgrid_test.go) file with unit tests as you modify the code.
|
||||
|
||||
To run the tests:
|
||||
|
||||
```bash
|
||||
go test -v ./...
|
||||
```
|
||||
|
||||
<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.
|
||||
|
||||
- [Go Code Review Comments](https://github.com/golang/go/wiki/CodeReviewComments)
|
||||
|
||||
Please run your code through:
|
||||
|
||||
- [fmt](https://blog.golang.org/go-fmt-your-code)
|
||||
|
||||
<a name="creating-a-pull-request"></a>
|
||||
## Creating a Pull Request
|
||||
|
||||
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-go
|
||||
|
||||
# Navigate to the newly cloned directory
|
||||
cd sendgrid-go
|
||||
|
||||
# Assign the original repo to a remote called "upstream"
|
||||
git remote add upstream https://github.com/sendgrid/sendgrid-go
|
||||
```
|
||||
|
||||
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.
|
||||
21
vendor/github.com/sendgrid/sendgrid-go/LICENSE.txt
generated
vendored
Normal file
21
vendor/github.com/sendgrid/sendgrid-go/LICENSE.txt
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2013-2018 SendGrid, Inc.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
259
vendor/github.com/sendgrid/sendgrid-go/README.md
generated
vendored
Normal file
259
vendor/github.com/sendgrid/sendgrid-go/README.md
generated
vendored
Normal file
@@ -0,0 +1,259 @@
|
||||

|
||||
|
||||
[](https://travis-ci.org/sendgrid/sendgrid-go)
|
||||
[](https://dx.sendgrid.com/newsletter/go)
|
||||
[](https://goreportcard.com/report/github.com/sendgrid/sendgrid-go)
|
||||
[](https://godoc.org/github.com/sendgrid/sendgrid-go)
|
||||
[](./LICENSE.txt)
|
||||
[](https://twitter.com/sendgrid)
|
||||
[](https://github.com/sendgrid/sendgrid-go/graphs/contributors)
|
||||
[](https://www.codetriage.com/sendgrid/sendgrid-go)
|
||||
|
||||
**NEW:** Subscribe to email [notifications](https://dx.sendgrid.com/newsletter/go) for releases and breaking changes.
|
||||
|
||||
**This library allows you to quickly and easily use the SendGrid Web API v3 via Go.**
|
||||
|
||||
Version 3.X.X of this library provides full support for all SendGrid [Web API v3](https://sendgrid.com/docs/API_Reference/Web_API_v3/index.html) endpoints, including the new [v3 /mail/send](https://sendgrid.com/blog/introducing-v3mailsend-sendgrids-new-mail-endpoint).
|
||||
|
||||
This library represents the beginning of a new path for SendGrid. We want this library to be community driven and SendGrid led. We need your help to realize this goal. To help make sure we are building the right things in the right order, we ask that you create [issues](https://github.com/sendgrid/sendgrid-go/issues) and [pull requests](https://github.com/sendgrid/sendgrid-go/blob/master/CONTRIBUTING.md) or simply upvote or comment on existing issues or pull requests.
|
||||
|
||||
Please browse the rest of this README for further detail.
|
||||
|
||||
We appreciate your continued support, thank you!
|
||||
|
||||
# Table of Contents
|
||||
|
||||
* [Installation](#installation)
|
||||
* [Quick Start](#quick-start)
|
||||
* [Processing Inbound Email](#inbound)
|
||||
* [Usage](#usage)
|
||||
* [Use Cases](#use-cases)
|
||||
* [Announcements](#announcements)
|
||||
* [Roadmap](#roadmap)
|
||||
* [How to Contribute](#contribute)
|
||||
* [Troubleshooting](#troubleshooting)
|
||||
* [About](#about)
|
||||
* [License](#license)
|
||||
|
||||
<a name="installation"></a>
|
||||
# Installation
|
||||
|
||||
## Prerequisites
|
||||
|
||||
- Go version 1.6
|
||||
- The SendGrid service, starting at the [free level](https://sendgrid.com/free?source=sendgrid-go)
|
||||
|
||||
## Setup Environment Variables
|
||||
|
||||
Update the development environment with your [SENDGRID_API_KEY](https://app.sendgrid.com/settings/api_keys), for example:
|
||||
|
||||
```bash
|
||||
echo "export SENDGRID_API_KEY='YOUR_API_KEY'" > sendgrid.env
|
||||
echo "sendgrid.env" >> .gitignore
|
||||
source ./sendgrid.env
|
||||
```
|
||||
|
||||
## Install Package
|
||||
|
||||
`go get github.com/sendgrid/sendgrid-go`
|
||||
|
||||
## Dependencies
|
||||
|
||||
- [rest](https://github.com/sendgrid/rest)
|
||||
|
||||
## Setup Environment Variables
|
||||
|
||||
### Initial Setup
|
||||
|
||||
```bash
|
||||
cp .env_sample .env
|
||||
```
|
||||
|
||||
### Environment Variable
|
||||
|
||||
Update the development environment with your [SENDGRID_API_KEY](https://app.sendgrid.com/settings/api_keys), for example:
|
||||
|
||||
```bash
|
||||
echo "export SENDGRID_API_KEY='YOUR_API_KEY'" > sendgrid.env
|
||||
echo "sendgrid.env" >> .gitignore
|
||||
source ./sendgrid.env
|
||||
```
|
||||
|
||||
<a name="quick-start"></a>
|
||||
# Quick Start
|
||||
|
||||
## Hello Email
|
||||
|
||||
The following is the minimum needed code to send an email with the [/mail/send Helper](https://github.com/sendgrid/sendgrid-go/tree/master/helpers/mail) ([here](https://github.com/sendgrid/sendgrid-go/blob/master/examples/helpers/mail/example.go#L32) is a full example):
|
||||
|
||||
### With Mail Helper Class
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/sendgrid/sendgrid-go"
|
||||
"github.com/sendgrid/sendgrid-go/helpers/mail"
|
||||
)
|
||||
|
||||
func main() {
|
||||
from := mail.NewEmail("Example User", "test@example.com")
|
||||
subject := "Sending with SendGrid is Fun"
|
||||
to := mail.NewEmail("Example User", "test@example.com")
|
||||
plainTextContent := "and easy to do anywhere, even with Go"
|
||||
htmlContent := "<strong>and easy to do anywhere, even with Go</strong>"
|
||||
message := mail.NewSingleEmail(from, subject, to, plainTextContent, htmlContent)
|
||||
client := sendgrid.NewSendClient(os.Getenv("SENDGRID_API_KEY"))
|
||||
response, err := client.Send(message)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
} else {
|
||||
fmt.Println(response.StatusCode)
|
||||
fmt.Println(response.Body)
|
||||
fmt.Println(response.Headers)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
The `NewEmail` constructor creates a [personalization object](https://sendgrid.com/docs/Classroom/Send/v3_Mail_Send/personalizations.html) for you. [Here](https://github.com/sendgrid/sendgrid-go/blob/master/examples/helpers/mail/example.go#L28) is an example of how to add to it.
|
||||
|
||||
### Without Mail Helper Class
|
||||
|
||||
The following is the minimum needed code to send an email without the /mail/send Helper ([here](https://github.com/sendgrid/sendgrid-go/blob/master/examples/mail/mail.go#L47) is a full example):
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/sendgrid/sendgrid-go"
|
||||
"log"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
request := sendgrid.GetRequest(os.Getenv("SENDGRID_API_KEY"), "/v3/mail/send", "https://api.sendgrid.com")
|
||||
request.Method = "POST"
|
||||
request.Body = []byte(` {
|
||||
"personalizations": [
|
||||
{
|
||||
"to": [
|
||||
{
|
||||
"email": "test@example.com"
|
||||
}
|
||||
],
|
||||
"subject": "Sending with SendGrid is Fun"
|
||||
}
|
||||
],
|
||||
"from": {
|
||||
"email": "test@example.com"
|
||||
},
|
||||
"content": [
|
||||
{
|
||||
"type": "text/plain",
|
||||
"value": "and easy to do anywhere, even with Go"
|
||||
}
|
||||
]
|
||||
}`)
|
||||
response, err := sendgrid.API(request)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
} else {
|
||||
fmt.Println(response.StatusCode)
|
||||
fmt.Println(response.Body)
|
||||
fmt.Println(response.Headers)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## General v3 Web API Usage
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/sendgrid/sendgrid-go"
|
||||
"log"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
request := sendgrid.GetRequest(os.Getenv("SENDGRID_API_KEY"), "/v3/api_keys", "https://api.sendgrid.com")
|
||||
request.Method = "GET"
|
||||
|
||||
response, err := sendgrid.API(request)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
} else {
|
||||
fmt.Println(response.StatusCode)
|
||||
fmt.Println(response.Body)
|
||||
fmt.Println(response.Headers)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
<a name="inbound"></a>
|
||||
# Processing Inbound Email
|
||||
|
||||
Please see [our helper](https://github.com/sendgrid/sendgrid-go/tree/master/helpers/inbound) for utilizing our Inbound Parse webhook.
|
||||
|
||||
<a name="usage"></a>
|
||||
# Usage
|
||||
|
||||
- [SendGrid Docs](https://sendgrid.com/docs/API_Reference/index.html)
|
||||
- [Library Usage Docs](https://github.com/sendgrid/sendgrid-go/tree/master/USAGE.md)
|
||||
- [Example Code](https://github.com/sendgrid/sendgrid-go/tree/master/examples)
|
||||
- [How-to: Migration from v2 to v3](https://sendgrid.com/docs/Classroom/Send/v3_Mail_Send/how_to_migrate_from_v2_to_v3_mail_send.html)
|
||||
- [v3 Web API Mail Send Helper](https://github.com/sendgrid/sendgrid-go/tree/master/helpers/mail/README.md)
|
||||
|
||||
<a name="use-cases"></a>
|
||||
# Use Cases
|
||||
|
||||
[Examples of common API use cases](https://github.com/sendgrid/sendgrid-go/blob/master/USE_CASES.md), such as how to send an email with a transactional template.
|
||||
|
||||
<a name="announcements"></a>
|
||||
# Announcements
|
||||
|
||||
Join an experienced and passionate team that focuses on making an impact. Opportunities abound to grow the product - and grow your career! Check out our [Software Engineer- Delivery role](http://grnh.se/mg6dr31)
|
||||
|
||||
Please see our announcement regarding [breaking changes](https://github.com/sendgrid/sendgrid-go/issues/81). Your support is appreciated!
|
||||
|
||||
All updates to this library are documented in our [CHANGELOG](https://github.com/sendgrid/sendgrid-go/blob/master/CHANGELOG.md) and [releases](https://github.com/sendgrid/sendgrid-go/releases). You may also subscribe to email [release notifications](https://dx.sendgrid.com/newsletter/go) for releases and breaking changes.
|
||||
|
||||
<a name="roadmap"></a>
|
||||
# Roadmap
|
||||
|
||||
If you are interested in the future direction of this project, please take a look at our open [issues](https://github.com/sendgrid/sendgrid-go/issues) and [pull requests](https://github.com/sendgrid/sendgrid-go/pulls). We would love to hear your feedback.
|
||||
|
||||
<a name="contribute"></a>
|
||||
# How to Contribute
|
||||
|
||||
We encourage contribution to our libraries (you might even score some nifty swag), please see our [CONTRIBUTING](https://github.com/sendgrid/sendgrid-go/blob/master/CONTRIBUTING.md) guide for details.
|
||||
|
||||
Quick links:
|
||||
|
||||
- [Feature Request](https://github.com/sendgrid/sendgrid-go/tree/master/CONTRIBUTING.md#feature-request)
|
||||
- [Bug Reports](https://github.com/sendgrid/sendgrid-go/tree/master/CONTRIBUTING.md#submit-a-bug-report)
|
||||
- [Sign the CLA to Create a Pull Request](https://github.com/sendgrid/sendgrid-go/tree/master/CONTRIBUTING.md#cla)
|
||||
- [Improvements to the Codebase](https://github.com/sendgrid/sendgrid-go/tree/master/CONTRIBUTING.md#improvements-to-the-codebase)
|
||||
|
||||
<a name="troubleshooting"></a>
|
||||
# Troubleshooting
|
||||
|
||||
Please see our [troubleshooting guide](https://github.com/sendgrid/sendgrid-go/blob/master/TROUBLESHOOTING.md) for common library issues.
|
||||
|
||||
<a name="about"></a>
|
||||
# About
|
||||
|
||||
sendgrid-go is guided and supported by the SendGrid [Developer Experience Team](mailto:dx@sendgrid.com).
|
||||
|
||||
sendgrid-go is maintained and funded by SendGrid, Inc. The names and logos for sendgrid-go are trademarks of SendGrid, Inc.
|
||||
|
||||
# License
|
||||
[The MIT License (MIT)](LICENSE.txt)
|
||||
108
vendor/github.com/sendgrid/sendgrid-go/TROUBLESHOOTING.md
generated
vendored
Normal file
108
vendor/github.com/sendgrid/sendgrid-go/TROUBLESHOOTING.md
generated
vendored
Normal file
@@ -0,0 +1,108 @@
|
||||
If you have a non-library SendGrid issue, please contact our [support team](https://support.sendgrid.com).
|
||||
|
||||
If you can't find a solution below, please open an [issue](https://github.com/sendgrid/sendgrid-go/issues).
|
||||
|
||||
|
||||
## Table of Contents
|
||||
|
||||
* [Migrating from v2 to v3](#migrating)
|
||||
* [Continue Using v2](#v2)
|
||||
* [Testing v3 /mail/send Calls Directly](#testing)
|
||||
* [Error Messages](#error)
|
||||
* [Versions](#versions)
|
||||
* [Environment Variables and Your SendGrid API Key](#environment)
|
||||
* [Viewing the Request Body](#request-body)
|
||||
|
||||
<a name="migrating"></a>
|
||||
## Migrating from v2 to v3
|
||||
|
||||
Please review [our guide](https://sendgrid.com/docs/Classroom/Send/v3_Mail_Send/how_to_migrate_from_v2_to_v3_mail_send.html) on how to migrate from v2 to v3.
|
||||
|
||||
<a name="v2"></a>
|
||||
## Continue Using v2
|
||||
|
||||
[Here](https://github.com/sendgrid/sendgrid-go/tree/0bf6332788d0230b7da84a1ae68d7531073200e1) is the last working version with v2 support.
|
||||
|
||||
Download:
|
||||
|
||||
Click the "Clone or download" green button in [GitHub](https://github.com/sendgrid/sendgrid-go/tree/0bf6332788d0230b7da84a1ae68d7531073200e1) and choose download.
|
||||
|
||||
<a name="testing"></a>
|
||||
## Testing v3 /mail/send Calls Directly
|
||||
|
||||
[Here](https://sendgrid.com/docs/Classroom/Send/v3_Mail_Send/curl_examples.html) are some cURL examples for common use cases.
|
||||
|
||||
<a name="error"></a>
|
||||
## Error Messages
|
||||
|
||||
An error is returned if caused by client policy (such as CheckRedirect), or failure to speak HTTP (such as a network connectivity problem).
|
||||
|
||||
To read the error message returned by SendGrid's API:
|
||||
|
||||
```go
|
||||
func main() {
|
||||
from := mail.NewEmail("Example User", "test@example.com")
|
||||
subject := "Hello World from the SendGrid Go Library"
|
||||
to := mail.NewEmail("Example User", "test@example.com")
|
||||
content := mail.NewContent("text/plain", "some text here")
|
||||
m := mail.NewV3MailInit(from, subject, to, content)
|
||||
|
||||
request := sendgrid.GetRequest(os.Getenv("SENDGRID_API_KE"), "/v3/mail/send", "https://api.sendgrid.com")
|
||||
request.Method = "POST"
|
||||
request.Body = mail.GetRequestBody(m)
|
||||
response, err := sendgrid.API(request)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
} else {
|
||||
fmt.Println(response.StatusCode)
|
||||
fmt.Println(response.Body)
|
||||
fmt.Println(response.Headers)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
__CAUTION__: A non-2xx status code doesn't cause an error on sendgrid.API and the application has to verify the response:
|
||||
|
||||
```golang
|
||||
resp, err := sendgrid.API(request)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if resp.StatusCode >= 400 {
|
||||
// something goes wrong and you have to handle (e.g. returning an error to the user or logging the problem)
|
||||
log.Printf("api response: HTTP %d: %s", resp.StatusCode, resp.Body)
|
||||
// OR
|
||||
// return fmt.Errorf("api response: HTTP %d: %s", resp.StatusCode, resp.Body)
|
||||
}
|
||||
```
|
||||
|
||||
<a name="versions"></a>
|
||||
## Versions
|
||||
|
||||
We follow the MAJOR.MINOR.PATCH versioning scheme as described by [SemVer.org](http://semver.org). Therefore, we recommend that you always pin (or vendor) the particular version you are working with to your code and never auto-update to the latest version. Especially when there is a MAJOR point release, since that is guaranteed to be a breaking change. Changes are documented in the [CHANGELOG](https://github.com/sendgrid/sendgrid-go/blob/master/CHANGELOG.md) and [releases](https://github.com/sendgrid/sendgrid-go/releases) section.
|
||||
|
||||
<a name="environment"></a>
|
||||
## Environment Variables and Your SendGrid API Key
|
||||
|
||||
All of our examples assume you are using [environment variables](https://github.com/sendgrid/sendgrid-go#setup-environment-variables) to hold your SendGrid API key.
|
||||
|
||||
If you choose to add your SendGrid API key directly (not recommended):
|
||||
|
||||
`os.Getenv("SENDGRID_API_KEY")`
|
||||
|
||||
becomes
|
||||
|
||||
`"SENDGRID_API_KEY"`
|
||||
|
||||
In the first case SENDGRID_API_KEY is in reference to the name of the environment variable, while the second case references the actual SendGrid API Key.
|
||||
|
||||
<a name="request-body"></a>
|
||||
## Viewing the Request Body
|
||||
|
||||
When debugging or testing, it may be useful to examine the raw request body to compare against the [documented format](https://sendgrid.com/docs/API_Reference/api_v3.html).
|
||||
|
||||
You can do this right before you call `response, err := client.Send(message)` like so:
|
||||
|
||||
```go
|
||||
fmt.Println(string(mail.GetRequestBody(message)))
|
||||
```
|
||||
6514
vendor/github.com/sendgrid/sendgrid-go/USAGE.md
generated
vendored
Normal file
6514
vendor/github.com/sendgrid/sendgrid-go/USAGE.md
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
1587
vendor/github.com/sendgrid/sendgrid-go/USE_CASES.md
generated
vendored
Normal file
1587
vendor/github.com/sendgrid/sendgrid-go/USE_CASES.md
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
12
vendor/github.com/sendgrid/sendgrid-go/go.test.sh
generated
vendored
Executable file
12
vendor/github.com/sendgrid/sendgrid-go/go.test.sh
generated
vendored
Executable file
@@ -0,0 +1,12 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -e
|
||||
echo "" > coverage.txt
|
||||
|
||||
for d in $(go list ./... | grep -v vendor); do
|
||||
go test -race -coverprofile=profile.out -covermode=atomic $d
|
||||
if [ -f profile.out ]; then
|
||||
cat profile.out >> coverage.txt
|
||||
rm profile.out
|
||||
fi
|
||||
done
|
||||
31
vendor/github.com/sendgrid/sendgrid-go/helpers/mail/README.md
generated
vendored
Normal file
31
vendor/github.com/sendgrid/sendgrid-go/helpers/mail/README.md
generated
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
**This helper allows you to quickly and easily build a Mail object for sending email through SendGrid.**
|
||||
|
||||
## Dependencies
|
||||
|
||||
- [rest](https://github.com/sendgrid/rest)
|
||||
|
||||
# Quick Start
|
||||
|
||||
Run the [example](https://github.com/sendgrid/sendgrid-go/tree/master/examples/helpers/mail/example.go) (make sure you have set your environment variable to include your SENDGRID_API_KEY).
|
||||
|
||||
```bash
|
||||
go run examples/helpers/mail/example.go
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
- See the [example](https://github.com/sendgrid/sendgrid-go/tree/master/examples/helpers/mail/example.go) for a complete working example.
|
||||
- [Documentation](https://sendgrid.com/docs/API_Reference/Web_API_v3/Mail/overview.html)
|
||||
|
||||
## Test
|
||||
|
||||
```bash
|
||||
go test ./... -v
|
||||
```
|
||||
|
||||
or
|
||||
|
||||
```bash
|
||||
cd helpers/mail
|
||||
go test -v
|
||||
```
|
||||
676
vendor/github.com/sendgrid/sendgrid-go/helpers/mail/mail_v3.go
generated
vendored
Normal file
676
vendor/github.com/sendgrid/sendgrid-go/helpers/mail/mail_v3.go
generated
vendored
Normal file
@@ -0,0 +1,676 @@
|
||||
package mail
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"log"
|
||||
)
|
||||
|
||||
// SGMailV3 contains mail struct
|
||||
type SGMailV3 struct {
|
||||
From *Email `json:"from,omitempty"`
|
||||
Subject string `json:"subject,omitempty"`
|
||||
Personalizations []*Personalization `json:"personalizations,omitempty"`
|
||||
Content []*Content `json:"content,omitempty"`
|
||||
Attachments []*Attachment `json:"attachments,omitempty"`
|
||||
TemplateID string `json:"template_id,omitempty"`
|
||||
Sections map[string]string `json:"sections,omitempty"`
|
||||
Headers map[string]string `json:"headers,omitempty"`
|
||||
Categories []string `json:"categories,omitempty"`
|
||||
CustomArgs map[string]string `json:"custom_args,omitempty"`
|
||||
SendAt int `json:"send_at,omitempty"`
|
||||
BatchID string `json:"batch_id,omitempty"`
|
||||
Asm *Asm `json:"asm,omitempty"`
|
||||
IPPoolID string `json:"ip_pool_name,omitempty"`
|
||||
MailSettings *MailSettings `json:"mail_settings,omitempty"`
|
||||
TrackingSettings *TrackingSettings `json:"tracking_settings,omitempty"`
|
||||
ReplyTo *Email `json:"reply_to,omitempty"`
|
||||
}
|
||||
|
||||
// Personalization ...
|
||||
type Personalization struct {
|
||||
To []*Email `json:"to,omitempty"`
|
||||
CC []*Email `json:"cc,omitempty"`
|
||||
BCC []*Email `json:"bcc,omitempty"`
|
||||
Subject string `json:"subject,omitempty"`
|
||||
Headers map[string]string `json:"headers,omitempty"`
|
||||
Substitutions map[string]string `json:"substitutions,omitempty"`
|
||||
CustomArgs map[string]string `json:"custom_args,omitempty"`
|
||||
DynamicTemplateData map[string]interface{} `json:"dynamic_template_data,omitempty"`
|
||||
Categories []string `json:"categories,omitempty"`
|
||||
SendAt int `json:"send_at,omitempty"`
|
||||
}
|
||||
|
||||
// Email holds email name and address info
|
||||
type Email struct {
|
||||
Name string `json:"name,omitempty"`
|
||||
Address string `json:"email,omitempty"`
|
||||
}
|
||||
|
||||
// Content defines content of the mail body
|
||||
type Content struct {
|
||||
Type string `json:"type,omitempty"`
|
||||
Value string `json:"value,omitempty"`
|
||||
}
|
||||
|
||||
// Attachment holds attachement information
|
||||
type Attachment struct {
|
||||
Content string `json:"content,omitempty"`
|
||||
Type string `json:"type,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
Filename string `json:"filename,omitempty"`
|
||||
Disposition string `json:"disposition,omitempty"`
|
||||
ContentID string `json:"content_id,omitempty"`
|
||||
}
|
||||
|
||||
// Asm ...
|
||||
type Asm struct {
|
||||
GroupID int `json:"group_id,omitempty"`
|
||||
GroupsToDisplay []int `json:"groups_to_display,omitempty"`
|
||||
}
|
||||
|
||||
// MailSettings ...
|
||||
type MailSettings struct {
|
||||
BCC *BccSetting `json:"bcc,omitempty"`
|
||||
BypassListManagement *Setting `json:"bypass_list_management,omitempty"`
|
||||
Footer *FooterSetting `json:"footer,omitempty"`
|
||||
SandboxMode *Setting `json:"sandbox_mode,omitempty"`
|
||||
SpamCheckSetting *SpamCheckSetting `json:"spam_check,omitempty"`
|
||||
}
|
||||
|
||||
// TrackingSettings ...
|
||||
type TrackingSettings struct {
|
||||
ClickTracking *ClickTrackingSetting `json:"click_tracking,omitempty"`
|
||||
OpenTracking *OpenTrackingSetting `json:"open_tracking,omitempty"`
|
||||
SubscriptionTracking *SubscriptionTrackingSetting `json:"subscription_tracking,omitempty"`
|
||||
GoogleAnalytics *GaSetting `json:"ganalytics,omitempty"`
|
||||
BCC *BccSetting `json:"bcc,omitempty"`
|
||||
BypassListManagement *Setting `json:"bypass_list_management,omitempty"`
|
||||
Footer *FooterSetting `json:"footer,omitempty"`
|
||||
SandboxMode *SandboxModeSetting `json:"sandbox_mode,omitempty"`
|
||||
}
|
||||
|
||||
// BccSetting ...
|
||||
type BccSetting struct {
|
||||
Enable *bool `json:"enable,omitempty"`
|
||||
Email string `json:"email,omitempty"`
|
||||
}
|
||||
|
||||
// FooterSetting ...
|
||||
type FooterSetting struct {
|
||||
Enable *bool `json:"enable,omitempty"`
|
||||
Text string `json:"text,omitempty"`
|
||||
Html string `json:"html,omitempty"`
|
||||
}
|
||||
|
||||
// ClickTrackingSetting ...
|
||||
type ClickTrackingSetting struct {
|
||||
Enable *bool `json:"enable,omitempty"`
|
||||
EnableText *bool `json:"enable_text,omitempty"`
|
||||
}
|
||||
|
||||
// OpenTrackingSetting ...
|
||||
type OpenTrackingSetting struct {
|
||||
Enable *bool `json:"enable,omitempty"`
|
||||
SubstitutionTag string `json:"substitution_tag,omitempty"`
|
||||
}
|
||||
|
||||
// SandboxModeSetting ...
|
||||
type SandboxModeSetting struct {
|
||||
Enable *bool `json:"enable,omitempty"`
|
||||
ForwardSpam *bool `json:"forward_spam,omitempty"`
|
||||
SpamCheck *SpamCheckSetting `json:"spam_check,omitempty"`
|
||||
}
|
||||
|
||||
// SpamCheckSetting ...
|
||||
type SpamCheckSetting struct {
|
||||
Enable *bool `json:"enable,omitempty"`
|
||||
SpamThreshold int `json:"threshold,omitempty"`
|
||||
PostToURL string `json:"post_to_url,omitempty"`
|
||||
}
|
||||
|
||||
// SubscriptionTrackingSetting ...
|
||||
type SubscriptionTrackingSetting struct {
|
||||
Enable *bool `json:"enable,omitempty"`
|
||||
Text string `json:"text,omitempty"`
|
||||
Html string `json:"html,omitempty"`
|
||||
SubstitutionTag string `json:"substitution_tag,omitempty"`
|
||||
}
|
||||
|
||||
// GaSetting ...
|
||||
type GaSetting struct {
|
||||
Enable *bool `json:"enable,omitempty"`
|
||||
CampaignSource string `json:"utm_source,omitempty"`
|
||||
CampaignTerm string `json:"utm_term,omitempty"`
|
||||
CampaignContent string `json:"utm_content,omitempty"`
|
||||
CampaignName string `json:"utm_campaign,omitempty"`
|
||||
CampaignMedium string `json:"utm_medium,omitempty"`
|
||||
}
|
||||
|
||||
// Setting ...
|
||||
type Setting struct {
|
||||
Enable *bool `json:"enable,omitempty"`
|
||||
}
|
||||
|
||||
// NewV3Mail ...
|
||||
func NewV3Mail() *SGMailV3 {
|
||||
return &SGMailV3{
|
||||
Personalizations: make([]*Personalization, 0),
|
||||
Content: make([]*Content, 0),
|
||||
Attachments: make([]*Attachment, 0),
|
||||
}
|
||||
}
|
||||
|
||||
// NewV3MailInit ...
|
||||
func NewV3MailInit(from *Email, subject string, to *Email, content ...*Content) *SGMailV3 {
|
||||
m := new(SGMailV3)
|
||||
m.SetFrom(from)
|
||||
m.Subject = subject
|
||||
p := NewPersonalization()
|
||||
p.AddTos(to)
|
||||
m.AddPersonalizations(p)
|
||||
m.AddContent(content...)
|
||||
return m
|
||||
}
|
||||
|
||||
// GetRequestBody ...
|
||||
func GetRequestBody(m *SGMailV3) []byte {
|
||||
b, err := json.Marshal(m)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
// AddPersonalizations ...
|
||||
func (s *SGMailV3) AddPersonalizations(p ...*Personalization) *SGMailV3 {
|
||||
s.Personalizations = append(s.Personalizations, p...)
|
||||
return s
|
||||
}
|
||||
|
||||
// AddContent ...
|
||||
func (s *SGMailV3) AddContent(c ...*Content) *SGMailV3 {
|
||||
s.Content = append(s.Content, c...)
|
||||
return s
|
||||
}
|
||||
|
||||
// AddAttachment ...
|
||||
func (s *SGMailV3) AddAttachment(a ...*Attachment) *SGMailV3 {
|
||||
s.Attachments = append(s.Attachments, a...)
|
||||
return s
|
||||
}
|
||||
|
||||
// SetFrom ...
|
||||
func (s *SGMailV3) SetFrom(e *Email) *SGMailV3 {
|
||||
s.From = e
|
||||
return s
|
||||
}
|
||||
|
||||
// SetReplyTo ...
|
||||
func (s *SGMailV3) SetReplyTo(e *Email) *SGMailV3 {
|
||||
s.ReplyTo = e
|
||||
return s
|
||||
}
|
||||
|
||||
// SetTemplateID ...
|
||||
func (s *SGMailV3) SetTemplateID(templateID string) *SGMailV3 {
|
||||
s.TemplateID = templateID
|
||||
return s
|
||||
}
|
||||
|
||||
// AddSection ...
|
||||
func (s *SGMailV3) AddSection(key string, value string) *SGMailV3 {
|
||||
if s.Sections == nil {
|
||||
s.Sections = make(map[string]string)
|
||||
}
|
||||
|
||||
s.Sections[key] = value
|
||||
return s
|
||||
}
|
||||
|
||||
// SetHeader ...
|
||||
func (s *SGMailV3) SetHeader(key string, value string) *SGMailV3 {
|
||||
if s.Headers == nil {
|
||||
s.Headers = make(map[string]string)
|
||||
}
|
||||
|
||||
s.Headers[key] = value
|
||||
return s
|
||||
}
|
||||
|
||||
// AddCategories ...
|
||||
func (s *SGMailV3) AddCategories(category ...string) *SGMailV3 {
|
||||
s.Categories = append(s.Categories, category...)
|
||||
return s
|
||||
}
|
||||
|
||||
// SetCustomArg ...
|
||||
func (s *SGMailV3) SetCustomArg(key string, value string) *SGMailV3 {
|
||||
if s.CustomArgs == nil {
|
||||
s.CustomArgs = make(map[string]string)
|
||||
}
|
||||
|
||||
s.CustomArgs[key] = value
|
||||
return s
|
||||
}
|
||||
|
||||
// SetSendAt ...
|
||||
func (s *SGMailV3) SetSendAt(sendAt int) *SGMailV3 {
|
||||
s.SendAt = sendAt
|
||||
return s
|
||||
}
|
||||
|
||||
// SetBatchID ...
|
||||
func (s *SGMailV3) SetBatchID(batchID string) *SGMailV3 {
|
||||
s.BatchID = batchID
|
||||
return s
|
||||
}
|
||||
|
||||
// SetASM ...
|
||||
func (s *SGMailV3) SetASM(asm *Asm) *SGMailV3 {
|
||||
s.Asm = asm
|
||||
return s
|
||||
}
|
||||
|
||||
// SetIPPoolID ...
|
||||
func (s *SGMailV3) SetIPPoolID(ipPoolID string) *SGMailV3 {
|
||||
s.IPPoolID = ipPoolID
|
||||
return s
|
||||
}
|
||||
|
||||
// SetMailSettings ...
|
||||
func (s *SGMailV3) SetMailSettings(mailSettings *MailSettings) *SGMailV3 {
|
||||
s.MailSettings = mailSettings
|
||||
return s
|
||||
}
|
||||
|
||||
// SetTrackingSettings ...
|
||||
func (s *SGMailV3) SetTrackingSettings(trackingSettings *TrackingSettings) *SGMailV3 {
|
||||
s.TrackingSettings = trackingSettings
|
||||
return s
|
||||
}
|
||||
|
||||
// NewPersonalization ...
|
||||
func NewPersonalization() *Personalization {
|
||||
return &Personalization{
|
||||
To: make([]*Email, 0),
|
||||
CC: make([]*Email, 0),
|
||||
BCC: make([]*Email, 0),
|
||||
Headers: make(map[string]string),
|
||||
Substitutions: make(map[string]string),
|
||||
CustomArgs: make(map[string]string),
|
||||
DynamicTemplateData: make(map[string]interface{}),
|
||||
Categories: make([]string, 0),
|
||||
}
|
||||
}
|
||||
|
||||
// AddTos ...
|
||||
func (p *Personalization) AddTos(to ...*Email) {
|
||||
p.To = append(p.To, to...)
|
||||
}
|
||||
|
||||
// AddCCs ...
|
||||
func (p *Personalization) AddCCs(cc ...*Email) {
|
||||
p.CC = append(p.CC, cc...)
|
||||
}
|
||||
|
||||
// AddBCCs ...
|
||||
func (p *Personalization) AddBCCs(bcc ...*Email) {
|
||||
p.BCC = append(p.BCC, bcc...)
|
||||
}
|
||||
|
||||
// SetHeader ...
|
||||
func (p *Personalization) SetHeader(key string, value string) {
|
||||
p.Headers[key] = value
|
||||
}
|
||||
|
||||
// SetSubstitution ...
|
||||
func (p *Personalization) SetSubstitution(key string, value string) {
|
||||
p.Substitutions[key] = value
|
||||
}
|
||||
|
||||
// SetCustomArg ...
|
||||
func (p *Personalization) SetCustomArg(key string, value string) {
|
||||
p.CustomArgs[key] = value
|
||||
}
|
||||
|
||||
// SetDynamicTemplateData ...
|
||||
func (p *Personalization) SetDynamicTemplateData(key string, value interface{}) {
|
||||
p.DynamicTemplateData[key] = value
|
||||
}
|
||||
|
||||
// SetSendAt ...
|
||||
func (p *Personalization) SetSendAt(sendAt int) {
|
||||
p.SendAt = sendAt
|
||||
}
|
||||
|
||||
// NewAttachment ...
|
||||
func NewAttachment() *Attachment {
|
||||
return &Attachment{}
|
||||
}
|
||||
|
||||
// SetContent ...
|
||||
func (a *Attachment) SetContent(content string) *Attachment {
|
||||
a.Content = content
|
||||
return a
|
||||
}
|
||||
|
||||
// SetType ...
|
||||
func (a *Attachment) SetType(contentType string) *Attachment {
|
||||
a.Type = contentType
|
||||
return a
|
||||
}
|
||||
|
||||
// SetFilename ...
|
||||
func (a *Attachment) SetFilename(filename string) *Attachment {
|
||||
a.Filename = filename
|
||||
return a
|
||||
}
|
||||
|
||||
// SetDisposition ...
|
||||
func (a *Attachment) SetDisposition(disposition string) *Attachment {
|
||||
a.Disposition = disposition
|
||||
return a
|
||||
}
|
||||
|
||||
// SetContentID ...
|
||||
func (a *Attachment) SetContentID(contentID string) *Attachment {
|
||||
a.ContentID = contentID
|
||||
return a
|
||||
}
|
||||
|
||||
// NewASM ...
|
||||
func NewASM() *Asm {
|
||||
return &Asm{}
|
||||
}
|
||||
|
||||
// SetGroupID ...
|
||||
func (a *Asm) SetGroupID(groupID int) *Asm {
|
||||
a.GroupID = groupID
|
||||
return a
|
||||
}
|
||||
|
||||
// AddGroupsToDisplay ...
|
||||
func (a *Asm) AddGroupsToDisplay(groupsToDisplay ...int) *Asm {
|
||||
a.GroupsToDisplay = append(a.GroupsToDisplay, groupsToDisplay...)
|
||||
return a
|
||||
}
|
||||
|
||||
// NewMailSettings ...
|
||||
func NewMailSettings() *MailSettings {
|
||||
return &MailSettings{}
|
||||
}
|
||||
|
||||
// SetBCC ...
|
||||
func (m *MailSettings) SetBCC(bcc *BccSetting) *MailSettings {
|
||||
m.BCC = bcc
|
||||
return m
|
||||
}
|
||||
|
||||
// SetBypassListManagement ...
|
||||
func (m *MailSettings) SetBypassListManagement(bypassListManagement *Setting) *MailSettings {
|
||||
m.BypassListManagement = bypassListManagement
|
||||
return m
|
||||
}
|
||||
|
||||
// SetFooter ...
|
||||
func (m *MailSettings) SetFooter(footerSetting *FooterSetting) *MailSettings {
|
||||
m.Footer = footerSetting
|
||||
return m
|
||||
}
|
||||
|
||||
// SetSandboxMode ...
|
||||
func (m *MailSettings) SetSandboxMode(sandboxMode *Setting) *MailSettings {
|
||||
m.SandboxMode = sandboxMode
|
||||
return m
|
||||
}
|
||||
|
||||
// SetSpamCheckSettings ...
|
||||
func (m *MailSettings) SetSpamCheckSettings(spamCheckSetting *SpamCheckSetting) *MailSettings {
|
||||
m.SpamCheckSetting = spamCheckSetting
|
||||
return m
|
||||
}
|
||||
|
||||
// NewTrackingSettings ...
|
||||
func NewTrackingSettings() *TrackingSettings {
|
||||
return &TrackingSettings{}
|
||||
}
|
||||
|
||||
// SetClickTracking ...
|
||||
func (t *TrackingSettings) SetClickTracking(clickTracking *ClickTrackingSetting) *TrackingSettings {
|
||||
t.ClickTracking = clickTracking
|
||||
return t
|
||||
|
||||
}
|
||||
|
||||
// SetOpenTracking ...
|
||||
func (t *TrackingSettings) SetOpenTracking(openTracking *OpenTrackingSetting) *TrackingSettings {
|
||||
t.OpenTracking = openTracking
|
||||
return t
|
||||
}
|
||||
|
||||
// SetSubscriptionTracking ...
|
||||
func (t *TrackingSettings) SetSubscriptionTracking(subscriptionTracking *SubscriptionTrackingSetting) *TrackingSettings {
|
||||
t.SubscriptionTracking = subscriptionTracking
|
||||
return t
|
||||
}
|
||||
|
||||
// SetGoogleAnalytics ...
|
||||
func (t *TrackingSettings) SetGoogleAnalytics(googleAnalytics *GaSetting) *TrackingSettings {
|
||||
t.GoogleAnalytics = googleAnalytics
|
||||
return t
|
||||
}
|
||||
|
||||
// NewBCCSetting ...
|
||||
func NewBCCSetting() *BccSetting {
|
||||
return &BccSetting{}
|
||||
}
|
||||
|
||||
// SetEnable ...
|
||||
func (b *BccSetting) SetEnable(enable bool) *BccSetting {
|
||||
setEnable := enable
|
||||
b.Enable = &setEnable
|
||||
return b
|
||||
}
|
||||
|
||||
// SetEmail ...
|
||||
func (b *BccSetting) SetEmail(email string) *BccSetting {
|
||||
b.Email = email
|
||||
return b
|
||||
}
|
||||
|
||||
// NewFooterSetting ...
|
||||
func NewFooterSetting() *FooterSetting {
|
||||
return &FooterSetting{}
|
||||
}
|
||||
|
||||
// SetEnable ...
|
||||
func (f *FooterSetting) SetEnable(enable bool) *FooterSetting {
|
||||
setEnable := enable
|
||||
f.Enable = &setEnable
|
||||
return f
|
||||
}
|
||||
|
||||
// SetText ...
|
||||
func (f *FooterSetting) SetText(text string) *FooterSetting {
|
||||
f.Text = text
|
||||
return f
|
||||
}
|
||||
|
||||
// SetHTML ...
|
||||
func (f *FooterSetting) SetHTML(html string) *FooterSetting {
|
||||
f.Html = html
|
||||
return f
|
||||
}
|
||||
|
||||
// NewOpenTrackingSetting ...
|
||||
func NewOpenTrackingSetting() *OpenTrackingSetting {
|
||||
return &OpenTrackingSetting{}
|
||||
}
|
||||
|
||||
// SetEnable ...
|
||||
func (o *OpenTrackingSetting) SetEnable(enable bool) *OpenTrackingSetting {
|
||||
setEnable := enable
|
||||
o.Enable = &setEnable
|
||||
return o
|
||||
}
|
||||
|
||||
// SetSubstitutionTag ...
|
||||
func (o *OpenTrackingSetting) SetSubstitutionTag(subTag string) *OpenTrackingSetting {
|
||||
o.SubstitutionTag = subTag
|
||||
return o
|
||||
}
|
||||
|
||||
// NewSubscriptionTrackingSetting ...
|
||||
func NewSubscriptionTrackingSetting() *SubscriptionTrackingSetting {
|
||||
return &SubscriptionTrackingSetting{}
|
||||
}
|
||||
|
||||
// SetEnable ...
|
||||
func (s *SubscriptionTrackingSetting) SetEnable(enable bool) *SubscriptionTrackingSetting {
|
||||
setEnable := enable
|
||||
s.Enable = &setEnable
|
||||
return s
|
||||
}
|
||||
|
||||
// SetText ...
|
||||
func (s *SubscriptionTrackingSetting) SetText(text string) *SubscriptionTrackingSetting {
|
||||
s.Text = text
|
||||
return s
|
||||
}
|
||||
|
||||
// SetHTML ...
|
||||
func (s *SubscriptionTrackingSetting) SetHTML(html string) *SubscriptionTrackingSetting {
|
||||
s.Html = html
|
||||
return s
|
||||
}
|
||||
|
||||
// SetSubstitutionTag ...
|
||||
func (s *SubscriptionTrackingSetting) SetSubstitutionTag(subTag string) *SubscriptionTrackingSetting {
|
||||
s.SubstitutionTag = subTag
|
||||
return s
|
||||
}
|
||||
|
||||
// NewGaSetting ...
|
||||
func NewGaSetting() *GaSetting {
|
||||
return &GaSetting{}
|
||||
}
|
||||
|
||||
// SetEnable ...
|
||||
func (g *GaSetting) SetEnable(enable bool) *GaSetting {
|
||||
setEnable := enable
|
||||
g.Enable = &setEnable
|
||||
return g
|
||||
}
|
||||
|
||||
// SetCampaignSource ...
|
||||
func (g *GaSetting) SetCampaignSource(campaignSource string) *GaSetting {
|
||||
g.CampaignSource = campaignSource
|
||||
return g
|
||||
}
|
||||
|
||||
// SetCampaignContent ...
|
||||
func (g *GaSetting) SetCampaignContent(campaignContent string) *GaSetting {
|
||||
g.CampaignContent = campaignContent
|
||||
return g
|
||||
}
|
||||
|
||||
// SetCampaignTerm ...
|
||||
func (g *GaSetting) SetCampaignTerm(campaignTerm string) *GaSetting {
|
||||
g.CampaignTerm = campaignTerm
|
||||
return g
|
||||
}
|
||||
|
||||
// SetCampaignName ...
|
||||
func (g *GaSetting) SetCampaignName(campaignName string) *GaSetting {
|
||||
g.CampaignName = campaignName
|
||||
return g
|
||||
}
|
||||
|
||||
// SetCampaignMedium ...
|
||||
func (g *GaSetting) SetCampaignMedium(campaignMedium string) *GaSetting {
|
||||
g.CampaignMedium = campaignMedium
|
||||
return g
|
||||
}
|
||||
|
||||
// NewSetting ...
|
||||
func NewSetting(enable bool) *Setting {
|
||||
setEnable := enable
|
||||
return &Setting{Enable: &setEnable}
|
||||
}
|
||||
|
||||
// NewEmail ...
|
||||
func NewEmail(name string, address string) *Email {
|
||||
return &Email{
|
||||
Name: name,
|
||||
Address: address,
|
||||
}
|
||||
}
|
||||
|
||||
// NewSingleEmail ...
|
||||
func NewSingleEmail(from *Email, subject string, to *Email, plainTextContent string, htmlContent string) *SGMailV3 {
|
||||
plainText := NewContent("text/plain", plainTextContent)
|
||||
html := NewContent("text/html", htmlContent)
|
||||
return NewV3MailInit(from, subject, to, plainText, html)
|
||||
}
|
||||
|
||||
// NewContent ...
|
||||
func NewContent(contentType string, value string) *Content {
|
||||
return &Content{
|
||||
Type: contentType,
|
||||
Value: value,
|
||||
}
|
||||
}
|
||||
|
||||
// NewClickTrackingSetting ...
|
||||
func NewClickTrackingSetting() *ClickTrackingSetting {
|
||||
return &ClickTrackingSetting{}
|
||||
}
|
||||
|
||||
// SetEnable ...
|
||||
func (c *ClickTrackingSetting) SetEnable(enable bool) *ClickTrackingSetting {
|
||||
setEnable := enable
|
||||
c.Enable = &setEnable
|
||||
return c
|
||||
}
|
||||
|
||||
// SetEnableText ...
|
||||
func (c *ClickTrackingSetting) SetEnableText(enableText bool) *ClickTrackingSetting {
|
||||
setEnable := enableText
|
||||
c.EnableText = &setEnable
|
||||
return c
|
||||
}
|
||||
|
||||
// NewSpamCheckSetting ...
|
||||
func NewSpamCheckSetting() *SpamCheckSetting {
|
||||
return &SpamCheckSetting{}
|
||||
}
|
||||
|
||||
// SetEnable ...
|
||||
func (s *SpamCheckSetting) SetEnable(enable bool) *SpamCheckSetting {
|
||||
setEnable := enable
|
||||
s.Enable = &setEnable
|
||||
return s
|
||||
}
|
||||
|
||||
// SetSpamThreshold ...
|
||||
func (s *SpamCheckSetting) SetSpamThreshold(spamThreshold int) *SpamCheckSetting {
|
||||
s.SpamThreshold = spamThreshold
|
||||
return s
|
||||
}
|
||||
|
||||
// SetPostToURL ...
|
||||
func (s *SpamCheckSetting) SetPostToURL(postToURL string) *SpamCheckSetting {
|
||||
s.PostToURL = postToURL
|
||||
return s
|
||||
}
|
||||
|
||||
// NewSandboxModeSetting ...
|
||||
func NewSandboxModeSetting(enable bool, forwardSpam bool, spamCheck *SpamCheckSetting) *SandboxModeSetting {
|
||||
setEnable := enable
|
||||
setForwardSpam := forwardSpam
|
||||
return &SandboxModeSetting{
|
||||
Enable: &setEnable,
|
||||
ForwardSpam: &setForwardSpam,
|
||||
SpamCheck: spamCheck,
|
||||
}
|
||||
}
|
||||
42
vendor/github.com/sendgrid/sendgrid-go/prism.sh
generated
vendored
Executable file
42
vendor/github.com/sendgrid/sendgrid-go/prism.sh
generated
vendored
Executable file
@@ -0,0 +1,42 @@
|
||||
#!/bin/bash
|
||||
|
||||
install () {
|
||||
|
||||
set -eu
|
||||
|
||||
UNAME=$(uname)
|
||||
ARCH=$(uname -m)
|
||||
if [ "$UNAME" != "Linux" ] && [ "$UNAME" != "Darwin" ] && [ "$ARCH" != "x86_64" ] && [ "$ARCH" != "i686" ]; then
|
||||
echo "Sorry, OS/Architecture not supported: ${UNAME}/${ARCH}. Download binary from https://github.com/stoplightio/prism/releases"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ "$UNAME" = "Darwin" ] ; then
|
||||
OSX_ARCH=$(uname -m)
|
||||
if [ "${OSX_ARCH}" = "x86_64" ] ; then
|
||||
PLATFORM="darwin_amd64"
|
||||
fi
|
||||
elif [ "$UNAME" = "Linux" ] ; then
|
||||
LINUX_ARCH=$(uname -m)
|
||||
if [ "${LINUX_ARCH}" = "i686" ] ; then
|
||||
PLATFORM="linux_386"
|
||||
elif [ "${LINUX_ARCH}" = "x86_64" ] ; then
|
||||
PLATFORM="linux_amd64"
|
||||
fi
|
||||
fi
|
||||
|
||||
#LATEST=$(curl -s https://api.github.com/repos/stoplightio/prism/tags | grep -Eo '"name":.*?[^\\]",' | head -n 1 | sed 's/[," ]//g' | cut -d ':' -f 2)
|
||||
LATEST="v0.1.5"
|
||||
URL="https://github.com/stoplightio/prism/releases/download/$LATEST/prism_$PLATFORM"
|
||||
DEST=/home/travis/gopath/bin/prism
|
||||
|
||||
if [ -z $LATEST ] ; then
|
||||
echo "Error requesting. Download binary from ${URL}"
|
||||
exit 1
|
||||
else
|
||||
curl -L $URL -o $DEST
|
||||
chmod +x $DEST
|
||||
fi
|
||||
}
|
||||
|
||||
install
|
||||
127
vendor/github.com/sendgrid/sendgrid-go/sendgrid.go
generated
vendored
Normal file
127
vendor/github.com/sendgrid/sendgrid-go/sendgrid.go
generated
vendored
Normal file
@@ -0,0 +1,127 @@
|
||||
// Package sendgrid provides a simple interface to interact with the SendGrid API
|
||||
package sendgrid
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/sendgrid/rest" // depends on version 2.2.0
|
||||
"github.com/sendgrid/sendgrid-go/helpers/mail"
|
||||
)
|
||||
|
||||
// Version is this client library's current version
|
||||
const (
|
||||
Version = "3.1.0"
|
||||
rateLimitRetry = 5
|
||||
rateLimitSleep = 1100
|
||||
)
|
||||
|
||||
// Client is the SendGrid Go client
|
||||
type Client struct {
|
||||
// rest.Request
|
||||
rest.Request
|
||||
}
|
||||
|
||||
// GetRequest returns a default request object.
|
||||
func GetRequest(key string, endpoint string, host string) rest.Request {
|
||||
if host == "" {
|
||||
host = "https://api.sendgrid.com"
|
||||
}
|
||||
baseURL := host + endpoint
|
||||
requestHeaders := map[string]string{
|
||||
"Authorization": "Bearer " + key,
|
||||
"User-Agent": "sendgrid/" + Version + ";go",
|
||||
"Accept": "application/json",
|
||||
}
|
||||
request := rest.Request{
|
||||
BaseURL: baseURL,
|
||||
Headers: requestHeaders,
|
||||
}
|
||||
return request
|
||||
}
|
||||
|
||||
// Send sends an email through SendGrid
|
||||
func (cl *Client) Send(email *mail.SGMailV3) (*rest.Response, error) {
|
||||
cl.Body = mail.GetRequestBody(email)
|
||||
return API(cl.Request)
|
||||
}
|
||||
|
||||
// NewSendClient constructs a new SendGrid client given an API key
|
||||
func NewSendClient(key string) *Client {
|
||||
request := GetRequest(key, "/v3/mail/send", "")
|
||||
request.Method = "POST"
|
||||
return &Client{request}
|
||||
}
|
||||
|
||||
// DefaultClient is used if no custom HTTP client is defined
|
||||
var DefaultClient = rest.DefaultClient
|
||||
|
||||
// API sets up the request to the SendGrid API, this is main interface.
|
||||
// This function is deprecated. Please use the MakeRequest or
|
||||
// MakeRequestAsync functions.
|
||||
func API(request rest.Request) (*rest.Response, error) {
|
||||
return DefaultClient.API(request)
|
||||
}
|
||||
|
||||
// MakeRequest attemps a SendGrid request synchronously.
|
||||
func MakeRequest(request rest.Request) (*rest.Response, error) {
|
||||
return DefaultClient.API(request)
|
||||
}
|
||||
|
||||
// MakeRequestRetry a synchronous request, but retry in the event of a rate
|
||||
// limited response.
|
||||
func MakeRequestRetry(request rest.Request) (*rest.Response, error) {
|
||||
retry := 0
|
||||
var response *rest.Response
|
||||
var err error
|
||||
|
||||
for {
|
||||
response, err = DefaultClient.API(request)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if response.StatusCode != http.StatusTooManyRequests {
|
||||
return response, nil
|
||||
}
|
||||
|
||||
if retry > rateLimitRetry {
|
||||
return nil, errors.New("Rate limit retry exceeded")
|
||||
}
|
||||
retry++
|
||||
|
||||
resetTime := time.Now().Add(rateLimitSleep * time.Millisecond)
|
||||
|
||||
reset, ok := response.Headers["X-RateLimit-Reset"]
|
||||
if ok && len(reset) > 0 {
|
||||
t, err := strconv.Atoi(reset[0])
|
||||
if err == nil {
|
||||
resetTime = time.Unix(int64(t), 0)
|
||||
}
|
||||
}
|
||||
time.Sleep(resetTime.Sub(time.Now()))
|
||||
}
|
||||
}
|
||||
|
||||
// MakeRequestAsync attempts a request asynchronously in a new go
|
||||
// routine. This function returns two channels: responses
|
||||
// and errors. This function will retry in the case of a
|
||||
// rate limit.
|
||||
func MakeRequestAsync(request rest.Request) (chan *rest.Response, chan error) {
|
||||
r := make(chan *rest.Response)
|
||||
e := make(chan error)
|
||||
|
||||
go func() {
|
||||
response, err := MakeRequestRetry(request)
|
||||
if err != nil {
|
||||
e <- err
|
||||
}
|
||||
if response != nil {
|
||||
r <- response
|
||||
}
|
||||
}()
|
||||
|
||||
return r, e
|
||||
}
|
||||
Reference in New Issue
Block a user