Move graphql_to_poll_option -> PollOption._from_graphql
This commit is contained in:
@@ -1248,7 +1248,7 @@ class Client(object):
|
|||||||
self.req_url.GET_POLL_OPTIONS, data, fix_request=True, as_json=True
|
self.req_url.GET_POLL_OPTIONS, data, fix_request=True, as_json=True
|
||||||
)
|
)
|
||||||
|
|
||||||
return [graphql_to_poll_option(m) for m in j["payload"]]
|
return [PollOption._from_graphql(m) for m in j["payload"]]
|
||||||
|
|
||||||
def fetchPlanInfo(self, plan_id):
|
def fetchPlanInfo(self, plan_id):
|
||||||
"""
|
"""
|
||||||
|
@@ -220,35 +220,13 @@ def graphql_to_live_location(a):
|
|||||||
def graphql_to_poll(a):
|
def graphql_to_poll(a):
|
||||||
rtn = Poll(
|
rtn = Poll(
|
||||||
title=a.get("title") if a.get("title") else a.get("text"),
|
title=a.get("title") if a.get("title") else a.get("text"),
|
||||||
options=[graphql_to_poll_option(m) for m in a.get("options")],
|
options=[PollOption._from_graphql(m) for m in a.get("options")],
|
||||||
)
|
)
|
||||||
rtn.uid = int(a["id"])
|
rtn.uid = int(a["id"])
|
||||||
rtn.options_count = a.get("total_count")
|
rtn.options_count = a.get("total_count")
|
||||||
return rtn
|
return rtn
|
||||||
|
|
||||||
|
|
||||||
def graphql_to_poll_option(a):
|
|
||||||
if a.get("viewer_has_voted") is None:
|
|
||||||
vote = None
|
|
||||||
elif isinstance(a["viewer_has_voted"], bool):
|
|
||||||
vote = a["viewer_has_voted"]
|
|
||||||
else:
|
|
||||||
vote = a["viewer_has_voted"] == "true"
|
|
||||||
rtn = PollOption(text=a.get("text"), vote=vote)
|
|
||||||
rtn.uid = int(a["id"])
|
|
||||||
rtn.voters = (
|
|
||||||
[m.get("node").get("id") for m in a.get("voters").get("edges")]
|
|
||||||
if isinstance(a.get("voters"), dict)
|
|
||||||
else a.get("voters")
|
|
||||||
)
|
|
||||||
rtn.votes_count = (
|
|
||||||
a.get("voters").get("count")
|
|
||||||
if isinstance(a.get("voters"), dict)
|
|
||||||
else a.get("total_count")
|
|
||||||
)
|
|
||||||
return rtn
|
|
||||||
|
|
||||||
|
|
||||||
def graphql_to_plan(a):
|
def graphql_to_plan(a):
|
||||||
if a.get("event_members"):
|
if a.get("event_members"):
|
||||||
rtn = Plan(
|
rtn = Plan(
|
||||||
|
@@ -32,3 +32,27 @@ class PollOption(object):
|
|||||||
voters = attr.ib(None, init=False)
|
voters = attr.ib(None, init=False)
|
||||||
#: Votes count
|
#: Votes count
|
||||||
votes_count = attr.ib(None, init=False)
|
votes_count = attr.ib(None, init=False)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _from_graphql(cls, data):
|
||||||
|
if data.get("viewer_has_voted") is None:
|
||||||
|
vote = None
|
||||||
|
elif isinstance(data["viewer_has_voted"], bool):
|
||||||
|
vote = data["viewer_has_voted"]
|
||||||
|
else:
|
||||||
|
vote = data["viewer_has_voted"] == "true"
|
||||||
|
return cls(
|
||||||
|
uid=int(data["id"]),
|
||||||
|
text=data.get("text"),
|
||||||
|
vote=vote,
|
||||||
|
voters=(
|
||||||
|
[m.get("node").get("id") for m in data.get("voters").get("edges")]
|
||||||
|
if isinstance(data.get("voters"), dict)
|
||||||
|
else data.get("voters")
|
||||||
|
),
|
||||||
|
votes_count=(
|
||||||
|
data.get("voters").get("count")
|
||||||
|
if isinstance(data.get("voters"), dict)
|
||||||
|
else data.get("total_count")
|
||||||
|
),
|
||||||
|
)
|
||||||
|
@@ -14,7 +14,6 @@ from ._graphql import (
|
|||||||
graphql_to_subattachment,
|
graphql_to_subattachment,
|
||||||
graphql_to_live_location,
|
graphql_to_live_location,
|
||||||
graphql_to_poll,
|
graphql_to_poll,
|
||||||
graphql_to_poll_option,
|
|
||||||
graphql_to_plan,
|
graphql_to_plan,
|
||||||
graphql_to_quick_reply,
|
graphql_to_quick_reply,
|
||||||
graphql_to_message,
|
graphql_to_message,
|
||||||
|
Reference in New Issue
Block a user