diff --git a/README.rst b/README.rst index eaeeb92..c6708ec 100644 --- a/README.rst +++ b/README.rst @@ -6,11 +6,13 @@ Python API for Wallabag v2 Requirements : ============== + * requests == 2.5.0 Installation: ============= + to get the project, from your virtualenv, do : .. code:: python @@ -25,4 +27,11 @@ Install Wallabag V2 on your own host like explain here http://doc.wallabag.org/e Then create a client API like explain here http://doc.wallabag.org/en/v2/developer/api.html +Then replace the client_id / client_secret / login / pass to wallabag_test.py and run + +``` python + +python wallabag_test.py + +``` diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 8e9709c..0000000 --- a/requirements.txt +++ /dev/null @@ -1 +0,0 @@ -requests==2.5.0 \ No newline at end of file diff --git a/setup.py b/setup.py index bcf3b74..7e0cb1f 100644 --- a/setup.py +++ b/setup.py @@ -1,27 +1,19 @@ from setuptools import setup, find_packages from wallabag_api import __version__ as version -import os - -def strip_comments(l): - return l.split('#', 1)[0].strip() - - -def reqs(*f): - return list(filter(None, [strip_comments(l) for l in open( - os.path.join(os.getcwd(), *f)).readlines()])) - -install_requires = reqs('requirements.txt') +install_requires = [ + 'requests==2.5.0', +] setup( name='wallabag_api', version=version, - description='Wallabag API', + description='Wallabag API to add every pages you want to your Wallabag account', author='FoxMaSk', author_email='foxmask@trigger-happy.eu', url='https://github.com/foxmask/wallabag_api', - download_url="https://github.com/foxmask/wallabag_api/archive/wallabag_api-" - + version + ".zip", + download_url="https://github.com/foxmask/wallabag_api/archive/" + "wallabag_api-" + version + ".zip", packages=find_packages(), classifiers=[ 'Development Status :: 4 - Beta', @@ -29,8 +21,8 @@ setup( 'License :: OSI Approved :: BSD License', 'Operating System :: OS Independent', 'Programming Language :: Python', - 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3.4', + 'Programming Language :: Python :: 3.5', ], install_requires=install_requires, include_package_data=True, diff --git a/wallabag_api/__init__.py b/wallabag_api/__init__.py index a38d425..5eb77f0 100644 --- a/wallabag_api/__init__.py +++ b/wallabag_api/__init__.py @@ -1,2 +1,2 @@ -VERSION = (0, 0, 1) # PEP 386 +VERSION = (1, 0, 0) # PEP 386 __version__ = ".".join([str(x) for x in VERSION]) \ No newline at end of file diff --git a/wallabag_api/wallabag.py b/wallabag_api/wallabag.py index e431b97..fb85415 100644 --- a/wallabag_api/wallabag.py +++ b/wallabag_api/wallabag.py @@ -76,9 +76,6 @@ class Wallabag(object): r = requests.delete(self.get_host() + path, headers=params) elif method == 'put': r = requests.put(self.get_host() + path, params=params) - elif method == 'get_token': - r = requests.post(self.get_host() + path, data=params) - # todo : handle case of self.ext is xml or html return self.handle_json_response(r) else: raise ValueError('method expected : get, post, patch, delete or put') @@ -315,8 +312,10 @@ class Wallabag(object): params = {'access_token': self.token} return self.query(path, "delete", **params) - def get_token(self, params): + @classmethod + def get_token(cls, host, **params): """ + :param host: host of the service :param params: will contain : params = {"grant_type": "password", @@ -327,6 +326,7 @@ class Wallabag(object): :return: access token """ + params['grant_type'] = ["password"] path = "/oauth/v2/token" - return self.query(path, "get_token", **params)['access_token'] - + r = requests.post(host + path, data=params) + return cls.handle_json_response(r)['access_token'] diff --git a/wallabag_api/wallabag_test.py b/wallabag_api/wallabag_test.py index 8a2a10e..691cfda 100644 --- a/wallabag_api/wallabag_test.py +++ b/wallabag_api/wallabag_test.py @@ -1,15 +1,42 @@ -# -*- coding: utf-8 -*- +# coding: utf-8 import unittest from wallabag import Wallabag class TestWallabag(unittest.TestCase): + host = 'http://localhost:8080' + client_id = '' + client_secret = '' + token = '' + def setUp(self): - self.host = "http://localhost:5000" - self.api_key = '12334567890' - self.user_agent = 'WallabagPython/1.0 +https://github.com/foxmask/wallabag-api' + access_token = self.test_get_token() self.format = 'json' + self.w = Wallabag(host=self.host, + token=access_token, + client_id=self.client_id, + client_secret=self.client_secret) + + def test_get_token(self): + params = {"grant_type": "password", + "client_id": '1_37e16ub8a62oc4gwcg0o0wssks800kw0ok408kkwo4kosgc88g', + "client_secret": '49etxpn66da8okg4cs40sswsog0sskwg4woc400c4w4w8s4wo4', + "username": 'foxmask', + "password": 'ratatab00m'} + + data = Wallabag.get_token(host='http://localhost:8080', **params) + self.assertTrue(isinstance(data, str), True) + return data + + def create_entry(self): + title = 'foobar title' + url = 'https://smcomm.trigger-happy.eu/' + tags = ['foo', 'bar'] + starred = 0 + archive = 0 + data = self.w.post_entries(url, title, tags, starred, archive) + return data def test_get_entries(self): params = {'archive': 0, @@ -20,79 +47,64 @@ class TestWallabag(unittest.TestCase): 'page': 1, 'perPage': 30, 'tags': []} - w = Wallabag(self.host).get_entries('ABCD', **params) - self.assertIsInstance(w, dict) - - def test_post_entries(self): - title = 'foobar title' - url = ['http://foobar.com/', 'http://barfoo.com/'] - tags = ['foo', 'bar'] - self.assertTrue(isinstance(title, str), True) - self.assertTrue(isinstance(tags, list), True) - w = Wallabag(self.host).post_entries('ABCD', url, title, tags) - self.assertTrue(w, True) + data = self.w.get_entries(**params) + self.assertIsInstance(data, dict) def test_get_entry(self): entry = 1 self.assertTrue(isinstance(entry, int), True) - w = Wallabag(self.host).get_entry('ABCD', entry) - self.assertTrue(w, str) - - def test_patch_entries(self): - entry = 1 - params = {'title': '', - 'archive': 0, - 'tags': [], - 'star': 0, - 'delete': 0} - self.assertTrue(isinstance(entry, int), True) - self.assertTrue(isinstance(params, dict), True) - w = Wallabag(self.host).patch_entries('ABCD', entry, **params) - self.assertTrue(w, True) - - def test_delete_entries(self): - entry = 1 - self.assertTrue(isinstance(entry, int), True) - w = Wallabag(self.host).delete_entries('ABCD', entry) - self.assertTrue(w, True) + data = self.w.get_entry(entry) + self.assertTrue(data, str) def test_get_entry_tags(self): entry = 1 self.assertTrue(isinstance(entry, int), True) - w = Wallabag(self.host).get_entry_tags('ABCD', entry) - self.assertIsInstance(w, list) + data = self.w.get_entry_tags(entry) + self.assertIsInstance(data, list) + + def test_get_tags(self): + data = self.w.get_tags() + self.assertIsInstance(data, list) + + def test_post_entries(self): + data = self.create_entry() + self.assertTrue(data, True) + + def test_patch_entries(self): + entry = 1 + params = {'title': 'I change the title', + 'archive': 0, + 'tags': ["bimbo", "pipo"], + 'star': 0, + 'delete': 0} + self.assertTrue(isinstance(entry, int), True) + self.assertTrue(isinstance(params, dict), True) + data = self.w.patch_entries(entry, **params) + self.assertTrue(data, True) + + def test_delete_entries(self): + entry = self.create_entry() + self.assertTrue(isinstance(entry['id'], int), True) + data = self.w.delete_entries(entry['id']) + self.assertTrue(data, True) def test_post_entry_tags(self): entry = 1 self.assertTrue(isinstance(entry, int), True) tags = ['foo', 'bar'] self.assertTrue(isinstance(tags, list), True) - w = Wallabag(self.host).post_entry_tags('ABCD', entry, tags) - self.assertTrue(w, True) + data = self.w.post_entry_tags(entry, tags) + self.assertTrue(data, True) + """ def test_delete_entry_tag(self): - entry = 1 - tag = 'tag1' - self.assertTrue(isinstance(entry, int), True) + entry = self.create_entry() + tag = 'bar' + self.assertTrue(isinstance(entry['id'], int), True) self.assertTrue(isinstance(tag, str), True) - w = Wallabag(self.host).delete_entry_tag('ABCD', entry, tag) - self.assertTrue(w, True) - - def test_get_tags(self): - w = Wallabag(self.host).get_tags('ABCD') - self.assertTrue(w, True) - - def test_get_tag(self): - tag = 'tag1' - self.assertTrue(isinstance(tag, str), True) - w = Wallabag(self.host).get_tag('ABCD', tag) - self.assertTrue(w, True) - - def test_delete_tag(self): - tag = 'tag1' - self.assertTrue(isinstance(tag, str), True) - w = Wallabag(self.host).delete_tag('ABCD', tag) - self.assertTrue(w, True) + resp = self.w.delete_entry_tag(entry['id'], tag) + self.assertTrue(resp, True) + """ if __name__ == '__main__': - unittest.main() \ No newline at end of file + unittest.main()