-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathactivity.go
178 lines (137 loc) · 4.33 KB
/
activity.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
package publishtweet
import (
"fmt"
"strconv"
s "strings"
"github.com/DipeshTest/allstarsshared/twitter"
"github.com/TIBCOSoftware/flogo-lib/core/activity"
"github.com/TIBCOSoftware/flogo-lib/logger"
)
// MyActivity is a stub for your Activity implementation
type MyActivity struct {
metadata *activity.Metadata
}
var log = logger.GetLogger("activity-twitterpublish")
// NewActivity creates a new activity
func NewActivity(metadata *activity.Metadata) activity.Activity {
return &MyActivity{metadata: metadata}
}
// Metadata implements activity.Activity.Metadata
func (a *MyActivity) Metadata() *activity.Metadata {
return a.metadata
}
// Eval implements activity.Activity.Eval
func (a *MyActivity) Eval(context activity.Context) (done bool, err error) {
consumerKey := s.TrimSpace(context.GetInput("consumerKey").(string))
consumerSecret := s.TrimSpace(context.GetInput("consumerSecret").(string))
accessToken := s.TrimSpace(context.GetInput("accessToken").(string))
accessTokenSecret := s.TrimSpace(context.GetInput("accessTokenSecret").(string))
twitterFunction := context.GetInput("twitterFunction").(string)
fmt.Println("test ", twitterFunction)
if len(consumerKey) == 0 {
context.SetOutput("statusCode", "101")
context.SetOutput("message", "Consumer Key field is blank")
} else if len(consumerSecret) == 0 {
context.SetOutput("statusCode", "102")
context.SetOutput("message", "Consumer Secret field is blank")
} else if len(accessToken) == 0 {
context.SetOutput("statusCode", "103")
context.SetOutput("message", "Access Token field is blank")
} else if len(accessTokenSecret) == 0 {
context.SetOutput("statusCode", "104")
context.SetOutput("message", "Access Token Secret field is blank")
} else {
var msg string
var code int
switch twitterFunction {
case "Tweet":
{
tweet := s.TrimSpace(context.GetInput("text").(string))
if len(tweet) == 0 {
code = 105
msg = "Tweet cannot be blank"
} else {
code, msg = twitter.PostTweet(consumerKey, consumerSecret, accessToken, accessTokenSecret, tweet)
}
}
case "ReTweet":
{
tweetId := context.GetInput("user")
tid := s.TrimSpace(tweetId.(string))
if len(tid) == 0 {
code = 105
msg = "TweetId cannot be blank"
} else {
value, err := strconv.Atoi(tid)
if err == nil {
code, msg = twitter.ReTweet(consumerKey, consumerSecret, accessToken, accessTokenSecret, int64(value))
} else {
code = 1001
msg = err.Error()
}
}
}
case "Block":
{
user := s.TrimSpace(context.GetInput("user").(string))
if len(user) == 0 {
code = 105
msg = "Block user field cannot be blank"
} else {
code, msg = twitter.BlockUser(consumerKey, consumerSecret, accessToken, accessTokenSecret, user)
}
}
case "Unblock":
{
user := s.TrimSpace(context.GetInput("user").(string))
if len(user) == 0 {
code = 105
msg = "UnBlock user field cannot be blank"
} else {
code, msg = twitter.UnBlockUser(consumerKey, consumerSecret, accessToken, accessTokenSecret, user)
}
}
case "Follow":
{
user := s.TrimSpace(context.GetInput("user").(string))
if len(user) == 0 {
code = 105
msg = "Follow user field cannot be blank"
} else {
code, msg = twitter.Follow(consumerKey, consumerSecret, accessToken, accessTokenSecret, user)
}
}
case "Unfollow":
{
user := s.TrimSpace(context.GetInput("user").(string))
if len(user) == 0 {
code = 105
msg = "UnFollow user field cannot be blank"
} else {
code, msg = twitter.UnFollow(consumerKey, consumerSecret, accessToken, accessTokenSecret, user)
}
}
case "DM":
{
user := s.TrimSpace(context.GetInput("user").(string))
directmsg := s.TrimSpace(context.GetInput("text").(string))
if len(user) == 0 || len(directmsg) == 0 {
context.SetOutput("statusCode", "105")
context.SetOutput("message", "User or Text field cannot be blank")
code = 105
msg = "User or Text field cannot be blank"
} else {
code, msg = twitter.DirectMessage(consumerKey, consumerSecret, accessToken, accessTokenSecret, directmsg, user)
}
}
default:
{
code = 105
msg = "TwitterFunction field cannot be blank"
}
}
context.SetOutput("statusCode", code)
context.SetOutput("message", msg)
}
return true, err
}