api registration page added

This commit is contained in:
Christian Mueller
2014-01-12 11:25:56 +01:00
parent 3231271744
commit 5f7d9ab251
6 changed files with 31 additions and 15 deletions
+6 -3
View File
@@ -1,20 +1,22 @@
# NoteHub API
**Version 1.0, status: draft!**
**Version 1.0, status: released.**
## Prerequisites
The NoteHub API can only be used in combination with a __Publisher ID__ (PID) and __Publisher Secret Key__ (PSK), which can be requested [here](http://notehub.org/api/register). The PSK can be revoked at any moment in case of an API abuse.
The NoteHub API can only be used in combination with a __Publisher ID__ (PID) and __Publisher Secret Key__ (PSK), which can be requested [here](#registration). The PSK can be revoked at any moment in case of an API abuse.
A PID is a string chosen by the publisher and cannot be longer than 16 characters (e.g.: __notepadPlugin__). A PSK will be generated by the NoteHub API and can be a string of any length and content.
All API requests must be issued with one special parameter `version` denoting the expected version of the API as a string, e.g. `1.0` (see examples below). You should always put the version of this document as a `version` parameter.
## <a name="registration"></a>NoteHub API Access Request
To register as a publisher and gain access to NoteHub API, please [send](mailto:notehub@icloud.com?subject=NoteHub API Access Request&body=Please add [a] your contact information, [b] short usage explanation and [c] the URL of the resource or it's website.) an email with the following information about you: contact information, short description of what you want to do and an URL of the resource where the API will be used or its website.
## Note Retrieval
A simple `GET` request to the following URL:
http://notehub.org/api/note?version=1.0&title=<NOTE-ID>
http://notehub.org/api/note?version=1.0&noteID=<NOTE-ID>
will return a JSON object containing following self explaining fields: `note`, `longURL`, `shortURL`, `statistics`, `status`.
@@ -113,3 +115,4 @@ Example:
}
The status object serves the same purpose as in the case of note retrieval and creation.
+2
View File
@@ -1,5 +1,6 @@
## News
- January 2014: NoteHub API v1.0 [introduced](/api).
- January 2014: NoteHub 2.0 released: new theme, more performance, extended markdown
- September 2013: Solarized color theme [added](https://github.com/chmllr/NoteHub/pull/4) (thanks Brandon!) ([Demo](http://notehub.org/2012/6/16/how-notehub-is-built?theme=solarized))
@@ -9,6 +10,7 @@
Send your feedback and comments directly to [@gravitydenier](http://twitter.com/gravitydenier) or open an [issue](https://github.com/chmllr/NoteHub/issues) on GitHub.
## Features
- **API**: Integrate the publishing functionality into your editor using the official [NoteHub API](/api).
- **Color Themes**: specify the color scheme by appending the corresponding parameter to the URL:
- [Dark](http://notehub.org/2012/6/16/how-notehub-is-built?theme=dark)
- [Solarized-Dark](http://notehub.org/2012/6/16/how-notehub-is-built?theme=solarized-dark)
+1
View File
@@ -23,3 +23,4 @@ stats = statistics
export = export
edit = edit
short-url = short url
api-registration = NoteHub API Access Request
+1
View File
@@ -2,6 +2,7 @@
:description "A free and anonymous hosting for markdown pages."
:dependencies [[org.clojure/clojure "1.5.1"]
[hiccup "1.0.0"]
[cheshire "5.3.1"]
[ring/ring-core "1.1.0"]
[clj-redis "0.0.12"]
[noir "1.3.0-beta1"]]
+6 -2
View File
@@ -16,6 +16,10 @@ var timerDelay = iosDetected ? 800 : 400;
var show = function(elem) { elem.style.display = "block" }
var $draft, $action, $preview, $password, $plain_password, $input_elems, $dashed_line, updatePreview;
function md2html(input){
return marked(input);
}
function loadPage() {
$draft = $("draft");
$action = $("action");
@@ -31,7 +35,7 @@ function loadPage() {
timer = setTimeout(function(){
show($dashed_line);
show($input_elems);
$preview.innerHTML = marked(content);
$preview.innerHTML = md2html(content);
}, delay);
};
if($action){
@@ -47,7 +51,7 @@ function loadPage() {
var mdDocs = document.getElementsByClassName("markdown");
for(var i = 0; i < mdDocs.length; i++){
mdDocs[i].innerHTML = marked(mdDocs[i].innerHTML);
mdDocs[i].innerHTML = md2html(mdDocs[i].innerHTML);
show(mdDocs[i]);
}
}
+15 -10
View File
@@ -1,8 +1,9 @@
(ns NoteHub.views.pages
(:require [hiccup.util :as util])
(:require [hiccup.util :as util]
[NoteHub.api :as api]
[cheshire.core :refer :all])
(:use
[NoteHub.storage] ; TODO: delete this
[NoteHub.api :only [build-key get-date]]
[NoteHub.settings]
[NoteHub.views.common]
[clojure.string :rename {replace sreplace}
@@ -95,8 +96,8 @@
; Update Note Page
(defpage "/:year/:month/:day/:title/edit" {:keys [year month day title]}
(input-form "/update-note" :update
(let [noteID (build-key [year month day] title)]
(let [noteID (api/build-key [year month day] title)]
(input-form "/update-note" :update
(html (hidden-field :key noteID))
(get-note noteID) :enter-passwd)))
@@ -112,16 +113,16 @@
(wrap
(create-short-url params)
(select-keys params [:title :theme :header-font :text-font])
(get-note (build-key [year month day] title))))
(get-note (api/build-key [year month day] title))))
; Provides Markdown of the specified note
(defpage "/:year/:month/:day/:title/export" {:keys [year month day title]}
(when-let [md-text (get-note (build-key [year month day] title))]
(when-let [md-text (get-note (api/build-key [year month day] title))]
(content-type "text/plain; charset=utf-8" md-text)))
; Provides the number of views of the specified note
(defpage "/:year/:month/:day/:title/stats" {:keys [year month day title]}
(when-let [views (get-note-views (build-key [year month day] title))]
(when-let [views (get-note-views (api/build-key [year month day] title))]
(layout (get-message :statistics)
[:table#stats.helvetica.central-element
[:tr
@@ -152,7 +153,7 @@
; if yes, we compute the current date, extract a title string from the text,
; which will be a part of the url and look whether this title is free today;
; if not, append "-n", where "n" is the next free number
(let [[year month day] (get-date)
(let [[year month day] (api/get-date)
untrimmed-line (filter #(or (= \- %) (Character/isLetterOrDigit %))
(-> draft split-lines first (sreplace " " "-") lower-case))
trim (fn [s] (apply str (drop-while #(= \- %) s)))
@@ -161,11 +162,11 @@
; TODO: replace to ccs/take when it gets fixed
proposed-title (apply str (take max-length title-uncut))
date [year month day]
title (first (drop-while #(note-exists? (build-key date %))
title (first (drop-while #(note-exists? (api/build-key date %))
(cons proposed-title
(map #(str proposed-title "-" (+ 2 %)) (range)))))]
(do
(add-note (build-key date title) draft password)
(add-note (api/build-key date title) draft password)
(redirect (url year month day title))))
(response 400))))
@@ -178,4 +179,8 @@
long-url (if (empty? rest-params) core-url (util/url core-url rest-params))]
(redirect long-url))))
; Here lives the API
(defpage "/api" args
(let [title (get-message :api-registration)]
(layout title [:article.markdown (slurp "API.md")])))