vk

package module
v0.0.0-...-1cdc6cc Latest Latest
Warning

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

Go to latest
Published: May 12, 2020 License: MIT Imports: 16 Imported by: 0

README

vk

golang vk api

Build Status Coverage Status GoDoc License

Usage
go get github.com/ernado-legacy/vk
import "github.com/ernado-legacy/vk"

Documentation

Index

Constants

View Source
const (
	GroupOpen    GroupType = 0
	GroupClosed  GroupType = 1
	GroupPrivate GroupType = 2

	GroupDeactivated GroupDeactivatedStatus = "deleted"
	GroupBanned      GroupDeactivatedStatus = "banned"
	GroupActive      GroupDeactivatedStatus = ""
)
View Source
const UserFields = "id,first_name,last_name,sex,country,city,photo_max,last_seen"

UserFields all fields that are in User struct

Variables

View Source
var (
	Debug = false
)

Functions

func IsServerError

func IsServerError(err error) bool

Types

type APIClient

type APIClient interface {
	Do(request Request) (*Response, error)
}

APIClient preforms request and fills

type Auth

type Auth struct {
	ID           int64
	Scope        Scope
	RedirectURI  string
	ResponseType string
	Display      string
}

Auth is helper struct for application authentication

func (Auth) URL

func (a Auth) URL() string

URL returns redirect url for application authentication

type Bool

type Bool bool

Bool is special format for vk bool values that are represented as integers - 1,0

func (Bool) EncodeValues

func (b Bool) EncodeValues(key string, v *url.Values) error

func (Bool) MarshalJSON

func (v Bool) MarshalJSON() ([]byte, error)

func (*Bool) UnmarshalJSON

func (v *Bool) UnmarshalJSON(data []byte) error

type City

type City struct {
	ID    int    `json:"id"`
	Title string `json:"title"`
}

type Client

type Client struct {
	Groups Groups
	Video  Video
	// contains filtered or unexported fields
}

Client for vk api

func New

func New() *Client

New creates and returns default vk api client

func NewWithToken

func NewWithToken(token string) *Client

func (*Client) Do

func (c *Client) Do(request Request) (response *Response, err error)

func (*Client) SetHTTPClient

func (c *Client) SetHTTPClient(httpClient HTTPClient)

SetHTTPClient sets underlying http client

type Country

type Country struct {
	ID    CountryID `json:"id"`
	Title string    `json:"title"`
}

func (Country) Is

func (c Country) Is(id CountryID) bool

func (Country) String

func (country Country) String() string

type CountryID

type CountryID int
const (
	CountryUnknown CountryID = 0
	Russia         CountryID = 1
)

type Encoder

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

func Encode

func Encode(input io.Reader) Encoder

func (Encoder) To

func (e Encoder) To(v interface{}) error

type Error

type Error struct {
	Code    ServerError    `json:"error_code,omitempty"`
	Message string         `json:"error_msg,omitempty"`
	Params  []RequestParam `json:"request_params,omitempty"`
	Request Request        `json:"-"`
}

func GetServerError

func GetServerError(err error) Error

func (Error) Error

func (e Error) Error() string

type ErrorResponse

type ErrorResponse struct {
	Error Error `json:"error"`
}

type Errors

type Errors []ExecuteError

func (Errors) Error

func (e Errors) Error() string

type ExecuteError

type ExecuteError struct {
	Method  string      `json:"method"`
	Code    ServerError `json:"error_code"`
	Message string      `json:"error_msg"`
}

func (ExecuteError) Error

func (e ExecuteError) Error() string

type Factory

type Factory struct {
	Token string
}

RequestFactory generates requests

func (Factory) Request

func (f Factory) Request(method string, arguments interface{}) (request Request)

Request generate new request with provided method and arguments

type Group

type Group struct {
	ID           int                    `json:"id"`
	Name         string                 `json:"name`
	Slug         string                 `json:"screen_name"`
	Deactivated  GroupDeactivatedStatus `json:"deactivated"`
	IsClosed     GroupType              `json:"is_closed"`
	IsAdmin      Bool                   `json:"is_admin"`
	IsMember     Bool                   `json:"is_member"`
	AdminLevel   GroupAdminLevel        `json:"admin_level"`
	Type         string                 `json:"type"`
	Photo50      string                 `json:"photo_50"`
	Photo100     string                 `json:"photo_100"`
	Photo200     string                 `json:"photo_200"`
	Description  string                 `json:"description"`
	MembersCount int                    `json:"members_count"`
	Status       string                 `json:"status"`
}

func (Group) GetStatus

func (g Group) GetStatus() string

func (Group) String

func (g Group) String() string

type GroupAdminLevel

type GroupAdminLevel int
const (
	GroupModerator     GroupAdminLevel = 1
	GroupRedactor      GroupAdminLevel = 2
	GroupAdministrator GroupAdminLevel = 3
)

func (GroupAdminLevel) String

func (i GroupAdminLevel) String() string

type GroupDeactivatedStatus

type GroupDeactivatedStatus string

type GroupGetFields

type GroupGetFields struct {
	Offset   int    `url:"offset,omitempty"`
	Count    int    `url:"count,omitempty"`
	UserID   int    `url:"user_id,omitempty"`
	GroupID  int    `url:"group_id,omitempty"`
	Extended Bool   `url:"extended,omitempty"`
	Fields   string `url:"fields,omitempty"`
}

type GroupGetResult

type GroupGetResult struct {
	Count int     `json:"count"`
	Items []Group `json:"items"`
}

type GroupSearchFields

type GroupSearchFields struct {
	ID int `structs:"id"`
}

type GroupSearchResult

type GroupSearchResult struct {
	Count int    `json:"count"`
	Items []User `json:"items"`
}

type GroupType

type GroupType int

func (GroupType) String

func (i GroupType) String() string

type Groups

type Groups struct {
	Resource
}

func (Groups) Get

func (g Groups) Get(fields GroupGetFields) (result GroupGetResult, err error)

func (Groups) GetBatch

func (g Groups) GetBatch(getFields GroupGetFields) ([]User, int, error)

batch get

func (Groups) GetForUser

func (g Groups) GetForUser(id int) ([]Group, error)

func (Groups) GetMembers

func (g Groups) GetMembers(q GroupSearchFields) (result GroupSearchResult, err error)

type HTTPClient

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

HTTPClient is abstaction under http client, that can Do requests

type Permission

type Permission string

Permission of application

const (
	PermOffline Permission = "offline"
	PermFriends Permission = "friends"
	PermPhotos  Permission = "photos"
	PermGroups  Permission = "groups"
)

func (Permission) String

func (p Permission) String() string

type Raw

type Raw []byte

RawString is a raw encoded JSON object. It implements Marshaler and Unmarshaler and can be used to delay JSON decoding or precompute a JSON encoding.

func (Raw) Bytes

func (r Raw) Bytes() []byte

func (Raw) MarshalJSON

func (m Raw) MarshalJSON() ([]byte, error)

MarshalJSON returns *m as the JSON encoding of m.

func (Raw) String

func (r Raw) String() string

func (*Raw) UnmarshalJSON

func (m *Raw) UnmarshalJSON(data []byte) error

UnmarshalJSON sets *m to a copy of data.

type Relation

type Relation int
const (
	RelationUnknown      Relation = 0
	RelationSingle       Relation = 1
	RelationHasFriend    Relation = 2
	RelationEngaged      Relation = 3
	RelationMarried      Relation = 4
	RelationComplicated  Relation = 5
	RelationActiveSearch Relation = 6
	RelationInLove       Relation = 7
)

func (Relation) String

func (i Relation) String() string

type Request

type Request struct {
	Method string     `json:"method"`
	Token  string     `json:"token"`
	Values url.Values `json:"values"`
}

Request to vk api serializable

func (Request) HTTP

func (r Request) HTTP() (req *http.Request)

HTTP converts to *http.Request

func (Request) JS

func (r Request) JS() string

type RequestFactory

type RequestFactory interface {
	Request(method string, arguments interface{}) (request Request)
}
var (
	// DefaultClient uses defaultHTTPClient for transport
	DefaultClient = New()
	// DefaultFactory with blank token
	DefaultFactory RequestFactory = Factory{}
)

type RequestParam

type RequestParam struct {
	Key   string `json:"key"`
	Value string `json:"value"`
}

type Resource

type Resource struct {
	APIClient
	RequestFactory
}

func (Resource) Decode

func (r Resource) Decode(request Request, v interface{}) error

type Response

type Response struct {
	Errors   Errors `json:"execute_errors,omitempty"`
	Error    `json:"error,omitempty"`
	Response Raw `json:"response,omitempty"`
}

func Process

func Process(input io.Reader) (response *Response, err error)

func (Response) ServerError

func (r Response) ServerError() error

func (Response) To

func (r Response) To(v interface{}) error

type ResponseProcessor

type ResponseProcessor interface {
	To(response *Response, err error)
}

ResponseProcessor fills response struct from response

type Scope

type Scope map[Permission]bool

func NewScope

func NewScope(permissions ...Permission) Scope

func (Scope) Add

func (s Scope) Add(permissions ...Permission)

func (Scope) Del

func (s Scope) Del(permissions ...Permission)

func (Scope) Has

func (s Scope) Has(p Permission) bool

func (Scope) String

func (s Scope) String() string

type ServerError

type ServerError int
const (
	// Possible error codes
	// https://vk.com/dev/errors
	ErrZero ServerError = iota
	ErrUnknown
	ErrApplicationDisabled
	ErrUnknownMethod
	ErrInvalidSignature
	ErrAuthFailed
	ErrTooManyRequests
	ErrInsufficientPermissions
	ErrInvalidRequest
	ErrTooManyOneTypeRequests
	ErrInternalServerError
	ErrAppInTestMode
	ErrCaptchaNeeded
	ErrNotAllowed
	ErrHttpsOnly
	ErrNeedValidation
	ErrStandaloneOnly
	ErrStandaloneOpenAPIOnly
	ErrMethodDisabled
	ErrNeedConfirmation
	ErrOneOfParametersInvalid    ServerError = 100
	ErrInvalidAPIID              ServerError = 101
	ErrInvalidAUserID            ServerError = 113
	ErrInvalidTimestamp          ServerError = 150
	ErrAlbumAccessProhibited     ServerError = 200
	ErrGroupAccessProhibited     ServerError = 203
	ErrAlbumOverflow             ServerError = 300
	ErrMoneyTransferNotAllowed   ServerError = 500
	ErrInsufficientPermissionsAd ServerError = 600
	ErrInternalServerErrorAd     ServerError = 603

	ErrBadResponseCode ServerError = -1
)

func (ServerError) Error

func (s ServerError) Error() string

func (ServerError) Is

func (e ServerError) Is(err error) bool

Is returns true, if err equals (or is Error with code equals) e

func (ServerError) String

func (i ServerError) String() string

type Sex

type Sex int

Sex of a user

const (
	SexUnknown Sex = 0
	Female     Sex = 1
	Male       Sex = 2
)

func (Sex) String

func (sex Sex) String() string

type User

type User struct {
	ID        int     `json:"id"`
	FirstName string  `json:"first_name"`
	LastName  string  `json:"last_name"`
	Sex       Sex     `json:"sex"`
	Country   Country `json:"country"`
	City      City    `json:"city"`
	Hidden    Bool    `json:"hidden"`
	Birthday  string  `json:"bdate"`
	PhotoMax  string  `json:"photo_max"`
	Status    string  `json:"status"`
	LastSeen  struct {
		Time     int64 `json:"time"`
		Platform int   `json:"platform"`
	} `json:"last_seen"`
	Books string `json:"books"`
	About string `json:"about"`
}

type Video

type Video struct {
	Resource
}

func (Video) Get

func (v Video) Get(fields VideoGetFields) (result VideoGetResult, err error)

type VideoFiles

type VideoFiles struct {
	External string `json:"external"`
}

type VideoGetFields

type VideoGetFields struct {
	Offset   int    `url:"offset,omitempty"`
	Count    int    `url:"count,omitempty"`
	Extended Bool   `url:"extended,omitempty"`
	Videos   string `url:"videos,omitempty"`
}

type VideoGetResult

type VideoGetResult struct {
	Count int         `json:"count"`
	Items []VideoItem `json:"items"`
}

type VideoImage

type VideoImage struct {
	Height int    `json:"height"`
	Width  int    `json:"width"`
	URL    string `json:"url"`
}

func (*VideoImage) UnmarshalJSON

func (v *VideoImage) UnmarshalJSON(b []byte) error

type VideoItem

type VideoItem struct {
	Duration int          `json:"duration"`
	Player   string       `json:"player"`
	Files    VideoFiles   `json:"files"`
	Images   []VideoImage `json:"image"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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