* Add NewFromToken convenience method to init client
Fixes#296
Adds a new convenience method for creating a new instance of `godo` from
just an API token.
Usage
Right now, it takes quite a few steps to create a `godo` instance:
```go
type TokenSource struct {
AccessToken string
}
func (t *TokenSource) Token() (*oauth2.Token, error) {
token := &oauth2.Token{
AccessToken: t.AccessToken,
}
return token, nil
}
func main() {
tokenSource := &TokenSource{
AccessToken: pat,
}
oauthClient := oauth2.NewClient(context.Background(), tokenSource)
client := godo.NewClient(oauthClient)
}
```
Now, it takes just a single line:
```go
func main() {
client := godo.NewFromToken("my-token")
}
```
The intention of this is to make initializing new clients easier. It
also has an additional benefit of not forcing users to have to import
the `golang.org/x/oauth2` dependency just to initialize new `godo`
instances.
* Add NewFromToken convenience method to init client
Fixes#296
Adds a new convenience method for creating a new instance of `godo` from
just an API token.
Usage
Right now, it takes quite a few steps to create a `godo` instance:
```go
type TokenSource struct {
AccessToken string
}
func (t *TokenSource) Token() (*oauth2.Token, error) {
token := &oauth2.Token{
AccessToken: t.AccessToken,
}
return token, nil
}
func main() {
tokenSource := &TokenSource{
AccessToken: pat,
}
oauthClient := oauth2.NewClient(context.Background(), tokenSource)
client := godo.NewClient(oauthClient)
}
```
Now, it takes just a single line:
```go
func main() {
client := godo.NewFromToken("my-token")
}
```
The intention of this is to make initializing new clients easier. It
also has an additional benefit of not forcing users to have to import
the `golang.org/x/oauth2` dependency just to initialize new `godo`
instances.
* Remove our own tokenSource type
It turns out you can use an `oauth2.Config` as a token source, so this
removes our own tokenSource type in favour of that one.
Co-authored-by: Zach Gershman <zachgersh@users.noreply.github.com>