From 9108f27a3a20a053dfd75653bc26f97fa278401e Mon Sep 17 00:00:00 2001 From: Knut Ahlers Date: Thu, 11 Mar 2021 19:23:11 +0100 Subject: [PATCH] Beerpay has been discontinued Signed-off-by: Knut Ahlers --- service_beerpay.go | 64 ---------------------------------------------- 1 file changed, 64 deletions(-) delete mode 100644 service_beerpay.go diff --git a/service_beerpay.go b/service_beerpay.go deleted file mode 100644 index c04d668..0000000 --- a/service_beerpay.go +++ /dev/null @@ -1,64 +0,0 @@ -package main - -import ( - "encoding/json" - "errors" - "fmt" - "net/http" - "time" - - "golang.org/x/net/context" -) - -func init() { - registerServiceHandler("beerpay", beerpayServiceHandler{}) -} - -type beerpayServiceHandler struct{} - -func (s beerpayServiceHandler) GetDocumentation() serviceHandlerDocumentationList { - return serviceHandlerDocumentationList{{ - ServiceName: "beerpay Total Amount", - DemoPath: "/beerpay/beerpay/beerpay.io", - Arguments: []string{"", ""}, - }} -} - -func (beerpayServiceHandler) IsEnabled() bool { return true } - -func (s beerpayServiceHandler) Handle(ctx context.Context, params []string) (title, text, color string, err error) { - if len(params) < 2 { - err = errors.New("You need to provide user and project") - return - } - - title = "beerpay" - color = "red" - - cacheKey := fmt.Sprintf("%s::%s", params[0], params[1]) - text, err = cacheStore.Get("beerpay", cacheKey) - - if err != nil { - var resp *http.Response - - apiURL := fmt.Sprintf("https://beerpay.io/api/v1/%s/projects/%s", params[0], params[1]) - req, _ := http.NewRequest("GET", apiURL, nil) - resp, err = http.DefaultClient.Do(req.WithContext(ctx)) - if err != nil { - return - } - defer resp.Body.Close() - - r := struct { - TotalAmount int `json:"total_amount"` - }{} - - if err = json.NewDecoder(resp.Body).Decode(&r); err != nil { - return - } - text = fmt.Sprintf("$%d", r.TotalAmount) - cacheStore.Set("beerpay", cacheKey, text, 5*time.Minute) - } - - return -}