Skip to content

Commit

Permalink
add users.Get method
Browse files Browse the repository at this point in the history
  • Loading branch information
vildan-valeev committed Dec 18, 2023
1 parent b56647e commit d59a5db
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 19 deletions.
27 changes: 18 additions & 9 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,6 @@ func (a API) GetUpdates(opts *UpdateOptions) (res APIResponseUpdate, err error)
return get[APIResponseUpdate](opts.Server, "", addValues(vals, opts))
}

func (a API) MessagesSend(text string, opts *MessagesSendOptions) (res APIResponseMessagesSend, err error) {
var vals = make(url.Values)
vals.Set("message", text)
vals.Set("access_token", a.token)
vals.Set("v", APIVersion)
vals.Set("random_id", strconv.Itoa(int(rand.Uint32())))
return get[APIResponseMessagesSend](a.base, "messages.send", addValues(vals, opts))
}

// MessagesGetLongPollServer https://dev.vk.com/ru/method/groups.getLongPollServer
func (a API) GroupsGetLongPollServer(opts *GetLongPollServerOptions) (res APIResponseGetLongPollServer, err error) {
var vals = make(url.Values)
Expand All @@ -60,3 +51,21 @@ func (a API) GroupsSetLongPollSettings(opts *SetLongPollSettingsOptions) (res AP
return get[APIResponseSetLongPollSettings](a.base, "groups.setLongPollSettings", addValues(vals, opts))

}

func (a API) MessagesSend(text string, opts *MessagesSendOptions) (res APIResponseMessagesSend, err error) {
var vals = make(url.Values)
vals.Set("message", text)
vals.Set("access_token", a.token)
vals.Set("v", APIVersion)
vals.Set("random_id", strconv.Itoa(int(rand.Uint32())))
return get[APIResponseMessagesSend](a.base, "messages.send", addValues(vals, opts))
}

// UsersGet https://dev.vk.com/ru/method/users.get
func (a API) UsersGet(opts *UsersGetOptions) (res APIResponseUsersGet, err error) {
var vals = make(url.Values)
vals.Set("access_token", a.token)
vals.Set("v", APIVersion)
vals.Set("random_id", strconv.Itoa(int(rand.Uint32())))
return get[APIResponseUsersGet](a.base, "users.get", addValues(vals, opts))
}
11 changes: 1 addition & 10 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
module github.com/vildan-valeev/gvk

go 1.20

require github.com/SevereCloud/vksdk/v2 v2.16.1

require (
github.com/klauspost/compress v1.16.7 // indirect
github.com/vmihailenco/msgpack/v5 v5.4.0 // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
golang.org/x/text v0.13.0 // indirect
)
go 1.21
5 changes: 5 additions & 0 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,8 @@ type SetLongPollSettingsOptions struct {
Enable int64 `query:"enable"`
APIVersion string `query:"api_version"`
}

type UsersGetOptions struct {
UserIDS string `json:"user_ids"`
Fields string `json:"fields"`
}
26 changes: 26 additions & 0 deletions responses.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,32 @@ func (a APIResponseMessagesSend) Base() APIError {
return a.Error
}

//------------------------------------------------------------

type APIResponseUsersGet struct {
Error APIError `json:"error,omitempty"`
Response []User `json:"response,omitempty"`
}

type User struct {
ID int64 `json:"id"`
FirstName string `json:"first_name"`
LastName string `json:"last_name"`
ScreenName string `json:"screen_name"` // aka username
Deactivated Deactivated `json:"deactivated"`
IsClosed bool `json:"is_closed"`
CanAccessClosed bool `json:"can_access_closed"`
}

type Deactivated string

const DeactivatedBanned Deactivated = "banned"
const DeactivatedDeleted Deactivated = "deleted"

func (a APIResponseUsersGet) Base() APIError {
return a.Error
}

//---------------------------------------------------------------

type APIResponseGetLongPollServer struct {
Expand Down

0 comments on commit d59a5db

Please sign in to comment.