apisdk

package module
v0.0.0-...-0ffe453 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MemberJoined = "member.joined"
	MemberLeft   = "member.left"
	MemberList   = "member.list"

	MessageReceived = "message.received"
	MessageDeleted  = "message.deleted"

	ErrorEvent          = "error"
	AuthenticationError = "error.auth"
	JoinFailed          = "error.join"
	RateLimited         = "error.rate_limited"
	Kicked              = "error.kicked"

	RoomDeleted = "room.deleted"
)

Variables

View Source
var (
	ErrMissingIDParameter       = errors.New("missing required id parameter")
	ErrMissingJoinCodeParameter = errors.New("missing required join code parameter")
	ErrMissingUsername          = errors.New("missing required username parameter")
)

Functions

func Bool

func Bool(value bool) param.Field[bool]

Bool is a param field helper which helps specify bools.

func DefaultClientOptions

func DefaultClientOptions() []option.RequestOption

func F

func F[T any](value T) param.Field[T]

F is a param field helper used to initialize a param.Field generic struct. This helps specify null, zero values, and overrides, as well as normal values. You can read more about this in our README.

func FileParam

func FileParam(reader io.Reader, filename string, contentType string) param.Field[io.Reader]

FileParam is a param field helper which helps files with a mime content-type.

func Float

func Float(value float64) param.Field[float64]

Float is a param field helper which helps specify floats.

func Int

func Int(value int64) param.Field[int64]

Int is a param field helper which helps specify integers. This is particularly helpful when specifying integer constants for fields.

func Null

func Null[T any]() param.Field[T]

Null is a param field helper which explicitly sends null to the API.

func Raw

func Raw[T any](value any) param.Field[T]

Raw is a param field helper for specifying values for fields when the type you are looking to send is different from the type that is specified in the SDK. For example, if the type of the field is an integer, but you want to send a float, you could do that by setting the corresponding field with Raw[int](0.5).

func String

func String(value string) param.Field[string]

String is a param field helper which helps specify strings.

Types

type BootPayload

type BootPayload struct {
	Username string `json:"username"`
	Reason   string `json:"reason"`
}

type Client

type Client struct {
	Options []option.RequestOption
	Room    *RoomService
	Message *MessageService
	Health  *HealthService
}

func NewClient

func NewClient(opts ...option.RequestOption) *Client

func (*Client) Delete

func (c *Client) Delete(ctx context.Context, path string, params, res any, opts ...option.RequestOption) error

func (*Client) Execute

func (c *Client) Execute(ctx context.Context, method, path string, params, res any, opts ...option.RequestOption) error

func (*Client) Get

func (c *Client) Get(ctx context.Context, path string, params, res any, opts ...option.RequestOption) error

func (*Client) Post

func (c *Client) Post(ctx context.Context, path string, params, res any, opts ...option.RequestOption) error

func (*Client) Put

func (c *Client) Put(ctx context.Context, path string, params, res any, opts ...option.RequestOption) error

type Error

type Error = apierror.Error

type ErrorPayload

type ErrorPayload struct {
	Code    string `json:"code,omitempty"`
	Message string `json:"message"`
	Retry   bool   `json:"retry,omitempty"`
}

type HealthResponse

type HealthResponse struct {
	Status string `json:"status"`
	Time   string `json:"time"`
}

func (*HealthResponse) UnmarshalJSON

func (r *HealthResponse) UnmarshalJSON(data []byte) error

type HealthService

type HealthService struct {
	Options []option.RequestOption
}

func NewHealthService

func NewHealthService(opts ...option.RequestOption) *HealthService

func (*HealthService) Get

Get retrieves the health status of the API

type JoinByCodeParams

type JoinByCodeParams struct {
	JoinCode string `json:"join_code"` // 6-character join code
	Username string `json:"username,omitempty"`
}

func (*JoinByCodeParams) MarshalJSON

func (r *JoinByCodeParams) MarshalJSON() ([]byte, error)

type JoinRoomParams

type JoinRoomParams struct {
	Username string `json:"username,omitempty"`
}

func (*JoinRoomParams) MarshalJSON

func (r *JoinRoomParams) MarshalJSON() ([]byte, error)

type MemberListPayload

type MemberListPayload struct {
	Members []MemberPayload `json:"members"`
}

type MemberPayload

type MemberPayload struct {
	UserID   string `json:"userId"`
	Username string `json:"username"`
	JoinedAt string `json:"joinedAt,omitempty"`
}

type MembershipResponse

type MembershipResponse struct {
	IsMember bool   `json:"is_member"`
	RoomID   string `json:"room_id"`
	UserID   string `json:"user_id,omitempty"`
}

func (*MembershipResponse) UnmarshalJSON

func (r *MembershipResponse) UnmarshalJSON(data []byte) error

type MessageCountResponse

type MessageCountResponse struct {
	RoomID string `json:"room_id"`
	Count  int64  `json:"count"`
}

func (*MessageCountResponse) UnmarshalJSON

func (r *MessageCountResponse) UnmarshalJSON(data []byte) error

type MessageDeletedPayload

type MessageDeletedPayload struct {
	MessageID string `json:"id"`
}

type MessageListAfterParams

type MessageListAfterParams struct {
	Timestamp time.Time
	Limit     int64 // Optional, defaults to 100 on server
}

type MessageListParams

type MessageListParams struct {
	Limit int64 // Optional, defaults to 50 on server
}

type MessagePayload

type MessagePayload struct {
	ID        string `json:"id"`
	Content   string `json:"content"`
	UserID    string `json:"userId"`
	Username  string `json:"username"`
	Timestamp string `json:"timestamp"`
}

type MessageResponse

type MessageResponse struct {
	ID        string    `json:"id"`
	RoomID    string    `json:"room_id"`
	UserID    string    `json:"user_id"`
	Username  string    `json:"username"`
	Content   string    `json:"content"`
	CreatedAt time.Time `json:"created_at"`
}

func (*MessageResponse) UnmarshalJSON

func (r *MessageResponse) UnmarshalJSON(data []byte) error

type MessageService

type MessageService struct {
	Options []option.RequestOption
}

func NewMessageService

func NewMessageService(opts ...option.RequestOption) *MessageService

func (*MessageService) Count

Count retrieves the message count for a room

func (*MessageService) List

List retrieves messages from a room with optional limit

func (*MessageService) ListAfter

ListAfter retrieves messages after a specific timestamp

func (*MessageService) Send

Send sends a message to a room

type MessagesResponse

type MessagesResponse struct {
	Messages []MessageResponse `json:"messages"`
	Count    int               `json:"count"`
	RoomID   string            `json:"room_id"`
}

func (*MessagesResponse) UnmarshalJSON

func (r *MessagesResponse) UnmarshalJSON(data []byte) error

type RoomCreateParams

type RoomCreateParams struct {
	ExpiryHours int `json:"expiry_hours"` // 1 to 168 hours (1 hour to 7 days)
}

func (*RoomCreateParams) MarshalJSON

func (r *RoomCreateParams) MarshalJSON() ([]byte, error)

type RoomDeletedPayload

type RoomDeletedPayload struct {
	RoomID string `json:"roomid"`
}

type RoomResponse

type RoomResponse struct {
	ID          string         `json:"id"`
	JoinCode    string         `json:"join_code"`
	Owner       UserResponse   `json:"owner"`
	CreatedAt   time.Time      `json:"created_at"`
	ExpiresAt   time.Time      `json:"expires_at"`
	Members     []UserResponse `json:"members"`
	CurrentUser UserResponse   `json:"current_user"`
}

func (*RoomResponse) UnmarshalJSON

func (r *RoomResponse) UnmarshalJSON(data []byte) error

type RoomService

type RoomService struct {
	Options []option.RequestOption
}

func NewRoomService

func NewRoomService(opts ...option.RequestOption) *RoomService

func (*RoomService) CheckMembership

func (r *RoomService) CheckMembership(ctx context.Context, id string, opts ...option.RequestOption) (*MembershipResponse, error)

CheckMembership checks if the current user is a member of a room

func (*RoomService) ConnectWebSocket

func (r *RoomService) ConnectWebSocket(
	ctx context.Context,
	roomID string,
	opts ...option.RequestOption,
) (*RoomWebSocket, error)

func (*RoomService) Create

Create creates a new room with specified expiry hours

func (*RoomService) Delete

func (r *RoomService) Delete(ctx context.Context, id string, opts ...option.RequestOption) error

Delete deletes a room (only owner can delete)

func (*RoomService) Get

func (r *RoomService) Get(ctx context.Context, id string, opts ...option.RequestOption) (*RoomResponse, error)

Get retrieves a room by ID

func (*RoomService) GetByJoinCode

func (r *RoomService) GetByJoinCode(ctx context.Context, body JoinByCodeParams, opts ...option.RequestOption) (*RoomResponse, error)

GetByJoinCode retrieves a room by join code and joins the user to it

func (*RoomService) Join

Join joins an existing room by room ID

func (*RoomService) KickMember

func (r *RoomService) KickMember(ctx context.Context, roomID, userID string, opts ...option.RequestOption) (*SuccessResponse, error)

KickMember kicks a member from the room (only owner can kick)

func (*RoomService) Leave

func (r *RoomService) Leave(ctx context.Context, id string, opts ...option.RequestOption) (*SuccessResponse, error)

Leave leaves a room

type RoomWebSocket

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

func (*RoomWebSocket) Close

func (ws *RoomWebSocket) Close() error

func (*RoomWebSocket) Listen

func (ws *RoomWebSocket) Listen(ctx context.Context) error

func (*RoomWebSocket) SendMessage

func (ws *RoomWebSocket) SendMessage(content string) error

func (*RoomWebSocket) SetErrorHandler

func (ws *RoomWebSocket) SetErrorHandler(handler func(error))

func (*RoomWebSocket) SetMessageHandler

func (ws *RoomWebSocket) SetMessageHandler(handler func(WSMessage))

type SendMessageParams

type SendMessageParams struct {
	Content string `json:"content"` // Max 1000 characters
}

func (*SendMessageParams) MarshalJSON

func (r *SendMessageParams) MarshalJSON() ([]byte, error)

type SuccessResponse

type SuccessResponse struct {
	Message string         `json:"message"`
	Data    map[string]any `json:"data,omitempty"`
}

func (*SuccessResponse) UnmarshalJSON

func (r *SuccessResponse) UnmarshalJSON(data []byte) error

type UserResponse

type UserResponse struct {
	ID       string `json:"id"`
	Username string `json:"username"`
}

type WSMessage

type WSMessage struct {
	Type   string `json:"type"`
	RoomID string `json:"roomId"`
	Data   any    `json:"data"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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