Pixela API client for Go.
https://godoc.org/github.com/ebc-2in2crc/pixela4go
$ go get -u github.com/ebc-2in2crc/pixela4go
package main
import (
"context"
"log"
pixela "github.com/ebc-2in2crc/pixela4go"
)
func main() {
// Specify the number of retries if you want to retry when the API call is rejected.
// If you do not want to retry, you do not need to specify it.
pixela.RetryCount = 10
client := pixela.New("YOUR_NAME", "YOUR_TOKEN")
// Create new user
uci := &pixela.UserCreateInput{
AgreeTermsOfService: pixela.Bool(true),
NotMinor: pixela.Bool(true),
ThanksCode: pixela.String("thanks-code"),
}
result, err := client.User().CreateWithContext(context.Background(), uci)
if err != nil {
log.Fatal(err)
}
if result.IsSuccess == false {
log.Fatal(result.Message)
}
// Updates the profile information for the user
upi := &pixela.UserProfileUpdateInput{
DisplayName: pixela.String("display-name"),
GravatarIconEmail: pixela.String("gravatar-icon-email"),
Title: pixela.String("title"),
Timezone: pixela.String("Asia/Tokyo"),
AboutURL: pixela.String("https://github.com/ebc-2in2crc"),
ContributeURLs: []string{},
PinnedGraphID: pixela.String("pinned-graph-id"),
}
result, err = client.UserProfile().UpdateWithContext(context.Background(), upi)
if err != nil {
log.Fatal(err)
}
if result.IsSuccess == false {
log.Fatal(result.Message)
}
// Create new graph
gci := &pixela.GraphCreateInput{
ID: pixela.String("graph-id"),
Name: pixela.String("graph-name"),
Unit: pixela.String("commit"),
Type: pixela.String(pixela.GraphTypeInt),
Color: pixela.String(pixela.GraphColorShibafu),
TimeZone: pixela.String("Asia/Tokyo"),
SelfSufficient: pixela.String(pixela.GraphSelfSufficientIncrement),
IsSecret: pixela.Bool(true),
PublishOptionalData: pixela.Bool(true),
}
result, err = client.Graph().CreateWithContext(context.Background(), gci)
if err != nil {
log.Fatal(err)
}
if result.IsSuccess == false {
log.Fatal(result.Message)
}
// Register value
pci := &pixela.PixelCreateInput{
Date: pixela.String("20180915"),
Quantity: pixela.String("5"),
GraphID: pixela.String("graph-id"),
}
result, err = client.Pixel().CreateWithContext(context.Background(), pci)
if err != nil {
log.Fatal(err)
}
if result.IsSuccess == false {
log.Fatal(result.Message)
}
// Create new webhook
wci := &pixela.WebhookCreateInput{
GraphID: pixela.String("graph-id"),
Type: pixela.String(pixela.WebhookTypeIncrement),
}
webhook, err := client.Webhook().CreateWithContext(context.Background(), wci)
if err != nil {
log.Fatal(err)
}
if webhook.IsSuccess == false {
log.Fatal(webhook.Message)
}
// Invoke webhook
wii := &pixela.WebhookInvokeInput{WebhookHash: pixela.String("webhook-hash")}
result, err = client.Webhook().InvokeWithContext(context.Background(), wii)
if err != nil {
log.Fatal(err)
}
if result.IsSuccess == false {
log.Fatal(result.Message)
}
}
- Fork this repository
- Create your issue branch (
git checkout -b issue/:id
) - Change codes
- Run test suite with the
make test
command and confirm that it passes - Run
make fmt
- Commit your changes (
git commit -am 'Add some feature'
) - Create new Pull Request