-
Notifications
You must be signed in to change notification settings - Fork 1
/
twitter.go
48 lines (42 loc) · 1.21 KB
/
twitter.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
package TwitterIOT
import (
"encoding/json"
"net/http"
"google.golang.org/appengine"
"google.golang.org/appengine/log"
)
//Twitter Webhook
type testStruct struct {
Test string
}
func twitterhook(w http.ResponseWriter, r *http.Request) {
ctx := appengine.NewContext(r)
//Log that this function is called
log.Debugf(ctx, "Webhook success!")
switch r.Method {
//If requesting a "Get" run CRC
case http.MethodGet:
log.Debugf(ctx, "This is a Get method")
secret := "8LRLAFoS7FlUE6q2hJKMG2kbtBXLPUTyl6btc1PABayI3416IV"
message := r.URL.Query().Get("message")
GetCRCResponse(secret, message, w)
//If POST parse data
case http.MethodPost:
log.Debugf(ctx, "This is a Post method")
decoder := json.NewDecoder(r.Body)
var t testStruct
err := decoder.Decode(&t)
if err != nil {
panic(err)
}
log.Debugf(ctx, t.Test)
//When Put is called, it is asking to renew so have CRC run
case http.MethodPut:
log.Debugf(ctx, "This is a Put method")
secret := "8LRLAFoS7FlUE6q2hJKMG2kbtBXLPUTyl6btc1PABayI3416IV"
message := r.URL.Query().Get("message")
GetCRCResponse(secret, message, w)
default: //Else this gets awkward
log.Debugf(ctx, "Yikes this wasn't supposed to happen (Not a GET or POST or PUT)")
}
}