本文整理汇总了Golang中github.com/tbruyelle/hipchat-go/hipchat.NewClient函数的典型用法代码示例。如果您正苦于以下问题:Golang NewClient函数的具体用法?Golang NewClient怎么用?Golang NewClient使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewClient函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: main
func main() {
flag.Parse()
if *token == "" || *roomId == "" {
flag.PrintDefaults()
return
}
c := hipchat.NewClient(*token)
hist, resp, err := c.Room.History(*roomId, &hipchat.HistoryRequest{})
if err != nil {
fmt.Printf("Error during room history req %q\n", err)
fmt.Printf("Server returns %+v\n", resp)
return
}
for _, m := range hist.Items {
from := ""
switch m.From.(type) {
case string:
from = m.From.(string)
case map[string]interface{}:
f := m.From.(map[string]interface{})
from = f["name"].(string)
}
msg := m.Message
if len(m.Message) > (maxMsgLen - len(moreString)) {
msg = fmt.Sprintf("%s%s", strings.Replace(m.Message[:maxMsgLen], "\n", " - ", -1), moreString)
}
fmt.Printf("%s [%s]: %s\n", from, m.Date, msg)
}
}
示例2: KnockKnock
// KnockKnock sends a private message to a user.
func (h *HipChat) KnockKnock(d *doorbot.Door, p *doorbot.Person) error {
log.WithFields(log.Fields{
"account_id": h.Account.ID,
"person_id": p.ID,
"door_id": d.ID,
}).Info("Notificator::HipChat->Notify request")
c := hipchat.NewClient(h.Token)
dbb := rendering.DoorbotBar()
renderingData := map[string]string{
"name": p.Name,
"door": d.Name,
}
messageRequest := &hipchat.MessageRequest{
Message: dbb.Render("Hi {{name}},\nThere is someone waiting at the {{door}}.\n\n - Doorbot", renderingData),
Notify: true,
}
response, err := c.User.Message(p.Email, messageRequest)
if response.StatusCode != 200 {
return err
}
return nil
}
示例3: Run
// Run shells out external program and store the output on c.Data.
func (hc *HipChat) Run() error {
hc.Data["Conditions"] = hc.Conditions
if hc.IsConditionMet() && hc.LowThresholdExceeded() && !hc.HighThresholdExceeded() {
c := hipchat.NewClient(hc.AuthToken)
rooms, _, err := c.Room.List()
if err != nil {
return err
}
hc.Data["Message"] = fmt.Sprintf("Conditions: %v, Message: %v", hc.Conditions, hc.Message)
notificationReq := &hipchat.NotificationRequest{Message: hc.Data["Message"].(string)}
for _, room := range rooms.Items {
if room.Name == hc.RoomName {
_, err := c.Room.Notification(room.Name, notificationReq)
if err != nil {
return err
}
}
}
if err != nil {
return err
}
}
return nil
}
示例4: main
func main() {
flag.Parse()
notification, _ := readMessageFromStdin()
if notification == nil {
notification = message
}
if isValidRequest(token, room, notification) {
client := hipchat.NewClient(*token)
request := hipchat.NotificationRequest{
Message: *notification,
Color: *color,
Notify: *notify,
MessageFormat: *format,
}
response, err := client.Room.Notification(*room, &request)
if err != nil {
fmt.Fprintf(os.Stderr, "Error during room notification %q\n", err)
fmt.Fprintf(os.Stderr, "Server returns %+v\n", response)
return
}
} else {
fmt.Fprintln(os.Stderr, "Message, Token, and Room must be specified.")
}
}
示例5: NewHipchat
// NewHipchat -
func NewHipchat(config *HipchatConfig) (h *Hipchat) {
h = &Hipchat{
Config: config,
Room: config.Room,
messages: make(chan *hipchat.NotificationRequest),
}
if config.Token == "" {
h.handler = func(msg *hipchat.NotificationRequest) {
fmt.Printf("hipchat: warning auth token not set")
}
} else {
client := hipchat.NewClient(config.Token)
h.handler = func(msg *hipchat.NotificationRequest) {
if _, err := client.Room.Notification(h.Room, msg); err != nil {
fmt.Printf("hipchat: Failed to send - %q", err)
}
}
}
go func() {
for m := range h.messages {
h.handler(m)
}
}()
return h
}
示例6: GetUsers
func (h *HipChat) GetUsers() ([]*HipChatUser, error) {
log.WithFields(log.Fields{
"account_id": h.AccountID,
"token": h.Token,
}).Info("Bridges::HipChat::GetUsers started")
c := hipchat.NewClient(h.Token)
svcUsers, _, err := c.User.List(0, 1000, false, false)
if err != nil {
log.WithFields(log.Fields{
"account_id": h.AccountID,
"error": err,
}).Error("Bridges::HipChat::GetUsers error")
}
users := make([]*HipChatUser, len(svcUsers))
for k, u := range svcUsers {
details, _, err := c.User.View(strconv.FormatInt(int64(u.ID), 10))
if err != nil {
return users, err
}
users[k] = &HipChatUser{
ID: u.ID,
Email: details.Email,
DisplayName: details.Name,
Title: details.Title,
}
}
return users, err
}
示例7: send_Notify
func send_Notify(token string, id string, message string, color string) {
c := hipchat.NewClient(token)
notifRq := &hipchat.NotificationRequest{Message: message, Color: color}
resp2, err := c.Room.Notification(id, notifRq)
if err != nil {
fmt.Printf("Error during room notification %q\n", err)
fmt.Printf("Server returns %+v\n", resp2)
}
}
示例8: newClient
func (hc *HipChat2) newClient() *hipchat.Client {
client := hipchat.NewClient(hc.Token)
if hc.BaseURL == "" {
return client
}
baseURL, err := url.Parse(hc.BaseURL)
if err != nil {
log.Errorf("Invalid Hipchat Base URL...: %s", err.Error())
return nil
}
client.BaseURL = baseURL
return client
}
示例9: setupHipchat
func setupHipchat() {
hipchat_api = hipchat.NewClient(os.Getenv("HIPCHAT_API_TOKEN"))
if len(os.Getenv("HIPCHAT_API_TOKEN")) == 0 ||
len(os.Getenv("HIPCHAT_ROOM_ID")) == 0 {
color.Yellow("[>] Skipping Hipchat setup, missing HIPCHAT_API_TOKEN and HIPCHAT_ROOM_ID")
return
}
if os.Getenv("HIPCHAT_SERVER") != "" {
hipchat_api.BaseURL, err = url.Parse(os.Getenv("HIPCHAT_SERVER"))
if err != nil {
color.Red("Error connecting to private hipchat server: ", err)
panic(err)
}
}
}
示例10: initClient
func (hh *HiprusHook) initClient() error {
c := hipchat.NewClient(hh.AuthToken)
if hh.BaseURL != "" {
hipchatUrl, _ := url.Parse(hh.BaseURL)
c.BaseURL = hipchatUrl
}
hh.c = c
if hh.Username == "" {
hh.Username = "HipRus"
}
return nil
}
示例11: Notify
func (m *Message) Notify() (success bool, err error) {
c := hipchat.NewClient(token)
nr := &hipchat.NotificationRequest{
Message: m.formatted(),
MessageFormat: "html",
Color: m.color(),
From: "( •_•)",
Notify: true,
}
resp, err := c.Room.Notification(roomId, nr)
if err != nil {
log.Println("error notifying room", err)
return false, err
}
log.Println("success notifying room", resp.StatusCode)
return resp.StatusCode == http.StatusNoContent, err
}
示例12: newHipCat
func newHipCat(authToken string, roomId string, roomName string) (*HipCat, error) {
hc := HipCat{
api: hipchat.NewClient(authToken),
queue: newStreamQ(),
shutdown: make(chan os.Signal, 1),
roomName: roomName,
roomId: roomId,
}
if hc.roomId == "" {
err := hc.lookupRoomId()
if err != nil {
return nil, err
}
}
signal.Notify(hc.shutdown, os.Interrupt)
return &hc, nil
}
示例13: main
func main() {
flag.Parse()
if *token == "" || *roomId == "" {
flag.PrintDefaults()
return
}
c := hipchat.NewClient(*token)
notifRq := &hipchat.NotificationRequest{Message: "Hey there!"}
resp, err := c.Room.Notification(*roomId, notifRq)
if err != nil {
fmt.Printf("Error during room notification %q\n", err)
fmt.Printf("Server returns %+v\n", resp)
return
}
fmt.Println("Lol sent !")
}
示例14: Notify
func (h *HipChat) Notify(msg Message) {
c := hipchat.NewClient(h.Token)
// https://www.hipchat.com/docs/apiv2/method/send_room_notification
nr := &hipchat.NotificationRequest{
Message: msg.String(),
// Update info here based on what type of notify message we have (status)
Notify: false, // Send desktop notification
Color: "green",
}
_, err := c.Room.Notification(h.Room, nr)
if err != nil {
log.WithFields(log.Fields{
"notify": "hipchat",
}).Warn(err)
}
}
示例15: initHipChatClient
func (d *Discovery) initHipChatClient() error {
if len(d.settings.HipChatToken) == 0 {
return errors.New("No HipChat token specified.")
}
d.hipchatClient = hipchat.NewClient(d.settings.HipChatToken)
hipchat.AuthTest = true
d.hipchatClient.Room.List()
_, ok := hipchat.AuthTestResponse["success"]
hipchat.AuthTest = false
if !ok {
return errors.New("Invalid HipChat token.")
}
return nil
}