/
main.go
105 lines (85 loc) · 1.83 KB
/
main.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package main
import (
"flag"
"fmt"
"log"
"net/http"
"os"
"github.com/BurntSushi/toml"
"github.com/k0kubun/pp"
"github.com/kaneshin/go-talentio/talentio"
"github.com/kaneshin/go-talentio/talentio/talentioutil"
)
const (
success = iota
failure
)
var (
page = flag.Int("page", 1, "")
status = flag.String("status", "ongoing", "")
configPath = flag.String("config", "$HOME/.config/talentio.tml", "")
)
// config represents a configuration of commands.
var config = struct {
AccessToken string `toml:"access_token"`
}{}
func flagParse() {
flag.Parse()
if *page < 0 {
*page = 1
}
statuses := [6]string{
talentio.StatusOngoing,
talentio.StatusReject,
talentio.StatusFail,
talentio.StatusPass,
talentio.StatusPoolActive,
talentio.StatusPoolInactive,
}
for _, s := range statuses {
if *status == s {
goto STATUS_OK
}
}
*status = talentio.StatusOngoing
STATUS_OK:
fp := os.ExpandEnv(*configPath)
_, _ = toml.DecodeFile(fp, &config)
}
func run() int {
flagParse()
c := talentio.NewConfig().WithHTTPClient(http.DefaultClient)
str := config.AccessToken
if str == "" {
str = os.Getenv("TALENTIO_ACCESS_TOKEN")
}
c.WithAccessToken(str)
client := talentio.NewClient(c)
cands, err := talentioutil.Candidates.List(client, &talentioutil.CandidatesListOptions{
MaxPage: 10,
Status: talentio.StatusOngoing,
Sort: talentio.SortRegisteredAtDescKey,
})
if err != nil {
log.Println(err)
return failure
}
for _, candidate := range cands {
fmt.Printf("ID=%d, RegisteredAt=%v\n", candidate.ID, candidate.RegisteredAt)
}
if len(cands) == 0 {
return 0
}
// Show details of candidates.
if err = talentioutil.Candidates.ApplyDetails(client, cands); err != nil {
log.Println(err)
return failure
}
for _, cand := range cands {
pp.Println(cand)
}
return 0
}
func main() {
os.Exit(run())
}