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 " )
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-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). "
action: user . getContent
" /export/history " :
spec:
description: " Export user history "
method: ' GET '
middleware: auth . auth
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."
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. "
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
" /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-01-02 03:04:48 +00:00
middleware: auth . auth ## removing cron since they may want to remove task first
action: challenges . unlink
# Inventory
" /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
path ( ' type ' , " The type of object you ' re selling back. " , ' string ' , [ ' gear ' , ' eggs ' , ' hatchingPotions ' , ' food ' ] )
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-01-02 03:04:48 +00:00
path ( ' type ' , " The type of object you ' re purchasing. " , ' string ' , [ ' gear ' , ' eggs ' , ' hatchingPotions ' , ' food ' ] )
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 '
description: " Equip an item (either pets, mounts, or gear) "
2014-01-02 03:34:31 +00:00
parameters: [
2014-01-02 03:04:48 +00:00
path ' type ' , " Type to equip " , ' string ' , [ ' pets ' , ' mounts ' , ' gear ' ]
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! "
middleware: auth . auth
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. "
params: [
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/buy-gems " :
2014-01-02 04:38:35 +00:00
spec: method: ' POST ' , description: " Do not use this route "
2014-01-02 03:04:48 +00:00
middleware: auth . auth
action : user . buyGems
" /user/buy-gems/paypal-ipn " :
2014-01-03 19:50:03 +00:00
spec:
method: ' POST '
description: " Don ' t use this route "
middleware: [ ]
2014-01-02 03:04:48 +00:00
action: user . buyGemsPaypalIPN
" /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 '
]
middleware: [ middleware . forceRefresh , auth . auth , cron ]
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
" /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
# ---------------------------------
# Groups
# ---------------------------------
" /groups:GET " :
2014-01-02 04:38:35 +00:00
spec:
path: ' /groups '
description: " Get a list of groups "
params: [
query ' type ' , " Comma-separated types of groups to return, eg ' party,guilds,public,tavern ' " , ' string '
]
2014-01-02 03:04:48 +00:00
middleware: auth . auth
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 '
params: [
body ' ' , ' Group object (see GroupSchema) ' , ' object '
]
2014-01-02 03:04:48 +00:00
middleware: auth . auth
action: groups . create
" /groups/{gid}:GET " :
2014-01-02 04:38:35 +00:00
spec:
path: ' /groups/{gid} '
description: " Get a group "
params: [ path ( ' gid ' , ' Group ID ' , ' string ' ) ]
2014-01-02 03:04:48 +00:00
middleware: auth . auth
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 "
params: [ body ( ' ' , ' Group object (see GroupSchema) ' , ' object ' ) ]
2014-01-02 03:04:48 +00:00
middleware: [ auth . auth , groups . attachGroup ]
action: groups . update
" /groups/{gid}/join " :
2014-01-02 04:38:35 +00:00
spec:
method: ' POST '
description: ' Join a group '
params: [ path ( ' gid ' , ' Id of the group to join ' , ' string ' ) ]
2014-01-02 03:04:48 +00:00
middleware: [ auth . auth , groups . attachGroup ]
action: groups . join
" /groups/{gid}/leave " :
2014-01-02 04:38:35 +00:00
spec:
method: ' POST '
description: ' Leave a group '
params: [ path ( ' ID of the group to leave ' , ' string ' ) ]
2014-01-02 03:04:48 +00:00
middleware: [ auth . auth , groups . attachGroup ]
action: groups . leave
" /groups/{gid}/invite " :
2014-01-02 04:38:35 +00:00
spec:
method: ' POST '
description: " Invite a user to a group "
params: [
path ' gid ' , ' Group id ' , ' string '
query ' uuid ' , ' User id to invite ' , ' string '
]
2014-01-02 03:04:48 +00:00
middleware: [ auth . auth , groups . attachGroup ]
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 "
params: [
path ' gid ' , ' Group id ' , ' string '
query ' uuid ' , ' User id to boot ' , ' string '
]
2014-01-02 03:04:48 +00:00
middleware: [ auth . auth , groups . attachGroup ]
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 '
]
middleware: [ auth . auth , groups . attachGroup ]
action : groups . questAccept
" /groups/{gid}/questReject " :
2014-01-02 04:38:35 +00:00
spec:
method: ' POST '
description: ' Reject quest invitation '
params: [
path ' gid ' , ' Group id ' , ' string '
]
2014-01-02 03:04:48 +00:00
middleware: [ auth . auth , groups . attachGroup ]
action: groups . questReject
" /groups/{gid}/questAbort " :
2014-01-02 04:38:35 +00:00
spec:
method: ' POST '
description: ' Abort quest '
params: [ path ( ' gid ' , ' Group to abort quest in ' , ' string ' ) ]
2014-01-02 03:04:48 +00:00
middleware: [ auth . auth , groups . attachGroup ]
action: groups . questAbort
#TODO GET /groups/:gid/chat
#TODO PUT /groups/:gid/chat/:messageId
" /groups/{gid}/chat " :
2014-01-02 04:38:35 +00:00
spec:
method: ' POST '
description: " Send a chat message "
params: [
query ' message ' , ' Chat message ' , ' string '
path ' gid ' , ' Group id ' , ' string '
]
2014-01-02 03:04:48 +00:00
middleware: [ auth . auth , groups . attachGroup ]
action: groups . postChat
" /groups/{gid}/chat/{messageId} " :
2014-01-02 04:38:35 +00:00
spec:
method: ' DELETE '
description: ' Delete a group '
params: [ path ( ' gid ' , ' ID of group to delete ' , ' string ' ) ]
2014-01-02 03:04:48 +00:00
middleware: [ auth . auth , groups . attachGroup ]
action: groups . deleteChatMessage
# ---------------------------------
# Members
# ---------------------------------
" /members/{uid} " :
spec : { }
action: groups . getMember
# ---------------------------------
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-01-06 01:03:47 +00:00
middleware : [ auth . auth ]
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} "
middleware : [ auth . auth , hall . ensureAdmin ]
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} "
middleware: [ auth . auth , hall . ensureAdmin ]
action: hall . updateHero
" /hall/patrons " :
2014-01-06 02:51:33 +00:00
spec:
params: [
query ' page ' , ' Page number to fetch (this list is long) ' , ' string '
]
2014-01-06 01:03:47 +00:00
middleware : [ auth . auth ]
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-01-02 03:04:48 +00:00
middleware: [ auth . auth ]
action: challenges . list
" /challenges:POST " :
2014-01-02 04:38:35 +00:00
spec:
path: ' /challenges '
method: ' POST '
description: " Create a challenge "
params: [ body ( ' ' , ' Challenge object (see ChallengeSchema) ' , ' object ' ) ]
2014-01-02 03:04:48 +00:00
middleware: [ auth . auth ]
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 '
params: [ path ( ' cid ' , ' Challenge id ' , ' string ' ) ]
2014-01-02 03:04:48 +00:00
action: challenges . get
" /challenges/{cid}:POST " :
2014-01-02 04:38:35 +00:00
spec:
path: ' /challenges/{cid} '
method: ' POST '
description: " Update a challenge "
params: [
path ' cid ' , ' Challenge id ' , ' string '
body ( ' ' , ' Challenge object (see ChallengeSchema) ' , ' object ' )
]
2014-01-02 03:04:48 +00:00
middleware: [ auth . auth ]
action: challenges . update
" /challenges/{cid}:DELETE " :
2014-01-02 04:38:35 +00:00
spec:
path: ' /challenges/{cid} '
method: ' DELETE '
description: " Delete a challenge "
params: [ path ( ' cid ' , ' Challenge id ' , ' string ' ) ]
2014-01-02 03:04:48 +00:00
middleware: [ auth . auth ]
action: challenges [ " delete " ]
" /challenges/{cid}/close " :
2014-01-02 04:38:35 +00:00
spec:
method: ' POST '
description: ' Close a challenge '
params: [
path ' cid ' , ' Challenge id ' , ' string '
query ' uid ' , ' User ID of the winner ' , ' string ' , true
]
2014-01-02 03:04:48 +00:00
middleware: [ auth . auth ]
action: challenges . selectWinner
" /challenges/{cid}/join " :
2014-01-02 04:38:35 +00:00
spec:
method: ' POST '
description: " Join a challenge "
params: [ path ( ' cid ' , ' Challenge id ' , ' string ' ) ]
2014-01-02 03:04:48 +00:00
middleware: [ auth . auth ]
action: challenges . join
" /challenges/{cid}/leave " :
2014-01-02 04:38:35 +00:00
spec:
method: ' POST '
description: ' Leave a challenge '
params: [ path ( ' cid ' , ' Challenge id ' , ' string ' ) ]
2014-01-02 03:04:48 +00:00
middleware: [ auth . auth ]
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 "
params: [
path ' cid ' , ' Challenge id ' , ' string '
path ' uid ' , ' User id ' , ' string '
]
2014-01-02 03:04:48 +00:00
middleware: [ auth . auth ]
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-01-02 04:09:01 +00:00
route . middleware ? = if path . indexOf ( ' /user ' ) is 0 then [ auth . auth , cron ] else [ ]
2014-01-02 03:04:48 +00:00
swagger [ " add #{ route . spec . method } " ] ( route ) ; true
2014-01-02 03:34:31 +00:00
swagger . configure ( " #{ nconf . get ( ' BASE_URL ' ) } /api/v2 " , " 2 " )