Repository: line/line-bot-sdk-python
Pull request #53 (2017-08-08 00:38:05)

Add Get Group/Room Member Profile API
Add the Get Group/Room Member Profile API as stated at https://devdocs.line.me/en/#get-group-room-member-profile.


Patch:
diff --git a/README.rst b/README.rst
index 96fcd16..69787ce 100644
--- a/README.rst
+++ b/README.rst
@@ -125,7 +125,6 @@ https://devdocs.line.me/en/#multicast
 
     line_bot_api.multicast(['to1', 'to2'], TextSendMessage(text='Hello World!'))
 
-
 get\_profile(self, user\_id, timeout=None)
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
@@ -142,6 +141,39 @@ https://devdocs.line.me/en/#bot-api-get-profile
     print(profile.picture_url)
     print(profile.status_message)
 
+get\_group\_member\_profile(self, group\_id, user\_id, timeout=None)
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+Gets the user profile of a member of a group that the bot is in. This can be
+the user ID of a user who has not added the bot as a friend or has blocked 
+the bot.
+
+https://devdocs.line.me/en/#get-group-room-member-profile
+
+.. code:: python
+
+    profile = line_bot_api.get_group_member_profile(group_id, user_id)
+
+    print(profile.display_name)
+    print(profile.user_id)
+    print(profile.picture_url)
+
+get\_room\_member\_profile(self, room\_id, user\_id, timeout=None)
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+Gets the user profile of a member of a room that the bot is in. This can be the
+user ID of a user who has not added the bot as a friend or has blocked the bot.
+
+https://devdocs.line.me/en/#get-group-room-member-profile
+
+.. code:: python
+
+    profile = line_bot_api.get_room_member_profile(room_id, user_id)
+
+    print(profile.display_name)
+    print(profile.user_id)
+    print(profile.picture_url)
+
 get\_message\_content(self, message\_id, timeout=None)
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
diff --git a/linebot/api.py b/linebot/api.py
index 702313c..0ec9988 100644
--- a/linebot/api.py
+++ b/linebot/api.py
@@ -179,6 +179,64 @@ class LineBotApi(object):
 
         return Profile.new_from_json_dict(response.json)
 
+    def get_group_member_profile(self, group_id, user_id, timeout=None):
+        """Call get group member profile API.
+
+        https://devdocs.line.me/en/#get-group-room-member-profile
+
+        Gets the user profile of a member of a group that
+        the bot is in. This can be the user ID of a user who has
+        not added the bot as a friend or has blocked the bot.
+
+        :param str user_id: User ID
+        :param str group_id: Group ID
+        :param timeout: (optional) How long to wait for the server
+            to send data before giving up, as a float,
+            or a (connect timeout, readtimeout) float tuple.
+            Default is self.http_client.timeout
+        :type timeout: float | tuple(float, float)
+        :rtype: :py:class:`linebot.models.responses.Profile`
+        :return: Profile instance
+        """
+        response = self._get(
+            '/v2/bot/group/{group_id}/member/{user_id}'.format(
+                user_id=user_id,
+                group_id=group_id
+            ),
+            timeout=timeout
+        )
+
+        return Profile.new_from_json_dict(response.json)
+
+    def get_room_member_profile(self, room_id, user_id, timeout=None):
+        """Call get room member profile API.
+
+        https://devdocs.line.me/en/#get-group-room-member-profile
+
+        Gets the user profile of a member of a room that
+        the bot is in. This can be the user ID of a user who has
+        not added the bot as a friend or has blocked the bot.
+
+        :param str user_id: User ID
+        :param str room_id: Room ID
+        :param timeout: (optional) How long to wait for the server
+            to send data before giving up, as a float,
+            or a (connect timeout, readtimeout) float tuple.
+            Default is self.http_client.timeout
+        :type timeout: float | tuple(float, float)
+        :rtype: :py:class:`linebot.models.responses.Profile`
+        :return: Profile instance
+        """
+        response = self._get(
+            '/v2/bot/room/{room_id}/member/{user_id}'.format(
+                user_id=user_id,
+                room_id=room_id
+            ),
+            timeout=timeout
+        )
+
+        return Profile.new_from_json_dict(response.json)
+
     def get_message_content(self, message_id, timeout=None):
         """Call get content API.
 


Test patch:
diff --git a/tests/api/test_get_group_member_profile.py b/tests/api/test_get_group_member_profile.py
new file mode 100644
index 0000000..0a03600
--- /dev/null
+++ b/tests/api/test_get_group_member_profile.py
@@ -0,0 +1,57 @@
+# -*- coding: utf-8 -*-
+
+#  Licensed under the Apache License, Version 2.0 (the "License"); you may
+#  not use this file except in compliance with the License. You may obtain
+#  a copy of the License at
+#
+#       https://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing, software
+#  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+#  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+#  License for the specific language governing permissions and limitations
+#  under the License.
+
+from __future__ import unicode_literals, absolute_import
+
+import unittest
+
+import responses
+from linebot import (
+    LineBotApi
+)
+
+
+class TestLineBotApi(unittest.TestCase):
+    def setUp(self):
+        self.tested = LineBotApi('channel_secret')
+
+    @responses.activate
+    def test_get_profile(self):
+        responses.add(
+            responses.GET,
+            LineBotApi.DEFAULT_API_ENDPOINT + '/v2/bot/group/group_id/' +
+            'member/user_id',
+            json={
+                "displayName": "LINE taro",
+                "userId": "Uxxxxxxxxxxxxxx...",
+                "pictureUrl": "http://obs.line-apps.com/..."
+            },
+            status=200
+        )
+
+        profile = self.tested.get_group_member_profile('group_id', 'user_id')
+
+        request = responses.calls[0].request
+        self.assertEqual(request.method, 'GET')
+        self.assertEqual(
+            request.url,
+            LineBotApi.DEFAULT_API_ENDPOINT + '/v2/bot/group/group_id/' +
+            'member/user_id')
+        self.assertEqual(profile.display_name, 'LINE taro')
+        self.assertEqual(profile.user_id, 'Uxxxxxxxxxxxxxx...')
+        self.assertEqual(profile.picture_url, 'http://obs.line-apps.com/...')
+
+
+if __name__ == '__main__':
+    unittest.main()
diff --git a/tests/api/test_get_profile.py b/tests/api/test_get_profile.py
index b33a838..de2c9f0 100644
--- a/tests/api/test_get_profile.py
+++ b/tests/api/test_get_profile.py
@@ -54,4 +54,4 @@ class TestLineBotApi(unittest.TestCase):
 
 
 if __name__ == '__main__':
-    unittest.maAAin()
+    unittest.main()
diff --git a/tests/api/test_get_room_member_profile.py b/tests/api/test_get_room_member_profile.py
new file mode 100644
index 0000000..64ef890
--- /dev/null
+++ b/tests/api/test_get_room_member_profile.py
@@ -0,0 +1,57 @@
+# -*- coding: utf-8 -*-
+
+#  Licensed under the Apache License, Version 2.0 (the "License"); you may
+#  not use this file except in compliance with the License. You may obtain
+#  a copy of the License at
+#
+#       https://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing, software
+#  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+#  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+#  License for the specific language governing permissions and limitations
+#  under the License.
+
+from __future__ import unicode_literals, absolute_import
+
+import unittest
+
+import responses
+from linebot import (
+    LineBotApi
+)
+
+
+class TestLineBotApi(unittest.TestCase):
+    def setUp(self):
+        self.tested = LineBotApi('channel_secret')
+
+    @responses.activate
+    def test_get_profile(self):
+        responses.add(
+            responses.GET,
+            LineBotApi.DEFAULT_API_ENDPOINT + '/v2/bot/room/room_id/' +
+            'member/user_id',
+            json={
+                "displayName": "LINE taro",
+                "userId": "Uxxxxxxxxxxxxxx...",
+                "pictureUrl": "http://obs.line-apps.com/..."
+            },
+            status=200
+        )
+
+        profile = self.tested.get_room_member_profile('room_id', 'user_id')
+
+        request = responses.calls[0].request
+        self.assertEqual(request.method, 'GET')
+        self.assertEqual(
+            request.url,
+            LineBotApi.DEFAULT_API_ENDPOINT + '/v2/bot/room/room_id/' +
+            'member/user_id')
+        self.assertEqual(profile.display_name, 'LINE taro')
+        self.assertEqual(profile.user_id, 'Uxxxxxxxxxxxxxx...')
+        self.assertEqual(profile.picture_url, 'http://obs.line-apps.com/...')
+
+
+if __name__ == '__main__':
+    unittest.main()