예제 #1
0
func (m *mailgunImpl) GetStats(limit int, skip int, startDate time.Time, event ...string) (int, []Stat, error) {
	r := simplehttp.NewGetRequest(generateApiUrl(m, statsEndpoint))

	if limit != -1 {
		r.AddParameter("limit", strconv.Itoa(limit))
	}
	if skip != -1 {
		r.AddParameter("skip", strconv.Itoa(skip))
	}

	r.AddParameter("start-date", startDate.Format("2006-02-01"))

	for _, e := range event {
		r.AddParameter("event", e)
	}
	r.SetBasicAuth(basicAuthUser, m.ApiKey())

	var res statsEnvelope
	err := r.MakeJSONRequest(&res)
	if err != nil {
		return -1, nil, err
	} else {
		return res.TotalCount, res.Items, nil
	}
}
func (m *mailgunImpl) GetSingleComplaint(address string) (Complaint, error) {
	r := simplehttp.NewGetRequest(generateApiUrl(m, complaintsEndpoint) + "/" + address)
	var c Complaint
	err := r.MakeJSONRequest(&c)
	if err != nil {
		return Complaint{}, err
	}
	return c, nil
}
예제 #3
0
func (m *mailgunImpl) GetCampaigns() (int, []Campaign, error) {
	r := simplehttp.NewGetRequest(generateApiUrl(m, campaignsEndpoint))
	r.SetBasicAuth(basicAuthUser, m.ApiKey())
	var envelope campaignsEnvelope
	err := r.MakeJSONRequest(&envelope)
	if err != nil {
		return -1, nil, err
	}
	return envelope.TotalCount, envelope.Items, nil
}
예제 #4
0
func (m *mailgunImpl) GetSingleDomain(domain string) (Domain, []DNSRecord, []DNSRecord, error) {
	r := simplehttp.NewGetRequest(generatePublicApiUrl(domainsEndpoint) + "/" + domain)
	r.SetBasicAuth(basicAuthUser, m.ApiKey())
	var envelope singleDomainEnvelope
	err := r.MakeJSONRequest(&envelope)
	if err != nil {
		return Domain{}, nil, nil, err
	}
	return envelope.Domain, envelope.ReceivingDNSRecords, envelope.SendingDNSRecords, nil
}
예제 #5
0
func (m *mailgunImpl) GetSingleBounce(address string) (Bounce, error) {
	r := simplehttp.NewGetRequest(generateApiUrl(m, bouncesEndpoint) + "/" + address)
	r.SetBasicAuth(basicAuthUser, m.ApiKey())

	var response singleBounceEnvelope
	err := r.MakeJSONRequest(&response)
	if err != nil {
		return Bounce{}, err
	}

	return response.Bounce, nil
}
func (m *mailgunImpl) ParseAddresses(addresses ...string) ([]string, []string, error) {
	r := simplehttp.NewGetRequest(generatePublicApiUrl(addressParseEndpoint))
	r.AddParameter("addresses", strings.Join(addresses, ","))
	r.SetBasicAuth(basicAuthUser, m.PublicApiKey())

	var response AddressParseResult
	err := r.MakeJSONRequest(&response)
	if err != nil {
		return nil, nil, err
	}

	return response.Parsed, response.Unparseable, nil
}
func (m *mailgunImpl) ValidateEmail(email string) (EmailVerification, error) {
	r := simplehttp.NewGetRequest(generatePublicApiUrl(addressValidateEndpoint))
	r.AddParameter("address", email)
	r.SetBasicAuth(basicAuthUser, m.PublicApiKey())

	var response EmailVerification
	err := r.MakeJSONRequest(&response)
	if err != nil {
		return EmailVerification{}, err
	}

	return response, nil
}
func (m *mailgunImpl) GetComplaints(limit, skip int) (int, []Complaint, error) {
	r := simplehttp.NewGetRequest(generateApiUrl(m, complaintsEndpoint))
	if limit != -1 {
		r.AddParameter("limit", strconv.Itoa(limit))
	}
	if skip != -1 {
		r.AddParameter("skip", strconv.Itoa(skip))
	}
	var envelope complaintsEnvelope
	err := r.MakeJSONRequest(&envelope)
	if err != nil {
		return -1, nil, err
	}
	return envelope.TotalCount, envelope.Items, nil
}
예제 #9
0
func (m *mailgunImpl) GetDomains(limit, skip int) (int, []Domain, error) {
	r := simplehttp.NewGetRequest(generatePublicApiUrl(domainsEndpoint))
	if limit != -1 {
		r.AddParameter("limit", strconv.Itoa(limit))
	}
	if skip != -1 {
		r.AddParameter("skip", strconv.Itoa(skip))
	}
	r.SetBasicAuth(basicAuthUser, m.ApiKey())

	var envelope domainsEnvelope
	err := r.MakeJSONRequest(&envelope)
	if err != nil {
		return -1, nil, err
	}
	return envelope.TotalCount, envelope.Items, nil
}
예제 #10
0
func (m *mailgunImpl) GetBounces(limit, skip int) (int, []Bounce, error) {
	r := simplehttp.NewGetRequest(generateApiUrl(m, bouncesEndpoint))
	if limit != -1 {
		r.AddParameter("limit", strconv.Itoa(limit))
	}
	if skip != -1 {
		r.AddParameter("skip", strconv.Itoa(skip))
	}

	r.SetBasicAuth(basicAuthUser, m.ApiKey())

	var response bounceEnvelope
	err := r.MakeJSONRequest(&response)
	if err != nil {
		return -1, nil, err
	}

	return response.TotalCount, response.Items, nil
}
예제 #11
0
func (m *mailgunImpl) DeleteDomain(name string) error {
	r := simplehttp.NewGetRequest(generatePublicApiUrl(domainsEndpoint) + "/" + name)
	r.SetBasicAuth(basicAuthUser, m.ApiKey())
	_, err := r.MakeRequest()
	return err
}