mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
* Add support to both the twitter and twitterstats modules for authenticating using both bearer tokens as well as consumer key + secret. * A bearer token is defaulted to if it's supplied * Add this support to both the twitterstats module as well as to the existing twitter module, modifying its functionality to re-use the same HTTP client and handle authentication upfront via oauth2
32 lines
498 B
Go
32 lines
498 B
Go
package twitter
|
|
|
|
import (
|
|
"bytes"
|
|
"net/http"
|
|
)
|
|
|
|
func Request(httpClient *http.Client, apiURL string) ([]byte, error) {
|
|
resp, err := httpClient.Get(apiURL)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer resp.Body.Close()
|
|
|
|
data, err := ParseBody(resp)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return data, err
|
|
}
|
|
|
|
func ParseBody(resp *http.Response) ([]byte, error) {
|
|
var buffer bytes.Buffer
|
|
_, err := buffer.ReadFrom(resp.Body)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return buffer.Bytes(), nil
|
|
}
|