diff --git a/pnutpy/api.py b/pnutpy/api.py index 9f3b537..ffedf64 100644 --- a/pnutpy/api.py +++ b/pnutpy/api.py @@ -29,7 +29,7 @@ class API(requests.Session): """ @classmethod - def build_api(cls, api_root='https://api.pnut.io/v0', access_token=None, verify_ssl=True, extra_headers=None): + def build_api(cls, api_root='https://api.pnut.io/v1', access_token=None, verify_ssl=True, extra_headers=None): api = cls() api.api_root = api_root if access_token: @@ -98,7 +98,7 @@ def request_json(self, method, *args, **kwargs): return self.request(method, *args, **kwargs) -re_path_template = re.compile('{\w+}') +re_path_template = re.compile(r'{\w+}') def bind_api_method(func_name, path, payload_type=None, payload_list=False, allowed_params=None, @@ -360,8 +360,8 @@ def run(self, *args, **kwargs): allowed_params=PAGINATION_PARAMS + CHANNEL_PARAMS, require_auth=True) -bind_api_method('num_unread_pm_channels', '/users/me/channels/num_unread/pm', payload_type=SimpleValueModel, - allowed_params=CHANNEL_PARAMS, require_auth=True) +bind_api_method('num_unread_pm_channels', '/users/me/channels/num_unread?channel_types=io.pnut.core.pm', + payload_type=SimpleValueModel, allowed_params=CHANNEL_PARAMS, require_auth=True) bind_api_method('update_channel', '/channels/{channel_id}', payload_type=Channel, method='PUT', diff --git a/pnutpy/models.py b/pnutpy/models.py index 0ed03f1..10d7505 100644 --- a/pnutpy/models.py +++ b/pnutpy/models.py @@ -292,7 +292,10 @@ class Channel(APIModel): @classmethod def from_response_data(cls, data, api=None): channel = super(Channel, cls).from_response_data(data, api) - channel.owner = User.from_response_data(channel.owner, api) + if channel.get('user'): + channel.user = User.from_response_data(channel.user, api) + if channel.get('user_id'): + channel.user_id = int(channel.user_id) return channel class File(APIModel): diff --git a/setup.py b/setup.py index f7461a4..619cfe1 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ from setuptools import setup, find_packages setup(name='pnutpy', - version='0.4.0', + version='0.5.0', description='pnut.io API library for python', long_description=open('README.rst').read(), license='MIT', diff --git a/tests/test_api.py b/tests/test_api.py index 8f99325..c02ac11 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -25,11 +25,11 @@ def test_post(self): post, meta = self.api.delete_post(post) - post, meta = self.api.repost_post(257434) - post, meta = self.api.unrepost_post(257434) + post, meta = self.api.repost_post(1309208) + post, meta = self.api.unrepost_post(1309208) - post, meta = self.api.bookmark_post(257434) - post, meta = self.api.unbookmark_post(257434) + post, meta = self.api.bookmark_post(1309208) + post, meta = self.api.unbookmark_post(1309208) posts, meta = self.api.get_posts(ids='1,2,3') self.assertEqual(len(posts), 3) diff --git a/tests/test_models.py b/tests/test_models.py index d19adfc..22dbcfc 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -15,7 +15,7 @@ def test_post(self): post.bookmark() post.unbookmark() post.delete() - post, meta = self.api.get_post(257434) + post, meta = self.api.get_post(1309208) post.repost() post.unrepost() @@ -25,7 +25,7 @@ def test_user(self): user.name = new_display_name user.update_user() - self.assertEquals(user.name, new_display_name) + self.assertEqual(user.name, new_display_name) user, meta = self.api.get_user(9) user.follow_user() @@ -37,6 +37,15 @@ def test_user(self): user.block_user() user.unblock_user() + def test_channel(self): + # normal public channel + user_id = 9 + channel, meta = self.api.get_channel(85) + self.assertEqual(user_id, channel.user.id) + # channel where the owner user account has been deleted + user_id = 213 + channel, meta = self.api.get_channel(955) + self.assertEqual(user_id, channel.user_id) if __name__ == '__main__': unittest.main()