pixela

package module
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 15, 2018 License: MIT Imports: 7 Imported by: 0

README

pixela-go-sdk

pixela-go-sdk is unofficial api client for pixe.la

GoDoc

I need review. plz check code and make Issue and PullRequest!

example

package main

import (
	"fmt"
	"log"
	"time"

	"github.com/gainings/pixela"
)

func main() {
	user := "test-pixela-sdk"
	pass := "testtest"
	c := pixela.NewClient(user, pass)

	//regiser as new user
	err := c.RegisterUser("yes", "yes")
	if err != nil {
		log.Fatal(err)
	}
	defer c.DeleteUser()

	//create new graph
	gi := pixela.GraphInfo{
		ID:       "hoge1",
		Name:     "hogehoge",
		Unit:     "Commit",
		UnitType: "int",
		Color:    "shibafu",
	}
	err = c.CreateGraph(gi)
	if err != nil {
		log.Fatal(err)
	}

	items, err := c.ListGraph()
	if err != nil {
		log.Fatal(err)
	}
	for _, item := range items {
		fmt.Println(item)
	}

	//register pixel with quantity in graph
	today := time.Now().Format("20060102")
	fmt.Println(today)
	err = c.RegisterPixel("hoge1", today, "5")
	if err != nil {
		log.Fatal(err)
	}

	err = c.IncrementPixelQuantity("hoge1")
	if err != nil {
		log.Fatal(err)
	}

	err = c.DecrementPixelQuantity("hoge1")
	if err != nil {
		log.Fatal(err)
	}

	q, err := c.GetPixelQuantity(gi.ID, today)
	fmt.Println(q)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	HTTPClient http.Client
	URL        string
	UserName   string
	Token      string
}

Client is Client for access to pixe.la service

func NewClient

func NewClient(userName, token string) *Client

NewClient is return Cilent

func (Client) CreateGraph

func (c Client) CreateGraph(gi GraphInfo) error

CreateGraph create new graph

func (Client) DecrementPixelQuantity

func (c Client) DecrementPixelQuantity(id string) error

DecrementPixelQuantity decrement quantity of the Day

func (Client) DeleteGraph

func (c Client) DeleteGraph(id string) error

DeleteGraph delete specific graphs

func (Client) DeletePixelQuantity

func (c Client) DeletePixelQuantity(id, date string) error

DeletePixelQuantity dlete quantity for already registered pixel

func (Client) DeleteUser

func (c Client) DeleteUser() error

DeleteUser delete registered user

func (Client) GetGraph

func (c Client) GetGraph(id, date string) (string, error)

GetGraph get specific graphs's svg

func (Client) GetPixelQuantity

func (c Client) GetPixelQuantity(id, date string) (float64, error)

GetPixelQuantity get quantity from specific pixel

func (Client) IncrementPixelQuantity

func (c Client) IncrementPixelQuantity(id string) error

IncrementPixelQuantity increment quantity of the Day

func (Client) ListGraph

func (c Client) ListGraph() ([]GraphInfo, error)

ListGraph return User's graph info list

func (Client) RegisterPixel

func (c Client) RegisterPixel(id, date, quantity string) error

RegisterPixel Register specific pixel

func (Client) RegisterUser

func (c Client) RegisterUser(agree, notMinor string) error

RegisterUser is register new user

func (Client) UpdateGraph

func (c Client) UpdateGraph(gi GraphInfo) error

UpdateGraph update specific graphs's information

func (Client) UpdatePixelQuantity

func (c Client) UpdatePixelQuantity(id, date, quantity string) error

UpdatePixelQuantity update quantity for already registered pixel

func (*Client) UpdateToken

func (c *Client) UpdateToken(newToken string) error

UpdateToken update user's token

type GraphInfo

type GraphInfo struct {
	ID       string `json:"id"`
	Name     string `json:"name"`
	Unit     string `json:"unit"`
	UnitType string `json:"type"`
	Color    string `json:"color"`
}

GraphInfo is need info to create graph

func (GraphInfo) Validate

func (gi GraphInfo) Validate() error

Validate check info need create Graph

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL