My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
Posting a message to Ping.fm
============================

Syncronous Client
-----------------

from pyngfm.client import PingFMSyncClient
from pyngfm.exception import PingFMResponseError

# both keys are needed to use this library
api_key = "xxx"
user_app_key = "yyy"
pinger = PingFMSyncClient(api_key, user_app_key)
try:
pinger.user_post('status','testing Ping.FM Python API :)')
print pinger.reponse.status
except PingFMResponseError, e:
print pinger.reponse.status
print e


Asyncronous Client
------------------

Just to keep things fresh, this example exercises a different method:

from twisted.internet import reactor
from pyngfm.client import PingFMAsyncClient
from pyngfm.exception import PingFMResponseError

def check_result(messages):
for message in messages:
print "title:", message.title
print "body:", message.body
services = [s.id for s in message.services]
print "services:", services, "\n"

def check_error(error):
print error.getErrorMessage()

def finish(ignored):
reactor.stop()

api_key = "xxx"
user_app_key = "yyy"

pinger = PingFMAsyncClient(api_key, user_app_key)
deferred = pinger.user_latest()
deferred.addCallback(check_result)
deferred.addErrback(check_error)
deferred.addCallback(finish)

reactor.run()


Testing the Source Code
=======================

With the inclusion of Twisted support, unit tests started getting added. Since
the Twisted test runner (trial) is easy to use with nicely legible output, the
unit tests are written for use with trial.

To run the unit tests, simply make sure you are in the top-level source
directory of pyngfm, and execute the following:

$ trial pyngfm

You can also run unit tests by subpackage:

$ trial pyngfm/client/

Or module:

$ trial pyngfm/client/tests/test_async.py

Or even using Python namespace dotted notation:

$ trial pyngfm.client.tests.test_async

Note that this allows running the unit tests at a finer-grained level:

$ trial pyngfm.client.tests.test_base.BaseClientTestCase.test_build_url

Change log

r56 by duncan.mcgreggor on Sep 11, 2009   Diff
Added examples.
Go to: 
Project members, sign in to write a code review

Older revisions

r53 by duncan.mcgreggor on Sep 7, 2009   Diff
Updated README.
r52 by duncan.mcgreggor on Sep 7, 2009   Diff
Merged twisted-support branch.

Issue:
  http://code.google.com/p/pyngfm/issu
es/detail?id=5
...
r33 by duncan.mcgreggor on Sep 6, 2009   Diff
Merged improved-results branch.

Issue:
  http://code.google.com/p/pyngfm/issu
es/detail?id=4
...
All revisions of this file

File info

Size: 2192 bytes, 82 lines
Powered by Google Project Hosting