~thrrgilag/woodstock

f6c03d77675e8e3bc62c55545cdb7b1b0cb53b85 — Morgan McMillian 2 years ago 13b37a0
Cleaned up README and added examples
5 files changed, 134 insertions(+), 33 deletions(-)

D CHANGELOG.md
M README.md
A examples/auth.go
A examples/post.go
A examples/stream.go
D CHANGELOG.md => CHANGELOG.md +0 -30
@@ 1,30 0,0 @@
# Changelog
All notable changes to this project will be documented in this file.  

The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).  

## [Unreleased]
### Added
- Message object now includes is_deleted and reply_to
- /files endpoint methods

### Fixed
- Updated endpoint for user and post interactions

## [0.1.1] - 2019-01-19 
### Added
- Unit tests for existing functions

### Fixed
- pnut.io API documentation urls in comments
- CreateMessage post with correct content-type
- typos in GetClient call
- SetMarker now calls correct method

## [0.1.0] - 2019-01-13
### Added
- Intial pre-release based on peanuts

[Unreleased]: https://gitlab.dreamfall.space/thrrgilag/woodstock/compare/0.1.1...HEAD
[0.1.1]: https://gitlab.dreamfall.space/thrrgilag/woodstock/tags/0.1.1
[0.1.0]: https://gitlab.dreamfall.space/thrrgilag/woodstock/tags/0.1.0

M README.md => README.md +51 -3
@@ 1,11 1,59 @@
# woodstock

A golang client library for pnut.io
A client library for pnut.io written in Go

Based on peanuts, originally written by yukkuri_sinai, this project aims to create a complete supported library.
[source code](https://git.sr.ht/~thrrgilag/woodstock) - 
[issue tracker](https://todo.sr.ht/~thrrgilag/woodstock) - 
[releases](https://git.sr.ht/~thrrgilag/woodstock/refs) - 
[mailing list](https://lists.sr.ht/~thrrgilag/woodstock)

### Installation
## Installation

```sh
go get git.sr.ht/~thrrgilag/woodstock
```

## Examples

New post
```go
package main

import (
    "fmt"
    "net/url"
    "git.sr.ht/~thrrgilag/woodstock"
)

func main() {
    client := woodstock.NewClient("<ClientID>","")
    client.SetAccessToken("<AccessToken>")
    text := "Hello pnut.io"
    v := url.Values{}
    v.Set("text", text)
    post, err := client.Post(v)
    if err != nil {
        fmt.Println(err)
    }
    fmt.Println(post.Data.Content.Text)
}
```

## Contributing

Send patches to 
[~thrrgilag/woodstock@lists.sr.ht](https://lists.sr.ht/~thrrgilag/woodstock).  

A nice tutorial on how to do that can be found at 
[git-send-email.io](https://git-send-email.io/).

Send bugs to 
[~thrrgilag/woodstock@todo.sr.ht](https://todo.sr.ht/~thrrgilag/woodstock).

## Discussion

Mailing List: 
[~thrrgilag/woodstock@lists.sr.ht](https://lists.sr.ht/~thrrgilag/woodstock) 

Chat Room: 
[#dev](https://thrrgilag.net/chat/dev/)

A examples/auth.go => examples/auth.go +29 -0
@@ 0,0 1,29 @@
package main

import (
	"fmt"

	"git.sr.ht/~thrrgilag/woodstock"
)

const (
	CLIENT_ID     = "client id"
	CLIENT_SECRET = "client secret"
	REDIRECT_URI  = "redirect uri"
)

func main() {
	client := woodstock.NewClient(CLIENT_ID, CLIENT_SECRET)
	fmt.Println(client.AuthURL(REDIRECT_URI, []string{"basic"}, "code"))
	fmt.Print("> ")

	var code string
	fmt.Scan(&code)

	result, err := client.AccessToken(code, REDIRECT_URI)
	if err != nil {
		fmt.Println(err)
		return
	}
	fmt.Println(result.AccessToken)
}

A examples/post.go => examples/post.go +26 -0
@@ 0,0 1,26 @@
package main

import (
	"fmt"
	"net/url"

	"git.sr.ht/~thrrgilag/woodstock"
)

const (
	CLIENT_ID     = "client id"
	CLIENT_SECRET = "client secret"
	ACCESS_TOKEN  = "access token"
)

func main() {
	client := woodstock.NewClient(CLIENT_ID, CLIENT_SECRET)
	client.SetAccessToken(ACCESS_TOKEN)
	v := url.Values{}
	v.Set("text", "Hello pnut.io")
	_, err := client.Post(v)
	if err != nil {
		fmt.Println(err)
		return
	}
}

A examples/stream.go => examples/stream.go +28 -0
@@ 0,0 1,28 @@
package main

import (
	"fmt"

	"git.sr.ht/~thrrgilag/woodstock"
)

const (
	CLIENT_ID     = "client id"
	CLIENT_SECRET = "client secret"
	ACCESS_TOKEN  = "access token"
)

func main() {
	client := woodstock.NewClient(CLIENT_ID, CLIENT_SECRET)
	client.SetAccessToken(ACCESS_TOKEN)
	result, err := client.GlobalStream()
	if err != nil {
		fmt.Println(err)
		return
	}
	fmt.Println("====")
	for _, post := range result.Data {
		fmt.Println(post.User.Username, ":", post.Content.Text)
		fmt.Println("====")
	}
}