Initial commit! Added api interface. Added license and readme. Added models.
authorJosh Roesslein <jroesslein@gmail.com>
Sun, 5 Jul 2009 19:24:56 +0000 (14:24 -0500)
committerJosh Roesslein <jroesslein@gmail.com>
Sun, 5 Jul 2009 19:24:56 +0000 (14:24 -0500)
.gitignore [new file with mode: 0644]
LICENSE [new file with mode: 0644]
README [new file with mode: 0644]
__init__.py [new file with mode: 0644]
api.py [new file with mode: 0644]
misc.py [new file with mode: 0644]
models.py [new file with mode: 0644]

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..c9b568f
--- /dev/null
@@ -0,0 +1,2 @@
+*.pyc
+*.swp
diff --git a/LICENSE b/LICENSE
new file mode 100644 (file)
index 0000000..d4a7114
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,19 @@
+Copyright (c) 2009 Joshua Roesslein
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
diff --git a/README b/README
new file mode 100644 (file)
index 0000000..e6d6023
--- /dev/null
+++ b/README
@@ -0,0 +1,11 @@
+==========================
+Tweepy Twitter API Library
+==========================
+
+A Twitter API library for Python!
+
+Author: Joshua Roesslein <jroesslein at gmail.com>
+License: MIT
+Dependencies:
+  Simplejson <http://undefined.org/python/#simplejson>
+    **Included in python 2.6+
diff --git a/__init__.py b/__init__.py
new file mode 100644 (file)
index 0000000..2f899cc
--- /dev/null
@@ -0,0 +1,7 @@
+"""
+Tweepy Twitter API library
+"""
+__version__ = '1.0'
+
+from models import *
+from api import API
diff --git a/api.py b/api.py
new file mode 100644 (file)
index 0000000..ae0a15d
--- /dev/null
+++ b/api.py
@@ -0,0 +1,70 @@
+import urllib
+import urllib2
+
+try:
+  import json
+except ImportError:
+  import simplejson as json
+
+from misc import *
+from models import *
+
+"""
+Twitter API Interface
+"""
+class API(object):
+
+  def __init__(self, username=None, password=None, host='twitter.com',
+                user_agent='tweepy', secure=False,
+                user_class=User, status_class=Status):
+    self._Status = status_class
+    self._User = user_class
+    self.username = username
+    self.host = host
+    if secure:
+      self._schema = 'https'
+    else:
+      self._schema = 'http'
+
+    # Setup headers
+    self._headers = {
+      'User-Agent': user_agent
+    }
+
+    self._opener = self._build_opener(username, password)
+
+  def public_timeline(self):
+    return self._fetch('statuses/public_timelinee.json')
+
+  @require_auth
+  def friends_timeline(self, since_id=None, max_id=None, count=None, page=None):
+    raise NotImplementedError
+
+  def _build_opener(self, username, password):
+    if username and password:
+      bauth = urllib2.HTTPBasicAuthHandler()
+      bauth.add_password(None, self.host, username, password)
+      return urllib2.build_opener(bauth)
+    else:
+      return urllib2.build_opener()
+
+  def _fetch(self, url, parameters=None, post_data=None):
+    # Build the url
+    if parameters:
+      _url = '%s://%s/%s?%s' % (self._schema, self.host, urllib.urlencode(parameters))
+    else:
+      _url = '%s://%s/%s' % (self._schema, self.host, url)
+
+    # Encode post data
+    post = None
+    if post_data:
+      post = urllib.encode(post_data)
+
+    # Build the request
+    req = urllib2.Request(_url, post, self._headers)
+
+    # Send request
+    try:
+      return self._opener.open(req)
+    except urllib2.HTTPError, e:
+      raise TweepError(json.loads(e.read())['error'])
diff --git a/misc.py b/misc.py
new file mode 100644 (file)
index 0000000..3d25d68
--- /dev/null
+++ b/misc.py
@@ -0,0 +1,21 @@
+"""
+Only allow method to be called with authentication.
+"""
+def require_auth(func):
+  def wrapper(instance, *args, **kargs):
+    if instance.username and instance.password:
+      func(instance, *args, **kargs)
+    else:
+      print 'require auth'
+  return wrapper
+
+"""
+Tweepy exception
+"""
+class TweepError(Exception):
+
+  def __init__(self, reason):
+    self.reason = reason
+
+  def __str__(self):
+    return self.reason
diff --git a/models.py b/models.py
new file mode 100644 (file)
index 0000000..fd765f1
--- /dev/null
+++ b/models.py
@@ -0,0 +1,7 @@
+class Status(object):
+
+  pass
+
+class User(object):
+
+  pass