client

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2024 License: LGPL-3.0 Imports: 16 Imported by: 2

Documentation

Overview

Package client provides a client for interacting with vecchiochan.

It includes functionality for creating new threads and posting replies to existing threads, and allows for custom http.Client, logger, logging behavior, and User-Agent header.

Index

Constants

This section is empty.

Variables

View Source
var DefaultConfig = Config{
	Client:    &http.Client{Timeout: 30 * time.Second},
	Logger:    log.New(os.Stderr, "", log.LstdFlags),
	UserAgent: "",
	Verbose:   false,
}

DefaultConfig provides default values for a VecchioClient.

Functions

This section is empty.

Types

type Config

type Config struct {
	Client    *http.Client
	Logger    *log.Logger
	UserAgent string
	Verbose   bool
}

Config is used to customize the creation of a VecchioClient.

It holds configurations for the underlying HTTP client, logger, user-agent, and logging verbosity.

When Verbose is set to true, HTTP response codes as well as the submitted form and response are logged.

type Reply

type Reply struct {
	Thread   int      // ID of the thread to reply to (required)
	Board    string   // Board where the reply is to be posted (e.g., 'b') (required)
	Name     string   // Name of the poster
	Email    string   // Email of the poster
	Spoiler  bool     // Marks attached files as spoiler
	Body     string   // The message of the reply
	Embed    string   // URL for an embedded media link (YouTube, Spotify...)
	Password string   // Password used to delete or edit the reply
	Sage     bool     // Replaces email with 'rabbia' and prevents bumping the thread
	Files    []string // Paths of the files to attach to the reply
}

Reply represents a response to a thread on a specific board.

It includes details such as the thread ID, board name, and message of the reply.

Thread and Board are the only mandatory fields checked by the client but keep in mind that since each board has its own settings, more fields may be required (such as Body).

func (Reply) GetBoard

func (r Reply) GetBoard() string

GetBoard returns the name of the board where the reply is to be posted.

func (Reply) GetBody

func (r Reply) GetBody() string

GetBody returns the message of the reply.

func (Reply) GetEmail

func (r Reply) GetEmail() string

GetEmail returns the email of the poster.

func (Reply) GetEmbed

func (r Reply) GetEmbed() string

GetEmbed returns the embedded media URL associated with the reply.

func (Reply) GetFiles

func (r Reply) GetFiles() []string

GetFiles returns a list of paths of the files to be attached to the reply.

func (Reply) GetName

func (r Reply) GetName() string

GetName returns the name of the poster.

func (Reply) GetPassword

func (r Reply) GetPassword() string

GetPassword returns the password for editing or deleting the reply.

func (Reply) GetSage

func (r Reply) GetSage() bool

GetSage returns whether the reply will bump the thread.

func (Reply) GetSpoiler

func (r Reply) GetSpoiler() bool

GetSpoiler returns whether the attached files are to be marked as spoiler.

func (Reply) GetSubject

func (r Reply) GetSubject() string

GetSubject returns the subject of the reply (empty for replies).

func (Reply) GetThread

func (r Reply) GetThread() int

GetThread returns the ID of the thread to reply to.

type Thread

type Thread struct {
	Board    string   // Board where the thread is to be posted (e.g., 'b') (required)
	Name     string   // Name of the poster
	Email    string   // Email of the poster
	Subject  string   // Subject of the thread
	Spoiler  bool     // Marks attached files as spoiler
	Body     string   // The message of the thread
	Embed    string   // URL for an embedded media link (YouTube, Spotify...)
	Password string   // Password used to delete or edit the thread
	Sage     bool     // Replaces email with 'rabbia' and prevents bumping the thread
	Files    []string // Paths of the files to attach to the thread
}

Thread represents a thread on a specific board.

It includes details such as the board name, and message of the thread.

Board is the only mandatory field checked by the client but keep in mind that since each board has its own settings, more fields may be required (such as Body).

func (Thread) GetBoard

func (t Thread) GetBoard() string

GetBoard returns the name of the board where the thread is to be posted.

func (Thread) GetBody

func (t Thread) GetBody() string

GetBody returns the message of the thread.

func (Thread) GetEmail

func (t Thread) GetEmail() string

GetEmail returns the email of the poster.

func (Thread) GetEmbed

func (t Thread) GetEmbed() string

GetEmbed returns the embedded media URL associated with the thread.

func (Thread) GetFiles

func (t Thread) GetFiles() []string

GetFiles returns a list of paths of the files to be attached to the thread.

func (Thread) GetName

func (t Thread) GetName() string

GetName returns the name of the poster.

func (Thread) GetPassword

func (t Thread) GetPassword() string

GetPassword returns the password for editing or deleting the thread.

func (Thread) GetSage

func (t Thread) GetSage() bool

GetSage returns whether the thread will bump in the board.

func (Thread) GetSpoiler

func (t Thread) GetSpoiler() bool

GetSpoiler returns whether the attached files are to be marked as spoiler.

func (Thread) GetSubject

func (t Thread) GetSubject() string

GetSubject returns the subject of the thread.

func (Thread) GetThread

func (t Thread) GetThread() int

GetThread returns the ID of the thread to reply to (0 for threads).

type VecchioClient

type VecchioClient struct {
	// contains filtered or unexported fields
}

VecchioClient is a client for interacting with vecchiochan.

It allows for posting new threads and replies.

func NewVecchioClient

func NewVecchioClient() *VecchioClient

NewVecchioClient creates a new VecchioClient with default configuration.

It uses a default HTTP client, logger, and user-agent and only base logging will be shown unless otherwise configured.

See NewVecchioClientWithConfig to pass a custom configuration.

func NewVecchioClientWithConfig

func NewVecchioClientWithConfig(config Config) *VecchioClient

NewVecchioClientWithConfig creates a new VecchioClient using the provided configuration.

If any field in the config is nil or empty, it will fall back to the corresponding default value.

If no custom configuration is needed calling NewVecchioClient instead is enough.

func (*VecchioClient) NewThread

func (c *VecchioClient) NewThread(thread Thread) (int, error)

NewThread submits a new thread to vecchiochan.

The thread argument should contain all the necessary information for a new thread.

It returns the id of the newly-created thread or an error if the operation fails.

func (*VecchioClient) PostReply

func (c *VecchioClient) PostReply(reply Reply) (int, error)

PostReply submits a reply to an existing thread on vecchiochan.

The reply argument should contain all the necessary information for a reply.

It returns the id of the submitted reply or an error if the operation fails.

Jump to

Keyboard shortcuts

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