-
Notifications
You must be signed in to change notification settings - Fork 0
/
lite.go
106 lines (88 loc) · 2.25 KB
/
lite.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
106
package cio
import (
"fmt"
"net/url"
"github.com/suicidegang/chttp"
)
const CIO_LITE_API = "https://api.context.io/lite/"
func ContextIO(token, secret string) ContextIOLite {
return ContextIOLite{token, secret}
}
type ContextIOLite struct {
token string
secret string
}
func (c ContextIOLite) GET(url string, f ...interface{}) chttp.Req {
return chttp.RequestOrPanic(
chttp.GET(fmt.Sprintf(CIO_LITE_API+url, f...)),
chttp.Header("Content-Type", "application/x-www-form-urlencoded"),
chttp.Header("Accept", "application/json"),
chttp.Header("Accept-Charset", "utf-8"),
chttp.Header("User-Agent", "suicidegang/chttp.context-io"),
chttp.Oauth(c.token, c.secret),
)
}
func (c ContextIOLite) User(id string) User {
return User{c, id}
}
/*req, err := ctx.GET("users/%s/email_accounts/%s/folders/%s/messages/%s/body", webhook.AccountID, s.Label, url.QueryEscape(s.Folder), id)
if err != nil {
c.StatusCode(iris.StatusBadRequest)
c.WriteString(err.Error())
return
}*/
type User struct {
Client ContextIOLite
AccountID string
}
func (u User) EmailAccount(label string) EmailAccount {
return EmailAccount{u, label}
}
type EmailAccount struct {
User User
Label string
}
func (e EmailAccount) Folder(label string) Folder {
return Folder{e, label}
}
type Folder struct {
EmailAccount EmailAccount
Label string
}
func (f Folder) Message(id string) Message {
return Message{f, id}
}
type Message struct {
Folder Folder
Id string
}
func (m Message) Remote() chttp.Req {
c := m.Folder.EmailAccount.User.Client
return c.GET(
"users/%s/email_accounts/%s/folders/%s/messages/%s",
m.Folder.EmailAccount.User.AccountID,
m.Folder.EmailAccount.Label,
url.QueryEscape(m.Folder.Label),
m.Id,
)
}
func (m Message) Body() chttp.Req {
c := m.Folder.EmailAccount.User.Client
return c.GET(
"users/%s/email_accounts/%s/folders/%s/messages/%s/body",
m.Folder.EmailAccount.User.AccountID,
m.Folder.EmailAccount.Label,
url.QueryEscape(m.Folder.Label),
m.Id,
)
}
func (m Message) Attachments() chttp.Req {
c := m.Folder.EmailAccount.User.Client
return c.GET(
"users/%s/email_accounts/%s/folders/%s/messages/%s/attachments",
m.Folder.EmailAccount.User.AccountID,
m.Folder.EmailAccount.Label,
url.QueryEscape(m.Folder.Label),
m.Id,
)
}