## Usage
+### Authenticate to a server
+
+
```
dead-tooter login --host hackers.town
```
+
+The first time you call `login`, this will register with your chosen server and
+store application information in your `~/.config/` directory. Your default
+browser will open to a login page, or if you are logged in, an app authorization
+page where you will be presented with an authorization token. Copy the token and
+paste it at the prompt. A login token will be stored in the same directory.
+
+### Get account info
+
+```
+dead-tooter --host hackers.town account [id]
+```
+
+### Get a list of followers
+
+```
+dead-tooter --host hackers.town account followers
+```
+
+### Get a list of following
+
+```
+dead-tooter --host hackers.town account following
+```
var account mastodon.Account
func init() {
+ accountCmd.AddCommand(getAccountCmd)
accountCmd.AddCommand(getFollowersCmd)
accountCmd.AddCommand(getFollowingCmd)
+
rootCmd.AddCommand(accountCmd)
}
Long: "Commands related to the logged in Mastodon account.",
}
+var getAccountCmd = &cobra.Command{
+ Use: "get [id]",
+ Short: "Get account info",
+ Long: "Return information the account specified by [id]. If no id is supplied, return information on the current logged in user.",
+
+ Run: func(cmd *cobra.Command, args []string) {
+ err := account.VerifyCredentials(host, token)
+ if err != nil {
+ panic(err.Error())
+ }
+
+ if len(args) < 1 {
+ fmt.Printf("%+v", account)
+ return
+ }
+
+ acct, err := account.Get(args[0], host, token)
+ if err != nil {
+ panic(err.Error())
+ }
+
+ fmt.Printf("%+v", acct)
+ },
+}
+
var getFollowersCmd = &cobra.Command{
Use: "followers",
Short: "Get account followers",
return
}
+// Get returns the details of account specified by ID.
+func (a *Account) Get(
+ ID string, host string, token Token) (account Account, err error) {
+
+ client := &http.Client{}
+
+ id := url.PathEscape(ID)
+ path, err := url.JoinPath("api/v1/accounts", id)
+ if err != nil {
+ return
+ }
+
+ u := url.URL{
+ Host: host,
+ Path: path,
+ }
+ u.Scheme = "https"
+
+ req, err := http.NewRequest("GET", u.String(), nil)
+ if err != nil {
+ return
+ }
+ req.Header.Add("Authorization", "Bearer "+token.AccessToken)
+
+ resp, err := client.Do(req)
+ if err != nil {
+ return
+ }
+ if resp.StatusCode != 200 {
+ err = errors.New(resp.Status)
+ return
+ }
+ defer resp.Body.Close()
+
+ body, err := io.ReadAll(resp.Body)
+ if err != nil {
+ return
+ }
+
+ err = json.Unmarshal(body, &account)
+ if err != nil {
+ return
+ }
+
+ return
+}
+
// GetFollowers returns a list of all accounts following the logged in user
func (a *Account) GetFollowers(
host string, token Token) (followers []Account, err error) {