File tree Expand file tree Collapse file tree 5 files changed +122
-6
lines changed Expand file tree Collapse file tree 5 files changed +122
-6
lines changed Original file line number Diff line number Diff line change 1+ <?xml version =" 1.0" encoding =" UTF-8" standalone =" yes" ?>
2+ <Order OrderNo =" 181219-001-345786" >
3+ <PersonInfoBillTo City =" Chennai" FirstName =" Tamizhvendan" LastName =" Sembiyan" State =" TamilNadu" ZipCode =" 600001" >
4+ <Extn IRLAddressLine1 =" Plot No 222" IRLAddressLine2 =" Ashok Nagar 42nd Street" />
5+ </PersonInfoBillTo >
6+ <PersonInfoShipTo City =" Chennai" FirstName =" Tamizhvendan" LastName =" Sembiyan" State =" TamilNadu" ZipCode =" 600001" >
7+ <Extn IRLAddressLine1 =" Plot No 222" IRLAddressLine2 =" Ashok Nagar 42nd Street" />
8+ </PersonInfoShipTo >
9+ <PaymentDetailsList >
10+ <PaymentDetails ProcessedAmount =" 900.0" Reference1 =" 000000-1545216772601" />
11+ </PaymentDetailsList >
12+ <OrderLines >
13+ <OrderLine >
14+ <Item ItemID =" 200374" />
15+ <LinePriceInfo LineTotal =" 900.0" />
16+ </OrderLine >
17+ </OrderLines >
18+ </Order >
Original file line number Diff line number Diff line change 1+ <?xml version =" 1.0" encoding =" UTF-8" standalone =" yes" ?>
2+ <Orders >
3+ <Order >
4+ <OrderNo >181219-001-345786</OrderNo >
5+ <AddressInfo >
6+ <Shipping >
7+ <FirstName >Tamizhvendan</FirstName >
8+ <LastName >Sembiyan</LastName >
9+ <Address1 >Plot No 222</Address1 >
10+ <Address2 >Ashok Nagar 42nd Street</Address2 >
11+ <City >Chennai</City >
12+ <State >TamilNadu</State >
13+ <Pincode >600001</Pincode >
14+ </Shipping >
15+ <Billing >
16+ <FirstName >Tamizhvendan</FirstName >
17+ <LastName >Sembiyan</LastName >
18+ <Address1 >Plot No 222</Address1 >
19+ <Address2 >Ashok Nagar 42nd Street</Address2 >
20+ <City >Chennai</City >
21+ <State >TamilNadu</State >
22+ <Pincode >600001</Pincode >
23+ </Billing >
24+ </AddressInfo >
25+ <PaymentInfo >
26+ <PaymentCost >900.0</PaymentCost >
27+ <PaymentId >000000-1545216772601</PaymentId >
28+ </PaymentInfo >
29+ <OrderLines >
30+ <OrderLine >
31+ <TransactionId >200058001702351</TransactionId >
32+ <ArticleNumber >200374</ArticleNumber >
33+ <Price >900.0</Price >
34+ </OrderLine >
35+ </OrderLines >
36+ </Order >
37+ </Orders >
Original file line number Diff line number Diff line change 1414 [toucan " 1.14.0" ]
1515 [clj-http " 3.10.0" ]
1616 [com.ibm.mq/com.ibm.mq.allclient " 9.1.0.0" ]
17- [clojurewerkz/quartzite " 2.1.0" ]]
17+ [clojurewerkz/quartzite " 2.1.0" ]
18+ [funcool/cuerdas " 2.0.5" ]]
1819 :main ^:skip-aot wheel.core
1920 :target-path " target/%s"
2021 :profiles {:uberjar {:aot :all }
Original file line number Diff line number Diff line change 11(ns wheel.marketplace.tata-cliq.api
2- (:require [clj-http.client :as http]))
2+ (:require [clj-http.client :as http]
3+ [wheel.xml :as wheel-xml]))
34
45(defn ranging [{:keys [base-url bearer-token]} channel-id items]
56 (let [url (str base-url " /channels/" channel-id " /ranging" )
89 :content-type :json
910 :headers {:authorization auth-header}})))
1011
12+ (defn- vectorize [x]
13+ (if (vector? x)
14+ x
15+ (vector x)))
16+
17+ (defn new-orders [{:keys [base-url bearer-token]} channel-id]
18+ (let [url (str base-url " /channels/" channel-id " /new-orders" )
19+ auth-header (str " Bearer " bearer-token)]
20+ (-> (http/get url {:headers {:authorization auth-header}})
21+ :body
22+ wheel-xml/xml-str->map
23+ (get-in [:orders :order ])
24+ vectorize)))
25+
1126(comment
12- ( ranging { :base-url " http://localhost:3000 "
13- :bearer-token " top-secret! " }
14- " UB " [{ :sku " SKU1 "
15- :ean " EAN1 " }] ))
27+
28+ ( new-orders { :base-url " http://localhost:3000 "
29+ :bearer-token " top-secret! " }
30+ " UB " ))
Original file line number Diff line number Diff line change 1+ (ns wheel.xml
2+ (:require [cuerdas.core :as str]
3+ [clojure.xml :as xml])
4+ (:import [java.io StringBufferInputStream]))
5+
6+ (defn- xml-element-merger [x y]
7+ (if (vector? x)
8+ (conj x y)
9+ (vector x y)))
10+
11+ (defn- merge-if [map source-map]
12+ (if (empty? map)
13+ source-map
14+ (merge map source-map)))
15+
16+ (defn hyphenate-keys [m]
17+ (reduce
18+ (fn [state x]
19+ (let [value (get m x)]
20+ (assoc (dissoc state x)
21+ (str/keyword x)
22+ (cond
23+ (map? value) (hyphenate-keys value)
24+ (sequential? value) (map #(hyphenate-keys %) value)
25+ :else value))))
26+ m (keys m)))
27+
28+ (defn xml-element->map [{:keys [tag attrs content]}]
29+ (let [attrs (hyphenate-keys attrs)]
30+ (if (= 1 (count content))
31+ (if (map? (first content))
32+ (hash-map (str/keyword tag) (->> (first content)
33+ xml-element->map
34+ (merge attrs)))
35+ (if (empty? attrs)
36+ (hash-map (str/keyword tag) (first content))
37+ (hash-map (str/keyword tag) attrs)))
38+ (hash-map (str/keyword tag) (->> (map xml-element->map content)
39+ (apply (partial merge-with xml-element-merger))
40+ (merge-if attrs))))))
41+
42+ (defn xml-str->map [raw-xml-str]
43+ (-> (StringBufferInputStream. raw-xml-str)
44+ xml/parse
45+ xml-element->map))
You can’t perform that action at this time.
0 commit comments