0

Blitline 提供了这个例子来从命令行调用;这将如何转化为clojure?

$ curl "http://api.blitline.com/job" -d json='{ "src" : "http://www.google.com/logos/2011/yokoyama11-hp.jpg", "functions" : [ {"name": "blur", "params" : {"radius" : 0.0, "sigma" : 2.0}, "save" : { "image_identifier" : "some_id" }} ]}'
4

2 回答 2

3

上面的答案是正确的。为了完整起见,我附上了您需要的完整代码:

(require '[clj-http.client :as http])
(require '[clojure.data.json :as json])

(def post
(http/post "http://api.blitline.com/job" {
:body 
    (json/json-str 
        { "json" 
        { "application_id" "sgOob0A3b3RdYaqwTEJCpA"
          "src" "http://www.google.com/logos/2011/yokoyama11-hp.jpg"
          "functions" [ {
                "name" "blur"
                "params" {
                    "radius" 0.0
                    "sigma" 2.0
                }
                "save" { "image_identifier" "some_id" }
                }
                ]}}) 
:body-encoding "UTF-8"
:content-type :json
:accept :json
}))

(json/read-json (:body post))
于 2012-09-18T02:08:52.850 回答
1

您可以使用 clj-http.client 和 clojure.data.json。以下是我用来与 Urban Airship JSON API 对话的一些代码作为示例:

(ns my-ns
  (:require [clj-http.client :as http]
            [clojure.data.json :as json]))

(def uu-base-url
  "https://go.urbanairship.com")

(def auth ["secret" "password"])    

(defn broadcast-message*
  [auth text]
  (http/post (str uu-base-url "/api/push/broadcast/") ;; target url
             {:basic-auth auth ;; leave this out if you don't need HTTP basic authentication
              :content-type "application/json"
              :body (json/json-str
                     ;; clojure data to be converted into JSON request body
                     {:aps {:badge 1
                            :alert text}})}))
于 2012-09-15T11:00:00.353 回答