deprecated all API versions less than 1.4
This commit is contained in:
@@ -9,6 +9,7 @@
|
|||||||
- **API**: Integrate the publishing functionality into your editor using the official [NoteHub API](/api).
|
- **API**: Integrate the publishing functionality into your editor using the official [NoteHub API](/api).
|
||||||
|
|
||||||
## Changelog
|
## Changelog
|
||||||
|
- July 2014: deprecated all API versions less than 1.4
|
||||||
- March 2014: all notes with __less than 30 views after the first 30 days__ will expire.
|
- March 2014: all notes with __less than 30 views after the first 30 days__ will expire.
|
||||||
- February 2014: a simple JS-client for API testing [added](/api-test.html).
|
- February 2014: a simple JS-client for API testing [added](/api-test.html).
|
||||||
- January 2014:
|
- January 2014:
|
||||||
|
|||||||
+5
-25
@@ -64,23 +64,7 @@
|
|||||||
(let [req-version (Double/parseDouble req-version)
|
(let [req-version (Double/parseDouble req-version)
|
||||||
version (Double/parseDouble version)]
|
version (Double/parseDouble version)]
|
||||||
(if (< req-version version)
|
(if (< req-version version)
|
||||||
(let [args params
|
{:status (create-response false "Deprecated API version")}
|
||||||
args (if (and (:noteID args) (< req-version 1.3))
|
|
||||||
(assoc args
|
|
||||||
:noteID (sreplace (args :noteID) #" " "/")
|
|
||||||
:noteID* (args :noteID))
|
|
||||||
args)
|
|
||||||
args (if (and (:note args) (< req-version 1.4))
|
|
||||||
(assoc args :note* (sreplace (args :note) #"[\n\r]" ""))
|
|
||||||
args)
|
|
||||||
resp (f args)
|
|
||||||
server-message (get-in resp [:status :message])]
|
|
||||||
(assoc-in resp [:status :message]
|
|
||||||
(str
|
|
||||||
server-message
|
|
||||||
(when server-message "; ")
|
|
||||||
"this API version is deprecated and "
|
|
||||||
"will be disabled by the end of June 2014!")))
|
|
||||||
(f params)))
|
(f params)))
|
||||||
{:status (create-response false "API version expected")}))
|
{:status (create-response false "API version expected")}))
|
||||||
|
|
||||||
@@ -98,12 +82,11 @@
|
|||||||
{:status (create-response false "noteID '%s' unknown" noteID)}))
|
{:status (create-response false "noteID '%s' unknown" noteID)}))
|
||||||
|
|
||||||
(defn post-note
|
(defn post-note
|
||||||
[{:keys [note pid signature password note*] :as params}]
|
[{:keys [note pid signature password] :as params}]
|
||||||
;(log "post-note: %s" {:pid pid :signature signature :password password :note note})
|
;(log "post-note: %s" {:pid pid :signature signature :password password :note note})
|
||||||
(let [errors (filter identity
|
(let [errors (filter identity
|
||||||
[(when-not (storage/valid-publisher? pid) "pid invalid")
|
[(when-not (storage/valid-publisher? pid) "pid invalid")
|
||||||
; TODO: remove note* after June 2014
|
(when-not (= signature (storage/sign pid (storage/get-psk pid) note))
|
||||||
(when-not (= signature (storage/sign pid (storage/get-psk pid) (or note* note)))
|
|
||||||
"signature invalid")
|
"signature invalid")
|
||||||
(when (blank? note) "note is empty")])]
|
(when (blank? note) "note is empty")])]
|
||||||
(if (empty? errors)
|
(if (empty? errors)
|
||||||
@@ -129,14 +112,11 @@
|
|||||||
{:status (create-response false (first errors))})))
|
{:status (create-response false (first errors))})))
|
||||||
|
|
||||||
|
|
||||||
(defn update-note [{:keys [noteID note pid signature password noteID* note*]}]
|
(defn update-note [{:keys [noteID note pid signature password]}]
|
||||||
;(log "update-note: %s" {:pid pid :noteID noteID :signature signature :password password :note note})
|
;(log "update-note: %s" {:pid pid :noteID noteID :signature signature :password password :note note})
|
||||||
(let [errors (filter identity
|
(let [errors (filter identity
|
||||||
[(when-not (storage/valid-publisher? pid) "pid invalid")
|
[(when-not (storage/valid-publisher? pid) "pid invalid")
|
||||||
; TODO: noteID* is a hack introduced by backwards-comp. to older APIs
|
(when-not (= signature (storage/sign pid (storage/get-psk pid) noteID note password))
|
||||||
(when-not (= signature (storage/sign pid (storage/get-psk pid) (or noteID* noteID)
|
|
||||||
; TODO: remove note* after June 2014
|
|
||||||
(or note* note) password))
|
|
||||||
"signature invalid")
|
"signature invalid")
|
||||||
(when (blank? note) "note is empty")
|
(when (blank? note) "note is empty")
|
||||||
(when-not (storage/valid-password? noteID password) "password invalid")])]
|
(when-not (storage/valid-password? noteID password) "password invalid")])]
|
||||||
|
|||||||
@@ -133,6 +133,7 @@
|
|||||||
url))))
|
url))))
|
||||||
|
|
||||||
(defn gc [password dry]
|
(defn gc [password dry]
|
||||||
|
(println (get-setting :admin-pw))
|
||||||
(when (= password (get-setting :admin-pw))
|
(when (= password (get-setting :admin-pw))
|
||||||
(let [N 30
|
(let [N 30
|
||||||
timestamp (- (get-current-date) (* N 24 60 60 1000))
|
timestamp (- (get-current-date) (* N 24 60 60 1000))
|
||||||
|
|||||||
+15
-16
@@ -125,15 +125,15 @@
|
|||||||
(is (has-status response 200))
|
(is (has-status response 200))
|
||||||
(is (get-in body ["status" "success"]))
|
(is (get-in body ["status" "success"]))
|
||||||
(is (= note ((parse-string
|
(is (= note ((parse-string
|
||||||
(:body (send-request [:get "/api/note"] {:version "1.0" :noteID noteID}))) "note")))
|
(:body (send-request [:get "/api/note"] {:version "1.4" :noteID noteID}))) "note")))
|
||||||
|
(is (= "Deprecated API version" (get-in (parse-string
|
||||||
|
(:body (send-request [:get "/api/note"] {:version "1.3" :noteID noteID}))) ["status" "message"])))
|
||||||
(is (= "API version expected" (get-in (parse-string
|
(is (= "API version expected" (get-in (parse-string
|
||||||
(:body (send-request [:get "/api/note"] {:noteID noteID}))) ["status" "message"])))
|
(:body (send-request [:get "/api/note"] {:noteID noteID}))) ["status" "message"])))
|
||||||
(is (= note ((parse-string
|
(is (= note ((parse-string
|
||||||
(:body (send-request [:get "/api/note"] {:version "1.1"
|
(:body (send-request [:get "/api/note"] {:version "1.4" :noteID noteID}))) "note")))
|
||||||
:noteID (clojure.string/replace noteID #"/" " ")}))) "note")))
|
|
||||||
(isnt (= note ((parse-string
|
(isnt (= note ((parse-string
|
||||||
(:body (send-request [:get "/api/note"] {:version "1.4"
|
(:body (send-request [:get "/api/note"] {:version "1.3" :noteID noteID}))) "note")))
|
||||||
:noteID (clojure.string/replace noteID #"/" " ")}))) "note")))
|
|
||||||
(is (do
|
(is (do
|
||||||
(storage/delete-note noteID)
|
(storage/delete-note noteID)
|
||||||
(not (storage/note-exists? noteID)))))))
|
(not (storage/note-exists? noteID)))))))
|
||||||
@@ -170,31 +170,29 @@
|
|||||||
:version "1.4"
|
:version "1.4"
|
||||||
:password "qwerty"})
|
:password "qwerty"})
|
||||||
body (parse-string (:body response))
|
body (parse-string (:body response))
|
||||||
origID (body "noteID")
|
noteID (body "noteID")]
|
||||||
noteID (clojure.string/replace origID #"/" " ")]
|
|
||||||
(testing "Note update"
|
(testing "Note update"
|
||||||
(is (has-status response 200))
|
(is (has-status response 200))
|
||||||
(is (get-in body ["status" "success"]))
|
(is (get-in body ["status" "success"]))
|
||||||
(is (storage/note-exists? origID))
|
(is (storage/note-exists? noteID))
|
||||||
(is (substring? "_test_ note"
|
(is (substring? "_test_ note"
|
||||||
((parse-string
|
((parse-string
|
||||||
(:body (send-request [:get "/api/note"] {:version "1.0" :noteID noteID}))) "note")))
|
(:body (send-request [:get "/api/note"] {:version "1.4" :noteID noteID}))) "note")))
|
||||||
(let [response (send-request [:put "/api/note"]
|
(let [response (send-request [:put "/api/note"]
|
||||||
{:noteID noteID
|
{:noteID noteID
|
||||||
:note "WRONG pass"
|
:note "WRONG pass"
|
||||||
:pid pid
|
:pid pid
|
||||||
:signature (storage/sign pid psk noteID "WRONG pass" "qwerty1")
|
:signature (storage/sign pid psk noteID "WRONG pass" "qwerty1")
|
||||||
:password "qwerty1"
|
:password "qwerty1"
|
||||||
:version "1.0"})
|
:version "1.4"})
|
||||||
body (parse-string (:body response))]
|
body (parse-string (:body response))]
|
||||||
(is (has-status response 200))
|
(is (has-status response 200))
|
||||||
(isnt (get-in body ["status" "success"]))
|
(isnt (get-in body ["status" "success"]))
|
||||||
(is (= "password invalid; this API version is deprecated and will be disabled by the end of June 2014!"
|
(is (= "password invalid" (get-in body ["status" "message"])))
|
||||||
(get-in body ["status" "message"])))
|
|
||||||
(isnt (get-in body ["statistics" "edited"]))
|
(isnt (get-in body ["statistics" "edited"]))
|
||||||
(is (substring? "_test_ note"
|
(is (substring? "_test_ note"
|
||||||
((parse-string
|
((parse-string
|
||||||
(:body (send-request [:get "/api/note"] {:version "1.0" :noteID noteID}))) "note"))))
|
(:body (send-request [:get "/api/note"] {:version "1.4" :noteID noteID}))) "note"))))
|
||||||
(is (get-in (parse-string
|
(is (get-in (parse-string
|
||||||
(:body (send-request [:put "/api/note"]
|
(:body (send-request [:put "/api/note"]
|
||||||
{:noteID noteID
|
{:noteID noteID
|
||||||
@@ -202,13 +200,14 @@
|
|||||||
:pid pid
|
:pid pid
|
||||||
:signature (storage/sign pid psk noteID "UPDATED CONTENT" "qwerty")
|
:signature (storage/sign pid psk noteID "UPDATED CONTENT" "qwerty")
|
||||||
:password "qwerty"
|
:password "qwerty"
|
||||||
:version "1.0"}))) ["status" "success"]))
|
:version "1.4"}))) ["status" "success"]))
|
||||||
(isnt (= nil (((parse-string
|
(isnt (= nil (((parse-string
|
||||||
(:body (send-request [:get "/api/note"] {:version "1.0" :noteID noteID})))
|
(:body (send-request [:get "/api/note"] {:version "1.4" :noteID noteID})))
|
||||||
"statistics") "edited")))
|
"statistics") "edited")))
|
||||||
|
(let [resp (send-request [:get "/api/note"] {:version "1.4" :noteID noteID})]
|
||||||
(is (substring? "UPDATED CONTENT"
|
(is (substring? "UPDATED CONTENT"
|
||||||
((parse-string
|
((parse-string
|
||||||
(:body (send-request [:get "/api/note"] {:version "1.0" :noteID noteID}))) "note")))
|
(:body resp)) "note"))))
|
||||||
(is (do
|
(is (do
|
||||||
(storage/delete-note noteID)
|
(storage/delete-note noteID)
|
||||||
(not (storage/note-exists? noteID)))))))
|
(not (storage/note-exists? noteID)))))))
|
||||||
|
|||||||
Reference in New Issue
Block a user