From bf29feb3218366e1fb7320ef0c1db9077805c9a7 Mon Sep 17 00:00:00 2001 From: Manuel Knitza Date: Sun, 17 Mar 2013 23:44:54 +0100 Subject: [PATCH] A nicer way to handle the API versions Instead of manually copy/pasting the API version functions every time we version bump, we should reuse the content of a previous API version. --- src/node/handler/APIHandler.js | 182 +++++++-------------------------- 1 file changed, 35 insertions(+), 147 deletions(-) diff --git a/src/node/handler/APIHandler.js b/src/node/handler/APIHandler.js index 4b7dd9517..d9ad73e16 100644 --- a/src/node/handler/APIHandler.js +++ b/src/node/handler/APIHandler.js @@ -38,8 +38,7 @@ catch(e) } //a list of all functions -var version = -{ "1": +var API_V1 = { "createGroup" : [] , "createGroupIfNotExistsFor" : ["groupMapper"] , "deleteGroup" : ["groupID"] @@ -67,154 +66,43 @@ var version = , "setPassword" : ["padID", "password"] , "isPasswordProtected" : ["padID"] , "listAuthorsOfPad" : ["padID"] - , "padUsersCount" : ["padID"] - } -, "1.1": - { "createGroup" : [] - , "createGroupIfNotExistsFor" : ["groupMapper"] - , "deleteGroup" : ["groupID"] - , "listPads" : ["groupID"] - , "createPad" : ["padID", "text"] - , "createGroupPad" : ["groupID", "padName", "text"] - , "createAuthor" : ["name"] - , "createAuthorIfNotExistsFor": ["authorMapper" , "name"] - , "listPadsOfAuthor" : ["authorID"] - , "createSession" : ["groupID", "authorID", "validUntil"] - , "deleteSession" : ["sessionID"] - , "getSessionInfo" : ["sessionID"] - , "listSessionsOfGroup" : ["groupID"] - , "listSessionsOfAuthor" : ["authorID"] - , "getText" : ["padID", "rev"] - , "setText" : ["padID", "text"] - , "getHTML" : ["padID", "rev"] - , "setHTML" : ["padID", "html"] - , "getRevisionsCount" : ["padID"] - , "getLastEdited" : ["padID"] - , "deletePad" : ["padID"] - , "getReadOnlyID" : ["padID"] - , "setPublicStatus" : ["padID", "publicStatus"] - , "getPublicStatus" : ["padID"] - , "setPassword" : ["padID", "password"] - , "isPasswordProtected" : ["padID"] - , "listAuthorsOfPad" : ["padID"] - , "padUsersCount" : ["padID"] - , "getAuthorName" : ["authorID"] - , "padUsers" : ["padID"] + , "padUsersCount" : ["padID"] }; + +var API_V1_1 = + { "getAuthorName" : ["authorID"] + , "padUsers" : ["padID"] , "sendClientsMessage" : ["padID", "msg"] - , "listAllGroups" : [] - } -, "1.2": - { "createGroup" : [] - , "createGroupIfNotExistsFor" : ["groupMapper"] - , "deleteGroup" : ["groupID"] - , "listPads" : ["groupID"] - , "createPad" : ["padID", "text"] - , "createGroupPad" : ["groupID", "padName", "text"] - , "createAuthor" : ["name"] - , "createAuthorIfNotExistsFor": ["authorMapper" , "name"] - , "listPadsOfAuthor" : ["authorID"] - , "createSession" : ["groupID", "authorID", "validUntil"] - , "deleteSession" : ["sessionID"] - , "getSessionInfo" : ["sessionID"] - , "listSessionsOfGroup" : ["groupID"] - , "listSessionsOfAuthor" : ["authorID"] - , "getText" : ["padID", "rev"] - , "setText" : ["padID", "text"] - , "getHTML" : ["padID", "rev"] - , "setHTML" : ["padID", "html"] - , "getRevisionsCount" : ["padID"] - , "getLastEdited" : ["padID"] - , "deletePad" : ["padID"] - , "getReadOnlyID" : ["padID"] - , "setPublicStatus" : ["padID", "publicStatus"] - , "getPublicStatus" : ["padID"] - , "setPassword" : ["padID", "password"] - , "isPasswordProtected" : ["padID"] - , "listAuthorsOfPad" : ["padID"] - , "padUsersCount" : ["padID"] - , "getAuthorName" : ["authorID"] - , "padUsers" : ["padID"] - , "sendClientsMessage" : ["padID", "msg"] - , "listAllGroups" : [] - , "checkToken" : [] - } -, "1.2.1": - { "createGroup" : [] - , "createGroupIfNotExistsFor" : ["groupMapper"] - , "deleteGroup" : ["groupID"] - , "listPads" : ["groupID"] - , "listAllPads" : [] - , "createPad" : ["padID", "text"] - , "createGroupPad" : ["groupID", "padName", "text"] - , "createAuthor" : ["name"] - , "createAuthorIfNotExistsFor": ["authorMapper" , "name"] - , "listPadsOfAuthor" : ["authorID"] - , "createSession" : ["groupID", "authorID", "validUntil"] - , "deleteSession" : ["sessionID"] - , "getSessionInfo" : ["sessionID"] - , "listSessionsOfGroup" : ["groupID"] - , "listSessionsOfAuthor" : ["authorID"] - , "getText" : ["padID", "rev"] - , "setText" : ["padID", "text"] - , "getHTML" : ["padID", "rev"] - , "setHTML" : ["padID", "html"] - , "getRevisionsCount" : ["padID"] - , "getLastEdited" : ["padID"] - , "deletePad" : ["padID"] - , "getReadOnlyID" : ["padID"] - , "setPublicStatus" : ["padID", "publicStatus"] - , "getPublicStatus" : ["padID"] - , "setPassword" : ["padID", "password"] - , "isPasswordProtected" : ["padID"] - , "listAuthorsOfPad" : ["padID"] - , "padUsersCount" : ["padID"] - , "getAuthorName" : ["authorID"] - , "padUsers" : ["padID"] - , "sendClientsMessage" : ["padID", "msg"] - , "listAllGroups" : [] - , "checkToken" : [] - } -, "1.2.7": - { "createGroup" : [] - , "createGroupIfNotExistsFor" : ["groupMapper"] - , "deleteGroup" : ["groupID"] - , "listPads" : ["groupID"] - , "listAllPads" : [] - , "createDiffHTML" : ["padID", "startRev", "endRev"] - , "createPad" : ["padID", "text"] - , "createGroupPad" : ["groupID", "padName", "text"] - , "createAuthor" : ["name"] - , "createAuthorIfNotExistsFor": ["authorMapper" , "name"] - , "listPadsOfAuthor" : ["authorID"] - , "createSession" : ["groupID", "authorID", "validUntil"] - , "deleteSession" : ["sessionID"] - , "getSessionInfo" : ["sessionID"] - , "listSessionsOfGroup" : ["groupID"] - , "listSessionsOfAuthor" : ["authorID"] - , "getText" : ["padID", "rev"] - , "setText" : ["padID", "text"] - , "getHTML" : ["padID", "rev"] - , "setHTML" : ["padID", "html"] - , "getRevisionsCount" : ["padID"] - , "getLastEdited" : ["padID"] - , "deletePad" : ["padID"] - , "getReadOnlyID" : ["padID"] - , "setPublicStatus" : ["padID", "publicStatus"] - , "getPublicStatus" : ["padID"] - , "setPassword" : ["padID", "password"] - , "isPasswordProtected" : ["padID"] - , "listAuthorsOfPad" : ["padID"] - , "padUsersCount" : ["padID"] - , "getAuthorName" : ["authorID"] - , "padUsers" : ["padID"] - , "sendClientsMessage" : ["padID", "msg"] - , "listAllGroups" : [] - , "checkToken" : [] + , "listAllGroups" : [] }; + +var API_V1_2 = + { "checkToken" : [] }; + +var API_V1_2_1 = + { "listAllPads" : [] }; + +var API_V1_2_7 = + { "createDiffHTML" : ["padID", "startRev", "endRev"] , "getChatHistory" : ["padID"] , "getChatHistory" : ["padID", "start", "end"] - , "getChatHead" : ["padID"] - } -}; + , "getChatHead" : ["padID"] }; + +function apiConcat(v1, v2) { + for (var key in v1) { + v2[key] = v1[key]; + } + return v2; +} + +API_V1_1 = apiConcat(API_V1, API_V1_1) ; +API_V1_2 = apiConcat(API_V1_1, API_V1_2) ; +API_V1_2_1 = apiConcat(API_V1_2, API_V1_2_1) ; +API_V1_2_7 = apiConcat(API_V1_2_1, API_V1_2_7) ; + +var version = { "1" : API_V1 + , "1.1" : API_V1_1 + , "1.2" : API_V1_2 + , "1.2.1" : API_V1_2_1 + , "1.2.7" : API_V1_2_7 }; // set the latest available API version here exports.latestApiVersion = '1.2.7';