2020-04-30 16:36:31 +02:00
|
|
|
package gorocket
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"net/http"
|
2020-06-10 18:19:25 +02:00
|
|
|
"time"
|
2020-04-30 16:36:31 +02:00
|
|
|
)
|
|
|
|
|
2020-06-10 18:19:25 +02:00
|
|
|
type RespInfo struct {
|
2024-02-03 21:54:40 +02:00
|
|
|
Version string `json:"version"`
|
|
|
|
Info struct {
|
2020-06-10 18:19:25 +02:00
|
|
|
Version string `json:"version"`
|
2022-09-01 15:22:58 +02:00
|
|
|
Build Build `json:"build"`
|
|
|
|
Commit Commit `json:"commit"`
|
2020-06-10 18:19:25 +02:00
|
|
|
MarketplaceAPIVersion string `json:"marketplaceApiVersion"`
|
|
|
|
} `json:"info"`
|
|
|
|
Success bool `json:"success"`
|
|
|
|
}
|
|
|
|
|
2022-09-01 15:22:58 +02:00
|
|
|
type Build struct {
|
2020-06-10 18:19:25 +02:00
|
|
|
Date time.Time `json:"date"`
|
|
|
|
NodeVersion string `json:"nodeVersion"`
|
|
|
|
Arch string `json:"arch"`
|
|
|
|
Platform string `json:"platform"`
|
|
|
|
OsRelease string `json:"osRelease"`
|
|
|
|
TotalMemory int64 `json:"totalMemory"`
|
|
|
|
FreeMemory int `json:"freeMemory"`
|
|
|
|
Cpus int `json:"cpus"`
|
|
|
|
}
|
|
|
|
|
2022-09-01 15:22:58 +02:00
|
|
|
type Commit struct {
|
2020-06-10 18:19:25 +02:00
|
|
|
Hash string `json:"hash"`
|
|
|
|
Date string `json:"date"`
|
|
|
|
Author string `json:"author"`
|
|
|
|
Subject string `json:"subject"`
|
|
|
|
Tag string `json:"tag"`
|
|
|
|
Branch string `json:"branch"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type RespDirectory struct {
|
2024-02-03 21:54:40 +02:00
|
|
|
Result []DirectoryResult `json:"result"`
|
|
|
|
Count int `json:"count"`
|
|
|
|
Offset int `json:"offset"`
|
|
|
|
Total int `json:"total"`
|
|
|
|
Success bool `json:"success"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type DirectoryResult struct {
|
|
|
|
ID string `json:"_id"`
|
|
|
|
CreatedAt time.Time `json:"createdAt"`
|
|
|
|
Emails []Email `json:"emails"`
|
|
|
|
Name string `json:"name"`
|
|
|
|
Username string `json:"username"`
|
|
|
|
AvatarETag string `json:"avatarETag"`
|
2020-06-10 18:19:25 +02:00
|
|
|
}
|
|
|
|
|
2022-09-01 15:22:58 +02:00
|
|
|
type Result struct {
|
2020-06-10 18:19:25 +02:00
|
|
|
ID string `json:"_id"`
|
|
|
|
Ts time.Time `json:"ts"`
|
|
|
|
T string `json:"t"`
|
|
|
|
Name string `json:"name"`
|
|
|
|
UsersCount int `json:"usersCount"`
|
|
|
|
Default bool `json:"default"`
|
2022-09-01 15:22:58 +02:00
|
|
|
LastMessage LastMessage `json:"lastMessage"`
|
2020-06-10 18:19:25 +02:00
|
|
|
}
|
|
|
|
|
2022-09-01 15:22:58 +02:00
|
|
|
type LastMessage struct {
|
2020-06-10 18:19:25 +02:00
|
|
|
ID string `json:"_id"`
|
|
|
|
Alias string `json:"alias"`
|
|
|
|
Msg string `json:"msg"`
|
|
|
|
Attachments []interface{} `json:"attachments"`
|
|
|
|
ParseUrls bool `json:"parseUrls"`
|
|
|
|
Groupable bool `json:"groupable"`
|
|
|
|
Ts time.Time `json:"ts"`
|
2022-09-01 15:22:58 +02:00
|
|
|
U U `json:"u"`
|
2020-06-10 18:19:25 +02:00
|
|
|
Rid string `json:"rid"`
|
|
|
|
UpdatedAt time.Time `json:"_updatedAt"`
|
|
|
|
Mentions []interface{} `json:"mentions"`
|
|
|
|
Channels []interface{} `json:"channels"`
|
|
|
|
}
|
|
|
|
|
2022-09-01 15:22:58 +02:00
|
|
|
type U struct {
|
2020-06-10 18:19:25 +02:00
|
|
|
ID string `json:"_id"`
|
|
|
|
Username string `json:"username"`
|
2020-08-24 23:21:08 +02:00
|
|
|
Name string `json:"name,omitempty"`
|
2020-06-10 18:19:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
type RespSpotlight struct {
|
2022-09-01 15:22:58 +02:00
|
|
|
Users []UsersInfo `json:"users"`
|
|
|
|
Rooms []RoomsInfo `json:"rooms"`
|
2020-06-10 18:19:25 +02:00
|
|
|
Success bool `json:"success"`
|
|
|
|
Error string `json:"error,omitempty"`
|
|
|
|
}
|
|
|
|
|
2022-09-01 15:22:58 +02:00
|
|
|
type UsersInfo struct {
|
2020-06-10 18:19:25 +02:00
|
|
|
ID string `json:"_id"`
|
|
|
|
Status string `json:"status"`
|
|
|
|
Name string `json:"name"`
|
|
|
|
Username string `json:"username"`
|
|
|
|
StatusText string `json:"statusText"`
|
2024-02-03 21:54:40 +02:00
|
|
|
AvatarETag string `json:"avatarETag,omitempty"`
|
2020-06-10 18:19:25 +02:00
|
|
|
}
|
|
|
|
|
2022-09-01 15:22:58 +02:00
|
|
|
type RoomsInfo struct {
|
2020-06-10 18:19:25 +02:00
|
|
|
ID string `json:"_id"`
|
|
|
|
Name string `json:"name"`
|
|
|
|
T string `json:"t"`
|
2022-09-01 15:22:58 +02:00
|
|
|
LastMessage LastMessage `json:"lastMessage"`
|
2020-06-10 18:19:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
type RespStatistics struct {
|
|
|
|
ID string `json:"_id"`
|
2022-09-01 15:22:58 +02:00
|
|
|
Wizard Wizard `json:"wizard"`
|
2020-06-10 18:19:25 +02:00
|
|
|
UniqueID string `json:"uniqueId"`
|
|
|
|
InstalledAt time.Time `json:"installedAt"`
|
|
|
|
Version string `json:"version"`
|
|
|
|
TotalUsers int `json:"totalUsers"`
|
|
|
|
ActiveUsers int `json:"activeUsers"`
|
|
|
|
ActiveGuests int `json:"activeGuests"`
|
|
|
|
NonActiveUsers int `json:"nonActiveUsers"`
|
|
|
|
AppUsers int `json:"appUsers"`
|
|
|
|
OnlineUsers int `json:"onlineUsers"`
|
|
|
|
AwayUsers int `json:"awayUsers"`
|
|
|
|
TotalConnectedUsers int `json:"totalConnectedUsers"`
|
|
|
|
OfflineUsers int `json:"offlineUsers"`
|
|
|
|
TotalRooms int `json:"totalRooms"`
|
|
|
|
TotalChannels int `json:"totalChannels"`
|
|
|
|
TotalPrivateGroups int `json:"totalPrivateGroups"`
|
|
|
|
TotalDirect int `json:"totalDirect"`
|
|
|
|
TotalLivechat int `json:"totalLivechat"`
|
|
|
|
TotalDiscussions int `json:"totalDiscussions"`
|
|
|
|
TotalThreads int `json:"totalThreads"`
|
|
|
|
TotalLivechatVisitors int `json:"totalLivechatVisitors"`
|
|
|
|
TotalLivechatAgents int `json:"totalLivechatAgents"`
|
|
|
|
LivechatEnabled bool `json:"livechatEnabled"`
|
|
|
|
TotalChannelMessages int `json:"totalChannelMessages"`
|
|
|
|
TotalPrivateGroupMessages int `json:"totalPrivateGroupMessages"`
|
|
|
|
TotalDirectMessages int `json:"totalDirectMessages"`
|
|
|
|
TotalLivechatMessages int `json:"totalLivechatMessages"`
|
|
|
|
TotalMessages int `json:"totalMessages"`
|
|
|
|
FederatedServers int `json:"federatedServers"`
|
|
|
|
FederatedUsers int `json:"federatedUsers"`
|
|
|
|
LastLogin time.Time `json:"lastLogin"`
|
|
|
|
LastMessageSentAt time.Time `json:"lastMessageSentAt"`
|
|
|
|
LastSeenSubscription time.Time `json:"lastSeenSubscription"`
|
2022-09-01 15:22:58 +02:00
|
|
|
Os Os `json:"os"`
|
|
|
|
Process Process `json:"process"`
|
|
|
|
Deploy Deploy `json:"deploy"`
|
2020-06-10 18:19:25 +02:00
|
|
|
EnterpriseReady bool `json:"enterpriseReady"`
|
|
|
|
UploadsTotal int `json:"uploadsTotal"`
|
|
|
|
UploadsTotalSize int `json:"uploadsTotalSize"`
|
2022-09-01 15:22:58 +02:00
|
|
|
Migration Migration `json:"migration"`
|
2020-06-10 18:19:25 +02:00
|
|
|
InstanceCount int `json:"instanceCount"`
|
|
|
|
OplogEnabled bool `json:"oplogEnabled"`
|
|
|
|
MongoVersion string `json:"mongoVersion"`
|
|
|
|
MongoStorageEngine string `json:"mongoStorageEngine"`
|
2022-09-01 15:22:58 +02:00
|
|
|
UniqueUsersOfYesterday Stats `json:"uniqueUsersOfYesterday"`
|
|
|
|
UniqueUsersOfLastMonth Stats `json:"uniqueUsersOfLastMonth"`
|
|
|
|
UniqueDevicesOfYesterday Stats `json:"uniqueDevicesOfYesterday"`
|
|
|
|
UniqueDevicesOfLastMonth Stats `json:"uniqueDevicesOfLastMonth"`
|
|
|
|
UniqueOSOfYesterday Stats `json:"uniqueOSOfYesterday"`
|
|
|
|
UniqueOSOfLastMonth Stats `json:"uniqueOSOfLastMonth"`
|
|
|
|
Apps Apps `json:"apps"`
|
|
|
|
Integrations Integrations `json:"integrations"`
|
2020-06-10 18:19:25 +02:00
|
|
|
PushQueue int `json:"pushQueue"`
|
|
|
|
CreatedAt time.Time `json:"createdAt"`
|
|
|
|
UpdatedAt time.Time `json:"_updatedAt"`
|
|
|
|
Success bool `json:"success"`
|
|
|
|
}
|
|
|
|
|
2022-09-01 15:22:58 +02:00
|
|
|
type Wizard struct {
|
2020-06-10 18:19:25 +02:00
|
|
|
OrganizationType string `json:"organizationType"`
|
|
|
|
Industry string `json:"industry"`
|
|
|
|
Size string `json:"size"`
|
|
|
|
Country string `json:"country"`
|
|
|
|
Language string `json:"language"`
|
|
|
|
ServerType string `json:"serverType"`
|
|
|
|
RegisterServer bool `json:"registerServer"`
|
|
|
|
}
|
|
|
|
|
2022-09-01 15:22:58 +02:00
|
|
|
type Os struct {
|
2020-06-10 18:19:25 +02:00
|
|
|
Type string `json:"type"`
|
|
|
|
Platform string `json:"platform"`
|
|
|
|
Arch string `json:"arch"`
|
|
|
|
Release string `json:"release"`
|
|
|
|
Uptime int `json:"uptime"`
|
|
|
|
Loadavg []float64 `json:"loadavg"`
|
|
|
|
Totalmem int64 `json:"totalmem"`
|
|
|
|
Freemem int `json:"freemem"`
|
2022-09-01 15:22:58 +02:00
|
|
|
Cpus []Cpus `json:"cpus"`
|
2020-06-10 18:19:25 +02:00
|
|
|
}
|
|
|
|
|
2022-09-01 15:22:58 +02:00
|
|
|
type Cpus struct {
|
2020-06-10 18:19:25 +02:00
|
|
|
Model string `json:"model"`
|
|
|
|
Speed int `json:"speed"`
|
2022-09-01 15:22:58 +02:00
|
|
|
Times Times `json:"times"`
|
2020-06-10 18:19:25 +02:00
|
|
|
}
|
|
|
|
|
2022-09-01 15:22:58 +02:00
|
|
|
type Times struct {
|
2020-06-10 18:19:25 +02:00
|
|
|
User int `json:"user"`
|
|
|
|
Nice int `json:"nice"`
|
|
|
|
Sys int `json:"sys"`
|
|
|
|
Idle int `json:"idle"`
|
|
|
|
Irq int `json:"irq"`
|
|
|
|
}
|
|
|
|
|
2022-09-01 15:22:58 +02:00
|
|
|
type Process struct {
|
2020-06-10 18:19:25 +02:00
|
|
|
NodeVersion string `json:"nodeVersion"`
|
|
|
|
Pid int `json:"pid"`
|
|
|
|
Uptime float64 `json:"uptime"`
|
|
|
|
}
|
|
|
|
|
2022-09-01 15:22:58 +02:00
|
|
|
type Apps struct {
|
2020-06-10 18:19:25 +02:00
|
|
|
EngineVersion string `json:"engineVersion"`
|
|
|
|
Enabled bool `json:"enabled"`
|
|
|
|
TotalInstalled int `json:"totalInstalled"`
|
|
|
|
TotalActive int `json:"totalActive"`
|
|
|
|
}
|
|
|
|
|
2022-09-01 15:22:58 +02:00
|
|
|
type Integrations struct {
|
2020-06-10 18:19:25 +02:00
|
|
|
TotalIntegrations int `json:"totalIntegrations"`
|
|
|
|
TotalIncoming int `json:"totalIncoming"`
|
|
|
|
TotalIncomingActive int `json:"totalIncomingActive"`
|
|
|
|
TotalOutgoing int `json:"totalOutgoing"`
|
|
|
|
TotalOutgoingActive int `json:"totalOutgoingActive"`
|
|
|
|
TotalWithScriptEnabled int `json:"totalWithScriptEnabled"`
|
|
|
|
}
|
|
|
|
|
2022-09-01 15:22:58 +02:00
|
|
|
type Stats struct {
|
2020-06-10 18:19:25 +02:00
|
|
|
Year int `json:"year"`
|
|
|
|
Month int `json:"month"`
|
|
|
|
Day int `json:"day"`
|
|
|
|
Data []interface{} `json:"data"`
|
|
|
|
}
|
|
|
|
|
2022-09-01 15:22:58 +02:00
|
|
|
type Migration struct {
|
2020-06-10 18:19:25 +02:00
|
|
|
ID string `json:"_id"`
|
|
|
|
Locked bool `json:"locked"`
|
|
|
|
Version int `json:"version"`
|
|
|
|
}
|
|
|
|
|
2022-09-01 15:22:58 +02:00
|
|
|
type Deploy struct {
|
2020-06-10 18:19:25 +02:00
|
|
|
Method string `json:"method"`
|
|
|
|
Platform string `json:"platform"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type RespStatisticsList struct {
|
|
|
|
Statistics []struct {
|
|
|
|
ID string `json:"_id"`
|
2022-09-01 15:22:58 +02:00
|
|
|
Wizard Wizard `json:"wizard"`
|
2020-06-10 18:19:25 +02:00
|
|
|
UniqueID string `json:"uniqueId"`
|
|
|
|
InstalledAt time.Time `json:"installedAt"`
|
|
|
|
Version string `json:"version"`
|
|
|
|
TotalUsers int `json:"totalUsers"`
|
|
|
|
ActiveUsers int `json:"activeUsers"`
|
|
|
|
ActiveGuests int `json:"activeGuests"`
|
|
|
|
NonActiveUsers int `json:"nonActiveUsers"`
|
|
|
|
AppUsers int `json:"appUsers"`
|
|
|
|
OnlineUsers int `json:"onlineUsers"`
|
|
|
|
AwayUsers int `json:"awayUsers"`
|
|
|
|
TotalConnectedUsers int `json:"totalConnectedUsers"`
|
|
|
|
OfflineUsers int `json:"offlineUsers"`
|
|
|
|
TotalRooms int `json:"totalRooms"`
|
|
|
|
TotalChannels int `json:"totalChannels"`
|
|
|
|
TotalPrivateGroups int `json:"totalPrivateGroups"`
|
|
|
|
TotalDirect int `json:"totalDirect"`
|
|
|
|
TotalLivechat int `json:"totalLivechat"`
|
|
|
|
TotalDiscussions int `json:"totalDiscussions"`
|
|
|
|
TotalThreads int `json:"totalThreads"`
|
|
|
|
TotalLivechatVisitors int `json:"totalLivechatVisitors"`
|
|
|
|
TotalLivechatAgents int `json:"totalLivechatAgents"`
|
|
|
|
TotalChannelMessages int `json:"totalChannelMessages"`
|
|
|
|
TotalPrivateGroupMessages int `json:"totalPrivateGroupMessages"`
|
|
|
|
TotalDirectMessages int `json:"totalDirectMessages"`
|
|
|
|
TotalLivechatMessages int `json:"totalLivechatMessages"`
|
|
|
|
TotalMessages int `json:"totalMessages"`
|
|
|
|
FederatedServers int `json:"federatedServers"`
|
|
|
|
FederatedUsers int `json:"federatedUsers"`
|
2022-09-01 15:22:58 +02:00
|
|
|
Os Os `json:"os"`
|
|
|
|
Process Process `json:"process"`
|
|
|
|
Deploy Deploy `json:"deploy"`
|
2020-06-10 18:19:25 +02:00
|
|
|
EnterpriseReady bool `json:"enterpriseReady"`
|
|
|
|
UploadsTotal int `json:"uploadsTotal"`
|
|
|
|
UploadsTotalSize int `json:"uploadsTotalSize"`
|
2022-09-01 15:22:58 +02:00
|
|
|
Migration Migration `json:"migration"`
|
2020-06-10 18:19:25 +02:00
|
|
|
InstanceCount int `json:"instanceCount"`
|
|
|
|
OplogEnabled bool `json:"oplogEnabled"`
|
|
|
|
MongoVersion string `json:"mongoVersion"`
|
|
|
|
MongoStorageEngine string `json:"mongoStorageEngine"`
|
2022-09-01 15:22:58 +02:00
|
|
|
UniqueUsersOfYesterday Stats `json:"uniqueUsersOfYesterday"`
|
|
|
|
UniqueUsersOfLastMonth Stats `json:"uniqueUsersOfLastMonth"`
|
|
|
|
UniqueDevicesOfYesterday Stats `json:"uniqueDevicesOfYesterday"`
|
|
|
|
UniqueDevicesOfLastMonth Stats `json:"uniqueDevicesOfLastMonth"`
|
|
|
|
UniqueOSOfYesterday Stats `json:"uniqueOSOfYesterday"`
|
|
|
|
UniqueOSOfLastMonth Stats `json:"uniqueOSOfLastMonth"`
|
|
|
|
Apps Apps `json:"apps"`
|
|
|
|
Integrations Integrations `json:"integrations"`
|
2020-06-10 18:19:25 +02:00
|
|
|
PushQueue int `json:"pushQueue"`
|
|
|
|
CreatedAt time.Time `json:"createdAt"`
|
|
|
|
UpdatedAt time.Time `json:"_updatedAt"`
|
|
|
|
LivechatEnabled bool `json:"livechatEnabled,omitempty"`
|
|
|
|
LastLogin time.Time `json:"lastLogin,omitempty"`
|
|
|
|
LastMessageSentAt time.Time `json:"lastMessageSentAt,omitempty"`
|
|
|
|
LastSeenSubscription time.Time `json:"lastSeenSubscription,omitempty"`
|
|
|
|
} `json:"statistics"`
|
|
|
|
Count int `json:"count"`
|
|
|
|
Offset int `json:"offset"`
|
|
|
|
Total int `json:"total"`
|
|
|
|
Success bool `json:"success"`
|
|
|
|
}
|
|
|
|
|
2024-02-03 21:54:40 +02:00
|
|
|
// Info returns information about the server
|
2020-06-10 18:19:25 +02:00
|
|
|
func (c *Client) Info() (*RespInfo, error) {
|
2020-04-30 16:36:31 +02:00
|
|
|
req, err := http.NewRequest("GET", fmt.Sprintf("%s/api/info", c.baseURL), nil)
|
|
|
|
if err != nil {
|
2020-06-10 18:19:25 +02:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
res := RespInfo{}
|
|
|
|
if err := c.sendRequest(req, &res); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &res, nil
|
|
|
|
}
|
|
|
|
|
2024-02-03 21:54:40 +02:00
|
|
|
// Directory returns a list of channels
|
2020-06-10 18:19:25 +02:00
|
|
|
func (c *Client) Directory() (*RespDirectory, error) {
|
|
|
|
req, err := http.NewRequest("GET", fmt.Sprintf("%s/%s/directory", c.baseURL, c.apiVersion), nil)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
res := RespDirectory{}
|
|
|
|
if err := c.sendRequest(req, &res); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &res, nil
|
|
|
|
}
|
|
|
|
|
2024-02-03 21:54:40 +02:00
|
|
|
// Spotlight returns a list of users and rooms that match the provided query
|
2020-06-10 18:19:25 +02:00
|
|
|
func (c *Client) Spotlight(query string) (*RespSpotlight, error) {
|
|
|
|
req, err := http.NewRequest("GET", fmt.Sprintf("%s/%s/spotlight?query=%s", c.baseURL, c.apiVersion, query), nil)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
res := RespSpotlight{}
|
|
|
|
if err := c.sendRequest(req, &res); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &res, nil
|
|
|
|
}
|
|
|
|
|
2024-02-03 21:54:40 +02:00
|
|
|
// Statistics returns statistics about the server
|
2020-06-10 18:19:25 +02:00
|
|
|
func (c *Client) Statistics() (*RespStatistics, error) {
|
|
|
|
req, err := http.NewRequest("GET", fmt.Sprintf("%s/%s/statistics", c.baseURL, c.apiVersion), nil)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2020-04-30 16:36:31 +02:00
|
|
|
}
|
|
|
|
|
2020-06-10 18:19:25 +02:00
|
|
|
res := RespStatistics{}
|
|
|
|
if err := c.sendRequest(req, &res); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &res, nil
|
|
|
|
}
|
2020-04-30 16:36:31 +02:00
|
|
|
|
2024-02-03 21:54:40 +02:00
|
|
|
// StatisticsList returns a list of statistics
|
2020-06-10 18:19:25 +02:00
|
|
|
func (c *Client) StatisticsList() (*RespStatisticsList, error) {
|
|
|
|
req, err := http.NewRequest("GET", fmt.Sprintf("%s/%s/statistics.list", c.baseURL, c.apiVersion), nil)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
res := RespStatisticsList{}
|
|
|
|
if err := c.sendRequest(req, &res); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2020-04-30 16:36:31 +02:00
|
|
|
|
2020-06-10 18:19:25 +02:00
|
|
|
return &res, nil
|
2020-04-30 16:36:31 +02:00
|
|
|
}
|