Documentation ¶
Overview ¶
Package lists provides easy API access to Sourcehut mailing lists.
Index ¶
- Constants
- type Client
- func (c *Client) GetUser(username string) (sourcehut.User, error)
- func (c *Client) List(username string) (ListIter, error)
- func (c *Client) ListEmails(username string) (PostIter, error)
- func (c *Client) ListPosts(username, listname string) (PostIter, error)
- func (c *Client) Version() (string, error)
- type List
- type ListIter
- type Option
- type Post
- type PostIter
- type ShortList
- type ShortPost
Examples ¶
Constants ¶
const BaseURL = "https://lists.sr.ht/api/"
BaseURL is the default public Sourcehut mailing lists API URL. It is exported for convenience.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client handles communication with the mailing lists related methods of the Sourcehut API.
API docs: https://man.sr.ht/lists.sr.ht/api.md
func (*Client) GetUser ¶ added in v0.0.2
GetUser returns information about the provided username, or the currently authenticated user if the username is empty.
func (*Client) List ¶
List returns an iterator over all mailing lists owned by the provided username. If an empty username is provided, the authenticated user is used.
func (*Client) ListEmails ¶ added in v0.0.2
ListEmails returns all emails sent by the provided user.
type List ¶
type List struct { ShortList Created time.Time `json:"created"` Updated time.Time `json:"updated"` Desc string `json:"description"` Perms struct { // TODO: "browse", "reply", and "post" are valid permissions. // Make a type for this. NonSubscriber []string `json:"nonsubscriber"` Subscriber []string `json:"subscriber"` Account []string `json:"account"` } `json:"permissions"` }
List represents the expanded form of a mailing list.
type ListIter ¶
type ListIter struct {
*sourcehut.Iter
}
ListIter is used for iterating over a collection of mailing lists.
type Option ¶
Option is used to configure an API client.
func Base ¶
Base returns an option that configures the public Sourcehut API URL.
If base does not have a trailing slash, one is added automatically. If unspecified, BaseURL is used.
func SrhtClient ¶
func SrhtClient(client sourcehut.Client) Option
SrhtClient returns an option that configures the client to use the provided sourcehut.Client for API requests. If unspecified, a default sourcehut.Client (with no options of its own) is used.
type Post ¶
type Post struct { ShortPost Patch bool `json:"is_patch"` PullRequest bool `json:"is_request_pull"` Replies int64 `json:"replies"` Participants int64 `json:"participants"` Envelope string `json:"envelope"` }
Post represents the expanded form of an email message.
type PostIter ¶
type PostIter struct {
*sourcehut.Iter
}
PostIter is used for iterating over a collection of mailing list posts.
Example ¶
srhtClient := sourcehut.NewClient(sourcehut.Token("<personal access token>")) listClient, _ := lists.NewClient(lists.SrhtClient(srhtClient)) iter, _ := listClient.ListPosts("~sircmpwn", "sr.ht-dev") for iter.Next() { p := iter.Post() log.Printf("Post %d: %q\n", p.ID, p.Subject) } if err := iter.Err(); err != nil { log.Fatalf("Error fetching posts: %q", err) }
Output:
type ShortList ¶
type ShortList struct { Name string `json:"name"` Owner sourcehut.ShortUser `json:"owner"` }
ShortList represents the unexpanded form of a mailing list.
type ShortPost ¶
type ShortPost struct { ID int64 `json:"id"` Created time.Time `json:"created"` List ShortList `json:"list"` MessageID string `json:"message_id"` ParentID int64 `json:"parent_id"` Sender *sourcehut.ShortUser `json:"sender"` Subject string `json:"subject"` ThreadID int64 `json:"thread_id"` }
ShortPost represents the unexpanded form of an email message.