Skip to content

Commit

Permalink
Moved the API version out of the base URL
Browse files Browse the repository at this point in the history
  • Loading branch information
vtopc committed Jan 2, 2025
1 parent 49c465a commit 81f1205
Show file tree
Hide file tree
Showing 18 changed files with 94 additions and 88 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ func main() {
// Create an instance of the Mailgun Client
mg := mailgun.NewMailgun(privateAPIKey)

//When you have an EU-domain, you must specify the endpoint:
//mg.SetAPIBase("https://api.eu.mailgun.net/v3")
// When you have an EU-domain, you must specify the endpoint:
// mg.SetAPIBase("https://api.eu.mailgun.net")

sender := "[email protected]"
subject := "Fancy subject!"
Expand Down
2 changes: 1 addition & 1 deletion analytics.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (mg *MailgunImpl) ListMetrics(opts MetricsOptions) (*MetricsIterator, error
opts.Pagination.Limit = 10
}

req := newHTTPRequest(generateApiUrl(mg, metricsEndpoint))
req := newHTTPRequest(generateApiUrl(mg, 1, metricsEndpoint))
req.setClient(mg.HTTPClient())
req.setBasicAuth(basicAuthUser, mg.APIKey())

Expand Down
12 changes: 6 additions & 6 deletions bounces.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type bouncesListResponse struct {
// 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) ListBounces(domain string, opts *ListOptions) *BouncesIterator {
r := newHTTPRequest(generateApiUrlWithDomain(mg, bouncesEndpoint, domain))
r := newHTTPRequest(generateApiV3UrlWithDomain(mg, bouncesEndpoint, domain))
r.setClient(mg.HTTPClient())
r.setBasicAuth(basicAuthUser, mg.APIKey())
if opts != nil {
Expand Down Expand Up @@ -147,7 +147,7 @@ func (ci *BouncesIterator) fetch(ctx context.Context, url string) error {

// GetBounce retrieves a single bounce record, if any exist, for the given recipient address.
func (mg *MailgunImpl) GetBounce(ctx context.Context, domain, address string) (Bounce, error) {
r := newHTTPRequest(generateApiUrlWithDomain(mg, bouncesEndpoint, domain) + "/" + address)
r := newHTTPRequest(generateApiV3UrlWithDomain(mg, bouncesEndpoint, domain) + "/" + address)
r.setClient(mg.HTTPClient())
r.setBasicAuth(basicAuthUser, mg.APIKey())

Expand All @@ -173,7 +173,7 @@ func (mg *MailgunImpl) GetBounce(ctx context.Context, domain, address string) (B
// Note that both code and error exist as strings, even though
// code will report as a number.
func (mg *MailgunImpl) AddBounce(ctx context.Context, domain, address, code, bounceError string) error {
r := newHTTPRequest(generateApiUrlWithDomain(mg, bouncesEndpoint, domain))
r := newHTTPRequest(generateApiV3UrlWithDomain(mg, bouncesEndpoint, domain))
r.setClient(mg.HTTPClient())
r.setBasicAuth(basicAuthUser, mg.APIKey())

Expand All @@ -191,7 +191,7 @@ func (mg *MailgunImpl) AddBounce(ctx context.Context, domain, address, code, bou

// Add Bounces adds a list of bounces to the bounce list
func (mg *MailgunImpl) AddBounces(ctx context.Context, domain string, bounces []Bounce) error {
r := newHTTPRequest(generateApiUrlWithDomain(mg, bouncesEndpoint, domain))
r := newHTTPRequest(generateApiV3UrlWithDomain(mg, bouncesEndpoint, domain))
r.setClient(mg.HTTPClient())
r.setBasicAuth(basicAuthUser, mg.APIKey())

Expand All @@ -203,7 +203,7 @@ func (mg *MailgunImpl) AddBounces(ctx context.Context, domain string, bounces []

// DeleteBounce removes all bounces associted with the provided e-mail address.
func (mg *MailgunImpl) DeleteBounce(ctx context.Context, domain, address string) error {
r := newHTTPRequest(generateApiUrlWithDomain(mg, bouncesEndpoint, domain) + "/" + address)
r := newHTTPRequest(generateApiV3UrlWithDomain(mg, bouncesEndpoint, domain) + "/" + address)
r.setClient(mg.HTTPClient())
r.setBasicAuth(basicAuthUser, mg.APIKey())
_, err := makeDeleteRequest(ctx, r)
Expand All @@ -212,7 +212,7 @@ func (mg *MailgunImpl) DeleteBounce(ctx context.Context, domain, address string)

// DeleteBounceList removes all bounces in the bounce list
func (mg *MailgunImpl) DeleteBounceList(ctx context.Context, domain string) error {
r := newHTTPRequest(generateApiUrlWithDomain(mg, bouncesEndpoint, domain))
r := newHTTPRequest(generateApiV3UrlWithDomain(mg, bouncesEndpoint, domain))
r.setClient(mg.HTTPClient())
r.setBasicAuth(basicAuthUser, mg.APIKey())
_, err := makeDeleteRequest(ctx, r)
Expand Down
32 changes: 16 additions & 16 deletions domains.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func (mg *MailgunImpl) ListDomains(opts *ListOptions) *DomainsIterator {
}
return &DomainsIterator{
mg: mg,
url: generateApiUrl(mg, domainsEndpoint),
url: generateApiUrl(mg, 3, domainsEndpoint),
domainsListResponse: domainsListResponse{TotalCount: -1},
limit: limit,
}
Expand Down Expand Up @@ -233,7 +233,7 @@ func (ri *DomainsIterator) fetch(ctx context.Context, skip, limit int) error {

// GetDomain retrieves detailed information about the named domain.
func (mg *MailgunImpl) GetDomain(ctx context.Context, domain string) (DomainResponse, error) {
r := newHTTPRequest(generateApiUrl(mg, domainsEndpoint) + "/" + domain)
r := newHTTPRequest(generateApiUrl(mg, 3, domainsEndpoint) + "/" + domain)
r.setClient(mg.HTTPClient())
r.setBasicAuth(basicAuthUser, mg.APIKey())
var resp DomainResponse
Expand All @@ -242,7 +242,7 @@ func (mg *MailgunImpl) GetDomain(ctx context.Context, domain string) (DomainResp
}

func (mg *MailgunImpl) VerifyDomain(ctx context.Context, domain string) (string, error) {
r := newHTTPRequest(generateApiUrl(mg, domainsEndpoint) + "/" + domain + "/verify")
r := newHTTPRequest(generateApiUrl(mg, 3, domainsEndpoint) + "/" + domain + "/verify")
r.setClient(mg.HTTPClient())
r.setBasicAuth(basicAuthUser, mg.APIKey())

Expand All @@ -254,7 +254,7 @@ func (mg *MailgunImpl) VerifyDomain(ctx context.Context, domain string) (string,

// VerifyAndReturnDomain verifies & retrieves detailed information about the named domain.
func (mg *MailgunImpl) VerifyAndReturnDomain(ctx context.Context, domain string) (DomainResponse, error) {
r := newHTTPRequest(generateApiUrl(mg, domainsEndpoint) + "/" + domain + "/verify")
r := newHTTPRequest(generateApiUrl(mg, 3, domainsEndpoint) + "/" + domain + "/verify")
r.setClient(mg.HTTPClient())
r.setBasicAuth(basicAuthUser, mg.APIKey())

Expand Down Expand Up @@ -282,7 +282,7 @@ type CreateDomainOptions struct {
// The wildcard parameter instructs Mailgun to treat all subdomains of this domain uniformly if true,
// and as different domains if false.
func (mg *MailgunImpl) CreateDomain(ctx context.Context, name string, opts *CreateDomainOptions) (DomainResponse, error) {
r := newHTTPRequest(generateApiUrl(mg, domainsEndpoint))
r := newHTTPRequest(generateApiUrl(mg, 3, domainsEndpoint))
r.setClient(mg.HTTPClient())
r.setBasicAuth(basicAuthUser, mg.APIKey())

Expand Down Expand Up @@ -319,17 +319,17 @@ func (mg *MailgunImpl) CreateDomain(ctx context.Context, name string, opts *Crea

// GetDomainConnection returns delivery connection settings for the defined domain
func (mg *MailgunImpl) GetDomainConnection(ctx context.Context, domain string) (DomainConnection, error) {
r := newHTTPRequest(generateApiUrl(mg, domainsEndpoint) + "/" + domain + "/connection")
r := newHTTPRequest(generateApiUrl(mg, 3, domainsEndpoint) + "/" + domain + "/connection")
r.setClient(mg.HTTPClient())
r.setBasicAuth(basicAuthUser, mg.APIKey())
var resp domainConnectionResponse
err := getResponseFromJSON(ctx, r, &resp)
return resp.Connection, err
}

// Updates the specified delivery connection settings for the defined domain
// UpdateDomainConnection updates the specified delivery connection settings for the defined domain
func (mg *MailgunImpl) UpdateDomainConnection(ctx context.Context, domain string, settings DomainConnection) error {
r := newHTTPRequest(generateApiUrl(mg, domainsEndpoint) + "/" + domain + "/connection")
r := newHTTPRequest(generateApiUrl(mg, 3, domainsEndpoint) + "/" + domain + "/connection")
r.setClient(mg.HTTPClient())
r.setBasicAuth(basicAuthUser, mg.APIKey())

Expand All @@ -342,7 +342,7 @@ func (mg *MailgunImpl) UpdateDomainConnection(ctx context.Context, domain string

// DeleteDomain instructs Mailgun to dispose of the named domain name
func (mg *MailgunImpl) DeleteDomain(ctx context.Context, name string) error {
r := newHTTPRequest(generateApiUrl(mg, domainsEndpoint) + "/" + name)
r := newHTTPRequest(generateApiUrl(mg, 3, domainsEndpoint) + "/" + name)
r.setClient(mg.HTTPClient())
r.setBasicAuth(basicAuthUser, mg.APIKey())
_, err := makeDeleteRequest(ctx, r)
Expand All @@ -351,7 +351,7 @@ func (mg *MailgunImpl) DeleteDomain(ctx context.Context, name string) error {

// GetDomainTracking returns tracking settings for a domain
func (mg *MailgunImpl) GetDomainTracking(ctx context.Context, domain string) (DomainTracking, error) {
r := newHTTPRequest(generateApiUrl(mg, domainsEndpoint) + "/" + domain + "/tracking")
r := newHTTPRequest(generateApiUrl(mg, 3, domainsEndpoint) + "/" + domain + "/tracking")
r.setClient(mg.HTTPClient())
r.setBasicAuth(basicAuthUser, mg.APIKey())
var resp domainTrackingResponse
Expand All @@ -360,7 +360,7 @@ func (mg *MailgunImpl) GetDomainTracking(ctx context.Context, domain string) (Do
}

func (mg *MailgunImpl) UpdateClickTracking(ctx context.Context, domain, active string) error {
r := newHTTPRequest(generateApiUrl(mg, domainsEndpoint) + "/" + domain + "/tracking/click")
r := newHTTPRequest(generateApiUrl(mg, 3, domainsEndpoint) + "/" + domain + "/tracking/click")
r.setClient(mg.HTTPClient())
r.setBasicAuth(basicAuthUser, mg.APIKey())

Expand All @@ -371,7 +371,7 @@ func (mg *MailgunImpl) UpdateClickTracking(ctx context.Context, domain, active s
}

func (mg *MailgunImpl) UpdateUnsubscribeTracking(ctx context.Context, domain, active, htmlFooter, textFooter string) error {
r := newHTTPRequest(generateApiUrl(mg, domainsEndpoint) + "/" + domain + "/tracking/unsubscribe")
r := newHTTPRequest(generateApiUrl(mg, 3, domainsEndpoint) + "/" + domain + "/tracking/unsubscribe")
r.setClient(mg.HTTPClient())
r.setBasicAuth(basicAuthUser, mg.APIKey())

Expand All @@ -384,7 +384,7 @@ func (mg *MailgunImpl) UpdateUnsubscribeTracking(ctx context.Context, domain, ac
}

func (mg *MailgunImpl) UpdateOpenTracking(ctx context.Context, domain, active string) error {
r := newHTTPRequest(generateApiUrl(mg, domainsEndpoint) + "/" + domain + "/tracking/open")
r := newHTTPRequest(generateApiUrl(mg, 3, domainsEndpoint) + "/" + domain + "/tracking/open")
r.setClient(mg.HTTPClient())
r.setBasicAuth(basicAuthUser, mg.APIKey())

Expand All @@ -396,7 +396,7 @@ func (mg *MailgunImpl) UpdateOpenTracking(ctx context.Context, domain, active st

// Update the DKIM selector for a domain
func (mg *MailgunImpl) UpdateDomainDkimSelector(ctx context.Context, domain, dkimSelector string) error {
r := newHTTPRequest(generateApiUrl(mg, domainsEndpoint) + "/" + domain + "/dkim_selector")
r := newHTTPRequest(generateApiUrl(mg, 3, domainsEndpoint) + "/" + domain + "/dkim_selector")
r.setClient(mg.HTTPClient())
r.setBasicAuth(basicAuthUser, mg.APIKey())

Expand All @@ -408,7 +408,7 @@ func (mg *MailgunImpl) UpdateDomainDkimSelector(ctx context.Context, domain, dki

// Update the CNAME used for tracking opens and clicks
func (mg *MailgunImpl) UpdateDomainTrackingWebPrefix(ctx context.Context, domain, webPrefix string) error {
r := newHTTPRequest(generateApiUrl(mg, domainsEndpoint) + "/" + domain + "/web_prefix")
r := newHTTPRequest(generateApiUrl(mg, 3, domainsEndpoint) + "/" + domain + "/web_prefix")
r.setClient(mg.HTTPClient())
r.setBasicAuth(basicAuthUser, mg.APIKey())

Expand All @@ -426,7 +426,7 @@ type UpdateDomainOptions struct {
// UpdateDomain updates a domain's attributes.
// Currently only the web_scheme update is supported, spam_action and wildcard are to be added.
func (mg *MailgunImpl) UpdateDomain(ctx context.Context, name string, opts *UpdateDomainOptions) error {
r := newHTTPRequest(generateApiUrl(mg, domainsEndpoint) + "/" + name)
r := newHTTPRequest(generateApiUrl(mg, 3, domainsEndpoint) + "/" + name)
r.setClient(mg.HTTPClient())
r.setBasicAuth(basicAuthUser, mg.APIKey())

Expand Down
2 changes: 1 addition & 1 deletion events.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type EventIterator struct {

// ListEvents creates a new iterator to fetch a page of events from the events api
func (mg *MailgunImpl) ListEvents(domain string, opts *ListEventOptions) *EventIterator {
url := generateApiUrlWithDomain(mg, eventsEndpoint, domain)
url := generateApiV3UrlWithDomain(mg, eventsEndpoint, domain)
return mg.listEvents(url, opts)
}

Expand Down
8 changes: 4 additions & 4 deletions exports.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type Export struct {

// Create an export based on the URL given
func (mg *MailgunImpl) CreateExport(ctx context.Context, url string) error {
r := newHTTPRequest(generateApiUrl(mg, exportsEndpoint))
r := newHTTPRequest(generateApiUrl(mg, 3, exportsEndpoint))
r.setClient(mg.HTTPClient())
r.setBasicAuth(basicAuthUser, mg.APIKey())

Expand All @@ -31,7 +31,7 @@ func (mg *MailgunImpl) CreateExport(ctx context.Context, url string) error {

// List all exports created within the past 24 hours
func (mg *MailgunImpl) ListExports(ctx context.Context, url string) ([]Export, error) {
r := newHTTPRequest(generateApiUrl(mg, exportsEndpoint))
r := newHTTPRequest(generateApiUrl(mg, 3, exportsEndpoint))
r.setClient(mg.HTTPClient())
if url != "" {
r.addParameter("url", url)
Expand All @@ -52,7 +52,7 @@ func (mg *MailgunImpl) ListExports(ctx context.Context, url string) ([]Export, e

// GetExport gets an export by id
func (mg *MailgunImpl) GetExport(ctx context.Context, id string) (Export, error) {
r := newHTTPRequest(generateApiUrl(mg, exportsEndpoint) + "/" + id)
r := newHTTPRequest(generateApiUrl(mg, 3, exportsEndpoint) + "/" + id)
r.setClient(mg.HTTPClient())
r.setBasicAuth(basicAuthUser, mg.APIKey())
var resp Export
Expand All @@ -63,7 +63,7 @@ func (mg *MailgunImpl) GetExport(ctx context.Context, id string) (Export, error)
// Download an export by ID. This will respond with a '302 Moved'
// with the Location header of temporary S3 URL if it is available.
func (mg *MailgunImpl) GetExportLink(ctx context.Context, id string) (string, error) {
r := newHTTPRequest(generateApiUrl(mg, exportsEndpoint) + "/" + id + "/download_url")
r := newHTTPRequest(generateApiUrl(mg, 3, exportsEndpoint) + "/" + id + "/download_url")
c := mg.HTTPClient()

// Ensure the client doesn't attempt to retry
Expand Down
10 changes: 5 additions & 5 deletions ips.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type okResp struct {

// ListIPS returns a list of IPs assigned to your account
func (mg *MailgunImpl) ListIPS(ctx context.Context, dedicated bool) ([]IPAddress, error) {
r := newHTTPRequest(generateApiUrl(mg, ipsEndpoint))
r := newHTTPRequest(generateApiUrl(mg, 3, ipsEndpoint))
r.setClient(mg.HTTPClient())
if dedicated {
r.addParameter("dedicated", "true")
Expand All @@ -40,7 +40,7 @@ func (mg *MailgunImpl) ListIPS(ctx context.Context, dedicated bool) ([]IPAddress

// GetIP returns information about the specified IP
func (mg *MailgunImpl) GetIP(ctx context.Context, ip string) (IPAddress, error) {
r := newHTTPRequest(generateApiUrl(mg, ipsEndpoint) + "/" + ip)
r := newHTTPRequest(generateApiUrl(mg, 3, ipsEndpoint) + "/" + ip)
r.setClient(mg.HTTPClient())
r.setBasicAuth(basicAuthUser, mg.APIKey())
var resp IPAddress
Expand All @@ -50,7 +50,7 @@ func (mg *MailgunImpl) GetIP(ctx context.Context, ip string) (IPAddress, error)

// ListDomainIPS returns a list of IPs currently assigned to the specified domain.
func (mg *MailgunImpl) ListDomainIPS(ctx context.Context, domain string) ([]IPAddress, error) {
r := newHTTPRequest(generateApiUrl(mg, domainsEndpoint) + "/" + domain + "/ips")
r := newHTTPRequest(generateApiUrl(mg, 3, domainsEndpoint) + "/" + domain + "/ips")
r.setClient(mg.HTTPClient())
r.setBasicAuth(basicAuthUser, mg.APIKey())

Expand All @@ -67,7 +67,7 @@ func (mg *MailgunImpl) ListDomainIPS(ctx context.Context, domain string) ([]IPAd

// Assign a dedicated IP to the domain specified.
func (mg *MailgunImpl) AddDomainIP(ctx context.Context, domain, ip string) error {
r := newHTTPRequest(generateApiUrl(mg, domainsEndpoint) + "/" + domain + "/ips")
r := newHTTPRequest(generateApiUrl(mg, 3, domainsEndpoint) + "/" + domain + "/ips")
r.setClient(mg.HTTPClient())
r.setBasicAuth(basicAuthUser, mg.APIKey())

Expand All @@ -79,7 +79,7 @@ func (mg *MailgunImpl) AddDomainIP(ctx context.Context, domain, ip string) error

// Unassign an IP from the domain specified.
func (mg *MailgunImpl) DeleteDomainIP(ctx context.Context, domain, ip string) error {
r := newHTTPRequest(generateApiUrl(mg, domainsEndpoint) + "/" + domain + "/ips/" + ip)
r := newHTTPRequest(generateApiUrl(mg, 3, domainsEndpoint) + "/" + domain + "/ips/" + ip)
r.setClient(mg.HTTPClient())
r.setBasicAuth(basicAuthUser, mg.APIKey())
_, err := makeDeleteRequest(ctx, r)
Expand Down
2 changes: 1 addition & 1 deletion limits.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ type TagLimits struct {

// GetTagLimits returns tracking settings for a domain
func (mg *MailgunImpl) GetTagLimits(ctx context.Context, domain string) (TagLimits, error) {
r := newHTTPRequest(generateApiUrl(mg, domainsEndpoint) + "/" + domain + "/limits/tag")
r := newHTTPRequest(generateApiUrl(mg, 3, domainsEndpoint) + "/" + domain + "/limits/tag")
r.setClient(mg.HTTPClient())
r.setBasicAuth(basicAuthUser, mg.APIKey())
var resp TagLimits
Expand Down
Loading

0 comments on commit 81f1205

Please sign in to comment.