Skip to content

Instantly share code, notes, and snippets.

@natikgadzhi
Last active January 3, 2016 03:14
Show Gist options
  • Save natikgadzhi/e54818a64572c7b5411d to your computer and use it in GitHub Desktop.
Save natikgadzhi/e54818a64572c7b5411d to your computer and use it in GitHub Desktop.
(defn make-path
"Assembles a URI path from the provided pieces"
[& parts]
(string/join "/" (concat (list api-url api-version) parts)))
(defn check-errors
"Checks response for common Chain.com API errrors"
[response]
(let [request-id (get (:headers response) "Chain-Request-Id")]
(if (nil? request-id)
(throw+ { :type "ConnectivityError"
:message "The request has not been assigned a Chain Request ID.
Most likely, there's a problem with the HTTP connection" }))))
(defn api-get
[path & { :keys [params] :or { params {} }}]
(http/get path
{ :basic-auth [api-token api-key]
:as :json
:client-params { "http.useragent" (str "chain-enterprise-clojure/" version) }
:query-params params }))
(defn issuer-nodes
[]
(api-get (make-path "projects" project-id "issuer-nodes") :params {:page 10 }))
(def raw-data (issuer-nodes))
((comp (partial into {}) check-errors) raw-data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment