Permalink
Browse files

DisqusClient init method now accepts kwargs

  • Loading branch information...
1 parent 1d7066b commit cabee7eff33f3709d442792e7a081f5db279b400 @arthurk committed Mar 8, 2010
Showing with 34 additions and 5 deletions.
  1. +2 −0 .gitignore
  2. +15 −2 disqus/api.py
  3. 0 disqus/models.py
  4. +15 −1 disqus/tests.py
  5. +2 −2 setup.py
View
@@ -1,3 +1,5 @@
*.pyc
*.swp
ve
+testproject
+*.egg-info
View
@@ -3,7 +3,8 @@
from django.utils import simplejson as json
-# do not auto-detect proxy settings
+# A custom ProxyHandler for the urllib2 module that will not
+# auto-detect proxy settings
proxy_support = urllib2.ProxyHandler({})
opener = urllib2.build_opener(proxy_support)
urllib2.install_opener(opener)
@@ -36,10 +37,17 @@ class DisqusClient(object):
'update_thread': 'POST',
}
- def __init__(self):
+ def __init__(self, **kwargs):
self.api_url = 'http://disqus.com/api/%s?api_version=1.1'
+ self.__dict__.update(kwargs)
def __getattr__(self, attr):
+ """
+ Called when an attribute is not found in the usual places
+ (__dict__, class tree) this method will check if the attribute
+ name is a DISQUS API method and call the `call` method.
+ If it isn't in the METHODS dict, it will raise an AttributeError.
+ """
if attr in self.METHODS:
def call_method(**kwargs):
return self.call(attr, **kwargs)
@@ -60,6 +68,11 @@ def _get_request(self, url, request_method, **params):
return request
def call(self, method, **params):
+ """
+ Call the DISQUS API and return the json response.
+ URLError is raised when the request failed.
+ DisqusException is raised when the query didn't succeed.
+ """
url = self.api_url % method
request = self._get_request(url, self.METHODS[method], **params)
try:
View
No changes.
View
@@ -6,4 +6,18 @@
from mock import Mock
__test__ = {'API_TESTS': """
-"""}
+
+First, we test if the DisqusClient class can be initialized
+and parameters that were passed are set correctly.
+
+>>> c = DisqusClient(foo='bar', bar='foo')
+>>> c.foo
+'bar'
+>>> c.bar
+'foo'
+>>> c.baz
+Traceback (most recent call last):
+ ...
+AttributeError
+""",
+}
View
@@ -4,8 +4,8 @@
setup(
name='django-disqus',
- version='0.2',
- description='Easily integrate DISQUS comments into your Django website',
+ version='0.3-dev',
+ description='Integrate DISQUS comments into your Django website',
author='Arthur Koziel',
author_email='arthur@arthurkoziel.com',
url='http://github.com/arthurk/django-disqus',

0 comments on commit cabee7e

Please sign in to comment.