From 13816b2b4b2cda547a7134f89f65edd606634dd8 Mon Sep 17 00:00:00 2001 From: Hunter Long Date: Sat, 3 Nov 2018 01:27:29 +0100 Subject: [PATCH] travis - notifier api --- .travis.yml | 2 +- handlers/api.go | 17 +++++++++++++++++ handlers/routes.go | 4 ++-- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index afd687e3..6d74ecda 100644 --- a/.travis.yml +++ b/.travis.yml @@ -64,7 +64,7 @@ before_install: install: - make dev-deps - - make dev + - make dep - make install before_script: diff --git a/handlers/api.go b/handlers/api.go index 1339913d..1030d074 100644 --- a/handlers/api.go +++ b/handlers/api.go @@ -17,8 +17,10 @@ package handlers import ( "encoding/json" + "fmt" "github.com/gorilla/mux" "github.com/hunterlong/statup/core" + "github.com/hunterlong/statup/core/notifier" "github.com/hunterlong/statup/types" "github.com/hunterlong/statup/utils" "net/http" @@ -327,6 +329,21 @@ func apiCreateUsersHandler(w http.ResponseWriter, r *http.Request) { json.NewEncoder(w).Encode(output) } +func apiNotifierGetHandler(w http.ResponseWriter, r *http.Request) { + if !isAPIAuthorized(r) { + http.Error(w, http.StatusText(http.StatusUnauthorized), http.StatusUnauthorized) + return + } + vars := mux.Vars(r) + notify, notifierObj, err := notifier.SelectNotifier(vars["notifier"]) + if err != nil { + http.Error(w, fmt.Sprintf("%v notifier was not found", vars["notifier"]), http.StatusInternalServerError) + return + } + fmt.Println(notify) + fmt.Println(notifierObj) +} + func isAPIAuthorized(r *http.Request) bool { if os.Getenv("GO_ENV") == "test" { return true diff --git a/handlers/routes.go b/handlers/routes.go index bc4f1aa0..65551fee 100644 --- a/handlers/routes.go +++ b/handlers/routes.go @@ -110,8 +110,8 @@ func Router() *mux.Router { r.Handle("/api/users/{id}", http.HandlerFunc(apiUserDeleteHandler)).Methods("DELETE") // API Notifier Routes - r.Handle("/api/notifier/{notifier}", http.HandlerFunc(apiCheckinHandler)).Methods("GET") - r.Handle("/api/notifier/{notifier}", http.HandlerFunc(apiCheckinHandler)).Methods("POST") + r.Handle("/api/notifier/{notifier}", http.HandlerFunc(apiNotifierGetHandler)).Methods("GET") + r.Handle("/api/notifier/{notifier}", http.HandlerFunc(apiNotifierGetHandler)).Methods("POST") // Generic API Routes r.Handle("/api", http.HandlerFunc(apiIndexHandler))