forked from ebhomengo/niki
1
0
Fork 0
niki/vendor/github.com/kavenegar/kavenegar-go/message_countInbox.go

71 lines
1.1 KiB
Go
Raw Normal View History

2024-02-18 10:42:21 +00:00
package kavenegar
import (
"net/url"
"time"
)
2024-06-14 08:41:36 +00:00
// MessageCountInbox ...
2024-02-18 10:42:21 +00:00
type MessageCountInbox struct {
Startdate int `json:"startdate"`
Enddate int `json:"enddate"`
Sumcount int `json:"sumcount"`
2024-02-18 10:42:21 +00:00
}
2024-06-14 08:41:36 +00:00
// MessageCountInboxResult ...
2024-02-18 10:42:21 +00:00
type MessageCountInboxResult struct {
*Return `json:"return"`
2024-02-18 10:42:21 +00:00
Entries []MessageCountInbox `json:"entries"`
}
2024-06-14 08:41:36 +00:00
// CountInbox ...
2024-02-18 10:42:21 +00:00
func (message *MessageService) CountInbox(linenumber string, startdate time.Time, endate time.Time, isread bool) (MessageCountInbox, error) {
v := url.Values{}
2024-02-18 10:42:21 +00:00
v.Set("linenumber", linenumber)
2024-02-18 10:42:21 +00:00
v.Set("startdate", ToUnix(startdate))
2024-02-18 10:42:21 +00:00
if !endate.IsZero() {
2024-02-18 10:42:21 +00:00
v.Set("endate", ToUnix(startdate))
2024-02-18 10:42:21 +00:00
}
2024-02-18 10:42:21 +00:00
//if isread != nil {
2024-02-18 10:42:21 +00:00
v.Set("isread", map[bool]string{true: "1", false: "0"}[isread != true])
2024-02-18 10:42:21 +00:00
//}
2024-02-18 10:42:21 +00:00
return message.CreateCountInbox(v)
2024-02-18 10:42:21 +00:00
}
2024-06-14 08:41:36 +00:00
// CreateCountInbox ...
2024-02-18 10:42:21 +00:00
func (message *MessageService) CreateCountInbox(v url.Values) (MessageCountInbox, error) {
2024-02-18 10:42:21 +00:00
u := message.client.EndPoint("sms", "countinbox")
2024-02-18 10:42:21 +00:00
m := new(MessageCountInboxResult)
2024-02-18 10:42:21 +00:00
err := message.client.Execute(u.String(), v, m)
2024-06-14 08:41:36 +00:00
if m.Entries == nil {
2024-06-14 08:41:36 +00:00
return MessageCountInbox{}, err
2024-02-18 10:42:21 +00:00
}
2024-02-18 10:42:21 +00:00
return m.Entries[0], err
2024-06-14 08:41:36 +00:00
}