Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/elias506/vk-sdk

Software development kit for VK API
https://github.com/elias506/vk-sdk

api go golang vk vk-sdk

Last synced: 3 months ago
JSON representation

Software development kit for VK API

Awesome Lists containing this project

README

        

# VK-SDK
[![Go Report Card](https://goreportcard.com/badge/github.com/elias506/vk-sdk)](https://goreportcard.com/report/github.com/elias506/vk-sdk)
![GitHub release (latest by date including pre-releases)](https://img.shields.io/github/v/release/elias506/vk-sdk?display_name=tag&include_prereleases)
![Lines of code](https://img.shields.io/tokei/lines/github/elias506/vk-sdk)
[![Contributors](https://img.shields.io/github/contributors/elias506/vk-sdk)](https://img.shields.io/github/contributors-anon/elias506/vk-sdk)
[![Go Reference](https://pkg.go.dev/badge/github.com/elias506/vk-sdk.svg)](https://pkg.go.dev/github.com/elias506/vk-sdk)
[![License](https://img.shields.io/github/license/elias506/vk-sdk)](https://img.shields.io/github/license/elias506/vk-sdk)

Package vk-sdk provides a **full generated** development kit to work
with [VKontakte API](https://dev.vk.com/method). The lack of reflection and using
[easyjson](https://github.com/mailru/easyjson) for objects represents a powerful performance.
**All** methods, error codes, objects and responses with provided descriptions are included.

Code was generated by using [fork](github.com/elias506/vk-api-schema) from official
[vk-api-schema](https://github.com/VKCOM/vk-api-schema). In other words, the package
is easy to maintain and can be comfortably used by consumers because of its comprehensive documentation.

### Contributing
We are welcome to new participants of the project. Feel free to create a
[bug](https://github.com/elias506/vk-sdk/issues/new?assignees=elias506&labels=bug&template=bug_report.md&title=)
or [enhancement](https://github.com/elias506/vk-sdk/issues/new?assignees=elias506&labels=enhancement&template=feature_request.md&title=)
issue and new [pull request](https://github.com/elias506/vk-sdk/pulls).

## Get started
### Install:
```sh
go get github.com/elias506/vk-sdk
```

## Examples
Look for full in `vk-sdk/example/example.go`:

**Get friends in online:**
```go
// Get new client instants with provided token
vk := vk_sdk.NewVK(http.DefaultClient, "")

// Get your online friend IDs
req := vk_sdk.Friends_GetOnline_Request{}

resp, apiErr, err := vk.Friends_GetOnline(context.Background(), req, vk_sdk.TestMode())

if err != nil || apiErr != nil {
log.Fatal()
}

fmt.Println("Online friends IDs:", resp.Response)
```

**Use Implicit/AuthCode flows to auth:**
```go
// Build auth request
authReq := vk_sdk.ImplicitFlowUserRequest{
ClientID: "",
//RedirectURI: "",
//Display: nil,
//Scope: nil,
//State: nil,
//Revoke: false,
}

// get redirect url for user
redirectURL := vk_sdk.GetAuthRedirectURL(authReq)

// wait user redirect...

// get token from redirect url
token, oAuthErr, err := vk_sdk.GetImplicitFlowUserToken()

if err != nil || oAuthErr != nil {
log.Fatal()
}
```

## Features
- `LimitClient` is `http.Client` implementation to do requests
with provided frequency
- Generated error codes with description, possible solution and links to subcodes.
For example:
```go
// Error_Request Invalid request.
// May contain one of the listed subcodes: [ UserReachedLinkedAccountsLimit, ServiceUuidLinkWithAnotherUser ].
// Solution: Check the request syntax (https://vk.com/dev/api_requests) and used parameters list (it can be found on a method description page).
// IsGlobal: true
Error_Request ErrorCode = 8
```
- Generated access permissions with specification.
For example:
````go
// UserPermissionWall Access to standard and advanced methods for the wall.
// Note that this access permission is unavailable for sites (it is ignored at attempt of authorization).
UserPermissionWall AccessPermission = 1 << 13
````
- Method descriptions contains
Schema specification, token types, additional error code links, and `dev.vk.com` method link.
For example:
```go
// Docs_Delete Deletes a user or community document.
// May execute with listed access token types:
// [ user ]
// When executing method, may return one of global or with listed codes API errors:
// [ Error_ParamDocDeleteAccess, Error_ParamDocId ]
//
// https://dev.vk.com/method/docs.delete
func (vk *VK) Docs_Delete(ctx context.Context, req Docs_Delete_Request, options ...Option) (resp Base_Ok_Response, apiErr ApiError, err error) {
values := make(url.Values, 4+len(options))
if err = req.fillIn(values); err != nil {
return
}
setOptions(values, options)
apiErr, err = vk.doReq("docs.delete", ctx, values, &resp)
return
}
```
- Every method contains implies presence context for internal client
and additional method option like response language, on/off application test mode
and captcha parameters.
- Enums generate extended name/value from vk-api-shcema.
For example:
```go
// Ads_AdCostType Cost type
type Ads_AdCostType int

const (
Ads_AdCostType_PerClicks Ads_AdCostType = 0
Ads_AdCostType_PerImpressions Ads_AdCostType = 1
Ads_AdCostType_PerActions Ads_AdCostType = 2
Ads_AdCostType_PerImpressionsOptimized Ads_AdCostType = 3
)
```
Here constant named `PerClicks` contains int value `0` and so on.
- Using [easyjson](https://github.com/mailru/easyjson) to work with api requests/responses
- There is up-to-date generated `vk-api` version

## Main idea
`vk-sdk` aims to be user-friendly due to the completeness of the generated code
and descriptions, and at the same time to show good executed speed.
This package reduces the amount of appeals to official API documentation for validating your request/response structure.
Just use right method. Right here.

In addition, code generation allows SDK developers to focus on improving
user experience and performance rather than fixing bugs and write large commits.
Any code change can be submitted and updated in all places just within a few seconds.

## Benchmarks
`go-vk-api/vk` use simple fields mapping without composition by method and execute with from-the-box speed.
In turn `SevereCloud/vksdk` use `reflect` package to add input data to request.

| lib | req/resp size | count | ns/op | B/op | allocs/op |
|:----------------------------|:--------------|-------------|-------:|--------:|----------:|
| vk-sdk | medium | 220738 | 5435 | 9064 | 60 |
| SevereCloud/vksdk | medium | 127970 | 9342 | 16165 | 117 |
| go-vk-api/vk | medium | 220962 | 5543 | 8787 | 64 |
| vk-sdk | small | 406672 | 2981 | 3424 | 44 |
| SevereCloud/vksdk | small | 271036 | 4420 | 5126 | 65 |
| go-vk-api/vk | small | 467112 | 2506 | 3129 | 41 |