From 89031c2f0828f55bbd6b5da707d2b0c435941d7d Mon Sep 17 00:00:00 2001 From: Christian Mueller Date: Sun, 12 Jan 2014 11:59:23 +0100 Subject: [PATCH] added routing to the API --- API.md | 11 +++++++++-- src/NoteHub/views/pages.clj | 14 ++++++++++++++ test/NoteHub/test/storage.clj | 2 +- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/API.md b/API.md index 6fb32e1..563d7d9 100644 --- a/API.md +++ b/API.md @@ -16,7 +16,14 @@ To register as a publisher and gain access to NoteHub API, please [send](mailto: A simple `GET` request to the following URL: - http://notehub.org/api/note?version=1.0¬eID= + http://notehub.org/api/note + +with the following parameters: + +Parameter | Explanation | Type +--- | --- | --- +`noteID` | Note-ID | **required** +`version` | Used API version | **required** will return a JSON object containing following self explaining fields: `note`, `longURL`, `shortURL`, `statistics`, `status`. @@ -39,7 +46,7 @@ Example: Hence, the status of the request can be evaluated by reading of the property `status.success`. The field `status.comment`might contain an error message, a warning or any other comments from the server. -The note ID is a string, containing the date of publishing and a few first words of the note (usually the title), e.g.: `2014 1 3 lorem-ipsum`. This ID will be generated by NoteHub automatically. +The note ID is a string, containing the date of publishing and a few first words of the note (usually the title), e.g.: `"2014 1 3 lorem-ipsum"`. This ID will be generated by NoteHub automatically. ## Note Creation diff --git a/src/NoteHub/views/pages.clj b/src/NoteHub/views/pages.clj index d54a98a..164630b 100644 --- a/src/NoteHub/views/pages.clj +++ b/src/NoteHub/views/pages.clj @@ -184,3 +184,17 @@ (defpage "/api" args (let [title (get-message :api-registration)] (layout title [:article.markdown (slurp "API.md")]))) + +(defpage [:get "/api/note"] {:keys [version noteID]} + (generate-string (api/get-note noteID))) + +(defpage [:post "/api/note"] {:keys [version note pid signature password]} + (generate-string (api/post-note note pid signature password))) + +(defpage [:put "/api/note"] {:keys [version noteID note pid signature password]} + (generate-string (api/update-note noteID note pid signature password))) + + + + + diff --git a/test/NoteHub/test/storage.clj b/test/NoteHub/test/storage.clj index d1e6957..68a0e34 100644 --- a/test/NoteHub/test/storage.clj +++ b/test/NoteHub/test/storage.clj @@ -41,7 +41,7 @@ (add-note (build-key date test-title) test-note "12345qwert") (get-note (build-key date test-title))) test-note)) - #_(is (valid-password? (build-key date test-title) "12345qwert")) + (is (valid-password? (build-key date test-title) "12345qwert")) (is (= (do (update-note (build-key date test-title) "update" "12345qwert") (get-note (build-key date test-title)))