sdkutil

package module
v3.0.0-alpha Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2021 License: MIT Imports: 2 Imported by: 0

README

VK SDK Utilities

CI Documentation codecov license

Some useful things for vksdk

Features

Middleware example

package main

import (
  "github.com/SevereCloud/vksdk/v2/api"
  sdkutil "github.com/tdakkota/vksdkutil/v3"
  "github.com/tdakkota/vksdkutil/v3/middleware/zapvk"
  "go.uber.org/zap"
  "go.uber.org/zap/zapcore"
)

func main() {
  vk := sdkutil.BuildSDK("token").WithMiddleware(
    zapvk.Log(zap.L(), zapcore.DebugLevel, true),
  ).Complete()
  // ...
}

Testing example

You have a file

package mypackage

import (
    "github.com/SevereCloud/vksdk/api"
)

func MarkAsRead(sdk *api.VK, peerID int) (int, error) {
    builder := params.NewMessagesMarkAsReadBuilder()
    builder.PeerID(peerID)
    
    return sdk.MessagesMarkAsRead(builder.Params)
}

So, with testutil you can test it

package mypackage

import (
    "testing"

    "github.com/tdakkota/vksdkutil/testutil"
)

func TestMarkAsRead(t *testing.T) {
	sdk, expect := testutil.CreateSDK(t)

	peerID, count := 10, 2
	expect.ExpectCall("messages.markAsRead").WithParams(api.Params{
		"peer_id": peerID,
	}).ReturnsJSON(count)

	read, err := MarkAsRead(sdk, peerID)
	if err != nil {
		t.Fatal(err)
	}

	if count != read {
		t.Errorf("expected %d, got %d", count, read)
	}
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PatchHandler

func PatchHandler(sdk *api.VK, f Middleware) *api.VK

Types

type Handler

type Handler = func(method string, params ...api.Params) (api.Response, error)

type Middleware

type Middleware func(handler Handler) Handler

type SDKBuilder

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

SDKBuilder represents *api.VK builder.

func BuildSDK

func BuildSDK(token string, tokens ...string) SDKBuilder

BuildSDK creates new SDKBuilder.

func (SDKBuilder) Complete

func (builder SDKBuilder) Complete() *api.VK

Complete returns built API client.

func (SDKBuilder) WithHTTPClient

func (builder SDKBuilder) WithHTTPClient(client *http.Client) SDKBuilder

WithHTTPClient sets HTTP client.

func (SDKBuilder) WithMethodURL

func (builder SDKBuilder) WithMethodURL(url string) SDKBuilder

WithMethodURL sets API endpoint URL.

func (SDKBuilder) WithMiddleware

func (builder SDKBuilder) WithMiddleware(f Middleware) SDKBuilder

WithMiddleware adds Handler middleware.

func (SDKBuilder) WithRequestLimit

func (builder SDKBuilder) WithRequestLimit(limit int) SDKBuilder

WithRequestLimit sets request limit by second.

func (SDKBuilder) WithRequestLimitPerToken

func (builder SDKBuilder) WithRequestLimitPerToken(limit int) SDKBuilder

WithRequestLimitPerToken sets request limit by second per token.

func (SDKBuilder) WithUserAgent

func (builder SDKBuilder) WithUserAgent(agent string) SDKBuilder

WithUserAgent sets User-Agent header.

func (SDKBuilder) WithVersion

func (builder SDKBuilder) WithVersion(v string) SDKBuilder

WithVersion sets API version.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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