Skip to content

Commit 4211f3c

Browse files
be-haseokdtsk
authored andcommitted
Change 'postback.params' type from python object to dict. (#64)
1 parent d1c2ba7 commit 4211f3c

File tree

4 files changed

+8
-51
lines changed

4 files changed

+8
-51
lines changed

README.rst

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -577,10 +577,7 @@ Event
577577
- reply\_token
578578
- postback: Postback
579579
- data
580-
- params: Params
581-
- date
582-
- time
583-
- datetime
580+
- params: dict
584581
- BeaconEvent
585582
- type
586583
- timestamp

linebot/models/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
PostbackEvent,
3232
BeaconEvent,
3333
Postback,
34-
Params,
3534
Beacon,
3635
)
3736
from .imagemap import ( # noqa

linebot/models/events.py

Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -269,50 +269,15 @@ def __init__(self, data=None, params=None, **kwargs):
269269
"""__init__ method.
270270
271271
:param str data: Postback data
272-
:param params: JSON object with the date and time
272+
:param dict params: JSON object with the date and time
273273
selected by a user through a datetime picker action.
274274
Only returned for postback actions via the datetime picker.
275-
:type params: T <= :py:class:`linebot.models.events.Params`
276275
:param kwargs:
277276
"""
278277
super(Postback, self).__init__(**kwargs)
279278

280279
self.data = data
281-
self.params = self.get_or_new_from_json_dict(
282-
params, Params
283-
)
284-
285-
286-
class Params(Base):
287-
"""Params.
288-
289-
Object with the date and time selected by a user
290-
through a datetime picker action.
291-
The format for the full-date, time-hour, and time-minute
292-
as shown below follow the RFC3339 protocol.
293-
294-
https://devdocs.line.me/en/#postback-params-object
295-
"""
296-
297-
def __init__(self, date=None, time=None, datetime=None, **kwargs):
298-
"""__init__ method.
299-
300-
:param str date: Date selected by user.
301-
Only included in the date mode.
302-
Format: full-date
303-
:param str time: Time selected by the user.
304-
Only included in the time mode.
305-
Format: time-hour":"time-minute
306-
:param str datetime: Date and time selected by the user.
307-
Only included in the datetime mode.
308-
Format: full-date"T"time-hour":"time-minute
309-
:param kwargs:
310-
"""
311-
super(Params, self).__init__(**kwargs)
312-
313-
self.date = date
314-
self.time = time
315-
self.datetime = datetime
280+
self.params = params
316281

317282

318283
class Beacon(Base):

tests/test_webhook.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616

1717
import os
1818
import unittest
19-
2019
from builtins import open
20+
2121
from linebot import (
2222
SignatureValidator, WebhookParser, WebhookHandler
2323
)
@@ -26,8 +26,7 @@
2626
LeaveEvent, PostbackEvent, BeaconEvent,
2727
TextMessage, ImageMessage, VideoMessage, AudioMessage,
2828
LocationMessage, StickerMessage,
29-
SourceUser, SourceRoom, SourceGroup,
30-
Params,
29+
SourceUser, SourceRoom, SourceGroup
3130
)
3231

3332

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

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

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

298294

299295
class TestWebhookHandler(unittest.TestCase):

0 commit comments

Comments
 (0)