From 9706617b65d17eb2794b04dc337644bd973b0807 Mon Sep 17 00:00:00 2001 From: Knut Ahlers Date: Wed, 21 Mar 2018 16:27:52 +0100 Subject: [PATCH] Gratipay service was discontinued Signed-off-by: Knut Ahlers --- service_gratipay.go | 89 --------------------------------------------- 1 file changed, 89 deletions(-) delete mode 100644 service_gratipay.go diff --git a/service_gratipay.go b/service_gratipay.go deleted file mode 100644 index be5a2ba..0000000 --- a/service_gratipay.go +++ /dev/null @@ -1,89 +0,0 @@ -package main - -import ( - "encoding/json" - "errors" - "fmt" - "net/http" - "strings" - "time" - - "golang.org/x/net/context" - "golang.org/x/net/context/ctxhttp" -) - -func init() { - registerServiceHandler("gratipay", gratipayServiceHandler{}) -} - -type gratipayServiceHandler struct{} - -func (s gratipayServiceHandler) GetDocumentation() serviceHandlerDocumentationList { - return serviceHandlerDocumentationList{ - { - ServiceName: "Gratipay user", - DemoPath: "/gratipay/user/js_bin", - Arguments: []string{"user", ""}, - }, - { - ServiceName: "Gratipay team", - DemoPath: "/gratipay/team/Gratipay", - Arguments: []string{"team", ""}, - }, - } -} - -func (s gratipayServiceHandler) Handle(ctx context.Context, params []string) (title, text, color string, err error) { - if len(params) < 2 { - err = errors.New("You need to provide type and user/teamname") - return - } - - if params[0] == "user" { - params[1] = "~" + params[1] - } - - path := strings.Join([]string{params[1], "public.json"}, "/") - text, err = cacheStore.Get("gratipay", path) - - if err != nil { - apiURL := "https://gratipay.com/" + path - - r := struct { - Receiving float64 `json:"receiving"` - Taking float64 `json:"taking,string"` - }{} - - var resp *http.Response - resp, err = ctxhttp.Get(ctx, http.DefaultClient, apiURL) - if err != nil { - return - } - defer resp.Body.Close() - - if err = json.NewDecoder(resp.Body).Decode(&r); err != nil { - return - } - - sum := r.Taking + r.Receiving - color = "brightgreen" - - if sum == 0.0 { - color = "red" - } else if sum < 10 { - color = "yellow" - } else if sum < 100 { - color = "green" - } - - text = fmt.Sprintf("$%.2f / week::%s", sum, color) - cacheStore.Set("gratipay", path, text, 10*time.Minute) - } - - tmp := strings.Split(text, "::") - text = tmp[0] - color = tmp[1] - - title = "gratipay" - return -}