Skip to content

Commit 2a6488c

Browse files
authored
Domain name change from api.line.me to api-data.line.me (#222)
* Domain name change from api.line.me to api-data.line.me * use not DEFAULT_API_DATA_ENDPOINT but data_endpoint property * refactoring
1 parent cc688ec commit 2a6488c

File tree

3 files changed

+19
-14
lines changed

3 files changed

+19
-14
lines changed

linebot/api.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,16 @@ class LineBotApi(object):
3535
"""LineBotApi provides interface for LINE messaging API."""
3636

3737
DEFAULT_API_ENDPOINT = 'https://api.line.me'
38+
DEFAULT_API_DATA_ENDPOINT = 'https://api-data.line.me'
3839

39-
def __init__(self, channel_access_token, endpoint=DEFAULT_API_ENDPOINT,
40+
def __init__(self, channel_access_token,
41+
endpoint=DEFAULT_API_ENDPOINT, data_endpoint=DEFAULT_API_DATA_ENDPOINT,
4042
timeout=HttpClient.DEFAULT_TIMEOUT, http_client=RequestsHttpClient):
4143
"""__init__ method.
4244
4345
:param str channel_access_token: Your channel access token
4446
:param str endpoint: (optional) Default is https://api.line.me
47+
:param str data_endpoint: (optional) Default is https://api-data.line.me
4548
:param timeout: (optional) How long to wait for the server
4649
to send data before giving up, as a float,
4750
or a (connect timeout, read timeout) float tuple.
@@ -51,6 +54,7 @@ def __init__(self, channel_access_token, endpoint=DEFAULT_API_ENDPOINT,
5154
:py:class:`linebot.http_client.RequestsHttpClient`
5255
:type http_client: T <= :py:class:`linebot.http_client.HttpClient`
5356
"""
57+
self.data_endpoint = data_endpoint
5458
self.endpoint = endpoint
5559
self.headers = {
5660
'Authorization': 'Bearer ' + channel_access_token,
@@ -441,7 +445,7 @@ def get_message_content(self, message_id, timeout=None):
441445
"""
442446
response = self._get(
443447
'/v2/bot/message/{message_id}/content'.format(message_id=message_id),
444-
stream=True, timeout=timeout
448+
endpoint=self.data_endpoint, stream=True, timeout=timeout
445449
)
446450

447451
return Content(response)
@@ -664,7 +668,7 @@ def get_rich_menu_image(self, rich_menu_id, timeout=None):
664668
"""
665669
response = self._get(
666670
'/v2/bot/richmenu/{rich_menu_id}/content'.format(rich_menu_id=rich_menu_id),
667-
timeout=timeout
671+
endpoint=self.data_endpoint, timeout=timeout
668672
)
669673

670674
return Content(response)
@@ -687,6 +691,7 @@ def set_rich_menu_image(self, rich_menu_id, content_type, content, timeout=None)
687691
"""
688692
self._post(
689693
'/v2/bot/richmenu/{rich_menu_id}/content'.format(rich_menu_id=rich_menu_id),
694+
endpoint=self.data_endpoint,
690695
data=content,
691696
headers={'Content-Type': content_type},
692697
timeout=timeout
@@ -961,8 +966,8 @@ def get_insight_message_event(self, request_id, timeout=None):
961966

962967
return InsightMessageEventResponse.new_from_json_dict(response.json)
963968

964-
def _get(self, path, params=None, headers=None, stream=False, timeout=None):
965-
url = self.endpoint + path
969+
def _get(self, path, endpoint=None, params=None, headers=None, stream=False, timeout=None):
970+
url = (endpoint or self.endpoint) + path
966971

967972
if headers is None:
968973
headers = {}
@@ -975,8 +980,8 @@ def _get(self, path, params=None, headers=None, stream=False, timeout=None):
975980
self.__check_error(response)
976981
return response
977982

978-
def _post(self, path, data=None, headers=None, timeout=None):
979-
url = self.endpoint + path
983+
def _post(self, path, endpoint=None, data=None, headers=None, timeout=None):
984+
url = (endpoint or self.endpoint) + path
980985

981986
if headers is None:
982987
headers = {'Content-Type': 'application/json'}
@@ -989,8 +994,8 @@ def _post(self, path, data=None, headers=None, timeout=None):
989994
self.__check_error(response)
990995
return response
991996

992-
def _delete(self, path, data=None, headers=None, timeout=None):
993-
url = self.endpoint + path
997+
def _delete(self, path, endpoint=None, data=None, headers=None, timeout=None):
998+
url = (endpoint or self.endpoint) + path
994999

9951000
if headers is None:
9961001
headers = {}

tests/api/test_error_handle.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def test_error_with_detail_handle(self):
104104
def test_error_handle_get_message_content(self):
105105
responses.add(
106106
responses.GET,
107-
LineBotApi.DEFAULT_API_ENDPOINT + '/v2/bot/message/1/content',
107+
LineBotApi.DEFAULT_API_DATA_ENDPOINT + '/v2/bot/message/1/content',
108108
json={
109109
"message": "Invalid reply token"
110110
},

tests/api/test_rich_menu.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ def test_get_rich_menu_image(self):
394394
body = b'hogieoidksk'
395395
responses.add(
396396
responses.GET,
397-
LineBotApi.DEFAULT_API_ENDPOINT +
397+
LineBotApi.DEFAULT_API_DATA_ENDPOINT +
398398
'/v2/bot/richmenu/{rich_menu_id}/content'.format(rich_menu_id=rich_menu_id),
399399
body=body, status=200
400400
)
@@ -405,7 +405,7 @@ def test_get_rich_menu_image(self):
405405
self.assertEqual(request.method, 'GET')
406406
self.assertEqual(
407407
request.url,
408-
LineBotApi.DEFAULT_API_ENDPOINT +
408+
LineBotApi.DEFAULT_API_DATA_ENDPOINT +
409409
'/v2/bot/richmenu/{rich_menu_id}/content'.format(rich_menu_id=rich_menu_id),
410410
)
411411
self.assertEqual(
@@ -419,7 +419,7 @@ def test_set_rich_menu_image(self):
419419
body = b'hogieoidksk'
420420
responses.add(
421421
responses.POST,
422-
LineBotApi.DEFAULT_API_ENDPOINT +
422+
LineBotApi.DEFAULT_API_DATA_ENDPOINT +
423423
'/v2/bot/richmenu/{rich_menu_id}/content'.format(rich_menu_id=rich_menu_id),
424424
json={}, status=200
425425
)
@@ -433,7 +433,7 @@ def test_set_rich_menu_image(self):
433433
request = responses.calls[0].request
434434
self.assertEqual('POST', request.method)
435435
self.assertEqual(
436-
LineBotApi.DEFAULT_API_ENDPOINT +
436+
LineBotApi.DEFAULT_API_DATA_ENDPOINT +
437437
'/v2/bot/richmenu/{rich_menu_id}/content'.format(rich_menu_id=rich_menu_id),
438438
request.url
439439
)

0 commit comments

Comments
 (0)