Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Rename Api to Dolt and use Simpleton for basic requests

  • Loading branch information...
commit e4cf5a36f79782f5468748e460094cf52e77d819 1 parent 3e8eca7
@six8 six8 authored
View
6 README.markdown
@@ -65,9 +65,9 @@ This works for other HTTP methods as well, such as `PUT`, `DELETE`, and `HEAD`.
Simple Request
--------------
-You can use the `Dolt` class directly for simple requests.
+You can use the `Simpleton` class for simple requests.
- api = Dolt('http://api.example.com')
+ api = Simpleton('http://api.example.com')
api.user.images()
# GET http://api.example.com/user/images
@@ -145,7 +145,7 @@ and params.
Other Useful Methods
--------------------
-* `with_params(**params)` - Add/overwrite URL query parameters to the request
+* `with_params(**params)` - Add/overwrite URL query parameters
* `get_url(self, *paths, **params)` - Returns the URL for this request
* `paths` - Additional URL path parts to add to the request
View
10 dolt/__init__.py
@@ -28,7 +28,7 @@ def _makes_clone(_func, *args, **kw):
_func(self, *args[1:], **kw)
return self
-class Api(object):
+class Dolt(object):
"""
A dumb little wrapper around RESTful interfaces.
@@ -36,7 +36,7 @@ class Api(object):
Example::
- class MyApi(Api):
+ class MyApi(Dolt):
_api_url = 'https://api.example.com'
_url_template = '%(domain)s/%(generated_url)s.json'
@@ -296,16 +296,16 @@ def __dir__(self):
except NameError:
pass
-class Dolt(Api):
+class Simpleton(Dolt):
"""
A dumber little wrapper around RESTful interfaces.
Example::
- api = Dolt('http://api.example.com')
+ api = Simpleton('http://api.example.com')
print api.images()
"""
def __init__(self, base_url, http=None):
- super(Dolt, self).__init__(http=http)
+ super(Simpleton, self).__init__(http=http)
self._api_url = base_url
View
4 dolt/apis/bitly.py
@@ -1,6 +1,6 @@
-from dolt import Api
+from dolt import Dolt
-class Bitly(Api):
+class Bitly(Dolt):
_api_url = 'http://api.bit.ly'
def __init__(self, http=None, **kwargs):
View
4 dolt/apis/couchdb.py
@@ -1,6 +1,6 @@
-from dolt import Api
+from dolt import Dolt
-class CouchDB(Api):
+class CouchDB(Dolt):
def __init__(self, couch_db, *args, **kwargs):
super(CouchDB, self).__init__(*args, **kwargs)
if couch_db.find("/") is -1:
View
4 dolt/apis/disqus.py
@@ -1,6 +1,6 @@
-from dolt import Api
+from dolt import Dolt
-class Disqus(Api):
+class Disqus(Dolt):
_api_url = "http://disqus.com"
def __init__(self, user_api_key, version="1.1", *args, **kwargs):
View
4 dolt/apis/github.py
@@ -1,6 +1,6 @@
-from dolt import Api
+from dolt import Dolt
-class GitHub(Api):
+class GitHub(Dolt):
def __init__(self, api_version="v2", *args, **kwargs):
super(GitHub, self).__init__(*args, **kwargs)
self._api_url = "https://github.com/api/%s/json" % api_version
View
4 dolt/apis/mosso.py
@@ -1,4 +1,4 @@
-from dolt import Api
+from dolt import Dolt
import datetime
import httplib2
try:
@@ -37,7 +37,7 @@ def initialize_auth_token(self):
self.auth_token = response['x-auth-token']
-class MossoServers(Api):
+class MossoServers(Dolt):
def __init__(self, username, api_key, **kwargs):
http = MossoHttp(username=username, api_key=api_key)
self._last_url = None
View
4 dolt/apis/statsmix.py
@@ -1,4 +1,4 @@
-from dolt import Api
+from dolt import Dolt
import httplib2
from xml.dom import minidom
@@ -13,7 +13,7 @@ def request(self, *args, **kwargs):
kwargs['headers']['X-StatsMix-Token'] = self.api_key
return self.http.request(*args, **kwargs)
-class StatsMix(Api):
+class StatsMix(Dolt):
def __init__(self, api_key, *args, **kwargs):
http = StatsMixHttp(api_key, *args, **kwargs)
kwargs['http'] = http
View
4 dolt/apis/twitter.py
@@ -1,5 +1,5 @@
-from dolt import Api
+from dolt import Dolt
-class Twitter(Api):
+class Twitter(Dolt):
_api_url = "https://twitter.com"
_url_template = '%(domain)s/%(generated_url)s.json'
View
4 examples/brightkite.py
@@ -2,10 +2,10 @@
import os, sys
sys.path[0:0] = os.path.join(os.path.dirname(__file__), "..")
-from dolt import Api
+from dolt import Dolt
from httplib2 import Http
-class Brightkite(Api):
+class Brightkite(Dolt):
_api_url = "http://brightkite.com"
_url_template = '%(domain)s/%(generated_url)s.json'
View
4 examples/flickr.py
@@ -1,9 +1,9 @@
import os, sys
sys.path[0:0] = os.path.join(os.path.dirname(__file__), ".."),
-from dolt import Api
+from dolt import Dolt
-class Flickr(Api):
+class Flickr(Dolt):
def __init__(self, api_key, *args, **kwargs):
super(self.__class__, self).__init__(*args, **kwargs)
self._api_key = api_key
View
4 examples/readernaut.py
@@ -2,10 +2,10 @@
import os, sys
sys.path[0:0] = os.path.join(os.path.dirname(__file__), "..")
-from dolt import Api
+from dolt import Dolt
from httplib2 import Http
-class Readernaut(Api):
+class Readernaut(Dolt):
_api_url = "http://readernaut.com"
_url_template = '%(domain)s/api/v1/json/%(generated_url)s'
View
14 tests/unit_tests.py
@@ -8,7 +8,7 @@
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
import unittest, mox
-from dolt import Dolt, Api
+from dolt import Dolt, Simpleton
from dolt.helpers import add_basic_auth
from dolt.apis.couchdb import CouchDB
from dolt.apis.twitter import Twitter
@@ -23,7 +23,7 @@ def random_attribute():
def testable_dolt():
http = mox.MockObject(Http)
- dolt = Dolt('', http=http)
+ dolt = Dolt(http=http)
return dolt
def dolt_request(dolt, url, method='GET', body=None, headers={}, response_headers=JSON_HEADERS, response_body='{}'):
@@ -38,7 +38,7 @@ def replay_all(*args):
class TestOfTwitterAPI(unittest.TestCase):
def test_subclasses_dolt(self):
twitter = Twitter()
- self.assert_(isinstance(twitter, Api))
+ self.assert_(isinstance(twitter, Dolt))
def test_contains_proper_api_url(self):
twitter = Twitter()
@@ -235,7 +235,7 @@ def test_supports_various_methods_as_attributes_as_well(self):
verify_all(dolt._http)
def test_instanciates_httplib2_object_if_not_provided(self):
- dolt = Dolt('')
+ dolt = Dolt()
self.assert_(isinstance(dolt._http, Http))
def test_returns_parsed_json_response_from_request(self):
@@ -250,7 +250,7 @@ def test_returns_parsed_json_response_from_request(self):
def test_takes_an_http_keyword_arg_and_sets_http_to_it(self):
random_http = "http-%s" % random.randint(1, 10)
- dolt = Api(http=random_http)
+ dolt = Dolt(http=random_http)
self.assertEqual(dolt._http, random_http)
def test_uses_collapse_stack_to_join_string_for_request(self):
@@ -426,9 +426,9 @@ def test_returns_parsed_json_with_content_type_params(self):
verify_all(dolt._http)
-class TestOfSimpleDolt(unittest.TestCase):
+class TestOfSimpleton(unittest.TestCase):
def test_base_url(self):
- dolt = Dolt('http://example.com')
+ dolt = Simpleton('http://example.com')
self.assertEquals(dolt._api_url, 'http://example.com')
if __name__ == '__main__':
Please sign in to comment.
Something went wrong with that request. Please try again.