From 43b274bbd29e832cfdf13f0a3d1730b1790088bd Mon Sep 17 00:00:00 2001 From: 178inaba <178inaba@users.noreply.github.com> Date: Thu, 27 Apr 2017 12:03:24 +0900 Subject: [PATCH] Add example --- example_test.go | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 example_test.go diff --git a/example_test.go b/example_test.go new file mode 100644 index 0000000..8eda8f3 --- /dev/null +++ b/example_test.go @@ -0,0 +1,42 @@ +package mastodon_test + +import ( + "context" + "fmt" + "log" + + "github.com/mattn/go-mastodon" +) + +func ExampleApplication_RegisterApp() { + app, err := mastodon.RegisterApp(context.Background(), &mastodon.AppConfig{ + Server: "https://mstdn.jp", + ClientName: "client-name", + Scopes: "read write follow", + Website: "https://github.com/mattn/go-mastodon", + }) + if err != nil { + log.Fatal(err) + } + fmt.Printf("client-id : %s\n", app.ClientID) + fmt.Printf("client-secret: %s\n", app.ClientSecret) +} + +func ExampleClient() { + c := mastodon.NewClient(&mastodon.Config{ + Server: "https://mstdn.jp", + ClientID: "client-id", + ClientSecret: "client-secret", + }) + err := c.Authenticate(context.Background(), "your-email", "your-password") + if err != nil { + log.Fatal(err) + } + timeline, err := c.GetTimelineHome(context.Background()) + if err != nil { + log.Fatal(err) + } + for i := len(timeline) - 1; i >= 0; i-- { + fmt.Println(timeline[i]) + } +}