travis - notifier api

pull/94/head
Hunter Long 2018-11-03 01:27:29 +01:00
parent d279d1c449
commit 13816b2b4b
3 changed files with 20 additions and 3 deletions

View File

@ -64,7 +64,7 @@ before_install:
install:
- make dev-deps
- make dev
- make dep
- make install
before_script:

View File

@ -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

View File

@ -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))