import (
"fmt"
- "os"
- "strings"
- "text/tabwriter"
"git.vexingworkshop.com/signal9/dead-tooter/pkg/mastodon"
"github.com/spf13/cobra"
panic(err.Error())
}
- w := tabwriter.NewWriter(os.Stdout, 0, 0, 3, ' ', 0)
- for _, value := range followers {
- fmt.Fprintln(w, strings.Join([]string{value.ID, value.Acct}, "\t"))
- }
- w.Flush()
+ followers.Display()
},
}
panic(err.Error())
}
- w := tabwriter.NewWriter(os.Stdout, 0, 0, 3, ' ', 0)
- for _, value := range following {
- fmt.Fprintln(w, strings.Join([]string{value.ID, value.Acct}, "\t"))
- }
- w.Flush()
+ following.Display()
},
}
panic(err.Error())
}
- w := tabwriter.NewWriter(os.Stdout, 0, 0, 3, ' ', 0)
- for _, value := range lists {
- fmt.Fprintln(w, strings.Join([]string{
- value.ID, value.Title, value.RepliesPolicy}, "\t"))
- }
- w.Flush()
+ lists.Display()
},
}
panic(err.Error())
}
- fmt.Printf("%+v", accounts)
+ accounts.Display()
},
}
panic(err.Error())
}
- fmt.Printf("%+v", lists)
+ lists.Display()
},
}
"io"
"net/http"
"net/url"
+ "os"
"os/exec"
+ "strings"
+ "text/tabwriter"
"git.vexingworkshop.com/signal9/dead-tooter/pkg/mastodon/api"
)
VisibleInPicker bool `json:"visible_in_picker"`
}
+// AccountCollection is a group of Accounts
+type AccountCollection []Account
+
+// Display a single Account
+func (a *Account) Display() string {
+ return strings.Join([]string{a.ID, a.Acct}, "\t")
+}
+
+// Display a collection of Accounts
+func (aa AccountCollection) Display() {
+ w := tabwriter.NewWriter(os.Stdout, 0, 0, 3, ' ', 0)
+ for _, value := range aa {
+ fmt.Fprintln(w, value.Display())
+ }
+ w.Flush()
+}
+
// Authorize opens the default browser to initiate the authorization flow
// for the current user.
func (a *Account) Authorize(host string, app Application) (code string, err error) {
// GetFollowers returns a list of all accounts following the logged in user
func (a *Account) GetFollowers(
- host string, token api.Token) (followers []Account, err error) {
+ host string, token api.Token) (followers AccountCollection, err error) {
id := url.PathEscape(a.ID)
path, err := url.JoinPath("api/v1/accounts", id, "followers")
// GetFollowing returns a list of all accounts followed by the logged in user
func (a *Account) GetFollowing(
- host string, token api.Token) (following []Account, err error) {
+ host string, token api.Token) (following AccountCollection, err error) {
id := url.PathEscape(a.ID)
path, err := url.JoinPath("api/v1/accounts", id, "following")
}
// GetLists fetches all lists the user owns
-func (a *Account) GetLists(host string, token api.Token) (lists []List, err error) {
+func (a *Account) GetLists(host string, token api.Token) (lists ListCollection, err error) {
u := url.URL{
Host: host,
Path: "api/v1/lists",
--- /dev/null
+package mastodon
+
+type DisplayItem interface {
+ Display() (string, error)
+}
+
+type DisplayList interface {
+ Display(items []interface{}) error
+}
import (
"encoding/json"
+ "fmt"
"net/url"
+ "os"
+ "strings"
+ "text/tabwriter"
"git.vexingworkshop.com/signal9/dead-tooter/pkg/mastodon/api"
)
RepliesPolicy string `json:"replies_policy"`
}
+// ListCollection is a group of Lists, usually associated with an account.
+type ListCollection []List
+
+// Display a single List
+func (l *List) Display() string {
+ return strings.Join([]string{l.ID, l.Title, l.RepliesPolicy}, "\t")
+}
+
+// Display a collection of Lists
+func (ll ListCollection) Display() {
+ w := tabwriter.NewWriter(os.Stdout, 0, 0, 3, ' ', 0)
+ for _, value := range ll {
+ fmt.Fprintln(w, value.Display())
+ }
+ w.Flush()
+}
+
// GetList returns a list specified by id.
func GetList(ID string, host string, token api.Token) (list List, err error) {
id := url.PathEscape(ID)
// ListsContainingAccount returns lists containing this account.
func ListsContainingAccount(
- accountID string, host string, token api.Token) (lists []List, err error) {
+ accountID string, host string, token api.Token) (lists ListCollection, err error) {
id := url.PathEscape(accountID)
path, err := url.JoinPath("api/v1/accounts", id, "lists")
}
// GetAccounts returns the accounts associated with a list.
-func (l *List) GetAccounts(host string, token api.Token) (accounts []Account, err error) {
+func (l *List) GetAccounts(host string, token api.Token) (accounts AccountCollection, err error) {
id := url.PathEscape(l.ID)
path, err := url.JoinPath("api/v1/lists", id, "accounts")
if err != nil {