Documentation ¶
Index ¶
- Constants
- Variables
- func NewStringResponse(responseContent string) *sarah.CommandResponse
- func NewStringResponseWithNext(responseContent string, next sarah.ContextualFunc) *sarah.CommandResponse
- 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 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 = errors.New("empty payload was given") )
Functions ¶
func NewStringResponse ¶
func NewStringResponse(responseContent string) *sarah.CommandResponse
NewStringResponse creates new sarah.CommandResponse instance with given string.
func NewStringResponseWithNext ¶
func NewStringResponseWithNext(responseContent string, next sarah.ContextualFunc) *sarah.CommandResponse
NewStringResponseWithNext creates new sarah.CommandResponse instance with given string and next function to continue
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.
func (*Adapter) BotType ¶
func (adapter *Adapter) BotType() sarah.BotType
BotType returns gitter designated BotType.
func (*Adapter) Run ¶
func (adapter *Adapter) Run(ctx context.Context, enqueueInput func(sarah.Input) error, notifyErr func(error))
Run fetches all belonging Room and connects to them.
func (*Adapter) SendMessage ¶
SendMessage let Bot send message to gitter.
type AdapterOption ¶
AdapterOption defines function signature that Adapter's functional option must satisfy.
type Config ¶
type Config struct { Token string `json:"token" yaml:"token"` RetryLimit uint `json:"retry_limit" yaml:"retry_limit"` RetryInterval time.Duration `json:"retry_interval" yaml:"retry_interval"` }
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 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