renamed paths to urls back
This commit is contained in:
@@ -26,14 +26,14 @@ Parameter | Explanation | Type
|
|||||||
`noteID` | Note-ID | **required**
|
`noteID` | Note-ID | **required**
|
||||||
`version` | Used API version | **required**
|
`version` | Used API version | **required**
|
||||||
|
|
||||||
will return a JSON object containing following self explaining fields: `note`, `longPath`, `shortPath`, `statistics`, `status`.
|
will return a JSON object containing following self explaining fields: `note`, `longURL`, `shortURL`, `statistics`, `status`.
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
{
|
{
|
||||||
note: <markdown source>,
|
note: <markdown source>,
|
||||||
longPath: "/2014/1/3/lorem-ipsum",
|
longURL: "http://notehub.org/2014/1/3/lorem-ipsum",
|
||||||
shortPath: "/0vrcp",
|
shortURL: "http://notehub.org/0vrcp",
|
||||||
statistics: {
|
statistics: {
|
||||||
published: "2014-1-3",
|
published: "2014-1-3",
|
||||||
edited: "2014-1-12",
|
edited: "2014-1-12",
|
||||||
@@ -71,14 +71,14 @@ The Signature is the MD5 hash of the following string concatenation:
|
|||||||
|
|
||||||
The signature serves as a proof, that the request is authentic and will be issued by the publisher corresponding to the provided PID.
|
The signature serves as a proof, that the request is authentic and will be issued by the publisher corresponding to the provided PID.
|
||||||
|
|
||||||
The response of the server will contain the fields `noteID`, `longPath`, `shortPath`, `status`.
|
The response of the server will contain the fields `noteID`, `longURL`, `shortURL`, `status`.
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
{
|
{
|
||||||
noteID: "2014/1/3/lorem-ipsum",
|
noteID: "2014/1/3/lorem-ipsum",
|
||||||
longPath: "/2014/1/3/lorem-ipsum",
|
longURL: "http://notehub.org/2014/1/3/lorem-ipsum",
|
||||||
shortPath: "/0vrcp",
|
shortURL: "http://notehub.org/0vrcp",
|
||||||
status: {
|
status: {
|
||||||
success: true,
|
success: true,
|
||||||
comment: "some server message"
|
comment: "some server message"
|
||||||
@@ -109,13 +109,13 @@ The Signature is the MD5 hash of the following string concatenation:
|
|||||||
pid + psk + noteID + note + password
|
pid + psk + noteID + note + password
|
||||||
|
|
||||||
|
|
||||||
The response of the server will contain the fields `longPath`, `shortPath`, `status`.
|
The response of the server will contain the fields `longURL`, `shortURL`, `status`.
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
{
|
{
|
||||||
longPath: "/2014/1/3/lorem-ipsum",
|
longURL: "http://notehub.org/2014/1/3/lorem-ipsum",
|
||||||
shortPath: "/0vrcp",
|
shortURL: "http://notehub.org/0vrcp",
|
||||||
status: {
|
status: {
|
||||||
success: true,
|
success: true,
|
||||||
comment: "some server message"
|
comment: "some server message"
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
max-title-length = 40
|
max-title-length = 40
|
||||||
domain = http://notehub.org/
|
domain = http://notehub.org
|
||||||
|
|||||||
+8
-8
@@ -36,12 +36,12 @@
|
|||||||
([success message & params]
|
([success message & params]
|
||||||
(assoc (create-response success) :message (apply format message params))))
|
(assoc (create-response success) :message (apply format message params))))
|
||||||
|
|
||||||
(defn- getPath [noteID & description]
|
(defn- get-path [noteID & description]
|
||||||
(if description
|
(if description
|
||||||
(str "/" (storage/get-short-url noteID))
|
(str "/" (storage/get-short-url noteID))
|
||||||
(let [[year month day title] (split noteID #" ")]
|
(let [[year month day title] (split noteID #" ")]
|
||||||
(apply str (interpose "/"
|
(apply str (interpose "/"
|
||||||
[year month day (ring.util.codec/url-encode title)])))))
|
[domain year month day (ring.util.codec/url-encode title)])))))
|
||||||
|
|
||||||
(let [md5Instance (java.security.MessageDigest/getInstance "MD5")]
|
(let [md5Instance (java.security.MessageDigest/getInstance "MD5")]
|
||||||
(defn get-signature
|
(defn get-signature
|
||||||
@@ -55,8 +55,8 @@
|
|||||||
(defn get-note [noteID]
|
(defn get-note [noteID]
|
||||||
(if (storage/note-exists? noteID)
|
(if (storage/note-exists? noteID)
|
||||||
{:note (storage/get-note noteID)
|
{:note (storage/get-note noteID)
|
||||||
:longPath (getPath noteID)
|
:longURL (get-path noteID)
|
||||||
:shortPath (getPath noteID :short)
|
:shortURL (get-path noteID :short)
|
||||||
:statistics (storage/get-note-statistics noteID)
|
:statistics (storage/get-note-statistics noteID)
|
||||||
:status (create-response true)}
|
:status (create-response true)}
|
||||||
(create-response false "noteID '%s' unknown" noteID)))
|
(create-response false "noteID '%s' unknown" noteID)))
|
||||||
@@ -88,8 +88,8 @@
|
|||||||
(storage/add-note noteID note password)
|
(storage/add-note noteID note password)
|
||||||
(storage/create-short-url noteID)
|
(storage/create-short-url noteID)
|
||||||
{:noteID noteID
|
{:noteID noteID
|
||||||
:longPath (getPath noteID)
|
:longURL (get-path noteID)
|
||||||
:shortPath (getPath noteID :short)
|
:shortURL (get-path noteID :short)
|
||||||
:status (create-response true)}))
|
:status (create-response true)}))
|
||||||
{:status (create-response false (first errors))}))))
|
{:status (create-response false (first errors))}))))
|
||||||
|
|
||||||
@@ -107,7 +107,7 @@
|
|||||||
(if (empty? errors)
|
(if (empty? errors)
|
||||||
(do
|
(do
|
||||||
(storage/edit-note noteID note)
|
(storage/edit-note noteID note)
|
||||||
{:longPath (getPath noteID)
|
{:longURL (get-path noteID)
|
||||||
:shortPath (getPath noteID :short)
|
:shortURL (get-path noteID :short)
|
||||||
:status (create-response true)})
|
:status (create-response true)})
|
||||||
{:status (create-response false (first errors))})))
|
{:status (create-response false (first errors))})))
|
||||||
|
|||||||
@@ -145,7 +145,7 @@
|
|||||||
(if (storage/valid-publisher? pid)
|
(if (storage/valid-publisher? pid)
|
||||||
(let [resp (api/post-note note pid (api/get-signature (str pid psk note)) password)]
|
(let [resp (api/post-note note pid (api/get-signature (str pid psk note)) password)]
|
||||||
(if (get-in resp [:status :success])
|
(if (get-in resp [:status :success])
|
||||||
(redirect (:longPath resp))
|
(redirect (:longURL resp))
|
||||||
(response 400)))
|
(response 400)))
|
||||||
(response 500)))
|
(response 500)))
|
||||||
(response 400)))
|
(response 400)))
|
||||||
@@ -159,7 +159,7 @@
|
|||||||
(api/get-signature (str pid psk noteID note password))
|
(api/get-signature (str pid psk noteID note password))
|
||||||
password)]
|
password)]
|
||||||
(if (get-in resp [:status :success])
|
(if (get-in resp [:status :success])
|
||||||
(redirect (:longPath resp))
|
(redirect (:longURL resp))
|
||||||
(response 403)))
|
(response 403)))
|
||||||
(response 500))))
|
(response 500))))
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
(def pid "somePlugin")
|
(def pid "somePlugin")
|
||||||
(def pid2 "somePlugin2")
|
(def pid2 "somePlugin2")
|
||||||
(def note-title (str (apply print-str (get-date)) " hello-world-this-is-a-test-note"))
|
(def note-title (str (apply print-str (get-date)) " hello-world-this-is-a-test-note"))
|
||||||
(def note-url (str (apply str (interpose "/" (get-date))) "/hello-world-this-is-a-test-note"))
|
(def note-url (str (apply str domain "/" (interpose "/" (get-date))) "/hello-world-this-is-a-test-note"))
|
||||||
(defn substring? [a b] (not (= nil (re-matches (re-pattern (str "(?s).*" a ".*")) b))))
|
(defn substring? [a b] (not (= nil (re-matches (re-pattern (str "(?s).*" a ".*")) b))))
|
||||||
|
|
||||||
(defmacro isnt [arg] `(is (not ~arg)))
|
(defmacro isnt [arg] `(is (not ~arg)))
|
||||||
@@ -43,8 +43,8 @@
|
|||||||
(is (:success (:status post-response)))
|
(is (:success (:status post-response)))
|
||||||
(is (:success (:status get-response)))
|
(is (:success (:status get-response)))
|
||||||
(is (= note (:note get-response)))
|
(is (= note (:note get-response)))
|
||||||
(is (= (:longPath post-response) (:longPath get-response) note-url))
|
(is (= (:longURL post-response) (:longURL get-response) note-url))
|
||||||
(is (= (:shortPath post-response) (:shortPath get-response)))
|
(is (= (:shortURL post-response) (:shortURL get-response)))
|
||||||
(is (= "1" (get-in get-response [:statistics :views])))
|
(is (= "1" (get-in get-response [:statistics :views])))
|
||||||
(isnt (get-in get-response [:statistics :edited]))
|
(isnt (get-in get-response [:statistics :edited]))
|
||||||
(is (= "2" (get-in (get-note (:noteID post-response)) [:statistics :views])))))
|
(is (= "2" (get-in (get-note (:noteID post-response)) [:statistics :views])))))
|
||||||
|
|||||||
@@ -35,18 +35,18 @@
|
|||||||
title "this-is-a-test-note"
|
title "this-is-a-test-note"
|
||||||
[year month day] date]
|
[year month day] date]
|
||||||
(testing "Note creation"
|
(testing "Note creation"
|
||||||
(is (has-status
|
(let [resp (send-request
|
||||||
(send-request
|
|
||||||
[:post "/post-note"]
|
[:post "/post-note"]
|
||||||
{:session session-key
|
{:session session-key
|
||||||
:note test-note
|
:note test-note
|
||||||
:signature (get-signature session-key test-note)}) 302))
|
:signature (get-signature session-key test-note)})]
|
||||||
|
(is (has-status resp 302))
|
||||||
(is (note-exists? (build-key date title)))
|
(is (note-exists? (build-key date title)))
|
||||||
(is (substring? "Hello _world_"
|
(is (substring? "Hello _world_"
|
||||||
((send-request (url year month day title)) :body)))
|
((send-request (url year month day title)) :body)))
|
||||||
(is (do
|
(is (do
|
||||||
(delete-note (build-key date title))
|
(delete-note (build-key date title))
|
||||||
(not (note-exists? (build-key date title))))))))
|
(not (note-exists? (build-key date title)))))))))
|
||||||
|
|
||||||
(deftest note-creation-utf
|
(deftest note-creation-utf
|
||||||
(let [session-key (create-session)
|
(let [session-key (create-session)
|
||||||
|
|||||||
Reference in New Issue
Block a user