Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -577,10 +577,7 @@ Event
- reply\_token
- postback: Postback
- data
- params: Params
- date
- time
- datetime
- params: dict
- BeaconEvent
- type
- timestamp
Expand Down
1 change: 0 additions & 1 deletion linebot/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
PostbackEvent,
BeaconEvent,
Postback,
Params,
Beacon,
)
from .imagemap import ( # noqa
Expand Down
39 changes: 2 additions & 37 deletions linebot/models/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,50 +269,15 @@ def __init__(self, data=None, params=None, **kwargs):
"""__init__ method.

:param str data: Postback data
:param params: JSON object with the date and time
:param dict params: JSON object with the date and time
selected by a user through a datetime picker action.
Only returned for postback actions via the datetime picker.
:type params: T <= :py:class:`linebot.models.events.Params`
:param kwargs:
"""
super(Postback, self).__init__(**kwargs)

self.data = data
self.params = self.get_or_new_from_json_dict(
params, Params
)


class Params(Base):
"""Params.

Object with the date and time selected by a user
through a datetime picker action.
The format for the full-date, time-hour, and time-minute
as shown below follow the RFC3339 protocol.

https://devdocs.line.me/en/#postback-params-object
"""

def __init__(self, date=None, time=None, datetime=None, **kwargs):
"""__init__ method.

:param str date: Date selected by user.
Only included in the date mode.
Format: full-date
:param str time: Time selected by the user.
Only included in the time mode.
Format: time-hour":"time-minute
:param str datetime: Date and time selected by the user.
Only included in the datetime mode.
Format: full-date"T"time-hour":"time-minute
:param kwargs:
"""
super(Params, self).__init__(**kwargs)

self.date = date
self.time = time
self.datetime = datetime
self.params = params


class Beacon(Base):
Expand Down
14 changes: 5 additions & 9 deletions tests/test_webhook.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

import os
import unittest

from builtins import open

from linebot import (
SignatureValidator, WebhookParser, WebhookHandler
)
Expand All @@ -26,8 +26,7 @@
LeaveEvent, PostbackEvent, BeaconEvent,
TextMessage, ImageMessage, VideoMessage, AudioMessage,
LocationMessage, StickerMessage,
SourceUser, SourceRoom, SourceGroup,
Params,
SourceUser, SourceRoom, SourceGroup
)


Expand Down Expand Up @@ -266,8 +265,7 @@ def test_parse(self):
self.assertEqual(events[15].source.user_id, 'U206d25c2ea6bd87c17655609a1c37cb8')
self.assertEqual(events[15].source.sender_id, 'U206d25c2ea6bd87c17655609a1c37cb8')
self.assertEqual(events[15].postback.data, 'action=buyItem&itemId=123123&color=red')
self.assertIsInstance(events[15].postback.params, Params)
self.assertEqual(events[15].postback.params.date, '2013-04-01')
self.assertEqual(events[15].postback.params['date'], '2013-04-01')

# PostbackEvent, SourceUser, with date params
self.assertIsInstance(events[16], PostbackEvent)
Expand All @@ -279,8 +277,7 @@ def test_parse(self):
self.assertEqual(events[16].source.user_id, 'U206d25c2ea6bd87c17655609a1c37cb8')
self.assertEqual(events[16].source.sender_id, 'U206d25c2ea6bd87c17655609a1c37cb8')
self.assertEqual(events[16].postback.data, 'action=buyItem&itemId=123123&color=red')
self.assertIsInstance(events[15].postback.params, Params)
self.assertEqual(events[16].postback.params.time, '10:00')
self.assertEqual(events[16].postback.params['time'], '10:00')

# PostbackEvent, SourceUser, with date params
self.assertIsInstance(events[17], PostbackEvent)
Expand All @@ -292,8 +289,7 @@ def test_parse(self):
self.assertEqual(events[17].source.user_id, 'U206d25c2ea6bd87c17655609a1c37cb8')
self.assertEqual(events[17].source.sender_id, 'U206d25c2ea6bd87c17655609a1c37cb8')
self.assertEqual(events[17].postback.data, 'action=buyItem&itemId=123123&color=red')
self.assertIsInstance(events[15].postback.params, Params)
self.assertEqual(events[17].postback.params.datetime, '2013-04-01T10:00')
self.assertEqual(events[17].postback.params['datetime'], '2013-04-01T10:00')


class TestWebhookHandler(unittest.TestCase):
Expand Down