gitter

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2019 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package gitter provides sarah.Adapter implementation for gitter.

Index

Constants

View Source
const (
	// GITTER is a dedicated BotType for gitter implementation.
	GITTER sarah.BotType = "gitter"
)
View Source
const (
	// RestAPIEndpoint defines base url of gitter REST API.
	RestAPIEndpoint = "https://api.gitter.im/"
)
View Source
const (
	// StreamingAPIEndpointFormat defines basic url format of gitter streaming API.
	StreamingAPIEndpointFormat = "https://stream.gitter.im/%s/rooms/%s/chatMessages"
)
View Source
const (
	// TimeFormat defines gitter-styled timestamp format.
	// https://golang.org/pkg/time/#Time.Format
	TimeFormat = "2006-01-02T15:04:05.999Z"
)

Variables

View Source
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

func (adapter *Adapter) SendMessage(ctx context.Context, output sarah.Output)

SendMessage let Bot send message to gitter.

type AdapterOption

type AdapterOption func(adapter *Adapter) error

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.

func NewConfig

func NewConfig() *Config

NewConfig returns initialized Config struct with default settings. Token is empty at this point. Token can be set by feeding this instance to json.Unmarshal/yaml.Unmarshal, or direct assignment.

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 Mention

type Mention struct {
	ScreenName string `json:"screenName"`
	UserID     string `json:"userId"`
}

Mention represents mention in the message.

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.

func (*RestAPIClient) Rooms

func (client *RestAPIClient) Rooms(ctx context.Context) (*Rooms, error)

Rooms fetches belonging rooms information.

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

type RoomMessage struct {
	Room            *Room
	ReceivedMessage *Message
}

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 Rooms

type Rooms []*Room

Rooms is a group of Room

type RoomsFetcher

type RoomsFetcher interface {
	Rooms(context.Context) (*Rooms, error)
}

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

type TimeStamp struct {
	Time          time.Time
	OriginalValue string // e.g. "2014-03-24T15:41:18.991Z"
}

TimeStamp represents gitter timestamp.

func (*TimeStamp) MarshalText

func (timeStamp *TimeStamp) MarshalText() ([]byte, error)

MarshalText marshals TimeStamp to gitter-styled one.

func (*TimeStamp) String

func (timeStamp *TimeStamp) String() string

String returns original gitter-styled timestamp value.

func (*TimeStamp) UnmarshalText

func (timeStamp *TimeStamp) UnmarshalText(b []byte) error

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

Jump to

Keyboard shortcuts

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