                      arglist*))))))))
 
 (defn- args-from
-  ;; FIXME: Not true
-  "Function arguments take an optional first parameter map
-  of AWS credentials. Addtional parameters are either a map,
-  or seq of keys and values."
+  "Parameters are either a map, or seq of keys and values."
   [arg-seq]
-  (let [args (first arg-seq)]
-    (cond
-      (or (and (or (map? args)
-                   (map? (first args)))
-               (or (contains? (first args) :access-key)
-                   (contains? (first args) :endpoint)
-                   (contains? (first args) :profile)
-                   (contains? (first args) :client-config)))
-          ;;(instance? AWSCredentialsProvider (first args))
-          ;;(instance? AWSCredentials (first args))
-          )
-      {:args (if (-> args rest first map?)
-                 (if (-> args rest first empty?)
-                     {}
-                     (mapcat identity (-> args rest args-from :args)))
-                 (rest args))
-       :credential (if (map? (first args))
-                       (dissoc (first args) :client-config)
-                       (first args))
-       :client-config (:client-config (first args))}
-      (map? (first args))
-      {:args (let [m (mapcat identity (first args))]
-               (if (seq m) m {}))}
-      :default {:args args})))
+  (let [args (first arg-seq)
+        1st-arg (first args)]
+    (if (map? 1st-arg)
+      {:args (let [m (mapcat identity 1st-arg)]
+               (if (empty? m)
+                 {}
+                 m))}
+      {:args args})))
 
 (defn- types-match-args
   [args ^Method method]

                        credential
                        client-config)]))))

(swap! client-config assoc :transfer-manager-fn (memoize transfer-manager*))

(defn candidate-client
  [clazz args]
  (let [cred-bound (or *credentials* (:credential args))
        credential (if (map? cred-bound)
                             (merge @credential cred-bound)
                             (or cred-bound @credential))
        config-bound (or *client-config* (:client-config args))
        client-config (merge @client-config config-bound)
        encryption-client (:encryption-client-fn client-config)
        amazon-client (:amazon-client-fn client-config)
        transfer-manager (:transfer-manager-fn client-config)
        crypto (if (even? (count (:args args)))
                   (:encryption (apply hash-map (:args args))))
        client  (if (and crypto (or (= (.getSimpleName clazz) "AmazonS3Client")
                                    (= (.getSimpleName clazz) "TransferManager")))
                    (delay (encryption-client crypto credential client-config))
                    (delay (amazon-client clazz credential client-config)))]
        (if (= (.getSimpleName clazz) "TransferManager")
            (transfer-manager credential client-config crypto)
            @client)))


(defn- fn-call
  "Returns a function that reflectively invokes method on
   clazz with supplied args (if any). The 'method' here is
   the Java method on the Amazon*Client class."
  [clazz method & arg]
  (binding [*client-class* clazz]
    (let [args    (args-from arg)
          arg-arr (prepare-args method (:args args))
          client  (delay (candidate-client clazz args))]
      (fn []
        (try
          (let [java (.invoke method @client arg-arr)
                cloj (marshall java)]
            (if (and
                  @root-unwrapping
                  (map? cloj)
                  (= 1 (count (keys cloj))))
              (-> cloj first second)
              cloj))
          (catch InvocationTargetException ite
            (throw (.getTargetException ite))))))))


























   #(str/replace % #"(?i)iscsi" "ISCSI")
   #(str/replace % #"(?i)openid" "OPENID")))

#_
(defn set-client
  "Intern into the specified namespace all public methods
   from the Amazon*Client class as Clojure functions."
