Skip to content

Commit 66ddf50

Browse files
committed
Email to Jet
Signed-off-by: Vishal Rana <[email protected]>
1 parent e97e978 commit 66ddf50

File tree

6 files changed

+33
-382
lines changed

6 files changed

+33
-382
lines changed

client.go

Lines changed: 5 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -53,43 +53,16 @@ func (c *Client) Cube() (cube *Cube) {
5353
go func() {
5454
d := time.Duration(cube.DispatchInterval) * time.Second
5555
for range time.Tick(d) {
56-
cube.dispatch()
56+
cube.Dispatch()
5757
}
5858
}()
5959
return
6060
}
6161

62-
// Email returns the email service.
63-
func (c *Client) Email() *Email {
64-
return &Email{
65-
sling: c.sling.Path("/email"),
62+
// Jet returns the jet service.
63+
func (c *Client) Jet() *Jet {
64+
return &Jet{
65+
sling: c.sling.Path("/jet"),
6666
logger: c.logger,
6767
}
6868
}
69-
70-
// Log returns the log service.
71-
func (c *Client) Log() (log *Log) {
72-
return &Log{
73-
sling: c.sling.Path("/log"),
74-
logger: c.logger,
75-
Level: LevelInfo,
76-
Fields: Fields{},
77-
}
78-
}
79-
80-
// Store returns the store service.
81-
func (c *Client) Store() *Store {
82-
return &Store{
83-
sling: c.sling,
84-
logger: c.logger,
85-
}
86-
}
87-
88-
func (f Fields) Add(key string, value interface{}) Fields {
89-
f[key] = value
90-
return f
91-
}
92-
93-
func (f Fields) Get(key string) interface{} {
94-
return f[key]
95-
}

email_test.go

Lines changed: 0 additions & 43 deletions
This file was deleted.

email.go renamed to jet.go

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,93 +10,93 @@ import (
1010
)
1111

1212
type (
13-
// Email defines the LabStack email service.
14-
Email struct {
13+
// Jet defines the LabStack jet service.
14+
Jet struct {
1515
sling *sling.Sling
1616
logger *log.Logger
1717
}
1818

19-
// EmailMessage defines the email message.
20-
EmailMessage struct {
19+
// JetMessage defines the jet message.
20+
JetMessage struct {
2121
inlines []string
2222
attachments []string
23-
Time string `json:"time,omitempty"`
24-
To string `json:"to,omitempty"`
25-
From string `json:"from,omitempty"`
26-
Subject string `json:"subject,omitempty"`
27-
Body string `json:"body,omitempty"`
28-
Inlines []*emailFile `json:"inlines,omitempty"`
29-
Attachments []*emailFile `json:"attachments,omitempty"`
30-
Status string `json:"status,omitempty"`
23+
Time string `json:"time,omitempty"`
24+
To string `json:"to,omitempty"`
25+
From string `json:"from,omitempty"`
26+
Subject string `json:"subject,omitempty"`
27+
Body string `json:"body,omitempty"`
28+
Inlines []*jetFile `json:"inlines,omitempty"`
29+
Attachments []*jetFile `json:"attachments,omitempty"`
30+
Status string `json:"status,omitempty"`
3131
}
3232

33-
emailFile struct {
33+
jetFile struct {
3434
Name string `json:"name"`
3535
Type string `json:"type"`
3636
Content string `json:"content"`
3737
}
3838

39-
// EmailError defines the email error.
40-
EmailError struct {
39+
// JetError defines the jet error.
40+
JetError struct {
4141
Code int `json:"code"`
4242
Message string `json:"message"`
4343
}
4444
)
4545

46-
func NewEmailMessage(to, from, subject string) *EmailMessage {
47-
return &EmailMessage{
46+
func NewJetMessage(to, from, subject string) *JetMessage {
47+
return &JetMessage{
4848
To: to,
4949
From: from,
5050
Subject: subject,
5151
}
5252
}
5353

54-
func (m *EmailMessage) addInlines() error {
54+
func (m *JetMessage) addInlines() error {
5555
for _, inline := range m.inlines {
5656
data, err := ioutil.ReadFile(inline)
5757
if err != nil {
5858
return err
5959
}
60-
m.Inlines = append(m.Inlines, &emailFile{
60+
m.Inlines = append(m.Inlines, &jetFile{
6161
Name: filepath.Base(inline),
6262
Content: base64.StdEncoding.EncodeToString(data),
6363
})
6464
}
6565
return nil
6666
}
6767

68-
func (m *EmailMessage) addAttachments() error {
68+
func (m *JetMessage) addAttachments() error {
6969
for _, attachment := range m.attachments {
7070
data, err := ioutil.ReadFile(attachment)
7171
if err != nil {
7272
return err
7373
}
74-
m.Inlines = append(m.Attachments, &emailFile{
74+
m.Inlines = append(m.Attachments, &jetFile{
7575
Name: filepath.Base(attachment),
7676
Content: base64.StdEncoding.EncodeToString(data),
7777
})
7878
}
7979
return nil
8080
}
8181

82-
func (m *EmailMessage) AddInline(path string) {
82+
func (m *JetMessage) AddInline(path string) {
8383
m.inlines = append(m.inlines, path)
8484
}
8585

86-
func (m *EmailMessage) AddAttachment(path string) {
86+
func (m *JetMessage) AddAttachment(path string) {
8787
m.attachments = append(m.attachments, path)
8888
}
8989

90-
// Send sends the email message.
91-
func (e *Email) Send(m *EmailMessage) (*EmailMessage, error) {
90+
// Send sends the jet message.
91+
func (e *Jet) Send(m *JetMessage) (*JetMessage, error) {
9292
if err := m.addInlines(); err != nil {
9393
return nil, err
9494
}
9595
if err := m.addAttachments(); err != nil {
9696
return nil, err
9797
}
98-
em := new(EmailMessage)
99-
ee := new(EmailError)
98+
em := new(JetMessage)
99+
ee := new(JetError)
100100
_, err := e.sling.Post("").BodyJSON(m).Receive(em, ee)
101101
if err != nil {
102102
return nil, err
@@ -107,6 +107,6 @@ func (e *Email) Send(m *EmailMessage) (*EmailMessage, error) {
107107
return nil, ee
108108
}
109109

110-
func (e *EmailError) Error() string {
110+
func (e *JetError) Error() string {
111111
return e.Message
112112
}

log.go

Lines changed: 0 additions & 110 deletions
This file was deleted.

log_test.go

Lines changed: 0 additions & 65 deletions
This file was deleted.

0 commit comments

Comments
 (0)