Пример #1
0
    def __init__(self, conf_file=None, *args, **kwargs):
        here = dirname(dirname(sys.argv[0]))
        self.config = Config.load(path=conf_file, conf_name="impim_api.conf",
            lookup_paths=[
                here,
                os.curdir,
                expanduser('~'),
                '/etc/',
                dirname(__file__),
            ])

        rest_api = TornadoRESTful(version='', base_url=self.config.APPLICATION_URL,
                discovery=True, cross_origin_enabled=True)
        rest_api.add_resource('alpha/images', ImagesResourceHandler)

        handlers = [
            (r'/healthcheck(?:/|\.html)?', HealthCheckHandler),
            (r'/thumbor_urls/?', JsonpEnabledThumborUrlHandler),
            (r'/alpha/images/(?P<key>.+)/.+', ImageHandler),
        ] + rest_api.get_url_mapping()

        super(ImagesApplication, self).__init__(handlers,
                thumbor_security_key=self.config.THUMBOR_SECURITY_KEY,
                thumbor_server_url=self.config.THUMBOR_SERVER_URL,
                *args,
                **kwargs)
Пример #2
0
    def __init__(self, conf_file=None, *args, **kwargs):
        here = dirname(dirname(sys.argv[0]))
        self.config = Config.load(path=conf_file,
                                  conf_name="impim_api.conf",
                                  lookup_paths=[
                                      here,
                                      os.curdir,
                                      expanduser('~'),
                                      '/etc/',
                                      dirname(__file__),
                                  ])

        rest_api = TornadoRESTful(version='',
                                  base_url=self.config.APPLICATION_URL,
                                  discovery=True,
                                  cross_origin_enabled=True)
        rest_api.add_resource('alpha/images', ImagesResourceHandler)

        handlers = [
            (r'/healthcheck(?:/|\.html)?', HealthCheckHandler),
            (r'/thumbor_urls/?', JsonpEnabledThumborUrlHandler),
            (r'/alpha/images/(?P<key>.+)/.+', ImageHandler),
        ] + rest_api.get_url_mapping()

        super(ImagesApplication, self).__init__(
            handlers,
            thumbor_security_key=self.config.THUMBOR_SECURITY_KEY,
            thumbor_server_url=self.config.THUMBOR_SERVER_URL,
            *args,
            **kwargs)
Пример #3
0
class TestApiManager(TestCase):

    def setUp(self):
        self.api = TornadoRESTful()

    def test_should_be_possible_to_add_a_handler(self):
        self.api.add_resource('api', ResourceHandler)
        assert ('/api/?', ResourceHandler) in self.api.get_url_mapping()

    def test_should_generate_a_path_for_access_direcly_an_instance(self):
        self.api.add_resource('comment', ResourceHandler)
        assert ('/comment/(?P<key>.+)/?', ResourceHandler) in \
                self.api.get_url_mapping()

    def test_should_generate_path_to_handler_return_type_specification(self):
        self.api.add_resource('comment', ResourceHandler)
        assert ('/comment\.(?P<force_return_type>\w+)', ResourceHandler) in \
                self.api.get_url_mapping()

    def test_should_generate_path_to_handler_return_type_specification(self):
        self.api.add_resource('comment', ResourceHandler)
        assert ('/comment/(?P<key>[^.]+)\.(?P<force_return_type>\w+)', ResourceHandler) in \
                self.api.get_url_mapping()
Пример #4
0
 def get_app(self):
     api = TornadoRESTful()
     api.add_resource('api', ResourceHandler)
     application = tornado.web.Application(api.get_url_mapping())
     return application
Пример #5
0
 def get_app(self):
     api = TornadoRESTful(cross_origin_enabled=True)
     api.add_resource('api', WithDefaultCallbackHandler)
     application = tornado.web.Application(api.get_url_mapping())
     return application
Пример #6
0
 def get_app(self):
     api = TornadoRESTful(version='v1', base_url='http://api.tapioca.com')
     api.add_resource('api', FullTestHandler)
     application = tornado.web.Application(api.get_url_mapping())
     return application
Пример #7
0
 def get_app(self):
     api = TornadoRESTful(
             version='v1', base_url='http://api.tapioca.com', discovery=True)
     api.add_resource('comments', ResourceWithDocumentation)
     return tornado.web.Application(api.get_url_mapping())
Пример #8
0
#!/usr/local/bin/python2.7
# encoding: utf-8


import tornado.ioloop
import tornado.web

from tapioca import TornadoRESTful, ResourceHandler

class HelloResource(ResourceHandler):

    def get_collection(self, callback):
        callback("Hello, world!")

api = TornadoRESTful(discovery=True)
api.add_resource('hello', HelloResource)
application = tornado.web.Application(
    api.get_url_mapping()
)

if __name__ == "__main__":
    application.listen(8888)
    tornado.ioloop.IOLoop.instance().start()
	
	
Пример #9
0
#!/usr/local/bin/python2.7
# encoding: utf-8

import tornado.ioloop
import tornado.web

from tapioca import TornadoRESTful, ResourceHandler


class HelloResource(ResourceHandler):
    def get_collection(self, callback):
        callback("Hello, world!")


api = TornadoRESTful(discovery=True)
api.add_resource('hello', HelloResource)
application = tornado.web.Application(api.get_url_mapping())

if __name__ == "__main__":
    application.listen(8888)
    tornado.ioloop.IOLoop.instance().start()
Пример #10
0
 def get_app(self):
     api = TornadoRESTful()
     api.add_resource('always_valid', NoAccessValuesInQuerystring)
     application = tornado.web.Application(api.get_url_mapping())
     return application
Пример #11
0
 def get_app(self):
     api = TornadoRESTful()
     api.add_resource('api', ResourceHandler)
     application = tornado.web.Application(api.get_url_mapping())
     return application
Пример #12
0
 def get_app(self):
     api = TornadoRESTful(cross_origin_enabled=True)
     api.add_resource('api', WithDefaultCallbackHandler)
     application = tornado.web.Application(api.get_url_mapping())
     return application
Пример #13
0
 def get_app(self):
     api = TornadoRESTful(version='v1',
                          base_url='http://api.tapioca.com',
                          discovery=True)
     api.add_resource('comments', ResourceWithDocumentation)
     return tornado.web.Application(api.get_url_mapping())
Пример #14
0
 def get_app(self):
     api = TornadoRESTful()
     api.add_resource('projects', ProjectsResource)
     application = tornado.web.Application(api.get_url_mapping())
     return application
Пример #15
0
import tornado.ioloop
from tornado.httpserver import HTTPServer

from tapioca import TornadoRESTful, ResourceHandler, validate


class ProjectsHandler(ResourceHandler):

    @validate(querystring={'name': (unicode, 'name of project that do you want to search')})
    def get_collection(self, callback, *args, **kwargs):
        callback([{'params': self.values['querystring']}])


if __name__ == '__main__':
    import os
    port = int(os.environ.get('PORT', 5000))
    main_loop = tornado.ioloop.IOLoop.instance()

    api = TornadoRESTful(version='', \
            base_url='http://tapioqueiro.herokuapp.com', discovery=True, \
            cross_origin_enabled=True)
    api.add_resource('projects', ProjectsHandler)
    application = tornado.web.Application(api.get_url_mapping())

    server = HTTPServer(application)
    server.bind(port, '0.0.0.0')
    server.start(1)
    main_loop.start()
Пример #16
0
 def get_app(self):
     api = TornadoRESTful(version='v1', base_url='http://api.tapioca.com')
     api.add_resource('api', FullTestHandler)
     application = tornado.web.Application(api.get_url_mapping())
     return application
Пример #17
0
 def get_app(self):
     api = TornadoRESTful()
     api.add_resource('projects', ProjectsResource)
     application = tornado.web.Application(api.get_url_mapping())
     return application