Move plan actions into Plan
This commit is contained in:
@@ -24,7 +24,7 @@ from ._quick_reply import (
|
|||||||
QuickReplyEmail,
|
QuickReplyEmail,
|
||||||
)
|
)
|
||||||
from ._poll import Poll, PollOption
|
from ._poll import Poll, PollOption
|
||||||
from ._plan import ACONTEXT, PlanData
|
from ._plan import PlanData
|
||||||
|
|
||||||
|
|
||||||
class Client:
|
class Client:
|
||||||
@@ -632,22 +632,6 @@ class Client:
|
|||||||
j = self._payload_post("/ajax/mercury/get_poll_options", data)
|
j = self._payload_post("/ajax/mercury/get_poll_options", data)
|
||||||
return [PollOption._from_graphql(m) for m in j]
|
return [PollOption._from_graphql(m) for m in j]
|
||||||
|
|
||||||
def fetch_plan_info(self, plan_id):
|
|
||||||
"""Fetch `Plan` object from the plan id.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
plan_id: Plan ID to fetch from
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
Plan: `Plan` object
|
|
||||||
|
|
||||||
Raises:
|
|
||||||
FBchatException: If request failed
|
|
||||||
"""
|
|
||||||
data = {"event_reminder_id": plan_id}
|
|
||||||
j = self._payload_post("/ajax/eventreminder", data)
|
|
||||||
return PlanData._from_fetch(self.session, j)
|
|
||||||
|
|
||||||
def _get_private_data(self):
|
def _get_private_data(self):
|
||||||
(j,) = self.graphql_requests(_graphql.from_doc_id("1868889766468115", {}))
|
(j,) = self.graphql_requests(_graphql.from_doc_id("1868889766468115", {}))
|
||||||
return j["viewer"]
|
return j["viewer"]
|
||||||
@@ -696,56 +680,6 @@ class Client:
|
|||||||
SEND METHODS
|
SEND METHODS
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def edit_plan(self, plan, new_plan):
|
|
||||||
"""Edit a plan.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
plan (Plan): Plan to edit
|
|
||||||
new_plan: New plan
|
|
||||||
|
|
||||||
Raises:
|
|
||||||
FBchatException: If request failed
|
|
||||||
"""
|
|
||||||
data = {
|
|
||||||
"event_reminder_id": plan.id,
|
|
||||||
"delete": "false",
|
|
||||||
"date": _util.datetime_to_seconds(new_plan.time),
|
|
||||||
"location_name": new_plan.location or "",
|
|
||||||
"location_id": new_plan.location_id or "",
|
|
||||||
"title": new_plan.title,
|
|
||||||
"acontext": ACONTEXT,
|
|
||||||
}
|
|
||||||
j = self._payload_post("/ajax/eventreminder/submit", data)
|
|
||||||
|
|
||||||
def delete_plan(self, plan):
|
|
||||||
"""Delete a plan.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
plan: Plan to delete
|
|
||||||
|
|
||||||
Raises:
|
|
||||||
FBchatException: If request failed
|
|
||||||
"""
|
|
||||||
data = {"event_reminder_id": plan.id, "delete": "true", "acontext": ACONTEXT}
|
|
||||||
j = self._payload_post("/ajax/eventreminder/submit", data)
|
|
||||||
|
|
||||||
def change_plan_participation(self, plan, take_part=True):
|
|
||||||
"""Change participation in a plan.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
plan: Plan to take part in or not
|
|
||||||
take_part: Whether to take part in the plan
|
|
||||||
|
|
||||||
Raises:
|
|
||||||
FBchatException: If request failed
|
|
||||||
"""
|
|
||||||
data = {
|
|
||||||
"event_reminder_id": plan.id,
|
|
||||||
"guest_state": "GOING" if take_part else "DECLINED",
|
|
||||||
"acontext": ACONTEXT,
|
|
||||||
}
|
|
||||||
j = self._payload_post("/ajax/eventreminder/rsvp", data)
|
|
||||||
|
|
||||||
def update_poll_vote(self, poll_id, option_ids=[], new_options=[]):
|
def update_poll_vote(self, poll_id, option_ids=[], new_options=[]):
|
||||||
"""Update a poll vote.
|
"""Update a poll vote.
|
||||||
|
|
||||||
|
@@ -1,7 +1,8 @@
|
|||||||
import attr
|
import attr
|
||||||
|
import datetime
|
||||||
import json
|
import json
|
||||||
from ._core import attrs_default, Enum
|
from ._core import attrs_default, Enum
|
||||||
from . import _util, _session
|
from . import _exception, _util, _session
|
||||||
|
|
||||||
|
|
||||||
class GuestStatus(Enum):
|
class GuestStatus(Enum):
|
||||||
@@ -26,6 +27,80 @@ class Plan:
|
|||||||
#: The plan's unique identifier.
|
#: The plan's unique identifier.
|
||||||
id = attr.ib(converter=str)
|
id = attr.ib(converter=str)
|
||||||
|
|
||||||
|
def fetch(self) -> "PlanData":
|
||||||
|
"""Fetch fresh `PlanData` object."""
|
||||||
|
data = {"event_reminder_id": self.id}
|
||||||
|
j = self.session._payload_post("/ajax/eventreminder", data)
|
||||||
|
return PlanData._from_fetch(self.session, j)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _create(
|
||||||
|
cls,
|
||||||
|
thread,
|
||||||
|
name: str,
|
||||||
|
at: datetime.datetime,
|
||||||
|
location_name: str = None,
|
||||||
|
location_id: str = None,
|
||||||
|
):
|
||||||
|
data = {
|
||||||
|
"event_type": "EVENT",
|
||||||
|
"event_time": _util.datetime_to_seconds(at),
|
||||||
|
"title": name,
|
||||||
|
"thread_id": thread.id,
|
||||||
|
"location_id": location_id or "",
|
||||||
|
"location_name": location_name or "",
|
||||||
|
"acontext": ACONTEXT,
|
||||||
|
}
|
||||||
|
j = thread.session._payload_post("/ajax/eventreminder/create", data)
|
||||||
|
if "error" in j:
|
||||||
|
raise _exception.FBchatFacebookError(
|
||||||
|
"Failed creating plan: {}".format(j["error"]),
|
||||||
|
fb_error_message=j["error"],
|
||||||
|
)
|
||||||
|
|
||||||
|
def edit(
|
||||||
|
self,
|
||||||
|
name: str,
|
||||||
|
at: datetime.datetime,
|
||||||
|
location_name: str = None,
|
||||||
|
location_id: str = None,
|
||||||
|
):
|
||||||
|
"""Edit the plan.
|
||||||
|
|
||||||
|
# TODO: Arguments
|
||||||
|
"""
|
||||||
|
data = {
|
||||||
|
"event_reminder_id": self.id,
|
||||||
|
"delete": "false",
|
||||||
|
"date": _util.datetime_to_seconds(at),
|
||||||
|
"location_name": location_name or "",
|
||||||
|
"location_id": location_id or "",
|
||||||
|
"title": name,
|
||||||
|
"acontext": ACONTEXT,
|
||||||
|
}
|
||||||
|
j = self.session._payload_post("/ajax/eventreminder/submit", data)
|
||||||
|
|
||||||
|
def delete(self):
|
||||||
|
"""Delete the plan."""
|
||||||
|
data = {"event_reminder_id": self.id, "delete": "true", "acontext": ACONTEXT}
|
||||||
|
j = self.session._payload_post("/ajax/eventreminder/submit", data)
|
||||||
|
|
||||||
|
def _change_participation(self):
|
||||||
|
data = {
|
||||||
|
"event_reminder_id": self.id,
|
||||||
|
"guest_state": "GOING" if take_part else "DECLINED",
|
||||||
|
"acontext": ACONTEXT,
|
||||||
|
}
|
||||||
|
j = self.session._payload_post("/ajax/eventreminder/rsvp", data)
|
||||||
|
|
||||||
|
def participate(self):
|
||||||
|
"""Set yourself as GOING/participating to the plan."""
|
||||||
|
self._change_participation(True)
|
||||||
|
|
||||||
|
def decline(self):
|
||||||
|
"""Set yourself as having DECLINED the plan."""
|
||||||
|
self._change_participation(False)
|
||||||
|
|
||||||
|
|
||||||
@attrs_default
|
@attrs_default
|
||||||
class PlanData(Plan):
|
class PlanData(Plan):
|
||||||
|
@@ -381,24 +381,10 @@ class ThreadABC(metaclass=abc.ABCMeta):
|
|||||||
# TODO: Arguments
|
# TODO: Arguments
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
title: Name of the new plan
|
name: Name of the new plan
|
||||||
at: When the plan is for
|
at: When the plan is for
|
||||||
"""
|
"""
|
||||||
data = {
|
return _plan.Plan._create(self, name, at, location_name, location_id)
|
||||||
"event_type": "EVENT",
|
|
||||||
"event_time": _util.datetime_to_seconds(at),
|
|
||||||
"title": name,
|
|
||||||
"thread_id": self.id,
|
|
||||||
"location_id": location_id or "",
|
|
||||||
"location_name": location_name or "",
|
|
||||||
"acontext": _plan.ACONTEXT,
|
|
||||||
}
|
|
||||||
j = self.session._payload_post("/ajax/eventreminder/create", data)
|
|
||||||
if "error" in j:
|
|
||||||
raise _exception.FBchatFacebookError(
|
|
||||||
"Failed creating plan: {}".format(j["error"]),
|
|
||||||
fb_error_message=j["error"],
|
|
||||||
)
|
|
||||||
|
|
||||||
def create_poll(self, question: str, options=Iterable[Tuple[str, bool]]):
|
def create_poll(self, question: str, options=Iterable[Tuple[str, bool]]):
|
||||||
"""Create poll in a thread.
|
"""Create poll in a thread.
|
||||||
|
Reference in New Issue
Block a user