sachaos / pixela-client-go

Pixela (https://pixe.la/) API client for Go

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

English | 日本語

pixela-client-go

Build Status MIT License GoDoc Go Report Card Version

Pixela API client for Go.

Cloning count

Documentation

https://godoc.org/github.com/ebc-2in2crc/pixela-client-go

Installation

$ go get -u github.com/ebc-2in2crc/pixela-client-go

Usage

package main

import (
	"log"
	
	"github.com/ebc-2in2crc/pixela-client-go"
)

func main() {
	client := pixela.NewClient("YOUR_NAME", "YOUR_TOKEN")

	// create new user
	result, err := client.CreateUser(true, true, "")
	if err != nil {
		log.Fatal(err)
	}
	if result.IsSuccess == false {
		log.Fatal(result.Message)
	}

	// create new slack channel
	detail := &pixela.SlackDetail{
		URL:         "https://hooks.slack.com/services/xxxx",
		UserName:    "slack-user-name",
		ChannelName: "slack-channel-name",
	}
	result, err = client.Channel().CreateSlackChannel("channel-id", "channel-name", detail)
	if err != nil {
		log.Fatal(err)
	}
	if result.IsSuccess == false {
		log.Fatal(result.Message)
	}

	// create new graph
	result, err = client.Graph("graph-id").Create(
		"graph-name",
		"commit",
		pixela.TypeInt,
		pixela.ColorShibafu,
		"Asia/Tokyo",
		pixela.SelfSufficientNone,
		false,
		false,
	)
	if err != nil {
		log.Fatal(err)
	}
	if result.IsSuccess == false {
		log.Fatal(result.Message)
	}

	// register value
	result, err = client.Pixel("graph-id").Create("20180915", "5", "")
	if err != nil {
		log.Fatal(err)
	}
	if result.IsSuccess == false {
		log.Fatal(result.Message)
	}

	// increment value
	result, err = client.Pixel("graph-id").Increment()
	if err != nil {
		log.Fatal(err)
	}
	if result.IsSuccess == false {
		log.Fatal(result.Message)
	}

	// create new notification rule
	result, err = client.Notification("graph-id").Create(
		"notification-id",
		"notification-name",
		pixela.TargetQuantity,
		pixela.ConditionGreaterThan,
		"3",
		"channel-id",
	)
	if err != nil {
		log.Fatal(err)
	}
	if result.IsSuccess == false {
		log.Fatal(result.Message)
	}

	// create new webhook
	webhook, err := client.Webhook().Create("graph-id", pixela.SelfSufficientIncrement)
	if err != nil {
		log.Fatal(err)
	}
	if webhook.IsSuccess == false {
		log.Fatal(webhook.Message)
	}

	// invoke webhook
	result, err = client.Webhook().Invoke(webhook.WebhookHash)
	if err != nil {
		log.Fatal(err)
	}
	if result.IsSuccess == false {
		log.Fatal(result.Message)
	}
}

Contribution

  1. Fork this repository
  2. Create your issue branch (git checkout -b issue/:id)
  3. Change codes
  4. Run test suite with the make test command and confirm that it passes
  5. Run make fmt
  6. Commit your changes (git commit -am 'Add some feature')
  7. Create new Pull Request

Licence

MIT

Author

ebc-2in2crc

About

Pixela (https://pixe.la/) API client for Go

License:MIT License


Languages

Language:Go 99.3%Language:Makefile 0.7%