accountCmd.AddCommand(getFollowersCmd)
accountCmd.AddCommand(getFollowingCmd)
accountCmd.AddCommand(getListsCmd)
+ accountCmd.AddCommand(getStatusesCmd)
rootCmd.AddCommand(accountCmd)
}
lists.Display()
},
}
+
+var getStatusesCmd = &cobra.Command{
+ Use: "statuses",
+ Short: "Get account's statuses",
+ Long: "Fetch statuses posted by account.",
+
+ PreRun: func(cmd *cobra.Command, args []string) {
+ err := account.VerifyCredentials(host, token)
+ if err != nil {
+ fmt.Println("Failed to verify credentials.")
+ os.Exit(1)
+ }
+ },
+
+ Run: func(cmd *cobra.Command, args []string) {
+ statuses, err := account.GetStatuses(host, token)
+ if err != nil {
+ fmt.Println("Failed to retrieve statuses.")
+ os.Exit(1)
+ }
+
+ statuses.Display()
+ },
+}
URL string `json:"url"`
StaticURL string `json:"static_url"`
VisibleInPicker bool `json:"visible_in_picker"`
+ Category string `json:"category"`
}
// AccountCollection is a group of Accounts
return following, err
}
-// GetLists fetches all lists the user owns
+// GetLists fetches all lists the account owns
func (a *Account) GetLists(host string, token api.Token) (lists ListCollection, err error) {
u := url.URL{
Host: host,
return lists, err
}
+
+// GetStatuses fetches a list of statuses by the account.
+func (a *Account) GetStatuses(
+ host string, token api.Token) (statuses StatusCollection, err error) {
+
+ id := url.PathEscape(a.ID)
+ path, err := url.JoinPath("api/v1/accounts", id, "statuses")
+ if err != nil {
+ return
+ }
+
+ u := url.URL{
+ Host: host,
+ Path: path,
+ }
+ u.Scheme = "https"
+
+ body, err := api.Get(u, host, token)
+ if err != nil {
+ return
+ }
+
+ err = json.Unmarshal(body, &statuses)
+ if err != nil {
+ return
+ }
+
+ return statuses, err
+}
--- /dev/null
+package mastodon
+
+import (
+ "fmt"
+ "os"
+ "strings"
+ "text/tabwriter"
+)
+
+// Status represents a post by an account.
+type Status struct {
+ ID string `json:"id"`
+ CreatedAt string `json:"created_at"`
+ InReplyToID string `json:"in_reply_to_id,omitempty"`
+ InReplyToAccountID string `json:"in_reply_to_account_id,omitempty"`
+ Sensitive bool `json:"sensitive"`
+ SpoilerText string `json:"spoiler_text"`
+ Visibility string `json:"visibility"`
+ Language string `json:"language"`
+ URI string `json:"uri"`
+ URL string `json:"url"`
+ RepliesCount int `json:"replies_count"`
+ ReblogsCount int `json:"reblogs_count"`
+ FavouritesCount int `json:"favourites_count"`
+ Favourited bool `json:"favourited"`
+ Reblogged bool `json:"Reblogged"`
+ Muted bool `json:"muted"`
+ Bookmarked bool `json:"bookmarked"`
+ Content string `json:"content"`
+ Application Application `json:"application"`
+ Account Account `json:"account"`
+ Card PreviewCard `json:"card"`
+ Emojis []Emoji `json:"emojis,omitempty"`
+ MediaAttachments []MediaAttachment `json:"media_attachments"`
+ Mentions []Mention `json:"mentions"`
+ Tags []Tag `json:"tags"`
+}
+
+// Reblog Status `json:"reblog,omitempty"`
+
+// StatusCollection is a group of Statuses.
+type StatusCollection []Status
+
+// MediaAttachment represents a file or media that can be added to a status.
+type MediaAttachment struct {
+ // TODO: Fill out struct and included substructs, with string enums for oneOfs.
+}
+
+// Tag are hashtags used within the Status content.
+type Tag struct {
+ Name string `json:"name"`
+ URL string `json:"url"`
+}
+
+// Mention represents accounts mentioned in a Status
+type Mention struct {
+ ID string `json:"id"`
+ UserName string `json:"username"`
+ URL string `json:"url"`
+ Acct string `json:"acct"`
+}
+
+// PreviewCard represents a rich preview that is generated using OpenGraph tags
+// from a URL.
+type PreviewCard struct {
+ URL string `json:"url"`
+ Title string `json:"title"`
+ Description string `json:"description"`
+ Type string `json:"type"`
+ AuthorName string `json:"author_name"`
+ AuthorURL string `json:"author_url"`
+ ProviderName string `json:"provider_name"`
+ ProviderURL string `json:"provider_url"`
+ HTML string `json:"html"`
+ Width int `json:"width"`
+ Height int `json:"height"`
+ Image string `json:"image"`
+ EmbedURL string `json:"embed_url"`
+}
+
+// Display a single Status
+func (s *Status) Display() string {
+ return strings.Join([]string{s.ID, s.CreatedAt, s.URL}, "\t")
+}
+
+// Display a collection of Statuses
+func (ss StatusCollection) Display() {
+ w := tabwriter.NewWriter(os.Stdout, 0, 0, 3, ' ', 0)
+ for _, value := range ss {
+ fmt.Fprintln(w, value.Display())
+ }
+ w.Flush()
+}