Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/mogita/go-fanfou

A Fanfou API library for Go
https://github.com/mogita/go-fanfou

api-client fanfou go golang oauth sdk sdk-go xauth

Last synced: 12 days ago
JSON representation

A Fanfou API library for Go

Awesome Lists containing this project

README

        



GO FANFOU


A Fanfou API library for Go



Software License
Travis
Go Report Card
Coverage Status
GoDoc

## Key Features

- Simple and intuitive endponits and error wrapping
- Struct and original JSON output
- Supports OAuth (safer) and XAuth (simpler)
- Covers all endpoints of [Fanfou API v1](https://github.com/mogita/FanFouAPIDoc/wiki) over HTTPS

## Installation

```
$ go get -u github.com/mogita/go-fanfou
```

## Usage

```go
package main

import "github.com/mogita/go-fanfou/fanfou"

func main() {
// ...
}
```

### Basic

To call an endpoint e.g. `/statuses/public_timeline`, you can call it like this:

```go
// Every API endpoint has the same return value structure
data, JSON, err := c.Statuses.PublicTimeline(&fanfou.StatusesOptParams{
Count: 10,
})
```

All optional parameter types starts with the resource's name. E.g. `Statuses` -> `StatusesOptParams`.

See the `examples` directory to learn how to authenticate the client instance before calling the endpoints.

### Error Handling

Errors default to the format as below:

```
POST http://api.fanfou.com/photos/upload.json: 400 上传照片失败
```

Meanwhile they can be asserted to extract the specific detail that you can use to handle the errors programmatically. Like this:

```go
_, _, err := c.Statuses.PublicTimeline(nil)

if err != nil {
if fanfouErr, ok := err.(*fanfou.ErrorResponse); ok {
// Will print only the error message text returned by Fanfou API
fmt.Printf("%s\n", fanfouErr.GetFanfouError())
return
}

// Will print the default error format
fmt.Println(err)
return
}
```

## Running the Examples

Check out the `examples` folder for working code snippets. You can run the examples with these commands to see how this library works:

### Standard OAuth

```shell
$ go run examples/oauth/oauth.go --consumerkey --consumersecret
```

### OOB OAuth

> OOB stands for "out of band"

```shell
$ go run examples/oauth_oob/oauth_oob.go --consumerkey --consumersecret
```

### XAuth

```shell
$ go run examples/xauth/xauth.go --consumerkey --consumersecret --username --password
```

### Upload Photos

```shell
$ go run examples/upload_photo/upload_photo.go --consumerkey --consumersecret --username --password
```

## Credits

- [oauth](https://godoc.org/github.com/mogita/oauth) (a fork of [mrjones/oauth](https://godoc.org/github.com/mrjones/oauth)) - OAuth 1.0 implementation in go (golang)
- [go-github](https://github.com/google/go-github) - This library mimics its structure. A copy of its LICENSE can be found here [go-github-LICENSE](./go-github-LICENSE)

## Contributing

Thank you very much for paying attention to this library. If you feel like helping improve it, please kindly make sure to follow the instructions:

Link the pre-commit hook which runs tests and go-fmt before committing

```
ln -s $PWD/pre-commit.sh .git/hooks/pre-commit
```

Always run tests before committing

```
go test ./...
```

You can also follow this [Trello board](https://trello.com/b/Z6XTVn7U/go-fanfou) if you're interested in the progress of this project and its sibling products.

## License

MIT © [mogita](https://github.com/mogita)