Esempio n. 1
0
func Example() {
	apiKey := os.Getenv("API_KEY")
	if apiKey == "" {
		fmt.Fprintf(os.Stderr, "You must set your Campaign Monitor API key in the API_KEY environment variable to run example_test.go. (Skipping.)\n")
		return
	}

	authClient := &http.Client{
		Transport: &createsend.APIKeyAuthTransport{APIKey: apiKey},
	}

	c := createsend.NewAPIClient(authClient)
	clients, err := c.ListClients()
	if err != nil {
		fmt.Printf("Error listing clients: %s\n", err)
		os.Exit(1)
	}
	fmt.Printf("Found %d clients.\n", len(clients))
	for _, client := range clients {
		fmt.Printf(" - %s (ID: [%d-char ID])\n", client.Name, len(client.ClientID))
	}

	// This output will be different for each account.

	// sample output:
	// Found 1 clients.
	//  - Sourcegraph (ID: [32-char ID])
}
Esempio n. 2
0
func main() {
	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, "Usage: createsend command [OPTS] ARGS...\n")
		fmt.Fprintln(os.Stderr)
		fmt.Fprintln(os.Stderr, "The commands are:")
		fmt.Fprintln(os.Stderr)
		fmt.Fprintln(os.Stderr, "\tlist-clients")
		fmt.Fprintln(os.Stderr, "\tlist-lists       CLIENT")
		fmt.Fprintln(os.Stderr, "\tlists-for-email CLIENT EMAIL")
		fmt.Fprintln(os.Stderr, "\tlist-subscribers LIST (active|unconfirmed|unsubscribed|bounced|deleted)")
		fmt.Fprintln(os.Stderr, "\tget-subscriber   LIST EMAIL")
		fmt.Fprintln(os.Stderr, "\tadd-subscriber   LIST EMAIL")
		fmt.Fprintln(os.Stderr, "\tunsubscribe      LIST EMAIL")
		fmt.Fprintln(os.Stderr)
		fmt.Fprintln(os.Stderr)
		fmt.Fprintln(os.Stderr, "Common arguments:")
		fmt.Fprintln(os.Stderr)
		fmt.Fprintln(os.Stderr, "\tCLIENT:\ta client ID")
		fmt.Fprintln(os.Stderr, "\tLIST:\ta list ID")
		fmt.Fprintln(os.Stderr, "\tEMAIL:\temail address")
		fmt.Fprintln(os.Stderr)
		fmt.Fprintln(os.Stderr, "Run `createsend command -h` for more information.")
		flag.PrintDefaults()
		os.Exit(1)
	}

	flag.Parse()

	if flag.NArg() == 0 {
		flag.Usage()
	}
	log.SetFlags(0)

	apiKey := os.Getenv("CREATESEND_API_KEY")
	if apiKey == "" {
		log.Fatal("Error: you must set your Campaign Monitor API key in the CREATESEND_API_KEY environment variable.")
	}
	authClient := &http.Client{
		Transport: &createsend.APIKeyAuthTransport{APIKey: apiKey},
	}
	apiclient = createsend.NewAPIClient(authClient)

	if *verbose {
		apiclient.Log = log.New(os.Stderr, "createsend: ", 0)
	}

	subcmd := flag.Arg(0)
	remaining := flag.Args()[1:]
	switch subcmd {
	case "list-clients":
		listClients(remaining)
	case "list-lists":
		listLists(remaining)
	case "lists-for-email":
		listsForEmail(remaining)
	case "list-subscribers":
		listSubscribers(remaining)
	case "get-subscriber":
		getSubscriber(remaining)
	case "add-subscriber":
		addSubscriber(remaining)
	case "unsubscribe":
		unsubscribe(remaining)
	}
}