forked from moul/go-freebox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcall.go
67 lines (58 loc) · 1.43 KB
/
call.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
package freebox
import (
"fmt"
"strconv"
"time"
)
// Airmedia
type CallEntry struct {
Number string `json:"number"`
Type string `json:"type"`
ID int `json:"id"`
Duration int `json:"duration"`
Datetime Epoch `json:"datetime"`
ContactID int `json:"contact_id"`
LineID int `json:"line_id"`
Name string `json:"name"`
New bool `json:"new"`
}
// Special handler from epoch to time
type Epoch time.Time
func (e *Epoch) UnmarshalJSON(data []byte) error {
millis, err := strconv.ParseInt(string(data), 10, 64)
if err != nil {
return err
}
*e = Epoch(time.Unix(millis, 0))
return nil
}
func (e Epoch) String() string {
return time.Time(e).Format("2006-01-02 15:04:05")
}
// Get call log
func (c *Client) GetCallEntries() ([]CallEntry, error) {
payload := []CallEntry{}
err := c.GetResult("call/log/", &payload)
if err != nil {
return nil, err
}
return payload, nil
}
// Mark all as read
func (c *Client) MarkAllRead() error {
_, err := c.PostResource("call/log/mark_all_as_read/", "", true)
return err
}
// Mark as read
func (c *Client) MarkRead(id int) error {
payload, _ := c.GetCallEntrie(id)
payload.New = false
_, err := c.PutResource(fmt.Sprintf("call/log/%v", id), &payload, true)
return err
}
// Get a call
func (c *Client) GetCallEntrie(id int) (CallEntry, error) {
payload := CallEntry{}
err := c.GetResult(fmt.Sprintf("call/log/%v", id), &payload)
return payload, err
}