コード例 #1
0
ファイル: api.py プロジェクト: anthill-platform/anthill-exec
    async def update_group_profiles(self,
                                    group_profiles,
                                    path=None,
                                    merge=True,
                                    synced=False,
                                    handler=None,
                                    *ignored):
        if not isinstance(group_profiles, dict):
            raise APIError(400, "Group profiles should be a dict")

        if path and not isinstance(path, (list, tuple)):
            raise APIError(400, "Path should be a list/tuple")

        internal = Internal()

        try:
            profile = await internal.request(
                "social",
                "update_group_profiles",
                timeout=API_TIMEOUT,
                gamespace=handler.env["gamespace"],
                group_profiles=group_profiles,
                path=path or [],
                merge=merge,
                synced=synced)
        except InternalError as e:
            raise APIError(e.code, e.body)

        return profile
コード例 #2
0
ファイル: api.py プロジェクト: anthill-platform/anthill-exec
    async def update(self,
                     profile=None,
                     path="",
                     merge=True,
                     handler=None,
                     *ignored):

        if not isinstance(path, str):
            raise APIError(400, "Path should be a string")

        key = "profile:" + str(path)
        if not profile:
            profile = {}

        internal = Internal()

        try:
            profile = await internal.request(
                "profile",
                "update_profile",
                timeout=API_TIMEOUT,
                gamespace_id=handler.env["gamespace"],
                account_id=handler.env["account"],
                fields=profile,
                path=path,
                merge=merge)
        except InternalError as e:
            raise APIError(e.code, e.body)

        handler.set_cache(key, profile)
        return profile
コード例 #3
0
ファイル: api.py プロジェクト: anthill-platform/anthill-exec
    async def update_profile(self,
                             group_id,
                             profile=None,
                             path=None,
                             merge=True,
                             handler=None,
                             *ignored):
        if path and not isinstance(path, (list, tuple)):
            raise APIError(400, "Path should be a list/tuple")

        internal = Internal()

        try:
            profile = await internal.request(
                "social",
                "update_group_profile",
                timeout=API_TIMEOUT,
                gamespace=handler.env["gamespace"],
                group_id=group_id,
                profile=profile,
                path=path,
                merge=merge)
        except InternalError as e:
            raise APIError(e.code, e.body)

        return profile
コード例 #4
0
ファイル: api.py プロジェクト: anthill-platform/anthill-exec
    async def new_order(self,
                        store,
                        item,
                        currency,
                        amount,
                        component,
                        env=None,
                        handler=None,
                        *ignored):

        internal = Internal()

        try:
            result = await internal.request("store",
                                            "new_order",
                                            timeout=API_TIMEOUT,
                                            gamespace=handler.env["gamespace"],
                                            account=handler.env["account"],
                                            store=store,
                                            item=item,
                                            currency=currency,
                                            amount=amount,
                                            component=component,
                                            env=env)
        except InternalError as e:
            raise APIError(e.code, e.body)

        return result
コード例 #5
0
ファイル: api.py プロジェクト: anthill-platform/anthill-exec
    async def check_name(self, kind, name, handler=None, *ignored):
        internal = Internal()

        try:
            account_id = await internal.request(
                "social",
                "check_name",
                gamespace=handler.env["gamespace"],
                kind=kind,
                name=name)
        except InternalError as e:
            raise APIError(e.code, e.body)

        return account_id
コード例 #6
0
ファイル: api.py プロジェクト: anthill-platform/anthill-exec
    async def update_orders(self, handler=None, *ignored):

        internal = Internal()

        try:
            result = await internal.request("store",
                                            "update_orders",
                                            timeout=API_TIMEOUT,
                                            gamespace=handler.env["gamespace"],
                                            account=handler.env["account"])
        except InternalError as e:
            raise APIError(e.code, e.body)

        return result
コード例 #7
0
ファイル: api.py プロジェクト: anthill-platform/anthill-exec
    async def release_name(self, kind, handler=None, *ignored):
        internal = Internal()

        try:
            released = await internal.request(
                "social",
                "release_name",
                gamespace=handler.env["gamespace"],
                account=handler.env["account"],
                kind=kind)
        except InternalError as e:
            raise APIError(e.code, e.body)

        return released
コード例 #8
0
ファイル: api.py プロジェクト: anthill-platform/anthill-exec
    async def list(self, extra_start_time=0, extra_end_time=0, handler=None):
        internal = Internal()

        try:
            events = await internal.request("event",
                                            "get_list",
                                            timeout=API_TIMEOUT,
                                            gamespace=handler.env["gamespace"],
                                            account=handler.env["account"],
                                            extra_start_time=extra_start_time,
                                            extra_end_time=extra_end_time)
        except InternalError as e:
            raise APIError(e.code, e.body)

        return events
コード例 #9
0
ファイル: api.py プロジェクト: anthill-platform/anthill-exec
    async def acquire_name(self, kind, name, handler=None, *ignored):
        internal = Internal()

        try:
            profile = await internal.request(
                "social",
                "acquire_name",
                gamespace=handler.env["gamespace"],
                account=handler.env["account"],
                kind=kind,
                name=name)
        except InternalError as e:
            raise APIError(e.code, e.body)

        return profile
コード例 #10
0
ファイル: api.py プロジェクト: anthill-platform/anthill-exec
    async def query(self, query, limit=1000, handler=None, *ignored):

        if not validate_value(query, "json_dict"):
            raise APIError(400, "Query should be a JSON object")

        internal = Internal()

        try:
            results = await internal.request(
                "profile",
                "query_profiles",
                timeout=API_TIMEOUT,
                gamespace_id=handler.env["gamespace"],
                query=query,
                limit=limit)
        except InternalError as e:
            raise APIError(e.code, e.body)

        return results
コード例 #11
0
ファイル: api.py プロジェクト: anthill-platform/anthill-exec
    async def get(self, path="", handler=None, *ignored):

        if not isinstance(path, str):
            raise APIError(400, "Path should be a string")

        internal = Internal()

        try:
            profile = await internal.request(
                "profile",
                "get_my_profile",
                timeout=API_TIMEOUT,
                gamespace_id=handler.env["gamespace"],
                account_id=handler.env["account"],
                path=path)
        except InternalError as e:
            raise APIError(e.code, e.body)

        return profile
コード例 #12
0
ファイル: api.py プロジェクト: anthill-platform/anthill-exec
    async def use_code(self, key, handler=None, *ignored):

        internal = Internal()

        try:
            result = await internal.request("promo",
                                            "use_code",
                                            timeout=API_TIMEOUT,
                                            gamespace=handler.env["gamespace"],
                                            account=handler.env["account"],
                                            key=key)
        except InternalError as e:
            raise APIError(e.code, e.body)

        try:
            result = result["result"]
        except KeyError:
            raise APIError(500, "Response had no 'result' field.")

        return result
コード例 #13
0
ファイル: api.py プロジェクト: anthill-platform/anthill-exec
    async def send_batch(self,
                         sender,
                         messages,
                         authoritative=True,
                         handler=None,
                         *ignored):

        internal = Internal()

        try:
            await internal.request("message",
                                   "send_batch",
                                   timeout=API_TIMEOUT,
                                   gamespace=handler.env["gamespace"],
                                   sender=sender,
                                   messages=messages,
                                   authoritative=authoritative)
        except InternalError as e:
            raise APIError(e.code, e.body)
        return "OK"
コード例 #14
0
ファイル: api.py プロジェクト: anthill-platform/anthill-exec
    async def update_event_profile(self,
                                   event_id,
                                   profile,
                                   path=None,
                                   merge=True,
                                   handler=None):
        internal = Internal()

        try:
            events = await internal.request("event",
                                            "update_event_profile",
                                            event_id=event_id,
                                            profile=profile,
                                            path=path,
                                            merge=merge,
                                            timeout=API_TIMEOUT,
                                            gamespace=handler.env["gamespace"],
                                            account=handler.env["account"])
        except InternalError as e:
            raise APIError(e.code, e.body)

        return events
コード例 #15
0
ファイル: api.py プロジェクト: anthill-platform/anthill-exec
    async def get(self, name, handler=None, *ignored):

        if not isinstance(name, str):
            raise APIError(400, "name should be a string")

        key = "store:" + str(name)
        cached = handler.get_cache(key)
        if cached:
            return cached

        internal = Internal()

        try:
            config = await internal.request("store",
                                            "get_store",
                                            timeout=API_TIMEOUT,
                                            gamespace=handler.env["gamespace"],
                                            name=name)
        except InternalError as e:
            raise APIError(e.code, e.body)

        handler.set_cache(key, config)
        return config
コード例 #16
0
ファイル: api.py プロジェクト: anthill-platform/anthill-exec
    async def get(self, handler=None, *ignored):

        app_name = handler.env["application_name"]
        app_version = handler.env["application_version"]

        key = "config:" + str(app_name) + ":" + str(app_version)
        cached = handler.get_cache(key)
        if cached:
            return cached

        internal = Internal()

        try:
            info = await internal.request("config",
                                          "get_configuration",
                                          timeout=API_TIMEOUT,
                                          app_name=app_name,
                                          app_version=app_version,
                                          gamespace=handler.env["gamespace"])
        except InternalError as e:
            raise APIError(e.code, e.body)

        handler.set_cache(key, info)
        return info
コード例 #17
0
ファイル: blog.py プロジェクト: anthill-platform/anthill-blog
 def __init__(self, db, app):
     self.db = db
     self.app = app
     self.internal = Internal()
コード例 #18
0
 def __init__(self, application, request, **kwargs):
     super(SessionHandler, self).__init__(application, request, **kwargs)
     self.session = None
     self.internal = Internal()