Skip to content

Commit

Permalink
Method names in the Mailgun interface are more consistent
Browse files Browse the repository at this point in the history
* Moved event structs into the 'event' package
  • Loading branch information
thrawn01 committed Jan 5, 2019
1 parent 29e0982 commit 87828f3
Show file tree
Hide file tree
Showing 28 changed files with 532 additions and 294 deletions.
8 changes: 4 additions & 4 deletions bounces.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ func (b Bounce) GetCode() (int, error) {
}
}

// GetBounces returns a complete set of bounces logged against the sender's domain, if any.
// ListBounces returns a complete set of bounces logged against the sender's domain, if any.
// The results include the total number of bounces (regardless of skip or limit settings),
// 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 (mg *MailgunImpl) GetBounces(limit, skip int) (int, []Bounce, error) {
func (mg *MailgunImpl) ListBounces(limit, skip int) (int, []Bounce, error) {
r := newHTTPRequest(generateApiUrl(mg, bouncesEndpoint))
if limit != -1 {
r.addParameter("limit", strconv.Itoa(limit))
Expand All @@ -74,8 +74,8 @@ func (mg *MailgunImpl) GetBounces(limit, skip int) (int, []Bounce, error) {
return len(response.Items), response.Items, nil
}

// GetSingleBounce retrieves a single bounce record, if any exist, for the given recipient address.
func (mg *MailgunImpl) GetSingleBounce(address string) (Bounce, error) {
// GetBounce retrieves a single bounce record, if any exist, for the given recipient address.
func (mg *MailgunImpl) GetBounce(address string) (Bounce, error) {
r := newHTTPRequest(generateApiUrl(mg, bouncesEndpoint) + "/" + address)
r.setClient(mg.Client())
r.setBasicAuth(basicAuthUser, mg.APIKey())
Expand Down
14 changes: 7 additions & 7 deletions bounces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func TestGetBounces(t *testing.T) {
mg, err := NewMailgunFromEnv()
ensure.Nil(t, err)

n, bounces, err := mg.GetBounces(-1, -1)
n, bounces, err := mg.ListBounces(-1, -1)
ensure.Nil(t, err)
ensure.DeepEqual(t, n, len(bounces))
}
Expand All @@ -24,7 +24,7 @@ func TestGetSingleBounce(t *testing.T) {
ensure.Nil(t, err)

exampleEmail := fmt.Sprintf("%s@%s", strings.ToLower(randomString(64, "")), domain)
_, err = mg.GetSingleBounce(exampleEmail)
_, err = mg.GetBounce(exampleEmail)
ensure.NotNil(t, err)

ure, ok := err.(*UnexpectedResponseError)
Expand All @@ -43,7 +43,7 @@ func TestAddDelBounces(t *testing.T) {
// First, basic sanity check.
// Fail early if we have bounces for a fictitious e-mail address.

n, _, err := mg.GetBounces(-1, -1)
n, _, err := mg.ListBounces(-1, -1)
ensure.Nil(t, err)
// Add the bounce for our address.

Expand All @@ -52,7 +52,7 @@ func TestAddDelBounces(t *testing.T) {

// We should now have one bounce listed when we query the API.

n, bounces, err := mg.GetBounces(-1, -1)
n, bounces, err := mg.ListBounces(-1, -1)
ensure.Nil(t, err)
if n == 0 {
t.Fatal("Expected at least one bounce for this domain.")
Expand All @@ -70,7 +70,7 @@ func TestAddDelBounces(t *testing.T) {
t.Fatalf("Expected bounce for address %s in list of bounces", exampleEmail)
}

bounce, err := mg.GetSingleBounce(exampleEmail)
bounce, err := mg.GetBounce(exampleEmail)
ensure.Nil(t, err)
if bounce.CreatedAt == "" {
t.Fatalf("Expected at least one bounce for %s", exampleEmail)
Expand All @@ -83,7 +83,7 @@ func TestAddDelBounces(t *testing.T) {

// Make sure we're back to the way we were.

n, bounces, err = mg.GetBounces(-1, -1)
n, bounces, err = mg.ListBounces(-1, -1)
ensure.Nil(t, err)

found = 0
Expand All @@ -98,6 +98,6 @@ func TestAddDelBounces(t *testing.T) {
t.Fatalf("Expected no bounce for address %s in list of bounces", exampleEmail)
}

_, err = mg.GetSingleBounce(exampleEmail)
_, err = mg.GetBounce(exampleEmail)
ensure.NotNil(t, err)
}
6 changes: 3 additions & 3 deletions cmd/mailgun/lists.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ func ListMailingList(parser *args.ArgParser, data interface{}) (int, error) {
}

// Create the tag iterator
it := mg.ListMailingLists(&mailgun.ListsOptions{
it := mg.ListMailingLists(&mailgun.ListOptions{
Limit: opts.Int("limit"),
})

var page []mailgun.List
var page []mailgun.MailingList
for it.Next(&page) {
for _, list := range page {
spew.Printf("%+v\n", list)
Expand Down Expand Up @@ -79,7 +79,7 @@ func ListMailingListMembers(parser *args.ArgParser, data interface{}) (int, erro
}

// Create the tag iterator
it := mg.ListMembers(opts.String("address"), &mailgun.ListMembersOptions{
it := mg.ListMembers(opts.String("address"), &mailgun.ListOptions{
Limit: opts.Int("limit"),
})

Expand Down
4 changes: 2 additions & 2 deletions credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ type Credential struct {
// ErrEmptyParam results occur when a required parameter is missing.
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) {
// ListCredentials returns the (possibly zero-length) list of credentials associated with your domain.
func (mg *MailgunImpl) ListCredentials(limit, skip int) (int, []Credential, error) {
r := newHTTPRequest(generateCredentialsUrl(mg, ""))
r.setClient(mg.Client())
if limit != DefaultLimit {
Expand Down
2 changes: 1 addition & 1 deletion credentials_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func TestGetCredentials(t *testing.T) {
mg, err := NewMailgunFromEnv()
ensure.Nil(t, err)

n, cs, err := mg.GetCredentials(DefaultLimit, DefaultSkip)
n, cs, err := mg.ListCredentials(DefaultLimit, DefaultSkip)
ensure.Nil(t, err)

t.Logf("Login\tCreated At\t\n")
Expand Down
19 changes: 8 additions & 11 deletions domains.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,16 @@ type DNSRecord struct {
}

type domainResponse struct {
Domain Domain `json:"domain"`
ReceivingDNSRecords []DNSRecord `json:"receiving_dns_records"`
SendingDNSRecords []DNSRecord `json:"sending_dns_records"`
Connection *DomainConnection `json:"connection,omitempty"`
Tracking *DomainTracking `json:"tracking,omitempty"`
TagLimits *TagLimits `json:"limits,omitempty"`
Domain Domain `json:"domain"`
ReceivingDNSRecords []DNSRecord `json:"receiving_dns_records"`
SendingDNSRecords []DNSRecord `json:"sending_dns_records"`
}

type domainConnectionResponse struct {
Connection DomainConnection `json:"connection"`
}

type DomainList struct {
type domainListResponse struct {
TotalCount int `json:"total_count"`
Items []Domain `json:"items"`
}
Expand Down Expand Up @@ -88,13 +85,13 @@ func (d Domain) GetCreatedAt() (t time.Time, err error) {
return
}

// GetDomains retrieves a set of domains from Mailgun.
// ListDomains retrieves a set of domains from Mailgun.
//
// Assuming no error, both the number of items retrieved and a slice of Domain instances.
// The number of items returned may be less than the specified limit, if it's specified.
// 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 (mg *MailgunImpl) GetDomains(limit, skip int) (int, []Domain, error) {
func (mg *MailgunImpl) ListDomains(limit, skip int) (int, []Domain, error) {
r := newHTTPRequest(generatePublicApiUrl(mg, domainsEndpoint))
r.setClient(mg.Client())
if limit != DefaultLimit {
Expand All @@ -105,7 +102,7 @@ func (mg *MailgunImpl) GetDomains(limit, skip int) (int, []Domain, error) {
}
r.setBasicAuth(basicAuthUser, mg.APIKey())

var list DomainList
var list domainListResponse
err := getResponseFromJSON(r, &list)
if err != nil {
return -1, nil, err
Expand All @@ -114,7 +111,7 @@ func (mg *MailgunImpl) GetDomains(limit, skip int) (int, []Domain, error) {
}

// Retrieve detailed information about the named domain.
func (mg *MailgunImpl) GetSingleDomain(domain string) (Domain, []DNSRecord, []DNSRecord, error) {
func (mg *MailgunImpl) GetDomain(domain string) (Domain, []DNSRecord, []DNSRecord, error) {
r := newHTTPRequest(generatePublicApiUrl(mg, domainsEndpoint) + "/" + domain)
r.setClient(mg.Client())
r.setBasicAuth(basicAuthUser, mg.APIKey())
Expand Down
8 changes: 4 additions & 4 deletions domains_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func TestGetDomains(t *testing.T) {
mg.SetAPIBase(server.URL())
ensure.Nil(t, err)

n, domains, err := mg.GetDomains(mailgun.DefaultLimit, mailgun.DefaultSkip)
n, domains, err := mg.ListDomains(mailgun.DefaultLimit, mailgun.DefaultSkip)
ensure.Nil(t, err)
ensure.DeepEqual(t, len(domains) != 0, true)

Expand All @@ -32,10 +32,10 @@ func TestGetSingleDomain(t *testing.T) {
mg.SetAPIBase(server.URL())
ensure.Nil(t, err)

_, domains, err := mg.GetDomains(mailgun.DefaultLimit, mailgun.DefaultSkip)
_, domains, err := mg.ListDomains(mailgun.DefaultLimit, mailgun.DefaultSkip)
ensure.Nil(t, err)

dr, rxDnsRecords, txDnsRecords, err := mg.GetSingleDomain(domains[0].Name)
dr, rxDnsRecords, txDnsRecords, err := mg.GetDomain(domains[0].Name)
ensure.Nil(t, err)
ensure.DeepEqual(t, len(rxDnsRecords) != 0, true)
ensure.DeepEqual(t, len(txDnsRecords) != 0, true)
Expand All @@ -53,7 +53,7 @@ func TestGetSingleDomainNotExist(t *testing.T) {
mg, err := mailgun.NewMailgunFromEnv()
mg.SetAPIBase(server.URL())
ensure.Nil(t, err)
_, _, _, err = mg.GetSingleDomain("mailgun.test")
_, _, _, err = mg.GetDomain("mailgun.test")
if err == nil {
t.Fatal("Did not expect a domain to exist")
}
Expand Down
Loading

0 comments on commit 87828f3

Please sign in to comment.