Skip to content

Commit

Permalink
feat(api): add calls (#218)
Browse files Browse the repository at this point in the history
- closed #216
  • Loading branch information
SevereCloud authored Feb 19, 2023
1 parent 31b3d7d commit 7172e78
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 0 deletions.
23 changes: 23 additions & 0 deletions api/calls.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package api // import "github.com/SevereCloud/vksdk/v2/api"

// CallsStartResponse struct.
type CallsStartResponse struct {
JoinLink string `json:"join_link"`
CallID string `json:"call_id"`
}

// CallsStart method.
//
// https://vk.com/dev/calls.start
func (vk *VK) CallsStart(params Params) (response CallsStartResponse, err error) {
err = vk.RequestUnmarshal("calls.start", &response, params)
return
}

// CallsForceFinish method.
//
// https://vk.com/dev/calls.forceFinish
func (vk *VK) CallsForceFinish(params Params) (response int, err error) {
err = vk.RequestUnmarshal("calls.forceFinish", &response, params)
return
}
21 changes: 21 additions & 0 deletions api/calls_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package api_test

import (
"testing"

"github.com/SevereCloud/vksdk/v2/api"
)

func TestVK_CallsStart(t *testing.T) {
t.Parallel()

needUserToken(t)

startCall, err := vkUser.CallsStart(nil)
noError(t, err)

_, err = vkUser.CallsForceFinish(api.Params{
"call_id": startCall.CallID,
})
noError(t, err)
}
4 changes: 4 additions & 0 deletions api/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ func (vk *VK) MessagesEditChat(params Params) (response int, err error) {

// MessagesForceCallFinish method.
//
// Deprecated: Use CallsForceFinish
//
// https://vk.com/dev/messages.forceCallFinish
func (vk *VK) MessagesForceCallFinish(params Params) (response int, err error) {
err = vk.RequestUnmarshal("messages.forceCallFinish", &response, params)
Expand Down Expand Up @@ -649,6 +651,8 @@ type MessagesStartCallResponse struct {

// MessagesStartCall method.
//
// Deprecated: Use CallsStart
//
// https://vk.com/dev/messages.startCall
func (vk *VK) MessagesStartCall(params Params) (response MessagesStartCallResponse, err error) {
err = vk.RequestUnmarshal("messages.startCall", &response, params)
Expand Down
39 changes: 39 additions & 0 deletions api/params/calls.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package params

import "github.com/SevereCloud/vksdk/v2/api"

// CallsStartBuilder builder.
//
// https://vk.com/dev/calls.start
type CallsStartBuilder struct {
api.Params
}

// NewCallsStartBuilder func.
func NewCallsStartBuilder() *CallsStartBuilder {
return &CallsStartBuilder{api.Params{}}
}

// GroupID parameter.
func (b *CallsStartBuilder) GroupID(v int) *CallsStartBuilder {
b.Params["group_id"] = v
return b
}

// CallsForceFinishBuilder builder.
//
// https://vk.com/dev/calls.forceFinish
type CallsForceFinishBuilder struct {
api.Params
}

// NewCallsForceFinishBuilder func.
func NewCallsForceFinishBuilder() *CallsForceFinishBuilder {
return &CallsForceFinishBuilder{api.Params{}}
}

// CallID parameter.
func (b *CallsForceFinishBuilder) CallID(v string) *CallsForceFinishBuilder {
b.Params["call_id"] = v
return b
}
28 changes: 28 additions & 0 deletions api/params/calls_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package params_test

import (
"testing"

"github.com/SevereCloud/vksdk/v2/api/params"
"github.com/stretchr/testify/assert"
)

func TestCallsStartBuilder(t *testing.T) {
t.Parallel()

b := params.NewCallsStartBuilder()

b.GroupID(1)

assert.Equal(t, b.Params["group_id"], 1)
}

func TestCallsForceFinishBuilder(t *testing.T) {
t.Parallel()

b := params.NewCallsForceFinishBuilder()

b.CallID("text")

assert.Equal(t, b.Params["call_id"], "text")
}

0 comments on commit 7172e78

Please sign in to comment.