params added to long urls as well

This commit is contained in:
Christian Mueller
2014-01-25 21:37:20 +01:00
parent 6cc030e855
commit 32238ff298
5 changed files with 28 additions and 19 deletions
+6
View File
@@ -1,3 +1,4 @@
# NoteHub API
**Version 1.2, status: released.**
@@ -72,6 +73,9 @@ Parameter | Explanation | Type
`signature` | Signature | **required**
`password` | MD5 hash of a plain password for editing | *optional*
`version` | Used API version | **required**
`theme` | Theme name | *optional*
`text-font` | Text font name | *optional*
`header-font`| Header font name | *optional*
The Signature is the MD5 hash of the following string concatenation:
@@ -79,6 +83,8 @@ 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 parameters specifying the theme name and fonts are optional and only impact the URLs returned back.
The response of the server will contain the fields `noteID`, `longURL`, `shortURL`, `status`.
Example:
+18 -10
View File
@@ -1,13 +1,15 @@
(ns NoteHub.api
(:import
[java.util Calendar])
[java.util Calendar])
(:use
[NoteHub.settings]
[clojure.string :rename {replace sreplace}
:only [replace blank? lower-case split-lines split]])
[NoteHub.settings]
[ring.util.codec :only [url-encode]]
[clojure.string :rename {replace sreplace}
:only [replace blank? lower-case split-lines split]])
(:require
[ring.util.codec]
[NoteHub.storage :as storage]))
[ring.util.codec]
[hiccup.util :as util]
[NoteHub.storage :as storage]))
(def version "1.1")
@@ -23,6 +25,11 @@
(apply printf (str "%s:" string) (str (storage/get-current-date) ":LOG") args)
(println))
(defn url
"Creates a local url from the given substrings"
[& args]
(apply str (interpose "/" (cons "" (map url-encode args)))))
; Concatenates all fields to a string
(defn build-key
"Returns a storage-key for the given note coordinates"
@@ -51,7 +58,7 @@
(let [[year month day title] (split token #" ")]
(if description
(str domain "/" (storage/create-short-url token {:year year :month month :day day :title title}))
(apply str (interpose "/" [domain year month day (ring.util.codec/url-encode title)]))))))
(str domain (url year month day title))))))
(let [md5Instance (java.security.MessageDigest/getInstance "MD5")]
(defn get-signature
@@ -99,12 +106,13 @@
(map #(str proposed-title "-" (+ 2 %)) (range)))))
noteID (build-key date title)
new-params (assoc params :year year :month month :day day :title title)
short-url (storage/create-short-url noteID new-params)]
short-url (get-path (storage/create-short-url noteID new-params) :url)
long-url (get-path noteID)]
(do
(storage/add-note noteID note pid password)
{:noteID noteID
:longURL (get-path noteID)
:shortURL (get-path short-url :url)
:longURL (if (empty? params) long-url (str (util/url long-url params)))
:shortURL short-url
:status (create-response true)}))
{:status (create-response false (first errors))}))))
+2 -8
View File
@@ -11,7 +11,6 @@
[noir.util.crypt :only [encrypt]]
[hiccup.form]
[hiccup.core]
[ring.util.codec :only [url-encode]]
[hiccup.element]
[hiccup.util :only [escape-html]]
[hiccup.page :only [include-js html5]]
@@ -54,11 +53,6 @@
[code]
(status code (get-page code)))
(defn url
"Creates a local url from the given substrings"
[& args]
(apply str (interpose "/" (cons "" (map url-encode args)))))
; input form for the markdown text with a preview area
(defpartial input-form [form-url command fields content passwd-msg]
(let [css-class (when (= :publish command) :hidden)]
@@ -113,7 +107,7 @@
(md-node :article.bottom-space (:note note))
(let [links (map #(link-to
(if (= :short-url %)
(url (storage/create-short-url noteID params))
(api/url (storage/create-short-url noteID params))
(str (:longURL note) "/" (name %)))
(get-message %))
[:stats :edit :export :short-url])
@@ -137,7 +131,7 @@
(when-let [params (storage/resolve-url short-url)]
(let [{:keys [year month day title]} params
rest-params (dissoc params :year :month :day :title)
core-url (url year month day title)
core-url (api/url year month day title)
long-url (if (empty? rest-params) core-url (util/url core-url rest-params))]
(redirect long-url))))
+1
View File
@@ -129,6 +129,7 @@
(str "/"
(last (clojure.string/split
((parse-string (:body response)) "shortURL") #"/"))))) "Location")]
(= url ((parse-string (:body response)) "longURL"))
(substring? "theme=dark" url)
(substring? "text-font=Felvetica" url))
(is (do
+1 -1
View File
@@ -1,6 +1,6 @@
(ns NoteHub.test.views.pages
(:use [NoteHub.views.pages]
[NoteHub.api :only [build-key get-signature get-date]]
[NoteHub.api :only [build-key get-signature get-date url]]
[noir.util.test]
[NoteHub.storage]
[clojure.test]))