Compare commits
No commits in common. "31e90b31e2d2eacf67a785f753cb6725ff65a009" and "4d30e643af6d16e837db9f15b9aee9cc454b48e8" have entirely different histories.
31e90b31e2
...
4d30e643af
3 changed files with 10 additions and 107 deletions
|
@ -74,39 +74,8 @@ func (g *Client) GetBookmarks(limit int) (model.StatusList, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := g.sendRequest(http.MethodGet, url, nil, &bookmarks.Statuses); err != nil {
|
if err := g.sendRequest(http.MethodGet, url, nil, &bookmarks.Statuses); err != nil {
|
||||||
return bookmarks, fmt.Errorf(
|
return bookmarks, fmt.Errorf("received an error after sending the request to get the bookmarks: %w", err)
|
||||||
"received an error after sending the request to get the bookmarks: %w",
|
|
||||||
err,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return bookmarks, nil
|
return bookmarks, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *Client) AddStatusToBookmarks(statusID string) error {
|
|
||||||
path := fmt.Sprintf("/api/v1/statuses/%s/bookmark", statusID)
|
|
||||||
url := g.Authentication.Instance + path
|
|
||||||
|
|
||||||
if err := g.sendRequest(http.MethodPost, url, nil, nil); err != nil {
|
|
||||||
return fmt.Errorf(
|
|
||||||
"received an error after sending the request to add the status to the list of bookmarks: %w",
|
|
||||||
err,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (g *Client) RemoveStatusFromBookmarks(statusID string) error {
|
|
||||||
path := fmt.Sprintf("/api/v1/statuses/%s/unbookmark", statusID)
|
|
||||||
url := g.Authentication.Instance + path
|
|
||||||
|
|
||||||
if err := g.sendRequest(http.MethodPost, url, nil, nil); err != nil {
|
|
||||||
return fmt.Errorf(
|
|
||||||
"received an error after sending the request to remove the status from the list of bookmarks: %w",
|
|
||||||
err,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
|
@ -18,7 +18,6 @@ type AddExecutor struct {
|
||||||
resourceType string
|
resourceType string
|
||||||
toResourceType string
|
toResourceType string
|
||||||
listID string
|
listID string
|
||||||
statusID string
|
|
||||||
accountNames AccountNames
|
accountNames AccountNames
|
||||||
content string
|
content string
|
||||||
}
|
}
|
||||||
|
@ -35,8 +34,7 @@ func NewAddExecutor(tlf TopLevelFlags, name, summary string) *AddExecutor {
|
||||||
addExe.StringVar(&addExe.resourceType, flagType, "", "specify the resource type to add (e.g. account, note)")
|
addExe.StringVar(&addExe.resourceType, flagType, "", "specify the resource type to add (e.g. account, note)")
|
||||||
addExe.StringVar(&addExe.toResourceType, flagTo, "", "specify the target resource type to add to (e.g. list, account, etc)")
|
addExe.StringVar(&addExe.toResourceType, flagTo, "", "specify the target resource type to add to (e.g. list, account, etc)")
|
||||||
addExe.StringVar(&addExe.listID, flagListID, "", "the ID of the list to add to")
|
addExe.StringVar(&addExe.listID, flagListID, "", "the ID of the list to add to")
|
||||||
addExe.StringVar(&addExe.statusID, flagStatusID, "", "the ID of the status")
|
addExe.Var(&addExe.accountNames, flagAccountName, "the name of the account to add to the resource")
|
||||||
addExe.Var(&addExe.accountNames, flagAccountName, "the name of the account")
|
|
||||||
addExe.StringVar(&addExe.content, flagContent, "", "the content of the note")
|
addExe.StringVar(&addExe.content, flagContent, "", "the content of the note")
|
||||||
|
|
||||||
addExe.Usage = commandUsageFunc(name, summary, addExe.FlagSet)
|
addExe.Usage = commandUsageFunc(name, summary, addExe.FlagSet)
|
||||||
|
@ -52,7 +50,6 @@ func (a *AddExecutor) Execute() error {
|
||||||
funcMap := map[string]func(*client.Client) error{
|
funcMap := map[string]func(*client.Client) error{
|
||||||
resourceList: a.addToList,
|
resourceList: a.addToList,
|
||||||
resourceAccount: a.addToAccount,
|
resourceAccount: a.addToAccount,
|
||||||
resourceBookmarks: a.addToBookmarks,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
doFunc, ok := funcMap[a.toResourceType]
|
doFunc, ok := funcMap[a.toResourceType]
|
||||||
|
@ -154,33 +151,3 @@ func (a *AddExecutor) addNoteToAccount(gtsClient *client.Client) error {
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *AddExecutor) addToBookmarks(gtsClient *client.Client) error {
|
|
||||||
funcMap := map[string]func(*client.Client) error{
|
|
||||||
resourceStatus: a.addStatusToBookmarks,
|
|
||||||
}
|
|
||||||
|
|
||||||
doFunc, ok := funcMap[a.resourceType]
|
|
||||||
if !ok {
|
|
||||||
return UnsupportedAddOperationError{
|
|
||||||
ResourceType: a.resourceType,
|
|
||||||
AddToResourceType: a.toResourceType,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return doFunc(gtsClient)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a *AddExecutor) addStatusToBookmarks(gtsClient *client.Client) error {
|
|
||||||
if a.statusID == "" {
|
|
||||||
return FlagNotSetError{flagText: flagStatusID}
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := gtsClient.AddStatusToBookmarks(a.statusID); err != nil {
|
|
||||||
return fmt.Errorf("unable to add the status to your bookmarks: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Println("Successfully added the status to your bookmarks.")
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
|
@ -18,7 +18,6 @@ type RemoveExecutor struct {
|
||||||
resourceType string
|
resourceType string
|
||||||
fromResourceType string
|
fromResourceType string
|
||||||
listID string
|
listID string
|
||||||
statusID string
|
|
||||||
accountNames AccountNames
|
accountNames AccountNames
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,7 +33,6 @@ func NewRemoveExecutor(tlf TopLevelFlags, name, summary string) *RemoveExecutor
|
||||||
removeExe.StringVar(&removeExe.resourceType, flagType, "", "specify the resource type to remove (e.g. account, note)")
|
removeExe.StringVar(&removeExe.resourceType, flagType, "", "specify the resource type to remove (e.g. account, note)")
|
||||||
removeExe.StringVar(&removeExe.fromResourceType, flagFrom, "", "specify the resource type to remove from (e.g. list, account, etc)")
|
removeExe.StringVar(&removeExe.fromResourceType, flagFrom, "", "specify the resource type to remove from (e.g. list, account, etc)")
|
||||||
removeExe.StringVar(&removeExe.listID, flagListID, "", "the ID of the list to remove from")
|
removeExe.StringVar(&removeExe.listID, flagListID, "", "the ID of the list to remove from")
|
||||||
removeExe.StringVar(&removeExe.statusID, flagStatusID, "", "the ID of the status")
|
|
||||||
removeExe.Var(&removeExe.accountNames, flagAccountName, "the name of the account to remove from the resource")
|
removeExe.Var(&removeExe.accountNames, flagAccountName, "the name of the account to remove from the resource")
|
||||||
|
|
||||||
removeExe.Usage = commandUsageFunc(name, summary, removeExe.FlagSet)
|
removeExe.Usage = commandUsageFunc(name, summary, removeExe.FlagSet)
|
||||||
|
@ -50,7 +48,6 @@ func (r *RemoveExecutor) Execute() error {
|
||||||
funcMap := map[string]func(*client.Client) error{
|
funcMap := map[string]func(*client.Client) error{
|
||||||
resourceList: r.removeFromList,
|
resourceList: r.removeFromList,
|
||||||
resourceAccount: r.removeFromAccount,
|
resourceAccount: r.removeFromAccount,
|
||||||
resourceBookmarks: r.removeFromBookmarks,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
doFunc, ok := funcMap[r.fromResourceType]
|
doFunc, ok := funcMap[r.fromResourceType]
|
||||||
|
@ -93,13 +90,13 @@ func (r *RemoveExecutor) removeAccountsFromList(gtsClient *client.Client) error
|
||||||
|
|
||||||
accountIDs := make([]string, len(r.accountNames))
|
accountIDs := make([]string, len(r.accountNames))
|
||||||
|
|
||||||
for ind := range r.accountNames {
|
for i := range r.accountNames {
|
||||||
accountID, err := getTheirAccountID(gtsClient, r.accountNames[ind])
|
accountID, err := getTheirAccountID(gtsClient, r.accountNames[i])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to get the account ID for %s, %w", r.accountNames[ind], err)
|
return fmt.Errorf("unable to get the account ID for %s, %w", r.accountNames[i], err)
|
||||||
}
|
}
|
||||||
|
|
||||||
accountIDs[ind] = accountID
|
accountIDs[i] = accountID
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := gtsClient.RemoveAccountsFromList(r.listID, accountIDs); err != nil {
|
if err := gtsClient.RemoveAccountsFromList(r.listID, accountIDs); err != nil {
|
||||||
|
@ -145,33 +142,3 @@ func (r *RemoveExecutor) removeNoteFromAccount(gtsClient *client.Client) error {
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *RemoveExecutor) removeFromBookmarks(gtsClient *client.Client) error {
|
|
||||||
funcMap := map[string]func(*client.Client) error{
|
|
||||||
resourceStatus: r.removeStatusFromBookmarks,
|
|
||||||
}
|
|
||||||
|
|
||||||
doFunc, ok := funcMap[r.resourceType]
|
|
||||||
if !ok {
|
|
||||||
return UnsupportedRemoveOperationError{
|
|
||||||
ResourceType: r.resourceType,
|
|
||||||
RemoveFromResourceType: r.fromResourceType,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return doFunc(gtsClient)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *RemoveExecutor) removeStatusFromBookmarks(gtsClient *client.Client) error {
|
|
||||||
if r.statusID == "" {
|
|
||||||
return FlagNotSetError{flagText: flagStatusID}
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := gtsClient.RemoveStatusFromBookmarks(r.statusID); err != nil {
|
|
||||||
return fmt.Errorf("unable to remove the status from your bookmarks: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Println("Successfully removed the status from your bookmarks.")
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue