Documentation
¶
Overview ¶
Package gitter provides sarah.Adapter implementation for gitter.
Index ¶
- Constants
- Variables
- func NewResponse(content string, options ...RespOption) (*sarah.CommandResponse, error)
- type APIClient
- type Adapter
- type AdapterOption
- type Config
- type Connection
- type Issue
- type MalformedPayloadError
- type Mention
- type Message
- type MessageReceiver
- type Meta
- type PostingMessage
- type RespOption
- type RestAPIClient
- func (client *RestAPIClient) Get(ctx context.Context, resourceFragments []string, intf interface{}) error
- func (client *RestAPIClient) Post(ctx context.Context, resourceFragments []string, sendingPayload interface{}, ...) error
- func (client *RestAPIClient) PostMessage(ctx context.Context, room *Room, text string) (*Message, error)
- func (client *RestAPIClient) Rooms(ctx context.Context) (*Rooms, error)
- type Room
- type RoomMessage
- type Rooms
- type RoomsFetcher
- type StreamConnector
- type StreamingAPIClient
- type StreamingClient
- type TimeStamp
- type User
Constants ¶
const ( // GITTER is a dedicated BotType for gitter implementation. GITTER sarah.BotType = "gitter" )
const (
// RestAPIEndpoint defines base url of gitter REST API.
RestAPIEndpoint = "https://api.gitter.im/"
)
const (
// StreamingAPIEndpointFormat defines basic url format of gitter streaming API.
StreamingAPIEndpointFormat = "https://stream.gitter.im/%s/rooms/%s/chatMessages"
)
const ( // TimeFormat defines gitter-styled timestamp format. // https://golang.org/pkg/time/#Time.Format TimeFormat = "2006-01-02T15:04:05.999Z" )
Variables ¶
var ( // ErrEmptyPayload is an error that represents empty payload. ErrEmptyPayload = xerrors.New("empty payload was given") )
Functions ¶
func NewResponse ¶
func NewResponse(content string, options ...RespOption) (*sarah.CommandResponse, error)
NewResponse creates *sarah.CommandResponse with given arguments.
Types ¶
type APIClient ¶
type APIClient interface {
Rooms(context.Context) (*Rooms, error)
PostMessage(context.Context, *Room, string) (*Message, error)
}
APIClient is an interface that Rest API client must satisfy. This is mainly defined to ease tests.
type Adapter ¶
type Adapter struct {
// contains filtered or unexported fields
}
Adapter stores REST/Streaming API clients' instances to let users interact with gitter.
func NewAdapter ¶
func NewAdapter(config *Config, options ...AdapterOption) (*Adapter, error)
NewAdapter creates and returns new Adapter instance.
type AdapterOption ¶
type AdapterOption func(adapter *Adapter)
AdapterOption defines function signature that Adapter's functional option must satisfy.
type Config ¶
type Config struct {
Token string `json:"token" yaml:"token"`
RetryPolicy *retry.Policy `json:"retry_policy" yaml:"retry_policy"`
}
Config contains some configuration variables for gitter Adapter.
type Connection ¶
type Connection interface {
MessageReceiver
io.Closer
}
Connection defines an interface that satisfies both MessageReceiver and io.Closer.
type Issue ¶
type Issue struct {
Number uint `json:"number"`
}
Issue represents issue number mentioned in a message.
type MalformedPayloadError ¶
type MalformedPayloadError struct {
Err string
}
MalformedPayloadError represents an error that given JSON payload is not properly formatted. e.g. required fields are not given, or payload is not a valid JSON string.
func NewMalformedPayloadError ¶
func NewMalformedPayloadError(str string) *MalformedPayloadError
NewMalformedPayloadError creates new MalformedPayloadError instance with given arguments.
func (*MalformedPayloadError) Error ¶
func (e *MalformedPayloadError) Error() string
Error returns its error string.
type Message ¶
type Message struct {
ID string `json:"id"`
Text string `json:"text"`
HTML string `json:"html"`
SendTimeStamp TimeStamp `json:"sent"`
EditTimeStamp TimeStamp `json:"editedAt"`
FromUser User `json:"fromUser"`
Unread bool `json:"unread"`
ReadBy uint `json:"readBy"`
URLs []string `json:"urls"`
Mentions []Mention `json:"mentions"`
Issues []Issue `json:"issues"`
Meta []Meta `json:"meta"` // Reserved, but not in use
Version uint `json:"v"`
}
Message represents gitter message resource. https://developer.gitter.im/docs/messages-resource
type MessageReceiver ¶
type MessageReceiver interface {
Receive() (*RoomMessage, error)
}
MessageReceiver defines an interface that receives RoomMessage.
type Meta ¶
type Meta struct {
}
Meta is reserved, but is not used so far. https://developer.gitter.im/docs/messages-resource
type PostingMessage ¶
type PostingMessage struct {
Text string `json:"text"`
}
PostingMessage represents the sending message. This can be marshaled and sent as JSON-styled payload.
type RespOption ¶
type RespOption func(*respOptions)
RespOption defines function signature that NewResponse's functional option must satisfy.
func RespWithNext ¶
func RespWithNext(fnc sarah.ContextualFunc) RespOption
RespWithNext sets given fnc as part of the response's *sarah.UserContext. The next input from the same user will be passed to this fnc. See sarah.UserContextStorage must be present or otherwise, fnc will be ignored.
func RespWithNextSerializable ¶
func RespWithNextSerializable(arg *sarah.SerializableArgument) RespOption
RespWithNextSerializable sets given arg as part of the response's *sarah.UserContext. The next input from the same user will be passed to the function defined in the arg. See sarah.UserContextStorage must be present or otherwise, arg will be ignored.
type RestAPIClient ¶
type RestAPIClient struct {
// contains filtered or unexported fields
}
RestAPIClient utilizes gitter REST API.
func NewRestAPIClient ¶
func NewRestAPIClient(token string) *RestAPIClient
NewRestAPIClient creates and returns API client instance. Version is fixed to v1.
func NewVersionSpecificRestAPIClient ¶
func NewVersionSpecificRestAPIClient(token string, apiVersion string) *RestAPIClient
NewVersionSpecificRestAPIClient creates API client instance with given API version.
func (*RestAPIClient) Get ¶
func (client *RestAPIClient) Get(ctx context.Context, resourceFragments []string, intf interface{}) error
Get sends GET request with given path and parameters.
func (*RestAPIClient) Post ¶
func (client *RestAPIClient) Post(ctx context.Context, resourceFragments []string, sendingPayload interface{}, responsePayload interface{}) error
Post sends POST requests to gitter with given parameters.
func (*RestAPIClient) PostMessage ¶
func (client *RestAPIClient) PostMessage(ctx context.Context, room *Room, text string) (*Message, error)
PostMessage sends message to gitter.
type Room ¶
type Room struct {
ID string `json:"id"`
Name string `json:"name"`
Topic string `json:"topic"`
URI string `json:"uri"`
OneToOne bool `json:"oneToOne"`
Users []*User `json:"users"`
UnreadItems uint `json:"unreadItems"`
Mentions uint `json:"mentions"`
LastAccessTime TimeStamp `json:"lastAccessTime"`
Favourite uint `json:"favourite"`
Lurk bool `json:"lurk"`
URL string `json:"url"` // path
GitHubType string `json:"githubType"` // TODO type
Tags []string `json:"tags"`
Version uint `json:"v"`
}
Room represents gitter room resource. https://developer.gitter.im/docs/rooms-resource
type RoomMessage ¶
RoomMessage stashes received Message and additional Room information.
func NewRoomMessage ¶
func NewRoomMessage(room *Room, message *Message) *RoomMessage
NewRoomMessage creates and returns new RoomMessage instance.
func (*RoomMessage) Message ¶
func (message *RoomMessage) Message() string
Message returns received text.
func (*RoomMessage) ReplyTo ¶
func (message *RoomMessage) ReplyTo() sarah.OutputDestination
ReplyTo returns Room that message was being delivered.
func (*RoomMessage) SenderKey ¶
func (message *RoomMessage) SenderKey() string
SenderKey returns message sending user's ID.
func (*RoomMessage) SentAt ¶
func (message *RoomMessage) SentAt() time.Time
SentAt returns when the message is sent.
type RoomsFetcher ¶
RoomsFetcher defines interface that fetch gitter rooms.
type StreamConnector ¶
type StreamConnector interface {
Connect(context.Context, *Room) (Connection, error)
}
StreamConnector defines an interface that connects to given gitter room
type StreamingAPIClient ¶
type StreamingAPIClient struct {
// contains filtered or unexported fields
}
StreamingAPIClient utilizes gitter streaming API.
func NewStreamingAPIClient ¶
func NewStreamingAPIClient(token string) *StreamingAPIClient
NewStreamingAPIClient creates and returns API client instance. API version is fixed to v1.
func NewVersionSpecificStreamingAPIClient ¶
func NewVersionSpecificStreamingAPIClient(apiVersion string, token string) *StreamingAPIClient
NewVersionSpecificStreamingAPIClient creates and returns API client instance.
func (*StreamingAPIClient) Connect ¶
func (client *StreamingAPIClient) Connect(ctx context.Context, room *Room) (Connection, error)
Connect initiates request to streaming API and returns established connection.
type StreamingClient ¶
type StreamingClient interface {
Connect(context.Context, *Room) (Connection, error)
}
StreamingClient is an interface that HTTP Streaming client must satisfy. This is mainly defined to ease tests.
type TimeStamp ¶
TimeStamp represents gitter timestamp.
func (*TimeStamp) MarshalText ¶
MarshalText marshals TimeStamp to gitter-styled one.
func (*TimeStamp) UnmarshalText ¶
UnmarshalText unmarshals given gitter-styled timestamp to TimeStamp
type User ¶
type User struct {
ID string `json:"id"`
UserName string `json:"username"`
DisplayName string `json:"displayName"`
URL string `json:"url"` // path
AvatarURLSmall string `json:"avatarUrlSmall"`
AvatarURLMedium string `json:"avatarUrlMedium"`
}
User represents gitter user resource. https://developer.gitter.im/docs/user-resource