hipchat

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2016 License: Apache-2.0, GPL-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package hipchat provides a client for using the HipChat API v2.

Index

Constants

View Source
const (
	// ScopeAdminGroup - Perform group administrative tasks
	ScopeAdminGroup = "admin_group"

	// ScopeAdminRoom - Perform room administrative tasks
	ScopeAdminRoom = "admin_room"

	// ScopeImportData - Import users, rooms, and chat history. Only available for select add-ons.
	ScopeImportData = "import_data"

	// ScopeManageRooms - Create, update, and remove rooms
	ScopeManageRooms = "manage_rooms"

	// ScopeSendMessage - Send private one-on-one messages
	ScopeSendMessage = "send_message"

	// ScopeSendNotification - Send room notifications
	ScopeSendNotification = "send_notification"

	// ScopeViewGroup - View users, rooms, and other group information
	ScopeViewGroup = "view_group"

	// ScopeViewMessages - View messages from chat rooms and private chats you have access to
	ScopeViewMessages = "view_messages"

	// ScopeViewRoom - View room information and participants, but not history
	ScopeViewRoom = "view_room"
)
View Source
const (
	// CardStyleFile represents a Card notification related to a file
	CardStyleFile = "file"

	// CardStyleImage represents a Card notification related to an image
	CardStyleImage = "image"

	// CardStyleApplication represents a Card notification related to an application
	CardStyleApplication = "application"

	// CardStyleLink represents a Card notification related to a link
	CardStyleLink = "link"

	// CardStyleMedia represents a Card notiifcation related to media
	CardStyleMedia = "media"
)

Variables

View Source
var AuthTest = false

AuthTest can be set to true to test an auth token.

HipChat API docs: https://www.hipchat.com/docs/apiv2/auth#auth_test

View Source
var AuthTestResponse = map[string]interface{}{}

AuthTestResponse will contain the server response of any API calls if AuthTest=true.

Functions

This section is empty.

Types

type Activity added in v0.4.0

type Activity struct {
	Icon *Icon  `json:"icon,omitempty"`
	HTML string `json:"html,omitempty"`
}

Activity represents an activity that occurred

type Attribute added in v0.4.0

type Attribute struct {
	Label string         `json:"label,omitempty"`
	Value AttributeValue `json:"value"`
}

Attribute represents an attribute on a Card

type AttributeValue added in v0.4.0

type AttributeValue struct {
	URL   string `json:"url,omitempty"`
	Style string `json:"style,omitempty"`
	Label string `json:"label"`
	Icon  *Icon  `json:"icon,omitempty"`
}

AttributeValue represents the value of an attribute

type Card added in v0.4.0

type Card struct {
	Style       string          `json:"style"`
	Description CardDescription `json:"description"`
	Format      string          `json:"format,omitempty"`
	URL         string          `json:"url,omitempty"`
	Title       string          `json:"title"`
	Thumbnail   *Icon           `json:"thumbnail,omitempty"`
	Activity    *Activity       `json:"activity,omitempty"`
	Attributes  []Attribute     `json:"attributes,omitempty"`
	ID          string          `json:"id,omitempty"`
	Icon        *Icon           `json:"icon,omitempty"`
}

Card is used to send information as messages to Hipchat rooms

func (*Card) AddAttribute added in v0.4.0

func (c *Card) AddAttribute(mainLabel, subLabel, url, iconURL string)

AddAttribute adds an attribute to a Card

type CardDescription added in v0.4.0

type CardDescription struct {
	Format string
	Value  string
}

CardDescription represents the main content of the Card

func (CardDescription) MarshalJSON added in v0.4.0

func (c CardDescription) MarshalJSON() ([]byte, error)

MarshalJSON serializes a CardDescription into JSON

func (*CardDescription) UnmarshalJSON added in v0.4.0

func (c *CardDescription) UnmarshalJSON(data []byte) error

UnmarshalJSON deserializes a JSON-serialized CardDescription

type Client

type Client struct {
	BaseURL *url.URL

	// Room gives access to the /room part of the API.
	Room *RoomService
	// User gives access to the /user part of the API.
	User *UserService
	// Emoticon gives access to the /emoticon part of the API.
	Emoticon *EmoticonService
	// contains filtered or unexported fields
}

Client manages the communication with the HipChat API.

func NewClient

func NewClient(authToken string) *Client

NewClient returns a new HipChat API client. You must provide a valid AuthToken retrieved from your HipChat account.

func (*Client) Do

func (c *Client) Do(req *http.Request, v interface{}) (*http.Response, error)

Do performs the request, the json received in the response is decoded and stored in the value pointed by v. Do can be used to perform the request created with NewRequest, as the latter it should be used only for API requests not implemented in this library.

func (*Client) GenerateToken added in v0.4.0

func (c *Client) GenerateToken(credentials ClientCredentials, scopes []string) (*OAuthAccessToken, *http.Response, error)

GenerateToken returns back an access token for a given integration's client ID and client secret

HipChat API documentation: https://www.hipchat.com/docs/apiv2/method/generate_token

func (*Client) NewFileUploadRequest

func (c *Client) NewFileUploadRequest(method, urlStr string, v interface{}) (*http.Request, error)

NewFileUploadRequest creates an API request to upload a file. This method manually formats the request as multipart/related with a single part of content-type application/json and a second part containing the file to be sent. Relative URLs should always be specified without a preceding slash.

func (*Client) NewRequest

func (c *Client) NewRequest(method, urlStr string, opt interface{}, body interface{}) (*http.Request, error)

NewRequest creates an API request. This method can be used to performs API request not implemented in this library. Otherwise it should not be be used directly. Relative URLs should always be specified without a preceding slash.

func (*Client) SetHTTPClient added in v0.4.0

func (c *Client) SetHTTPClient(httpClient *http.Client)

SetHTTPClient sets the HTTP client for performing API requests. If a nil httpClient is provided, http.DefaultClient will be used.

type ClientCredentials added in v0.4.0

type ClientCredentials struct {
	ClientID     string
	ClientSecret string
}

ClientCredentials represents the OAuth2 client ID and secret for an integration

type CreateRoomRequest

type CreateRoomRequest struct {
	Topic       string `json:"topic,omitempty"`
	GuestAccess bool   `json:"guest_access,omitempty"`
	Name        string `json:"name,omitempty"`
	OwnerUserID string `json:"owner_user_id,omitempty"`
	Privacy     string `json:"privacy,omitempty"`
}

CreateRoomRequest represents a HipChat room creation request.

type CreateWebhookRequest

type CreateWebhookRequest struct {
	Name    string `json:"name"`
	Event   string `json:"event"`
	Pattern string `json:"pattern"`
	URL     string `json:"url"`
}

CreateWebhookRequest represents the body of the CreateWebhook method.

type Emoticon

type Emoticon struct {
	ID       int    `json:"id"`
	URL      string `json:"url"`
	Links    Links  `json:"links"`
	Shortcut string `json:"shortcut"`
}

Emoticon represents a hipchat emoticon.

type EmoticonService

type EmoticonService struct {
	// contains filtered or unexported fields
}

EmoticonService gives access to the emoticon related part of the API.

func (*EmoticonService) List

List returns the list of all the emoticons

HipChat api docs : https://www.hipchat.com/docs/apiv2/method/get_all_emoticons

type Emoticons

type Emoticons struct {
	Items      []Emoticon `json:"items"`
	StartIndex int        `json:"startIndex"`
	MaxResults int        `json:"maxResults"`
	Links      PageLinks  `json:"links"`
}

Emoticons represents a list of hipchat emoticons.

type EmoticonsListOptions added in v0.4.0

type EmoticonsListOptions struct {
	ListOptions

	// The type of emoticons to get (global, group or all)
	Type string `url:"type,omitempty"`
}

EmoticonsListOptions specifies the optionnal parameters of the EmoticonService.List method.

type History

type History struct {
	Items      []Message `json:"items"`
	StartIndex int       `json:"startIndex"`
	MaxResults int       `json:"maxResults"`
	Links      PageLinks `json:"links"`
}

History represents a HipChat room chat history.

type HistoryOptions added in v0.4.0

type HistoryOptions struct {
	ListOptions

	// Either the latest date to fetch history for in ISO-8601 format, or 'recent' to fetch
	// the latest 75 messages. Paging isn't supported for 'recent', however they are real-time
	// values, whereas date queries may not include the most recent messages.
	Date string `url:"date,omitempty"`

	// Your timezone. Must be a supported timezone
	Timezone string `url:"timezone,omitempty"`

	// Reverse the output such that the oldest message is first.
	// For consistent paging, set to 'false'.
	Reverse bool `url:"reverse,omitempty"`
}

HistoryOptions represents a HipChat room chat history request.

type ID

type ID struct {
	ID string `json:"id"`
}

ID represents a HipChat id. Use a separate struct because it can be a string or a int.

type Icon added in v0.4.0

type Icon struct {
	URL   string `json:"url"`
	URL2x string `json:"url@2x,omitempty"`
}

Icon represents an icon

type InviteRequest

type InviteRequest struct {
	Reason string `json:"reason"`
}

InviteRequest represents a hipchat invite to room request

type LatestHistoryOptions added in v0.4.0

type LatestHistoryOptions struct {

	// The maximum number of messages to return.
	MaxResults int `url:"max-results,omitempty"`

	// Your timezone. Must be a supported timezone.
	Timezone string `url:"timezone,omitempty"`

	// The id of the message that is oldest in the set of messages to be returned.
	// The server will not return any messages that chronologically precede this message.
	NotBefore string `url:"not-before,omitempty"`
}

LatestHistoryOptions represents a HipChat room chat latest history request.

type Links struct {
	Self string `json:"self"`
}

Links represents the HipChat default links.

type ListOptions added in v0.4.0

type ListOptions struct {
	// For paginated results, represents the first page to display.
	StartIndex int `url:"start-index,omitempty"`
	// For paginated results, reprensents the number of items per page.
	MaxResults int `url:"max-results,omitempty"`
}

ListOptions specifies the optional parameters to various List methods that support pagination.

type ListWebhooksOptions added in v0.4.0

type ListWebhooksOptions struct {
	ListOptions
}

ListWebhooksOptions represents options for ListWebhooks method.

type Message

type Message struct {
	Date          string      `json:"date"`
	From          interface{} `json:"from"` // string | obj <- weak
	ID            string      `json:"id"`
	Mentions      []User      `json:"mentions"`
	Message       string      `json:"message"`
	MessageFormat string      `json:"message_format"`
	Type          string      `json:"type"`
}

Message represents a HipChat message.

type MessageRequest

type MessageRequest struct {
	Message       string `json:"message,omitempty"`
	Notify        bool   `json:"notify,omitempty"`
	MessageFormat string `json:"message_format,omitempty"`
}

MessageRequest represents a HipChat private message to user.

type NotificationRequest

type NotificationRequest struct {
	Color         string `json:"color,omitempty"`
	Message       string `json:"message,omitempty"`
	Notify        bool   `json:"notify,omitempty"`
	MessageFormat string `json:"message_format,omitempty"`
	From          string `json:"from,omitempty"`
	Card          *Card  `json:"card,omitempty"`
}

NotificationRequest represents a HipChat room notification request.

type OAuthAccessToken added in v0.4.0

type OAuthAccessToken struct {
	AccessToken string `json:"access_token"`
	ExpiresIn   uint32 `json:"expires_in"`
	GroupID     uint32 `json:"group_id"`
	GroupName   string `json:"group_name"`
	Scope       string `json:"scope"`
	TokenType   string `json:"token_type"`
}

OAuthAccessToken represents a newly created Hipchat OAuth access token

func (*OAuthAccessToken) CreateClient added in v0.4.0

func (t *OAuthAccessToken) CreateClient() *Client

CreateClient creates a new client from this OAuth token

type PageLinks struct {
	Links
	Prev string `json:"prev"`
	Next string `json:"next"`
}

PageLinks represents the HipChat page links.

type Room

type Room struct {
	ID                int            `json:"id"`
	Links             RoomLinks      `json:"links"`
	Name              string         `json:"name"`
	XmppJid           string         `json:"xmpp_jid"`
	Statistics        RoomStatistics `json:"statistics"`
	Created           string         `json:"created"`
	IsArchived        bool           `json:"is_archived"`
	Privacy           string         `json:"privacy"`
	IsGuestAccessible bool           `json:"is_guess_accessible"`
	Topic             string         `json:"topic"`
	Participants      []User         `json:"participants"`
	Owner             User           `json:"owner"`
	GuestAccessURL    string         `json:"guest_access_url"`
}

Room represents a HipChat room.

type RoomLinks struct {
	Links
	Webhooks     string `json:"webhooks"`
	Members      string `json:"members"`
	Participants string `json:"participants"`
}

RoomLinks represents the HipChat room links.

type RoomService

type RoomService struct {
	// contains filtered or unexported fields
}

RoomService gives access to the room related methods of the API.

func (*RoomService) Create

func (r *RoomService) Create(roomReq *CreateRoomRequest) (*Room, *http.Response, error)

Create creates a new room.

HipChat API docs: https://www.hipchat.com/docs/apiv2/method/create_room

func (*RoomService) CreateWebhook

func (r *RoomService) CreateWebhook(id interface{}, roomReq *CreateWebhookRequest) (*Webhook, *http.Response, error)

CreateWebhook creates a new webhook.

HipChat API docs: https://www.hipchat.com/docs/apiv2/method/create_webhook

func (*RoomService) Delete

func (r *RoomService) Delete(id string) (*http.Response, error)

Delete deletes an existing room.

HipChat API docs: https://www.hipchat.com/docs/apiv2/method/delete_room

func (*RoomService) DeleteWebhook

func (r *RoomService) DeleteWebhook(id interface{}, webhookID interface{}) (*http.Response, error)

DeleteWebhook removes the given webhook.

HipChat API docs: https://www.hipchat.com/docs/apiv2/method/delete_webhook

func (*RoomService) Get

func (r *RoomService) Get(id string) (*Room, *http.Response, error)

Get returns the room specified by the id.

HipChat API docs: https://www.hipchat.com/docs/apiv2/method/get_room

func (*RoomService) History

func (r *RoomService) History(id string, opt *HistoryOptions) (*History, *http.Response, error)

History fetches a room's chat history.

HipChat API docs: https://www.hipchat.com/docs/apiv2/method/view_room_history

func (*RoomService) Invite

func (r *RoomService) Invite(room string, user string, reason string) (*http.Response, error)

Invite someone to the Room.

HipChat API docs: https://www.hipchat.com/docs/apiv2/method/invite_user

func (*RoomService) Latest added in v0.4.0

func (r *RoomService) Latest(id string, opt *LatestHistoryOptions) (*History, *http.Response, error)

Latest fetches a room's chat history.

HipChat API docs: https://www.hipchat.com/docs/apiv2/method/view_recent_room_history

func (*RoomService) List

func (r *RoomService) List() (*Rooms, *http.Response, error)

List returns all the rooms authorized.

HipChat API docs: https://www.hipchat.com/docs/apiv2/method/get_all_rooms

func (*RoomService) ListWebhooks

func (r *RoomService) ListWebhooks(id interface{}, opt *ListWebhooksOptions) (*WebhookList, *http.Response, error)

ListWebhooks returns all the webhooks for a given room.

HipChat API docs: https://www.hipchat.com/docs/apiv2/method/get_all_webhooks

func (*RoomService) Notification

func (r *RoomService) Notification(id string, notifReq *NotificationRequest) (*http.Response, error)

Notification sends a notification to the room specified by the id.

HipChat API docs: https://www.hipchat.com/docs/apiv2/method/send_room_notification

func (*RoomService) SetTopic

func (r *RoomService) SetTopic(id string, topic string) (*http.Response, error)

SetTopic sets Room topic.

HipChat API docs: https://www.hipchat.com/docs/apiv2/method/set_topic

func (*RoomService) ShareFile

func (r *RoomService) ShareFile(id string, shareFileReq *ShareFileRequest) (*http.Response, error)

ShareFile sends a file to the room specified by the id.

HipChat API docs: https://www.hipchat.com/docs/apiv2/method/share_file_with_room

func (*RoomService) Update

func (r *RoomService) Update(id string, roomReq *UpdateRoomRequest) (*http.Response, error)

Update updates an existing room.

HipChat API docs: https://www.hipchat.com/docs/apiv2/method/update_room

type RoomStatistics

type RoomStatistics struct {
	Links Links `json:"links"`
}

RoomStatistics represents the HipChat room statistics.

type Rooms

type Rooms struct {
	Items      []Room    `json:"items"`
	StartIndex int       `json:"startIndex"`
	MaxResults int       `json:"maxResults"`
	Links      PageLinks `json:"links"`
}

Rooms represents a HipChat room list.

type SetTopicRequest

type SetTopicRequest struct {
	Topic string `json:"topic"`
}

SetTopicRequest represents a hipchat update topic request

type ShareFileRequest

type ShareFileRequest struct {
	Path     string `json:"path"`
	Filename string `json:"filename,omitempty"`
	Message  string `json:"message,omitempty"`
}

ShareFileRequest represents a HipChat room file share request.

type Thumbnail added in v0.4.0

type Thumbnail struct {
	URL    string `json:"url"`
	URL2x  string `json:"url@2x,omitempty"`
	Width  uint   `json:"width,omitempty"`
	Height uint   `json:"url,omitempty"`
}

Thumbnail represents a thumbnail image

type UpdateRoomRequest

type UpdateRoomRequest struct {
	Name          string `json:"name"`
	Topic         string `json:"topic"`
	IsGuestAccess bool   `json:"is_guest_access"`
	IsArchived    bool   `json:"is_archived"`
	Privacy       string `json:"privacy"`
	Owner         ID     `json:"owner"`
}

UpdateRoomRequest represents a HipChat room update request.

type User

type User struct {
	XmppJid      string       `json:"xmpp_jid"`
	IsDeleted    bool         `json:"is_deleted"`
	Name         string       `json:"name"`
	LastActive   string       `json:"last_active"`
	Title        string       `json:"title"`
	Presence     UserPresence `json:"presence"`
	Created      string       `json:"created"`
	ID           int          `json:"id"`
	MentionName  string       `json:"mention_name"`
	IsGroupAdmin bool         `json:"is_group_admin"`
	Timezone     string       `json:"timezone"`
	IsGuest      bool         `json:"is_guest"`
	Email        string       `json:"email"`
	PhotoURL     string       `json:"photo_url"`
	Links        Links        `json:"links"`
}

User represents the HipChat user.

type UserListOptions added in v0.4.0

type UserListOptions struct {
	ListOptions
	// Include active guest users in response.
	IncludeGuests bool `url:"include-guests,omitempty"`
	// Include deleted users in response.
	IncludeDeleted bool `url:"include-deleted,omitempty"`
}

UserListOptions specified the parameters to the UserService.List method.

type UserPresence

type UserPresence struct {
	Status   string `json:"status"`
	Idle     int    `json:"idle"`
	Show     string `json:"show"`
	IsOnline bool   `json:"is_online"`
}

UserPresence represents the HipChat user's presence.

type UserService

type UserService struct {
	// contains filtered or unexported fields
}

UserService gives access to the user related methods of the API.

func (*UserService) List

func (u *UserService) List(opt *UserListOptions) ([]User, *http.Response, error)

List returns all users in the group.

HipChat API docs: https://www.hipchat.com/docs/apiv2/method/get_all_users

func (*UserService) Message

func (u *UserService) Message(id string, msgReq *MessageRequest) (*http.Response, error)

Message sends a private message to the user specified by the id.

HipChat API docs: https://www.hipchat.com/docs/apiv2/method/private_message_user

func (*UserService) ShareFile

func (u *UserService) ShareFile(id string, shareFileReq *ShareFileRequest) (*http.Response, error)

ShareFile sends a file to the user specified by the id.

HipChat API docs: https://www.hipchat.com/docs/apiv2/method/share_file_with_user

func (*UserService) View

func (u *UserService) View(id string) (*User, *http.Response, error)

View fetches a user's details.

HipChat API docs: https://www.hipchat.com/docs/apiv2/method/view_user

type Users

type Users struct {
	Items      []User `json:"items"`
	StartIndex int    `json:"start_index"`
	MaxResults int    `json:"max_results"`
	Links      Links  `json:"links"`
}

Users represents the API return of a collection of Users plus metadata

type Webhook

type Webhook struct {
	Links   Links  `json:"links"`
	Name    string `json:"name"`
	Event   string `json:"event"`
	Pattern string `json:"pattern"`
	URL     string `json:"url"`
	ID      int    `json:"id,omitempty"`
}

Webhook represents a HipChat webhook.

type WebhookList

type WebhookList struct {
	Webhooks   []Webhook `json:"items"`
	StartIndex int       `json:"startIndex"`
	MaxResults int       `json:"maxResults"`
	Links      PageLinks `json:"links"`
}

WebhookList represents a HipChat webhook list.

Jump to

Keyboard shortcuts

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