rest

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2021 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package rest provides a RocketChat rest client.

Index

Constants

View Source
const (
	IDField       = "_id"
	NameField     = "name"
	UserNameField = "username"
	RoomIDField   = "rid"
)

Variables

View Source
var (
	ErrResponse = fmt.Errorf("got false response")
)

Functions

func ChatErrorNotFound

func ChatErrorNotFound(err error) bool

func IsCharError

func IsCharError(err error) bool

func StringsToAny

func StringsToAny(s []string) []interface{}

Types

type ChannelMembersResponse

type ChannelMembersResponse struct {
	Status
	models.Pagination
	Members []models.User `json:"members"`
}

type ChannelMessagesResponse

type ChannelMessagesResponse struct {
	Status
	models.Pagination
	Messages []models.Message `json:"messages"`
}

type ChannelResponse

type ChannelResponse struct {
	Status
	Channel models.Channel `json:"channel"`
}

type ChannelsResponse

type ChannelsResponse struct {
	Status
	models.Pagination
	Channels []models.Channel `json:"channels"`
}

type ChatError

type ChatError struct {
	Status Status
	// contains filtered or unexported fields
}

func AsCharError

func AsCharError(err error) (ChatError, bool)

func NewChatError

func NewChatError(status Status, err error) ChatError

type Client

type Client struct {
	Client HTTPClient

	Protocol string
	Host     string
	Path     string
	Port     string
	Version  string

	// Use this switch to see all network communication.
	Debug bool
	// contains filtered or unexported fields
}

func NewClient

func NewClient(server *url.URL, opts ...ClientOption) *Client

NewClient creates new REST Rocket.Chat client.

func (*Client) AddGroupOwner

func (c *Client) AddGroupOwner(group *models.InviteGroupRequest) (*models.Group, error)

AddGroupOwner gives the role of owner for a user in the current group.

https://docs.rocket.chat/api/rest-api/methods/groups/addowner

func (*Client) CreateGroup

func (c *Client) CreateGroup(group *models.CreateGroupRequest) (*models.Group, error)

CreateGroup Creates a new private group, optionally including specified users. The group creator is always included.

https://docs.rocket.chat/api/rest-api/methods/groups/create

func (*Client) CreateToken

func (c *Client) CreateToken(userID, username string) (*models.UserCredentials, error)

CreateToken creates an access token for a user

https://rocket.chat/docs/developer-guides/rest-api/users/createtoken/

func (*Client) CreateUser

func (c *Client) CreateUser(req *models.CreateUserRequest) (*CreateUserResponse, error)

CreateUser being logged in with a user that has permission to do so.

https://rocket.chat/docs/developer-guides/rest-api/users/create

func (*Client) DeleteGroup

func (c *Client) DeleteGroup(group *models.Group) error

DeleteGroup remove a private channel.

https://docs.rocket.chat/api/rest-api/methods/groups/delete

func (*Client) Get

func (c *Client) Get(api string, params Parameters, response Response) error

Get call Get.

func (*Client) GetChannelInfo

func (c *Client) GetChannelInfo(channel *models.Channel) (*models.Channel, error)

GetChannelInfo get information about a channel. That might be useful to update the usernames.

https://rocket.chat/docs/developer-guides/rest-api/channels/info

func (*Client) GetDirectory

func (c *Client) GetDirectory(params Parameters) (*models.Directory, error)

GetDirectory a method, that searches by users or channels on all users and channels available on server. It supports the Offset, Count, and Sort Query Parameters along with Query and Fields Query Parameters.

https://rocket.chat/docs/developer-guides/rest-api/miscellaneous/directory

func (*Client) GetGroupInfo

func (c *Client) GetGroupInfo(group *models.Group) (*models.Group, error)

GetGroupInfo retrieves the information about the private group, only if you're part of the group.

https://docs.rocket.chat/api/rest-api/methods/groups/info

func (*Client) GetJoinedChannels

func (c *Client) GetJoinedChannels(params Parameters) (*ChannelsResponse, error)

GetJoinedChannels returns all channels that the user has joined.

https://rocket.chat/docs/developer-guides/rest-api/channels/list-joined

func (*Client) GetMessages

func (c *Client) GetMessages(channel *models.Channel, page *models.Pagination) ([]models.Message, error)

Get messages from a channel. The channel id has to be not nil. Optionally a count can be specified to limit the size of the returned messages.

https://rocket.chat/docs/developer-guides/rest-api/channels/history

func (*Client) GetPublicChannels

func (c *Client) GetPublicChannels() (*ChannelsResponse, error)

GetPublicChannels returns all channels that can be seen by the logged in user.

https://rocket.chat/docs/developer-guides/rest-api/channels/list

func (*Client) GetServerInfo

func (c *Client) GetServerInfo() (*models.Info, error)

GetServerInfo a simple method, requires no authentication, that returns information about the server including version information.

https://rocket.chat/docs/developer-guides/rest-api/miscellaneous/info

func (*Client) GetSpotlight

func (c *Client) GetSpotlight(params Parameters) (*models.Spotlight, error)

GetSpotlight searches for users or rooms that are visible to the user. WARNING: It will only return rooms that user didn’t join yet.

https://rocket.chat/docs/developer-guides/rest-api/miscellaneous/spotlight

func (*Client) GetStatistics

func (c *Client) GetStatistics() (*models.StatisticsInfo, error)

GetStatistics Statistics about the Rocket.Chat server.

https://rocket.chat/docs/developer-guides/rest-api/miscellaneous/statistics

func (*Client) GetStatisticsList

func (c *Client) GetStatisticsList(params Parameters) (*models.StatisticsList, error)

GetStatisticsList Selectable statistics about the Rocket.Chat server. It supports the Offset, Count and Sort Query Parameters along with just the Fields and Query Parameters.

https://rocket.chat/docs/developer-guides/rest-api/miscellaneous/statistics.list

func (*Client) GetUserInfo

func (c *Client) GetUserInfo(user *models.User) (*models.User, error)

GetUserInfo get information about a channel. That might be useful to update the usernames.

https://rocket.chat/docs/developer-guides/rest-api/channels/info

func (*Client) GroupHistory

func (c *Client) GroupHistory(group *models.Group) ([]models.Message, error)

GroupHistory retrieves the messages from a private group, only if you're part of the group.

https://docs.rocket.chat/api/rest-api/methods/groups/history

func (*Client) GroupInviteUser

func (c *Client) GroupInviteUser(group *models.InviteGroupRequest) (*models.Group, error)

GroupInviteUser adds a user to the private group.

https://docs.rocket.chat/api/rest-api/methods/groups/invite

func (*Client) GroupKickUser

func (c *Client) GroupKickUser(group *models.InviteGroupRequest) (*models.Group, error)

GroupKickUser removes a user from the private group.

https://docs.rocket.chat/api/rest-api/methods/groups/kick

func (*Client) GroupList

func (c *Client) GroupList(params Parameters) ([]models.Group, error)

GroupList lists all of the private groups the calling user has joined.

https://docs.rocket.chat/api/rest-api/methods/groups/list

func (*Client) GroupMembers

func (c *Client) GroupMembers(group *models.Group) ([]models.User, error)

GroupMembers lists the users of participants of a private group.

https://docs.rocket.chat/api/rest-api/methods/groups/members

func (*Client) GroupMessages

func (c *Client) GroupMessages(group *models.Group) ([]models.Message, error)

GroupMessages Lists all of the specific group messages on the server. It supports the Offset, Count, and Sort Query Parameters along with Query and Fields Query Parameters.

https://docs.rocket.chat/api/rest-api/methods/groups/messages

func (*Client) LeaveChannel

func (c *Client) LeaveChannel(channel *models.Channel) error

LeaveChannel leaves a channel. The id of the channel has to be not nil.

https://rocket.chat/docs/developer-guides/rest-api/channels/leave

func (*Client) LeaveGroup

func (c *Client) LeaveGroup(group *models.Group) error

LeaveGroup causes the callee to be removed from the private group, if they're part of it and are not the last owner.

https://docs.rocket.chat/api/rest-api/methods/groups/leave

func (*Client) ListAllGroups

func (c *Client) ListAllGroups(params Parameters) ([]models.Group, error)

ListAllGroups Lists all of the private groups of any users.

https://docs.rocket.chat/api/rest-api/methods/groups/listall

func (*Client) ListAllUsers

func (c *Client) ListAllUsers(params Parameters) ([]models.User, error)

ListAllUsers Gets all of the users in the system and their information, the result is only limited to what the callee has access to view.

https://docs.rocket.chat/api/rest-api/methods/users/list

func (*Client) Login

func (c *Client) Login(credentials *models.UserCredentials) error

Login a user. The Email and the Password are mandatory. The auth token of the user is stored in the Client instance.

https://rocket.chat/docs/developer-guides/rest-api/authentication/login

func (*Client) Logout

func (c *Client) Logout() (string, error)

Logout a user. The function returns the response message of the server.

https://rocket.chat/docs/developer-guides/rest-api/authentication/logout

func (*Client) Post

func (c *Client) Post(api string, body io.Reader, response Response) error

Post call as JSON.

func (*Client) PostForm

func (c *Client) PostForm(api string, params Parameters, response Response) error

PostForm call as Form Data.

func (*Client) PostMessage

func (c *Client) PostMessage(msg *models.PostMessage) (*MessageResponse, error)

PostMessage send a message to a channel. The channel or roomID has to be not nil. The message will be json encode.

https://rocket.chat/docs/developer-guides/rest-api/chat/postmessage

func (*Client) RemoveGroupOwner

func (c *Client) RemoveGroupOwner(group *models.InviteGroupRequest) (*models.Group, error)

RemoveOwnerGroup removes the role of owner from a user in the current Group.

https://docs.rocket.chat/api/rest-api/methods/groups/removeowner

func (*Client) Send

func (c *Client) Send(channel *models.Channel, msg string) error

Sends a message to a channel. The name of the channel has to be not nil. The message will be html escaped.

https://rocket.chat/docs/developer-guides/rest-api/chat/postmessage

func (*Client) SetGroupAnnouncement

func (c *Client) SetGroupAnnouncement(groupID, announcement string) error

SetGroupAnnouncement remove a private channel.

https://docs.rocket.chat/api/rest-api/methods/groups/setannouncement

func (*Client) SetUserAvatar

func (c *Client) SetUserAvatar(userID, username, avatarURL string) (*Status, error)

SetUserAvatar updates a user's avatar being logged in with a user that has permission to do so. Currently only passing an URL is possible.

https://rocket.chat/docs/developer-guides/rest-api/users/setavatar/

func (*Client) UpdateUser

func (c *Client) UpdateUser(req *models.UpdateUserRequest) (*CreateUserResponse, error)

UpdateUser updates a user's data being logged in with a user that has permission to do so.

https://rocket.chat/docs/developer-guides/rest-api/users/update/

type ClientOption

type ClientOption func(*Client)

func WithDebug

func WithDebug(b bool) ClientOption

WithHTTPClient allows overriding the default Doer, which is automatically created using http.Client. This is useful for tests.

func WithHTTPClient

func WithHTTPClient(client HTTPClient) ClientOption

WithHTTPClient allows overriding the default Doer, which is automatically created using http.Client. This is useful for tests.

type CreateUserResponse

type CreateUserResponse struct {
	Status
	User struct {
		ID        string    `json:"_id"`
		CreatedAt time.Time `json:"createdAt"`
		Services  struct {
			Password struct {
				Bcrypt string `json:"bcrypt"`
			} `json:"password"`
		} `json:"services"`
		Username string `json:"username"`
		Emails   []struct {
			Address  string `json:"address"`
			Verified bool   `json:"verified"`
		} `json:"emails"`
		Type         string            `json:"type"`
		Status       string            `json:"status"`
		Active       bool              `json:"active"`
		Roles        []string          `json:"roles"`
		UpdatedAt    time.Time         `json:"_updatedAt"`
		Name         string            `json:"name"`
		CustomFields map[string]string `json:"customFields"`
	} `json:"user"`
}

type DirectoryResponse

type DirectoryResponse struct {
	Status
	models.Directory
}

type Fields

type Fields map[string]interface{}

func NewFields

func NewFields() Fields

func (Fields) Add

func (f Fields) Add(name string, value interface{}) Fields

Add match.

func (Fields) Encode

func (f Fields) Encode() string

func (Fields) ID

func (f Fields) ID(id string) Fields

ID adds "_id" match.

func (Fields) String

func (f Fields) String() string

type GroupMembersResponse

type GroupMembersResponse = ChannelMembersResponse

type GroupMessagesResponse

type GroupMessagesResponse = ChannelMessagesResponse

type GroupResponse

type GroupResponse struct {
	Status
	Group models.Group `json:"group"`
}

type GroupsResponse

type GroupsResponse struct {
	Status
	models.Pagination
	Groups []models.Group `json:"groups"`
}

type HTTPClient

type HTTPClient interface {
	Do(req *http.Request) (*http.Response, error)
}

type InfoResponse

type InfoResponse struct {
	Status
	Info models.Info `json:"info"`
}

type MessageResponse

type MessageResponse struct {
	Status
	Message models.Message `json:"message"`
}

type MessagesResponse

type MessagesResponse struct {
	Status
	Messages []models.Message `json:"messages"`
}

type Parameters

type Parameters interface {
	Encode() string
}

Parameters encoder (eg.: url.Values, Query, Fields).

type Query

type Query map[string]interface{}

func NewQuery

func NewQuery() Query

func (Query) Add

func (q Query) Add(name string, value interface{}) Query

Add match.

func (Query) And

func (q Query) And(value ...Query) Query

And joins query clauses with a logical AND returns all documents that match the conditions of both clauses.

func (Query) Encode

func (q Query) Encode() string

func (Query) Equal

func (q Query) Equal(value interface{}) Query

Equal matches values that are equal to a specified value.

func (Query) Greater

func (q Query) Greater(value interface{}) Query

Greater matches values that are greater than a specified value.

func (Query) GreaterOrEqual

func (q Query) GreaterOrEqual(value interface{}) Query

GreaterOrEqual matches values that are greater than or equal to a specified value.

func (Query) ID

func (q Query) ID(id string) Query

ID adds "_id" match.

func (Query) In

func (q Query) In(values ...interface{}) Query

In matches any of the values specified in an array.

func (Query) Less

func (q Query) Less(value interface{}) Query

Less matches values that are less than a specified value.

func (Query) LessOrEqual

func (q Query) LessOrEqual(value interface{}) Query

LessEqual matches values that are less than or equal to a specified value.

func (Query) Not

func (q Query) Not(value Query) Query

Not inverts the effect of a query expression and returns documents that do not match the query expression.

func (Query) NotEqual

func (q Query) NotEqual(value interface{}) Query

NotEqual matches all values that are not equal to a specified value.

func (Query) NotIn

func (q Query) NotIn(value ...interface{}) Query

NotIn matches none of the values specified in an array.

func (Query) NotOr

func (q Query) NotOr(value ...Query) Query

NotOr performs a logical NOR operation on an array of one or more query expression and selects the documents that fail all the query expressions in the array.

func (Query) Or

func (q Query) Or(value ...Query) Query

NotOr joins query clauses with a logical OR returns all documents that match the conditions of either clause.

func (Query) Regex

func (q Query) Regex(pattern string) Query

Regex selects documents where values match a specified regular expression.

func (Query) String

func (q Query) String() string

type Response

type Response interface {
	OK() error
}

type SpotlightResponse

type SpotlightResponse struct {
	Status
	models.Spotlight
}

type StatisticsListResponse

type StatisticsListResponse struct {
	Status
	models.StatisticsList
}

type StatisticsResponse

type StatisticsResponse struct {
	Status
	models.StatisticsInfo
}

type Status

type Status struct {
	Success bool   `json:"success"`
	Error   string `json:"error"`

	Status  string `json:"status"`
	Message string `json:"message"`
}

func (Status) OK

func (s Status) OK() error

type StatusResponse

type StatusResponse struct {
	Status
	Channel string `json:"channel"`
}

StatusResponse The base for the most of the json responses.

type UpdatePermissionsRequest

type UpdatePermissionsRequest struct {
	Permissions []models.Permission `json:"permissions"`
}

type UpdatePermissionsResponse

type UpdatePermissionsResponse struct {
	Status
	Permissions []models.Permission `json:"permissions"`
}

type UserResponse

type UserResponse struct {
	Status
	User models.User `json:"user"`
}

type UsersResponse

type UsersResponse struct {
	Status
	Users []models.User `json:"users"`
}

Jump to

Keyboard shortcuts

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