diff --git a/icon.gif b/icon.gif new file mode 100644 index 0000000..c690106 Binary files /dev/null and b/icon.gif differ diff --git a/setup.py b/setup.py index 33a7f30..33de7ed 100644 --- a/setup.py +++ b/setup.py @@ -38,6 +38,7 @@ 'Operating System :: OS Independent', 'Topic :: Utilities', ], + test_suite = "fbconsole.test_suite", entry_points = """ [console_scripts] fbconsole = fbconsole:shell diff --git a/src/fbconsole.py b/src/fbconsole.py index a2a60a4..e22be4f 100644 --- a/src/fbconsole.py +++ b/src/fbconsole.py @@ -26,6 +26,7 @@ import time import types import urllib2 +import urllib import webbrowser from urlparse import urlparse, parse_qs @@ -208,8 +209,7 @@ def graph_url(path, params=None): download a large profile picture of Mark Zuckerberg: >>> url = graph_url('/zuck/picture', {"type":"large"}) - >>> import urllib - >>> urllib.urlretrieve(url, 'mark.jpg') + >>> filename, response = urllib.urlretrieve(url, 'mark.jpg') """ return _get_url(path, args=params) @@ -219,8 +219,12 @@ def get(path, params=None): For example: - >>> get('/me') - >>> get('/me', {'fields':'id,name'}) + >>> user = get('/me') + >>> print user['first_name'] + David + >>> short_user = get('/me', {'fields':'id,first_name'}) + >>> print short_user['id'], short_user['first_name'] + 100003169144448 David """ return json.load(urllib2.urlopen(_get_url(path, args=params))) @@ -230,9 +234,11 @@ def post(path, params=None): You can also upload files using this function. For example: - >>> post('/me/photos', + >>> photo_id = post('/me/photos', ... {'name': 'My Photo', - ... 'source': open("myphoto.jpg")}) + ... 'source': open("icon.gif")})['id'] + >>> print get('/'+photo_id)['name'] + My Photo """ opener = urllib2.build_opener( @@ -247,6 +253,7 @@ def delete(path, params=None): >>> msg_id = post('/me/feed', {'message':'hello world'})['id'] >>> delete('/'+msg_id) + True """ if not params: @@ -260,6 +267,7 @@ def fql(query): For example: >>> fql('SELECT name FROM user WHERE uid = me()') + [{u'name': u'David Amcafiaddddh Yangstein'}] """ url = _get_url('/method/fql.query', @@ -291,5 +299,12 @@ def shell(): import code code.InteractiveConsole(globals()).interact(INTRO_MESSAGE) + +def test_suite(): + import doctest + global ACCESS_TOKEN + ACCESS_TOKEN = 'AAACjeiZB6FgIBAB8eZABg7So8ALDisFLugfIJSZCg3FEDRy82yEmdXYYfNvdv2kWVMWxaJgWqqVMPtG5v5n4lMG5VXmZBZBykQkeluhpFPQZDZD' + return doctest.DocTestSuite() + if __name__ == '__main__': shell()