<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>James Rohal &#187; Mathematica</title>
	<atom:link href="http://jamesrohal.com/category/mathematica/feed/" rel="self" type="application/rss+xml" />
	<link>http://jamesrohal.com</link>
	<description></description>
	<lastBuildDate>Thu, 03 Sep 2009 18:35:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.3</generator>
		<item>
		<title>Updating Twitter from Mathematica</title>
		<link>http://jamesrohal.com/2009/04/05/updating-twitter-from-mathematica/</link>
		<comments>http://jamesrohal.com/2009/04/05/updating-twitter-from-mathematica/#comments</comments>
		<pubDate>Sun, 05 Apr 2009 18:19:23 +0000</pubDate>
		<dc:creator>Jim</dc:creator>
				<category><![CDATA[Mathematica]]></category>
		<category><![CDATA[Twitter]]></category>

		<guid isPermaLink="false">http://jamesrohal.com/?p=258</guid>
		<description><![CDATA[Since Twitter has become a way to instantly collaborate it seemed logical to implement a way to update your Twitter status from Mathematica. The method I created uses Web Services Link to access a WSDL based SOAP server automatically generated by NuSOAP. First, download the latest version of NuSOAP and put it in a folder [...]]]></description>
			<content:encoded><![CDATA[<p>Since Twitter has become a way to instantly collaborate it seemed logical to implement a way to update your Twitter status from <em>Mathematica</em>. The method I created uses <a href="http://reference.wolfram.com/mathematica/WebServices/guide/WebServiceOperations.html">Web Services Link</a> to access a WSDL based SOAP server automatically generated by <a href="http://www.sourceforge.net/projects/nusoap/">NuSOAP</a>.</p>
<p>First, <a href="http://sourceforge.net/project/showfiles.php?group_id=57663&#038;package_id=53241&#038;release_id=552239">download</a> the latest version of NuSOAP and put it in a folder on your server. Let&#8217;s say this folder is called &#8216;twitter&#8217; and is located in the root of your server.</p>
<p>Now we need to create the php file that will generate the WSDL service. Let&#8217;s call this file mathematica.php. Much of this code was adapted by Scott Nichol&#8217;s tutorial on <a href="http://www.scottnichol.com/nusoapprogwsdl.htm">Programming with NuSOAP using WSDL</a>.</p>
<p>[sourcecode language='php']<br />
< ?php<br />
require_once('lib/nusoap.php');<br />
$server = new soap_server();<br />
$server->configureWSDL(&#8216;twitterupdate&#8217;, &#8216;urn:twitterupdate&#8217;);<br />
$server->register(&#8216;Twitter&#8217;,<br />
    array(&#8216;name&#8217; => &#8216;xsd:string&#8217;),<br />
    array(&#8216;return&#8217; => &#8216;xsd:string&#8217;),<br />
    &#8216;urn:twitterupdate&#8217;,<br />
    &#8216;urn:twitterupdate#Twitter&#8217;,<br />
    &#8216;rpc&#8217;,<br />
    &#8216;encoded&#8217;,<br />
    &#8216;Provides the Twitter function to change your Twitter status using Mathematica&#8217;<br />
);</p>
<p>function Twitter($status) {<br />
	if strlen($status) < = 140 {<br />
		$user = 'yourtwitterusername';<br />
		$pw = 'yourtwitterpassword';<br />
		$curl_handle = curl_init();<br />
		curl_setopt($curl_handle, CURLOPT_URL, "http://twitter.com/statuses/update.xml");<br />
		curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2);<br />
		curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);<br />
		curl_setopt($curl_handle, CURLOPT_POST, 1);<br />
		curl_setopt($curl_handle, CURLOPT_POSTFIELDS, "status=$status");<br />
		curl_setopt($curl_handle, CURLOPT_USERPWD, "$user:$pw");<br />
		$buffer = curl_exec($curl_handle);<br />
		curl_close($curl_handle);<br />
	} else {<br />
		return "Your update must be 140 characters or less";<br />
	}<br />
}<br />
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';<br />
$server->service($HTTP_RAW_POST_DATA);<br />
?><br />
[/sourcecode]</p>
<p>Now to access the WSDL file generated by mathematica.php we can go to http://www.yourserver.com/twitter/mathematica.php?wsdl. This WSDL service provides the operation named Twitter which will update the status for the username and password provided in the php file. The Update operation takes a string as its only argument. </p>
<p>Now to access the Twitter operation in <em>Mathematica</em> we must first load the WebServices package and then install the service provided by automatically generated WSDL file.</p>
<p>[sourcecode language='plain']<br />
In[1]:= <<WebServices`<br />
In[2]:= InstallService["http://www.yourserver.com/twitter/mathematica.php?wsdl"]<br />
Out[2]:= {Twitter}<br />
In[3]:= Twitter["I updated my Twitter status using Mathematica: http://tinyurl.com/mm2twitter"]<br />
[/sourcecode]</p>
<p>In the future I plan on creating a persistent session so you can use the InstallService to input your Twitter username and password. I would also like to support TinyURL generation.</p>
]]></content:encoded>
			<wfw:commentRss>http://jamesrohal.com/2009/04/05/updating-twitter-from-mathematica/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>

