Skip to content
Prev Previous commit
Next Next commit
Add function GetDefaultBrandedLink
  • Loading branch information
frederikcreemers committed Oct 13, 2018
commit 05dabda4a749ac070dddfdc617a8eb9450655a39
16 changes: 13 additions & 3 deletions helpers/whitelabel/branded_links.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"github.com/sendgrid/sendgrid-go"
"strconv"
)

type brandedLinkRequest struct {
Expand Down Expand Up @@ -62,9 +63,8 @@ func GetBrandedLinks(key string) ([]BrandedLink, error) {
return links, err
}

// GetBrandedLink fetches a branded domain with a specific id.
func GetBrandedLink(key string, id int) (BrandedLink, error) {
cl := sendgrid.NewClientForEndpoint(key, fmt.Sprintf("%v/%v", linksEndpoint, id))
func getSingleBrandedLink(key, identifier string) (BrandedLink, error) {
cl := sendgrid.NewClientForEndpoint(key, linksEndpoint+"/"+identifier)
cl.Method = "GET"
var link BrandedLink

Expand All @@ -76,3 +76,13 @@ func GetBrandedLink(key string, id int) (BrandedLink, error) {
err = json.Unmarshal([]byte(resp.Body), &link)
return link, err
}

// GetBrandedLink fetches a branded domain with a specific id.
func GetBrandedLink(key string, id int64) (BrandedLink, error) {
return getSingleBrandedLink(key, strconv.FormatInt(id, 10))
}

// GetDefaultBrandedLink fetches the default branded link
func GetDefaultBrandedLink(key string) (BrandedLink, error) {
return getSingleBrandedLink(key, "default")
}