-
Notifications
You must be signed in to change notification settings - Fork 2
/
sinker.go
47 lines (34 loc) · 845 Bytes
/
sinker.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
package main
import (
"context"
"log"
"time"
"github.com/dghubble/go-twitter/twitter"
ce "github.com/knative/pkg/cloudevents"
)
func newSinkPoster(sink string) (sinker *sinkPoster, err error) {
// cloud events
ceClient := ce.NewClient(sink, ce.Builder{
EventType: "com.twitter",
Source: "https://api.twitter.com/1.1/search/tweets.json",
})
s := &sinkPoster{
client: ceClient,
}
return s, nil
}
type sinkPoster struct {
client *ce.Client
}
func (s *sinkPoster) post(ctx context.Context, t *twitter.Tweet) error {
log.Printf("Posting tweet: %s\n", t.IDStr)
eventTime, err := time.Parse(time.RubyDate, t.CreatedAt)
if err != nil {
log.Printf("Error while parsing created at: %v", err)
eventTime = time.Now()
}
return s.client.Send(t, ce.V01EventContext{
EventID: t.IDStr,
EventTime: eventTime,
})
}