-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathstocks.go
44 lines (39 loc) · 952 Bytes
/
stocks.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package main
import (
"github.com/codegangsta/cli"
"github.com/pascalw/go-alfred"
"github.com/spf13/viper"
)
func cmdStocks(c *cli.Context) {
query := c.Args()
client, err := newQiitaClient()
if err != nil {
return
}
items, _, err := client.Users.Stocks(viper.GetString("id"), nil)
if err != nil {
errRes := alfred.NewResponse()
errRes.AddItem(&alfred.AlfredResponseItem{
Valid: true,
Title: "Failed to authorize",
Subtitle: "Press 'qiita setup' to setup your personal token",
})
errRes.Print()
return
}
alfred.InitTerms(query)
response := alfred.NewResponse()
for _, item := range items {
if !alfred.MatchesTerms(query, item.Title+item.Body) {
continue
}
response.AddItem(&alfred.AlfredResponseItem{
Valid: true,
Uid: item.Id,
Title: item.Title,
Arg: item.URL,
Subtitle: item.User.Id + " " + item.CreatedAt.Format("2006/01/02 15:04:05"),
})
}
response.Print()
}