commit
4f3888ff3c
6
apps.go
6
apps.go
|
@ -45,13 +45,13 @@ func RegisterApp(appConfig *AppConfig) (*Application, error) {
|
||||||
params.Set("scopes", appConfig.Scopes)
|
params.Set("scopes", appConfig.Scopes)
|
||||||
params.Set("website", appConfig.Website)
|
params.Set("website", appConfig.Website)
|
||||||
|
|
||||||
url, err := url.Parse(appConfig.Server)
|
u, err := url.Parse(appConfig.Server)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
url.Path = path.Join(url.Path, "/api/v1/apps")
|
u.Path = path.Join(u.Path, "/api/v1/apps")
|
||||||
|
|
||||||
req, err := http.NewRequest(http.MethodPost, url.String(), strings.NewReader(params.Encode()))
|
req, err := http.NewRequest(http.MethodPost, u.String(), strings.NewReader(params.Encode()))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
12
mastodon.go
12
mastodon.go
|
@ -24,14 +24,14 @@ type Client struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) doAPI(method string, uri string, params url.Values, res interface{}) error {
|
func (c *Client) doAPI(method string, uri string, params url.Values, res interface{}) error {
|
||||||
url, err := url.Parse(c.config.Server)
|
u, err := url.Parse(c.config.Server)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
url.Path = path.Join(url.Path, uri)
|
u.Path = path.Join(u.Path, uri)
|
||||||
|
|
||||||
var resp *http.Response
|
var resp *http.Response
|
||||||
req, err := http.NewRequest(method, url.String(), strings.NewReader(params.Encode()))
|
req, err := http.NewRequest(method, u.String(), strings.NewReader(params.Encode()))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -70,13 +70,13 @@ func (c *Client) Authenticate(username, password string) error {
|
||||||
params.Set("password", password)
|
params.Set("password", password)
|
||||||
params.Set("scope", "read write follow")
|
params.Set("scope", "read write follow")
|
||||||
|
|
||||||
url, err := url.Parse(c.config.Server)
|
u, err := url.Parse(c.config.Server)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
url.Path = path.Join(url.Path, "/oauth/token")
|
u.Path = path.Join(u.Path, "/oauth/token")
|
||||||
|
|
||||||
req, err := http.NewRequest(http.MethodPost, url.String(), strings.NewReader(params.Encode()))
|
req, err := http.NewRequest(http.MethodPost, u.String(), strings.NewReader(params.Encode()))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,11 +69,11 @@ func handleReader(ctx context.Context, q chan Event, r io.Reader) error {
|
||||||
|
|
||||||
// StreamingPublic return channel to read events.
|
// StreamingPublic return channel to read events.
|
||||||
func (c *Client) StreamingPublic(ctx context.Context) (chan Event, error) {
|
func (c *Client) StreamingPublic(ctx context.Context) (chan Event, error) {
|
||||||
url, err := url.Parse(c.config.Server)
|
u, err := url.Parse(c.config.Server)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
url.Path = path.Join(url.Path, "/api/v1/streaming/public")
|
u.Path = path.Join(u.Path, "/api/v1/streaming/public")
|
||||||
|
|
||||||
var resp *http.Response
|
var resp *http.Response
|
||||||
|
|
||||||
|
@ -82,7 +82,7 @@ func (c *Client) StreamingPublic(ctx context.Context) (chan Event, error) {
|
||||||
defer ctx.Done()
|
defer ctx.Done()
|
||||||
|
|
||||||
for {
|
for {
|
||||||
req, err := http.NewRequest(http.MethodGet, url.String(), nil)
|
req, err := http.NewRequest(http.MethodGet, u.String(), nil)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
req.Header.Set("Authorization", "Bearer "+c.config.AccessToken)
|
req.Header.Set("Authorization", "Bearer "+c.config.AccessToken)
|
||||||
resp, err = c.Do(req)
|
resp, err = c.Do(req)
|
||||||
|
|
Loading…
Reference in New Issue