udpapi

package
v0.0.0-...-57d0119 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2014 License: MIT Imports: 16 Imported by: 3

Documentation

Overview

Low-level AniDB UDP API client library

Implements the commands essential to setting up and tearing down an API connection, as well as an asynchronous layer. Throttles sends internally according to API spec.

This library doesn't implement caching; beware since aggressive caching is an implementation requirement. Not doing so can get you banned.

Index

Constants

View Source
const (
	AniDBUDPServer = "api.anidb.net"
	AniDBUDPPort   = 9000
)

Variables

View Source
var TimeoutError = errors.New("Timeout")

The value APIReply.Error() returns after a timeout. Unrelated to the server-side error 604 TIMEOUT - DELAY AND RESUBMIT.

Functions

This section is empty.

Types

type APIError

type APIError struct {
	Code int
	Desc string
}

func (*APIError) Error

func (err *APIError) Error() string

type APIReply

type APIReply interface {
	// An opaque string used as identifying tag.
	Tag() string

	// The integer code for the reply.
	Code() int

	// The description for the reply (first line minus code).
	Text() string

	// Slice with all lines of the reply.
	Lines() []string

	// Indicates whether the network code detected truncation.
	Truncated() bool

	// Returns the underlying error, if any.
	Error() error
}

The interface for all UDP API replies.

The user should call Error() to verify if the API call completed successfully.

type AniDBUDP

type AniDBUDP struct {
	// Interval between keep-alive packets; only sent when PUSH notifications are enabled (default: 20 minutes)
	KeepAliveInterval time.Duration

	// The time to wait before a packet is considered lost (default: 45 seconds)
	Timeout time.Duration

	// Channel where PUSH notifications are sent to
	Notifications chan APIReply
	// contains filtered or unexported fields
}

func NewAniDBUDP

func NewAniDBUDP() *AniDBUDP

Creates and initializes the AniDBUDP struct

func (*AniDBUDP) Auth

func (a *AniDBUDP) Auth(user, password, udpKey string) (reply APIReply)

Authenticates the supplied user with the supplied password. Blocks until we have a reply. Needed before almost any other API command can be used.

If the udpKey is not "", then the connection will be encrypted, but the protocol's encryption uses the VERY weak ECB mode.

http://wiki.anidb.net/w/UDP_API_Definition#AUTH:_Authing_to_the_AnimeDB

http://wiki.anidb.net/w/UDP_API_Definition#ENCRYPT:_Start_Encrypted_Session

func (*AniDBUDP) Logout

func (a *AniDBUDP) Logout() (err error)

Ends the API session. Blocks until we have confirmation.

http://wiki.anidb.net/w/UDP_API_Definition#LOGOUT:_Logout

func (*AniDBUDP) Ping

func (a *AniDBUDP) Ping() <-chan *PingReply

Simple echo command. The recommended way to verify if the server is alive and responding. Does not require authentication.

Returns a channel through which the eventual response will be sent.

http://wiki.anidb.net/w/UDP_API_Definition#PING:_Ping_Command

func (*AniDBUDP) SendRecv

func (a *AniDBUDP) SendRecv(command string, args ParamMap) <-chan APIReply

Sends the requested query to the AniDB UDP API server.

Returns a channel through which the eventual reply is sent.

See http://wiki.anidb.net/w/UDP_API_Definition for the defined commands.

func (*AniDBUDP) Uptime

func (a *AniDBUDP) Uptime() <-chan *UptimeReply

Retrieves the server's uptime. The recommended way to verify if a session is valid.

Returns a channel through which the eventual response will be sent.

http://wiki.anidb.net/w/UDP_API_Definition#UPTIME:_Retrieve_Server_Uptime

type ParamMap

type ParamMap map[string]interface{}

Key-value list of parameters.

func (ParamMap) String

func (m ParamMap) String() string

Returns a query-like string representation of the ParamMap

type PingReply

type PingReply struct {
	APIReply
	Port uint16 // This client's local UDP port
}

type UptimeReply

type UptimeReply struct {
	APIReply
	Uptime time.Duration
}

Jump to

Keyboard shortcuts

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