本文整理汇总了Golang中github.com/SparkPost/gosparkpost.Client类的典型用法代码示例。如果您正苦于以下问题:Golang Client类的具体用法?Golang Client怎么用?Golang Client使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Client类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestAllEventsSamples
func TestAllEventsSamples(t *testing.T) {
if true {
// Temporarily disable test so TravisCI reports build success instead of test failure.
return
}
cfgMap, err := test.LoadConfig()
if err != nil {
t.Error(err)
return
}
cfg, err := sp.NewConfig(cfgMap)
if err != nil {
t.Error(err)
return
}
var client sp.Client
err = client.Init(cfg)
if err != nil {
t.Error(err)
return
}
e, err := client.EventSamples(nil)
if err != nil {
t.Error(err)
return
}
if len(*e) == 0 {
t.Error("expected non-empty result")
}
for _, ev := range *e {
switch event := ev.(type) {
case *events.Click, *events.Open, *events.GenerationFailure, *events.GenerationRejection,
*events.ListUnsubscribe, *events.LinkUnsubscribe, *events.PolicyRejection,
*events.RelayInjection, *events.RelayRejection, *events.RelayDelivery,
*events.RelayTempfail, *events.RelayPermfail, *events.SpamComplaint, *events.SMSStatus:
if len(fmt.Sprintf("%v", event)) == 0 {
t.Errorf("Empty output of %T.String()", event)
}
case *events.Bounce, *events.Delay, *events.Delivery, *events.Injection, *events.OutOfBand:
if len(events.ECLog(event)) == 0 {
t.Errorf("Empty output of %T.ECLog()", event)
}
case *events.Unknown:
t.Errorf("Uknown type: %v", event)
default:
t.Errorf("Uknown type: %T", event)
}
}
}
开发者ID:SparkPost,项目名称:gosparkpost,代码行数:57,代码来源:message_events_test.go
示例2: TestTemplates
func TestTemplates(t *testing.T) {
if true {
// Temporarily disable test so TravisCI reports build success instead of test failure.
return
}
cfgMap, err := test.LoadConfig()
if err != nil {
t.Error(err)
return
}
cfg, err := sp.NewConfig(cfgMap)
if err != nil {
t.Error(err)
return
}
var client sp.Client
err = client.Init(cfg)
if err != nil {
t.Error(err)
return
}
tlist, _, err := client.Templates()
if err != nil {
t.Error(err)
return
}
t.Error(fmt.Errorf("%s", tlist))
return
content := sp.Content{
Subject: "this is a test template",
// NB: deliberate syntax error
//Text: "text part of the test template {{a}",
Text: "text part of the test template",
From: map[string]string{
"name": "test name",
"email": "[email protected]",
},
}
template := &sp.Template{Content: content, Name: "test template"}
id, _, err := client.TemplateCreate(template)
if err != nil {
t.Error(err)
return
}
fmt.Printf("Created Template with id=%s\n", id)
_, err = client.TemplateDelete(id)
if err != nil {
t.Error(err)
return
}
fmt.Printf("Deleted Template with id=%s\n", id)
}
开发者ID:cbroglie,项目名称:gosparkpost,代码行数:59,代码来源:templates_test.go
示例3: TestMessageEvents
func TestMessageEvents(t *testing.T) {
if true {
// Temporarily disable test so TravisCI reports build success instead of test failure.
return
}
cfgMap, err := test.LoadConfig()
if err != nil {
t.Error(err)
return
}
cfg, err := sp.NewConfig(cfgMap)
if err != nil {
t.Error(err)
return
}
var client sp.Client
err = client.Init(cfg)
if err != nil {
t.Error(err)
return
}
//types := []string{"open", "click", "bounce"}
//e, err := client.EventSamples(&types)
e, err := client.EventSamples(nil)
if err != nil {
t.Error(err)
return
}
for _, ev := range *e {
//t.Error(fmt.Errorf("%s", ev))
switch event := ev.(type) {
case *events.Click, *events.Open, *events.GenerationFailure, *events.GenerationRejection,
*events.ListUnsubscribe, *events.LinkUnsubscribe, *events.PolicyRejection,
*events.RelayInjection, *events.RelayRejection, *events.RelayDelivery,
*events.RelayTempfail, *events.RelayPermfail, *events.SpamComplaint:
t.Error(fmt.Errorf("%s", event))
case *events.Bounce, *events.Delay, *events.Delivery, *events.Injection, *events.OutOfBand:
t.Error(fmt.Errorf("%s", events.ECLog(event)))
default:
t.Errorf("Unsupported type [%s]", reflect.TypeOf(ev))
}
}
}
开发者ID:cbroglie,项目名称:gosparkpost,代码行数:49,代码来源:message_events_test.go
示例4: doList
func doList(client *sp.Client, parameters map[string]string) {
e, err := client.ListWebhooks(parameters)
if err != nil {
log.Fatalf("ERROR: %s\n\nFor additional information try using `--verbose true`\n\n\n", err)
return
} else if e.Errors != nil {
log.Fatalf("ERROR: %s.\n\nFor additional information try using `--verbose true`\n\n\n", e.Errors)
return
} else {
for _, element := range e.Results {
listSummaryPrinter(element)
}
}
}
开发者ID:SparkPost,项目名称:sparkpost-cli,代码行数:15,代码来源:sp-webhook-cli.go
示例5: doItemQuery
func doItemQuery(client *sp.Client, parameters map[string]string, id string) {
e, err := client.QueryWebhook(id, parameters)
if err != nil {
log.Fatalf("ERROR: %s\n\nFor additional information try using `--verbose true`\n\n\n", err)
return
} else if e.Errors != nil {
log.Fatalf("ERROR: %s.\n\nFor additional information try using `--verbose true`\n\n\n", e.Errors)
return
} else {
// for _, element := range e.Results {
webhookDetailPrinter(e.Results)
// }
}
}
开发者ID:SparkPost,项目名称:sparkpost-cli,代码行数:15,代码来源:sp-webhook-cli.go
示例6: doStatus
func doStatus(client *sp.Client, parameters map[string]string, id string) {
e, err := client.WebhookStatus(id, parameters)
if err != nil {
log.Fatalf("ERROR: %s\n\nFor additional information try using `--verbose true`\n\n\n", err)
return
} else if e.Errors != nil {
log.Fatalf("ERROR: %s.\n\nFor additional information try using `--verbose true`\n\n\n", e.Errors)
return
} else {
for _, element := range e.Results {
webhookStatusPrinter(element)
}
}
}
开发者ID:SparkPost,项目名称:sparkpost-cli,代码行数:15,代码来源:sp-webhook-cli.go
示例7: TestFilteredEventsSamples
func TestFilteredEventsSamples(t *testing.T) {
if true {
// Temporarily disable test so TravisCI reports build success instead of test failure.
return
}
cfgMap, err := test.LoadConfig()
if err != nil {
t.Error(err)
return
}
cfg, err := sp.NewConfig(cfgMap)
if err != nil {
t.Error(err)
return
}
var client sp.Client
err = client.Init(cfg)
if err != nil {
t.Error(err)
return
}
types := []string{"open", "click", "bounce"}
e, err := client.EventSamples(&types)
if err != nil {
t.Error(err)
return
}
if len(*e) == 0 {
t.Error("expected non-empty result")
}
for _, ev := range *e {
switch event := ev.(type) {
case *events.Click, *events.Open, *events.Bounce:
// Expected, ok.
default:
t.Errorf("Unexpected type %T, should have been filtered out.", event)
}
}
}
开发者ID:SparkPost,项目名称:gosparkpost,代码行数:44,代码来源:message_events_test.go
示例8: TestRecipients
func TestRecipients(t *testing.T) {
if true {
// Temporarily disable test so TravisCI reports build success instead of test failure.
return
}
cfgMap, err := test.LoadConfig()
if err != nil {
t.Error(err)
return
}
cfg, err := sp.NewConfig(cfgMap)
if err != nil {
t.Error(err)
return
}
var client sp.Client
err = client.Init(cfg)
if err != nil {
t.Error(err)
return
}
list, _, err := client.RecipientLists()
if err != nil {
t.Error(err)
return
}
strs := make([]string, len(*list))
for idx, rl := range *list {
strs[idx] = rl.String()
}
t.Errorf("%s\n", strings.Join(strs, "\n"))
}
开发者ID:cbroglie,项目名称:gosparkpost,代码行数:36,代码来源:recipient_lists_test.go
示例9: main
func main() {
VALID_PARAMETERS := []string{
"timezone", "limit",
}
app := cli.NewApp()
app.Version = "0.0.1"
app.Name = "sparkpost-message-event-cli"
app.Usage = "SparkPost Message Event CLI"
app.Flags = []cli.Flag{
// Core Client Configuration
cli.StringFlag{
Name: "baseurl, u",
Value: "https://api.sparkpost.com",
Usage: "Optional baseUrl for SparkPost.",
EnvVar: "SPARKPOST_BASEURL",
},
cli.StringFlag{
Name: "apikey, k",
Value: "",
Usage: "Required SparkPost API key",
EnvVar: "SPARKPOST_API_KEY",
},
cli.StringFlag{
Name: "username",
Value: "",
Usage: "Username this is a special case it is more common to use apikey",
},
cli.StringFlag{
Name: "password, p",
Value: "",
Usage: "Username this is a special it is more common to use apikey",
},
cli.StringFlag{
Name: "verbose",
Value: "false",
Usage: "Dumps additional information to console",
},
// Webhook Parameters
cli.StringFlag{
Name: "command, c",
Value: "list",
Usage: "Optional one of list, query, status. Default is \"list\"",
},
cli.StringFlag{
Name: "timezone, tz",
Value: "",
Usage: "Optional Standard timezone identification string, defaults to UTC Example: America/New_York.",
},
cli.StringFlag{
Name: "id",
Value: "",
Usage: "Optional UUID identifying a webhook Example: 12affc24-f183-11e3-9234-3c15c2c818c2.",
},
cli.StringFlag{
Name: "limit",
Value: "",
Usage: "Optional Maximum number of results to return. Defaults to 1000. Example: 1000.",
},
}
app.Action = func(c *cli.Context) {
if c.String("baseurl") == "" {
log.Fatalf("Error: SparkPost BaseUrl must be set\n")
return
}
if c.String("apikey") == "" && c.String("username") == "" && c.String("password") == "" {
log.Fatalf("Error: SparkPost API key must be set\n")
return
}
isVerbose := false
if c.String("verbose") == "true" {
isVerbose = true
}
//println("SparkPost baseUrl: ", c.String("baseurl"))
cfg := &sp.Config{
BaseUrl: c.String("baseurl"),
ApiKey: c.String("apikey"),
Username: c.String("username"),
Password: c.String("password"),
ApiVersion: 1,
Verbose: isVerbose,
}
var client sp.Client
err := client.Init(cfg)
if err != nil {
log.Fatalf("SparkPost client init failed: %s\n", err)
}
parameters := make(map[string]string)
//.........这里部分代码省略.........
开发者ID:SparkPost,项目名称:sparkpost-cli,代码行数:101,代码来源:sp-webhook-cli.go
示例10: main
//.........这里部分代码省略.........
},
cli.StringFlag{
Name: "reason",
Value: "",
Usage: "Optional bounce/failure/rejection reason that will be matched using a wildcard (e.g., %%reason%%). Example: bounce.",
},
cli.StringFlag{
Name: "recipients",
Value: "",
Usage: "Optional Comma-delimited list of recipients to search. Example: [email protected]",
},
cli.StringFlag{
Name: "template_ids",
Value: "",
Usage: "Optional Comma-delimited list of template ID's to search. Example: templ-1234.",
},
cli.StringFlag{
Name: "timezone",
Value: "",
Usage: "Optional Standard timezone identification string. Example: America/New_York. Default: UTC",
},
cli.StringFlag{
Name: "to",
Value: "",
Usage: "Optional Datetime in format of YYYY-MM-DDTHH:MM. Example: 2016-02-10T00:00. Default: now.",
},
cli.StringFlag{
Name: "transmission_ids",
Value: "",
Usage: "Optional Comma-delimited list of transmission ID's to search (i.e. id generated during creation of a transmission). Example: 65832150921904138.",
},
cli.StringFlag{
Name: "subaccounts",
Value: "",
Usage: "Optional Comma-delimited list of subaccount ID's to search. Example: 101",
},
}
app.Action = func(c *cli.Context) {
if c.String("baseurl") == "" {
log.Fatalf("Error: SparkPost BaseUrl must be set\n")
return
}
if c.String("apikey") == "" && c.String("username") == "" && c.String("password") == "" {
log.Fatalf("Error: SparkPost API key must be set\n")
return
}
isVerbose := false
if c.String("verbose") == "true" {
isVerbose = true
}
//println("SparkPost baseUrl: ", c.String("baseurl"))
cfg := &sp.Config{
BaseUrl: c.String("baseurl"),
ApiKey: c.String("apikey"),
Username: c.String("username"),
Password: c.String("password"),
ApiVersion: 1,
Verbose: isVerbose,
}
var client sp.Client
err := client.Init(cfg)
if err != nil {
log.Fatalf("SparkPost client init failed: %s\n", err)
}
parameters := make(map[string]string)
for i, val := range VALID_PARAMETERS {
if c.String(VALID_PARAMETERS[i]) != "" {
parameters[val] = c.String(val)
}
}
e, err := client.MessageEvents(parameters)
//e, err := client.SearchMessageEvents(nil)
if err != nil {
log.Fatalf("Error: %s\n For additional information try using `--verbose true`\n", err)
return
} else {
for index, element := range e.Events {
log.Printf("%d\t %s%s", index, element, "\n")
//log.Printf("%d\t %v\n", index, element)
}
log.Printf("\t-------------------\n")
log.Printf("\tResult Count: %d\n", e.TotalCount)
}
}
app.Run(os.Args)
}
开发者ID:SparkPost,项目名称:sparkpost-cli,代码行数:101,代码来源:sp-message-events-cli.go
示例11: TestTransmissions
func TestTransmissions(t *testing.T) {
if true {
// Temporarily disable test so TravisCI reports build success instead of test failure.
return
}
cfgMap, err := test.LoadConfig()
if err != nil {
t.Error(err)
return
}
cfg, err := sp.NewConfig(cfgMap)
if err != nil {
t.Error(err)
return
}
var client sp.Client
err = client.Init(cfg)
if err != nil {
t.Error(err)
return
}
campaignID := "msys_smoke"
tlist, res, err := client.Transmissions(&campaignID, nil)
if err != nil {
t.Error(err)
return
}
t.Errorf("List: %d, %d entries", res.HTTP.StatusCode, len(tlist))
for _, tr := range tlist {
t.Errorf("%s: %s", tr.ID, tr.CampaignID)
}
// TODO: 404 from Transmission Create could mean either
// Recipient List or Content wasn't found - open doc ticket
// to make error message more specific
T := &sp.Transmission{
CampaignID: "msys_smoke",
ReturnPath: "[email protected]",
Recipients: []string{"[email protected]", "[email protected]"},
// Single-recipient Transmissions are transient - Retrieve will 404
//Recipients: []string{"[email protected]"},
Content: sp.Content{
Subject: "this is a test message",
HTML: "this is the <b>HTML</b> body of the test message",
From: map[string]string{
"name": "Dave Gray",
"email": "[email protected]",
},
},
Metadata: map[string]interface{}{
"binding": "example",
},
}
err = T.Validate()
if err != nil {
t.Error(err)
return
}
id, _, err := client.Send(T)
if err != nil {
t.Error(err)
return
}
t.Errorf("Transmission created with id [%s]", id)
tr, res, err := client.Transmission(id)
if err != nil {
t.Error(err)
return
}
if res != nil {
t.Errorf("Retrieve returned HTTP %s\n", res.HTTP.Status)
if len(res.Errors) > 0 {
for _, e := range res.Errors {
json, err := e.Json()
if err != nil {
t.Error(err)
}
t.Errorf("%s\n", json)
}
} else {
t.Errorf("Transmission retrieved: %s=%s\n", tr.ID, tr.State)
}
}
res, err = client.TransmissionDelete(id)
if err != nil {
t.Error(err)
return
}
t.Errorf("Delete returned HTTP %s\n%s\n", res.HTTP.Status, res.Body)
//.........这里部分代码省略.........
开发者ID:cbroglie,项目名称:gosparkpost,代码行数:101,代码来源:transmissions_test.go
示例12: main
func main() {
VALID_PARAMETERS := []string{
"from", "to", "types", "limit",
}
app := cli.NewApp()
app.Version = "0.0.1"
app.Name = "suppression-sparkpost-cli"
app.Usage = "SparkPost suppression list cli"
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "baseurl, u",
Value: "https://api.sparkpost.com",
Usage: "Optional baseUrl for SparkPost.",
EnvVar: "SPARKPOST_BASEURL",
},
cli.StringFlag{
Name: "apikey, k",
Value: "",
Usage: "Required SparkPost API key",
EnvVar: "SPARKPOST_API_KEY",
},
cli.StringFlag{
Name: "verbose",
Value: "false",
Usage: "Dumps additional information to console",
},
cli.StringFlag{
Name: "file, f",
Value: "",
Usage: "Mandrill blocklist CSV. See https://mandrill.zendesk.com/hc/en-us/articles/205582997",
},
cli.StringFlag{
Name: "command",
Value: "list",
Usage: "Optional one of list, retrieve, search, delete, mandrill, sendgrid",
},
cli.StringFlag{
Name: "recipient",
Value: "",
Usage: "Recipient email address. Example [email protected]",
},
// Search Parameters
cli.StringFlag{
Name: "from",
Value: "",
Usage: "Optional datetime the entries were last updated, in the format of YYYY-MM-DDTHH:mm:ssZ (2015-04-10T00:00:00)",
},
cli.StringFlag{
Name: "to",
Value: "",
Usage: "Optional datetime the entries were last updated, in the format YYYY-MM-DDTHH:mm:ssZ (2015-04-10T00:00:00)",
},
cli.StringFlag{
Name: "types",
Value: "",
Usage: "Optional types of entries to include in the search, i.e. entries with \"transactional\" and/or \"non_transactional\" keys set to true",
},
cli.StringFlag{
Name: "limit",
Value: "",
Usage: "Optional maximum number of results to return. Must be between 1 and 100000. Default value is 100000",
},
}
app.Action = func(c *cli.Context) {
if c.String("apikey") == "" {
log.Fatalf("Error: SparkPost API key must be set\n")
return
}
isVerbose := false
if c.String("verbose") == "true" {
isVerbose = true
}
cfg := &sp.Config{
BaseUrl: c.String("baseurl"),
ApiKey: c.String("apikey"),
ApiVersion: 1,
Verbose: isVerbose,
}
var client sp.Client
err := client.Init(cfg)
if err != nil {
log.Fatalf("SparkPost client init failed: %s\n", err)
return
}
parameters := make(map[string]string)
for i, val := range VALID_PARAMETERS {
if c.String(VALID_PARAMETERS[i]) != "" {
parameters[val] = c.String(val)
}
//.........这里部分代码省略.........
开发者ID:SparkPost,项目名称:sparkpost-cli,代码行数:101,代码来源:sp-suppression-list-cli.go
示例13: main
//.........这里部分代码省略.........
Name: "binding_groups",
Value: "",
Usage: "Optional comma-delimited list of binding groups to include (Note: SparkPost Elite only) Example: Transaction",
},
cli.StringFlag{
Name: "protocols",
Value: "",
Usage: "Optional comma-delimited list of protocols for filtering (Note: SparkPost Elite only) Example: smtp",
},
cli.StringFlag{
Name: "timezone",
Value: "",
Usage: "Standard timezone identification string, defaults to UTC Example: America/New_York.",
},
cli.StringFlag{
Name: "limit",
Value: "",
Usage: "Optional maximum number of results to return Example: 5",
},
cli.StringFlag{
Name: "order_by",
Value: "",
Usage: "Optional metric by which to order results Example: count_injected",
},
cli.StringFlag{
Name: "subaccounts",
Value: "",
Usage: "Optional Comma-delimited list of subaccount ID's to search. Example: 101",
},
}
app.Action = func(c *cli.Context) {
if c.String("baseurl") == "" {
log.Fatalf("Error: SparkPost BaseUrl must be set\n")
return
}
if c.String("apikey") == "" && c.String("username") == "" && c.String("password") == "" {
log.Fatalf("Error: SparkPost API key must be set\n")
return
}
isVerbose := false
if c.String("verbose") == "true" {
isVerbose = true
}
//println("SparkPost baseUrl: ", c.String("baseurl"))
cfg := &sp.Config{
BaseUrl: c.String("baseurl"),
ApiKey: c.String("apikey"),
Username: c.String("username"),
Password: c.String("password"),
ApiVersion: 1,
Verbose: isVerbose,
}
var client sp.Client
err := client.Init(cfg)
if err != nil {
log.Fatalf("SparkPost client init failed: %s\n", err)
}
parameters := make(map[string]string)
for i, val := range VALID_PARAMETERS {
if c.String(VALID_PARAMETERS[i]) != "" {
parameters[val] = c.String(val)
}
}
e, err := client.QueryDeliverabilityMetrics(c.String("command"), parameters)
if err != nil {
log.Fatalf("ERROR: %s\n\nFor additional information try using `--verbose true`\n\n\n", err)
return
} else if e.Errors != nil {
log.Fatalf("ERROR: %s.\n\nFor additional information try using `--verbose true`\n\n\n", e.Errors)
return
} else {
metrics := c.String("metrics")
log.Printf(metrics)
fields := strings.Split(metrics, ",")
// TODO: add an HTML output
csvHeaderPrinter(fields)
for _, element := range e.Results {
csvEntryPrinter(fields, c.String("command"), element)
}
}
}
app.Run(os.Args)
}
开发者ID:SparkPost,项目名称:sparkpost-cli,代码行数:101,代码来源:sp-deliverability-metrics-cli.go
示例14: main
func main() {
flag.Parse()
if *help {
flag.Usage()
os.Exit(0)
}
if len(to) <= 0 {
log.Fatal("SUCCESS: send mail to nobody!\n")
}
apiKey := os.Getenv("SPARKPOST_API_KEY")
if strings.TrimSpace(apiKey) == "" && *dryrun == false {
log.Fatal("FATAL: API key not found in environment!\n")
}
hasHtml := strings.TrimSpace(*htmlFlag) != ""
hasText := strings.TrimSpace(*textFlag) != ""
hasRFC822 := strings.TrimSpace(*rfc822Flag) != ""
hasSubs := strings.TrimSpace(*subsFlag) != ""
// rfc822 must be specified by itself, i.e. no text or html
if hasRFC822 && (hasHtml || hasText) {
log.Fatal("FATAL: --rfc822 cannot be combined with --html or --text!\n")
} else if !hasRFC822 && !hasHtml && !hasText {
log.Fatal("FATAL: must specify one of --html or --text!\n")
}
cfg := &sp.Config{ApiKey: apiKey}
if strings.TrimSpace(*url) != "" {
if !strings.HasPrefix(*url, "https://") {
log.Fatal("FATAL: base url must be https!\n")
}
cfg.BaseUrl = *url
}
if *httpDump {
cfg.Verbose = true
}
var sparky sp.Client
err := sparky.Init(cfg)
if err != nil {
log.Fatalf("SparkPost client init failed: %s\n", err)
}
content := sp.Content{
From: *from,
Subject: *subject,
}
if hasRFC822 {
// these are pulled from the raw message
content.From = nil
content.Subject = ""
if strings.HasPrefix(*rfc822Flag, "/") || strings.HasPrefix(*rfc822Flag, "./") {
// read file to get raw message
rfc822Bytes, err := ioutil.ReadFile(*rfc822Flag)
if err != nil {
log.Fatal(err)
}
content.EmailRFC822 = string(rfc822Bytes)
} else {
// raw message string passed on command line
content.EmailRFC822 = *rfc822Flag
}
}
if hasHtml {
if strings.HasPrefix(*htmlFlag, "/") || strings.HasPrefix(*htmlFlag, "./") {
// read file to get html
htmlBytes, err := ioutil.ReadFile(*htmlFlag)
if err != nil {
log.Fatal(err)
}
content.HTML = string(htmlBytes)
} else {
// html string passed on command line
content.HTML = *htmlFlag
}
}
if hasText {
if strings.HasPrefix(*textFlag, "/") || strings.HasPrefix(*textFlag, "./") {
// read file to get text
textBytes, err := ioutil.ReadFile(*textFlag)
if err != nil {
log.Fatal(err)
}
content.Text = string(textBytes)
} else {
// text string passed on command line
content.Text = *textFlag
}
}
if len(images) > 0 {
for _, imgStr := range images {
img := strings.SplitN(imgStr, ":", 3)
if len(img) != 3 {
//.........这里部分代码省略.........
开发者ID:SparkPost,项目名称:gosparkpost,代码行数:101,代码来源:sparks.go
示例15: TestTemplates
func TestTemplates(t *testing.T) {
if true {
// Temporarily disable test so TravisCI reports build success instead of test failure.
// NOTE: need travis to set sparkpost base urls etc, or mock http request
return
}
cfgMap, err := test.LoadConfig()
if err != nil {
t.Error(err)
return
}
cfg, err := sp.NewConfig(cfgMap)
if err != nil {
t.Error(err)
return
}
var client sp.Client
err = client.Init(cfg)
if err != nil {
t.Error(err)
return
}
tlist, _, err := client.Templates()
if err != nil {
t.Error(err)
return
}
t.Logf("templates listed: %+v", tlist)
content := sp.Content{
Subject: "this is a test template",
// NB: deliberate syntax error
//Text: "text part of the test template {{a}",
Text: "text part of the test template",
From: map[string]string{
"name": "test name",
"email": "[email protected]",
},
}
template := &sp.Template{Content: content, Name: "test template"}
id, _, err := client.TemplateCreate(template)
if err != nil {
t.Error(err)
return
}
fmt.Printf("Created Template with id=%s\n", id)
d := map[string]interface{}{}
res, err := client.TemplatePreview(id, &sp.PreviewOptions{d})
if err != nil {
t.Error(err)
return
}
fmt.Printf("Preview Template with id=%s and response %+v\n", id, res)
_, err = client.TemplateDelete(id)
if err != nil {
t.Error(err)
return
}
fmt.Printf("Deleted Template with id=%s\n", id)
}
开发者ID:SparkPost,项目名称:gosparkpost,代码行数:66,代码来源:templates_test.go
注:本文中的github.com/SparkPost/gosparkpost.Client类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论