Add a Python and curl example of invoking the Perl simpletext services
authordbs <dbs@9efc2488-bf62-4759-914b-345cdb29e865>
Tue, 9 Nov 2010 01:59:03 +0000 (01:59 +0000)
committerdbs <dbs@9efc2488-bf62-4759-914b-345cdb29e865>
Tue, 9 Nov 2010 01:59:03 +0000 (01:59 +0000)
git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@2058 9efc2488-bf62-4759-914b-345cdb29e865

configure.ac
examples/simple_text.py.in [new file with mode: 0644]
examples/simple_text_curl.sh [new file with mode: 0644]

index 89558d3..7418c82 100644 (file)
@@ -263,6 +263,7 @@ if test x$OSRF_INSTALL_PYTHON = xtrue; then
     AC_PYTHON_MOD([setuptools])
     AC_CONFIG_FILES([
         examples/math_client.py
+        examples/simple_text.py
         src/python/Makefile
     ])
 fi
diff --git a/examples/simple_text.py.in b/examples/simple_text.py.in
new file mode 100644 (file)
index 0000000..2319e03
--- /dev/null
@@ -0,0 +1,26 @@
+#!/usr/bin/env python
+import osrf.system
+import osrf.ses
+
+# XXX: Replace with command line arguments
+file = '@CONF_DIR@/conf/opensrf_core.xml'
+method = 'opensrf.simple-text.reverse'
+text = 'raboof'
+
+# Pull connection settings from <config><opensrf> section of opensrf_core.xml
+osrf.system.System.connect(config_file=file, config_context='config.opensrf')
+
+# Set up a connection to the opensrf.math service
+session = osrf.ses.ClientSession('opensrf.simple-text')
+
+# Call one of the methods defined by the opensrf.math service
+request = session.request(method, text)
+
+# Retrieve the response from the method
+response = request.recv(timeout=2)
+
+print(response.content())
+
+# Cleanup request and connection resources
+request.cleanup()
+session.cleanup()
diff --git a/examples/simple_text_curl.sh b/examples/simple_text_curl.sh
new file mode 100644 (file)
index 0000000..c5d9b49
--- /dev/null
@@ -0,0 +1,10 @@
+#!/bin/sh
+
+# Simple demonstration of invoking a public OpenSRF method via curl
+
+# Expected output will be something like:
+# [{"__c":"osrfMessage","__p":{"threadTrace":"0","locale":"en-CA","type":"RESULT","payload":{"__c":"osrfResult","__p":{"status":"OK","statusCode":"200","content":4}}}},{"__c":"osrfMessage","__p":{"threadTrace":"0","locale":"en-CA","type":"STATUS","payload":{"__c":"osrfConnectStatus","__p":{"status":"Request Complete","statusCode":"205"}}}}]
+
+#curl -H "X-OpenSRF-service: opensrf.simple-text" --data 'osrf-msg=[{"__c":"osrfMessage","__p":{"threadTrace":0,"type":"REQUEST","payload":{"__c":"osrfMethod","__p":{"method":"opensrf.simple-text.reverse","params":["foobar"]}},"locale":"en-CA"}}]' http://localhost/osrf-http-translator
+curl -H "X-OpenSRF-service: opensrf.simple-text" --data 'osrf-msg=[{"__c":"osrfMessage","__p":{"threadTrace":0,"type":"REQUEST","payload":{"__c":"osrfMethod","__p":{"method":"opensrf.simple-text.split","params":["This is a test, it%27s only a test"]}},"locale":"en-CA"}}]' http://localhost/osrf-http-translator
+#curl -H "X-OpenSRF-service: opensrf.simple-text" --data 'osrf-msg=[{"__c":"osrfMessage","__p":{"threadTrace":0,"type":"REQUEST","payload":{"__c":"osrfMethod","__p":{"method":"opensrf.simple-text.substring","params":["foobar", 3, 1]}},"locale":"en-CA"}}]' http://localhost/osrf-http-translator