twtr

package
v0.2.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 24, 2022 License: Unlicense Imports: 12 Imported by: 0

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

View Source
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

func (client *Client) Fetch(source Source) (feed Feed, err error)

Fetch a twtxt feed from the given source.

Returns any error that occurs while fetching or parsing the feed.

func (*Client) Post

func (client *Client) Post(tweet string) (err error)

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.

func (Feed) String added in v0.2.3

func (feed Feed) String() string

String formats the feed as a file representing the tweets and the metadata specified.

func (Feed) WriteTo added in v0.2.3

func (feed Feed) WriteTo(w io.Writer) (n int64, err error)

WriteTo formats the feed as a file representing the tweets and the metadata specified.

type Source added in v0.2.3

type Source struct {
	Nick string
	URI  string
}

Source of a tweet, where the tweet was posted and who posted it.

func (Source) String added in v0.2.3

func (source Source) String() string

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

func (timeline Timeline) String() string

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

func (Timeline) Tweets added in v0.2.3

func (timeline Timeline) Tweets() Tweets

Tweets of the timeline's feeds.

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

func NewTweet(message string) Tweet

NewTweet creates a new tweet from the given message with the time set to time.Now().

func (Tweet) String added in v0.2.3

func (tweet Tweet) String() string

String formats the tweet as a string representing the tweet according to the twtxt.txt file specification.

func (Tweet) WriteTo added in v0.2.3

func (tweet Tweet) WriteTo(w io.Writer) (n int64, err error)

WriteTo writes the tweet to the given writer according to the twtxt.txt file specification.

TIMESTAMP\tMESSAGE\n

See also: https://twtxt.readthedocs.io/en/latest/user/twtxtfile.html

type Tweets added in v0.2.3

type Tweets []Tweet

Tweets are a collection of tweets.

func (Tweets) Len added in v0.2.3

func (tweets Tweets) Len() int

Len reports the number of tweets.

func (Tweets) Less added in v0.2.3

func (tweets Tweets) Less(i, j int) bool

Less reports whether the tweet at index i was posted before the tweet at j.

func (Tweets) String added in v0.2.3

func (tweets Tweets) String() string

String formats the tweets as a string representing all the tweets according to the twtxt.txt file specification.

func (Tweets) Swap added in v0.2.3

func (tweets Tweets) Swap(i, j int)

Swap the tweet with index i for the tweet with index j.

Directories

Path Synopsis
Package parse provides lexical analysis and parsing methods for twtr.
Package parse provides lexical analysis and parsing methods for twtr.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL