40 lines
838 B
Go
40 lines
838 B
Go
package realdebrid
|
|
|
|
import (
|
|
"context"
|
|
"io"
|
|
"net/http"
|
|
"net/url"
|
|
"strings"
|
|
)
|
|
|
|
func (c Client) createRequest(ctx context.Context, path, method string, body io.Reader) (*http.Request, error) {
|
|
req, err := http.NewRequestWithContext(ctx, method, "https://api.real-debrid.com/rest/1.0"+path, body)
|
|
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
req.Header.Set("Authorization", "Bearer "+c.Token)
|
|
|
|
return req, nil
|
|
}
|
|
|
|
func (c Client) createPostRequest(ctx context.Context, path string, data map[string]string) (*http.Request, error) {
|
|
values := url.Values{}
|
|
|
|
for key, value := range data {
|
|
values.Add(key, value)
|
|
}
|
|
|
|
req, err := c.createRequest(ctx, path, http.MethodPost, strings.NewReader(values.Encode()))
|
|
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
|
return req, nil
|
|
}
|