Example #1
0
 def black_cards(self, code):
     req = requests.get(self.card_list_url.format(code=code))
     if req.status_code == requests.codes.ok:
         return BlackCard.from_json(req.json())
     elif req.status_code == requests.codes.not_found:
         err = "Black cards not found: {}".format(code)
         raise CardNotFoundError(err) from req.raise_for_status()
     else:
         err = "Error retrieving black cards: {}".format(code)
         raise CardRetrievalError(err) from req.raise_for_status()
Example #2
0
 def black_cards(self, code):
     req = requests.get(self.card_list_url.format(code=code))
     if req.status_code == requests.codes.ok:
         return BlackCard.from_json(req.json())
     elif req.status_code == requests.codes.not_found:
         err = "Black cards not found: {}".format(code)
         raise CardNotFoundError(err) from req.raise_for_status()
     else:
         err = "Error retrieving black cards: {}".format(code)
         raise CardRetrievalError(err) from req.raise_for_status()
Example #3
0
 def cards(self, code):
     req = yield from aiohtp.request("get", self.card_list_url.format(
         code=code))
     if req.status == 200:
         json = yield from req.json()
         return (BlackCard.from_json(json), WhiteCard.from_json(json))
     elif req.status == 404:
         err = "Cards not found: {}".format(code)
         raise CardNotFoundError(err)
     else:
         err = "Error retrieving cards: {} (code {})".format(code,
                                                             req.status)
         raise CardRetrievalError(err)
Example #4
0
    def from_json(cls, data_deck, data_cards):
        deckinfo = DeckInfo.from_json(data_deck)
        if "calls" in data_cards:
            blackcards = BlackCard.from_json(data_cards["calls"])
        else:
            blackcards = []

        if "responses" in data_cards:
            whitecards = WhiteCard.from_json(data_cards["responses"])
        else:
            whitecards = []

        return cls(deckinfo, blackcards, whitecards)
Example #5
0
    def from_json(cls, data_deck, data_cards):
        deckinfo = DeckInfo.from_json(data_deck)
        if "calls" in data_cards:
            blackcards = BlackCard.from_json(data_cards["calls"])
        else:
            blackcards = []

        if "responses" in data_cards:
            whitecards = WhiteCard.from_json(data_cards["responses"])
        else:
            whitecards = []

        return cls(deckinfo, blackcards, whitecards)
Example #6
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)
Example #7
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)