<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="../../assets/xml/rss.xsl" media="all"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Mariano Guerra's Log (Publicaciones sobre pshb)</title><link>http://marianoguerra.org/</link><description></description><atom:link href="http://marianoguerra.org/es/categories/pshb.xml" rel="self" type="application/rss+xml"></atom:link><language>es</language><lastBuildDate>Mon, 18 Nov 2024 17:56:39 GMT</lastBuildDate><generator>Nikola (getnikola.com)</generator><docs>http://blogs.law.harvard.edu/tech/rss</docs><item><title>PubHubSubBub Developer Tutorial</title><link>http://marianoguerra.org/es/posts/201103pubhubsubbub-developer-tutorial/</link><dc:creator>Mariano Guerra</dc:creator><description>&lt;p&gt;Note: the project and this document are hosted here: &lt;a href="https://github.com/marianoguerra/pshb-example"&gt;https://github.com/marianoguerra/pshb-example &lt;/a&gt;improvements and corrections are welcome!&lt;br&gt;&lt;br&gt;welcome, this document contains an example application written in python that will help you play with a pshb (pubsubhubbub from now on) hub and an application that publishes its content to it.&lt;br&gt;&lt;br&gt;this guide explains how to install a pubsubhubbub server in your computer so you can play with it, normally on a web application you would use a pshb compatible server like:&lt;br&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;official pshb hub on app engine: &lt;a href="http://pubsubhubbub.appspot.com/"&gt;http://pubsubhubbub.appspot.com/&lt;/a&gt;&lt;/li&gt;&lt;li&gt;superfeedr hub: &lt;a href="http://superfeedr.com/"&gt;http://superfeedr.com/&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div class="section" id="requirements"&gt;&lt;h1&gt; &lt;/h1&gt;&lt;h1&gt;Requirements&lt;/h1&gt;&lt;h1&gt; &lt;/h1&gt;&lt;blockquote&gt;&lt;ul class="simple"&gt;&lt;li&gt;python &amp;gt;= 2.5 (I'm using 2.6.1)&lt;/li&gt;&lt;li&gt;git (for the example)&lt;/li&gt;&lt;li&gt;subversion (to download pshb code)&lt;/li&gt;&lt;li&gt;bash or similar shell to run the scripts&lt;/li&gt;&lt;/ul&gt;&lt;/blockquote&gt;&lt;/div&gt;&lt;div class="section" id="installing"&gt;&lt;h1&gt; &lt;/h1&gt;&lt;h1&gt;Installing&lt;/h1&gt;&lt;h1&gt; &lt;/h1&gt;&lt;pre class="literal-block"&gt;git clone https://github.com/marianoguerra/pshb-example.git&lt;br&gt;cd pshb-example&lt;br&gt;bash setup.sh&lt;/pre&gt;&lt;pre class="literal-block"&gt;&lt;/pre&gt;the first command will fetch the project from github, the third one will get some libraries needed for the example to run.&lt;br&gt;&lt;br&gt;note: answer "y" to sammy and "n" to all the other questions that the script does (we don't need those libraries)&lt;/div&gt;&lt;div class="section" id="running"&gt;&lt;h1&gt; &lt;/h1&gt;&lt;h1&gt;Running&lt;/h1&gt;&lt;h1&gt; &lt;/h1&gt;now we will start the example application called pleinu twice (so we can test the communication using the hub) and we will start a local pshb hub.&lt;br&gt;&lt;br&gt;open 3 terminals and run one comment on each one:&lt;br&gt;&lt;br&gt;&lt;pre class="literal-block"&gt;google_appengine/dev_appserver.py src/ -p 8000 --datastore_path=/tmp/tubes1&lt;br&gt;google_appengine/dev_appserver.py src/ -p 8001 --datastore_path=/tmp/tubes2&lt;br&gt;google_appengine/dev_appserver.py pubsubhubbub/hub/&lt;/pre&gt;&lt;pre class="literal-block"&gt;&lt;/pre&gt;this commands asume that you are at the root of the pshb-example folder.&lt;/div&gt;&lt;div class="section" id="playing"&gt;&lt;h1&gt; &lt;/h1&gt;&lt;h1&gt;Playing&lt;/h1&gt;&lt;h1&gt; &lt;/h1&gt;open a browser tabs pointing to:&lt;br&gt;&lt;blockquote&gt;&lt;ul class="simple"&gt;&lt;li&gt;&lt;a class="reference external" href="http://localhost:8000/"&gt;http://localhost:8000/&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/blockquote&gt;click the signup link and create a new user.&lt;br&gt;&lt;br&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="https://github.com/marianoguerra/pshb-example/raw/master/doc/img/pshb-1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="121" src="https://github.com/marianoguerra/pshb-example/raw/master/doc/img/pshb-1.png" width="320"&gt;&lt;/a&gt;&lt;/div&gt;&lt;br&gt;&lt;br&gt;I will create one called spongebob, you will have to change the username whenever you see it.&lt;br&gt;&lt;br&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="https://github.com/marianoguerra/pshb-example/raw/master/doc/img/pshb-2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="119" src="https://github.com/marianoguerra/pshb-example/raw/master/doc/img/pshb-2.png" width="320"&gt;&lt;/a&gt;&lt;/div&gt;&lt;br&gt;&lt;br&gt;after the signup process click the login button and enter the user and password you just entered.&lt;br&gt;&lt;br&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="https://github.com/marianoguerra/pshb-example/raw/master/doc/img/pshb-3.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="62" src="https://github.com/marianoguerra/pshb-example/raw/master/doc/img/pshb-3.png" width="320"&gt;&lt;/a&gt;&lt;/div&gt;&lt;br&gt;&lt;br&gt;create a message and click send, the message should appear below.&lt;br&gt;&lt;br&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="https://github.com/marianoguerra/pshb-example/raw/master/doc/img/pshb-4.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="90" src="https://github.com/marianoguerra/pshb-example/raw/master/doc/img/pshb-4.png" width="320"&gt;&lt;/a&gt;&lt;/div&gt;&lt;br&gt;&lt;br&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="https://github.com/marianoguerra/pshb-example/raw/master/doc/img/pshb-5.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="116" src="https://github.com/marianoguerra/pshb-example/raw/master/doc/img/pshb-5.png" width="320"&gt;&lt;/a&gt;&lt;/div&gt;&lt;br&gt;&lt;br&gt;now go to &lt;a class="reference external" href="http://localhost:8000/atom/messages/from/spongebob/"&gt;http://localhost:8000/atom/messages/from/spongebob/&lt;/a&gt;&lt;br&gt;&lt;br&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="https://github.com/marianoguerra/pshb-example/raw/master/doc/img/pshb-6.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="233" src="https://github.com/marianoguerra/pshb-example/raw/master/doc/img/pshb-6.png" width="320"&gt;&lt;/a&gt;&lt;/div&gt;&lt;br&gt;&lt;br&gt;you should see an atom feed with the message you just created.&lt;/div&gt;&lt;div class="section" id="publishing"&gt;&lt;h1&gt; &lt;/h1&gt;&lt;h1&gt;Publishing&lt;/h1&gt;&lt;h1&gt; &lt;/h1&gt;now that we have a page that generates information we need to publish it on the hub.&lt;br&gt;&lt;br&gt;open a tab in your browser pointing to &lt;a class="reference external" href="http://localhost:8080/"&gt;http://localhost:8080/&lt;/a&gt; and click on the publish link near the bottom.&lt;br&gt;&lt;br&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="https://github.com/marianoguerra/pshb-example/raw/master/doc/img/pshb-7.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="320" src="https://github.com/marianoguerra/pshb-example/raw/master/doc/img/pshb-7.png" width="317"&gt;&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="section" id="publishing"&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="https://github.com/marianoguerra/pshb-example/raw/master/doc/img/pshb-8.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="320" src="https://github.com/marianoguerra/pshb-example/raw/master/doc/img/pshb-8.png" width="300"&gt;&lt;/a&gt;&lt;/div&gt;&lt;br&gt;&lt;br&gt;if you get an error remove the s from the https protocol in the address bar and refresh.&lt;br&gt;&lt;br&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="https://github.com/marianoguerra/pshb-example/raw/master/doc/img/pshb-9.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="88" src="https://github.com/marianoguerra/pshb-example/raw/master/doc/img/pshb-9.png" width="320"&gt;&lt;/a&gt;&lt;/div&gt;&lt;br&gt;&lt;br&gt;on the Topic field enter the url to the atom feed we saw before: &lt;a class="reference external" href="http://localhost:8000/atom/messages/from/spongebob/"&gt;http://localhost:8000/atom/messages/from/spongebob/&lt;/a&gt;&lt;br&gt;&lt;br&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="https://github.com/marianoguerra/pshb-example/raw/master/doc/img/pshb-10.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="146" src="https://github.com/marianoguerra/pshb-example/raw/master/doc/img/pshb-10.png" width="320"&gt;&lt;/a&gt;&lt;/div&gt;&lt;br&gt;&lt;br&gt;and click Publish, the page wont change, that's ok.&lt;/div&gt;&lt;div class="section" id="subscribing"&gt;&lt;h1&gt; &lt;/h1&gt;&lt;h1&gt;Subscribing&lt;/h1&gt;&lt;h1&gt; &lt;/h1&gt;now we need to subscribe one user from the other site (&lt;a class="reference external" href="http://localhost:8001/"&gt;http://localhost:8001/&lt;/a&gt;) to the messages sent by our user.&lt;br&gt;&lt;br&gt;go to &lt;a class="reference external" href="http://localhost:8001/"&gt;http://localhost:8001/&lt;/a&gt; and create another user, I will call it patrick&lt;br&gt;&lt;br&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="https://github.com/marianoguerra/pshb-example/raw/master/doc/img/pshb-11.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="121" src="https://github.com/marianoguerra/pshb-example/raw/master/doc/img/pshb-11.png" width="320"&gt;&lt;/a&gt;&lt;/div&gt;&lt;br&gt;&lt;br&gt;in the main page of the hub (&lt;a class="reference external" href="http://localhost:8080/"&gt;http://localhost:8080/&lt;/a&gt;) click on the subscribe like near the bottom&lt;br&gt;&lt;br&gt;enter &lt;a class="reference external" href="http://localhost:8001/p/notify/patrick/"&gt;http://localhost:8001/p/notify/patrick/&lt;/a&gt; on the Callback field (change patrick for your username if you used another one) enter &lt;a class="reference external" href="http://localhost:8000/atom/messages/from/spongebob/"&gt;http://localhost:8000/atom/messages/from/spongebob/&lt;/a&gt; on the Topic field (change spongebob for your username if you used another one)&lt;br&gt;&lt;br&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="https://github.com/marianoguerra/pshb-example/raw/master/doc/img/pshb-12.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="320" src="https://github.com/marianoguerra/pshb-example/raw/master/doc/img/pshb-12.png" width="308"&gt;&lt;/a&gt;&lt;/div&gt;&lt;br&gt;&lt;br&gt;click the "Do it" button, the page won't change, that's ok.&lt;/div&gt;&lt;div class="section" id="sending-a-message"&gt;&lt;h1&gt; &lt;/h1&gt;&lt;h1&gt;Sending a message&lt;/h1&gt;&lt;h1&gt; &lt;/h1&gt;Go to &lt;a class="reference external" href="http://localhost:8000/"&gt;http://localhost:8000/&lt;/a&gt; (login if you closed it) and send a message.&lt;br&gt;&lt;br&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="https://github.com/marianoguerra/pshb-example/raw/master/doc/img/pshb-13.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="213" src="https://github.com/marianoguerra/pshb-example/raw/master/doc/img/pshb-13.png" width="320"&gt;&lt;/a&gt;&lt;/div&gt;&lt;br&gt;&lt;br&gt; Now go to &lt;a class="reference external" href="http://localhost:8001/"&gt;http://localhost:8001/&lt;/a&gt; and refresh the page, you should see the messages published by the user in the other site.&lt;br&gt;&lt;br&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="https://github.com/marianoguerra/pshb-example/raw/master/doc/img/pshb-16.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="214" src="https://github.com/marianoguerra/pshb-example/raw/master/doc/img/pshb-16.png" width="320"&gt;&lt;/a&gt;&lt;/div&gt;&lt;br&gt;&lt;br&gt;&lt;div class="note"&gt;&lt;div class="first admonition-title"&gt;&lt;b&gt;Note&lt;/b&gt;&lt;/div&gt;&lt;div class="first admonition-title"&gt;&lt;br&gt;&lt;/div&gt;&lt;i&gt; &lt;/i&gt;&lt;br&gt;&lt;div class="last"&gt;&lt;i&gt;to make it work and avoid an exception I had to add a  return statement at the beginning of the log_message function at  google_appengine/google/appengine/tools/dev_appserver.py&lt;/i&gt;&lt;/div&gt;&lt;/div&gt;&lt;br&gt;if you get that exception like this:&lt;br&gt;&lt;br&gt;&lt;pre class="literal-block"&gt;in log_request&lt;br&gt;    self.requestline, str(code), str(size))&lt;br&gt;  File "/home/asd/pubsubhubbub/pshb/google_appengine/google/appengine/&lt;br&gt;tools/dev_appserver.py", line 3314, in log_message&lt;br&gt;    if self.channel_poll_path_re.match(self.path):&lt;br&gt;AttributeError: DevAppServerRequestHandler instance has no attribute&lt;br&gt;'path'&lt;/pre&gt;&lt;pre class="literal-block"&gt;&lt;/pre&gt;edit the function to look like this:&lt;br&gt;&lt;pre class="literal-block"&gt; &lt;/pre&gt;&lt;pre class="literal-block"&gt;def log_message(self, format, *args):&lt;br&gt;  """Redirect log messages through the logging module."""&lt;br&gt;  return&lt;br&gt;  if self.channel_poll_path_re.match(self.path):&lt;br&gt;    logging.debug(format, *args)&lt;br&gt;  else:&lt;br&gt;    logging.info(format, *args)&lt;br&gt;&lt;/pre&gt;&lt;br&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="https://github.com/marianoguerra/pshb-example/raw/master/doc/img/pshb-15.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="142" src="https://github.com/marianoguerra/pshb-example/raw/master/doc/img/pshb-15.png" width="320"&gt;&lt;/a&gt;&lt;/div&gt;&lt;br&gt;&lt;br&gt;you will have to set write permissions to the file to save it (chmod u+w dev_appserver.py)&lt;br&gt;&lt;br&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="https://github.com/marianoguerra/pshb-example/raw/master/doc/img/pshb-14.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="137" src="https://github.com/marianoguerra/pshb-example/raw/master/doc/img/pshb-14.png" width="320"&gt;&lt;/a&gt;&lt;/div&gt;&lt;br&gt;&lt;br&gt;you will have to restart the pshb server:&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;pre class="literal-block"&gt;google_appengine/dev_appserver.py pubsubhubbub/hub/&lt;/pre&gt;&lt;/div&gt;</description><guid>http://marianoguerra.org/es/posts/201103pubhubsubbub-developer-tutorial/</guid><pubDate>Tue, 15 Mar 2011 02:22:00 GMT</pubDate></item></channel></rss>