misskey

package
v1.2.5 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2023 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ResponseReadError occues when error happened while we tried to
	// read the response.
	ResponseReadError = "Error reading body"
	// ResponseReadBodyError occues when error happened while we tried to
	// read the body of the response.
	ResponseReadBodyError = "Error reading body"
	// ErrorResponseParseError occues when the response was an error,
	// but something went wrong with parsing it as an Error.
	ErrorResponseParseError = "Error response parse error"
)
View Source
const RequestTimout = 10

RequestTimout is the timeout of a request in seconds.

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseRequest

type BaseRequest struct {
	APIToken string
	Path     string
	Request  interface{}
}

BaseRequest is the base request.

func (*BaseRequest) SetAPIToken

func (r *BaseRequest) SetAPIToken(token string)

SetAPIToken stores the API key for a Misskey User.

func (BaseRequest) ToJSON

func (r BaseRequest) ToJSON() ([]byte, error)

ToJSON returns with the JSON []byte representation of the request.

type Client

type Client struct {
	BaseURL    string
	Token      string
	HTTPClient HTTPClient
}

Client is the main Misskey client struct.

func NewClient

func NewClient(baseURL, token string) *Client

NewClient creates a new Misskey Client.

func (*Client) CreateFile added in v1.2.0

func (c *Client) CreateFile(content []byte, name string) (*FileCreateResponse, error)

CreateFile sends a request to the Misskey server to create a file.

func (*Client) CreateFileFromURL added in v1.2.0

func (c *Client) CreateFileFromURL(url, name string) (*FileCreateResponse, error)

CreateFileFromURL sends a request to the Misskey server to create a file from a URL.

func (*Client) CreateNote

func (c *Client) CreateNote(content string, file *FileCreateResponse) error

CreateNote sends a request to the Misskey server to create a note.

type ClientInterface

type ClientInterface interface {
	CreateNote(content string, file *FileCreateResponse) error
	CreateFile(content []byte, name string) (*FileCreateResponse, error)
	CreateFileFromURL(url, name string) (*FileCreateResponse, error)
}

ClientInterface is an interface to describe how a Client looks like. Mostly for Mocking. Or later if Misskey gets multiple API versions.

type ErrorResponse

type ErrorResponse struct {
	Message string `json:"message"`
	Code    string `json:"code"`
	ID      string `json:"id"`
	Kind    string `json:"kind"`
	Info    struct {
		Param  string `json:"param"`
		Reason string `json:"reason"`
	} `json:"info"`
}

ErrorResponse represents any kind of Error responses from Misskey.

type FileCreateRequest added in v1.2.0

type FileCreateRequest struct {
	*BaseRequest
	FolderID  string
	Name      string
	Sensitive bool
	Force     bool
	Content   []byte
}

FileCreateRequest represents a CreateNote request.

func (*FileCreateRequest) Multipart added in v1.2.0

func (f *FileCreateRequest) Multipart(iToken string) (*bytes.Buffer, string)

Multipart retruns with the multipart body and FormDataContentType.

type FileCreateResponse added in v1.2.0

type FileCreateResponse struct {
	ID        string `json:"id"`
	CreatedAt string `json:"createdAt"`
	Name      string `json:"name"`
	Type      string `json:"type"`
	MD5       string `json:"md5"`
	Size      uint   `json:"size"`
	URL       string `json:"url"`
	FolderID  string `json:"folderId"`
	Sensitive bool   `json:"isSensitive"`
}

FileCreateResponse is the response structure of a file creation request.

type HTTPClient

type HTTPClient interface {
	Do(req *http.Request) (*http.Response, error)
}

HTTPClient is a simple intreface for http.Client.

type MultipartRequest added in v1.2.0

type MultipartRequest interface {
	Multipart(token string) (*bytes.Buffer, string)
}

MultipartRequest is an interface for multipart form requests.

type NoteCreateRequest

type NoteCreateRequest struct {
	*BaseRequest
	Visibility        string   `json:"visibility"`
	VisibleUserIDs    []string `json:"visibleUserIds,omitempty"`
	Text              string   `json:"text,omitempty"`
	CW                string   `json:"cw,omitempty"`
	ViaMobile         bool     `json:"viaMobile"`
	LocalOnly         bool     `json:"localOnly"`
	NoExtractMentions bool     `json:"noExtractMentions"`
	NoExtractHashtags bool     `json:"noExtractHashtags"`
	NoExtractEmojis   bool     `json:"noExtractEmojis"`
	FileIDs           []string `json:"fileIds,omitempty"`
	ReplyID           string   `json:"replyId,omitempty"`
	RenoteID          string   `json:"renoteId,omitempty"`
	Poll              *Poll    `json:"poll,omitempty"`
}

NoteCreateRequest represents a CreateNote request.

type Poll

type Poll struct {
	Choices      []string `json:"choices,omitempty"`
	Multiple     bool     `json:"multiple,omitempty"`
	ExpiresAt    uint     `json:"expiresAt,omitempty"`
	ExpiredAfter uint     `json:"expiredAfter,omitempty"`
}

Poll represents a Poll data structure for Misskey.

type RequestError

type RequestError struct {
	Message string
	Origin  error
}

RequestError happens when something went wrong with the request.

func (RequestError) Error

func (e RequestError) Error() string

type UnknownError

type UnknownError struct {
	Response ErrorResponse
}

UnknownError occues when we coudn't determine the source of the error.

func (UnknownError) Error

func (e UnknownError) Error() string

Jump to

Keyboard shortcuts

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