longpoll

package
v0.0.0-...-014d9b8 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2020 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultVersion is a default version of the VK Long Poll API.
	DefaultVersion = 2
	// DefaultWait is a waiting period. Maximum: 90.
	DefaultWait = 25
	// DefaultMode is an additional answer options.
	DefaultMode = ReceiveAttachments
)
View Source
const (
	EventNewMessage = 4
)

Event codes.

Variables

View Source
var (
	ErrEventHistoryOutdated = errors.New("event history outdated")
	ErrKeyExpired           = errors.New("key expired")
	ErrUserInformationLost  = errors.New("user information lost")
	ErrInvalidVersion       = errors.New("invalid version")
)

Functions

This section is empty.

Types

type Longpoll

type Longpoll struct {
	Key     string
	Server  string
	Wait    int64
	Mode    Mode
	Version int64

	NeedPts int64
	GroupID int64
	// contains filtered or unexported fields
}

Longpoll manages communication with VK User Long Poll API.

func New

func New(client *vk.Client) (*Longpoll, error)

New initializes a new longpoll client with default values.

func NewWithOptions

func NewWithOptions(client *vk.Client, options ...Option) (*Longpoll, error)

NewWithOptions initializes a new longpoll client with default values. It takes functors to modify values when creating it, like `NewWithOptions(WithMode(…))`.

func (*Longpoll) GetUpdatesStream

func (lp *Longpoll) GetUpdatesStream(ts int64) (*Stream, error)

GetUpdatesStream starts and returns a stream of updates.

func (*Longpoll) Poll

func (lp *Longpoll) Poll(ts int64) (updates []*Update, newTS int64, err error)

Poll requests updates starting with the ts and returns a new updates and ts.

func (*Longpoll) UpdateServer

func (lp *Longpoll) UpdateServer() (newTs int64, err error)

UpdateServer updates the longpoll server and returns a new ts.

type Mode

type Mode int64

Mode represents the additional answer options.

const (
	ReceiveAttachments           Mode = 2
	ReturnExpandedSetOfEvents    Mode = 8
	ReturnPts                    Mode = 32
	ReturnFriendOnlineExtraField Mode = 64
	ReturnRandomID               Mode = 128
)

type NewMessage

type NewMessage struct {
	ID          int64
	Flags       int64
	PeerID      int64
	Timestamp   int64
	Text        string
	Attachments map[string]string
	RandomID    int64
}

NewMessage represents the information an event EventNewMessage contains.

type Option

type Option func(*Longpoll) error

Option is a configuration option to initialize a longpoll.

func WithMode

func WithMode(m Mode) Option

WithMode overrides the longpoll mode with the specified one.

type Stream

type Stream struct {
	TS int64

	Updates <-chan *Update
	Errors  <-chan error
	// contains filtered or unexported fields
}

Stream represents a stream of events the VK User Longpoll API.

func (*Stream) Start

func (s *Stream) Start() error

Start starts a channel for getting updates.

func (*Stream) Stop

func (s *Stream) Stop()

Stop stops the stream.

type Update

type Update struct {
	Type    int64
	Data    interface{}
	RawData json.RawMessage
}

Update represents the information an event contains.

func (*Update) Unmarshal

func (update *Update) Unmarshal(outputStruct interface{}) error

Unmarshal parses JSON-encoded update.RawData and stores the result in the struct value pointed to by outputStruct.

func (*Update) UnmarshalJSON

func (update *Update) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

Jump to

Keyboard shortcuts

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