client

package
v0.0.0-...-7609c90 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2021 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultURI is the default base URI to use for the Twtxt API endpoint
	DefaultURI = "http://localhost:8000/api/v1/"
)

Variables

View Source
var (
	// DefaultUserAgent ...
	DefaultUserAgent = fmt.Sprintf("twt/%s", twtxt.FullVersion())

	// ErrBadRequest ...
	ErrBadRequest = errors.New("error: bad request")

	// ErrUnauthorized ...
	ErrUnauthorized = errors.New("error: authorization failed")

	// ErrServerError
	ErrServerError = errors.New("error: server error")
)

Functions

This section is empty.

Types

type Client

type Client struct {
	BaseURL   *url.URL
	Config    *Config
	UserAgent string
	// contains filtered or unexported fields
}

Client ...

func NewClient

func NewClient(options ...Option) (*Client, error)

NewClient ...

func (*Client) Login

func (c *Client) Login(username, password string) (res types.AuthResponse, err error)

Login ...

func (*Client) Post

func (c *Client) Post(text string) (res types.AuthResponse, err error)

Post ...

func (*Client) Timeline

func (c *Client) Timeline(page int) (res types.PagedResponse, err error)

Timeline ...

type Config

type Config struct {
	URI   string `yaml:"uri"`
	Token string `yaml:"token"`
}

Config contains the client configuration parameters

func Load

func Load(path string) (*Config, error)

Load loads a configuration from the given path

func NewConfig

func NewConfig() *Config

NewConfig ...

func (*Config) Save

func (c *Config) Save(path string) error

Save saves the configuration to the provided path

type Option

type Option func(*Config) error

Option is a function that takes a config struct and modifies it

func WithToken

func WithToken(token string) Option

WithToken sets the API token to use for authenticating to Twtxt endpoints

func WithURI

func WithURI(uri string) Option

WithURI sets the base URI to used for the Twtxt API endpoint

Jump to

Keyboard shortcuts

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