当前位置: 首页>>代码示例>>Golang>>正文


Golang Client.TransmissionDelete方法代码示例

本文整理汇总了Golang中github.com/SparkPost/gosparkpost.Client.TransmissionDelete方法的典型用法代码示例。如果您正苦于以下问题:Golang Client.TransmissionDelete方法的具体用法?Golang Client.TransmissionDelete怎么用?Golang Client.TransmissionDelete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/SparkPost/gosparkpost.Client的用法示例。


在下文中一共展示了Client.TransmissionDelete方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: 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


注:本文中的github.com/SparkPost/gosparkpost.Client.TransmissionDelete方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。