(ns riemann.keenio
  "Forwards events to Keen IO"
  (:require [clj-http.client :as client])
  (:require [cheshire.core :as json]))

(def ^:private event-url
  "https://api.keen.io/3.0/projects/")

(defn- post
  "POST to Keen IO."
  [collection project-id write-key request]

  (def final-event-url
    (str event-url project-id "/events/" collection))

  (client/post final-event-url
               {:body (json/generate-string request)
                :query-params { "api_key" write-key }
                :socket-timeout 5000
                :conn-timeout 5000
                :content-type :json
                :accept :json
                :throw-entire-message? true}))

(defn keenio
  "Creates a keen adapter. Takes your Keen project id and write key, and
  returns a function that accepts an event and sends it to Keen IO. The full
  event will be sent.

(streams
  (let [kio (keenio \"COLLECTION_NAME\", \"PROJECT_ID\" \"WRITE_KEY\")]
    (where (state \"error\") kio)))"

  [collection project-id, write-key]
  (fn [event]
    (post collection project-id write-key event)))

(ns riemann.keenio
  "Forwards events to Keen IO"
  (:require [clj-http.client :as client])
  (:require [cheshire.core :as json]))

(def ^:private event-url
  "https://api.keen.io/3.0/projects/")

(defn- post
  "POST to Keen IO."
  [collection project-id write-key request]

  (let [final-event-url
    (str event-url project-id "/events/" collection)]

  (client/post final-event-url
               {:body (json/generate-string request)
                :query-params { "api_key" write-key }
                :socket-timeout 5000
                :conn-timeout 5000
                :content-type :json
                :accept :json
                :throw-entire-message? true})))

(defn keenio
  "Creates a keen adapter. Takes your Keen project id and write key, and
  returns a function that accepts an event and sends it to Keen IO. The full
  event will be sent.

(streams
  (let [kio (keenio \"COLLECTION_NAME\" \"PROJECT_ID\" \"WRITE_KEY\")]
    (where (state \"error\") kio)))"

  [collection project-id, write-key]
  (fn [event]
    (post collection project-id write-key event)))

Use let, not def. Fix docs
Use let, not def. Fix docs

bg451/riemann,yeller/riemann,pyr/riemann,pharaujo/riemann,mirwan/riemann,mirwan/riemann,DasAllFolks/riemann,bfritz/riemann,DasAllFolks/riemann,irudyak/riemann,bwilber/riemann,rhysr/riemann,forter/riemann,zamaterian/riemann,Anvil/riemann,yeller/riemann,alq666/riemann,rekhajoshm/riemann,mbuczko/riemann,rhysr/riemann,timbuchwaldt/riemann,nberger/riemann,vincentbernat/riemann,counsyl/riemann,irudyak/riemann,bmhatfield/riemann,alq666/riemann,rekhajoshm/riemann,shokunin/riemann,forter/riemann,jamtur01/riemann,bfritz/riemann,jeanpralo/riemann,VideoAmp/riemann-1,vincentbernat/riemann,bowlofstew/riemann,joerayme/riemann,VideoAmp/riemann-1,jeanpralo/riemann,shokunin/riemann,nberger/riemann,lispmeister/riemann,robashton/riemann,forter/riemann,patrox/riemann,rhysr/riemann,vixns/riemann,bowlofstew/riemann,pyr/riemann,AkihiroSuda/riemann,counsyl/riemann,pradeepchhetri/riemann,aphyr/riemann,lispmeister/riemann,joerayme/riemann,patrox/riemann,abailly/riemann,eric/riemann,robashton/riemann,LubyRuffy/riemann,cswaroop/riemann,shokunin/riemann,LubyRuffy/riemann,riemann/riemann,riemann/riemann,cswaroop/riemann,rekhajoshm/riemann,bmhatfield/riemann,mbuczko/riemann,timbuchwaldt/riemann,abailly/riemann,pradeepchhetri/riemann,moonranger/riemann,eric/riemann,patrox/riemann,moonranger/riemann,Anvil/riemann,yeller/riemann,bg451/riemann,AkihiroSuda/riemann,lispmeister/riemann,vixns/riemann,cswaroop/riemann,zamaterian/riemann,mirwan/riemann,aphyr/riemann,bwilber/riemann,jamtur01/riemann,pharaujo/riemann