Repository: line/line-bot-sdk-python
Pull request #222 (2019-11-08 16:55:39)

Domain name change from api.line.me to api-data.line.me
#221


Patch:
diff --git a/linebot/api.py b/linebot/api.py
index 689dd88..111d844 100644
--- a/linebot/api.py
+++ b/linebot/api.py
@@ -35,13 +35,16 @@ class LineBotApi(object):
     """LineBotApi provides interface for LINE messaging API."""
 
     DEFAULT_API_ENDPOINT = 'https://api.line.me'
+    DEFAULT_API_DATA_ENDPOINT = 'https://api-data.line.me'
 
-    def __init__(self, channel_access_token, endpoint=DEFAULT_API_ENDPOINT,
+    def __init__(self, channel_access_token,
+                 endpoint=DEFAULT_API_ENDPOINT, data_endpoint=DEFAULT_API_DATA_ENDPOINT,
                  timeout=HttpClient.DEFAULT_TIMEOUT, http_client=RequestsHttpClient):
         """__init__ method.
 
         :param str channel_access_token: Your channel access token
         :param str endpoint: (optional) Default is https://api.line.me
+        :param str data_endpoint: (optional) Default is https://api-data.line.me
         :param timeout: (optional) How long to wait for the server
             to send data before giving up, as a float,
             or a (connect timeout, read timeout) float tuple.
@@ -51,6 +54,7 @@ class LineBotApi(object):
             :py:class:`linebot.http_client.RequestsHttpClient`
         :type http_client: T <= :py:class:`linebot.http_client.HttpClient`
         """
+        self.data_endpoint = data_endpoint
         self.endpoint = endpoint
         self.headers = {
             'Authorization': 'Bearer ' + channel_access_token,
@@ -441,7 +445,7 @@ class LineBotApi(object):
         """
         response = self._get(
             '/v2/bot/message/{message_id}/content'.format(message_id=message_id),
-            stream=True, timeout=timeout
+            endpoint=self.data_endpoint, stream=True, timeout=timeout
         )
 
         return Content(response)
@@ -664,7 +668,7 @@ class LineBotApi(object):
         """
         response = self._get(
             '/v2/bot/richmenu/{rich_menu_id}/content'.format(rich_menu_id=rich_menu_id),
-            timeout=timeout
+            endpoint=self.data_endpoint, timeout=timeout
         )
 
         return Content(response)
@@ -687,6 +691,7 @@ class LineBotApi(object):
         """
         self._post(
             '/v2/bot/richmenu/{rich_menu_id}/content'.format(rich_menu_id=rich_menu_id),
+            endpoint=self.data_endpoint,
             data=content,
             headers={'Content-Type': content_type},
             timeout=timeout
@@ -961,8 +966,8 @@ class LineBotApi(object):
 
         return InsightMessageEventResponse.new_from_json_dict(response.json)
 
-    def _get(self, path, params=None, headers=None, stream=False, timeout=None):
-        url = self.endpoint + path
+    def _get(self, path, endpoint=None, params=None, headers=None, stream=False, timeout=None):
+        url = (endpoint or self.endpoint) + path
 
         if headers is None:
             headers = {}
@@ -975,8 +980,8 @@ class LineBotApi(object):
         self.__check_error(response)
         return response
 
-    def _post(self, path, data=None, headers=None, timeout=None):
-        url = self.endpoint + path
+    def _post(self, path, endpoint=None, data=None, headers=None, timeout=None):
+        url = (endpoint or self.endpoint) + path
 
         if headers is None:
             headers = {'Content-Type': 'application/json'}
@@ -989,8 +994,8 @@ class LineBotApi(object):
         self.__check_error(response)
         return response
 
-    def _delete(self, path, data=None, headers=None, timeout=None):
-        url = self.endpoint + path
+    def _delete(self, path, endpoint=None, data=None, headers=None, timeout=None):
+        url = (endpoint or self.endpoint) + path
 
         if headers is None:
             headers = {}


Test patch:
diff --git a/tests/api/test_error_handle.py b/tests/api/test_error_handle.py
index 99e74ca..dba3fe7 100644
--- a/tests/api/test_error_handle.py
+++ b/tests/api/test_error_handle.py
@@ -104,7 +104,7 @@ class TestLineBotApi(unittest.TestCase):
     def test_error_handle_get_message_content(self):
         responses.add(
             responses.GET,
-            LineBotApi.DEFAULT_API_ENDPOINT + '/v2/bot/message/1/content',
+            LineBotApi.DEFAULT_API_DATA_ENDPOINT + '/v2/bot/message/1/content',
             json={
                 "message": "Invalid reply token"
             },
diff --git a/tests/api/test_rich_menu.py b/tests/api/test_rich_menu.py
index b770c63..44c4102 100644
--- a/tests/api/test_rich_menu.py
+++ b/tests/api/test_rich_menu.py
@@ -394,7 +394,7 @@ class TestLineBotApi(unittest.TestCase):
         body = b'hogieoidksk'
         responses.add(
             responses.GET,
-            LineBotApi.DEFAULT_API_ENDPOINT +
+            LineBotApi.DEFAULT_API_DATA_ENDPOINT +
             '/v2/bot/richmenu/{rich_menu_id}/content'.format(rich_menu_id=rich_menu_id),
             body=body, status=200
         )
@@ -405,7 +405,7 @@ class TestLineBotApi(unittest.TestCase):
         self.assertEqual(request.method, 'GET')
         self.assertEqual(
             request.url,
-            LineBotApi.DEFAULT_API_ENDPOINT +
+            LineBotApi.DEFAULT_API_DATA_ENDPOINT +
             '/v2/bot/richmenu/{rich_menu_id}/content'.format(rich_menu_id=rich_menu_id),
         )
         self.assertEqual(
@@ -419,7 +419,7 @@ class TestLineBotApi(unittest.TestCase):
         body = b'hogieoidksk'
         responses.add(
             responses.POST,
-            LineBotApi.DEFAULT_API_ENDPOINT +
+            LineBotApi.DEFAULT_API_DATA_ENDPOINT +
             '/v2/bot/richmenu/{rich_menu_id}/content'.format(rich_menu_id=rich_menu_id),
             json={}, status=200
         )
@@ -433,7 +433,7 @@ class TestLineBotApi(unittest.TestCase):
         request = responses.calls[0].request
         self.assertEqual('POST', request.method)
         self.assertEqual(
-            LineBotApi.DEFAULT_API_ENDPOINT +
+            LineBotApi.DEFAULT_API_DATA_ENDPOINT +
             '/v2/bot/richmenu/{rich_menu_id}/content'.format(rich_menu_id=rich_menu_id),
             request.url
         )