Ejemplo n.º 1
0
    def from_json(cls, data):
        if "responses" in data:
            return [cls.from_json(c) for c in data["responses"]]

        if data["id"] == "not_found":
            raise CardNotFoundError(data["message"])

        return cls(isoformat(data["created_at"]), data["id"], data["text"])
Ejemplo n.º 2
0
    def from_json(cls, data):
        if "responses" in data:
            return [cls.from_json(c) for c in data["responses"]]

        if data["id"] == "not_found":
            raise CardNotFoundError(data["message"])

        return cls(isoformat(data["created_at"]), data["id"], data["text"])
Ejemplo n.º 3
0
    def from_json(cls, data):
        if "id" in data and data["id"] == "not_found":
            raise DeckInfoNotFoundError(data["message"])

        code = data["code"]
        name = data["name"]
        description = data.get("description", None)
        category = data["category"]

        blackcount = int(data["call_count"])
        whitecount = int(data["response_count"])

        if "sample_calls" in data:
            blacksample = BlackCard.from_json(data["sample_calls"])
        else:
            blacksample = None

        if "sample_responses" in data:
            whitesample = WhiteCard.from_json(data["sample_responses"])
        else:
            whitesample = None

        unlisted = data.get("unlisted", False)

        author = Author(data["author"]["username"], data["author"]["id"])
        copyright = Copyright(data["external_copyright"],
                              data.get("copyright_holder_url", None))

        created = isoformat(data["created_at"])
        updated = isoformat(data["updated_at"])

        rating = float(data["rating"])

        return cls(code, name, description, category, blackcount, whitecount,
                   blacksample, whitesample, unlisted, author, copyright,
                   created, updated, rating)
Ejemplo n.º 4
0
    def from_json(cls, data):
        if "id" in data and data["id"] == "not_found":
            raise DeckInfoNotFoundError(data["message"])

        code = data["code"]
        name = data["name"]
        description = data.get("description", None)
        category = data["category"]

        blackcount = int(data["call_count"])
        whitecount = int(data["response_count"])

        if "sample_calls" in data:
            blacksample = BlackCard.from_json(data["sample_calls"])
        else:
            blacksample = None

        if "sample_responses" in data:
            whitesample = WhiteCard.from_json(data["sample_responses"])
        else:
            whitesample = None

        unlisted = data.get("unlisted", False)

        author = Author(data["author"]["username"], data["author"]["id"])
        copyright = Copyright(data["external_copyright"],
                              data.get("copyright_holder_url", None))

        created = isoformat(data["created_at"])
        updated = isoformat(data["updated_at"])

        rating = float(data["rating"])

        return cls(code, name, description, category, blackcount, whitecount,
                   blacksample, whitesample, unlisted, author, copyright,
                   created, updated, rating)