2014-01-02 03:04:48 +00:00
# ##
- - - - - - - - - - / api / v2 API - - - - - - - - - - - -
see https : / / github . com / wordnik / swagger - node - express
Every url added to router is prefaced by / api / v2
Note: Many user - route ops exist in habitrpg - shard / script / index . coffee #user.ops, so that they can (1) be called both
client and server .
v1 user . Requires x - api - user ( user id ) and x - api - key ( api key ) headers , Test with:
$ mocha test / user . mocha . coffee
# ##
user = require ( " ../controllers/user " )
groups = require ( " ../controllers/groups " )
2014-11-27 10:32:57 +00:00
members = require ( " ../controllers/members " )
2014-01-02 03:04:48 +00:00
auth = require ( " ../controllers/auth " )
2014-01-06 01:03:47 +00:00
hall = require ( " ../controllers/hall " )
2014-01-02 03:04:48 +00:00
challenges = require ( " ../controllers/challenges " )
dataexport = require ( " ../controllers/dataexport " )
nconf = require ( " nconf " )
middleware = require ( " ../middleware " )
cron = user . cron
_ = require ( ' lodash ' )
content = require ( ' habitrpg-shared ' ) . content
2014-03-10 16:28:49 +00:00
i18n = require ( ' ../i18n ' )
2014-01-02 03:04:48 +00:00
2014-01-02 03:34:31 +00:00
module.exports = (swagger, v2) ->
2014-01-02 03:04:48 +00:00
[ path , body , query ] = [ swagger . pathParam , swagger . bodyParam , swagger . queryParam ]
2014-01-02 03:34:31 +00:00
swagger . setAppHandler ( v2 )
swagger . setErrorHandler ( " next " )
swagger.setHeaders = -> #disable setHeaders, since we have our own thing going on in middleware.js (and which requires `req`, which swagger doesn't pass in)
2014-01-02 03:04:48 +00:00
swagger . configureSwaggerPaths ( " " , " /api-docs " , " " )
api =
' /status ' :
spec:
description: " Returns the status of the server (up or down) "
action: (req, res) ->
res . json status: " up "
' /content ' :
spec:
description: " Get all available content objects. This is essential, since Habit often depends on item keys (eg, when purchasing a weapon). "
2014-05-15 21:15:57 +00:00
parameters: [
query ( " language " , " Optional language to use for content ' s strings. Default is english. " , " string " )
]
2014-01-02 03:04:48 +00:00
action: user . getContent
2014-07-17 20:09:39 +00:00
' /content/paths ' :
spec:
description: " Show user model tree "
action: user . getModelPaths
2014-01-02 03:04:48 +00:00
" /export/history " :
spec:
description: " Export user history "
method: ' GET '
2014-03-10 16:28:49 +00:00
middleware: [ auth . auth , i18n . getUserLanguage ]
2014-01-02 03:04:48 +00:00
action: dataexport . history #[todo] encode data output options in the data controller and use these to build routes
# ---------------------------------
# User
# ---------------------------------
# Scoring
" /user/tasks/{id}/{direction} " :
spec:
2014-01-02 04:38:35 +00:00
#notes: "Simple scoring of a task."
2014-07-06 13:01:46 +00:00
description: " Simple scoring of a task. This is most-likely the only API route you ' ll be using as a 3rd-party developer. The most common operation is for the user to gain or lose points based on some action (browsing Reddit, running a mile, 1 Pomodor, etc). Call this route, if the task you ' re trying to score doesn ' t exist, it will be created for you. When random events occur, the <b>user._tmp</b> variable will be filled. Critical hits can be accessed through <b>user._tmp.crit</b>. The Streakbonus can be accessed through <b>user._tmp.streakBonus</b>. Both will contain the multiplier value. When random drops occur, the following values are available: <b>user._tmp.drop = {text,type,dialog,value,key,notes}</b> "
2014-01-02 03:34:31 +00:00
parameters: [
2014-01-02 03:04:48 +00:00
path ( " id " , " ID of the task to score. If this task doesn ' t exist, a task will be created automatically " , " string " )
path ( " direction " , " Either ' up ' or ' down ' " , " string " )
2014-01-02 04:38:35 +00:00
body ' ' , " If you ' re creating a 3rd-party task, pass up any task attributes in the body (see TaskSchema). " , ' object '
2014-01-02 03:04:48 +00:00
]
method: ' POST '
action: user . score
# Tasks
2014-01-02 23:42:46 +00:00
" /user/tasks:GET " :
2014-01-02 03:04:48 +00:00
spec:
2014-01-02 23:42:46 +00:00
path: ' /user/tasks '
2014-01-02 03:04:48 +00:00
description: " Get all user ' s tasks "
action: user . getTasks
2014-01-02 23:42:46 +00:00
" /user/tasks:POST " :
2014-01-02 03:04:48 +00:00
spec:
2014-01-02 23:42:46 +00:00
path: ' /user/tasks '
description: " Create a task "
method: ' POST '
parameters: [ body " " , " Send up the whole task (see TaskSchema) " , " object " ]
action: user . addTask
" /user/tasks/{id}:GET " :
spec:
path: ' /user/tasks/{id} '
2014-01-02 03:04:48 +00:00
description: " Get an individual task "
2014-01-02 03:34:31 +00:00
parameters: [
2014-01-02 03:04:48 +00:00
path ( " id " , " Task ID " , " string " )
]
action: user . getTask
2014-01-02 23:42:46 +00:00
" /user/tasks/{id}:PUT " :
2014-01-02 03:04:48 +00:00
spec:
2014-01-02 23:42:46 +00:00
path: ' /user/tasks/{id} '
2014-01-02 03:04:48 +00:00
description: " Update a user ' s task "
method: ' PUT '
2014-01-02 03:34:31 +00:00
parameters: [
2014-01-02 04:38:35 +00:00
path " id " , " Task ID " , " string "
body " " , " Send up the whole task (see TaskSchema) " , " object "
2014-01-02 03:04:48 +00:00
]
action: user . updateTask
2014-01-02 23:42:46 +00:00
" /user/tasks/{id}:DELETE " :
2014-01-02 03:04:48 +00:00
spec:
2014-01-02 23:42:46 +00:00
path: ' /user/tasks/{id} '
2014-01-02 03:04:48 +00:00
description: " Delete a task "
method: ' DELETE '
2014-01-02 03:34:31 +00:00
parameters: [ path ( " id " , " Task ID " , " string " ) ]
2014-01-02 03:04:48 +00:00
action: user . deleteTask
" /user/tasks/{id}/sort " :
spec:
method: ' POST '
description: ' Sort tasks '
2014-01-02 03:34:31 +00:00
parameters: [
2014-01-02 03:04:48 +00:00
path ( " id " , " Task ID " , " string " )
query ( " from " , " Index where you ' re sorting from (0-based) " , " integer " )
query ( " to " , " Index where you ' re sorting to (0-based) " , " integer " )
]
action: user . sortTask
2014-08-10 03:54:10 +00:00
2014-01-02 03:04:48 +00:00
" /user/tasks/clear-completed " :
spec:
method: ' POST '
2014-01-02 04:38:35 +00:00
description: " Clears competed To-Dos (needed periodically for performance). "
2014-01-02 03:04:48 +00:00
action: user . clearCompleted
" /user/tasks/{id}/unlink " :
spec:
method: ' POST '
description: ' Unlink a task from its challenge '
2014-01-02 04:38:35 +00:00
parameters: [
path ( " id " , " Task ID " , " string " )
query ' keep ' , " When unlinking a challenge task, how to handle the orphans? " , ' string ' , [ ' keep ' , ' keep-all ' , ' remove ' , ' remove-all ' ]
]
2014-03-10 16:28:49 +00:00
middleware: [ auth . auth , i18n . getUserLanguage ] ## removing cron since they may want to remove task first
2014-01-02 03:04:48 +00:00
action: challenges . unlink
# Inventory
2014-08-25 16:23:04 +00:00
" /user/inventory/buy " :
spec:
description: " Get a list of buyable gear "
action: user . getBuyList
2014-01-02 03:04:48 +00:00
" /user/inventory/buy/{key} " :
spec:
method: ' POST '
description: " Buy a gear piece and equip it automatically "
2014-01-02 03:34:31 +00:00
parameters : [
2014-01-02 03:04:48 +00:00
path ' key ' , " The key of the item to buy (call /content route for available keys) " , ' string ' , _ . keys ( content . gear . flat )
]
action: user . buy
" /user/inventory/sell/{type}/{key} " :
spec:
method: ' POST '
description: " Sell inventory items back to Alexander "
2014-01-02 03:34:31 +00:00
parameters: [
2014-01-02 03:04:48 +00:00
#TODO verify these are the correct types
2014-07-03 16:51:40 +00:00
path ( ' type ' , " The type of object you ' re selling back. " , ' string ' , [ ' eggs ' , ' hatchingPotions ' , ' food ' ] )
2014-01-02 03:04:48 +00:00
path ( ' key ' , " The object key you ' re selling back (call /content route for available keys) " , ' string ' )
]
action: user . sell
" /user/inventory/purchase/{type}/{key} " :
spec:
method: ' POST '
description: " Purchase a gem-purchaseable item from Alexander "
2014-01-02 03:34:31 +00:00
parameters : [
2014-07-03 16:51:40 +00:00
path ( ' type ' , " The type of object you ' re purchasing. " , ' string ' , [ ' eggs ' , ' hatchingPotions ' , ' food ' , ' quests ' , ' special ' ] )
2014-01-02 03:04:48 +00:00
path ( ' key ' , " The object key you ' re purchasing (call /content route for available keys) " , ' string ' )
]
action: user . purchase
" /user/inventory/feed/{pet}/{food} " :
spec:
method: ' POST '
description: " Feed your pet some food "
2014-01-02 03:34:31 +00:00
parameters: [
2014-01-02 04:38:35 +00:00
path ' pet ' , " The key of the pet you ' re feeding " , ' string ' , _ . keys ( content . pets )
2014-01-02 03:04:48 +00:00
path ' food ' , " The key of the food to feed your pet " , ' string ' , _ . keys ( content . food )
]
action: user . feed
" /user/inventory/equip/{type}/{key} " :
spec:
method: ' POST '
2014-07-03 16:51:40 +00:00
description: " Equip an item (either pet, mount, equipped or costume) "
2014-01-02 03:34:31 +00:00
parameters: [
2014-05-27 21:54:58 +00:00
path ' type ' , " Type to equip " , ' string ' , [ ' pet ' , ' mount ' , ' equipped ' , ' costume ' ]
2014-01-02 03:04:48 +00:00
path ' key ' , " The object key you ' re equipping (call /content route for available keys) " , ' string '
]
action: user . equip
" /user/inventory/hatch/{egg}/{hatchingPotion} " :
spec:
method: ' POST '
description: " Pour a hatching potion on an egg "
2014-01-02 03:34:31 +00:00
parameters: [
2014-01-02 03:04:48 +00:00
path ' egg ' , " The egg key to hatch " , ' string ' , _ . keys ( content . eggs )
path ' hatchingPotion ' , " The hatching potion to pour " , ' string ' , _ . keys ( content . hatchingPotions )
]
action: user . hatch
# User
" /user:GET " :
spec:
path: ' /user '
description: " Get the full user object "
action: user . getUser
" /user:PUT " :
spec:
path: ' /user '
method: ' PUT '
description: " Update the user object (only certain attributes are supported) "
2014-01-02 03:34:31 +00:00
parameters: [
2014-01-02 04:38:35 +00:00
body ' ' , ' The user object (see UserSchema) ' , ' object '
2014-01-02 03:04:48 +00:00
]
action: user . update
" /user:DELETE " :
spec:
path: ' /user '
method: ' DELETE '
description: " Delete a user object entirely, USE WITH CAUTION! "
2014-03-10 16:28:49 +00:00
middleware: [ auth . auth , i18n . getUserLanguage ]
2014-01-02 03:04:48 +00:00
action: user [ " delete " ]
" /user/revive " :
spec:
method: ' POST '
description: " Revive your dead user "
action: user . revive
" /user/reroll " :
spec:
method: ' POST '
description: ' Drink the Fortify Potion (Note, it used to be called re-roll) '
action: user . reroll
" /user/reset " :
spec:
method: ' POST '
description: " Completely reset your account "
action: user . reset
" /user/sleep " :
spec:
method: ' POST '
description: " Toggle whether you ' re resting in the inn "
action: user . sleep
" /user/rebirth " :
spec:
method: ' POST '
description: " Rebirth your avatar "
action: user . rebirth
" /user/class/change " :
spec:
method: ' POST '
description: " Either remove your avatar ' s class, or change it to something new "
2014-01-02 03:34:31 +00:00
parameters: [
2014-01-02 03:04:48 +00:00
query ' class ' , " The key of the class to change to. If not provided, user ' s class is removed. " , ' string ' , [ ' warrior ' , ' healer ' , ' rogue ' , ' wizard ' , ' ' ]
]
action: user . changeClass
" /user/class/allocate " :
spec:
method: ' POST '
description: " Allocate one point towards an attribute "
2014-01-02 03:34:31 +00:00
parameters: [
2014-01-02 04:38:35 +00:00
query ' stat ' , ' The stat to allocate towards ' , ' string ' , [ ' str ' , ' per ' , ' int ' , ' con ' ]
2014-01-02 03:04:48 +00:00
]
action : user . allocate
" /user/class/cast/{spell} " :
spec:
method: ' POST '
2014-01-02 04:38:35 +00:00
description: " Casts a spell on a target. "
2014-01-08 03:23:22 +00:00
parameters: [
2014-01-02 04:38:35 +00:00
path ' spell ' , " The key of the spell to cast (see habitrpg-shared # content.coffee) " , ' string '
query ' targetType ' , " The type of object you ' re targeting " , ' string ' , [ ' party ' , ' self ' , ' user ' , ' task ' ]
query ' targetId ' , " The ID of the object you ' re targeting " , ' string '
]
2014-01-02 03:04:48 +00:00
action: user . cast
" /user/unlock " :
spec:
method: ' POST '
description: " Unlock a certain gem-purchaseable path (or multiple paths) "
2014-01-02 03:34:31 +00:00
parameters: [
2014-01-02 03:04:48 +00:00
query ' path ' , " The path to unlock, such as hair.green or shirts.red,shirts.blue " , ' string '
]
action: user . unlock
" /user/batch-update " :
spec:
method: ' POST '
2014-01-02 03:34:31 +00:00
description: " This is an advanced route which is useful for apps which might for example need offline support. You can send a whole batch of user-based operations, which allows you to queue them up offline and send them all at once. The format is {op: ' nameOfOperation ' ,parameters:{},body:{},query:{}} "
parameters : [
2014-01-02 03:04:48 +00:00
body ' ' , ' The array of batch-operations to perform ' , ' object '
]
2014-11-27 10:32:57 +00:00
middleware: [ middleware . forceRefresh , auth . auth , i18n . getUserLanguage , cron , user . sessionPartyInvite ]
2014-01-02 03:04:48 +00:00
action: user . batchUpdate
# Tags
" /user/tags " :
spec:
method: ' POST '
description: ' Create a new tag '
2014-01-02 03:34:31 +00:00
parameters: [
2014-01-02 04:38:35 +00:00
body ' ' , ' New tag (see UserSchema.tags) ' , ' object '
2014-01-02 03:04:48 +00:00
]
action: user . addTag
2014-08-10 03:54:10 +00:00
" /user/tags/sort " :
spec:
method: ' POST '
description: ' Sort tags '
parameters: [
query ( " from " , " Index where you ' re sorting from (0-based) " , " integer " )
query ( " to " , " Index where you ' re sorting to (0-based) " , " integer " )
]
action: user . sortTag
2014-01-02 03:04:48 +00:00
" /user/tags/{id}:PUT " :
spec:
2014-01-02 06:05:42 +00:00
path: ' /user/tags/{id} '
2014-01-02 03:04:48 +00:00
method: ' PUT '
description: " Edit a tag "
2014-01-02 03:34:31 +00:00
parameters: [
2014-01-02 03:04:48 +00:00
path ' id ' , ' The id of the tag to edit ' , ' string '
2014-01-02 04:38:35 +00:00
body ' ' , ' Tag edits (see UserSchema.tags) ' , ' object '
2014-01-02 03:04:48 +00:00
]
action: user . updateTag
" /user/tags/{id}:DELETE " :
spec:
2014-01-02 06:05:42 +00:00
path: ' /user/tags/{id} '
2014-01-02 03:04:48 +00:00
method: ' DELETE '
description: ' Delete a tag '
2014-01-02 03:34:31 +00:00
parameters: [
2014-01-02 03:04:48 +00:00
path ' id ' , ' Id of tag to delete ' , ' string '
]
action: user . deleteTag
2014-11-27 10:32:57 +00:00
" /user/social/invite-friends " :
spec:
method: ' POST '
description: ' Invite friends via email '
parameters: [
body ' invites ' , ' Array of [{name: " Friend \' s Name " , email: " friends@email.com " }] to invite to play in your party ' , ' object '
]
action: user . inviteFriends
# Webhooks
" /user/webhooks " :
spec:
method: ' POST '
description: ' Create a new webhook '
parameters: [
body ' ' , ' New Webhook {url: " webhook endpoint (required) " , id: " id of webhook (shared.uuid(), optional) " , enabled: " whether webhook is enabled (true by default, optional) " } ' , ' object '
]
action: user . addWebhook
" /user/webhooks/{id}:PUT " :
spec:
path: ' /user/webhooks/{id} '
method: ' PUT '
description: " Edit a webhook "
parameters: [
path ' id ' , ' The id of the webhook to edit ' , ' string '
body ' ' , ' New Webhook {url: " webhook endpoint (required) " , id: " id of webhook (shared.uuid(), optional) " , enabled: " whether webhook is enabled (true by default, optional) " } ' , ' object '
]
action: user . updateWebhook
" /user/webhooks/{id}:DELETE " :
spec:
path: ' /user/webhooks/{id} '
method: ' DELETE '
description: ' Delete a webhook '
parameters: [
path ' id ' , ' Id of webhook to delete ' , ' string '
]
action: user . deleteWebhook
2014-01-02 03:04:48 +00:00
# ---------------------------------
# Groups
# ---------------------------------
" /groups:GET " :
2014-01-02 04:38:35 +00:00
spec:
path: ' /groups '
description: " Get a list of groups "
2014-01-08 03:23:22 +00:00
parameters: [
2014-01-02 04:38:35 +00:00
query ' type ' , " Comma-separated types of groups to return, eg ' party,guilds,public,tavern ' " , ' string '
]
2014-03-10 16:28:49 +00:00
middleware: [ auth . auth , i18n . getUserLanguage ]
2014-01-02 03:04:48 +00:00
action: groups . list
2014-01-02 04:38:35 +00:00
2014-01-02 03:04:48 +00:00
" /groups:POST " :
2014-01-02 04:38:35 +00:00
spec:
2014-01-02 23:42:46 +00:00
path: ' /groups '
method: ' POST '
2014-01-02 04:38:35 +00:00
description: ' Create a group '
2014-01-08 03:23:22 +00:00
parameters: [
2014-01-02 04:38:35 +00:00
body ' ' , ' Group object (see GroupSchema) ' , ' object '
]
2014-03-10 16:28:49 +00:00
middleware: [ auth . auth , i18n . getUserLanguage ]
2014-01-02 03:04:48 +00:00
action: groups . create
" /groups/{gid}:GET " :
2014-01-02 04:38:35 +00:00
spec:
path: ' /groups/{gid} '
2014-07-03 16:51:40 +00:00
description: " Get a group. The party the user currently is in can be accessed with the gid ' party ' . "
2014-01-08 03:23:22 +00:00
parameters: [ path ( ' gid ' , ' Group ID ' , ' string ' ) ]
2014-03-10 16:28:49 +00:00
middleware: [ auth . auth , i18n . getUserLanguage ]
2014-01-02 03:04:48 +00:00
action: groups . get
2014-01-02 23:42:46 +00:00
" /groups/{gid}:POST " :
2014-01-02 04:38:35 +00:00
spec:
2014-01-02 05:40:27 +00:00
path: ' /groups/{gid} '
method: ' POST '
2014-01-02 04:38:35 +00:00
description: " Edit a group "
2014-01-08 03:23:22 +00:00
parameters: [ body ( ' ' , ' Group object (see GroupSchema) ' , ' object ' ) ]
2014-03-10 16:28:49 +00:00
middleware: [ auth . auth , i18n . getUserLanguage , groups . attachGroup ]
2014-01-02 03:04:48 +00:00
action: groups . update
" /groups/{gid}/join " :
2014-01-02 04:38:35 +00:00
spec:
method: ' POST '
description: ' Join a group '
2014-01-08 03:23:22 +00:00
parameters: [ path ( ' gid ' , ' Id of the group to join ' , ' string ' ) ]
2014-03-10 16:28:49 +00:00
middleware: [ auth . auth , i18n . getUserLanguage , groups . attachGroup ]
2014-01-02 03:04:48 +00:00
action: groups . join
" /groups/{gid}/leave " :
2014-01-02 04:38:35 +00:00
spec:
method: ' POST '
description: ' Leave a group '
2014-01-08 04:15:19 +00:00
parameters: [ path ( ' gid ' , ' ID of the group to leave ' , ' string ' ) ]
2014-03-10 16:28:49 +00:00
middleware: [ auth . auth , i18n . getUserLanguage , groups . attachGroup ]
2014-01-02 03:04:48 +00:00
action: groups . leave
" /groups/{gid}/invite " :
2014-01-02 04:38:35 +00:00
spec:
method: ' POST '
description: " Invite a user to a group "
2014-01-08 03:23:22 +00:00
parameters: [
2014-01-02 04:38:35 +00:00
path ' gid ' , ' Group id ' , ' string '
query ' uuid ' , ' User id to invite ' , ' string '
]
2014-03-10 16:28:49 +00:00
middleware: [ auth . auth , i18n . getUserLanguage , groups . attachGroup ]
2014-01-02 03:04:48 +00:00
action : groups . invite
" /groups/{gid}/removeMember " :
2014-01-02 04:38:35 +00:00
spec:
method: ' POST '
description: " Remove / boot a member from a group "
2014-01-08 03:23:22 +00:00
parameters: [
2014-01-02 04:38:35 +00:00
path ' gid ' , ' Group id ' , ' string '
query ' uuid ' , ' User id to boot ' , ' string '
]
2014-03-10 16:28:49 +00:00
middleware: [ auth . auth , i18n . getUserLanguage , groups . attachGroup ]
2014-01-02 03:04:48 +00:00
action : groups . removeMember
" /groups/{gid}/questAccept " :
spec:
method: ' POST '
2014-01-02 04:38:35 +00:00
description: " Accept a quest invitation "
2014-01-02 03:34:31 +00:00
parameters: [
2014-01-02 04:38:35 +00:00
path ' gid ' , " Group id " , ' string '
2014-01-02 03:04:48 +00:00
query ' key ' , " optional. if provided, trigger new invite, if not, accept existing invite " , ' string '
]
2014-03-10 16:28:49 +00:00
middleware: [ auth . auth , i18n . getUserLanguage , groups . attachGroup ]
2014-01-02 03:04:48 +00:00
action : groups . questAccept
" /groups/{gid}/questReject " :
2014-01-02 04:38:35 +00:00
spec:
method: ' POST '
description: ' Reject quest invitation '
2014-01-08 03:23:22 +00:00
parameters: [
2014-01-02 04:38:35 +00:00
path ' gid ' , ' Group id ' , ' string '
]
2014-03-10 16:28:49 +00:00
middleware: [ auth . auth , i18n . getUserLanguage , groups . attachGroup ]
2014-01-02 03:04:48 +00:00
action: groups . questReject
2014-09-08 08:46:11 +00:00
" /groups/{gid}/questCancel " :
spec:
method: ' POST '
description: ' Cancel quest before it starts (in invitation stage) '
parameters: [ path ( ' gid ' , ' Group to cancel quest in ' , ' string ' ) ]
middleware: [ auth . auth , i18n . getUserLanguage , groups . attachGroup ]
action: groups . questCancel
2014-01-02 03:04:48 +00:00
" /groups/{gid}/questAbort " :
2014-01-02 04:38:35 +00:00
spec:
method: ' POST '
2014-09-08 08:46:11 +00:00
description: ' Abort quest after it has started (all progress will be lost) '
2014-01-08 03:23:22 +00:00
parameters: [ path ( ' gid ' , ' Group to abort quest in ' , ' string ' ) ]
2014-03-10 16:28:49 +00:00
middleware: [ auth . auth , i18n . getUserLanguage , groups . attachGroup ]
2014-01-02 03:04:48 +00:00
action: groups . questAbort
#TODO PUT /groups/:gid/chat/:messageId
2014-01-14 16:21:51 +00:00
" /groups/{gid}/chat:GET " :
spec:
path: " /groups/{gid}/chat "
description: " Get all chat messages "
2014-04-11 04:31:24 +00:00
parameters: [ path ( ' gid ' , ' Group to return the chat from ' , ' string ' ) ]
2014-03-10 16:28:49 +00:00
middleware: [ auth . auth , i18n . getUserLanguage , groups . attachGroup ]
2014-01-14 16:21:51 +00:00
action: groups . getChat
" /groups/{gid}/chat:POST " :
2014-01-02 04:38:35 +00:00
spec:
method: ' POST '
2014-01-14 16:21:51 +00:00
path: " /groups/{gid}/chat "
2014-01-02 04:38:35 +00:00
description: " Send a chat message "
2014-01-08 03:23:22 +00:00
parameters: [
2014-01-02 04:38:35 +00:00
query ' message ' , ' Chat message ' , ' string '
path ' gid ' , ' Group id ' , ' string '
]
2014-03-10 16:28:49 +00:00
middleware: [ auth . auth , i18n . getUserLanguage , groups . attachGroup ]
2014-01-02 03:04:48 +00:00
action: groups . postChat
2014-02-13 04:20:42 +00:00
# placing before route below, so that if !=='seen' it goes to next()
" /groups/{gid}/chat/seen " :
spec:
method: ' POST '
description: " Flag chat messages for a particular group as seen "
parameters: [
path ' gid ' , ' Group id ' , ' string '
]
action: groups . seenMessage
2014-01-02 03:04:48 +00:00
" /groups/{gid}/chat/{messageId} " :
2014-01-02 04:38:35 +00:00
spec:
method: ' DELETE '
2014-07-03 16:44:56 +00:00
description: ' Delete a chat message in a given group '
parameters: [
path ' gid ' , ' ID of the group containing the message to be deleted ' , ' string '
path ' messageId ' , ' ID of message to be deleted ' , ' string '
]
2014-03-10 16:28:49 +00:00
middleware: [ auth . auth , i18n . getUserLanguage , groups . attachGroup ]
2014-01-02 03:04:48 +00:00
action: groups . deleteChatMessage
2014-01-06 05:10:34 +00:00
" /groups/{gid}/chat/{mid}/like " :
spec:
method: ' POST '
description: " Like a chat message "
2014-01-08 03:23:22 +00:00
parameters: [
2014-01-06 05:10:34 +00:00
path ' gid ' , ' Group id ' , ' string '
path ' mid ' , ' Message id ' , ' string '
]
2014-03-10 16:28:49 +00:00
middleware: [ auth . auth , i18n . getUserLanguage , groups . attachGroup ]
2014-01-06 05:10:34 +00:00
action: groups . likeChatMessage
2014-12-07 13:35:09 +00:00
" /groups/{gid}/chat/{mid}/flag " :
spec:
method: ' POST '
description: " Flag a chat message "
parameters: [
path ' gid ' , ' Group id ' , ' string '
path ' mid ' , ' Message id ' , ' string '
]
middleware: [ auth . auth , i18n . getUserLanguage , groups . attachGroup ]
action: groups . flagChatMessage
2014-12-11 23:29:01 +00:00
" /groups/{gid}/chat/{mid}/clearflags " :
spec:
method: ' POST '
description: " Clear flag count from message and unhide it "
parameters: [
path ' gid ' , ' Group id ' , ' string '
path ' mid ' , ' Message id ' , ' string '
]
middleware: [ auth . auth , i18n . getUserLanguage , groups . attachGroup ]
action: groups . clearFlagCount
2014-01-02 03:04:48 +00:00
# ---------------------------------
# Members
# ---------------------------------
2014-12-19 16:43:15 +00:00
" /members/{uuid}:GET " :
spec:
path: ' /members/{uuid} '
description: " Get a member. "
parameters: [ path ( ' uuid ' , ' Member ID ' , ' string ' ) ]
middleware: [ auth . auth , i18n . getUserLanguage ]
2014-11-27 10:32:57 +00:00
action: members . getMember
" /members/{uuid}/message " :
spec:
method: ' POST '
description: ' Send a private message to a member '
parameters: [
path ' uuid ' , ' The UUID of the member to message ' , ' string '
2014-12-19 16:44:55 +00:00
body ' ' , ' { " message " : " The private message to send " } ' , ' object '
2014-11-27 10:32:57 +00:00
]
middleware: [ auth . auth ]
action: members . sendPrivateMessage
" /members/{uuid}/block " :
spec:
method: ' POST '
description: ' Block a member from sending private messages '
parameters: [
path ' uuid ' , ' The UUID of the member to message ' , ' string '
]
middleware: [ auth . auth ]
action: user . blockUser
2014-11-25 21:53:52 +00:00
" /members/{uuid}/gift " :
spec:
method: ' POST '
description: ' Send a gift to a member '
parameters: [
path ' uuid ' , ' The UUID of the member ' , ' string '
2014-12-19 17:05:24 +00:00
body ' ' , ' { " type " : " gems or subscription " , " gems " :{ " amount " :Number, " fromBalance " :Boolean}, " subscription " :{ " months " :Number}} ' , ' object '
2014-11-25 21:53:52 +00:00
]
middleware: [ auth . auth ]
action: members . sendGift
2014-01-02 03:04:48 +00:00
# ---------------------------------
2014-01-06 01:03:47 +00:00
# Hall of Heroes / Patrons
2014-01-02 03:04:48 +00:00
# ---------------------------------
2014-01-06 01:03:47 +00:00
" /hall/heroes " :
2014-01-02 03:04:48 +00:00
spec: { }
2014-03-10 16:28:49 +00:00
middleware : [ auth . auth , i18n . getUserLanguage ]
2014-01-06 01:03:47 +00:00
action: hall . getHeroes
2014-01-02 03:04:48 +00:00
2014-01-06 01:03:47 +00:00
" /hall/heroes/{uid}:GET " :
spec: path: " /hall/heroes/{uid} "
2014-03-10 16:28:49 +00:00
middleware : [ auth . auth , i18n . getUserLanguage , hall . ensureAdmin ]
2014-01-06 01:03:47 +00:00
action: hall . getHero
2014-01-02 03:04:48 +00:00
2014-01-06 01:03:47 +00:00
" /hall/heroes/{uid}:POST " :
2014-01-02 18:00:22 +00:00
spec:
method: ' POST '
2014-01-06 01:03:47 +00:00
path: " /hall/heroes/{uid} "
2014-03-10 16:28:49 +00:00
middleware: [ auth . auth , i18n . getUserLanguage , hall . ensureAdmin ]
2014-01-06 01:03:47 +00:00
action: hall . updateHero
" /hall/patrons " :
2014-01-06 02:51:33 +00:00
spec:
2014-01-08 03:23:22 +00:00
parameters: [
2014-01-06 02:51:33 +00:00
query ' page ' , ' Page number to fetch (this list is long) ' , ' string '
]
2014-03-10 16:28:49 +00:00
middleware : [ auth . auth , i18n . getUserLanguage ]
2014-01-06 01:03:47 +00:00
action: hall . getPatrons
2014-01-02 03:04:48 +00:00
# ---------------------------------
# Challenges
# ---------------------------------
# Note: while challenges belong to groups, and would therefore make sense as a nested resource
# (eg /groups/:gid/challenges/:cid), they will also be referenced by users from the "challenges" tab
# without knowing which group they belong to. So to prevent unecessary lookups, we have them as a top-level resource
" /challenges:GET " :
2014-01-02 04:38:35 +00:00
spec:
path: ' /challenges '
description: " Get a list of challenges "
2014-03-10 16:28:49 +00:00
middleware: [ auth . auth , i18n . getUserLanguage ]
2014-01-02 03:04:48 +00:00
action: challenges . list
2014-01-23 06:20:16 +00:00
2014-01-02 03:04:48 +00:00
" /challenges:POST " :
2014-01-02 04:38:35 +00:00
spec:
path: ' /challenges '
method: ' POST '
description: " Create a challenge "
2014-01-08 03:23:22 +00:00
parameters: [ body ( ' ' , ' Challenge object (see ChallengeSchema) ' , ' object ' ) ]
2014-03-10 16:28:49 +00:00
middleware: [ auth . auth , i18n . getUserLanguage ]
2014-01-02 03:04:48 +00:00
action: challenges . create
" /challenges/{cid}:GET " :
2014-01-02 04:38:35 +00:00
spec:
2014-01-02 23:58:48 +00:00
path: ' /challenges/{cid} '
2014-01-02 04:38:35 +00:00
description: ' Get a challenge '
2014-01-08 03:23:22 +00:00
parameters: [ path ( ' cid ' , ' Challenge id ' , ' string ' ) ]
2014-01-02 03:04:48 +00:00
action: challenges . get
2014-01-23 06:20:16 +00:00
" /challenges/{cid}/csv " :
spec:
description: ' Get a challenge (csv format) '
parameters: [ path ( ' cid ' , ' Challenge id ' , ' string ' ) ]
action: challenges . csv
2014-01-02 03:04:48 +00:00
" /challenges/{cid}:POST " :
2014-01-02 04:38:35 +00:00
spec:
path: ' /challenges/{cid} '
method: ' POST '
description: " Update a challenge "
2014-01-08 03:23:22 +00:00
parameters: [
2014-01-02 04:38:35 +00:00
path ' cid ' , ' Challenge id ' , ' string '
body ( ' ' , ' Challenge object (see ChallengeSchema) ' , ' object ' )
]
2014-03-10 16:28:49 +00:00
middleware: [ auth . auth , i18n . getUserLanguage ]
2014-01-02 03:04:48 +00:00
action: challenges . update
" /challenges/{cid}:DELETE " :
2014-01-02 04:38:35 +00:00
spec:
path: ' /challenges/{cid} '
method: ' DELETE '
description: " Delete a challenge "
2014-01-08 03:23:22 +00:00
parameters: [ path ( ' cid ' , ' Challenge id ' , ' string ' ) ]
2014-03-10 16:28:49 +00:00
middleware: [ auth . auth , i18n . getUserLanguage ]
2014-01-02 03:04:48 +00:00
action: challenges [ " delete " ]
" /challenges/{cid}/close " :
2014-01-02 04:38:35 +00:00
spec:
method: ' POST '
description: ' Close a challenge '
2014-01-08 03:23:22 +00:00
parameters: [
2014-01-02 04:38:35 +00:00
path ' cid ' , ' Challenge id ' , ' string '
query ' uid ' , ' User ID of the winner ' , ' string ' , true
]
2014-03-10 16:28:49 +00:00
middleware: [ auth . auth , i18n . getUserLanguage ]
2014-01-02 03:04:48 +00:00
action: challenges . selectWinner
" /challenges/{cid}/join " :
2014-01-02 04:38:35 +00:00
spec:
method: ' POST '
description: " Join a challenge "
2014-01-08 03:23:22 +00:00
parameters: [ path ( ' cid ' , ' Challenge id ' , ' string ' ) ]
2014-03-10 16:28:49 +00:00
middleware: [ auth . auth , i18n . getUserLanguage ]
2014-01-02 03:04:48 +00:00
action: challenges . join
" /challenges/{cid}/leave " :
2014-01-02 04:38:35 +00:00
spec:
method: ' POST '
description: ' Leave a challenge '
2014-01-08 03:23:22 +00:00
parameters: [ path ( ' cid ' , ' Challenge id ' , ' string ' ) ]
2014-03-10 16:28:49 +00:00
middleware: [ auth . auth , i18n . getUserLanguage ]
2014-01-02 03:04:48 +00:00
action: challenges . leave
" /challenges/{cid}/member/{uid} " :
2014-01-02 04:38:35 +00:00
spec:
description: " Get a member ' s progress in a particular challenge "
2014-01-08 03:23:22 +00:00
parameters: [
2014-01-02 04:38:35 +00:00
path ' cid ' , ' Challenge id ' , ' string '
path ' uid ' , ' User id ' , ' string '
]
2014-03-10 16:28:49 +00:00
middleware: [ auth . auth , i18n . getUserLanguage ]
2014-01-02 03:04:48 +00:00
action: challenges . getMember
if nconf . get ( " NODE_ENV " ) is " development "
api [ " /user/addTenGems " ] =
spec: method : ' POST '
action: user . addTenGems
_ . each api , (route, path) ->
## Spec format is:
# spec:
# path: "/pet/{petId}"
# description: "Operations about pets"
# notes: "Returns a pet based on ID"
# summary: "Find pet by ID"
# method: "GET"
2014-01-02 03:34:31 +00:00
# parameters: [path("petId", "ID of pet that needs to be fetched", "string")]
2014-01-02 03:04:48 +00:00
# type: "Pet"
# errorResponses: [swagger.errors.invalid("id"), swagger.errors.notFound("pet")]
# nickname: "getPetById"
route . spec . description ? = ' '
_ . defaults route . spec ,
path: path
nickname: path
notes: route . spec . description
summary: route . spec . description
2014-01-02 03:34:31 +00:00
parameters: [ ]
2014-01-02 03:04:48 +00:00
#type: 'Pet'
errorResponses: [ ]
method: ' GET '
2014-05-12 14:52:11 +00:00
route . middleware ? = if path . indexOf ( ' /user ' ) is 0 then [ auth . auth , i18n . getUserLanguage , cron ] else [ i18n . getUserLanguage ]
2014-01-02 03:04:48 +00:00
swagger [ " add #{ route . spec . method } " ] ( route ) ; true
2014-04-11 04:31:24 +00:00
swagger . configure ( " #{ nconf . get ( ' BASE_URL ' ) } /api/v2 " , " 2 " )