Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
D
dex
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
dex
Commits
9fe70514
Commit
9fe70514
authored
Jun 28, 2016
by
Eric Chiang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
revendor
parent
abd36d63
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
32 changed files
with
456 additions
and
944 deletions
+456
-944
glide.lock
glide.lock
+4
-6
.travis.yml
vendor/github.com/mailgun/mailgun-go/.travis.yml
+2
-3
bounces.go
vendor/github.com/mailgun/mailgun-go/bounces.go
+18
-15
campaigns.go
vendor/github.com/mailgun/mailgun-go/campaigns.go
+18
-18
credentials.go
vendor/github.com/mailgun/mailgun-go/credentials.go
+19
-16
domains.go
vendor/github.com/mailgun/mailgun-go/domains.go
+19
-16
email_validation.go
vendor/github.com/mailgun/mailgun-go/email_validation.go
+8
-7
events.go
vendor/github.com/mailgun/mailgun-go/events.go
+11
-11
httphelpers.go
vendor/github.com/mailgun/mailgun-go/httphelpers.go
+154
-41
mailgun.go
vendor/github.com/mailgun/mailgun-go/mailgun.go
+22
-4
mailgun_test.go
vendor/github.com/mailgun/mailgun-go/mailgun_test.go
+10
-0
mailing_lists.go
vendor/github.com/mailgun/mailgun-go/mailing_lists.go
+0
-0
messages.go
vendor/github.com/mailgun/mailgun-go/messages.go
+39
-37
rest_shim.go
vendor/github.com/mailgun/mailgun-go/rest_shim.go
+40
-39
routes.go
vendor/github.com/mailgun/mailgun-go/routes.go
+27
-23
spam_complaints.go
vendor/github.com/mailgun/mailgun-go/spam_complaints.go
+16
-13
stats.go
vendor/github.com/mailgun/mailgun-go/stats.go
+10
-9
unsubscribes.go
vendor/github.com/mailgun/mailgun-go/unsubscribes.go
+17
-14
webhooks.go
vendor/github.com/mailgun/mailgun-go/webhooks.go
+22
-21
.gitignore
vendor/github.com/mbanzon/simplehttp/.gitignore
+0
-1
.travis.yml
vendor/github.com/mbanzon/simplehttp/.travis.yml
+0
-11
LICENSE
vendor/github.com/mbanzon/simplehttp/LICENSE
+0
-27
README.md
vendor/github.com/mbanzon/simplehttp/README.md
+0
-16
helpers.go
vendor/github.com/mbanzon/simplehttp/helpers.go
+0
-17
helpers_test.go
vendor/github.com/mbanzon/simplehttp/helpers_test.go
+0
-133
json_utils.go
vendor/github.com/mbanzon/simplehttp/json_utils.go
+0
-31
parsing.go
vendor/github.com/mbanzon/simplehttp/parsing.go
+0
-15
payload_test.go
vendor/github.com/mbanzon/simplehttp/payload_test.go
+0
-38
shorthand.go
vendor/github.com/mbanzon/simplehttp/shorthand.go
+0
-74
shorthand_test.go
vendor/github.com/mbanzon/simplehttp/shorthand_test.go
+0
-104
simplehttp.go
vendor/github.com/mbanzon/simplehttp/simplehttp.go
+0
-147
simplehttp_test.go
vendor/github.com/mbanzon/simplehttp/simplehttp_test.go
+0
-37
No files found.
glide.lock
View file @
9fe70514
hash:
af5ee807138ecd53eebc54567b4dcd66e3a6ddc7d758fb9f34e6e3eb13b20cf2
updated: 2016-06-
13T10:58:04.608971954+09
:00
hash:
ed84ba1c371faf2f9a0bf64f6a7767a017e663cb99afa273ec5659432bb474d5
updated: 2016-06-
28T10:15:56.223659517-07
:00
imports:
- name: github.com/andybalholm/cascadia
version: 6122e68c2642b7b75c538a63b15168c6c80fb757
...
...
@@ -39,11 +39,9 @@ imports:
subpackages:
- oid
- name: github.com/mailgun/mailgun-go
version:
9578dc67692294bb7e2a6f4b15dd18c97af19440
version:
a98c4eecda3e6a36bd804ae80e9a4f8edaa6cd99
- name: github.com/mattn/go-sqlite3
version: 2513631704612107a1c8b1803fb8e6b3dda2230e
- name: github.com/mbanzon/simplehttp
version: 04c542e7ac706a25820090f274ea6a4f39a63326
- name: github.com/pborman/uuid
version: ca53cad383cad2479bbba7f7a1a05797ec1386e4
- name: github.com/PuerkitoBio/goquery
...
...
@@ -83,4 +81,4 @@ imports:
version: c87af80f3cc5036b55b83d77171e156791085e2e
- name: gopkg.in/ldap.v2
version: e9a325d64989e2844be629682cb085d2c58eef8d
dev
Imports: []
test
Imports: []
vendor/github.com/mailgun/mailgun-go/.travis.yml
View file @
9fe70514
language
:
go
go
:
-
1.1.2
-
1.2
-
tip
-
1.4
-
1.3.3
env
:
-
GOARCH=amd64
-
GOARCH=386
...
...
vendor/github.com/mailgun/mailgun-go/bounces.go
View file @
9fe70514
package
mailgun
import
(
"github.com/mbanzon/simplehttp"
"strconv"
"time"
)
...
...
@@ -52,15 +51,16 @@ func (b Bounce) GetCode() (int, error) {
// and the slice of bounces specified, if successful.
// Note that the length of the slice may be smaller than the total number of bounces.
func
(
m
*
MailgunImpl
)
GetBounces
(
limit
,
skip
int
)
(
int
,
[]
Bounce
,
error
)
{
r
:=
simplehttp
.
N
ewHTTPRequest
(
generateApiUrl
(
m
,
bouncesEndpoint
))
r
:=
n
ewHTTPRequest
(
generateApiUrl
(
m
,
bouncesEndpoint
))
if
limit
!=
-
1
{
r
.
A
ddParameter
(
"limit"
,
strconv
.
Itoa
(
limit
))
r
.
a
ddParameter
(
"limit"
,
strconv
.
Itoa
(
limit
))
}
if
skip
!=
-
1
{
r
.
A
ddParameter
(
"skip"
,
strconv
.
Itoa
(
skip
))
r
.
a
ddParameter
(
"skip"
,
strconv
.
Itoa
(
skip
))
}
r
.
SetBasicAuth
(
basicAuthUser
,
m
.
ApiKey
())
r
.
setClient
(
m
.
Client
())
r
.
setBasicAuth
(
basicAuthUser
,
m
.
ApiKey
())
var
response
bounceEnvelope
err
:=
getResponseFromJSON
(
r
,
&
response
)
...
...
@@ -73,8 +73,9 @@ func (m *MailgunImpl) GetBounces(limit, skip int) (int, []Bounce, error) {
// GetSingleBounce retrieves a single bounce record, if any exist, for the given recipient address.
func
(
m
*
MailgunImpl
)
GetSingleBounce
(
address
string
)
(
Bounce
,
error
)
{
r
:=
simplehttp
.
NewHTTPRequest
(
generateApiUrl
(
m
,
bouncesEndpoint
)
+
"/"
+
address
)
r
.
SetBasicAuth
(
basicAuthUser
,
m
.
ApiKey
())
r
:=
newHTTPRequest
(
generateApiUrl
(
m
,
bouncesEndpoint
)
+
"/"
+
address
)
r
.
setClient
(
m
.
Client
())
r
.
setBasicAuth
(
basicAuthUser
,
m
.
ApiKey
())
var
response
singleBounceEnvelope
err
:=
getResponseFromJSON
(
r
,
&
response
)
...
...
@@ -98,16 +99,17 @@ func (m *MailgunImpl) GetSingleBounce(address string) (Bounce, error) {
// Note that both code and error exist as strings, even though
// code will report as a number.
func
(
m
*
MailgunImpl
)
AddBounce
(
address
,
code
,
error
string
)
error
{
r
:=
simplehttp
.
NewHTTPRequest
(
generateApiUrl
(
m
,
bouncesEndpoint
))
r
.
SetBasicAuth
(
basicAuthUser
,
m
.
ApiKey
())
r
:=
newHTTPRequest
(
generateApiUrl
(
m
,
bouncesEndpoint
))
r
.
setClient
(
m
.
Client
())
r
.
setBasicAuth
(
basicAuthUser
,
m
.
ApiKey
())
payload
:=
simplehttp
.
N
ewUrlEncodedPayload
()
payload
.
A
ddValue
(
"address"
,
address
)
payload
:=
n
ewUrlEncodedPayload
()
payload
.
a
ddValue
(
"address"
,
address
)
if
code
!=
""
{
payload
.
A
ddValue
(
"code"
,
code
)
payload
.
a
ddValue
(
"code"
,
code
)
}
if
error
!=
""
{
payload
.
A
ddValue
(
"error"
,
error
)
payload
.
a
ddValue
(
"error"
,
error
)
}
_
,
err
:=
makePostRequest
(
r
,
payload
)
return
err
...
...
@@ -115,8 +117,9 @@ func (m *MailgunImpl) AddBounce(address, code, error string) error {
// DeleteBounce removes all bounces associted with the provided e-mail address.
func
(
m
*
MailgunImpl
)
DeleteBounce
(
address
string
)
error
{
r
:=
simplehttp
.
NewHTTPRequest
(
generateApiUrl
(
m
,
bouncesEndpoint
)
+
"/"
+
address
)
r
.
SetBasicAuth
(
basicAuthUser
,
m
.
ApiKey
())
r
:=
newHTTPRequest
(
generateApiUrl
(
m
,
bouncesEndpoint
)
+
"/"
+
address
)
r
.
setClient
(
m
.
Client
())
r
.
setBasicAuth
(
basicAuthUser
,
m
.
ApiKey
())
_
,
err
:=
makeDeleteRequest
(
r
)
return
err
}
vendor/github.com/mailgun/mailgun-go/campaigns.go
View file @
9fe70514
package
mailgun
import
(
"github.com/mbanzon/simplehttp"
)
// Campaigns have been deprecated since development work on this SDK commenced.
// Please refer to http://documentation.mailgun.com/api_reference .
type
Campaign
struct
{
...
...
@@ -28,8 +24,9 @@ type campaignsEnvelope struct {
// Campaigns have been deprecated since development work on this SDK commenced.
// Please refer to http://documentation.mailgun.com/api_reference .
func
(
m
*
MailgunImpl
)
GetCampaigns
()
(
int
,
[]
Campaign
,
error
)
{
r
:=
simplehttp
.
NewHTTPRequest
(
generateApiUrl
(
m
,
campaignsEndpoint
))
r
.
SetBasicAuth
(
basicAuthUser
,
m
.
ApiKey
())
r
:=
newHTTPRequest
(
generateApiUrl
(
m
,
campaignsEndpoint
))
r
.
setClient
(
m
.
Client
())
r
.
setBasicAuth
(
basicAuthUser
,
m
.
ApiKey
())
var
envelope
campaignsEnvelope
err
:=
getResponseFromJSON
(
r
,
&
envelope
)
...
...
@@ -42,13 +39,14 @@ func (m *MailgunImpl) GetCampaigns() (int, []Campaign, error) {
// Campaigns have been deprecated since development work on this SDK commenced.
// Please refer to http://documentation.mailgun.com/api_reference .
func
(
m
*
MailgunImpl
)
CreateCampaign
(
name
,
id
string
)
error
{
r
:=
simplehttp
.
NewHTTPRequest
(
generateApiUrl
(
m
,
campaignsEndpoint
))
r
.
SetBasicAuth
(
basicAuthUser
,
m
.
ApiKey
())
r
:=
newHTTPRequest
(
generateApiUrl
(
m
,
campaignsEndpoint
))
r
.
setClient
(
m
.
Client
())
r
.
setBasicAuth
(
basicAuthUser
,
m
.
ApiKey
())
payload
:=
simplehttp
.
N
ewUrlEncodedPayload
()
payload
.
A
ddValue
(
"name"
,
name
)
payload
:=
n
ewUrlEncodedPayload
()
payload
.
a
ddValue
(
"name"
,
name
)
if
id
!=
""
{
payload
.
A
ddValue
(
"id"
,
id
)
payload
.
a
ddValue
(
"id"
,
id
)
}
_
,
err
:=
makePostRequest
(
r
,
payload
)
return
err
...
...
@@ -57,13 +55,14 @@ func (m *MailgunImpl) CreateCampaign(name, id string) error {
// Campaigns have been deprecated since development work on this SDK commenced.
// Please refer to http://documentation.mailgun.com/api_reference .
func
(
m
*
MailgunImpl
)
UpdateCampaign
(
oldId
,
name
,
newId
string
)
error
{
r
:=
simplehttp
.
NewHTTPRequest
(
generateApiUrl
(
m
,
campaignsEndpoint
)
+
"/"
+
oldId
)
r
.
SetBasicAuth
(
basicAuthUser
,
m
.
ApiKey
())
r
:=
newHTTPRequest
(
generateApiUrl
(
m
,
campaignsEndpoint
)
+
"/"
+
oldId
)
r
.
setClient
(
m
.
Client
())
r
.
setBasicAuth
(
basicAuthUser
,
m
.
ApiKey
())
payload
:=
simplehttp
.
N
ewUrlEncodedPayload
()
payload
.
A
ddValue
(
"name"
,
name
)
payload
:=
n
ewUrlEncodedPayload
()
payload
.
a
ddValue
(
"name"
,
name
)
if
newId
!=
""
{
payload
.
A
ddValue
(
"id"
,
newId
)
payload
.
a
ddValue
(
"id"
,
newId
)
}
_
,
err
:=
makePostRequest
(
r
,
payload
)
return
err
...
...
@@ -72,8 +71,9 @@ func (m *MailgunImpl) UpdateCampaign(oldId, name, newId string) error {
// Campaigns have been deprecated since development work on this SDK commenced.
// Please refer to http://documentation.mailgun.com/api_reference .
func
(
m
*
MailgunImpl
)
DeleteCampaign
(
id
string
)
error
{
r
:=
simplehttp
.
NewHTTPRequest
(
generateApiUrl
(
m
,
campaignsEndpoint
)
+
"/"
+
id
)
r
.
SetBasicAuth
(
basicAuthUser
,
m
.
ApiKey
())
r
:=
newHTTPRequest
(
generateApiUrl
(
m
,
campaignsEndpoint
)
+
"/"
+
id
)
r
.
setClient
(
m
.
Client
())
r
.
setBasicAuth
(
basicAuthUser
,
m
.
ApiKey
())
_
,
err
:=
makeDeleteRequest
(
r
)
return
err
}
vendor/github.com/mailgun/mailgun-go/credentials.go
View file @
9fe70514
...
...
@@ -2,7 +2,6 @@ package mailgun
import
(
"fmt"
"github.com/mbanzon/simplehttp"
"strconv"
)
...
...
@@ -18,14 +17,15 @@ var ErrEmptyParam = fmt.Errorf("empty or illegal parameter")
// GetCredentials returns the (possibly zero-length) list of credentials associated with your domain.
func
(
mg
*
MailgunImpl
)
GetCredentials
(
limit
,
skip
int
)
(
int
,
[]
Credential
,
error
)
{
r
:=
simplehttp
.
NewHTTPRequest
(
generateCredentialsUrl
(
mg
,
""
))
r
:=
newHTTPRequest
(
generateCredentialsUrl
(
mg
,
""
))
r
.
setClient
(
mg
.
Client
())
if
limit
!=
DefaultLimit
{
r
.
A
ddParameter
(
"limit"
,
strconv
.
Itoa
(
limit
))
r
.
a
ddParameter
(
"limit"
,
strconv
.
Itoa
(
limit
))
}
if
skip
!=
DefaultSkip
{
r
.
A
ddParameter
(
"skip"
,
strconv
.
Itoa
(
skip
))
r
.
a
ddParameter
(
"skip"
,
strconv
.
Itoa
(
skip
))
}
r
.
S
etBasicAuth
(
basicAuthUser
,
mg
.
ApiKey
())
r
.
s
etBasicAuth
(
basicAuthUser
,
mg
.
ApiKey
())
var
envelope
struct
{
TotalCount
int
`json:"total_count"`
Items
[]
Credential
`json:"items"`
...
...
@@ -42,11 +42,12 @@ func (mg *MailgunImpl) CreateCredential(login, password string) error {
if
(
login
==
""
)
||
(
password
==
""
)
{
return
ErrEmptyParam
}
r
:=
simplehttp
.
NewHTTPRequest
(
generateCredentialsUrl
(
mg
,
""
))
r
.
SetBasicAuth
(
basicAuthUser
,
mg
.
ApiKey
())
p
:=
simplehttp
.
NewUrlEncodedPayload
()
p
.
AddValue
(
"login"
,
login
)
p
.
AddValue
(
"password"
,
password
)
r
:=
newHTTPRequest
(
generateCredentialsUrl
(
mg
,
""
))
r
.
setClient
(
mg
.
Client
())
r
.
setBasicAuth
(
basicAuthUser
,
mg
.
ApiKey
())
p
:=
newUrlEncodedPayload
()
p
.
addValue
(
"login"
,
login
)
p
.
addValue
(
"password"
,
password
)
_
,
err
:=
makePostRequest
(
r
,
p
)
return
err
}
...
...
@@ -56,10 +57,11 @@ func (mg *MailgunImpl) ChangeCredentialPassword(id, password string) error {
if
(
id
==
""
)
||
(
password
==
""
)
{
return
ErrEmptyParam
}
r
:=
simplehttp
.
NewHTTPRequest
(
generateCredentialsUrl
(
mg
,
id
))
r
.
SetBasicAuth
(
basicAuthUser
,
mg
.
ApiKey
())
p
:=
simplehttp
.
NewUrlEncodedPayload
()
p
.
AddValue
(
"password"
,
password
)
r
:=
newHTTPRequest
(
generateCredentialsUrl
(
mg
,
id
))
r
.
setClient
(
mg
.
Client
())
r
.
setBasicAuth
(
basicAuthUser
,
mg
.
ApiKey
())
p
:=
newUrlEncodedPayload
()
p
.
addValue
(
"password"
,
password
)
_
,
err
:=
makePutRequest
(
r
,
p
)
return
err
}
...
...
@@ -69,8 +71,9 @@ func (mg *MailgunImpl) DeleteCredential(id string) error {
if
id
==
""
{
return
ErrEmptyParam
}
r
:=
simplehttp
.
NewHTTPRequest
(
generateCredentialsUrl
(
mg
,
id
))
r
.
SetBasicAuth
(
basicAuthUser
,
mg
.
ApiKey
())
r
:=
newHTTPRequest
(
generateCredentialsUrl
(
mg
,
id
))
r
.
setClient
(
mg
.
Client
())
r
.
setBasicAuth
(
basicAuthUser
,
mg
.
ApiKey
())
_
,
err
:=
makeDeleteRequest
(
r
)
return
err
}
vendor/github.com/mailgun/mailgun-go/domains.go
View file @
9fe70514
package
mailgun
import
(
"github.com/mbanzon/simplehttp"
"strconv"
"time"
)
...
...
@@ -67,14 +66,15 @@ func (d Domain) GetCreatedAt() (t time.Time, err error) {
// Note that zero items and a zero-length slice do not necessarily imply an error occurred.
// Except for the error itself, all results are undefined in the event of an error.
func
(
m
*
MailgunImpl
)
GetDomains
(
limit
,
skip
int
)
(
int
,
[]
Domain
,
error
)
{
r
:=
simplehttp
.
NewHTTPRequest
(
generatePublicApiUrl
(
domainsEndpoint
))
r
:=
newHTTPRequest
(
generatePublicApiUrl
(
domainsEndpoint
))
r
.
setClient
(
m
.
Client
())
if
limit
!=
DefaultLimit
{
r
.
A
ddParameter
(
"limit"
,
strconv
.
Itoa
(
limit
))
r
.
a
ddParameter
(
"limit"
,
strconv
.
Itoa
(
limit
))
}
if
skip
!=
DefaultSkip
{
r
.
A
ddParameter
(
"skip"
,
strconv
.
Itoa
(
skip
))
r
.
a
ddParameter
(
"skip"
,
strconv
.
Itoa
(
skip
))
}
r
.
S
etBasicAuth
(
basicAuthUser
,
m
.
ApiKey
())
r
.
s
etBasicAuth
(
basicAuthUser
,
m
.
ApiKey
())
var
envelope
domainsEnvelope
err
:=
getResponseFromJSON
(
r
,
&
envelope
)
...
...
@@ -86,8 +86,9 @@ func (m *MailgunImpl) GetDomains(limit, skip int) (int, []Domain, error) {
// Retrieve detailed information about the named domain.
func
(
m
*
MailgunImpl
)
GetSingleDomain
(
domain
string
)
(
Domain
,
[]
DNSRecord
,
[]
DNSRecord
,
error
)
{
r
:=
simplehttp
.
NewHTTPRequest
(
generatePublicApiUrl
(
domainsEndpoint
)
+
"/"
+
domain
)
r
.
SetBasicAuth
(
basicAuthUser
,
m
.
ApiKey
())
r
:=
newHTTPRequest
(
generatePublicApiUrl
(
domainsEndpoint
)
+
"/"
+
domain
)
r
.
setClient
(
m
.
Client
())
r
.
setBasicAuth
(
basicAuthUser
,
m
.
ApiKey
())
var
envelope
singleDomainEnvelope
err
:=
getResponseFromJSON
(
r
,
&
envelope
)
return
envelope
.
Domain
,
envelope
.
ReceivingDNSRecords
,
envelope
.
SendingDNSRecords
,
err
...
...
@@ -100,22 +101,24 @@ func (m *MailgunImpl) GetSingleDomain(domain string) (Domain, []DNSRecord, []DNS
// The wildcard parameter instructs Mailgun to treat all subdomains of this domain uniformly if true,
// and as different domains if false.
func
(
m
*
MailgunImpl
)
CreateDomain
(
name
string
,
smtpPassword
string
,
spamAction
string
,
wildcard
bool
)
error
{
r
:=
simplehttp
.
NewHTTPRequest
(
generatePublicApiUrl
(
domainsEndpoint
))
r
.
SetBasicAuth
(
basicAuthUser
,
m
.
ApiKey
())
r
:=
newHTTPRequest
(
generatePublicApiUrl
(
domainsEndpoint
))
r
.
setClient
(
m
.
Client
())
r
.
setBasicAuth
(
basicAuthUser
,
m
.
ApiKey
())
payload
:=
simplehttp
.
N
ewUrlEncodedPayload
()
payload
.
A
ddValue
(
"name"
,
name
)
payload
.
A
ddValue
(
"smtp_password"
,
smtpPassword
)
payload
.
A
ddValue
(
"spam_action"
,
spamAction
)
payload
.
A
ddValue
(
"wildcard"
,
strconv
.
FormatBool
(
wildcard
))
payload
:=
n
ewUrlEncodedPayload
()
payload
.
a
ddValue
(
"name"
,
name
)
payload
.
a
ddValue
(
"smtp_password"
,
smtpPassword
)
payload
.
a
ddValue
(
"spam_action"
,
spamAction
)
payload
.
a
ddValue
(
"wildcard"
,
strconv
.
FormatBool
(
wildcard
))
_
,
err
:=
makePostRequest
(
r
,
payload
)
return
err
}
// DeleteDomain instructs Mailgun to dispose of the named domain name.
func
(
m
*
MailgunImpl
)
DeleteDomain
(
name
string
)
error
{
r
:=
simplehttp
.
NewHTTPRequest
(
generatePublicApiUrl
(
domainsEndpoint
)
+
"/"
+
name
)
r
.
SetBasicAuth
(
basicAuthUser
,
m
.
ApiKey
())
r
:=
newHTTPRequest
(
generatePublicApiUrl
(
domainsEndpoint
)
+
"/"
+
name
)
r
.
setClient
(
m
.
Client
())
r
.
setBasicAuth
(
basicAuthUser
,
m
.
ApiKey
())
_
,
err
:=
makeDeleteRequest
(
r
)
return
err
}
vendor/github.com/mailgun/mailgun-go/email_validation.go
View file @
9fe70514
package
mailgun
import
(
"github.com/mbanzon/simplehttp"
"strings"
)
...
...
@@ -41,9 +40,10 @@ type addressParseResult struct {
// It may also be used to break an email address into its sub-components. (See example.)
// NOTE: Use of this function requires a proper public API key. The private API key will not work.
func
(
m
*
MailgunImpl
)
ValidateEmail
(
email
string
)
(
EmailVerification
,
error
)
{
r
:=
simplehttp
.
NewHTTPRequest
(
generatePublicApiUrl
(
addressValidateEndpoint
))
r
.
AddParameter
(
"address"
,
email
)
r
.
SetBasicAuth
(
basicAuthUser
,
m
.
PublicApiKey
())
r
:=
newHTTPRequest
(
generatePublicApiUrl
(
addressValidateEndpoint
))
r
.
setClient
(
m
.
Client
())
r
.
addParameter
(
"address"
,
email
)
r
.
setBasicAuth
(
basicAuthUser
,
m
.
PublicApiKey
())
var
response
EmailVerification
err
:=
getResponseFromJSON
(
r
,
&
response
)
...
...
@@ -57,9 +57,10 @@ func (m *MailgunImpl) ValidateEmail(email string) (EmailVerification, error) {
// ParseAddresses takes a list of addresses and sorts them into valid and invalid address categories.
// NOTE: Use of this function requires a proper public API key. The private API key will not work.
func
(
m
*
MailgunImpl
)
ParseAddresses
(
addresses
...
string
)
([]
string
,
[]
string
,
error
)
{
r
:=
simplehttp
.
NewHTTPRequest
(
generatePublicApiUrl
(
addressParseEndpoint
))
r
.
AddParameter
(
"addresses"
,
strings
.
Join
(
addresses
,
","
))
r
.
SetBasicAuth
(
basicAuthUser
,
m
.
PublicApiKey
())
r
:=
newHTTPRequest
(
generatePublicApiUrl
(
addressParseEndpoint
))
r
.
setClient
(
m
.
Client
())
r
.
addParameter
(
"addresses"
,
strings
.
Join
(
addresses
,
","
))
r
.
setBasicAuth
(
basicAuthUser
,
m
.
PublicApiKey
())
var
response
addressParseResult
err
:=
getResponseFromJSON
(
r
,
&
response
)
...
...
vendor/github.com/mailgun/mailgun-go/events.go
View file @
9fe70514
...
...
@@ -2,7 +2,6 @@ package mailgun
import
(
"fmt"
"github.com/mbanzon/simplehttp"
"time"
)
...
...
@@ -58,28 +57,28 @@ func (ei *EventIterator) GetFirstPage(opts GetEventsOptions) error {
return
fmt
.
Errorf
(
"collation cannot at once be both ascending and descending"
)
}
payload
:=
simplehttp
.
N
ewUrlEncodedPayload
()
payload
:=
n
ewUrlEncodedPayload
()
if
opts
.
Limit
!=
0
{
payload
.
A
ddValue
(
"limit"
,
fmt
.
Sprintf
(
"%d"
,
opts
.
Limit
))
payload
.
a
ddValue
(
"limit"
,
fmt
.
Sprintf
(
"%d"
,
opts
.
Limit
))
}
if
opts
.
Compact
{
payload
.
A
ddValue
(
"pretty"
,
"no"
)
payload
.
a
ddValue
(
"pretty"
,
"no"
)
}
if
opts
.
ForceAscending
{
payload
.
A
ddValue
(
"ascending"
,
"yes"
)
payload
.
a
ddValue
(
"ascending"
,
"yes"
)
}
if
opts
.
ForceDescending
{
payload
.
A
ddValue
(
"ascending"
,
"no"
)
payload
.
a
ddValue
(
"ascending"
,
"no"
)
}
if
opts
.
Begin
!=
noTime
{
payload
.
A
ddValue
(
"begin"
,
formatMailgunTime
(
&
opts
.
Begin
))
payload
.
a
ddValue
(
"begin"
,
formatMailgunTime
(
&
opts
.
Begin
))
}
if
opts
.
End
!=
noTime
{
payload
.
A
ddValue
(
"end"
,
formatMailgunTime
(
&
opts
.
End
))
payload
.
a
ddValue
(
"end"
,
formatMailgunTime
(
&
opts
.
End
))
}
if
opts
.
Filter
!=
nil
{
for
k
,
v
:=
range
opts
.
Filter
{
payload
.
A
ddValue
(
k
,
v
)
payload
.
a
ddValue
(
k
,
v
)
}
}
...
...
@@ -105,8 +104,9 @@ func (ei *EventIterator) GetNext() error {
// GetFirstPage, GetPrevious, and GetNext all have a common body of code.
// fetch completes the API fetch common to all three of these functions.
func
(
ei
*
EventIterator
)
fetch
(
url
string
)
error
{
r
:=
simplehttp
.
NewHTTPRequest
(
url
)
r
.
SetBasicAuth
(
basicAuthUser
,
ei
.
mg
.
ApiKey
())
r
:=
newHTTPRequest
(
url
)
r
.
setClient
(
ei
.
mg
.
Client
())
r
.
setBasicAuth
(
basicAuthUser
,
ei
.
mg
.
ApiKey
())
var
response
map
[
string
]
interface
{}
err
:=
getResponseFromJSON
(
r
,
&
response
)
if
err
!=
nil
{
...
...
vendor/github.com/m
banzon/simplehttp/payload
s.go
→
vendor/github.com/m
ailgun/mailgun-go/httphelper
s.go
View file @
9fe70514
package
simplehttp
package
mailgun
import
(
"bytes"
"encoding/json"
"io"
"io/ioutil"
"mime/multipart"
"net/http"
"net/url"
"os"
"path"
)
type
httpRequest
struct
{
URL
string
Parameters
map
[
string
][]
string
Headers
map
[
string
]
string
BasicAuthUser
string
BasicAuthPassword
string
Client
*
http
.
Client
}
type
httpResponse
struct
{
Code
int
Data
[]
byte
}
type
payload
interface
{
getPayloadBuffer
()
(
*
bytes
.
Buffer
,
error
)
getContentType
()
string
}
type
keyValuePair
struct
{
key
string
value
string
...
...
@@ -20,60 +42,78 @@ type keyNameRC struct {
value
io
.
ReadCloser
}
type
Payload
interface
{
GetPayloadBuffer
()
(
*
bytes
.
Buffer
,
error
)
GetContentType
()
string
}
type
RawPayload
struct
{
Data
[]
byte
}
type
FormDataPayload
struct
{
type
formDataPayload
struct
{
contentType
string
Values
[]
keyValuePair
Files
[]
keyValuePair
ReadClosers
[]
keyNameRC
}
type
U
rlEncodedPayload
struct
{
type
u
rlEncodedPayload
struct
{
Values
[]
keyValuePair
}
func
NewRawPayload
(
data
[]
byte
)
*
RawPayload
{
return
&
RawPayload
{
Data
:
data
}
func
newHTTPRequest
(
url
string
)
*
httpRequest
{
return
&
httpRequest
{
URL
:
url
,
Client
:
http
.
DefaultClient
}
}
func
(
r
*
RawPayload
)
GetPayloadBuffer
()
(
*
bytes
.
Buffer
,
error
)
{
data
:=
&
bytes
.
Buffer
{}
c
,
err
:=
data
.
Write
(
r
.
Data
)
if
c
!=
len
(
r
.
Data
)
||
err
!=
nil
{
return
data
,
err
func
(
r
*
httpRequest
)
addParameter
(
name
,
value
string
)
{
if
r
.
Parameters
==
nil
{
r
.
Parameters
=
make
(
map
[
string
][]
string
)
}
r
eturn
data
,
nil
r
.
Parameters
[
name
]
=
append
(
r
.
Parameters
[
name
],
value
)
}
func
(
r
*
RawPayload
)
GetContentType
()
string
{
r
eturn
""
func
(
r
*
httpRequest
)
setClient
(
c
*
http
.
Client
)
{
r
.
Client
=
c
}
func
NewFormDataPayload
()
*
FormDataPayload
{
return
&
FormDataPayload
{}
func
(
r
*
httpRequest
)
setBasicAuth
(
user
,
password
string
)
{
r
.
BasicAuthUser
=
user
r
.
BasicAuthPassword
=
password
}
func
(
f
*
FormDataPayload
)
AddValue
(
key
,
value
string
)
{
func
newUrlEncodedPayload
()
*
urlEncodedPayload
{
return
&
urlEncodedPayload
{}
}
func
(
f
*
urlEncodedPayload
)
addValue
(
key
,
value
string
)
{
f
.
Values
=
append
(
f
.
Values
,
keyValuePair
{
key
:
key
,
value
:
value
})
}
func
(
f
*
FormDataPayload
)
AddFile
(
key
,
file
string
)
{
func
(
f
*
urlEncodedPayload
)
getPayloadBuffer
()
(
*
bytes
.
Buffer
,
error
)
{
data
:=
url
.
Values
{}
for
_
,
keyVal
:=
range
f
.
Values
{
data
.
Add
(
keyVal
.
key
,
keyVal
.
value
)
}
return
bytes
.
NewBufferString
(
data
.
Encode
()),
nil
}
func
(
f
*
urlEncodedPayload
)
getContentType
()
string
{
return
"application/x-www-form-urlencoded"
}
func
(
r
*
httpResponse
)
parseFromJSON
(
v
interface
{})
error
{
return
json
.
Unmarshal
(
r
.
Data
,
v
)
}
func
newFormDataPayload
()
*
formDataPayload
{
return
&
formDataPayload
{}
}
func
(
f
*
formDataPayload
)
addValue
(
key
,
value
string
)
{
f
.
Values
=
append
(
f
.
Values
,
keyValuePair
{
key
:
key
,
value
:
value
})
}
func
(
f
*
formDataPayload
)
addFile
(
key
,
file
string
)
{
f
.
Files
=
append
(
f
.
Files
,
keyValuePair
{
key
:
key
,
value
:
file
})
}
func
(
f
*
FormDataPayload
)
A
ddReadCloser
(
key
,
name
string
,
rc
io
.
ReadCloser
)
{
func
(
f
*
formDataPayload
)
a
ddReadCloser
(
key
,
name
string
,
rc
io
.
ReadCloser
)
{
f
.
ReadClosers
=
append
(
f
.
ReadClosers
,
keyNameRC
{
key
:
key
,
name
:
name
,
value
:
rc
})
}
func
(
f
*
FormDataPayload
)
G
etPayloadBuffer
()
(
*
bytes
.
Buffer
,
error
)
{
func
(
f
*
formDataPayload
)
g
etPayloadBuffer
()
(
*
bytes
.
Buffer
,
error
)
{
data
:=
&
bytes
.
Buffer
{}
writer
:=
multipart
.
NewWriter
(
data
)
defer
writer
.
Close
()
...
...
@@ -113,29 +153,102 @@ func (f *FormDataPayload) GetPayloadBuffer() (*bytes.Buffer, error) {
return
data
,
nil
}
func
(
f
*
FormDataPayload
)
G
etContentType
()
string
{
func
(
f
*
formDataPayload
)
g
etContentType
()
string
{
if
f
.
contentType
==
""
{
f
.
G
etPayloadBuffer
()
f
.
g
etPayloadBuffer
()
}
return
f
.
contentType
}
func
NewUrlEncodedPayload
()
*
UrlEncodedPayload
{
return
&
UrlEncodedPayload
{}
func
(
r
*
httpRequest
)
addHeader
(
name
,
value
string
)
{
if
r
.
Headers
==
nil
{
r
.
Headers
=
make
(
map
[
string
]
string
)
}
r
.
Headers
[
name
]
=
value
}
func
(
f
*
UrlEncodedPayload
)
AddValue
(
key
,
value
string
)
{
f
.
Values
=
append
(
f
.
Values
,
keyValuePair
{
key
:
key
,
value
:
value
}
)
func
(
r
*
httpRequest
)
makeGetRequest
()
(
*
httpResponse
,
error
)
{
return
r
.
makeRequest
(
"GET"
,
nil
)
}
func
(
f
*
UrlEncodedPayload
)
GetPayloadBuffer
()
(
*
bytes
.
Buffer
,
error
)
{
data
:=
url
.
Values
{}
for
_
,
keyVal
:=
range
f
.
Values
{
data
.
Add
(
keyVal
.
key
,
keyVal
.
value
)
func
(
r
*
httpRequest
)
makePostRequest
(
payload
payload
)
(
*
httpResponse
,
error
)
{
return
r
.
makeRequest
(
"POST"
,
payload
)
}
func
(
r
*
httpRequest
)
makePutRequest
(
payload
payload
)
(
*
httpResponse
,
error
)
{
return
r
.
makeRequest
(
"PUT"
,
payload
)
}
func
(
r
*
httpRequest
)
makeDeleteRequest
()
(
*
httpResponse
,
error
)
{
return
r
.
makeRequest
(
"DELETE"
,
nil
)
}
func
(
r
*
httpRequest
)
makeRequest
(
method
string
,
payload
payload
)
(
*
httpResponse
,
error
)
{
url
,
err
:=
r
.
generateUrlWithParameters
()
if
err
!=
nil
{
return
nil
,
err
}
return
bytes
.
NewBufferString
(
data
.
Encode
()),
nil
var
body
io
.
Reader
if
payload
!=
nil
{
if
body
,
err
=
payload
.
getPayloadBuffer
();
err
!=
nil
{
return
nil
,
err
}
}
else
{
body
=
nil
}
req
,
err
:=
http
.
NewRequest
(
method
,
url
,
body
)
if
err
!=
nil
{
return
nil
,
err
}
if
payload
!=
nil
&&
payload
.
getContentType
()
!=
""
{
req
.
Header
.
Add
(
"Content-Type"
,
payload
.
getContentType
())
}
if
r
.
BasicAuthUser
!=
""
&&
r
.
BasicAuthPassword
!=
""
{
req
.
SetBasicAuth
(
r
.
BasicAuthUser
,
r
.
BasicAuthPassword
)
}
for
header
,
value
:=
range
r
.
Headers
{
req
.
Header
.
Add
(
header
,
value
)
}
response
:=
httpResponse
{}
resp
,
err
:=
r
.
Client
.
Do
(
req
)
if
resp
!=
nil
{
response
.
Code
=
resp
.
StatusCode
}
if
err
!=
nil
{
return
nil
,
err
}
defer
resp
.
Body
.
Close
()
responseBody
,
err
:=
ioutil
.
ReadAll
(
resp
.
Body
)
if
err
!=
nil
{
return
nil
,
err
}
response
.
Data
=
responseBody
return
&
response
,
nil
}
func
(
f
*
UrlEncodedPayload
)
GetContentType
()
string
{
return
"application/x-www-form-urlencoded"
func
(
r
*
httpRequest
)
generateUrlWithParameters
()
(
string
,
error
)
{
url
,
err
:=
url
.
Parse
(
r
.
URL
)
if
err
!=
nil
{
return
""
,
err
}
q
:=
url
.
Query
()
if
r
.
Parameters
!=
nil
&&
len
(
r
.
Parameters
)
>
0
{
for
name
,
values
:=
range
r
.
Parameters
{
for
_
,
value
:=
range
values
{
q
.
Add
(
name
,
value
)
}
}
}
url
.
RawQuery
=
q
.
Encode
()
return
url
.
String
(),
nil
}
vendor/github.com/mailgun/mailgun-go/mailgun.go
View file @
9fe70514
...
...
@@ -94,8 +94,8 @@ package mailgun
import
(
"fmt"
"github.com/mbanzon/simplehttp"
"io"
"net/http"
"time"
)
...
...
@@ -131,6 +131,8 @@ type Mailgun interface {
Domain
()
string
ApiKey
()
string
PublicApiKey
()
string
Client
()
*
http
.
Client
SetClient
(
client
*
http
.
Client
)
Send
(
m
*
Message
)
(
string
,
string
,
error
)
ValidateEmail
(
email
string
)
(
EmailVerification
,
error
)
ParseAddresses
(
addresses
...
string
)
([]
string
,
[]
string
,
error
)
...
...
@@ -195,11 +197,17 @@ type MailgunImpl struct {
domain
string
apiKey
string
publicApiKey
string
client
*
http
.
Client
}
// NewMailGun creates a new client instance.
func
NewMailgun
(
domain
,
apiKey
,
publicApiKey
string
)
Mailgun
{
m
:=
MailgunImpl
{
domain
:
domain
,
apiKey
:
apiKey
,
publicApiKey
:
publicApiKey
}
m
:=
MailgunImpl
{
domain
:
domain
,
apiKey
:
apiKey
,
publicApiKey
:
publicApiKey
,
client
:
http
.
DefaultClient
,
}
return
&
m
}
...
...
@@ -218,6 +226,16 @@ func (m *MailgunImpl) PublicApiKey() string {
return
m
.
publicApiKey
}
// Client returns the HTTP client configured for this client.
func
(
m
*
MailgunImpl
)
Client
()
*
http
.
Client
{
return
m
.
client
}
// SetClient updates the HTTP client for this client.
func
(
m
*
MailgunImpl
)
SetClient
(
c
*
http
.
Client
)
{
m
.
client
=
c
}
// generateApiUrl renders a URL for an API endpoint using the domain and endpoint name.
func
generateApiUrl
(
m
Mailgun
,
endpoint
string
)
string
{
return
fmt
.
Sprintf
(
"%s/%s/%s"
,
apiBase
,
m
.
Domain
(),
endpoint
)
...
...
@@ -270,8 +288,8 @@ func generatePublicApiUrl(endpoint string) string {
}
// generateParameterizedUrl works as generateApiUrl, but supports query parameters.
func
generateParameterizedUrl
(
m
Mailgun
,
endpoint
string
,
payload
simplehttp
.
P
ayload
)
(
string
,
error
)
{
paramBuffer
,
err
:=
payload
.
G
etPayloadBuffer
()
func
generateParameterizedUrl
(
m
Mailgun
,
endpoint
string
,
payload
p
ayload
)
(
string
,
error
)
{
paramBuffer
,
err
:=
payload
.
g
etPayloadBuffer
()
if
err
!=
nil
{
return
""
,
err
}
...
...
vendor/github.com/mailgun/mailgun-go/mailgun_test.go
View file @
9fe70514
package
mailgun
import
(
"net/http"
"strconv"
"testing"
)
...
...
@@ -23,6 +24,15 @@ func TestMailgun(t *testing.T) {
if
publicApiKey
!=
m
.
PublicApiKey
()
{
t
.
Fatal
(
"PublicApiKey not equal!"
)
}
if
http
.
DefaultClient
!=
m
.
Client
()
{
t
.
Fatal
(
"HTTP client not default!"
)
}
client
:=
new
(
http
.
Client
)
m
.
SetClient
(
client
)
if
client
!=
m
.
Client
()
{
t
.
Fatal
(
"HTTP client not equal!"
)
}
}
func
TestBounceGetCode
(
t
*
testing
.
T
)
{
...
...
vendor/github.com/mailgun/mailgun-go/mailing_lists.go
View file @
9fe70514
This diff is collapsed.
Click to expand it.
vendor/github.com/mailgun/mailgun-go/messages.go
View file @
9fe70514
...
...
@@ -5,8 +5,6 @@ import (
"errors"
"io"
"time"
"github.com/mbanzon/simplehttp"
)
// MaxNumberOfRecipients represents the largest batch of recipients that Mailgun can support in a single API call.
...
...
@@ -118,7 +116,7 @@ type features interface {
addCC
(
string
)
addBCC
(
string
)
setHtml
(
string
)
addValues
(
*
simplehttp
.
F
ormDataPayload
)
addValues
(
*
f
ormDataPayload
)
isValid
()
bool
endpoint
()
string
recipientCount
()
int
...
...
@@ -423,44 +421,44 @@ func (m *MailgunImpl) Send(message *Message) (mes string, id string, err error)
if
!
isValid
(
message
)
{
err
=
errors
.
New
(
"Message not valid"
)
}
else
{
payload
:=
simplehttp
.
N
ewFormDataPayload
()
payload
:=
n
ewFormDataPayload
()
message
.
specific
.
addValues
(
payload
)
for
_
,
to
:=
range
message
.
to
{
payload
.
A
ddValue
(
"to"
,
to
)
payload
.
a
ddValue
(
"to"
,
to
)
}
for
_
,
tag
:=
range
message
.
tags
{
payload
.
A
ddValue
(
"o:tag"
,
tag
)
payload
.
a
ddValue
(
"o:tag"
,
tag
)
}
for
_
,
campaign
:=
range
message
.
campaigns
{
payload
.
A
ddValue
(
"o:campaign"
,
campaign
)
payload
.
a
ddValue
(
"o:campaign"
,
campaign
)
}
if
message
.
dkimSet
{
payload
.
A
ddValue
(
"o:dkim"
,
yesNo
(
message
.
dkim
))
payload
.
a
ddValue
(
"o:dkim"
,
yesNo
(
message
.
dkim
))
}
if
message
.
deliveryTime
!=
nil
{
payload
.
A
ddValue
(
"o:deliverytime"
,
formatMailgunTime
(
message
.
deliveryTime
))
payload
.
a
ddValue
(
"o:deliverytime"
,
formatMailgunTime
(
message
.
deliveryTime
))
}
if
message
.
testMode
{
payload
.
A
ddValue
(
"o:testmode"
,
"yes"
)
payload
.
a
ddValue
(
"o:testmode"
,
"yes"
)
}
if
message
.
trackingSet
{
payload
.
A
ddValue
(
"o:tracking"
,
yesNo
(
message
.
tracking
))
payload
.
a
ddValue
(
"o:tracking"
,
yesNo
(
message
.
tracking
))
}
if
message
.
trackingClicksSet
{
payload
.
A
ddValue
(
"o:tracking-clicks"
,
yesNo
(
message
.
trackingClicks
))
payload
.
a
ddValue
(
"o:tracking-clicks"
,
yesNo
(
message
.
trackingClicks
))
}
if
message
.
trackingOpensSet
{
payload
.
A
ddValue
(
"o:tracking-opens"
,
yesNo
(
message
.
trackingOpens
))
payload
.
a
ddValue
(
"o:tracking-opens"
,
yesNo
(
message
.
trackingOpens
))
}
if
message
.
headers
!=
nil
{
for
header
,
value
:=
range
message
.
headers
{
payload
.
A
ddValue
(
"h:"
+
header
,
value
)
payload
.
a
ddValue
(
"h:"
+
header
,
value
)
}
}
if
message
.
variables
!=
nil
{
for
variable
,
value
:=
range
message
.
variables
{
payload
.
A
ddValue
(
"v:"
+
variable
,
value
)
payload
.
a
ddValue
(
"v:"
+
variable
,
value
)
}
}
if
message
.
recipientVariables
!=
nil
{
...
...
@@ -468,26 +466,27 @@ func (m *MailgunImpl) Send(message *Message) (mes string, id string, err error)
if
err
!=
nil
{
return
""
,
""
,
err
}
payload
.
A
ddValue
(
"recipient-variables"
,
string
(
j
))
payload
.
a
ddValue
(
"recipient-variables"
,
string
(
j
))
}
if
message
.
attachments
!=
nil
{
for
_
,
attachment
:=
range
message
.
attachments
{
payload
.
A
ddFile
(
"attachment"
,
attachment
)
payload
.
a
ddFile
(
"attachment"
,
attachment
)
}
}
if
message
.
readerAttachments
!=
nil
{
for
_
,
readerAttachment
:=
range
message
.
readerAttachments
{
payload
.
A
ddReadCloser
(
"attachment"
,
readerAttachment
.
Filename
,
readerAttachment
.
ReadCloser
)
payload
.
a
ddReadCloser
(
"attachment"
,
readerAttachment
.
Filename
,
readerAttachment
.
ReadCloser
)
}
}
if
message
.
inlines
!=
nil
{
for
_
,
inline
:=
range
message
.
inlines
{
payload
.
A
ddFile
(
"inline"
,
inline
)
payload
.
a
ddFile
(
"inline"
,
inline
)
}
}
r
:=
simplehttp
.
NewHTTPRequest
(
generateApiUrl
(
m
,
message
.
specific
.
endpoint
()))
r
.
SetBasicAuth
(
basicAuthUser
,
m
.
ApiKey
())
r
:=
newHTTPRequest
(
generateApiUrl
(
m
,
message
.
specific
.
endpoint
()))
r
.
setClient
(
m
.
Client
())
r
.
setBasicAuth
(
basicAuthUser
,
m
.
ApiKey
())
var
response
sendMessageResponse
err
=
postResponseFromJSON
(
r
,
payload
,
&
response
)
...
...
@@ -500,23 +499,23 @@ func (m *MailgunImpl) Send(message *Message) (mes string, id string, err error)
return
}
func
(
pm
*
plainMessage
)
addValues
(
p
*
simplehttp
.
F
ormDataPayload
)
{
p
.
A
ddValue
(
"from"
,
pm
.
from
)
p
.
A
ddValue
(
"subject"
,
pm
.
subject
)
p
.
A
ddValue
(
"text"
,
pm
.
text
)
func
(
pm
*
plainMessage
)
addValues
(
p
*
f
ormDataPayload
)
{
p
.
a
ddValue
(
"from"
,
pm
.
from
)
p
.
a
ddValue
(
"subject"
,
pm
.
subject
)
p
.
a
ddValue
(
"text"
,
pm
.
text
)
for
_
,
cc
:=
range
pm
.
cc
{
p
.
A
ddValue
(
"cc"
,
cc
)
p
.
a
ddValue
(
"cc"
,
cc
)
}
for
_
,
bcc
:=
range
pm
.
bcc
{
p
.
A
ddValue
(
"bcc"
,
bcc
)
p
.
a
ddValue
(
"bcc"
,
bcc
)
}
if
pm
.
html
!=
""
{
p
.
A
ddValue
(
"html"
,
pm
.
html
)
p
.
a
ddValue
(
"html"
,
pm
.
html
)
}
}
func
(
mm
*
mimeMessage
)
addValues
(
p
*
simplehttp
.
F
ormDataPayload
)
{
p
.
A
ddReadCloser
(
"message"
,
"message.mime"
,
mm
.
body
)
func
(
mm
*
mimeMessage
)
addValues
(
p
*
f
ormDataPayload
)
{
p
.
a
ddReadCloser
(
"message"
,
"message.mime"
,
mm
.
body
)
}
func
(
pm
*
plainMessage
)
endpoint
()
string
{
...
...
@@ -612,8 +611,9 @@ func validateStringList(list []string, requireOne bool) bool {
// This provides visibility into, e.g., replies to a message sent to a mailing list.
func
(
mg
*
MailgunImpl
)
GetStoredMessage
(
id
string
)
(
StoredMessage
,
error
)
{
url
:=
generateStoredMessageUrl
(
mg
,
messagesEndpoint
,
id
)
r
:=
simplehttp
.
NewHTTPRequest
(
url
)
r
.
SetBasicAuth
(
basicAuthUser
,
mg
.
ApiKey
())
r
:=
newHTTPRequest
(
url
)
r
.
setClient
(
mg
.
Client
())
r
.
setBasicAuth
(
basicAuthUser
,
mg
.
ApiKey
())
var
response
StoredMessage
err
:=
getResponseFromJSON
(
r
,
&
response
)
...
...
@@ -625,9 +625,10 @@ func (mg *MailgunImpl) GetStoredMessage(id string) (StoredMessage, error) {
// thus delegates to the caller the required parsing.
func
(
mg
*
MailgunImpl
)
GetStoredMessageRaw
(
id
string
)
(
StoredMessageRaw
,
error
)
{
url
:=
generateStoredMessageUrl
(
mg
,
messagesEndpoint
,
id
)
r
:=
simplehttp
.
NewHTTPRequest
(
url
)
r
.
SetBasicAuth
(
basicAuthUser
,
mg
.
ApiKey
())
r
.
AddHeader
(
"Accept"
,
"message/rfc2822"
)
r
:=
newHTTPRequest
(
url
)
r
.
setClient
(
mg
.
Client
())
r
.
setBasicAuth
(
basicAuthUser
,
mg
.
ApiKey
())
r
.
addHeader
(
"Accept"
,
"message/rfc2822"
)
var
response
StoredMessageRaw
err
:=
getResponseFromJSON
(
r
,
&
response
)
...
...
@@ -640,8 +641,9 @@ func (mg *MailgunImpl) GetStoredMessageRaw(id string) (StoredMessageRaw, error)
// Consult the current Mailgun API documentation for more details.
func
(
mg
*
MailgunImpl
)
DeleteStoredMessage
(
id
string
)
error
{
url
:=
generateStoredMessageUrl
(
mg
,
messagesEndpoint
,
id
)
r
:=
simplehttp
.
NewHTTPRequest
(
url
)
r
.
SetBasicAuth
(
basicAuthUser
,
mg
.
ApiKey
())
r
:=
newHTTPRequest
(
url
)
r
.
setClient
(
mg
.
Client
())
r
.
setBasicAuth
(
basicAuthUser
,
mg
.
ApiKey
())
_
,
err
:=
makeDeleteRequest
(
r
)
return
err
}
vendor/github.com/mailgun/mailgun-go/rest_shim.go
View file @
9fe70514
...
...
@@ -2,7 +2,6 @@ package mailgun
import
(
"fmt"
"github.com/mbanzon/simplehttp"
)
// The MailgunGoUserAgent identifies the client to the server, for logging purposes.
...
...
@@ -17,12 +16,13 @@ type UnexpectedResponseError struct {
Expected
[]
int
Actual
int
URL
string
Data
[]
byte
}
// String() converts the error into a human-readable, logfmt-compliant string.
// See http://godoc.org/github.com/kr/logfmt for details on logfmt formatting.
func
(
e
*
UnexpectedResponseError
)
String
()
string
{
return
fmt
.
Sprintf
(
"UnexpectedResponseError URL=%s ExpectedOneOf=%#v Got=%d
"
,
e
.
URL
,
e
.
Expected
,
e
.
Actual
)
return
fmt
.
Sprintf
(
"UnexpectedResponseError URL=%s ExpectedOneOf=%#v Got=%d
Error: %s"
,
e
.
URL
,
e
.
Expected
,
e
.
Actual
,
string
(
e
.
Data
)
)
}
// Error() performs as String().
...
...
@@ -31,11 +31,12 @@ func (e *UnexpectedResponseError) Error() string {
}
// newError creates a new error condition to be returned.
func
newError
(
url
string
,
expected
[]
int
,
got
int
)
error
{
func
newError
(
url
string
,
expected
[]
int
,
got
*
httpResponse
)
error
{
return
&
UnexpectedResponseError
{
URL
:
url
,
Expected
:
expected
,
Actual
:
got
,
Actual
:
got
.
Code
,
Data
:
got
.
Data
,
}
}
...
...
@@ -56,97 +57,97 @@ var expected = []int{200, 202, 204}
// makeRequest shim performs a generic request, checking for a positive outcome.
// See simplehttp.MakeRequest for more details.
func
makeRequest
(
r
*
simplehttp
.
HTTPRequest
,
kind
string
,
p
simplehttp
.
Payload
)
(
*
simplehttp
.
HTTP
Response
,
error
)
{
r
.
A
ddHeader
(
"User-Agent"
,
MailgunGoUserAgent
)
rsp
,
err
:=
r
.
M
akeRequest
(
kind
,
p
)
func
makeRequest
(
r
*
httpRequest
,
kind
string
,
p
payload
)
(
*
http
Response
,
error
)
{
r
.
a
ddHeader
(
"User-Agent"
,
MailgunGoUserAgent
)
rsp
,
err
:=
r
.
m
akeRequest
(
kind
,
p
)
if
(
err
==
nil
)
&&
notGood
(
rsp
.
Code
,
expected
)
{
return
rsp
,
newError
(
r
.
URL
,
expected
,
rsp
.
Code
)
return
rsp
,
newError
(
r
.
URL
,
expected
,
rsp
)
}
return
rsp
,
err
}
// getResponseFromJSON shim performs a GET request, checking for a positive outcome.
// See simplehttp.GetResponseFromJSON for more details.
func
getResponseFromJSON
(
r
*
simplehttp
.
HTTP
Request
,
v
interface
{})
error
{
r
.
A
ddHeader
(
"User-Agent"
,
MailgunGoUserAgent
)
response
,
err
:=
r
.
M
akeGetRequest
()
func
getResponseFromJSON
(
r
*
http
Request
,
v
interface
{})
error
{
r
.
a
ddHeader
(
"User-Agent"
,
MailgunGoUserAgent
)
response
,
err
:=
r
.
m
akeGetRequest
()
if
err
!=
nil
{
return
err
}
if
notGood
(
response
.
Code
,
expected
)
{
return
newError
(
r
.
URL
,
expected
,
response
.
Code
)
return
newError
(
r
.
URL
,
expected
,
response
)
}
return
response
.
P
arseFromJSON
(
v
)
return
response
.
p
arseFromJSON
(
v
)
}
// postResponseFromJSON shim performs a POST request, checking for a positive outcome.
// See simplehttp.PostResponseFromJSON for more details.
func
postResponseFromJSON
(
r
*
simplehttp
.
HTTPRequest
,
p
simplehttp
.
P
ayload
,
v
interface
{})
error
{
r
.
A
ddHeader
(
"User-Agent"
,
MailgunGoUserAgent
)
response
,
err
:=
r
.
M
akePostRequest
(
p
)
func
postResponseFromJSON
(
r
*
httpRequest
,
p
p
ayload
,
v
interface
{})
error
{
r
.
a
ddHeader
(
"User-Agent"
,
MailgunGoUserAgent
)
response
,
err
:=
r
.
m
akePostRequest
(
p
)
if
err
!=
nil
{
return
err
}
if
notGood
(
response
.
Code
,
expected
)
{
return
newError
(
r
.
URL
,
expected
,
response
.
Code
)
return
newError
(
r
.
URL
,
expected
,
response
)
}
return
response
.
P
arseFromJSON
(
v
)
return
response
.
p
arseFromJSON
(
v
)
}
// putResponseFromJSON shim performs a PUT request, checking for a positive outcome.
// See simplehttp.PutResponseFromJSON for more details.
func
putResponseFromJSON
(
r
*
simplehttp
.
HTTPRequest
,
p
simplehttp
.
P
ayload
,
v
interface
{})
error
{
r
.
A
ddHeader
(
"User-Agent"
,
MailgunGoUserAgent
)
response
,
err
:=
r
.
M
akePutRequest
(
p
)
func
putResponseFromJSON
(
r
*
httpRequest
,
p
p
ayload
,
v
interface
{})
error
{
r
.
a
ddHeader
(
"User-Agent"
,
MailgunGoUserAgent
)
response
,
err
:=
r
.
m
akePutRequest
(
p
)
if
err
!=
nil
{
return
err
}
if
notGood
(
response
.
Code
,
expected
)
{
return
newError
(
r
.
URL
,
expected
,
response
.
Code
)
return
newError
(
r
.
URL
,
expected
,
response
)
}
return
response
.
P
arseFromJSON
(
v
)
return
response
.
p
arseFromJSON
(
v
)
}
// makeGetRequest shim performs a GET request, checking for a positive outcome.
// See simplehttp.MakeGetRequest for more details.
func
makeGetRequest
(
r
*
simplehttp
.
HTTPRequest
)
(
*
simplehttp
.
HTTP
Response
,
error
)
{
r
.
A
ddHeader
(
"User-Agent"
,
MailgunGoUserAgent
)
rsp
,
err
:=
r
.
M
akeGetRequest
()
func
makeGetRequest
(
r
*
httpRequest
)
(
*
http
Response
,
error
)
{
r
.
a
ddHeader
(
"User-Agent"
,
MailgunGoUserAgent
)
rsp
,
err
:=
r
.
m
akeGetRequest
()
if
(
err
==
nil
)
&&
notGood
(
rsp
.
Code
,
expected
)
{
return
rsp
,
newError
(
r
.
URL
,
expected
,
rsp
.
Code
)
return
rsp
,
newError
(
r
.
URL
,
expected
,
rsp
)
}
return
rsp
,
err
}
// makePostRequest shim performs a POST request, checking for a positive outcome.
// See simplehttp.MakePostRequest for more details.
func
makePostRequest
(
r
*
simplehttp
.
HTTPRequest
,
p
simplehttp
.
Payload
)
(
*
simplehttp
.
HTTP
Response
,
error
)
{
r
.
A
ddHeader
(
"User-Agent"
,
MailgunGoUserAgent
)
rsp
,
err
:=
r
.
M
akePostRequest
(
p
)
func
makePostRequest
(
r
*
httpRequest
,
p
payload
)
(
*
http
Response
,
error
)
{
r
.
a
ddHeader
(
"User-Agent"
,
MailgunGoUserAgent
)
rsp
,
err
:=
r
.
m
akePostRequest
(
p
)
if
(
err
==
nil
)
&&
notGood
(
rsp
.
Code
,
expected
)
{
return
rsp
,
newError
(
r
.
URL
,
expected
,
rsp
.
Code
)
return
rsp
,
newError
(
r
.
URL
,
expected
,
rsp
)
}
return
rsp
,
err
}
// makePutRequest shim performs a PUT request, checking for a positive outcome.
// See simplehttp.MakePutRequest for more details.
func
makePutRequest
(
r
*
simplehttp
.
HTTPRequest
,
p
simplehttp
.
Payload
)
(
*
simplehttp
.
HTTP
Response
,
error
)
{
r
.
A
ddHeader
(
"User-Agent"
,
MailgunGoUserAgent
)
rsp
,
err
:=
r
.
M
akePutRequest
(
p
)
func
makePutRequest
(
r
*
httpRequest
,
p
payload
)
(
*
http
Response
,
error
)
{
r
.
a
ddHeader
(
"User-Agent"
,
MailgunGoUserAgent
)
rsp
,
err
:=
r
.
m
akePutRequest
(
p
)
if
(
err
==
nil
)
&&
notGood
(
rsp
.
Code
,
expected
)
{
return
rsp
,
newError
(
r
.
URL
,
expected
,
rsp
.
Code
)
return
rsp
,
newError
(
r
.
URL
,
expected
,
rsp
)
}
return
rsp
,
err
}
// makeDeleteRequest shim performs a DELETE request, checking for a positive outcome.
// See simplehttp.MakeDeleteRequest for more details.
func
makeDeleteRequest
(
r
*
simplehttp
.
HTTPRequest
)
(
*
simplehttp
.
HTTP
Response
,
error
)
{
r
.
A
ddHeader
(
"User-Agent"
,
MailgunGoUserAgent
)
rsp
,
err
:=
r
.
M
akeDeleteRequest
()
func
makeDeleteRequest
(
r
*
httpRequest
)
(
*
http
Response
,
error
)
{
r
.
a
ddHeader
(
"User-Agent"
,
MailgunGoUserAgent
)
rsp
,
err
:=
r
.
m
akeDeleteRequest
()
if
(
err
==
nil
)
&&
notGood
(
rsp
.
Code
,
expected
)
{
return
rsp
,
newError
(
r
.
URL
,
expected
,
rsp
.
Code
)
return
rsp
,
newError
(
r
.
URL
,
expected
,
rsp
)
}
return
rsp
,
err
}
vendor/github.com/mailgun/mailgun-go/routes.go
View file @
9fe70514
package
mailgun
import
(
"github.com/mbanzon/simplehttp"
"strconv"
)
...
...
@@ -34,14 +33,15 @@ type Route struct {
// messages sent to a specfic address on your domain.
// See the Mailgun documentation for more information.
func
(
mg
*
MailgunImpl
)
GetRoutes
(
limit
,
skip
int
)
(
int
,
[]
Route
,
error
)
{
r
:=
simplehttp
.
N
ewHTTPRequest
(
generatePublicApiUrl
(
routesEndpoint
))
r
:=
n
ewHTTPRequest
(
generatePublicApiUrl
(
routesEndpoint
))
if
limit
!=
DefaultLimit
{
r
.
A
ddParameter
(
"limit"
,
strconv
.
Itoa
(
limit
))
r
.
a
ddParameter
(
"limit"
,
strconv
.
Itoa
(
limit
))
}
if
skip
!=
DefaultSkip
{
r
.
A
ddParameter
(
"skip"
,
strconv
.
Itoa
(
skip
))
r
.
a
ddParameter
(
"skip"
,
strconv
.
Itoa
(
skip
))
}
r
.
SetBasicAuth
(
basicAuthUser
,
mg
.
ApiKey
())
r
.
setClient
(
mg
.
Client
())
r
.
setBasicAuth
(
basicAuthUser
,
mg
.
ApiKey
())
var
envelope
struct
{
TotalCount
int
`json:"total_count"`
...
...
@@ -59,14 +59,15 @@ func (mg *MailgunImpl) GetRoutes(limit, skip int) (int, []Route, error) {
// only a subset of the fields influence the operation.
// See the Route structure definition for more details.
func
(
mg
*
MailgunImpl
)
CreateRoute
(
prototype
Route
)
(
Route
,
error
)
{
r
:=
simplehttp
.
NewHTTPRequest
(
generatePublicApiUrl
(
routesEndpoint
))
r
.
SetBasicAuth
(
basicAuthUser
,
mg
.
ApiKey
())
p
:=
simplehttp
.
NewUrlEncodedPayload
()
p
.
AddValue
(
"priority"
,
strconv
.
Itoa
(
prototype
.
Priority
))
p
.
AddValue
(
"description"
,
prototype
.
Description
)
p
.
AddValue
(
"expression"
,
prototype
.
Expression
)
r
:=
newHTTPRequest
(
generatePublicApiUrl
(
routesEndpoint
))
r
.
setClient
(
mg
.
Client
())
r
.
setBasicAuth
(
basicAuthUser
,
mg
.
ApiKey
())
p
:=
newUrlEncodedPayload
()
p
.
addValue
(
"priority"
,
strconv
.
Itoa
(
prototype
.
Priority
))
p
.
addValue
(
"description"
,
prototype
.
Description
)
p
.
addValue
(
"expression"
,
prototype
.
Expression
)
for
_
,
action
:=
range
prototype
.
Actions
{
p
.
A
ddValue
(
"action"
,
action
)
p
.
a
ddValue
(
"action"
,
action
)
}
var
envelope
struct
{
Message
string
`json:"message"`
...
...
@@ -80,16 +81,18 @@ func (mg *MailgunImpl) CreateRoute(prototype Route) (Route, error) {
// To avoid ambiguity, Mailgun identifies the route by unique ID.
// See the Route structure definition and the Mailgun API documentation for more details.
func
(
mg
*
MailgunImpl
)
DeleteRoute
(
id
string
)
error
{
r
:=
simplehttp
.
NewHTTPRequest
(
generatePublicApiUrl
(
routesEndpoint
)
+
"/"
+
id
)
r
.
SetBasicAuth
(
basicAuthUser
,
mg
.
ApiKey
())
r
:=
newHTTPRequest
(
generatePublicApiUrl
(
routesEndpoint
)
+
"/"
+
id
)
r
.
setClient
(
mg
.
Client
())
r
.
setBasicAuth
(
basicAuthUser
,
mg
.
ApiKey
())
_
,
err
:=
makeDeleteRequest
(
r
)
return
err
}
// GetRouteByID retrieves the complete route definition associated with the unique route ID.
func
(
mg
*
MailgunImpl
)
GetRouteByID
(
id
string
)
(
Route
,
error
)
{
r
:=
simplehttp
.
NewHTTPRequest
(
generatePublicApiUrl
(
routesEndpoint
)
+
"/"
+
id
)
r
.
SetBasicAuth
(
basicAuthUser
,
mg
.
ApiKey
())
r
:=
newHTTPRequest
(
generatePublicApiUrl
(
routesEndpoint
)
+
"/"
+
id
)
r
.
setClient
(
mg
.
Client
())
r
.
setBasicAuth
(
basicAuthUser
,
mg
.
ApiKey
())
var
envelope
struct
{
Message
string
`json:"message"`
*
Route
`json:"route"`
...
...
@@ -102,21 +105,22 @@ func (mg *MailgunImpl) GetRouteByID(id string) (Route, error) {
// Only those route fields which are non-zero or non-empty are updated.
// All other fields remain as-is.
func
(
mg
*
MailgunImpl
)
UpdateRoute
(
id
string
,
route
Route
)
(
Route
,
error
)
{
r
:=
simplehttp
.
NewHTTPRequest
(
generatePublicApiUrl
(
routesEndpoint
)
+
"/"
+
id
)
r
.
SetBasicAuth
(
basicAuthUser
,
mg
.
ApiKey
())
p
:=
simplehttp
.
NewUrlEncodedPayload
()
r
:=
newHTTPRequest
(
generatePublicApiUrl
(
routesEndpoint
)
+
"/"
+
id
)
r
.
setClient
(
mg
.
Client
())
r
.
setBasicAuth
(
basicAuthUser
,
mg
.
ApiKey
())
p
:=
newUrlEncodedPayload
()
if
route
.
Priority
!=
0
{
p
.
A
ddValue
(
"priority"
,
strconv
.
Itoa
(
route
.
Priority
))
p
.
a
ddValue
(
"priority"
,
strconv
.
Itoa
(
route
.
Priority
))
}
if
route
.
Description
!=
""
{
p
.
A
ddValue
(
"description"
,
route
.
Description
)
p
.
a
ddValue
(
"description"
,
route
.
Description
)
}
if
route
.
Expression
!=
""
{
p
.
A
ddValue
(
"expression"
,
route
.
Expression
)
p
.
a
ddValue
(
"expression"
,
route
.
Expression
)
}
if
route
.
Actions
!=
nil
{
for
_
,
action
:=
range
route
.
Actions
{
p
.
A
ddValue
(
"action"
,
action
)
p
.
a
ddValue
(
"action"
,
action
)
}
}
// For some reason, this API function just returns a bare Route on success.
...
...
vendor/github.com/mailgun/mailgun-go/spam_complaints.go
View file @
9fe70514
package
mailgun
import
(
"github.com/mbanzon/simplehttp"
"strconv"
)
...
...
@@ -28,14 +27,15 @@ type complaintsEnvelope struct {
// Recipients of your messages can click on a link which sends feedback to Mailgun
// indicating that the message they received is, to them, spam.
func
(
m
*
MailgunImpl
)
GetComplaints
(
limit
,
skip
int
)
(
int
,
[]
Complaint
,
error
)
{
r
:=
simplehttp
.
NewHTTPRequest
(
generateApiUrl
(
m
,
complaintsEndpoint
))
r
.
SetBasicAuth
(
basicAuthUser
,
m
.
ApiKey
())
r
:=
newHTTPRequest
(
generateApiUrl
(
m
,
complaintsEndpoint
))
r
.
setClient
(
m
.
Client
())
r
.
setBasicAuth
(
basicAuthUser
,
m
.
ApiKey
())
if
limit
!=
-
1
{
r
.
A
ddParameter
(
"limit"
,
strconv
.
Itoa
(
limit
))
r
.
a
ddParameter
(
"limit"
,
strconv
.
Itoa
(
limit
))
}
if
skip
!=
-
1
{
r
.
A
ddParameter
(
"skip"
,
strconv
.
Itoa
(
skip
))
r
.
a
ddParameter
(
"skip"
,
strconv
.
Itoa
(
skip
))
}
var
envelope
complaintsEnvelope
...
...
@@ -49,8 +49,9 @@ func (m *MailgunImpl) GetComplaints(limit, skip int) (int, []Complaint, error) {
// GetSingleComplaint returns a single complaint record filed by a recipient at the email address provided.
// If no complaint exists, the Complaint instance returned will be empty.
func
(
m
*
MailgunImpl
)
GetSingleComplaint
(
address
string
)
(
Complaint
,
error
)
{
r
:=
simplehttp
.
NewHTTPRequest
(
generateApiUrl
(
m
,
complaintsEndpoint
)
+
"/"
+
address
)
r
.
SetBasicAuth
(
basicAuthUser
,
m
.
ApiKey
())
r
:=
newHTTPRequest
(
generateApiUrl
(
m
,
complaintsEndpoint
)
+
"/"
+
address
)
r
.
setClient
(
m
.
Client
())
r
.
setBasicAuth
(
basicAuthUser
,
m
.
ApiKey
())
var
c
Complaint
err
:=
getResponseFromJSON
(
r
,
&
c
)
...
...
@@ -60,10 +61,11 @@ func (m *MailgunImpl) GetSingleComplaint(address string) (Complaint, error) {
// CreateComplaint registers the specified address as a recipient who has complained of receiving spam
// from your domain.
func
(
m
*
MailgunImpl
)
CreateComplaint
(
address
string
)
error
{
r
:=
simplehttp
.
NewHTTPRequest
(
generateApiUrl
(
m
,
complaintsEndpoint
))
r
.
SetBasicAuth
(
basicAuthUser
,
m
.
ApiKey
())
p
:=
simplehttp
.
NewUrlEncodedPayload
()
p
.
AddValue
(
"address"
,
address
)
r
:=
newHTTPRequest
(
generateApiUrl
(
m
,
complaintsEndpoint
))
r
.
setClient
(
m
.
Client
())
r
.
setBasicAuth
(
basicAuthUser
,
m
.
ApiKey
())
p
:=
newUrlEncodedPayload
()
p
.
addValue
(
"address"
,
address
)
_
,
err
:=
makePostRequest
(
r
,
p
)
return
err
}
...
...
@@ -71,8 +73,9 @@ func (m *MailgunImpl) CreateComplaint(address string) error {
// DeleteComplaint removes a previously registered e-mail address from the list of people who complained
// of receiving spam from your domain.
func
(
m
*
MailgunImpl
)
DeleteComplaint
(
address
string
)
error
{
r
:=
simplehttp
.
NewHTTPRequest
(
generateApiUrl
(
m
,
complaintsEndpoint
)
+
"/"
+
address
)
r
.
SetBasicAuth
(
basicAuthUser
,
m
.
ApiKey
())
r
:=
newHTTPRequest
(
generateApiUrl
(
m
,
complaintsEndpoint
)
+
"/"
+
address
)
r
.
setClient
(
m
.
Client
())
r
.
setBasicAuth
(
basicAuthUser
,
m
.
ApiKey
())
_
,
err
:=
makeDeleteRequest
(
r
)
return
err
}
vendor/github.com/mailgun/mailgun-go/stats.go
View file @
9fe70514
package
mailgun
import
(
"github.com/mbanzon/simplehttp"
"strconv"
"time"
)
...
...
@@ -23,23 +22,24 @@ type statsEnvelope struct {
// Events start at the given start date, if one is provided.
// If not, this function will consider all stated events dating to the creation of the sending domain.
func
(
m
*
MailgunImpl
)
GetStats
(
limit
int
,
skip
int
,
startDate
*
time
.
Time
,
event
...
string
)
(
int
,
[]
Stat
,
error
)
{
r
:=
simplehttp
.
N
ewHTTPRequest
(
generateApiUrl
(
m
,
statsEndpoint
))
r
:=
n
ewHTTPRequest
(
generateApiUrl
(
m
,
statsEndpoint
))
if
limit
!=
-
1
{
r
.
A
ddParameter
(
"limit"
,
strconv
.
Itoa
(
limit
))
r
.
a
ddParameter
(
"limit"
,
strconv
.
Itoa
(
limit
))
}
if
skip
!=
-
1
{
r
.
A
ddParameter
(
"skip"
,
strconv
.
Itoa
(
skip
))
r
.
a
ddParameter
(
"skip"
,
strconv
.
Itoa
(
skip
))
}
if
startDate
!=
nil
{
r
.
A
ddParameter
(
"start-date"
,
startDate
.
Format
(
time
.
RFC3339
))
r
.
a
ddParameter
(
"start-date"
,
startDate
.
Format
(
time
.
RFC3339
))
}
for
_
,
e
:=
range
event
{
r
.
A
ddParameter
(
"event"
,
e
)
r
.
a
ddParameter
(
"event"
,
e
)
}
r
.
SetBasicAuth
(
basicAuthUser
,
m
.
ApiKey
())
r
.
setClient
(
m
.
Client
())
r
.
setBasicAuth
(
basicAuthUser
,
m
.
ApiKey
())
var
res
statsEnvelope
err
:=
getResponseFromJSON
(
r
,
&
res
)
...
...
@@ -52,8 +52,9 @@ func (m *MailgunImpl) GetStats(limit int, skip int, startDate *time.Time, event
// DeleteTag removes all counters for a particular tag, including the tag itself.
func
(
m
*
MailgunImpl
)
DeleteTag
(
tag
string
)
error
{
r
:=
simplehttp
.
NewHTTPRequest
(
generateApiUrl
(
m
,
deleteTagEndpoint
)
+
"/"
+
tag
)
r
.
SetBasicAuth
(
basicAuthUser
,
m
.
ApiKey
())
r
:=
newHTTPRequest
(
generateApiUrl
(
m
,
deleteTagEndpoint
)
+
"/"
+
tag
)
r
.
setClient
(
m
.
Client
())
r
.
setBasicAuth
(
basicAuthUser
,
m
.
ApiKey
())
_
,
err
:=
makeDeleteRequest
(
r
)
return
err
}
vendor/github.com/mailgun/mailgun-go/unsubscribes.go
View file @
9fe70514
package
mailgun
import
(
"github.com/mbanzon/simplehttp"
"strconv"
)
...
...
@@ -15,14 +14,15 @@ type Unsubscription struct {
// GetUnsubscribes retrieves a list of unsubscriptions issued by recipients of mail from your domain.
// Zero is a valid list length.
func
(
mg
*
MailgunImpl
)
GetUnsubscribes
(
limit
,
skip
int
)
(
int
,
[]
Unsubscription
,
error
)
{
r
:=
simplehttp
.
N
ewHTTPRequest
(
generateApiUrl
(
mg
,
unsubscribesEndpoint
))
r
:=
n
ewHTTPRequest
(
generateApiUrl
(
mg
,
unsubscribesEndpoint
))
if
limit
!=
DefaultLimit
{
r
.
A
ddParameter
(
"limit"
,
strconv
.
Itoa
(
limit
))
r
.
a
ddParameter
(
"limit"
,
strconv
.
Itoa
(
limit
))
}
if
skip
!=
DefaultSkip
{
r
.
A
ddParameter
(
"skip"
,
strconv
.
Itoa
(
skip
))
r
.
a
ddParameter
(
"skip"
,
strconv
.
Itoa
(
skip
))
}
r
.
SetBasicAuth
(
basicAuthUser
,
mg
.
ApiKey
())
r
.
setClient
(
mg
.
Client
())
r
.
setBasicAuth
(
basicAuthUser
,
mg
.
ApiKey
())
var
envelope
struct
{
TotalCount
int
`json:"total_count"`
Items
[]
Unsubscription
`json:"items"`
...
...
@@ -34,8 +34,9 @@ func (mg *MailgunImpl) GetUnsubscribes(limit, skip int) (int, []Unsubscription,
// GetUnsubscribesByAddress retrieves a list of unsubscriptions by recipient address.
// Zero is a valid list length.
func
(
mg
*
MailgunImpl
)
GetUnsubscribesByAddress
(
a
string
)
(
int
,
[]
Unsubscription
,
error
)
{
r
:=
simplehttp
.
NewHTTPRequest
(
generateApiUrlWithTarget
(
mg
,
unsubscribesEndpoint
,
a
))
r
.
SetBasicAuth
(
basicAuthUser
,
mg
.
ApiKey
())
r
:=
newHTTPRequest
(
generateApiUrlWithTarget
(
mg
,
unsubscribesEndpoint
,
a
))
r
.
setClient
(
mg
.
Client
())
r
.
setBasicAuth
(
basicAuthUser
,
mg
.
ApiKey
())
var
envelope
struct
{
TotalCount
int
`json:"total_count"`
Items
[]
Unsubscription
`json:"items"`
...
...
@@ -46,11 +47,12 @@ func (mg *MailgunImpl) GetUnsubscribesByAddress(a string) (int, []Unsubscription
// Unsubscribe adds an e-mail address to the domain's unsubscription table.
func
(
mg
*
MailgunImpl
)
Unsubscribe
(
a
,
t
string
)
error
{
r
:=
simplehttp
.
NewHTTPRequest
(
generateApiUrl
(
mg
,
unsubscribesEndpoint
))
r
.
SetBasicAuth
(
basicAuthUser
,
mg
.
ApiKey
())
p
:=
simplehttp
.
NewUrlEncodedPayload
()
p
.
AddValue
(
"address"
,
a
)
p
.
AddValue
(
"tag"
,
t
)
r
:=
newHTTPRequest
(
generateApiUrl
(
mg
,
unsubscribesEndpoint
))
r
.
setClient
(
mg
.
Client
())
r
.
setBasicAuth
(
basicAuthUser
,
mg
.
ApiKey
())
p
:=
newUrlEncodedPayload
()
p
.
addValue
(
"address"
,
a
)
p
.
addValue
(
"tag"
,
t
)
_
,
err
:=
makePostRequest
(
r
,
p
)
return
err
}
...
...
@@ -59,8 +61,9 @@ func (mg *MailgunImpl) Unsubscribe(a, t string) error {
// If passing in an ID (discoverable from, e.g., GetUnsubscribes()), the e-mail address associated
// with the given ID will be removed.
func
(
mg
*
MailgunImpl
)
RemoveUnsubscribe
(
a
string
)
error
{
r
:=
simplehttp
.
NewHTTPRequest
(
generateApiUrlWithTarget
(
mg
,
unsubscribesEndpoint
,
a
))
r
.
SetBasicAuth
(
basicAuthUser
,
mg
.
ApiKey
())
r
:=
newHTTPRequest
(
generateApiUrlWithTarget
(
mg
,
unsubscribesEndpoint
,
a
))
r
.
setClient
(
mg
.
Client
())
r
.
setBasicAuth
(
basicAuthUser
,
mg
.
ApiKey
())
_
,
err
:=
makeDeleteRequest
(
r
)
return
err
}
vendor/github.com/mailgun/mailgun-go/webhooks.go
View file @
9fe70514
package
mailgun
import
(
"github.com/mbanzon/simplehttp"
)
// GetWebhooks returns the complete set of webhooks configured for your domain.
// Note that a zero-length mapping is not an error.
func
(
mg
*
MailgunImpl
)
GetWebhooks
()
(
map
[
string
]
string
,
error
)
{
r
:=
simplehttp
.
NewHTTPRequest
(
generateDomainApiUrl
(
mg
,
webhooksEndpoint
))
r
.
SetBasicAuth
(
basicAuthUser
,
mg
.
ApiKey
())
r
:=
newHTTPRequest
(
generateDomainApiUrl
(
mg
,
webhooksEndpoint
))
r
.
setClient
(
mg
.
Client
())
r
.
setBasicAuth
(
basicAuthUser
,
mg
.
ApiKey
())
var
envelope
struct
{
Webhooks
map
[
string
]
interface
{}
`json:"webhooks"`
}
...
...
@@ -27,42 +24,46 @@ func (mg *MailgunImpl) GetWebhooks() (map[string]string, error) {
// CreateWebhook installs a new webhook for your domain.
func
(
mg
*
MailgunImpl
)
CreateWebhook
(
t
,
u
string
)
error
{
r
:=
simplehttp
.
NewHTTPRequest
(
generateDomainApiUrl
(
mg
,
webhooksEndpoint
))
r
.
SetBasicAuth
(
basicAuthUser
,
mg
.
ApiKey
())
p
:=
simplehttp
.
NewUrlEncodedPayload
()
p
.
AddValue
(
"id"
,
t
)
p
.
AddValue
(
"url"
,
u
)
r
:=
newHTTPRequest
(
generateDomainApiUrl
(
mg
,
webhooksEndpoint
))
r
.
setClient
(
mg
.
Client
())
r
.
setBasicAuth
(
basicAuthUser
,
mg
.
ApiKey
())
p
:=
newUrlEncodedPayload
()
p
.
addValue
(
"id"
,
t
)
p
.
addValue
(
"url"
,
u
)
_
,
err
:=
makePostRequest
(
r
,
p
)
return
err
}
// DeleteWebhook removes the specified webhook from your domain's configuration.
func
(
mg
*
MailgunImpl
)
DeleteWebhook
(
t
string
)
error
{
r
:=
simplehttp
.
NewHTTPRequest
(
generateDomainApiUrl
(
mg
,
webhooksEndpoint
)
+
"/"
+
t
)
r
.
SetBasicAuth
(
basicAuthUser
,
mg
.
ApiKey
())
r
:=
newHTTPRequest
(
generateDomainApiUrl
(
mg
,
webhooksEndpoint
)
+
"/"
+
t
)
r
.
setClient
(
mg
.
Client
())
r
.
setBasicAuth
(
basicAuthUser
,
mg
.
ApiKey
())
_
,
err
:=
makeDeleteRequest
(
r
)
return
err
}
// GetWebhookByType retrieves the currently assigned webhook URL associated with the provided type of webhook.
func
(
mg
*
MailgunImpl
)
GetWebhookByType
(
t
string
)
(
string
,
error
)
{
r
:=
simplehttp
.
NewHTTPRequest
(
generateDomainApiUrl
(
mg
,
webhooksEndpoint
)
+
"/"
+
t
)
r
.
SetBasicAuth
(
basicAuthUser
,
mg
.
ApiKey
())
r
:=
newHTTPRequest
(
generateDomainApiUrl
(
mg
,
webhooksEndpoint
)
+
"/"
+
t
)
r
.
setClient
(
mg
.
Client
())
r
.
setBasicAuth
(
basicAuthUser
,
mg
.
ApiKey
())
var
envelope
struct
{
Webhook
struct
{
Url
*
string
`json:"url"`
Url
string
`json:"url"`
}
`json:"webhook"`
}
err
:=
getResponseFromJSON
(
r
,
&
envelope
)
return
*
envelope
.
Webhook
.
Url
,
err
return
envelope
.
Webhook
.
Url
,
err
}
// UpdateWebhook replaces one webhook setting for another.
func
(
mg
*
MailgunImpl
)
UpdateWebhook
(
t
,
u
string
)
error
{
r
:=
simplehttp
.
NewHTTPRequest
(
generateDomainApiUrl
(
mg
,
webhooksEndpoint
)
+
"/"
+
t
)
r
.
SetBasicAuth
(
basicAuthUser
,
mg
.
ApiKey
())
p
:=
simplehttp
.
NewUrlEncodedPayload
()
p
.
AddValue
(
"url"
,
u
)
r
:=
newHTTPRequest
(
generateDomainApiUrl
(
mg
,
webhooksEndpoint
)
+
"/"
+
t
)
r
.
setClient
(
mg
.
Client
())
r
.
setBasicAuth
(
basicAuthUser
,
mg
.
ApiKey
())
p
:=
newUrlEncodedPayload
()
p
.
addValue
(
"url"
,
u
)
_
,
err
:=
makePutRequest
(
r
,
p
)
return
err
}
vendor/github.com/mbanzon/simplehttp/.gitignore
deleted
100644 → 0
View file @
abd36d63
desktop.ini
vendor/github.com/mbanzon/simplehttp/.travis.yml
deleted
100644 → 0
View file @
abd36d63
language
:
go
go
:
-
1.3
-
1.4
env
:
-
GOARCH=amd64
-
GOARCH=386
script
:
-
go get github.com/mbanzon/callbackenv
-
go get github.com/mbanzon/dummyserver
-
go test
vendor/github.com/mbanzon/simplehttp/LICENSE
deleted
100644 → 0
View file @
abd36d63
Copyright (c) 2013-2014, Michael Banzon
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.
* Neither the name of the {organization} nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
vendor/github.com/mbanzon/simplehttp/README.md
deleted
100644 → 0
View file @
abd36d63
simplehttp
==========
[
![Build Status
](
https://travis-ci.org/mbanzon/simplehttp.png?branch=master
)
](https://travis-ci.org/mbanzon/simplehttp)
Simple HTTP library for Go.
This small library adds some utility functions for doing HTTP request and easilly gettings results as
structs from JSON and XML.
Supports alternative
`http.Client`
instances to support use on Google App Engine.
Examples are coming soon.
The code is released under a 3-clause BSD license. See the LICENSE file for more information.
\ No newline at end of file
vendor/github.com/mbanzon/simplehttp/helpers.go
deleted
100644 → 0
View file @
abd36d63
package
simplehttp
func
(
r
*
HTTPRequest
)
GetResponseFromJSON
(
v
interface
{})
error
{
response
,
err
:=
r
.
MakeGetRequest
()
if
err
!=
nil
{
return
err
}
return
response
.
ParseFromJSON
(
v
)
}
func
(
r
*
HTTPRequest
)
PostResponseFromJSON
(
payload
Payload
,
v
interface
{})
error
{
response
,
err
:=
r
.
MakePostRequest
(
payload
)
if
err
!=
nil
{
return
err
}
return
response
.
ParseFromJSON
(
v
)
}
vendor/github.com/mbanzon/simplehttp/helpers_test.go
deleted
100644 → 0
View file @
abd36d63
package
simplehttp
import
(
"encoding/json"
"encoding/xml"
"testing"
)
func
TestParsingGetFromJson
(
t
*
testing
.
T
)
{
tmp
:=
testStruct
{
Value1
:
"1"
,
Value2
:
"2"
,
Value3
:
"3"
,
}
data
,
err
:=
json
.
Marshal
(
tmp
)
if
err
!=
nil
{
t
.
Fail
()
}
server
.
SetNextResponse
(
data
)
request
:=
NewHTTPRequest
(
dummyurl
)
var
retVal
testStruct
err
=
request
.
GetResponseFromJSON
(
&
retVal
)
if
err
!=
nil
{
t
.
Fail
()
}
if
tmp
.
Value1
!=
retVal
.
Value1
{
t
.
Fail
()
}
if
tmp
.
Value2
!=
retVal
.
Value2
{
t
.
Fail
()
}
if
tmp
.
Value3
!=
retVal
.
Value3
{
t
.
Fail
()
}
}
func
TestFailingParsingGetFromJson
(
t
*
testing
.
T
)
{
request
:=
NewHTTPRequest
(
invalidurl
)
var
retVal
testStruct
err
:=
request
.
GetResponseFromJSON
(
&
retVal
)
if
err
==
nil
{
t
.
Fail
()
}
}
func
TestParsingPostFromJson
(
t
*
testing
.
T
)
{
tmp
:=
testStruct
{
Value1
:
"1"
,
Value2
:
"2"
,
Value3
:
"3"
,
}
data
,
err
:=
json
.
Marshal
(
tmp
)
if
err
!=
nil
{
t
.
Fail
()
}
server
.
SetNextResponse
(
data
)
request
:=
NewHTTPRequest
(
dummyurl
)
var
retVal
testStruct
err
=
request
.
PostResponseFromJSON
(
nil
,
&
retVal
)
if
err
!=
nil
{
t
.
Fail
()
}
if
tmp
.
Value1
!=
retVal
.
Value1
{
t
.
Fail
()
}
if
tmp
.
Value2
!=
retVal
.
Value2
{
t
.
Fail
()
}
if
tmp
.
Value3
!=
retVal
.
Value3
{
t
.
Fail
()
}
}
func
TestFailingParsingPostFromJson
(
t
*
testing
.
T
)
{
request
:=
NewHTTPRequest
(
invalidurl
)
var
retVal
testStruct
err
:=
request
.
PostResponseFromJSON
(
nil
,
&
retVal
)
if
err
==
nil
{
t
.
Fail
()
}
}
func
TestParsingGetFromXml
(
t
*
testing
.
T
)
{
tmp
:=
testStruct
{
Value1
:
"1"
,
Value2
:
"2"
,
Value3
:
"3"
,
}
data
,
err
:=
xml
.
Marshal
(
tmp
)
if
err
!=
nil
{
t
.
Fail
()
}
server
.
SetNextResponse
(
data
)
request
:=
NewHTTPRequest
(
dummyurl
)
var
retVal
testStruct
response
,
err
:=
request
.
MakeGetRequest
()
response
.
ParseFromXML
(
&
retVal
)
if
err
!=
nil
{
t
.
Fail
()
}
if
tmp
.
Value1
!=
retVal
.
Value1
{
t
.
Fail
()
}
if
tmp
.
Value2
!=
retVal
.
Value2
{
t
.
Fail
()
}
if
tmp
.
Value3
!=
retVal
.
Value3
{
t
.
Fail
()
}
}
vendor/github.com/mbanzon/simplehttp/json_utils.go
deleted
100644 → 0
View file @
abd36d63
package
simplehttp
import
(
"encoding/json"
"net/http"
)
func
GetJSONInput
(
r
*
http
.
Request
,
w
http
.
ResponseWriter
,
v
interface
{})
(
err
error
)
{
decoder
:=
json
.
NewDecoder
(
r
.
Body
)
err
=
decoder
.
Decode
(
v
)
if
err
!=
nil
{
http
.
Error
(
w
,
"Bad request."
,
http
.
StatusBadRequest
)
return
err
}
return
nil
}
func
OutputJSON
(
w
http
.
ResponseWriter
,
v
interface
{})
(
err
error
)
{
var
data
[]
byte
data
,
err
=
json
.
Marshal
(
v
)
if
err
!=
nil
{
http
.
Error
(
w
,
"Internal error."
,
http
.
StatusInternalServerError
)
return
err
}
w
.
Header
()
.
Add
(
"Content-Type"
,
"application/json"
)
_
,
err
=
w
.
Write
(
data
)
return
nil
}
vendor/github.com/mbanzon/simplehttp/parsing.go
deleted
100644 → 0
View file @
abd36d63
package
simplehttp
import
(
"encoding/json"
"encoding/xml"
)
// Parses the HTTPResponse as JSON to the given interface.
func
(
r
*
HTTPResponse
)
ParseFromJSON
(
v
interface
{})
error
{
return
json
.
Unmarshal
(
r
.
Data
,
v
)
}
func
(
r
*
HTTPResponse
)
ParseFromXML
(
v
interface
{})
error
{
return
xml
.
Unmarshal
(
r
.
Data
,
v
)
}
vendor/github.com/mbanzon/simplehttp/payload_test.go
deleted
100644 → 0
View file @
abd36d63
package
simplehttp
import
(
"bytes"
"github.com/mbanzon/callbackenv"
"io/ioutil"
"testing"
)
const
(
FILE_ENV
=
"SIMPLEHTTP_TEST_FILE"
)
func
TestFormDataPayloadPost
(
t
*
testing
.
T
)
{
payload
:=
NewFormDataPayload
()
payload
.
AddValue
(
"key"
,
"value"
)
buf
:=
&
bytes
.
Buffer
{}
buf
.
Write
([]
byte
(
"testing testing testing"
))
rc
:=
ioutil
.
NopCloser
(
buf
)
payload
.
AddReadCloser
(
"foo"
,
"bar"
,
rc
)
callbackenv
.
RequireEnv
(
FILE_ENV
,
func
(
file
string
)
{
payload
.
AddFile
(
"file"
,
file
)
},
nil
)
request
:=
NewHTTPRequest
(
dummyurl
)
request
.
MakePostRequest
(
payload
)
}
func
TestUrlEncodedPayloadPost
(
t
*
testing
.
T
)
{
payload
:=
NewUrlEncodedPayload
()
payload
.
AddValue
(
"key"
,
"value"
)
request
:=
NewHTTPRequest
(
dummyurl
)
request
.
MakePostRequest
(
payload
)
}
vendor/github.com/mbanzon/simplehttp/shorthand.go
deleted
100644 → 0
View file @
abd36d63
package
simplehttp
// Type to encapsulate basic authentication for requests.
type
BasicAuthentication
struct
{
User
string
Password
string
}
// Type to wrap requests.
type
Request
struct
{
Url
string
Authentication
BasicAuthentication
UserAgent
string
Data
[]
byte
}
func
createHttpRequest
(
req
Request
)
*
HTTPRequest
{
r
:=
NewHTTPRequest
(
req
.
Url
)
if
req
.
Authentication
.
User
!=
""
{
r
.
SetBasicAuth
(
req
.
Authentication
.
User
,
req
.
Authentication
.
Password
)
}
if
req
.
UserAgent
!=
""
{
r
.
AddHeader
(
"User-Agent"
,
req
.
UserAgent
)
}
return
r
}
func
(
r
Request
)
Get
()
(
int
,
[]
byte
,
error
)
{
req
:=
createHttpRequest
(
r
)
res
,
err
:=
req
.
MakeGetRequest
()
if
err
==
nil
{
return
res
.
Code
,
res
.
Data
,
err
}
else
{
return
-
1
,
nil
,
err
}
}
func
(
r
Request
)
Post
()
(
int
,
[]
byte
,
error
)
{
req
:=
createHttpRequest
(
r
)
var
payload
Payload
=
nil
if
r
.
Data
!=
nil
{
payload
=
NewRawPayload
(
r
.
Data
)
}
res
,
err
:=
req
.
MakePostRequest
(
payload
)
if
err
==
nil
{
return
res
.
Code
,
res
.
Data
,
err
}
else
{
return
-
1
,
nil
,
err
}
}
func
(
r
Request
)
Put
()
(
int
,
[]
byte
,
error
)
{
req
:=
createHttpRequest
(
r
)
var
payload
Payload
=
nil
if
r
.
Data
!=
nil
{
payload
=
NewRawPayload
(
r
.
Data
)
}
res
,
err
:=
req
.
MakePutRequest
(
payload
)
if
err
==
nil
{
return
res
.
Code
,
res
.
Data
,
err
}
else
{
return
-
1
,
nil
,
err
}
}
func
(
r
Request
)
Delete
()
(
int
,
[]
byte
,
error
)
{
req
:=
createHttpRequest
(
r
)
res
,
err
:=
req
.
MakeDeleteRequest
()
if
err
==
nil
{
return
res
.
Code
,
res
.
Data
,
err
}
else
{
return
-
1
,
nil
,
err
}
}
vendor/github.com/mbanzon/simplehttp/shorthand_test.go
deleted
100644 → 0
View file @
abd36d63
package
simplehttp
import
(
"testing"
)
func
TestShorthandFailingPayload
(
t
*
testing
.
T
)
{
Request
{
Url
:
dummyurl
,
Data
:
nil
,
}
.
Post
()
}
func
TestShorthandGet
(
t
*
testing
.
T
)
{
code
,
_
,
err
:=
Request
{
Url
:
dummyurl
,
UserAgent
:
"simplehttp go test"
,
}
.
Get
()
if
code
==
-
1
||
err
!=
nil
{
t
.
Fail
()
}
}
func
TestShorthandPost
(
t
*
testing
.
T
)
{
code
,
_
,
err
:=
Request
{
Url
:
dummyurl
,
Data
:
[]
byte
(
"foobar"
),
UserAgent
:
"simplehttp go test"
,
Authentication
:
BasicAuthentication
{
User
:
"test"
,
Password
:
"test"
,
},
}
.
Post
()
if
code
==
-
1
||
err
!=
nil
{
t
.
Fail
()
}
}
func
TestShorthandPut
(
t
*
testing
.
T
)
{
code
,
_
,
err
:=
Request
{
Url
:
dummyurl
,
Data
:
[]
byte
(
"foobar"
),
UserAgent
:
"simplehttp go test"
,
}
.
Put
()
if
code
==
-
1
||
err
!=
nil
{
t
.
Fail
()
}
}
func
TestShorthandDelete
(
t
*
testing
.
T
)
{
code
,
_
,
err
:=
Request
{
Url
:
dummyurl
,
UserAgent
:
"simplehttp go test"
,
}
.
Delete
()
if
code
==
-
1
||
err
!=
nil
{
t
.
Fail
()
}
}
func
TestFailingShorthandGet
(
t
*
testing
.
T
)
{
code
,
_
,
err
:=
Request
{
Url
:
invalidurl
,
}
.
Get
()
if
code
!=
-
1
||
err
==
nil
{
t
.
Fail
()
}
}
func
TestFailingShorthandPost
(
t
*
testing
.
T
)
{
code
,
_
,
err
:=
Request
{
Url
:
invalidurl
,
Data
:
[]
byte
(
"foobar"
),
}
.
Post
()
if
code
!=
-
1
||
err
==
nil
{
t
.
Fail
()
}
}
func
TestFailingShorthandPut
(
t
*
testing
.
T
)
{
code
,
_
,
err
:=
Request
{
Url
:
invalidurl
,
Data
:
[]
byte
(
"foobar"
),
}
.
Put
()
if
code
!=
-
1
||
err
==
nil
{
t
.
Fail
()
}
}
func
TestFailingShorthandDelete
(
t
*
testing
.
T
)
{
code
,
_
,
err
:=
Request
{
Url
:
invalidurl
,
}
.
Delete
()
if
code
!=
-
1
||
err
==
nil
{
t
.
Fail
()
}
}
vendor/github.com/mbanzon/simplehttp/simplehttp.go
deleted
100644 → 0
View file @
abd36d63
// Package simplehttp provides some simple methods and types to do
// HTTP queries with form values and parameters easily - especially
// if the returned result is expected to be JSON or XML.
//
// Author: Michael Banzon
package
simplehttp
import
(
"io"
"io/ioutil"
"net/http"
"net/url"
)
// Holds all information used to make a HTTP request.
type
HTTPRequest
struct
{
URL
string
Parameters
map
[
string
][]
string
Headers
map
[
string
]
string
BasicAuthUser
string
BasicAuthPassword
string
Client
*
http
.
Client
}
type
HTTPResponse
struct
{
Code
int
Data
[]
byte
}
// Creates a new HTTPRequest instance.
func
NewHTTPRequest
(
url
string
)
*
HTTPRequest
{
return
&
HTTPRequest
{
URL
:
url
,
Client
:
http
.
DefaultClient
}
}
// Adds a parameter to the generated query string.
func
(
r
*
HTTPRequest
)
AddParameter
(
name
,
value
string
)
{
if
r
.
Parameters
==
nil
{
r
.
Parameters
=
make
(
map
[
string
][]
string
)
}
r
.
Parameters
[
name
]
=
append
(
r
.
Parameters
[
name
],
value
)
}
// Adds a header that will be sent with the HTTP request.
func
(
r
*
HTTPRequest
)
AddHeader
(
name
,
value
string
)
{
// hej
if
r
.
Headers
==
nil
{
r
.
Headers
=
make
(
map
[
string
]
string
)
}
r
.
Headers
[
name
]
=
value
}
// Sets username and password for basic authentication.
func
(
r
*
HTTPRequest
)
SetBasicAuth
(
user
,
password
string
)
{
r
.
BasicAuthUser
=
user
r
.
BasicAuthPassword
=
password
}
func
(
r
*
HTTPRequest
)
MakeGetRequest
()
(
*
HTTPResponse
,
error
)
{
return
r
.
MakeRequest
(
"GET"
,
nil
)
}
func
(
r
*
HTTPRequest
)
MakePostRequest
(
payload
Payload
)
(
*
HTTPResponse
,
error
)
{
return
r
.
MakeRequest
(
"POST"
,
payload
)
}
func
(
r
*
HTTPRequest
)
MakePutRequest
(
payload
Payload
)
(
*
HTTPResponse
,
error
)
{
return
r
.
MakeRequest
(
"PUT"
,
payload
)
}
func
(
r
*
HTTPRequest
)
MakeDeleteRequest
()
(
*
HTTPResponse
,
error
)
{
return
r
.
MakeRequest
(
"DELETE"
,
nil
)
}
func
(
r
*
HTTPRequest
)
MakeRequest
(
method
string
,
payload
Payload
)
(
*
HTTPResponse
,
error
)
{
url
,
err
:=
r
.
generateUrlWithParameters
()
if
err
!=
nil
{
return
nil
,
err
}
var
body
io
.
Reader
if
payload
!=
nil
{
if
body
,
err
=
payload
.
GetPayloadBuffer
();
err
!=
nil
{
return
nil
,
err
}
}
else
{
body
=
nil
}
req
,
err
:=
http
.
NewRequest
(
method
,
url
,
body
)
if
err
!=
nil
{
return
nil
,
err
}
if
payload
!=
nil
&&
payload
.
GetContentType
()
!=
""
{
req
.
Header
.
Add
(
"Content-Type"
,
payload
.
GetContentType
())
}
if
r
.
BasicAuthUser
!=
""
&&
r
.
BasicAuthPassword
!=
""
{
req
.
SetBasicAuth
(
r
.
BasicAuthUser
,
r
.
BasicAuthPassword
)
}
for
header
,
value
:=
range
r
.
Headers
{
req
.
Header
.
Add
(
header
,
value
)
}
response
:=
HTTPResponse
{}
resp
,
err
:=
r
.
Client
.
Do
(
req
)
if
resp
!=
nil
{
response
.
Code
=
resp
.
StatusCode
}
if
err
!=
nil
{
return
nil
,
err
}
defer
resp
.
Body
.
Close
()
responseBody
,
err
:=
ioutil
.
ReadAll
(
resp
.
Body
)
if
err
!=
nil
{
return
nil
,
err
}
response
.
Data
=
responseBody
return
&
response
,
nil
}
// Generates the complete URL using GET parameters.
func
(
r
*
HTTPRequest
)
generateUrlWithParameters
()
(
string
,
error
)
{
url
,
err
:=
url
.
Parse
(
r
.
URL
)
if
err
!=
nil
{
return
""
,
err
}
q
:=
url
.
Query
()
if
r
.
Parameters
!=
nil
&&
len
(
r
.
Parameters
)
>
0
{
for
name
,
values
:=
range
r
.
Parameters
{
for
_
,
value
:=
range
values
{
q
.
Add
(
name
,
value
)
}
}
}
url
.
RawQuery
=
q
.
Encode
()
return
url
.
String
(),
nil
}
func
(
r
*
HTTPRequest
)
SetClient
(
c
*
http
.
Client
)
{
r
.
Client
=
c
}
vendor/github.com/mbanzon/simplehttp/simplehttp_test.go
deleted
100644 → 0
View file @
abd36d63
package
simplehttp
import
(
"github.com/mbanzon/dummyserver"
"log"
"strconv"
"testing"
)
var
(
server
*
dummyserver
.
DummyServer
dummyurl
string
invalidurl
string
)
type
testStruct
struct
{
Value1
string
`json:"value1" xml:"value1"`
Value2
string
`json:"value2" xml:"value2"`
Value3
string
`json:"value3" xml:"value3"`
}
func
init
()
{
server
=
dummyserver
.
NewRandomServer
()
go
func
()
{
err
:=
server
.
Start
()
log
.
Fatal
(
err
)
}()
dummyurl
=
"http://localhost:"
+
strconv
.
Itoa
(
server
.
GetPort
())
+
"/"
invalidurl
=
"invalid://invalid"
}
func
TestAddParameters
(
t
*
testing
.
T
)
{
request
:=
NewHTTPRequest
(
dummyurl
)
request
.
AddParameter
(
"p1"
,
"v1"
)
request
.
MakeGetRequest
()
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment