renamed paths to urls back
This commit is contained in:
@@ -26,14 +26,14 @@ Parameter | Explanation | Type
|
||||
`noteID` | Note-ID | **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:
|
||||
|
||||
{
|
||||
note: <markdown source>,
|
||||
longPath: "/2014/1/3/lorem-ipsum",
|
||||
shortPath: "/0vrcp",
|
||||
longURL: "http://notehub.org/2014/1/3/lorem-ipsum",
|
||||
shortURL: "http://notehub.org/0vrcp",
|
||||
statistics: {
|
||||
published: "2014-1-3",
|
||||
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 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:
|
||||
|
||||
{
|
||||
noteID: "2014/1/3/lorem-ipsum",
|
||||
longPath: "/2014/1/3/lorem-ipsum",
|
||||
shortPath: "/0vrcp",
|
||||
longURL: "http://notehub.org/2014/1/3/lorem-ipsum",
|
||||
shortURL: "http://notehub.org/0vrcp",
|
||||
status: {
|
||||
success: true,
|
||||
comment: "some server message"
|
||||
@@ -109,13 +109,13 @@ The Signature is the MD5 hash of the following string concatenation:
|
||||
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:
|
||||
|
||||
{
|
||||
longPath: "/2014/1/3/lorem-ipsum",
|
||||
shortPath: "/0vrcp",
|
||||
longURL: "http://notehub.org/2014/1/3/lorem-ipsum",
|
||||
shortURL: "http://notehub.org/0vrcp",
|
||||
status: {
|
||||
success: true,
|
||||
comment: "some server message"
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
max-title-length = 40
|
||||
domain = http://notehub.org/
|
||||
domain = http://notehub.org
|
||||
|
||||
+8
-8
@@ -36,12 +36,12 @@
|
||||
([success message & params]
|
||||
(assoc (create-response success) :message (apply format message params))))
|
||||
|
||||
(defn- getPath [noteID & description]
|
||||
(defn- get-path [noteID & description]
|
||||
(if description
|
||||
(str "/" (storage/get-short-url noteID))
|
||||
(let [[year month day title] (split noteID #" ")]
|
||||
(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")]
|
||||
(defn get-signature
|
||||
@@ -55,8 +55,8 @@
|
||||
(defn get-note [noteID]
|
||||
(if (storage/note-exists? noteID)
|
||||
{:note (storage/get-note noteID)
|
||||
:longPath (getPath noteID)
|
||||
:shortPath (getPath noteID :short)
|
||||
:longURL (get-path noteID)
|
||||
:shortURL (get-path noteID :short)
|
||||
:statistics (storage/get-note-statistics noteID)
|
||||
:status (create-response true)}
|
||||
(create-response false "noteID '%s' unknown" noteID)))
|
||||
@@ -88,8 +88,8 @@
|
||||
(storage/add-note noteID note password)
|
||||
(storage/create-short-url noteID)
|
||||
{:noteID noteID
|
||||
:longPath (getPath noteID)
|
||||
:shortPath (getPath noteID :short)
|
||||
:longURL (get-path noteID)
|
||||
:shortURL (get-path noteID :short)
|
||||
:status (create-response true)}))
|
||||
{:status (create-response false (first errors))}))))
|
||||
|
||||
@@ -107,7 +107,7 @@
|
||||
(if (empty? errors)
|
||||
(do
|
||||
(storage/edit-note noteID note)
|
||||
{:longPath (getPath noteID)
|
||||
:shortPath (getPath noteID :short)
|
||||
{:longURL (get-path noteID)
|
||||
:shortURL (get-path noteID :short)
|
||||
:status (create-response true)})
|
||||
{:status (create-response false (first errors))})))
|
||||
|
||||
@@ -145,7 +145,7 @@
|
||||
(if (storage/valid-publisher? pid)
|
||||
(let [resp (api/post-note note pid (api/get-signature (str pid psk note)) password)]
|
||||
(if (get-in resp [:status :success])
|
||||
(redirect (:longPath resp))
|
||||
(redirect (:longURL resp))
|
||||
(response 400)))
|
||||
(response 500)))
|
||||
(response 400)))
|
||||
@@ -159,7 +159,7 @@
|
||||
(api/get-signature (str pid psk noteID note password))
|
||||
password)]
|
||||
(if (get-in resp [:status :success])
|
||||
(redirect (:longPath resp))
|
||||
(redirect (:longURL resp))
|
||||
(response 403)))
|
||||
(response 500))))
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
(def pid "somePlugin")
|
||||
(def pid2 "somePlugin2")
|
||||
(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))))
|
||||
|
||||
(defmacro isnt [arg] `(is (not ~arg)))
|
||||
@@ -43,8 +43,8 @@
|
||||
(is (:success (:status post-response)))
|
||||
(is (:success (:status get-response)))
|
||||
(is (= note (:note get-response)))
|
||||
(is (= (:longPath post-response) (:longPath get-response) note-url))
|
||||
(is (= (:shortPath post-response) (:shortPath get-response)))
|
||||
(is (= (:longURL post-response) (:longURL get-response) note-url))
|
||||
(is (= (:shortURL post-response) (:shortURL get-response)))
|
||||
(is (= "1" (get-in get-response [:statistics :views])))
|
||||
(isnt (get-in get-response [:statistics :edited]))
|
||||
(is (= "2" (get-in (get-note (:noteID post-response)) [:statistics :views])))))
|
||||
|
||||
@@ -35,18 +35,18 @@
|
||||
title "this-is-a-test-note"
|
||||
[year month day] date]
|
||||
(testing "Note creation"
|
||||
(is (has-status
|
||||
(send-request
|
||||
(let [resp (send-request
|
||||
[:post "/post-note"]
|
||||
{:session session-key
|
||||
: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 (substring? "Hello _world_"
|
||||
((send-request (url year month day title)) :body)))
|
||||
(is (do
|
||||
(delete-note (build-key date title))
|
||||
(not (note-exists? (build-key date title))))))))
|
||||
(not (note-exists? (build-key date title)))))))))
|
||||
|
||||
(deftest note-creation-utf
|
||||
(let [session-key (create-session)
|
||||
|
||||
Reference in New Issue
Block a user