当前位置: 首页>>代码示例>>Golang>>正文


Golang hipchat.NewClient函数代码示例

本文整理汇总了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)
	}
}
开发者ID:shkw,项目名称:hipchat-go,代码行数:29,代码来源:main.go

示例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
}
开发者ID:masom,项目名称:doorbot,代码行数:30,代码来源:hipchat.go

示例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
}
开发者ID:simudream,项目名称:resourced,代码行数:32,代码来源:hipchat.go

示例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.")
	}
}
开发者ID:malonem,项目名称:hipchat-notification-cli,代码行数:29,代码来源:main.go

示例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
}
开发者ID:johnt337,项目名称:pingdom,代码行数:29,代码来源:hipchat.go

示例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
}
开发者ID:masom,项目名称:doorbot,代码行数:35,代码来源:hipchat.go

示例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)
	}
}
开发者ID:hannibal0112,项目名称:hipchat-go,代码行数:12,代码来源:SendNotification.go

示例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
}
开发者ID:bkreed,项目名称:walter,代码行数:14,代码来源:hipchat2.go

示例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)
		}
	}
}
开发者ID:joshrendek,项目名称:influx-alert,代码行数:15,代码来源:notifiers.go

示例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
}
开发者ID:nubo,项目名称:hiprus,代码行数:16,代码来源:hiprus.go

示例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
}
开发者ID:danriti,项目名称:standup,代码行数:17,代码来源:standup.go

示例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
}
开发者ID:samdfonseca,项目名称:hipcat,代码行数:17,代码来源:hipcat.go

示例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 !")
}
开发者ID:JC1738,项目名称:hipchat-go,代码行数:17,代码来源:main.go

示例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)
	}
}
开发者ID:JustAdam,项目名称:metl,代码行数:18,代码来源:Notifications.go

示例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
}
开发者ID:herzog31,项目名称:service-discovery,代码行数:18,代码来源:hipchat.go


注:本文中的github.com/tbruyelle/hipchat-go/hipchat.NewClient函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。