Skip to content

Commit

Permalink
Moved gen-methods to client ns.
Browse files Browse the repository at this point in the history
  • Loading branch information
neotyk committed Apr 8, 2011
1 parent 87a2588 commit f3a96d0
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 49 deletions.
48 changes: 48 additions & 0 deletions src/clj/http/async/client.clj
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,54 @@
(binding [*client* c#]
~@body)))

(defmacro gen-methods [& methods]
(list* 'do
(map (fn [method#]
(let [fn-name (symbol (.toUpperCase (name method#)))
fn-doc (str "Sends asynchronously HTTP " fn-name " request to url.
Returns a map:
- :id - unique ID of request
- :status - promise that once status is received is delivered, contains lazy map of:
- :code - response code
- :msg - response message
- :protocol - protocol with version
- :major - major version of protocol
- :minor - minor version of protocol
- :headers - promise that once headers are received is delivered, contains lazy map of:
- :server - header names are keyworded, values stay not changed
- :body - body of response, depends on request type, might be ByteArrayOutputStream
or lazy sequence, use conveniece methods to extract it, like string
- :done - promise that is delivered once receiving response has finished
- :error - promise that is delivered if requesting resource failed, once delivered
will contain Throwable.
Arguments:
- url - URL to request
- options - keyworded arguments:
:query - map of query parameters
:headers - map of headers
:body - body
:cookies - cookies to send
:proxy - map with proxy configuration to be used
:host - proxy host
:port - proxy port
:protocol - (optional) protocol to communicate with proxy,
:http (default, if you provide no value) and :https are allowed
:user - (optional) user name to use for proxy authentication,
has to be provided with :password
:password - (optional) password to use for proxy authentication,
has to be provided with :user
:auth - map with authentication to be used
:type - either :basic or :digest
:user - user name to be used
:password - password to be used
:realm - realm name to authenticate in
:timeout - request timeout in ms")]
`(defn ~fn-name ~fn-doc [#^String ~'url & {:as ~'options}]
(apply execute-request
(apply prepare-request ~method# ~'url (apply concat ~'options))
(apply concat *default-callbacks*)))))
methods)))

(gen-methods :get :post :put :delete :head :options)

(defn request-stream
Expand Down
49 changes: 0 additions & 49 deletions src/clj/http/async/client/util.clj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"Asynchronous HTTP Client - Clojure - Utils"
{:author "Hubert Iwaniuk"}
(:refer-clojure :exclude [promise])
(:require [http.async.client.request :as r])
(:import (com.ning.http.client ProxyServer
ProxyServer$Protocol
Realm$AuthScheme
Expand Down Expand Up @@ -55,54 +54,6 @@
(if-let [f (:delivered? (meta p))]
(f)))

(defmacro gen-methods [& methods]
(list* 'do
(map (fn [method#]
(let [fn-name (symbol (.toUpperCase (name method#)))
fn-doc (str "Sends asynchronously HTTP " fn-name " request to url.
Returns a map:
- :id - unique ID of request
- :status - promise that once status is received is delivered, contains lazy map of:
- :code - response code
- :msg - response message
- :protocol - protocol with version
- :major - major version of protocol
- :minor - minor version of protocol
- :headers - promise that once headers are received is delivered, contains lazy map of:
- :server - header names are keyworded, values stay not changed
- :body - body of response, depends on request type, might be ByteArrayOutputStream
or lazy sequence, use conveniece methods to extract it, like string
- :done - promise that is delivered once receiving response has finished
- :error - promise that is delivered if requesting resource failed, once delivered
will contain Throwable.
Arguments:
- url - URL to request
- options - keyworded arguments:
:query - map of query parameters
:headers - map of headers
:body - body
:cookies - cookies to send
:proxy - map with proxy configuration to be used
:host - proxy host
:port - proxy port
:protocol - (optional) protocol to communicate with proxy,
:http (default, if you provide no value) and :https are allowed
:user - (optional) user name to use for proxy authentication,
has to be provided with :password
:password - (optional) password to use for proxy authentication,
has to be provided with :user
:auth - map with authentication to be used
:type - either :basic or :digest
:user - user name to be used
:password - password to be used
:realm - realm name to authenticate in
:timeout - request timeout in ms")]
`(defn ~fn-name ~fn-doc [#^String ~'url & {:as ~'options}]
(apply r/execute-request
(apply r/prepare-request ~method# ~'url (apply concat ~'options))
(apply concat r/*default-callbacks*)))))
methods)))

(defn- proto-map [proto]
(if proto
({:http ProxyServer$Protocol/HTTP
Expand Down

0 comments on commit f3a96d0

Please sign in to comment.