Esempio n. 1
0
func tasks() {
	token := os.Getenv("CHATWORK_API_TOKEN")
	if token == "" {
		fmt.Println("skip this test because no token")
		return
	}

	client := chatwork.New(token)

	task, err := client.GetSpecificTask(42, 21)
	if err == nil {
		fmt.Println(task)
	} else {
		fmt.Println(err)
	}

	taskIDs, err := client.PostTasks(42, "new task", time.Now(), []int64{1})
	if err == nil {
		fmt.Println(taskIDs)
	} else {
		fmt.Println(err)
	}

	tasks, err := client.GetTasks(42, 0, 0, "done")
	if err == nil {
		fmt.Println(tasks)
	} else {
		fmt.Println(err)
	}
}
Esempio n. 2
0
func member() {
	token := os.Getenv("CHATWORK_API_TOKEN")
	if token == "" {
		fmt.Println("skip this test because no token")
		return
	}

	client := chatwork.New(token)
	admin := []int64{1}
	var member []int64
	read := []int64{2}
	ad, me, re, err := client.PutMembers(42, admin, member, read)
	if err == nil {
		fmt.Println(ad)
		fmt.Println(me)
		fmt.Println(re)
	} else {
		fmt.Println("error")
		fmt.Println(err)
	}

	accounts, err := client.GetMembers(42)
	if err == nil {
		fmt.Println(accounts)
	} else {
		fmt.Println("error")
		fmt.Println(err)
	}
}
Esempio n. 3
0
func sendMessage(roomID int64, message string) bool {
	if roomID == 0 {
		fmt.Println("please set roomID (-r option)")
		return false
	}
	if message == "" {
		fmt.Println("please set message (-m option)")
		return false
	}

	apiToken, err := getApiToken(ChatworkDomain)
	if err != nil {
		fmt.Println(err)
		return false
	}

	ch := chatwork.New(apiToken)
	if ch == nil {
		fmt.Println("create chatwork client error")
		return false
	}
	_, err = ch.PostMessage(roomID, message)
	if err != nil {
		fmt.Println(err)
		return false
	}
	return true
}
Esempio n. 4
0
func message() {
	token := os.Getenv("CHATWORK_API_TOKEN")
	if token == "" {
		fmt.Println("skip this test because no token")
		return
	}

	client := chatwork.New(token)

	message, err := client.GetSpecificMessage(42, 21)
	if err == nil {
		fmt.Println(message)
	} else {
		fmt.Println(err)
	}

	messages, err := client.GetMessage(42, true)
	if err == nil {
		fmt.Println(messages)
	} else {
		fmt.Println(err)
	}

	messageID, err := client.PostMessage(42, "test")
	if err == nil {
		fmt.Println(messageID)
	} else {
		fmt.Println(err)
	}
}
Esempio n. 5
0
func my() {
	token := os.Getenv("CHATWORK_API_TOKEN")
	if token == "" {
		fmt.Println("skip this test because no token")
		return
	}

	client := chatwork.New(token)

	status, err := client.MyStatus()
	if err == nil {
		fmt.Println(status)
	} else {
		fmt.Println(err)
	}

	params := url.Values{}
	params.Add("status", "done")

	tasks, err := client.MyTasks(params)
	if err == nil {
		fmt.Println(tasks)
	} else {
		fmt.Println(err)
	}
}
Esempio n. 6
0
func me() {
	token := os.Getenv("CHATWORK_API_TOKEN")
	if token == "" {
		fmt.Println("skip this test because no token")
		return
	}

	client := chatwork.New(token)
	me, err := client.Me()
	if err == nil {
		fmt.Println(me)
	} else {
		fmt.Println(err)
	}
}
Esempio n. 7
0
func contacts() {
	token := os.Getenv("CHATWORK_API_TOKEN")
	if token == "" {
		fmt.Println("skip this test because no token")
		return
	}

	client := chatwork.New(token)

	accounts, err := client.GetContacts()
	if err == nil {
		fmt.Println(accounts)
	} else {
		fmt.Println(err)
	}
}
Esempio n. 8
0
func NewWatchAPI(duration int) (*watchAPI, error) {
	apiToken, err := getApiToken(ChatworkDomain)
	if err != nil {
		return nil, err
	}

	if duration <= 0 {
		duration = 1
	}

	watch := &watchAPI{
		ch:        chatwork.New(apiToken),
		duration:  time.Duration(duration) * time.Minute,
		checkTime: time.Now(),
		unReads:   make(map[int64]int64),
	}

	return watch, nil
}
Esempio n. 9
0
func room() {
	token := os.Getenv("CHATWORK_API_TOKEN")
	if token == "" {
		fmt.Println("skip this test because no token")
		return
	}

	client := chatwork.New(token)

	newRoomID, err := client.PostRooms("description", "project", []int64{}, []int64{}, []int64{}, "name")
	if err == nil {
		fmt.Println(newRoomID)
	} else {
		fmt.Println(err)
	}

	err = client.DeleteRooms(42, "delete")
	if err == nil {
		fmt.Println(err)
	}

	roomID, err := client.PutRooms(42, "dest", "idea", "test")
	if err == nil {
		fmt.Println(roomID)
	} else {
		fmt.Println(err)
	}

	rooms, err := client.GetRooms()
	if err == nil {
		fmt.Println(rooms)
	} else {
		fmt.Println(err)
	}

	room, err := client.GetSpecificRooms(42)
	if err == nil {
		fmt.Println(room)
	} else {
		fmt.Println(err)
	}
}
Esempio n. 10
0
func files() {
	token := os.Getenv("CHATWORK_API_TOKEN")
	if token == "" {
		fmt.Println("skip this test because no token")
		return
	}

	client := chatwork.New(token)

	file, err := client.GetSpecificFiles(42, 21, true)
	if err == nil {
		fmt.Println(file)
	} else {
		fmt.Println(err)
	}

	files, err := client.GetFiles(42, 0)
	if err == nil {
		fmt.Println(files)
	} else {
		fmt.Println(err)
	}
}