Documentation ¶
Overview ¶
Package twtr is the backend to the twtr twtxt client.
go get duriny.envs.sh/twtr/pkg
Note that this package imports under the name 'twtr' by default.
import twtr "duriny.envs.sh/twtr/pkg"
This serves as an API and backend for the command line client, but also allows custom frontends to be built around it. See the cmd package for the reference frontend.
Index ¶
Examples ¶
Constants ¶
const Version = "v0.2.5"
Version of the twtr client.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct { // Timeout for all network activity, defaults to no timeout. Timeout time.Duration // Feed to write tweets to, if unset, tweets will be discarded. Feed io.Writer }
Client is an instance of the twtr client.
Configure the client as desired.
func (*Client) Fetch ¶ added in v0.2.4
Fetch a twtxt feed from the given source.
Returns any error that occurs while fetching or parsing the feed.
func (*Client) Post ¶
Post a new tweet on this client, running the pre/post tweet hooks along the way, return any error that occurs.
Example ¶
// construct a client client := &Client{ // What happens if you just post to STDOUT? Give it a try :) // Feed: os.Stdout, } // post tweet to the feed if err := client.Post("Hello World!"); err != nil { fmt.Println("err:", err) }
Output:
type Feed ¶ added in v0.2.3
type Feed struct { // Source of the feed Source // Description of the feed. Description string // Follows these other feeds. Follows map[string]string // Tweets of the feed. Tweets }
Feed represents a twtxt feed file.
type Source ¶ added in v0.2.3
Source of a tweet, where the tweet was posted and who posted it.
func (Source) String ¶ added in v0.2.3
String represents the source as a mention string.
The mention syntax is pretty straightforward, if the source is missing a URI value, then the mention string is empty, as it is not possible to mention somebody by nickname alone, the URI is required.
@<URI> // e.g. @<https://alice.example.com/twtxt.txt> @<NICK URI> // e.g. @<bob https://bob.example.com/twtxt.txt>
See https://twtxt.readthedocs.io/en/latest/user/twtxtfile.html
type Timeline ¶ added in v0.2.3
type Timeline []Feed
Timeline of feeds.
func (Timeline) String ¶ added in v0.2.3
String formats the tweets of the timeline according to the twtxt registry format specification.
NICK\tURL\tTIMESTAMP\tMESSAGE
See https://twtxt.readthedocs.io/en/latest/user/registry.html
type Tweet ¶ added in v0.2.3
type Tweet struct { // Source of the tweet. Source // Time that the tweet was posted. Time time.Time // Text of the tweet. Text string }
Tweet represents a posted message, when it was posted, and where it was posted (if the source is known).
func NewTweet ¶ added in v0.2.3
NewTweet creates a new tweet from the given message with the time set to time.Now().
type Tweets ¶ added in v0.2.3
type Tweets []Tweet
Tweets are a collection of tweets.
func (Tweets) Less ¶ added in v0.2.3
Less reports whether the tweet at index i was posted before the tweet at j.