refactor: update client package
- add a type for the parameters of the sendRequest method - contentType is now a parameter for the sendRequest method.
This commit is contained in:
parent
bad22ecd70
commit
2ccfdc4336
11 changed files with 447 additions and 56 deletions
|
@ -19,7 +19,15 @@ func (g *Client) VerifyCredentials() (model.Account, error) {
|
||||||
|
|
||||||
var account model.Account
|
var account model.Account
|
||||||
|
|
||||||
if err := g.sendRequest(http.MethodGet, url, nil, &account); err != nil {
|
params := requestParameters{
|
||||||
|
httpMethod: http.MethodGet,
|
||||||
|
url: url,
|
||||||
|
requestBody: nil,
|
||||||
|
contentType: "",
|
||||||
|
output: &account,
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := g.sendRequest(params); err != nil {
|
||||||
return model.Account{}, fmt.Errorf("received an error after sending the request to verify the credentials: %w", err)
|
return model.Account{}, fmt.Errorf("received an error after sending the request to verify the credentials: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,7 +39,15 @@ func (g *Client) GetAccount(accountURI string) (model.Account, error) {
|
||||||
|
|
||||||
var account model.Account
|
var account model.Account
|
||||||
|
|
||||||
if err := g.sendRequest(http.MethodGet, url, nil, &account); err != nil {
|
params := requestParameters{
|
||||||
|
httpMethod: http.MethodGet,
|
||||||
|
url: url,
|
||||||
|
requestBody: nil,
|
||||||
|
contentType: "",
|
||||||
|
output: &account,
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := g.sendRequest(params); err != nil {
|
||||||
return model.Account{}, fmt.Errorf("received an error after sending the request to get the account information: %w", err)
|
return model.Account{}, fmt.Errorf("received an error after sending the request to get the account information: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,7 +59,15 @@ func (g *Client) GetAccountRelationship(accountID string) (*model.AccountRelatio
|
||||||
|
|
||||||
var relationships []model.AccountRelationship
|
var relationships []model.AccountRelationship
|
||||||
|
|
||||||
if err := g.sendRequest(http.MethodGet, url, nil, &relationships); err != nil {
|
params := requestParameters{
|
||||||
|
httpMethod: http.MethodGet,
|
||||||
|
url: url,
|
||||||
|
requestBody: nil,
|
||||||
|
contentType: "",
|
||||||
|
output: &relationships,
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := g.sendRequest(params); err != nil {
|
||||||
return nil, fmt.Errorf(
|
return nil, fmt.Errorf(
|
||||||
"received an error after sending the request to get the account relationship: %w",
|
"received an error after sending the request to get the account relationship: %w",
|
||||||
err,
|
err,
|
||||||
|
@ -75,7 +99,15 @@ func (g *Client) FollowAccount(form FollowAccountForm) error {
|
||||||
requestBody := bytes.NewBuffer(data)
|
requestBody := bytes.NewBuffer(data)
|
||||||
url := g.Authentication.Instance + baseAccountsPath + "/" + form.AccountID + "/follow"
|
url := g.Authentication.Instance + baseAccountsPath + "/" + form.AccountID + "/follow"
|
||||||
|
|
||||||
if err := g.sendRequest(http.MethodPost, url, requestBody, nil); err != nil {
|
params := requestParameters{
|
||||||
|
httpMethod: http.MethodPost,
|
||||||
|
url: url,
|
||||||
|
requestBody: requestBody,
|
||||||
|
contentType: applicationJSON,
|
||||||
|
output: nil,
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := g.sendRequest(params); err != nil {
|
||||||
return fmt.Errorf("received an error after sending the follow request: %w", err)
|
return fmt.Errorf("received an error after sending the follow request: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,7 +117,15 @@ func (g *Client) FollowAccount(form FollowAccountForm) error {
|
||||||
func (g *Client) UnfollowAccount(accountID string) error {
|
func (g *Client) UnfollowAccount(accountID string) error {
|
||||||
url := g.Authentication.Instance + baseAccountsPath + "/" + accountID + "/unfollow"
|
url := g.Authentication.Instance + baseAccountsPath + "/" + accountID + "/unfollow"
|
||||||
|
|
||||||
if err := g.sendRequest(http.MethodPost, url, nil, nil); err != nil {
|
params := requestParameters{
|
||||||
|
httpMethod: http.MethodPost,
|
||||||
|
url: url,
|
||||||
|
requestBody: nil,
|
||||||
|
contentType: "",
|
||||||
|
output: nil,
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := g.sendRequest(params); err != nil {
|
||||||
return fmt.Errorf("received an error after sending the request to unfollow the account: %w", err)
|
return fmt.Errorf("received an error after sending the request to unfollow the account: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,7 +137,15 @@ func (g *Client) GetFollowers(accountID string, limit int) (model.AccountList, e
|
||||||
|
|
||||||
accounts := make([]model.Account, limit)
|
accounts := make([]model.Account, limit)
|
||||||
|
|
||||||
if err := g.sendRequest(http.MethodGet, url, nil, &accounts); err != nil {
|
params := requestParameters{
|
||||||
|
httpMethod: http.MethodGet,
|
||||||
|
url: url,
|
||||||
|
requestBody: nil,
|
||||||
|
contentType: "",
|
||||||
|
output: &accounts,
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := g.sendRequest(params); err != nil {
|
||||||
return model.AccountList{}, fmt.Errorf("received an error after sending the request to get the list of followers: %w", err)
|
return model.AccountList{}, fmt.Errorf("received an error after sending the request to get the list of followers: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,7 +162,15 @@ func (g *Client) GetFollowing(accountID string, limit int) (model.AccountList, e
|
||||||
|
|
||||||
accounts := make([]model.Account, limit)
|
accounts := make([]model.Account, limit)
|
||||||
|
|
||||||
if err := g.sendRequest(http.MethodGet, url, nil, &accounts); err != nil {
|
params := requestParameters{
|
||||||
|
httpMethod: http.MethodGet,
|
||||||
|
url: url,
|
||||||
|
requestBody: nil,
|
||||||
|
contentType: "",
|
||||||
|
output: &accounts,
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := g.sendRequest(params); err != nil {
|
||||||
return model.AccountList{}, fmt.Errorf("received an error after sending the request to get the list of followed accounts: %w", err)
|
return model.AccountList{}, fmt.Errorf("received an error after sending the request to get the list of followed accounts: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,7 +185,15 @@ func (g *Client) GetFollowing(accountID string, limit int) (model.AccountList, e
|
||||||
func (g *Client) BlockAccount(accountID string) error {
|
func (g *Client) BlockAccount(accountID string) error {
|
||||||
url := g.Authentication.Instance + baseAccountsPath + "/" + accountID + "/block"
|
url := g.Authentication.Instance + baseAccountsPath + "/" + accountID + "/block"
|
||||||
|
|
||||||
if err := g.sendRequest(http.MethodPost, url, nil, nil); err != nil {
|
params := requestParameters{
|
||||||
|
httpMethod: http.MethodPost,
|
||||||
|
url: url,
|
||||||
|
requestBody: nil,
|
||||||
|
contentType: "",
|
||||||
|
output: nil,
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := g.sendRequest(params); err != nil {
|
||||||
return fmt.Errorf("received an error after sending the request to block the account: %w", err)
|
return fmt.Errorf("received an error after sending the request to block the account: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,7 +203,15 @@ func (g *Client) BlockAccount(accountID string) error {
|
||||||
func (g *Client) UnblockAccount(accountID string) error {
|
func (g *Client) UnblockAccount(accountID string) error {
|
||||||
url := g.Authentication.Instance + baseAccountsPath + "/" + accountID + "/unblock"
|
url := g.Authentication.Instance + baseAccountsPath + "/" + accountID + "/unblock"
|
||||||
|
|
||||||
if err := g.sendRequest(http.MethodPost, url, nil, nil); err != nil {
|
params := requestParameters{
|
||||||
|
httpMethod: http.MethodPost,
|
||||||
|
url: url,
|
||||||
|
requestBody: nil,
|
||||||
|
contentType: "",
|
||||||
|
output: nil,
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := g.sendRequest(params); err != nil {
|
||||||
return fmt.Errorf("received an error after sending the request to unblock the account: %w", err)
|
return fmt.Errorf("received an error after sending the request to unblock the account: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -151,7 +223,15 @@ func (g *Client) GetBlockedAccounts(limit int) (model.AccountList, error) {
|
||||||
|
|
||||||
var accounts []model.Account
|
var accounts []model.Account
|
||||||
|
|
||||||
if err := g.sendRequest(http.MethodGet, url, nil, &accounts); err != nil {
|
params := requestParameters{
|
||||||
|
httpMethod: http.MethodGet,
|
||||||
|
url: url,
|
||||||
|
requestBody: nil,
|
||||||
|
contentType: "",
|
||||||
|
output: &accounts,
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := g.sendRequest(params); err != nil {
|
||||||
return model.AccountList{}, fmt.Errorf("received an error after sending the request to get the list of blocked accounts: %w", err)
|
return model.AccountList{}, fmt.Errorf("received an error after sending the request to get the list of blocked accounts: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -178,7 +258,15 @@ func (g *Client) SetPrivateNote(accountID, note string) error {
|
||||||
requestBody := bytes.NewBuffer(data)
|
requestBody := bytes.NewBuffer(data)
|
||||||
url := g.Authentication.Instance + baseAccountsPath + "/" + accountID + "/note"
|
url := g.Authentication.Instance + baseAccountsPath + "/" + accountID + "/note"
|
||||||
|
|
||||||
if err := g.sendRequest(http.MethodPost, url, requestBody, nil); err != nil {
|
params := requestParameters{
|
||||||
|
httpMethod: http.MethodPost,
|
||||||
|
url: url,
|
||||||
|
requestBody: requestBody,
|
||||||
|
contentType: applicationJSON,
|
||||||
|
output: nil,
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := g.sendRequest(params); err != nil {
|
||||||
return fmt.Errorf("received an error after sending the request to set the private note: %w", err)
|
return fmt.Errorf("received an error after sending the request to set the private note: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -190,7 +278,15 @@ func (g *Client) GetFollowRequests(limit int) (model.AccountList, error) {
|
||||||
|
|
||||||
var accounts []model.Account
|
var accounts []model.Account
|
||||||
|
|
||||||
if err := g.sendRequest(http.MethodGet, url, nil, &accounts); err != nil {
|
params := requestParameters{
|
||||||
|
httpMethod: http.MethodGet,
|
||||||
|
url: url,
|
||||||
|
requestBody: nil,
|
||||||
|
contentType: "",
|
||||||
|
output: &accounts,
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := g.sendRequest(params); err != nil {
|
||||||
return model.AccountList{}, fmt.Errorf("received an error after sending the request to get the list of follow requests: %w", err)
|
return model.AccountList{}, fmt.Errorf("received an error after sending the request to get the list of follow requests: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -205,7 +301,15 @@ func (g *Client) GetFollowRequests(limit int) (model.AccountList, error) {
|
||||||
func (g *Client) AcceptFollowRequest(accountID string) error {
|
func (g *Client) AcceptFollowRequest(accountID string) error {
|
||||||
url := g.Authentication.Instance + baseFollowRequestsPath + "/" + accountID + "/authorize"
|
url := g.Authentication.Instance + baseFollowRequestsPath + "/" + accountID + "/authorize"
|
||||||
|
|
||||||
if err := g.sendRequest(http.MethodPost, url, nil, nil); err != nil {
|
params := requestParameters{
|
||||||
|
httpMethod: http.MethodPost,
|
||||||
|
url: url,
|
||||||
|
requestBody: nil,
|
||||||
|
contentType: "",
|
||||||
|
output: nil,
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := g.sendRequest(params); err != nil {
|
||||||
return fmt.Errorf("received an error after sending the request to accept the follow request: %w", err)
|
return fmt.Errorf("received an error after sending the request to accept the follow request: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -215,7 +319,15 @@ func (g *Client) AcceptFollowRequest(accountID string) error {
|
||||||
func (g *Client) RejectFollowRequest(accountID string) error {
|
func (g *Client) RejectFollowRequest(accountID string) error {
|
||||||
url := g.Authentication.Instance + baseFollowRequestsPath + "/" + accountID + "/reject"
|
url := g.Authentication.Instance + baseFollowRequestsPath + "/" + accountID + "/reject"
|
||||||
|
|
||||||
if err := g.sendRequest(http.MethodPost, url, nil, nil); err != nil {
|
params := requestParameters{
|
||||||
|
httpMethod: http.MethodPost,
|
||||||
|
url: url,
|
||||||
|
requestBody: nil,
|
||||||
|
contentType: "",
|
||||||
|
output: nil,
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := g.sendRequest(params); err != nil {
|
||||||
return fmt.Errorf("received an error after sending the request to reject the follow request: %w", err)
|
return fmt.Errorf("received an error after sending the request to reject the follow request: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -227,7 +339,15 @@ func (g *Client) GetMutedAccounts(limit int) (model.AccountList, error) {
|
||||||
|
|
||||||
var accounts []model.Account
|
var accounts []model.Account
|
||||||
|
|
||||||
if err := g.sendRequest(http.MethodGet, url, nil, &accounts); err != nil {
|
params := requestParameters{
|
||||||
|
httpMethod: http.MethodGet,
|
||||||
|
url: url,
|
||||||
|
requestBody: nil,
|
||||||
|
contentType: "",
|
||||||
|
output: &accounts,
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := g.sendRequest(params); err != nil {
|
||||||
return model.AccountList{}, fmt.Errorf("received an error after sending the request to get the list of muted accounts: %w", err)
|
return model.AccountList{}, fmt.Errorf("received an error after sending the request to get the list of muted accounts: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -253,7 +373,15 @@ func (g *Client) MuteAccount(accountID string, form MuteAccountForm) error {
|
||||||
requestBody := bytes.NewBuffer(data)
|
requestBody := bytes.NewBuffer(data)
|
||||||
url := g.Authentication.Instance + baseAccountsPath + "/" + accountID + "/mute"
|
url := g.Authentication.Instance + baseAccountsPath + "/" + accountID + "/mute"
|
||||||
|
|
||||||
if err := g.sendRequest(http.MethodPost, url, requestBody, nil); err != nil {
|
params := requestParameters{
|
||||||
|
httpMethod: http.MethodPost,
|
||||||
|
url: url,
|
||||||
|
requestBody: requestBody,
|
||||||
|
contentType: applicationJSON,
|
||||||
|
output: nil,
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := g.sendRequest(params); err != nil {
|
||||||
return fmt.Errorf("received an error after sending the request to mute the account: %w", err)
|
return fmt.Errorf("received an error after sending the request to mute the account: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -263,7 +391,15 @@ func (g *Client) MuteAccount(accountID string, form MuteAccountForm) error {
|
||||||
func (g *Client) UnmuteAccount(accountID string) error {
|
func (g *Client) UnmuteAccount(accountID string) error {
|
||||||
url := g.Authentication.Instance + baseAccountsPath + "/" + accountID + "/unmute"
|
url := g.Authentication.Instance + baseAccountsPath + "/" + accountID + "/unmute"
|
||||||
|
|
||||||
if err := g.sendRequest(http.MethodPost, url, nil, nil); err != nil {
|
params := requestParameters{
|
||||||
|
httpMethod: http.MethodPost,
|
||||||
|
url: url,
|
||||||
|
requestBody: nil,
|
||||||
|
contentType: "",
|
||||||
|
output: nil,
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := g.sendRequest(params); err != nil {
|
||||||
return fmt.Errorf("received an error after sending the request to unmute the account: %w", err)
|
return fmt.Errorf("received an error after sending the request to unmute the account: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -295,7 +431,15 @@ func (g *Client) GetAccountStatuses(form GetAccountStatusesForm) (*model.StatusL
|
||||||
|
|
||||||
var statuses []model.Status
|
var statuses []model.Status
|
||||||
|
|
||||||
if err := g.sendRequest(http.MethodGet, url, nil, &statuses); err != nil {
|
params := requestParameters{
|
||||||
|
httpMethod: http.MethodGet,
|
||||||
|
url: url,
|
||||||
|
requestBody: nil,
|
||||||
|
contentType: "",
|
||||||
|
output: &statuses,
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := g.sendRequest(params); err != nil {
|
||||||
return nil, fmt.Errorf("received an error after sending the request to get the account's statuses: %w", err)
|
return nil, fmt.Errorf("received an error after sending the request to get the account's statuses: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,10 @@ import (
|
||||||
"codeflow.dananglin.me.uk/apollo/enbas/internal/config"
|
"codeflow.dananglin.me.uk/apollo/enbas/internal/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
applicationJSON string = "application/json; charset=utf-8"
|
||||||
|
)
|
||||||
|
|
||||||
type Client struct {
|
type Client struct {
|
||||||
Authentication config.Credentials
|
Authentication config.Credentials
|
||||||
HTTPClient http.Client
|
HTTPClient http.Client
|
||||||
|
@ -94,17 +98,28 @@ func (g *Client) DownloadMedia(url, path string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *Client) sendRequest(method string, url string, requestBody io.Reader, object any) error {
|
type requestParameters struct {
|
||||||
|
httpMethod string
|
||||||
|
url string
|
||||||
|
contentType string
|
||||||
|
requestBody io.Reader
|
||||||
|
output any
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g *Client) sendRequest(params requestParameters) error {
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), g.Timeout)
|
ctx, cancel := context.WithTimeout(context.Background(), g.Timeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
request, err := http.NewRequestWithContext(ctx, method, url, requestBody)
|
request, err := http.NewRequestWithContext(ctx, params.httpMethod, params.url, params.requestBody)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to create the HTTP request: %w", err)
|
return fmt.Errorf("unable to create the HTTP request: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
request.Header.Set("Content-Type", "application/json; charset=utf-8")
|
if params.contentType != "" {
|
||||||
request.Header.Set("Accept", "application/json; charset=utf-8")
|
request.Header.Set("Content-Type", params.contentType)
|
||||||
|
}
|
||||||
|
|
||||||
|
request.Header.Set("Accept", applicationJSON)
|
||||||
request.Header.Set("User-Agent", g.UserAgent)
|
request.Header.Set("User-Agent", g.UserAgent)
|
||||||
|
|
||||||
if len(g.Authentication.AccessToken) > 0 {
|
if len(g.Authentication.AccessToken) > 0 {
|
||||||
|
@ -140,11 +155,11 @@ func (g *Client) sendRequest(method string, url string, requestBody io.Reader, o
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if object == nil {
|
if params.output == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := json.NewDecoder(response.Body).Decode(object); err != nil {
|
if err := json.NewDecoder(response.Body).Decode(params.output); err != nil {
|
||||||
return fmt.Errorf(
|
return fmt.Errorf(
|
||||||
"unable to decode the response from the GoToSocial server: %w",
|
"unable to decode the response from the GoToSocial server: %w",
|
||||||
err,
|
err,
|
||||||
|
|
|
@ -13,7 +13,15 @@ func (g *Client) GetInstance() (model.InstanceV2, error) {
|
||||||
|
|
||||||
var instance model.InstanceV2
|
var instance model.InstanceV2
|
||||||
|
|
||||||
if err := g.sendRequest(http.MethodGet, url, nil, &instance); err != nil {
|
params := requestParameters{
|
||||||
|
httpMethod: http.MethodGet,
|
||||||
|
url: url,
|
||||||
|
requestBody: nil,
|
||||||
|
contentType: "",
|
||||||
|
output: &instance,
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := g.sendRequest(params); err != nil {
|
||||||
return model.InstanceV2{}, fmt.Errorf("received an error after sending the request to get the instance details: %w", err)
|
return model.InstanceV2{}, fmt.Errorf("received an error after sending the request to get the instance details: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,15 @@ func (g *Client) GetAllLists() ([]model.List, error) {
|
||||||
|
|
||||||
var lists []model.List
|
var lists []model.List
|
||||||
|
|
||||||
if err := g.sendRequest(http.MethodGet, url, nil, &lists); err != nil {
|
params := requestParameters{
|
||||||
|
httpMethod: http.MethodGet,
|
||||||
|
url: url,
|
||||||
|
requestBody: nil,
|
||||||
|
contentType: "",
|
||||||
|
output: &lists,
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := g.sendRequest(params); err != nil {
|
||||||
return nil, fmt.Errorf(
|
return nil, fmt.Errorf(
|
||||||
"received an error after sending the request to get the list of lists: %w",
|
"received an error after sending the request to get the list of lists: %w",
|
||||||
err,
|
err,
|
||||||
|
@ -33,7 +41,15 @@ func (g *Client) GetList(listID string) (model.List, error) {
|
||||||
|
|
||||||
var list model.List
|
var list model.List
|
||||||
|
|
||||||
if err := g.sendRequest(http.MethodGet, url, nil, &list); err != nil {
|
params := requestParameters{
|
||||||
|
httpMethod: http.MethodGet,
|
||||||
|
url: url,
|
||||||
|
requestBody: nil,
|
||||||
|
contentType: "",
|
||||||
|
output: &list,
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := g.sendRequest(params); err != nil {
|
||||||
return model.List{}, fmt.Errorf(
|
return model.List{}, fmt.Errorf(
|
||||||
"received an error after sending the request to get the list: %w",
|
"received an error after sending the request to get the list: %w",
|
||||||
err,
|
err,
|
||||||
|
@ -59,7 +75,15 @@ func (g *Client) CreateList(form CreateListForm) (model.List, error) {
|
||||||
|
|
||||||
var list model.List
|
var list model.List
|
||||||
|
|
||||||
if err := g.sendRequest(http.MethodPost, url, requestBody, &list); err != nil {
|
params := requestParameters{
|
||||||
|
httpMethod: http.MethodPost,
|
||||||
|
url: url,
|
||||||
|
requestBody: requestBody,
|
||||||
|
contentType: applicationJSON,
|
||||||
|
output: &list,
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := g.sendRequest(params); err != nil {
|
||||||
return model.List{}, fmt.Errorf(
|
return model.List{}, fmt.Errorf(
|
||||||
"received an error after sending the request to create the list: %w",
|
"received an error after sending the request to create the list: %w",
|
||||||
err,
|
err,
|
||||||
|
@ -88,7 +112,15 @@ func (g *Client) UpdateList(listToUpdate model.List) (model.List, error) {
|
||||||
|
|
||||||
var updatedList model.List
|
var updatedList model.List
|
||||||
|
|
||||||
if err := g.sendRequest(http.MethodPut, url, requestBody, &updatedList); err != nil {
|
params := requestParameters{
|
||||||
|
httpMethod: http.MethodPut,
|
||||||
|
url: url,
|
||||||
|
requestBody: requestBody,
|
||||||
|
contentType: applicationJSON,
|
||||||
|
output: &updatedList,
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := g.sendRequest(params); err != nil {
|
||||||
return model.List{}, fmt.Errorf(
|
return model.List{}, fmt.Errorf(
|
||||||
"received an error after sending the request to update the list: %w",
|
"received an error after sending the request to update the list: %w",
|
||||||
err,
|
err,
|
||||||
|
@ -101,7 +133,22 @@ func (g *Client) UpdateList(listToUpdate model.List) (model.List, error) {
|
||||||
func (g *Client) DeleteList(listID string) error {
|
func (g *Client) DeleteList(listID string) error {
|
||||||
url := g.Authentication.Instance + baseListPath + "/" + listID
|
url := g.Authentication.Instance + baseListPath + "/" + listID
|
||||||
|
|
||||||
return g.sendRequest(http.MethodDelete, url, nil, nil)
|
params := requestParameters{
|
||||||
|
httpMethod: http.MethodDelete,
|
||||||
|
url: url,
|
||||||
|
requestBody: nil,
|
||||||
|
contentType: "",
|
||||||
|
output: nil,
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := g.sendRequest(params); err != nil {
|
||||||
|
return fmt.Errorf(
|
||||||
|
"received an error after sending the request to delete the list: %w",
|
||||||
|
err,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *Client) AddAccountsToList(listID string, accountIDs []string) error {
|
func (g *Client) AddAccountsToList(listID string, accountIDs []string) error {
|
||||||
|
@ -119,7 +166,15 @@ func (g *Client) AddAccountsToList(listID string, accountIDs []string) error {
|
||||||
requestBody := bytes.NewBuffer(data)
|
requestBody := bytes.NewBuffer(data)
|
||||||
url := g.Authentication.Instance + baseListPath + "/" + listID + "/accounts"
|
url := g.Authentication.Instance + baseListPath + "/" + listID + "/accounts"
|
||||||
|
|
||||||
if err := g.sendRequest(http.MethodPost, url, requestBody, nil); err != nil {
|
params := requestParameters{
|
||||||
|
httpMethod: http.MethodPost,
|
||||||
|
url: url,
|
||||||
|
requestBody: requestBody,
|
||||||
|
contentType: applicationJSON,
|
||||||
|
output: nil,
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := g.sendRequest(params); err != nil {
|
||||||
return fmt.Errorf(
|
return fmt.Errorf(
|
||||||
"received an error after sending the request to add the accounts to the list: %w",
|
"received an error after sending the request to add the accounts to the list: %w",
|
||||||
err,
|
err,
|
||||||
|
@ -144,7 +199,15 @@ func (g *Client) RemoveAccountsFromList(listID string, accountIDs []string) erro
|
||||||
requestBody := bytes.NewBuffer(data)
|
requestBody := bytes.NewBuffer(data)
|
||||||
url := g.Authentication.Instance + baseListPath + "/" + listID + "/accounts"
|
url := g.Authentication.Instance + baseListPath + "/" + listID + "/accounts"
|
||||||
|
|
||||||
if err := g.sendRequest(http.MethodDelete, url, requestBody, nil); err != nil {
|
params := requestParameters{
|
||||||
|
httpMethod: http.MethodDelete,
|
||||||
|
url: url,
|
||||||
|
requestBody: requestBody,
|
||||||
|
contentType: applicationJSON,
|
||||||
|
output: nil,
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := g.sendRequest(params); err != nil {
|
||||||
return fmt.Errorf(
|
return fmt.Errorf(
|
||||||
"received an error after sending the request to remove the accounts from the list: %w",
|
"received an error after sending the request to remove the accounts from the list: %w",
|
||||||
err,
|
err,
|
||||||
|
@ -160,7 +223,15 @@ func (g *Client) GetAccountsFromList(listID string, limit int) ([]model.Account,
|
||||||
|
|
||||||
var accounts []model.Account
|
var accounts []model.Account
|
||||||
|
|
||||||
if err := g.sendRequest(http.MethodGet, url, nil, &accounts); err != nil {
|
params := requestParameters{
|
||||||
|
httpMethod: http.MethodGet,
|
||||||
|
url: url,
|
||||||
|
requestBody: nil,
|
||||||
|
contentType: "",
|
||||||
|
output: &accounts,
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := g.sendRequest(params); err != nil {
|
||||||
return nil, fmt.Errorf(
|
return nil, fmt.Errorf(
|
||||||
"received an error after sending the request to get the accounts from the list: %w",
|
"received an error after sending the request to get the accounts from the list: %w",
|
||||||
err,
|
err,
|
||||||
|
|
|
@ -7,14 +7,36 @@ import (
|
||||||
"codeflow.dananglin.me.uk/apollo/enbas/internal/model"
|
"codeflow.dananglin.me.uk/apollo/enbas/internal/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
baseMediaPath string = "/api/v1/media"
|
||||||
|
)
|
||||||
|
|
||||||
func (g *Client) GetMediaAttachment(mediaAttachmentID string) (model.Attachment, error) {
|
func (g *Client) GetMediaAttachment(mediaAttachmentID string) (model.Attachment, error) {
|
||||||
url := g.Authentication.Instance + "/api/v1/media/" + mediaAttachmentID
|
url := g.Authentication.Instance + baseMediaPath + "/" + mediaAttachmentID
|
||||||
|
|
||||||
var attachment model.Attachment
|
var attachment model.Attachment
|
||||||
|
|
||||||
if err := g.sendRequest(http.MethodGet, url, nil, &attachment); err != nil {
|
params := requestParameters{
|
||||||
|
httpMethod: http.MethodGet,
|
||||||
|
url: url,
|
||||||
|
requestBody: nil,
|
||||||
|
contentType: "",
|
||||||
|
output: &attachment,
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := g.sendRequest(params); err != nil {
|
||||||
return model.Attachment{}, fmt.Errorf("received an error after sending the request to get the media attachment: %w", err)
|
return model.Attachment{}, fmt.Errorf("received an error after sending the request to get the media attachment: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return attachment, nil
|
return attachment, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//type CreateMediaAttachmentForm struct {
|
||||||
|
// Description string
|
||||||
|
// Focus string
|
||||||
|
// Filepath string
|
||||||
|
//}
|
||||||
|
//
|
||||||
|
//func (g *Client) CreateMediaAttachment(form CreateMediaAttachmentForm) (model.Attachment, error) {
|
||||||
|
// return model.Attachment{}, nil
|
||||||
|
//}
|
||||||
|
|
|
@ -18,7 +18,15 @@ func (g *Client) GetPoll(pollID string) (model.Poll, error) {
|
||||||
|
|
||||||
var poll model.Poll
|
var poll model.Poll
|
||||||
|
|
||||||
if err := g.sendRequest(http.MethodGet, url, nil, &poll); err != nil {
|
params := requestParameters{
|
||||||
|
httpMethod: http.MethodGet,
|
||||||
|
url: url,
|
||||||
|
requestBody: nil,
|
||||||
|
contentType: "",
|
||||||
|
output: &poll,
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := g.sendRequest(params); err != nil {
|
||||||
return model.Poll{}, fmt.Errorf(
|
return model.Poll{}, fmt.Errorf(
|
||||||
"received an error after sending the request to get the poll: %w",
|
"received an error after sending the request to get the poll: %w",
|
||||||
err,
|
err,
|
||||||
|
@ -43,7 +51,15 @@ func (g *Client) VoteInPoll(pollID string, choices []int) error {
|
||||||
requestBody := bytes.NewBuffer(data)
|
requestBody := bytes.NewBuffer(data)
|
||||||
url := g.Authentication.Instance + pollPath + "/" + pollID + "/votes"
|
url := g.Authentication.Instance + pollPath + "/" + pollID + "/votes"
|
||||||
|
|
||||||
if err := g.sendRequest(http.MethodPost, url, requestBody, nil); err != nil {
|
params := requestParameters{
|
||||||
|
httpMethod: http.MethodPost,
|
||||||
|
url: url,
|
||||||
|
requestBody: requestBody,
|
||||||
|
contentType: applicationJSON,
|
||||||
|
output: nil,
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := g.sendRequest(params); err != nil {
|
||||||
return fmt.Errorf("received an error after sending the request to vote in the poll: %w", err)
|
return fmt.Errorf("received an error after sending the request to vote in the poll: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,8 +12,19 @@ func (g *Client) GetUserPreferences() (*model.Preferences, error) {
|
||||||
|
|
||||||
var preferences model.Preferences
|
var preferences model.Preferences
|
||||||
|
|
||||||
if err := g.sendRequest(http.MethodGet, url, nil, &preferences); err != nil {
|
params := requestParameters{
|
||||||
return nil, fmt.Errorf("received an error after sending the request to get the user preferences: %w", err)
|
httpMethod: http.MethodGet,
|
||||||
|
url: url,
|
||||||
|
requestBody: nil,
|
||||||
|
contentType: "",
|
||||||
|
output: &preferences,
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := g.sendRequest(params); err != nil {
|
||||||
|
return nil, fmt.Errorf(
|
||||||
|
"received an error after sending the request to get the user preferences: %w",
|
||||||
|
err,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
return &preferences, nil
|
return &preferences, nil
|
||||||
|
|
|
@ -18,14 +18,14 @@ type registerRequest struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *Client) Register() error {
|
func (g *Client) Register() error {
|
||||||
params := registerRequest{
|
registerParams := registerRequest{
|
||||||
ClientName: internal.ApplicationName,
|
ClientName: internal.ApplicationName,
|
||||||
RedirectUris: internal.RedirectURI,
|
RedirectUris: internal.RedirectURI,
|
||||||
Scopes: "read write",
|
Scopes: "read write",
|
||||||
Website: internal.ApplicationWebsite,
|
Website: internal.ApplicationWebsite,
|
||||||
}
|
}
|
||||||
|
|
||||||
data, err := json.Marshal(params)
|
data, err := json.Marshal(registerParams)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to marshal the request body: %w", err)
|
return fmt.Errorf("unable to marshal the request body: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,15 @@ func (g *Client) Register() error {
|
||||||
|
|
||||||
var app model.Application
|
var app model.Application
|
||||||
|
|
||||||
if err := g.sendRequest(http.MethodPost, url, requestBody, &app); err != nil {
|
requestParams := requestParameters{
|
||||||
|
httpMethod: http.MethodPost,
|
||||||
|
url: url,
|
||||||
|
requestBody: requestBody,
|
||||||
|
contentType: applicationJSON,
|
||||||
|
output: &app,
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := g.sendRequest(requestParams); err != nil {
|
||||||
return fmt.Errorf("received an error after sending the registration request: %w", err)
|
return fmt.Errorf("received an error after sending the registration request: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,15 @@ func (g *Client) GetStatus(statusID string) (model.Status, error) {
|
||||||
|
|
||||||
var status model.Status
|
var status model.Status
|
||||||
|
|
||||||
if err := g.sendRequest(http.MethodGet, url, nil, &status); err != nil {
|
params := requestParameters{
|
||||||
|
httpMethod: http.MethodGet,
|
||||||
|
url: url,
|
||||||
|
requestBody: nil,
|
||||||
|
contentType: "",
|
||||||
|
output: &status,
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := g.sendRequest(params); err != nil {
|
||||||
return model.Status{}, fmt.Errorf(
|
return model.Status{}, fmt.Errorf(
|
||||||
"received an error after sending the request to get the status information: %w",
|
"received an error after sending the request to get the status information: %w",
|
||||||
err,
|
err,
|
||||||
|
@ -62,7 +70,15 @@ func (g *Client) CreateStatus(form CreateStatusForm) (model.Status, error) {
|
||||||
|
|
||||||
var status model.Status
|
var status model.Status
|
||||||
|
|
||||||
if err := g.sendRequest(http.MethodPost, url, requestBody, &status); err != nil {
|
params := requestParameters{
|
||||||
|
httpMethod: http.MethodPost,
|
||||||
|
url: url,
|
||||||
|
requestBody: requestBody,
|
||||||
|
contentType: applicationJSON,
|
||||||
|
output: &status,
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := g.sendRequest(params); err != nil {
|
||||||
return model.Status{}, fmt.Errorf(
|
return model.Status{}, fmt.Errorf(
|
||||||
"received an error after sending the request to create the status: %w",
|
"received an error after sending the request to create the status: %w",
|
||||||
err,
|
err,
|
||||||
|
@ -81,7 +97,15 @@ func (g *Client) GetBookmarks(limit int) (model.StatusList, error) {
|
||||||
Statuses: nil,
|
Statuses: nil,
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := g.sendRequest(http.MethodGet, url, nil, &bookmarks.Statuses); err != nil {
|
params := requestParameters{
|
||||||
|
httpMethod: http.MethodGet,
|
||||||
|
url: url,
|
||||||
|
requestBody: nil,
|
||||||
|
contentType: "",
|
||||||
|
output: &bookmarks.Statuses,
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := g.sendRequest(params); err != nil {
|
||||||
return bookmarks, fmt.Errorf(
|
return bookmarks, fmt.Errorf(
|
||||||
"received an error after sending the request to get the bookmarks: %w",
|
"received an error after sending the request to get the bookmarks: %w",
|
||||||
err,
|
err,
|
||||||
|
@ -95,7 +119,15 @@ func (g *Client) AddStatusToBookmarks(statusID string) error {
|
||||||
path := fmt.Sprintf("/api/v1/statuses/%s/bookmark", statusID)
|
path := fmt.Sprintf("/api/v1/statuses/%s/bookmark", statusID)
|
||||||
url := g.Authentication.Instance + path
|
url := g.Authentication.Instance + path
|
||||||
|
|
||||||
if err := g.sendRequest(http.MethodPost, url, nil, nil); err != nil {
|
params := requestParameters{
|
||||||
|
httpMethod: http.MethodPost,
|
||||||
|
url: url,
|
||||||
|
requestBody: nil,
|
||||||
|
contentType: "",
|
||||||
|
output: nil,
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := g.sendRequest(params); err != nil {
|
||||||
return fmt.Errorf(
|
return fmt.Errorf(
|
||||||
"received an error after sending the request to add the status to the list of bookmarks: %w",
|
"received an error after sending the request to add the status to the list of bookmarks: %w",
|
||||||
err,
|
err,
|
||||||
|
@ -109,7 +141,15 @@ func (g *Client) RemoveStatusFromBookmarks(statusID string) error {
|
||||||
path := fmt.Sprintf("/api/v1/statuses/%s/unbookmark", statusID)
|
path := fmt.Sprintf("/api/v1/statuses/%s/unbookmark", statusID)
|
||||||
url := g.Authentication.Instance + path
|
url := g.Authentication.Instance + path
|
||||||
|
|
||||||
if err := g.sendRequest(http.MethodPost, url, nil, nil); err != nil {
|
params := requestParameters{
|
||||||
|
httpMethod: http.MethodPost,
|
||||||
|
url: url,
|
||||||
|
requestBody: nil,
|
||||||
|
contentType: "",
|
||||||
|
output: nil,
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := g.sendRequest(params); err != nil {
|
||||||
return fmt.Errorf(
|
return fmt.Errorf(
|
||||||
"received an error after sending the request to remove the status from the list of bookmarks: %w",
|
"received an error after sending the request to remove the status from the list of bookmarks: %w",
|
||||||
err,
|
err,
|
||||||
|
@ -122,7 +162,15 @@ func (g *Client) RemoveStatusFromBookmarks(statusID string) error {
|
||||||
func (g *Client) LikeStatus(statusID string) error {
|
func (g *Client) LikeStatus(statusID string) error {
|
||||||
url := g.Authentication.Instance + baseStatusesPath + "/" + statusID + "/favourite"
|
url := g.Authentication.Instance + baseStatusesPath + "/" + statusID + "/favourite"
|
||||||
|
|
||||||
if err := g.sendRequest(http.MethodPost, url, nil, nil); err != nil {
|
params := requestParameters{
|
||||||
|
httpMethod: http.MethodPost,
|
||||||
|
url: url,
|
||||||
|
requestBody: nil,
|
||||||
|
contentType: "",
|
||||||
|
output: nil,
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := g.sendRequest(params); err != nil {
|
||||||
return fmt.Errorf(
|
return fmt.Errorf(
|
||||||
"received an error after sending the request to like the status: %w",
|
"received an error after sending the request to like the status: %w",
|
||||||
err,
|
err,
|
||||||
|
@ -135,7 +183,15 @@ func (g *Client) LikeStatus(statusID string) error {
|
||||||
func (g *Client) UnlikeStatus(statusID string) error {
|
func (g *Client) UnlikeStatus(statusID string) error {
|
||||||
url := g.Authentication.Instance + baseStatusesPath + "/" + statusID + "/unfavourite"
|
url := g.Authentication.Instance + baseStatusesPath + "/" + statusID + "/unfavourite"
|
||||||
|
|
||||||
if err := g.sendRequest(http.MethodPost, url, nil, nil); err != nil {
|
params := requestParameters{
|
||||||
|
httpMethod: http.MethodPost,
|
||||||
|
url: url,
|
||||||
|
requestBody: nil,
|
||||||
|
contentType: "",
|
||||||
|
output: nil,
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := g.sendRequest(params); err != nil {
|
||||||
return fmt.Errorf(
|
return fmt.Errorf(
|
||||||
"received an error after sending the request to unlike the status: %w",
|
"received an error after sending the request to unlike the status: %w",
|
||||||
err,
|
err,
|
||||||
|
@ -153,7 +209,15 @@ func (g *Client) GetLikedStatuses(limit int, resourceName string) (model.StatusL
|
||||||
Statuses: nil,
|
Statuses: nil,
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := g.sendRequest(http.MethodGet, url, nil, &liked.Statuses); err != nil {
|
params := requestParameters{
|
||||||
|
httpMethod: http.MethodGet,
|
||||||
|
url: url,
|
||||||
|
requestBody: nil,
|
||||||
|
contentType: "",
|
||||||
|
output: &liked.Statuses,
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := g.sendRequest(params); err != nil {
|
||||||
return model.StatusList{}, fmt.Errorf(
|
return model.StatusList{}, fmt.Errorf(
|
||||||
"received an error after sending the request to get the list of statuses: %w",
|
"received an error after sending the request to get the list of statuses: %w",
|
||||||
err,
|
err,
|
||||||
|
@ -166,7 +230,15 @@ func (g *Client) GetLikedStatuses(limit int, resourceName string) (model.StatusL
|
||||||
func (g *Client) ReblogStatus(statusID string) error {
|
func (g *Client) ReblogStatus(statusID string) error {
|
||||||
url := g.Authentication.Instance + baseStatusesPath + "/" + statusID + "/reblog"
|
url := g.Authentication.Instance + baseStatusesPath + "/" + statusID + "/reblog"
|
||||||
|
|
||||||
if err := g.sendRequest(http.MethodPost, url, nil, nil); err != nil {
|
params := requestParameters{
|
||||||
|
httpMethod: http.MethodPost,
|
||||||
|
url: url,
|
||||||
|
requestBody: nil,
|
||||||
|
contentType: "",
|
||||||
|
output: nil,
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := g.sendRequest(params); err != nil {
|
||||||
return fmt.Errorf(
|
return fmt.Errorf(
|
||||||
"received an error after sending the request to reblog the status; %w",
|
"received an error after sending the request to reblog the status; %w",
|
||||||
err,
|
err,
|
||||||
|
@ -179,7 +251,15 @@ func (g *Client) ReblogStatus(statusID string) error {
|
||||||
func (g *Client) UnreblogStatus(statusID string) error {
|
func (g *Client) UnreblogStatus(statusID string) error {
|
||||||
url := g.Authentication.Instance + baseStatusesPath + "/" + statusID + "/unreblog"
|
url := g.Authentication.Instance + baseStatusesPath + "/" + statusID + "/unreblog"
|
||||||
|
|
||||||
if err := g.sendRequest(http.MethodPost, url, nil, nil); err != nil {
|
params := requestParameters{
|
||||||
|
httpMethod: http.MethodPost,
|
||||||
|
url: url,
|
||||||
|
requestBody: nil,
|
||||||
|
contentType: "",
|
||||||
|
output: nil,
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := g.sendRequest(params); err != nil {
|
||||||
return fmt.Errorf(
|
return fmt.Errorf(
|
||||||
"received an error after sending the request to un-reblog the status; %w",
|
"received an error after sending the request to un-reblog the status; %w",
|
||||||
err,
|
err,
|
||||||
|
|
|
@ -56,7 +56,15 @@ func (g *Client) getTimeline(path string, timeline model.StatusList) (model.Stat
|
||||||
|
|
||||||
var statuses []model.Status
|
var statuses []model.Status
|
||||||
|
|
||||||
if err := g.sendRequest(http.MethodGet, url, nil, &statuses); err != nil {
|
params := requestParameters{
|
||||||
|
httpMethod: http.MethodGet,
|
||||||
|
url: url,
|
||||||
|
requestBody: nil,
|
||||||
|
contentType: "",
|
||||||
|
output: &statuses,
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := g.sendRequest(params); err != nil {
|
||||||
return timeline, fmt.Errorf("received an error after sending the request to get the timeline: %w", err)
|
return timeline, fmt.Errorf("received an error after sending the request to get the timeline: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ type tokenResponse struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *Client) UpdateToken(code string) error {
|
func (g *Client) UpdateToken(code string) error {
|
||||||
params := tokenRequest{
|
tokenReq := tokenRequest{
|
||||||
RedirectURI: internal.RedirectURI,
|
RedirectURI: internal.RedirectURI,
|
||||||
ClientID: g.Authentication.ClientID,
|
ClientID: g.Authentication.ClientID,
|
||||||
ClientSecret: g.Authentication.ClientSecret,
|
ClientSecret: g.Authentication.ClientSecret,
|
||||||
|
@ -36,7 +36,7 @@ func (g *Client) UpdateToken(code string) error {
|
||||||
Code: code,
|
Code: code,
|
||||||
}
|
}
|
||||||
|
|
||||||
data, err := json.Marshal(params)
|
data, err := json.Marshal(tokenReq)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to marshal the request body: %w", err)
|
return fmt.Errorf("unable to marshal the request body: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -46,7 +46,15 @@ func (g *Client) UpdateToken(code string) error {
|
||||||
|
|
||||||
var response tokenResponse
|
var response tokenResponse
|
||||||
|
|
||||||
if err := g.sendRequest(http.MethodPost, url, requestBody, &response); err != nil {
|
params := requestParameters{
|
||||||
|
httpMethod: http.MethodPost,
|
||||||
|
url: url,
|
||||||
|
requestBody: requestBody,
|
||||||
|
contentType: applicationJSON,
|
||||||
|
output: &response,
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := g.sendRequest(params); err != nil {
|
||||||
return fmt.Errorf("received an error after sending the token request: %w", err)
|
return fmt.Errorf("received an error after sending the token request: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue