示例#1
0
class SessionAPI(object):
    """
    A thin wrapper for the the session portion of the Mojang API

    References
    ----------
    * http://wiki.vg/Mojang_API
    """

    def __init__(self, auth, host=DEFAULT_MOJANG_SESSION_HOST):
        self.auth = auth
        self.api = APIHost(host)

        if self.auth.accessToken:
            bearer =  "Bearer " + self.auth.accessToken
            self.api.headers["Authorization"] = bearer


    def profile_info(self, uuid):
        data = self.api.get("/session/minecraft/profile/%s" % uuid)

        if data:
            props = data.get("properties", ())
            for prop in props:
                if prop["name"] == "textures":
                    # we'll transform this particular named property
                    # value since we know it's actually JSON
                    val = prop.get("value")
                    val = b64decode(val)
                    val = loads(val)
                    prop["value"] = val
                    break

        return data


    def blocked_servers(self):
        return self.api.get("/blockedservers")
示例#2
0
class StatusAPI(object):
    """
    A thin wrapper for the the status portion of the Mojang API

    References
    ----------
    * http://wiki.vg/Mojang_API
    """

    def __init__(self, auth, host=DEFAULT_MOJANG_STATUS_HOST):
        self.auth = auth # unused, maybe useful in the future.
        self.api = APIHost(host)


    def check(self):
        resp = self.api.get("/check")
        return resp
示例#3
0
class MojangAPI(object):
    """
    A thin wrapper for the the core portion of the Mojang API

    References
    ----------
    * http://wiki.vg/Mojang_API
    """

    def __init__(self, auth, host=DEFAULT_MOJANG_API_HOST):
        self.auth = auth
        self.api = APIHost(host)

        if self.auth.accessToken:
            bearer =  "Bearer " + self.auth.accessToken
            self.api.headers["Authorization"] = bearer


    def username_to_uuid(self, username, at_time=0):
        return self.api.get("/users/profiles/minecraft/%s?at=%i" %
                            (username, at_time))


    def uuid_name_history(self, uuid):
        return self.api.get("/user/profiles/%s/names" % uuid)


    def playernames_to_uuids(self, playernames):
        return self.api.post("/profiles/minecraft", list(playernames))


    def change_skin(self, uuid, skin_url, slim=False):
        payload = {"model": "slim" if slim else "",
                   "url": skin_url}

        return self.api.post_encoded("/user/profile/%s/skin" % uuid)


    def upload_skin(self, uuid, skin_stream, slim=False):
        payload = {"model": "slim" if slim else "",
                   "file": ("harambe.png", skin_stream, "image/png")}

        return self.api.post_form("/user/profile/%s/skin" % uuid, payload)


    def upload_skin_filename(self, uuid, skin_filename, slim=False):
        with open(skin_filename) as skin_stream:
            return upload_skin(self, uuid, skin_stream, slim)


    def reset_skin(self, uuid):
        return self.api.delete("/user/profile/%s/skin" % uuid)


    def whoami(self):
        return self.api.get("/user")


    def statistics(self, which=DEFAULT_STATISTICS):
        which = {"metricKeys": list(which)}
        return self.api.post("/orders/statistics", which)
示例#4
0
class RealmsAPI(object):
    """
    A thin wrapper for the Mojang Realms API

    References
    ----------
    * http://wiki.vg/Realms_API
    """

    def __init__(self, auth, host=DEFAULT_REALMS_HOST,
                 version=DEFAULT_REALMS_VERSION):

        # compose the necessary cookies from data in the auth object
        self.auth = auth
        sid =  "token:%s:%s" % (auth.accessToken, auth.selectedProfile["id"])
        user = auth.selectedProfile["name"]

        self.api = APIHost(host)
        self.api.cookies.set("sid", sid)
        self.api.cookies.set("user", user)
        self.api.cookies.set("version", version)


    def mco_available(self):
        return self.api.get("/mco/available")


    def mco_client_outdated(self):
        return self.api.get("/mco/client/outdated")


    def mco_tos_agree(self):
        return self.api.post("/mco/tos/agreed")


    def realm_list(self):
        """
        List the realms available for the given account auth
        """

        return self.api.get("/worlds")


    def realm_info(self, realm_id):
        """
        Information about a specific realm by ID
        """

        return self.api.get("/worlds/%i" % realm_id)


    def realm_join(self, realm_id):
        """
        Wakes up a realm so that it can be joined, returns a string
        specifying the IP_ADDRESS:PORT of the running server
        """

        return self.api.get("/worlds/%i/join" % realm_id)


    def realm_backups(self, realm_id):
        """
        Show the backups available for the given realm ID
        """

        return self.api.get("/worlds/%i/backups" % realm_id)


    def realm_world_url(self, realm_id, world):
        """
        Show the download URL for the latest world backup for the given
        realm ID
        """

        return self.api.get("/worlds/%i/slot/%i/download" % (realm_id, world))


    def realm_ops_list(self, realm_id):
        return self.api.get("/ops/%i" % realm_id)


    def realm_subscription(self, realm_id):
        return self.api.get("/subscriptions/%i" % realm_id)