示例#1
0
文件: api.py 项目: entropiae/urlist
    def get(self, user_id, mode=None):
        user_id = _smart_user_id(self, user_id)

        ctx = self.context()

        if not user_id:
            user_id = ctx.get('current_user_id')

        if mode not in ["list", "url", "lists", "urls"]:
            mode = "list"

        api_msg = MBMessage(None, 'fetch_user_network',
                    {'user_id': user_id, 'mode': mode}, {}, ctx)

        go = GoHandler.can_handle(self, api_msg)

        if go:
            go_resp  = yield go.dispatch()

            resp = go.make_response(go_resp)
        else:
            resp = yield self.dispatch(api_msg)

        self.write(resp.payload)
        self.finish()
示例#2
0
文件: api.py 项目: entropiae/urlist
    def post(self):
        self.set_header('Content-Type', 'application/json')

        body_data = self.request.body
        messages = json.loads(body_data)

        api_msgs = [self.decode_api_msg(msg_data) for msg_data in messages]

        go_handlers = {}

        resps = yield [GoHandler.hyperdrive_dispatch(self, go_handlers, api_msg)
                       for api_msg in api_msgs]

        def _unmarshal(raw_response):
            resp = GoHandler.hyperdrive_decode(go_handlers, raw_response)

            if not resp:
                logging.info("GO ERROR")

                return None

            resp_msg = MBMessage(resp.msg_id, resp.action, resp.target,
                                 resp.payload, resp.context, merge_target=False)

            self.mb_cookies(resp)

            return resp_msg.to_json()

        resp_msgs = [_unmarshal(resp) or "" for resp in resps]

        json_resp = '[{}]'.format(','.join(resp_msgs))

        self.write(json_resp)
        self.finish()
示例#3
0
    def get(self, user_id, mode=None):
        user_id = _smart_user_id(self, user_id)

        ctx = self.context()

        if not user_id:
            user_id = ctx.get('current_user_id')

        if mode not in ["list", "url", "lists", "urls"]:
            mode = "list"

        api_msg = MBMessage(None, 'fetch_user_network', {
            'user_id': user_id,
            'mode': mode
        }, {}, ctx)

        go = GoHandler.can_handle(self, api_msg)

        if go:
            go_resp = yield go.dispatch()

            resp = go.make_response(go_resp)
        else:
            resp = yield self.dispatch(api_msg)

        self.write(resp.payload)
        self.finish()
示例#4
0
    def get(self):
        api_msg = MBMessage(None, 'fetch_hashtags', {}, {}, self.context())

        go = GoHandler.can_handle(self, api_msg)

        if go:
            go_resp = yield go.dispatch()

            resp = go.make_response(go_resp)
        else:
            resp = yield self.dispatch(api_msg)

        self.write(resp.payload)
        self.finish()
示例#5
0
文件: api.py 项目: entropiae/urlist
        def _unmarshal(raw_response):
            resp = GoHandler.hyperdrive_decode(go_handlers, raw_response)

            if not resp:
                logging.info("GO ERROR")

                return None

            resp_msg = MBMessage(resp.msg_id, resp.action, resp.target,
                                 resp.payload, resp.context, merge_target=False)

            self.mb_cookies(resp)

            return resp_msg.to_json()
示例#6
0
文件: api.py 项目: entropiae/urlist
    def get(self, user_id=None):
        api_msg = MBMessage(None, 'fetch_user',
                            {'user_id': user_id}, {}, self.context())

        go = GoHandler.can_handle(self, api_msg)

        if go:
            go_resp  = yield go.dispatch()

            resp = go.make_response(go_resp)
        else:
            resp = yield self.dispatch(api_msg)

        self.write(resp.payload)
        self.finish()
示例#7
0
文件: api.py 项目: entropiae/urlist
    def get(self, hashtag):
        api_msg = MBMessage(None, 'fetch_hashtag',
                    {'hashtag': hashtag}, {}, self.context())

        go = GoHandler.can_handle(self, api_msg)

        if go:
            go_resp  = yield go.dispatch()

            resp = go.make_response(go_resp)
        else:
            resp = yield self.dispatch(api_msg)

        self.write(resp.payload)
        self.finish()
示例#8
0
文件: api.py 项目: entropiae/urlist
    def get(self):
        ctx = self.context()

        api_msg = MBMessage(None, 'fetch_popular', {}, {}, ctx)

        go = GoHandler.can_handle(self, api_msg)

        if go:
            go_resp  = yield go.dispatch()

            resp = go.make_response(go_resp)
        else:
            resp = yield self.dispatch(api_msg)

        self.write(resp.payload)
        self.finish()
示例#9
0
    def get(self, edition=None):
        ctx = self.context()

        api_msg = MBMessage(None, 'fetch_followmore', {}, {}, ctx)

        go = GoHandler.can_handle(self, api_msg)

        if go:
            go_resp = yield go.dispatch()

            resp = go.make_response(go_resp)
        else:
            resp = yield self.dispatch(api_msg)

        self.write(resp.payload)
        self.finish()
示例#10
0
    def get(self, categories=None):
        api_msg = MBMessage(None, 'fetch_list_by_categories',
                            {'categories': categories}, {}, self.context())

        go = GoHandler.can_handle(self, api_msg)

        if go:
            go_resp = yield go.dispatch()

            resp = go.make_response(go_resp)
        else:
            resp = yield self.dispatch(api_msg)

        self.guess_ctype()
        self.write(resp.payload)
        self.finish()
示例#11
0
文件: api.py 项目: entropiae/urlist
    def get(self, categories=None):
        api_msg = MBMessage(None, 'fetch_list_by_categories',
                            {'categories': categories}, {}, self.context())

        go = GoHandler.can_handle(self, api_msg)

        if go:
            go_resp  = yield go.dispatch()

            resp = go.make_response(go_resp)
        else:
            resp = yield self.dispatch(api_msg)

        self.guess_ctype()
        self.write(resp.payload)
        self.finish()
示例#12
0
    def get(self, action):
        args_as_list = self.request.arguments

        payload = {k: v[0] for k, v in args_as_list.iteritems()}

        api_msg = MBMessage(None, action, {}, payload, self.context())

        go = GoHandler.can_handle(self, api_msg)

        if go:
            raw_resp = yield go.dispatch()
            resp = go.make_response(raw_resp)
        else:
            resp = yield self.dispatch(api_msg)

        self.write(resp.payload)
        self.finish()
示例#13
0
    def post(self):
        query = self.get_argument('q') or self.get_argument('query')

        api_msg = MBMessage(None, 'beta_search_url', {'query': query}, {},
                            self.context())

        go = GoHandler.can_handle(self, api_msg)

        if go:
            go_resp = yield go.dispatch()

            resp = go.make_response(go_resp)
        else:
            resp = yield self.dispatch(api_msg)

        self.write(resp.payload)
        self.finish()
示例#14
0
    def get(self, user_id=None):
        api_msg = MBMessage(None, 'fetch_user_profile', {'user_id': user_id},
                            {}, self.context())

        go = GoHandler.can_handle(self, api_msg)

        if go:
            go_resp = yield go.dispatch()

            resp = go.make_response(go_resp)
        else:
            resp = yield self.dispatch(api_msg)

        self.guess_ctype()

        self.write(resp.payload)
        self.finish()
示例#15
0
文件: api.py 项目: entropiae/urlist
    def get(self, key=""):
        api_msg = MBMessage(None, 'fetch_landing',
                  {}, {'key': key}, self.context())

        go = GoHandler.can_handle(self, api_msg)

        if go:
            go_resp  = yield go.dispatch()

            resp = go.make_response(go_resp)
        else:
            resp = yield self.dispatch(api_msg)

        self.guess_ctype()

        self.write(resp.payload)
        self.finish()
示例#16
0
文件: debug.py 项目: entropiae/urlist
    def get(self, action):
        args_as_list = self.request.arguments

        payload = {k: v[0] for k, v in args_as_list.iteritems()}

        api_msg = MBMessage(None, action, {}, payload, self.context())

        go = GoHandler.can_handle(self, api_msg)

        if go:
            raw_resp = yield go.dispatch()
            resp = go.make_response(raw_resp)
        else:
            resp = yield self.dispatch(api_msg)

        self.write(resp.payload)
        self.finish()
示例#17
0
    def get(self, key=""):
        api_msg = MBMessage(None, 'fetch_landing', {}, {'key': key},
                            self.context())

        go = GoHandler.can_handle(self, api_msg)

        if go:
            go_resp = yield go.dispatch()

            resp = go.make_response(go_resp)
        else:
            resp = yield self.dispatch(api_msg)

        self.guess_ctype()

        self.write(resp.payload)
        self.finish()
示例#18
0
文件: api.py 项目: entropiae/urlist
    def get(self, category=None):
        ctx = self.context()

        api_msg = MBMessage(None, 'fetch_topusers',
                       {'category': category or choice(CATEGORIES)}, {}, ctx)

        go = GoHandler.can_handle(self, api_msg)

        if go:
            go_resp  = yield go.dispatch()

            resp = go.make_response(go_resp)
        else:
            resp = yield self.dispatch(api_msg)

        self.write(resp.payload)
        self.finish()
示例#19
0
文件: api.py 项目: entropiae/urlist
    def post(self):
        query = self.get_argument('q') or self.get_argument('query')

        api_msg = MBMessage(None, 'beta_search_url',
                            {'query': query}, {}, self.context())

        go = GoHandler.can_handle(self, api_msg)

        if go:
            go_resp  = yield go.dispatch()

            resp = go.make_response(go_resp)
        else:
            resp = yield self.dispatch(api_msg)

        self.write(resp.payload)
        self.finish()
示例#20
0
文件: api.py 项目: entropiae/urlist
    def get(self, edition=None):
        ctx = self.context()

        api_msg = MBMessage(None, 'fetch_toplists',
                       {}, {'edition': edition or ""}, ctx)

        go = GoHandler.can_handle(self, api_msg)

        if go:
            go_resp  = yield go.dispatch()

            resp = go.make_response(go_resp)
        else:
            resp = yield self.dispatch(api_msg)

        self.write(resp.payload)
        self.finish()
示例#21
0
    def get(self, category=None):
        ctx = self.context()

        api_msg = MBMessage(None, 'fetch_topusers',
                            {'category': category or choice(CATEGORIES)}, {},
                            ctx)

        go = GoHandler.can_handle(self, api_msg)

        if go:
            go_resp = yield go.dispatch()

            resp = go.make_response(go_resp)
        else:
            resp = yield self.dispatch(api_msg)

        self.write(resp.payload)
        self.finish()
示例#22
0
    def get(self, user_id=None):
        if not user_id:
            user_id = self.context().get("current_user_id")

        api_msg = MBMessage(None, 'fetch_notifications', {'user_id': user_id},
                            {}, self.context())

        go = GoHandler.can_handle(self, api_msg)

        if go:
            go_resp = yield go.dispatch()

            resp = go.make_response(go_resp)
        else:
            resp = yield self.dispatch(api_msg)

        self.write(resp.payload)
        self.finish()
示例#23
0
        def _unmarshal(raw_response):
            resp = GoHandler.hyperdrive_decode(go_handlers, raw_response)

            if not resp:
                logging.info("GO ERROR")

                return None

            resp_msg = MBMessage(resp.msg_id,
                                 resp.action,
                                 resp.target,
                                 resp.payload,
                                 resp.context,
                                 merge_target=False)

            self.mb_cookies(resp)

            return resp_msg.to_json()
示例#24
0
文件: api.py 项目: entropiae/urlist
    def post(self):
        api_msg = self.decode_api_msg(self.request.body)

        go = GoHandler.can_handle(self, api_msg)
        if go:
            resp = yield go.dispatch()

            resp_msg = go.make_response(resp)
        else:
            resp = yield self.dispatch(api_msg)

            resp_msg = MBMessage(resp.msg_id, resp.action,
                                 api_msg.target, resp.payload, resp.context, merge_target=False)

            self.mb_cookies(resp)

        self.set_header('Content-Type', 'application/json')
        self.write(resp_msg.to_json())
        self.finish()
示例#25
0
    def post(self):
        self.set_header('Content-Type', 'application/json')

        body_data = self.request.body
        messages = json.loads(body_data)

        api_msgs = [self.decode_api_msg(msg_data) for msg_data in messages]

        go_handlers = {}

        resps = yield [
            GoHandler.hyperdrive_dispatch(self, go_handlers, api_msg)
            for api_msg in api_msgs
        ]

        def _unmarshal(raw_response):
            resp = GoHandler.hyperdrive_decode(go_handlers, raw_response)

            if not resp:
                logging.info("GO ERROR")

                return None

            resp_msg = MBMessage(resp.msg_id,
                                 resp.action,
                                 resp.target,
                                 resp.payload,
                                 resp.context,
                                 merge_target=False)

            self.mb_cookies(resp)

            return resp_msg.to_json()

        resp_msgs = [_unmarshal(resp) or "" for resp in resps]

        json_resp = '[{}]'.format(','.join(resp_msgs))

        self.write(json_resp)
        self.finish()
示例#26
0
    def post(self):
        api_msg = self.decode_api_msg(self.request.body)

        go = GoHandler.can_handle(self, api_msg)
        if go:
            resp = yield go.dispatch()

            resp_msg = go.make_response(resp)
        else:
            resp = yield self.dispatch(api_msg)

            resp_msg = MBMessage(resp.msg_id,
                                 resp.action,
                                 api_msg.target,
                                 resp.payload,
                                 resp.context,
                                 merge_target=False)

            self.mb_cookies(resp)

        self.set_header('Content-Type', 'application/json')
        self.write(resp_msg.to_json())
        self.finish()
示例#27
0
    def get(self):
        self.guess_ctype()

        if self.is_anonymous():
            self.write(json.dumps({'notifications': []}))
            self.finish()

            return

        api_msg = MBMessage(None, 'fetch_contrib_notifications', {}, {},
                            self.context())

        go = GoHandler.can_handle(self, api_msg)

        if go:
            go_resp = yield go.dispatch()

            resp = go.make_response(go_resp)
        else:
            resp = yield self.dispatch(api_msg)

        self.write(resp.payload)
        self.finish()
示例#28
0
文件: api.py 项目: entropiae/urlist
    def get(self):
        self.guess_ctype()

        if self.is_anonymous():
            self.write(json.dumps({'notifications': []}))
            self.finish()

            return

        api_msg = MBMessage(None, 'fetch_contrib_notifications',
                            {}, {}, self.context())

        go = GoHandler.can_handle(self, api_msg)

        if go:
            go_resp  = yield go.dispatch()

            resp = go.make_response(go_resp)
        else:
            resp = yield self.dispatch(api_msg)

        self.write(resp.payload)
        self.finish()