]> jfr.im git - z_archive/twitter.git/commitdiff
- Documentation updates.
authorMike Verdone <redacted>
Mon, 10 May 2010 21:53:04 +0000 (23:53 +0200)
committerMike Verdone <redacted>
Mon, 10 May 2010 21:53:04 +0000 (23:53 +0200)
 - Default domain changed to 'api.twitter.com'
 - Added api_version param, default '1'. Changes URIs so they start with '1/'.

twitter/api.py
twitter/cmdline.py

index 42d9e53a62aee3f00c8959ac9822805688023c1f..a003b28b44439b6bcaa076728f5193c983ac6e73 100644 (file)
@@ -34,8 +34,11 @@ class TwitterHTTPError(TwitterError):
       self.encoded_args = encoded_args
 
     def __str__(self):
-        return "Twitter sent status %i for URL: %s.%s using parameters: (%s)\ndetails: %s" %(
-                    self.e.code, self.uri, self.format, self.encoded_args, self.e.fp.read())
+        return (
+            "Twitter sent status %i for URL: %s.%s using parameters: "
+            "(%s)\ndetails: %s" %(
+                self.e.code, self.uri, self.format, self.encoded_args, 
+                self.e.fp.read()))
 
 class TwitterCall(object):
     def __init__(
@@ -150,10 +153,12 @@ class Twitter(TwitterCall):
       # Search for the latest News on #gaza
       twitter_search.search(q="#gaza")
 
-    Using the data returned::
 
-      Twitter API calls return decoded JSON. This is converted into
-      a bunch of Python lists, dicts, ints, and strings. For example,
+    Using the data returned
+    -----------------------
+
+    Twitter API calls return decoded JSON. This is converted into
+    a bunch of Python lists, dicts, ints, and strings. For example::
 
       x = twitter.statuses.public_timeline()
 
@@ -163,37 +168,64 @@ class Twitter(TwitterCall):
       # The screen name of the user who wrote the first 'tweet'
       x[0]['user']['screen_name']
 
-    Getting raw XML data::
 
-      If you prefer to get your Twitter data in XML format, pass
-      format="xml" to the Twitter object when you instantiate it:
+    Getting raw XML data
+    --------------------
+
+    If you prefer to get your Twitter data in XML format, pass
+    format="xml" to the Twitter object when you instantiate it::
 
       twitter = Twitter(format="xml")
 
       The output will not be parsed in any way. It will be a raw string
       of XML.
+
     """
     def __init__(
-        self, email=None, password=None, format="json", domain="twitter.com",
-        agent=None, secure=True, auth=None):
+        self, email=None, password=None, format="json",
+        domain="api.twitter.com", agent=None, secure=True, auth=None,
+        api_version=1):
         """
-        Create a new twitter API connector using the specified
-        credentials (email and password). Format specifies the output
-        format ("json" (default) or "xml").
+        Create a new twitter API connector.
+
+        Pass an `auth` parameter to use the credentials of a specific
+        user. Generally you'll want to pass an `OAuth`
+        instance. Alternately you can pass `email` and `password`
+        parameters but this authentication mode will be deactive by
+        Twitter in the future and is not recommended.
+
+        `domain` lets you change the domain you are connecting. By
+        default it's twitter.com but `search.twitter.com` may be
+        useful too.
+
+        If `secure` is False you will connect with HTTP instead of
+        HTTPS.
+
+        The value of `agent` is sent in the `X-Twitter-Client`
+        header. This is deprecated. Instead Twitter determines the
+        application using the OAuth Client Key and Client Key Secret
+        parameters.
         """
         
         if email is not None or password is not None:
-            if auth is not None:
-                raise ValueError, "can't specify 'email' or 'password' and 'auth' params"
+            if auth:
+                raise (
+                    "Can't specify 'email'/'password' and 'auth' params"
+                    " simultaneously.")
             auth = UserPassAuth(email, password)
 
         if not auth:
             auth = NoAuth()
 
         if (format not in ("json", "xml", "")):
-            raise TwitterError("Unknown data format '%s'" %(format))
+            raise ValueError("Unknown data format '%s'" %(format))
+
+        uri = ""
+        if api_version:
+            uri = str(api_version)
+
         TwitterCall.__init__(
-            self, auth, format, domain, "", agent, 
+            self, auth, format, domain, uri, agent, 
             secure=secure)
 
 __all__ = ["Twitter", "TwitterError", "TwitterHTTPError"]
index 54ebc61cd795fbc4b8b561db5555a5528dc9e7c4..21c26c9e7b22b558300f6c7fc049b5b4676b0fe4 100644 (file)
@@ -457,6 +457,9 @@ paste or type it here:
     webbrowser.open(
         'http://api.twitter.com/oauth/authorize?oauth_token=' +
         oauth_token)
+    time.sleep(2) # Sometimes the last command can print some
+                  # crap. Wait a bit so it doesn't mess up the next
+                  # prompt.
     oauth_verifier = raw_input("Please type the PIN: ").strip()
     twitter = Twitter(
         auth=OAuth(
@@ -468,6 +471,7 @@ paste or type it here:
     print >> oauth_file, oauth_token
     print >> oauth_file, oauth_token_secret
     oauth_file.close()
+    print
     print "That's it! Your authorization keys have been written to %s." % (
         options['oauth_filename'])