-
Notifications
You must be signed in to change notification settings - Fork 0
/
punchmark.go
71 lines (60 loc) · 1.66 KB
/
punchmark.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
package bugyoclient
import (
"errors"
"fmt"
"net/url"
)
type ClockType string
const (
ClockTypeClockIn = ClockType("ClockIn")
ClockTypeClockOut = ClockType("ClockOut")
ClockTypeGoOut = ClockType("GoOut")
ClockTypeReturned = ClockType("Returned")
)
func (b *bugyoClient) Punchmark(clockType ClockType) error {
// move PunchMark page
if err := b.movePunchMarkPage(); err != nil {
return err
}
// ClockIn/ClockOut
if err := b.insertReadDateTime(clockType); err != nil {
return err
}
return nil
}
func (b *bugyoClient) movePunchMarkPage() error {
if b.userCode == "" {
return errors.New("login required")
}
// GET: https://hromssp.obc.jp/{tenantCode}/{userCode}/timeclock/punchmark/
uri := fmt.Sprintf(urlPunchmarkPage, b.config.TenantCode, b.userCode)
doc, err := b.get(uri)
if err != nil {
return err
}
if token, ok := doc.Find("input[name=__RequestVerificationToken]").Attr("value"); ok {
b.token = token
return nil
}
return errors.New("no token")
}
func (b *bugyoClient) insertReadDateTime(clockType ClockType) error {
if b.userCode == "" {
return errors.New("login required")
}
// POST https://hromssp.obc.jp/{tenantCode}/{userCode}/TimeClock/InsertReadDateTime/
uri := fmt.Sprintf(urlInsertReadDateTime, b.config.TenantCode, b.userCode)
body := url.Values{}
body.Set("ClockType", string(clockType))
body.Set("LaborSystemID", "0")
body.Set("LaborSystemCode", "")
body.Set("LaborSystemName", "")
body.Set("PositionLatitude", "35.6812") // FIXME: tokyo station
body.Set("PositionLongitude", "139.7671") // FIXME: tokyo station
body.Set("PositionAccuracy", "0")
_, err := b.post(uri, body)
if err != nil {
return err
}
return nil
}