{"id":6480,"date":"2011-11-13T14:48:09","date_gmt":"2011-11-13T05:48:09","guid":{"rendered":"http:\/\/fukata.org\/?p=6480"},"modified":"2017-08-11T22:58:48","modified_gmt":"2017-08-11T22:58:48","slug":"clojure-clj-aws-ecs","status":"publish","type":"post","link":"https:\/\/blog.fukata.org\/archives\/6480\/","title":{"rendered":"Clojure\u304b\u3089ECS\u306b\u30a2\u30af\u30bb\u30b9\u3059\u308b\u300cclj-aws-ecs\u300d"},"content":{"rendered":"

making\/clj-aws-ecs – GitHub<\/a><\/p>\n

\u4eca\u4f5c\u3063\u3066\u3044\u308b\u30b5\u30fc\u30d3\u30b9\u3067\u5c11\u3057\u4f7f\u3063\u3066\u307f\u305f\u306e\u3067\u3001\u30e1\u30e2\u3057\u3066\u304a\u304d\u307e\u3059\u3002<\/p>\n

<\/p>\n

\u4f7f\u3044\u65b9\u306f\u81f3\u3063\u3066\u7c21\u5358\u3067\u3001<\/p>\n

\r\n(use 'am.ik.clj-aws-ecs)\r\n(def requester (make-requester \"ecs.amazonaws.jp\" \"YOUR-ACCESS-KEY-ID\" \"YOUR-ACCESS-SECRET-KEY\"))\r\n(item-search-map requester \"SearchIndex\" \"KEYWORD\")\r\n<\/pre>\n

\u5546\u54c1\u30ab\u30c6\u30b4\u30ea\u30fc\u306e\u6307\u5b9a(SearchIndex) – \u5546\u54c1\u691c\u7d22(ItemSearch) – Amazon Web \u30b5\u30fc\u30d3\u30b9<\/a><\/p>\n

SearchIndex\u4e00\u89a7\u306b\u3064\u3044\u3066\u306f\u4e0a\u8a18\u306e\u30da\u30fc\u30b8\u306b\u66f8\u3044\u3066\u3044\u307e\u3059\u3002<\/p>\n

clj-aws-ecs | Clojars<\/a><\/p>\n

clojars.org\u306b\u3082\u767b\u9332\u3055\u308c\u3066\u3044\u308b\u306e\u3067\u3001project.clj\u306b\u4e0b\u8a18\u306e\u3088\u3046\u306b\u767b\u9332\u3059\u308c\u3070\u7c21\u5358\u306b\u4f7f\u3048\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n

\r\n[am.ik\/clj-aws-ecs \"0.1.0\"]\r\n<\/pre>\n

\u305f\u3060\u3001ECS\u306e\u623b\u308a\u5024\u304cXML\u3067\u3001item-search-map<\/strong>\u306e\u69cb\u9020\u306fXML\u3092\u305d\u306e\u307e\u307eMap\u306b\u5909\u63db\u3057\u305f\u69cb\u9020\u306b\u306a\u3063\u3066\u3044\u308b\u305f\u3081\u3001\u305d\u306e\u5024\u3092\u4f7f\u3063\u3066\u4f55\u304b\u306b\u5229\u7528\u3059\u308b\u6642\u306b\u9762\u5012\u306a\u306e\u3067\u3001\u7c21\u6613\u7684\u3067\u3059\u304c\u3001\u4e0b\u8a18\u306e\u3088\u3046\u306a\u30b3\u30fc\u30c9\u3092\u66f8\u3044\u3066XML\u30d9\u30fc\u30b9\u306eMap\u304b\u3089\u5024\u3092\u629c\u304d\u51fa\u3059\u51e6\u7406\u3092\u66f8\u304d\u307e\u3057\u305f\u3002<\/p>\n

\r\n(defn ecs-attr-value\r\n  ([attrs tag] (ecs-attr-value attrs tag true))\r\n  ([attrs tag first-only]\r\n   (if (empty? attrs)\r\n     nil \r\n     (let [attr (first attrs)\r\n           attr-tag (:tag (first attrs))]\r\n       (if (= tag attr-tag)\r\n         (if first-only\r\n           (first (:content attr))\r\n           (:content attr))\r\n         (recur (next attrs) tag first-only))))))\r\n\r\n(defn ecs-item-attrs-parse\r\n  [item attrs]\r\n  (if (empty? attrs)\r\n    item\r\n    (let [attr (first attrs)]\r\n      (def attr-value\r\n        (cond\r\n          (= (:tag attr) :ASIN) {:ASIN (first (:content attr))} \r\n          (= (:tag attr) :ItemAttributes) {:Title (ecs-attr-value (:content attr) :Title)} \r\n          (= (:tag attr) :SmallImage) {:SmallImage (ecs-attr-value (:content attr) :URL)} \r\n          (= (:tag attr) :MediumImage) {:MediumImage (ecs-attr-value (:content attr) :URL)} \r\n          (= (:tag attr) :LargeImage) {:LargeImage (ecs-attr-value (:content attr) :URL)} \r\n          (= (:tag attr) :DetailPageURL) {:DetailPageURL (first (:content attr))}))\r\n      (recur (if (nil? attr-value) item (conj item attr-value)) (next attrs)))))\r\n\r\n(defn ecs-item-parse [items xml-items] \r\n  (if (empty? xml-items)\r\n    items\r\n    (recur \r\n      (conj items (ecs-item-attrs-parse {} (:content (first xml-items)))) \r\n      (next xml-items))))\r\n\r\n(defn ecs-item-search [search-index keywords]\r\n  (ecs-item-parse [] (filter \r\n                       #(= :Item (% :tag))\r\n                       (:content \r\n                         (first \r\n                           (filter \r\n                             #(= :Items (% :tag))\r\n                             (:content (item-search-map \r\n                                         requester \r\n                                         search-index \r\n                                         keywords \r\n                                         {\"AssociateTag\" \"example-22\"\r\n                                          \"ResponseGroup\" \"Medium\"}))))))))\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"

making\/clj-aws-ecs – GitHub \u4eca\u4f5c\u3063\u3066\u3044\u308b\u30b5\u30fc\u30d3\u30b9\u3067\u5c11\u3057\u4f7f\u3063\u3066\u307f\u305f\u306e\u3067\u3001\u30e1\u30e2\u3057\u3066\u304a\u304d\u307e\u3059\u3002 … \u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":2,"featured_media":9223372036854775807,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1980],"tags":[120,803,937],"_links":{"self":[{"href":"https:\/\/blog.fukata.org\/wp-json\/wp\/v2\/posts\/6480"}],"collection":[{"href":"https:\/\/blog.fukata.org\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.fukata.org\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.fukata.org\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.fukata.org\/wp-json\/wp\/v2\/comments?post=6480"}],"version-history":[{"count":0,"href":"https:\/\/blog.fukata.org\/wp-json\/wp\/v2\/posts\/6480\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.fukata.org\/wp-json\/wp\/v2\/media\/9223372036854775807"}],"wp:attachment":[{"href":"https:\/\/blog.fukata.org\/wp-json\/wp\/v2\/media?parent=6480"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.fukata.org\/wp-json\/wp\/v2\/categories?post=6480"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.fukata.org\/wp-json\/wp\/v2\/tags?post=6480"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}