1
0
mirror of https://github.com/taigrr/wtf synced 2026-04-01 05:28:48 -07:00
Files
wtf/modules/twitter/request.go
Casey Primozic a99af9a091 Support both bearer + consumer tokens for Twitter modules
* 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
2019-10-29 03:15:57 -07:00

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
}