Exemplo n.º 1
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()
Exemplo n.º 2
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()
Exemplo n.º 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()
Exemplo n.º 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()
Exemplo n.º 5
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()
Exemplo n.º 6
0
    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()
Exemplo n.º 7
0
    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()
Exemplo n.º 8
0
    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()
Exemplo n.º 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()
Exemplo n.º 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()
Exemplo n.º 11
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()
Exemplo n.º 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()
Exemplo n.º 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()
Exemplo n.º 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()
Exemplo n.º 15
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()
Exemplo n.º 16
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()
Exemplo n.º 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()
Exemplo n.º 18
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()
Exemplo n.º 19
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()
Exemplo n.º 20
0
    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()
Exemplo n.º 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()
Exemplo n.º 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()
Exemplo n.º 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()
Exemplo n.º 24
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()
Exemplo n.º 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()
Exemplo n.º 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()
Exemplo n.º 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()
Exemplo n.º 28
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()