""" recentActivity = yield self.facadeClient.getRecentUserActivity( self.session, self.username) body = buildPayload('application/json', recentActivity) request.setHeader('Content-length', str(len(body))) request.setHeader('Content-type', 'application/json') request.setResponseCode(http.OK) returnValue(body) # API DOCUMENTATION # GET on /recent topLevel = HTTPTopLevel('recent', 'GET') topLevel.description = dedent(""" The GET method on recent is used to retrieve information about the latest updated tag values on a given object or user.""") registry.register(topLevel) # GET on /recent/objects usage = HTTPUsage('/objects', dedent(""" To request information on the latest tag values on the objects returned by a given query""")) usage.resourceClass = RecentObjectsActivityResource usage.addArgument(Argument( 'query', dedent(""" A query string specifying what sorts of objects to get recent activity for. The query language is described <a href="http://doc.fluidinfo.com/fluidDB/queries.html">here</a>. You must convert your query to UTF-8 and then <a href="http://en.wikipedia.org/wiki
usage = registry.findUsage(httpValueCategoryName, 'DELETE', ValuesResource) registry.checkRequest(usage, request) query = request.args[queryArg][0] tags = request.args[tagArg] if tags == ['*']: tags = None yield self.facadeClient.deleteValuesForQuery(self.session, query, tags) request.setResponseCode(usage.successCode) defer.returnValue(None) # ------------------------------ Values GET ----------------------------- topLevel = HTTPTopLevel(httpValueCategoryName, 'GET') topLevel.description = """The GET method on values is used to retrieve tag values from objects matching a query.""" # We could here mention # href="http://doc.fluidinfo.com/fluidDB/api/draft-values-spec.html"> # /values draft spec</a>. registry.register(topLevel) # --- GET /values -------------------------------------------------------- usage = HTTPUsage( '', """Search for objects matching a Fluidinfo query, and return the value of the requested tags on the matching objects.""") usage.resourceClass = ValuesResource topLevel.addUsage(usage)
registry.checkRequest(usage, request) responseType = usage.getResponsePayloadTypeFromAcceptHeader(request) query = request.args['query'][0] results = yield self.facadeClient.resolveQuery(self.session, query) responseDict = {'ids': list(results)} registry.checkResponse(responseType, responseDict, usage, request) body = payloads.buildPayload(responseType, responseDict) request.setHeader('Content-length', str(len(body))) request.setHeader('Content-type', responseType) request.setResponseCode(usage.successCode) defer.returnValue(body) # ------------------------------ Objects POST ----------------------------- topLevel = HTTPTopLevel(httpObjectCategoryName, 'POST') topLevel.description = "Create a new Fluidinfo object." registry.register(topLevel) # --- POST /objects ------------------------------------------------------- usage = HTTPUsage('', 'Create a new object. You must provide credentials for ' 'this call to succeed.') topLevel.addUsage(usage) usage.resourceClass = ObjectsResource usage.successCode = http.CREATED apiDoc.addBadRequestPayload(usage) apiDoc.addCannotRespondWithPayload(usage) usage.addReturn(Return(apiDoc.UNAUTHORIZED,
else: try: # Make sure we have valid UTF-8 in the about value. about.decode('utf-8') except UnicodeDecodeError: return ErrorResource( http.BAD_REQUEST, error.BadArgument, {'Error-Message': 'About value in URI was not UTF-8'}) else: return AboutObjectResource( self.facadeClient, self.session, about) # ------------------------------ About POST ----------------------------- topLevel = HTTPTopLevel(httpAboutCategoryName, 'POST') topLevel.description = "Create a new object." registry.register(topLevel) # --- POST /about ------------------------------------------------------- usage = HTTPUsage('/' + apiDoc.ABOUTSTR, ('''Create a new object with the given about value. If there is already a Fluidinfo object whose ''' + apiDoc.ABOUT_TAG + ''' tag has the given value, the returned object id will be that of the pre-existing object. In this call, and all others with an about value in the URI, you must convert your about value to UTF-8 and then <a href="http://en.wikipedia.org/wiki/Percent-encoding"> percent-encode</a> it before adding it to the request URI. You must provide valid credentials for this call to succeed. For an example see the PUT request, below.'''))
else: try: # Make sure we have valid UTF-8 in the about value. about.decode('utf-8') except UnicodeDecodeError: return ErrorResource( http.BAD_REQUEST, error.BadArgument, {'Error-Message': 'About value in URI was not UTF-8'}) else: return AboutObjectResource(self.facadeClient, self.session, about) # ------------------------------ About POST ----------------------------- topLevel = HTTPTopLevel(httpAboutCategoryName, 'POST') topLevel.description = "Create a new object." registry.register(topLevel) # --- POST /about ------------------------------------------------------- usage = HTTPUsage('/' + apiDoc.ABOUTSTR, ('''Create a new object with the given about value. If there is already a Fluidinfo object whose ''' + apiDoc.ABOUT_TAG + ''' tag has the given value, the returned object id will be that of the pre-existing object. In this call, and all others with an about value in the URI, you must convert your about value to UTF-8 and then <a href="http://en.wikipedia.org/wiki/Percent-encoding"> percent-encode</a> it before adding it to the request URI. You must provide valid credentials for this call to succeed. For an example see the PUT request, below.'''))
recentActivity = yield self.facadeClient.getRecentUserActivity( self.session, self.username) body = buildPayload('application/json', recentActivity) request.setHeader('Content-length', str(len(body))) request.setHeader('Content-type', 'application/json') request.setResponseCode(http.OK) returnValue(body) # API DOCUMENTATION # GET on /recent topLevel = HTTPTopLevel('recent', 'GET') topLevel.description = dedent(""" The GET method on recent is used to retrieve information about the latest updated tag values on a given object or user.""") registry.register(topLevel) # GET on /recent/objects usage = HTTPUsage( '/objects', dedent(""" To request information on the latest tag values on the objects returned by a given query""")) usage.resourceClass = RecentObjectsActivityResource usage.addArgument( Argument('query', dedent(""" A query string specifying what sorts of objects to get recent activity for. The query language is described <a
class PermissionsResource(WSFEResource): def getChild(self, name, request): try: klass = _classForCategory[name] except KeyError: return NoResource() else: return klass(self.facadeClient, self.session) # ------------------------------ Permissions POST ------------------------- topLevel = HTTPTopLevel(httpPermissionCategoryName, 'POST') topLevel.description = """ POST is not supported on permissions, because permissions are automatically set from a user's default permissions when a namespace or tag is first created. Use PUT to adjust the permissions on a given namespace or tag. """ # TODO: Finish this sentence and add it to the description: # To change a user's defaults, do a PUT on.... what exactly? registry.register(topLevel) # ------------------------------ Permissions GET -------------------------- topLevel = HTTPTopLevel('permissions', 'GET') registry.register(topLevel) # --- GET /permissions/namespaces/NAMESPACE1/NAMESPACE2 ------------
usage = registry.findUsage(httpValueCategoryName, 'DELETE', ValuesResource) registry.checkRequest(usage, request) query = request.args[queryArg][0] tags = request.args[tagArg] if tags == ['*']: tags = None yield self.facadeClient.deleteValuesForQuery(self.session, query, tags) request.setResponseCode(usage.successCode) defer.returnValue(None) # ------------------------------ Values GET ----------------------------- topLevel = HTTPTopLevel(httpValueCategoryName, 'GET') topLevel.description = """The GET method on values is used to retrieve tag values from objects matching a query.""" # We could here mention # href="http://doc.fluidinfo.com/fluidDB/api/draft-values-spec.html"> # /values draft spec</a>. registry.register(topLevel) # --- GET /values -------------------------------------------------------- usage = HTTPUsage( '', """Search for objects matching a Fluidinfo query, and return the value of the requested tags on the matching objects.""") usage.resourceClass = ValuesResource
registry.checkRequest(usage, request) responseType = usage.getResponsePayloadTypeFromAcceptHeader(request) query = request.args['query'][0] results = yield self.facadeClient.resolveQuery(self.session, query) responseDict = {'ids': list(results)} registry.checkResponse(responseType, responseDict, usage, request) body = payloads.buildPayload(responseType, responseDict) request.setHeader('Content-length', str(len(body))) request.setHeader('Content-type', responseType) request.setResponseCode(usage.successCode) defer.returnValue(body) # ------------------------------ Objects POST ----------------------------- topLevel = HTTPTopLevel(httpObjectCategoryName, 'POST') topLevel.description = "Create a new Fluidinfo object." registry.register(topLevel) # --- POST /objects ------------------------------------------------------- usage = HTTPUsage( '', 'Create a new object. You must provide credentials for ' 'this call to succeed.') topLevel.addUsage(usage) usage.resourceClass = ObjectsResource usage.successCode = http.CREATED apiDoc.addBadRequestPayload(usage) apiDoc.addCannotRespondWithPayload(usage)
} class PermissionsResource(WSFEResource): def getChild(self, name, request): try: klass = _classForCategory[name] except KeyError: return NoResource() else: return klass(self.facadeClient, self.session) # ------------------------------ Permissions POST ------------------------- topLevel = HTTPTopLevel(httpPermissionCategoryName, 'POST') topLevel.description = """ POST is not supported on permissions, because permissions are automatically set from a user's default permissions when a namespace or tag is first created. Use PUT to adjust the permissions on a given namespace or tag. """ # TODO: Finish this sentence and add it to the description: # To change a user's defaults, do a PUT on.... what exactly? registry.register(topLevel) # ------------------------------ Permissions GET -------------------------- topLevel = HTTPTopLevel('permissions', 'GET') registry.register(topLevel) # --- GET /permissions/namespaces/NAMESPACE1/NAMESPACE2 ------------ usage = HTTPUsage(