[ckan-changes] commit/ckanclient: 4 new changesets

Bitbucket commits-noreply at bitbucket.org
Wed Nov 9 22:09:31 UTC 2011


4 new commits in ckanclient:


https://bitbucket.org/okfn/ckanclient/changeset/b4282da521b8/
changeset:   b4282da521b8
user:        dread
date:        2011-08-09 19:41:26
summary:     [release]: Adding version 0.9 for release today. (#1270 was bug fixed in previous cset.)
affected #:  1 file

diff -r ca5295c9c8cf8024dbb0b10f2c7f52e04dc9768f -r b4282da521b85a0d4f9743c189c40f15b8892a71 ckanclient/__init__.py
--- a/ckanclient/__init__.py
+++ b/ckanclient/__init__.py
@@ -1,4 +1,4 @@
-__version__ = '0.8'
+__version__ = '0.9'
 __description__ = 'The CKAN client Python package.'
 __long_description__ = \
 '''The CKAN client software may be used to make requests on the Comprehensive
@@ -72,7 +72,7 @@
 Changelog
 =========
 
-v0.9 2011-XX-XX
+v0.9 2011-08-09
 ---------------
 
   * Default URL changed to thedatahub.org



https://bitbucket.org/okfn/ckanclient/changeset/a3082d86fb07/
changeset:   a3082d86fb07
user:        dread
date:        2011-08-09 19:41:35
summary:     Added tag ckanclient-v0.9 for changeset b4282da521b8
affected #:  1 file

diff -r b4282da521b85a0d4f9743c189c40f15b8892a71 -r a3082d86fb0788fca7c70003abdf8961a4acec96 .hgtags
--- a/.hgtags
+++ b/.hgtags
@@ -14,3 +14,4 @@
 0000000000000000000000000000000000000000 ckanclient-v0.8
 0000000000000000000000000000000000000000 ckanclient-v0.8
 1cd25d44129287503bfdc8ab9b783dd0ced03c71 ckanclient-v0.8
+b4282da521b85a0d4f9743c189c40f15b8892a71 ckanclient-v0.9



https://bitbucket.org/okfn/ckanclient/changeset/bcafddf0328d/
changeset:   bcafddf0328d
user:        dread
date:        2011-11-09 23:07:34
summary:     Added basic Action Api facility.
affected #:  2 files

diff -r a3082d86fb0788fca7c70003abdf8961a4acec96 -r bcafddf0328da15c2df5d53791b9ede8c195cb86 ckanclient/__init__.py
--- a/ckanclient/__init__.py
+++ b/ckanclient/__init__.py
@@ -13,7 +13,9 @@
     import ckanclient
 
     # Instantiate the CKAN client.
-    ckan = ckanclient.CkanClient(api_key=my_key)
+    ckan = ckanclient.CkanClient(base_location='http://thedatahub.org/api',
+                                 api_key='adbc-1c0d')
+    # (use your own api_key from http://thedatahub.org/user/me )
     
     # Get the package list.
     package_list = ckan.package_register_get()
@@ -72,6 +74,12 @@
 Changelog
 =========
 
+vXX
+---------------
+
+  * Action API functions
+
+
 v0.9 2011-08-09
 ---------------
 
@@ -172,6 +180,7 @@
 class CkanApiNotFoundError(CkanApiError): pass
 class CkanApiNotAuthorizedError(CkanApiError): pass
 class CkanApiConflictError(CkanApiError): pass
+class CkanApiActionError(Exception): pass
 
 
 class ApiRequest(Request):
@@ -202,6 +211,9 @@
         self.last_message = None
         self.last_http_error = None
         self.last_url_error = None
+        self.last_help = None # Action API only
+        self.last_result = None # Action API only
+        self.last_ckan_error = None # Action API only
 
     def open_url(self, location, data=None, headers={}, method=None):
         if self.is_verbose:
@@ -267,6 +279,9 @@
                     path += '/' + entity2_id            
         return base + path
 
+    def get_action_location(self, action_name):
+        return '%s/action/%s' % (self.base_location, action_name)
+
     def _dumpstr(self, data):
         return json.dumps(data)
     
@@ -348,6 +363,26 @@
                 raise CkanApiError(self.last_message)
         return result
             
+    def open_action_url(self, url, data_dict):
+        data_json = self._dumpstr(data_dict)
+        result = super(CkanClient, self).open_url(url, data=data_json)
+        if self.last_status not in (200, 201):
+            if self.last_status == 404:
+                raise CkanApiNotFoundError(self.last_status)
+            elif self.last_status == 403:
+                raise CkanApiNotAuthorizedError(self.last_status)
+            elif self.last_status == 409:
+                raise CkanApiConflictError(self.last_status)
+            else:
+                raise CkanApiError(self.last_message)
+        self.last_help = self.last_message['help']
+        if self.last_message['success']:
+            self.last_result = self.last_message['result']
+        else:
+            self.last_ckan_error = self.last_message['error']
+            raise CkanApiActionError(self.last_ckan_error)
+        return self.last_result
+
     def api_version_get(self):
         self.reset()
         url = self.get_location('Base')
@@ -614,9 +649,33 @@
         payload = self._dumpstr(headers)
         self.open_url(url, payload, method="POST")
         return self._loadstr(self.last_message)
+
+    #
+    # Action API
+    #
+
+    # for any action
+    def action(self, action_name, **kwargs):
+        self.reset()
+        url = self.get_action_location(action_name)
+        self.open_action_url(url, kwargs)
+        return self.last_result
+
+    def package_list(self):
+        return self.action('package_list')
+        
+    def package_show(self, package_id):
+        return self.action('package_show', id=package_id)
+
+    def status_show(self):
+        return self.action('status_show')
+
+    def ckan_version(self):
+        return self.action('status_show')['ckan_version']
+
     
     #
-    # Utils
+    # CkanClient utils
     #
     def is_id(self, id_string):
         '''Tells the client if the string looks like an id or not'''


diff -r a3082d86fb0788fca7c70003abdf8961a4acec96 -r bcafddf0328da15c2df5d53791b9ede8c195cb86 ckanclient/tests/test_ckanclient.py
--- a/ckanclient/tests/test_ckanclient.py
+++ b/ckanclient/tests/test_ckanclient.py
@@ -359,3 +359,17 @@
         assert set(david['packages']) == set((u'annakarenina', u'warandpeace')), david
         roger = self.c.group_entity_get('roger')
         assert roger['packages'] == [u'annakarenina'], roger
+
+    def test_17_package_list(self):
+        res = self.c.package_list()
+        status = self.c.last_status
+        assert status == 200
+        assert_equal(res, self.c.last_result)
+        message = self.c.last_message
+        assert set(message.keys()) >= set(('help', 'success', 'result')), message
+        assert 'annakarenina' in res, res
+
+    def test_18_ckan_version(self):
+        res = self.c.ckan_version()
+        assert res[0] in '12345'
+        



https://bitbucket.org/okfn/ckanclient/changeset/425117855316/
changeset:   425117855316
user:        dread
date:        2011-11-09 23:09:21
summary:     [merge]
affected #:  2 files

diff -r bcafddf0328da15c2df5d53791b9ede8c195cb86 -r 425117855316c875ff92909d4a18ddf049d99199 ckanclient/__init__.py
--- a/ckanclient/__init__.py
+++ b/ckanclient/__init__.py
@@ -169,7 +169,13 @@
 try: # since python 2.6
     import json
 except ImportError:
-    import simplejson as json
+    try:
+        import simplejson as json
+    except ImportError:
+        class _json(object):
+            def __getattr__(self, name):
+                import simplejson as json
+        json = _json()
 
 import logging
 logger = logging.getLogger('ckanclient')


diff -r bcafddf0328da15c2df5d53791b9ede8c195cb86 -r 425117855316c875ff92909d4a18ddf049d99199 setup.py
--- a/setup.py
+++ b/setup.py
@@ -9,6 +9,14 @@
 
 import os
 
+install_requires = []
+try:
+    __import__('json')
+except ImportError:
+    # The json module isn't available in the standard library until 2.6;
+    # use simplejson instead,
+    install_requires.append('simplejson')
+
 setup(
     name='ckanclient',
     version=__version__,
@@ -19,10 +27,7 @@
     description=__description__,
     keywords='data packaging component tool client',
     long_description =__long_description__,
-    install_requires=[
-        # only required if python <= 2.5 (as json library in python >= 2.6)
-        # 'simplejson',
-    ],
+    install_requires=install_requires,
     packages=find_packages(exclude=['ez_setup']),
     include_package_data=True,
     always_unzip=True,

Repository URL: https://bitbucket.org/okfn/ckanclient/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.




More information about the ckan-changes mailing list