def from_json(cls, data): totaldecks = data["total"] results = data["results"] count = results["count"] offset = results["offset"] data = [DeckInfo.from_json(d) for d in results["data"]] return cls(totaldecks, count, offset, data)
def deck_info(self, code): req = requests.get(self.deck_info_url.format(code=code)) if req.status_code == requests.codes.ok: return DeckInfo.from_json(req.json()) elif req.status_code == requests.codes.not_found: err = "Deck not found: {}".format(code) raise DeckInfoNotFoundError(err) from req.raise_for_status() else: err = "Error retrieving deck: {}".format(code) raise DeckInfoRetrievalError(err) from req.raise_for_status()
class CardcastAPI(CardcastAPIBase): """A :py:class:`~pycardcast.net.CardcastAPIBase` implementation using the aiohttp library. All the methods here are coroutines except for one: :py:meth:`~pycardcast.net.aiohttp.CardcastAPI.search_iter`. """ @asyncio.coroutine def deck_info(self, code): req = yield from aiohttp.request("get", self.deck_info_url.format code=code)) if req.status == 200: json=yield from req.json() return DeckInfo.from_json(json) elif req.status == 404: err="Deck not found: {}".format(code) raise DeckInfoNotFoundError(err) else: err="Error retrieving deck: {} (code {})".format(code, req.status) raise DeckInfoRetrievalError(err) @asyncio.coroutine def white_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 WhiteCard.from_json(json)