示例#1
0
func ExampleBuilder_simple() {
	//To create a prowl client which is goo for sending out
	//message we will need an api key and the application string won't hurt
	client, err := prowl.NewBuilder().
		AddAPIKey(singleValidAPIKey).
		SetApplication("prowlgo Test").
		Build()
	if err != nil {
		fmt.Println(err)
	}

	//Let's see if we got what we expected...
	if len(client.Config().APIKeys) == 1 && client.Config().APIKeys[0] == singleValidAPIKey {
		fmt.Println("api key is ok")
	}
	if client.Config().Application == "prowlgo Test" {
		fmt.Println("application is ok")
	}
	if len(client.Config().ProviderKey) != 0 {
		fmt.Println("error " + client.Config().ProviderKey + ".")
	}
	if len(client.Config().Token) != 0 {
		fmt.Println("error " + client.Config().Token + ".")
	}
	if *client.Config().ToProwlLabel != prowl.DefaultToProwlLabel {
		fmt.Println("error " + *client.Config().ToProwlLabel + ".")
	}

	//output:
	//api key is ok
	//application is ok
}
示例#2
0
func ExampleBuilder_more() {
	toProwlLabel := "--> prowl"

	//A client which should also have just one
	client, err := prowl.NewBuilder().
		AddAPIKey(singleValidAPIKey).
		AddAPIKey(singleValidAPIKey).
		AddAllAPIKeys([]string{singleValidAPIKey, singleValidAPIKey}).
		SetProviderKey(aValidProviderKey).
		SetToken("0123456789012345678901234567890123456789").
		SetApplication("prowlgo Test").
		SetToProwlLabel(toProwlLabel).
		SetLogger(log.New(os.Stdout, "", 0)).
		Build()
	if err != nil {
		fmt.Println(err)
		return
	}

	if len(client.Config().APIKeys) != 1 {
		fmt.Printf("error config api key count %d", len(client.Config().APIKeys))
	}
	if client.Config().APIKeys[0] == singleValidAPIKey {
		fmt.Println("api key is ok")
	}
	if client.Config().Application == "prowlgo Test" {
		fmt.Println("application is ok")
	}
	if client.Config().ProviderKey == aValidProviderKey {
		fmt.Println("provider key is ok")
	}
	if client.Config().Token == "0123456789012345678901234567890123456789" {
		fmt.Println("token is ok")
	}
	if *client.Config().ToProwlLabel == toProwlLabel {
		fmt.Println("toProwlLabel is ok")
	}

	//output:
	//api key is ok
	//application is ok
	//provider key is ok
	//token is ok
	//toProwlLabel is ok
}