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


Golang Client.QueryDeliverabilityMetrics方法代码示例

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


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

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


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