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

(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

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