2016-06-12 22:39:00 +00:00
|
|
|
package footballdata_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/icedream/go-footballdata"
|
|
|
|
)
|
|
|
|
|
|
|
|
func Example() {
|
2016-06-26 10:57:14 +00:00
|
|
|
// Create client and tell it to use our API token
|
|
|
|
client := new(footballdata.Client)
|
2016-06-12 22:39:00 +00:00
|
|
|
|
2016-06-26 10:57:14 +00:00
|
|
|
// Tell it to use our API token (optional)
|
2016-06-25 10:29:32 +00:00
|
|
|
client.SetToken("<insert your api token here>")
|
2016-06-12 22:39:00 +00:00
|
|
|
|
|
|
|
// Get list of seasons...
|
|
|
|
seasons, err := client.SoccerSeasons().Do()
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// ...and print them
|
|
|
|
for _, season := range seasons {
|
|
|
|
fmt.Println(season.Id, season.Caption)
|
|
|
|
}
|
|
|
|
}
|
2016-06-26 10:02:53 +00:00
|
|
|
|
|
|
|
func ExampleClient() {
|
|
|
|
// Create client
|
|
|
|
client := footballdata.NewClient(http.DefaultClient)
|
|
|
|
|
2016-06-26 10:57:14 +00:00
|
|
|
// Tell it to use our API token (optional)
|
|
|
|
client.SetToken("<insert your api token here>")
|
|
|
|
|
|
|
|
// Do something with the client instance...
|
|
|
|
// Here we just fetch the listed soccer seasons on the API
|
2016-06-26 10:02:53 +00:00
|
|
|
seasons, err := client.SoccerSeasons().Do()
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
for _, season := range seasons {
|
|
|
|
fmt.Println(season.Id, season.Caption)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-26 10:57:14 +00:00
|
|
|
func ExampleClient_setTokenAndHttpClient() {
|
2016-06-26 10:02:53 +00:00
|
|
|
// Create client
|
2016-06-26 10:57:14 +00:00
|
|
|
client := new(footballdata.Client)
|
2016-06-26 10:02:53 +00:00
|
|
|
|
2016-06-26 10:57:14 +00:00
|
|
|
// If you have an API token, you can tell the Client instance to use it
|
2016-06-26 10:02:53 +00:00
|
|
|
client.SetToken("<insert your api token here>")
|
2016-06-26 10:57:14 +00:00
|
|
|
|
|
|
|
// The Client instance also allows you to use your own HTTP client configuration
|
|
|
|
client.SetHttpClient(&http.Client{
|
|
|
|
Transport: &http.Transport{
|
|
|
|
DisableCompression: true,
|
|
|
|
}})
|
2016-06-26 10:02:53 +00:00
|
|
|
}
|