From b695f3c90d2e6bea36052472cb2c1e6393d237aa Mon Sep 17 00:00:00 2001 From: "Michael M. Wasser" Date: Mon, 1 Jun 2015 15:38:53 -0700 Subject: [PATCH] moving feature tracking after validation --- handler/item_handler.go | 6 +++--- handler/search_source_handler.go | 6 +++--- handler/sources_handler.go | 4 ++-- handler/yourchart_create_handler.go | 8 ++------ handler/yourchart_fetch_handler.go | 4 ++-- handler_compat/npi_item_handler.go | 6 +++--- handler_compat/npi_search_handler.go | 6 +++--- 7 files changed, 18 insertions(+), 22 deletions(-) diff --git a/handler/item_handler.go b/handler/item_handler.go index d48ffc5..edb27f8 100644 --- a/handler/item_handler.go +++ b/handler/item_handler.go @@ -20,9 +20,6 @@ func ItemHandler (w http.ResponseWriter, req *http.Request) { source := strings.ToLower(vars["source"]) id := vars["id"] - api.AddFeature(req, "handler:item") - api.AddFeature(req, source) - bloomConn := api.Conn() searchConn := bloomConn.SearchConnection() @@ -79,6 +76,9 @@ func ItemHandler (w http.ResponseWriter, req *http.Request) { body := map[string]interface{} { "result": found } + api.AddFeature(req, "handler:item") + api.AddFeature(req, source) + api.Render(w, req, http.StatusOK, body) return } \ No newline at end of file diff --git a/handler/search_source_handler.go b/handler/search_source_handler.go index 620db11..a479cad 100644 --- a/handler/search_source_handler.go +++ b/handler/search_source_handler.go @@ -14,9 +14,6 @@ func SearchSourceHandler (w http.ResponseWriter, req *http.Request) { vars := mux.Vars(req) source := strings.ToLower(vars["source"]) - api.AddFeature(req, source) - api.AddFeature(req, "handler:search") - conn := api.Conn() apiKey, ok := context.Get(req, "api_key").(string) if !ok { @@ -51,6 +48,9 @@ func SearchSourceHandler (w http.ResponseWriter, req *http.Request) { return } + api.AddFeature(req, source) + api.AddFeature(req, "handler:search") + api.Render(w, req, http.StatusOK, results) return } \ No newline at end of file diff --git a/handler/sources_handler.go b/handler/sources_handler.go index bd39e24..cd05c24 100644 --- a/handler/sources_handler.go +++ b/handler/sources_handler.go @@ -20,8 +20,6 @@ func SourcesHandler (w http.ResponseWriter, req *http.Request) { conn := api.Conn() apiKey, ok := context.Get(req, "api_key").(string) - api.AddFeature(req, "handler:sources") - if !ok { apiKey = "" } @@ -53,5 +51,7 @@ func SourcesHandler (w http.ResponseWriter, req *http.Request) { } } + api.AddFeature(req, "handler:sources") + api.Render(w, req, http.StatusOK, map[string][]dataSource{"result": sources}) } \ No newline at end of file diff --git a/handler/yourchart_create_handler.go b/handler/yourchart_create_handler.go index 595bc77..7e99e82 100644 --- a/handler/yourchart_create_handler.go +++ b/handler/yourchart_create_handler.go @@ -11,8 +11,6 @@ import ( "github.com/gorilla/context" "github.com/spf13/viper" "github.com/untoldone/bloomapi/api" - - "fmt" ) func YourChartCreateHandler (w http.ResponseWriter, req *http.Request) { @@ -38,8 +36,6 @@ func YourChartCreateHandler (w http.ResponseWriter, req *http.Request) { return } - api.AddFeature(req, "handler:yourchart:create") - postResp, err := http.PostForm(yourchartUrl, url.Values{ "username": {username}, "password": {password}, @@ -74,8 +70,6 @@ func YourChartCreateHandler (w http.ResponseWriter, req *http.Request) { return } - fmt.Println(jobId) - err = YourchartAuthorize(apiKey, jobId) if err != nil { log.Println(err) @@ -83,5 +77,7 @@ func YourChartCreateHandler (w http.ResponseWriter, req *http.Request) { return } + api.AddFeature(req, "handler:yourchart:create") + api.Render(w, req, http.StatusOK, decoded) } \ No newline at end of file diff --git a/handler/yourchart_fetch_handler.go b/handler/yourchart_fetch_handler.go index 4761b03..3bb0a20 100644 --- a/handler/yourchart_fetch_handler.go +++ b/handler/yourchart_fetch_handler.go @@ -46,8 +46,6 @@ func YourChartFetchHandler (w http.ResponseWriter, req *http.Request) { }) return } - - api.AddFeature(req, "handler:yourchart:fetch") getResp, err := http.Get(yourchartUrl + "/" + id) body, err := ioutil.ReadAll(getResp.Body) @@ -66,5 +64,7 @@ func YourChartFetchHandler (w http.ResponseWriter, req *http.Request) { return } + api.AddFeature(req, "handler:yourchart:fetch") + api.Render(w, req, http.StatusOK, decoded) } \ No newline at end of file diff --git a/handler_compat/npi_item_handler.go b/handler_compat/npi_item_handler.go index eccd242..784f653 100644 --- a/handler_compat/npi_item_handler.go +++ b/handler_compat/npi_item_handler.go @@ -13,9 +13,6 @@ func NpiItemHandler (w http.ResponseWriter, req *http.Request) { vars := mux.Vars(req) npi := vars["npi"] - api.AddFeature(req, "usgov.hhs.npi") - api.AddFeature(req, "handler:legacynpi:item") - conn := api.Conn().SearchConnection() result, err := conn.Search("usgov.hhs.npi", "main", nil, map[string]interface{} { @@ -49,6 +46,9 @@ func NpiItemHandler (w http.ResponseWriter, req *http.Request) { body := map[string]interface{} {"result": hits[0]} valuesToStrings(body) + api.AddFeature(req, "usgov.hhs.npi") + api.AddFeature(req, "handler:legacynpi:item") + api.Render(w, req, http.StatusOK, body) return } diff --git a/handler_compat/npi_search_handler.go b/handler_compat/npi_search_handler.go index 4b0f82a..5e4e10c 100644 --- a/handler_compat/npi_search_handler.go +++ b/handler_compat/npi_search_handler.go @@ -15,9 +15,6 @@ func NpiSearchHandler (w http.ResponseWriter, req *http.Request) { return } - api.AddFeature(req, "usgov.hhs.npi") - api.AddFeature(req, "handler:legacynpi:search") - results, err := handler.Search("usgov.hhs.npi", params, req) if err != nil { switch err.(type) { @@ -32,6 +29,9 @@ func NpiSearchHandler (w http.ResponseWriter, req *http.Request) { } valuesToStrings(results) + + api.AddFeature(req, "usgov.hhs.npi") + api.AddFeature(req, "handler:legacynpi:search") api.Render(w, req, http.StatusOK, results) return