Skip to content

Commit f1917e3

Browse files
committed
Rename package and modify related code. Rewrite README.md. Fix simple-server-echo (for python2 and 3 issue)
1 parent a046454 commit f1917e3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+133
-83
lines changed

MANIFEST.in

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
include LICENSE
22
include requirements.txt
3-
include requirements-test.txt
3+
include requirements-test.txt
4+
include requirements-dev.txt
5+
include tox.ini

README.md

+17-10
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ ja: https://devdocs.line.me/ja/
1313
## Install
1414

1515
```
16-
$ pip install line_bot
16+
$ pip install line-bot-sdk
1717
```
1818

1919
## Synopsis
@@ -23,9 +23,14 @@ Usage is:
2323
```python
2424
from flask import Flask, request, abort
2525

26-
from line_bot import (
27-
LineBotApi, MessageEvent, TextMessage, TextSendMessage,
28-
WebhookParser, InvalidSignatureError
26+
from linebot import (
27+
LineBotApi, WebhookHandler
28+
)
29+
from linebot.exceptions import (
30+
InvalidSignatureError
31+
)
32+
from linebot.models import (
33+
MessageEvent, TextMessage, TextSendMessage,
2934
)
3035

3136
app = Flask(__name__)
@@ -70,7 +75,7 @@ def handle_message(event):
7075
Create a new LineBotApi instance.
7176

7277
```python
73-
line_bot_api = LineBotApi('YOUR_CHANNEL_ACCESS_TOKEN')
78+
line_bot_api = linebot.LineBotApi('YOUR_CHANNEL_ACCESS_TOKEN')
7479
```
7580

7681
You can override `timeout` value at each methods.
@@ -160,16 +165,16 @@ try:
160165
'to',
161166
TextSendMessage(text='Hello World!')
162167
)
163-
except LineBotApiError as e:
168+
except linebot.LineBotApiError as e:
164169
print(e.error.message)
165170
print(e.error.details)
166171
```
167172

168173
### Send message object
169174

170-
How to create Send message object
175+
https://devdocs.line.me/en/#send-message-object
171176

172-
(See also https://devdocs.line.me/en/#send-message-object)
177+
These following class in `linebot.models` package.
173178

174179
#### TextSendMessage
175180

@@ -360,7 +365,7 @@ carousel_template_message = TemplateSendMessage(
360365
#### \__init__(self, channel_secret)
361366

362367
```python
363-
parser = WebhookParser('YOUR_CHANNEL_SECRET')
368+
parser = linebot.WebhookParser('YOUR_CHANNEL_SECRET')
364369
```
365370

366371
#### parse(self, body, signature)
@@ -382,7 +387,7 @@ for event in events:
382387
#### \__init__(self, channel_secret)
383388

384389
```python
385-
handler = WebhookHandler('YOUR_CHANNEL_SECRET')
390+
handler = linebot.WebhookHandler('YOUR_CHANNEL_SECRET')
386391
```
387392

388393
#### handle(self, body, signature)
@@ -431,6 +436,8 @@ There is no handler for event, this default handler method is called.
431436

432437
https://devdocs.line.me/en/#webhooks
433438

439+
These following class in `linebot.models` package.
440+
434441
#### Event
435442

436443
* MessageEvent

examples/flask-echo/README.md

+9-4
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,21 @@ Sample echo-bot using [Flask](http://flask.pocoo.org/)
44

55
## Getting Start
66

7-
WebhookParser sample
8-
97
```
8+
$ export LINE_CHANNEL_SECRET=YOUR_LINE_CHANNEL_SECRET
9+
$ export LINE_CHANNEL_ACCESS_TOKEN=YOUR_LINE_CHANNEL_ACCESS_TOKEN
10+
1011
$ pip install -r requirements.txt
12+
```
13+
14+
Run WebhookParser sample
15+
16+
```
1117
$ python app.py
1218
```
1319

14-
WebhookHandler sample
20+
Run WebhookHandler sample
1521

1622
```
17-
$ pip install -r requirements.txt
1823
$ python app_with_handler.py
1924
```

examples/flask-echo/app.py

+12-6
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,33 @@
1+
# -*- coding: utf-8 -*-
2+
from __future__ import unicode_literals
3+
14
import os
5+
import sys
26
from argparse import ArgumentParser
37

48
from flask import Flask, request, abort
59

6-
from line_bot import (
10+
from linebot import (
711
LineBotApi, WebhookParser
812
)
9-
from line_bot.exceptions import (
13+
from linebot.exceptions import (
1014
InvalidSignatureError
1115
)
12-
from line_bot.models import (
16+
from linebot.models import (
1317
MessageEvent, TextMessage, TextSendMessage,
1418
)
1519

1620
app = Flask(__name__)
1721

1822
# get channel_secret and channel_access_token from your environment variable
1923
channel_secret = os.getenv('LINE_CHANNEL_SECRET', None)
20-
if channel_secret is None:
21-
print('Specify LINE_CHANNEL_SECRET as env.')
2224
channel_access_token = os.getenv('LINE_CHANNEL_ACCESS_TOKEN', None)
25+
if channel_secret is None:
26+
print('Specify LINE_CHANNEL_SECRET as environment variable.')
27+
sys.exit(1)
2328
if channel_access_token is None:
24-
print('Specify LINE_CHANNEL_ACCESS_TOKEN as env.')
29+
print('Specify LINE_CHANNEL_ACCESS_TOKEN as environment variable.')
30+
sys.exit(1)
2531

2632
line_bot_api = LineBotApi(channel_access_token)
2733
parser = WebhookParser(channel_secret)

examples/flask-echo/app_with_handler.py

+9-6
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,30 @@
11
import os
2+
import sys
23
from argparse import ArgumentParser
34

45
from flask import Flask, request, abort
56

6-
from line_bot import (
7+
from linebot import (
78
LineBotApi, WebhookHandler
89
)
9-
from line_bot.exceptions import (
10+
from linebot.exceptions import (
1011
InvalidSignatureError
1112
)
12-
from line_bot.models import (
13+
from linebot.models import (
1314
MessageEvent, TextMessage, TextSendMessage,
1415
)
1516

1617
app = Flask(__name__)
1718

1819
# get channel_secret and channel_access_token from your environment variable
1920
channel_secret = os.getenv('LINE_CHANNEL_SECRET', None)
20-
if channel_secret is None:
21-
print('Specify LINE_CHANNEL_SECRET as env.')
2221
channel_access_token = os.getenv('LINE_CHANNEL_ACCESS_TOKEN', None)
22+
if channel_secret is None:
23+
print('Specify LINE_CHANNEL_SECRET as environment variable.')
24+
sys.exit(1)
2325
if channel_access_token is None:
24-
print('Specify LINE_CHANNEL_ACCESS_TOKEN as env.')
26+
print('Specify LINE_CHANNEL_ACCESS_TOKEN as environment variable.')
27+
sys.exit(1)
2528

2629
line_bot_api = LineBotApi(channel_access_token)
2730
handler = WebhookHandler(channel_secret)

examples/flask-echo/requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
line_bot
1+
line-bot-sdk
22
flask

examples/flask-kitchensink/README.md

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ Sample bot using [Flask](http://flask.pocoo.org/)
55
## Getting Start
66

77
```
8+
$ export LINE_CHANNEL_SECRET=YOUR_LINE_CHANNEL_SECRET
9+
$ export LINE_CHANNEL_ACCESS_TOKEN=YOUR_LINE_CHANNEL_ACCESS_TOKEN
10+
811
$ pip install -r requirements.txt
12+
913
$ python app.py
1014
```

examples/flask-kitchensink/app.py

+9-6
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,18 @@
33

44
import errno
55
import os
6+
import sys
67
from argparse import ArgumentParser
78

89
from flask import Flask, request, abort
910

10-
from line_bot import (
11+
from linebot import (
1112
LineBotApi, WebhookHandler
1213
)
13-
from line_bot.exceptions import (
14+
from linebot.exceptions import (
1415
InvalidSignatureError
1516
)
16-
from line_bot.models import (
17+
from linebot.models import (
1718
MessageEvent, TextMessage, TextSendMessage,
1819
SourceUser, SourceGroup, SourceRoom,
1920
TemplateSendMessage, ConfirmTemplate, MessageTemplateAction,
@@ -28,11 +29,13 @@
2829

2930
# get channel_secret and channel_access_token from your environment variable
3031
channel_secret = os.getenv('LINE_CHANNEL_SECRET', None)
31-
if channel_secret is None:
32-
print('Specify LINE_CHANNEL_SECRET as env.')
3332
channel_access_token = os.getenv('LINE_CHANNEL_ACCESS_TOKEN', None)
33+
if channel_secret is None:
34+
print('Specify LINE_CHANNEL_SECRET as environment variable.')
35+
sys.exit(1)
3436
if channel_access_token is None:
35-
print('Specify LINE_CHANNEL_ACCESS_TOKEN as env.')
37+
print('Specify LINE_CHANNEL_ACCESS_TOKEN as environment variable.')
38+
sys.exit(1)
3639

3740
line_bot_api = LineBotApi(channel_access_token)
3841
handler = WebhookHandler(channel_secret)
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
line_bot
1+
line-bot-sdk
22
flask

examples/simple-server-echo/README.md

+4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ Sample echo-bot using [wsgiref.simple_server](https://docs.python.org/3/library/
55
## Getting Start
66

77
```
8+
$ export LINE_CHANNEL_SECRET=YOUR_LINE_CHANNEL_SECRET
9+
$ export LINE_CHANNEL_ACCESS_TOKEN=YOUR_LINE_CHANNEL_ACCESS_TOKEN
10+
811
$ pip install -r requirements.txt
12+
913
$ python app.py
1014
```
1115

examples/simple-server-echo/app.py

+24-12
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,31 @@
11
# -*- coding: utf-8 -*-
2-
32
import os
3+
import sys
44
import wsgiref.simple_server
55
from argparse import ArgumentParser
66

7-
from line_bot import (
7+
from builtins import bytes
8+
9+
from linebot import (
810
LineBotApi, WebhookParser
911
)
10-
from line_bot.exceptions import (
12+
from linebot.exceptions import (
1113
InvalidSignatureError
1214
)
13-
from line_bot.models import (
15+
from linebot.models import (
1416
MessageEvent, TextMessage, TextSendMessage
1517
)
18+
from linebot.utils import PY3
1619

17-
# get from os env
20+
# get channel_secret and channel_access_token from your environment variable
1821
channel_secret = os.getenv('LINE_CHANNEL_SECRET', None)
19-
if channel_secret is None:
20-
print('Specify LINE_CHANNEL_SECRET as env.')
2122
channel_access_token = os.getenv('LINE_CHANNEL_ACCESS_TOKEN', None)
23+
if channel_secret is None:
24+
print('Specify LINE_CHANNEL_SECRET as environment variable.')
25+
sys.exit(1)
2226
if channel_access_token is None:
23-
print('Specify LINE_CHANNEL_ACCESS_TOKEN as env.')
27+
print('Specify LINE_CHANNEL_ACCESS_TOKEN as environment variable.')
28+
sys.exit(1)
2429

2530
line_bot_api = LineBotApi(channel_access_token)
2631
parser = WebhookParser(channel_secret)
@@ -30,12 +35,12 @@ def application(environ, start_response):
3035
# check request path
3136
if environ['PATH_INFO'] != '/callback':
3237
start_response('404 Not Found', [])
33-
return 'Not Found'
38+
return create_body('Not Found')
3439

3540
# check request method
3641
if environ['REQUEST_METHOD'] != 'POST':
3742
start_response('405 Method Not Allowed', [])
38-
return 'Method Not Allowed'
43+
return create_body('Method Not Allowed')
3944

4045
# get X-Line-Signature header value
4146
signature = environ['HTTP_X_LINE_SIGNATURE']
@@ -50,7 +55,7 @@ def application(environ, start_response):
5055
events = parser.parse(body, signature)
5156
except InvalidSignatureError:
5257
start_response('400 Bad Request', [])
53-
return 'Bad Request'
58+
return create_body('Bad Request')
5459

5560
# if event is MessageEvent and message is TextMessage, then echo text
5661
for event in events:
@@ -65,7 +70,14 @@ def application(environ, start_response):
6570
)
6671

6772
start_response('200 OK', [])
68-
return 'OK'
73+
return create_body('OK')
74+
75+
76+
def create_body(text):
77+
if PY3:
78+
return [bytes(text, 'utf-8')]
79+
else:
80+
return text
6981

7082

7183
if __name__ == '__main__':
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
line_bot
1+
line-bot-sdk

line_bot/__about__.py linebot/__about__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# -*- coding: utf-8 -*-
22
from __future__ import unicode_literals
33

4-
__version__ = '0.0.1'
4+
__version__ = '0.1.0'
55

66
__all__ = (
77
'__version__'
File renamed without changes.

line_bot/api.py linebot/api.py

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

line_bot/utils.py linebot/utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import re
66
import sys
77

8-
LOGGER = logging.getLogger('line_bot')
8+
LOGGER = logging.getLogger('linebot')
99

1010
PY3 = sys.version_info[0] == 3
1111

File renamed without changes.

0 commit comments

Comments
 (0)