<?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>devylon &#187; federation</title>
	<atom:link href="http://blog.devylon.com/tag/federation/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.devylon.com</link>
	<description>just call it friend-o</description>
	<lastBuildDate>Mon, 06 Sep 2010 11:11:02 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>Simple Twitter Agent For The Google Wave Federation Server</title>
		<link>http://blog.devylon.com/2009/08/simple-twitter-agent-for-the-google-wave-federation-server/#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://blog.devylon.com/2009/08/simple-twitter-agent-for-the-google-wave-federation-server/#comments</comments>
		<pubDate>Sat, 22 Aug 2009 11:54:01 +0000</pubDate>
		<dc:creator>devylon</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[federation]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[twitter]]></category>
		<category><![CDATA[wave]]></category>

		<guid isPermaLink="false">http://blog.devylon.com/?p=58</guid>
		<description><![CDATA[This week some code was push to the repository to implement some kind of agents for the federation server. A simple EchoAgent was added to demonstrate the code. With this as starting point I implemented a small TwitterAgent. Just add the TwitterAgent to a wave.  The agent listens to every message  and updates your twitter [...]]]></description>
			<content:encoded><![CDATA[<p>This week some code was push to the repository to implement some kind of agents for the federation server. A simple <a href="http://code.google.com/p/wave-protocol/source/browse/src/org/waveprotocol/wave/examples/fedone/agents/echoey/Echoey.java?spec=svn84a45607cb9e0cee00971fe116bb35383f6578de&amp;r=84a45607cb9e0cee00971fe116bb35383f6578de" target="_blank">EchoAgent</a> was added to demonstrate the code.</p>
<p>With this as starting point I implemented a small TwitterAgent. Just add the TwitterAgent to a wave.  The agent listens to every message  and updates your twitter status. I took the <a href="http://yusuke.homeip.net/twitter4j/en/index.html" target="_blank">twitter4j</a> API which is pretty easy to use.</p>
<pre>package org.waveprotocol.wave.examples.fedone.agents.twitter;

import java.util.ArrayList;
import java.util.List;
import org.waveprotocol.wave.examples.fedone.agents.agent.AbstractAgent;
import org.waveprotocol.wave.examples.fedone.agents.agent.AgentConnection;
import org.waveprotocol.wave.examples.fedone.util.Log;
import org.waveprotocol.wave.model.document.operation.AnnotationBoundaryMap;
import org.waveprotocol.wave.model.document.operation.Attributes;
import org.waveprotocol.wave.model.document.operation.AttributesUpdate;
import org.waveprotocol.wave.model.document.operation.BufferedDocOp;
import org.waveprotocol.wave.model.document.operation.DocOpCursor;
import org.waveprotocol.wave.model.operation.wave.WaveletDocumentOperation;
import org.waveprotocol.wave.model.wave.ParticipantId;
import org.waveprotocol.wave.model.wave.data.WaveletData;

import twitter4j.Twitter;
import twitter4j.TwitterException;

public class TwitterAgent extends AbstractAgent {
  private static final Log LOGGER = Log.get(TwitterAgent.class);
  private Twitter twitter;

  private TwitterAgent(String username, String hostname, int port, String twitterUsername, String twitterPassword) {
    super(AgentConnection.newConnection(username, hostname, port));
    this.twitter = new Twitter(twitterUsername, twitterPassword);
  }

  private void tweetLines(List lines) {
    for (String line : lines) {
      LOGGER.info("updateStatus: " + line);
      try {
        twitter.updateStatus(line);
      } catch (TwitterException e) {
        LOGGER.warning(e.getMessage(), e);
      }
    }
  }

  @Override
  public void onDocumentChanged(WaveletData wavelet, WaveletDocumentOperation documentOperation) {
    BufferedDocOp docOp = documentOperation.getOperation();
    final List lines = new ArrayList();
    docOp.apply(new DocOpCursor() {
      @Override public void annotationBoundary(AnnotationBoundaryMap map) { }
      @Override public void characters(String chars) { lines.add(chars); }
      @Override public void deleteCharacters(String chars) { }
      @Override public void deleteElementEnd() { }
      @Override public void deleteElementStart(String type, Attributes attrs) { }
      @Override public void elementEnd() { }
      @Override public void elementStart(String type, Attributes attrs) { }
      @Override public void replaceAttributes(Attributes oldAttrs, Attributes newAttrs) { }
      @Override public void retain(int itemCount) { }
      @Override public void updateAttributes(AttributesUpdate attrUpdate) { }
    });
    tweetLines(lines);
  }

  @Override
  public void onParticipantAdded(WaveletData wavelet, ParticipantId participant) { }

  @Override
  public void onParticipantRemoved(WaveletData wavelet, ParticipantId participant) { }

  @Override public void onSelfAdded(WaveletData wavelet) { }

  @Override public void onSelfRemoved(WaveletData wavelet) { }

  public static void main(String[] args) {
    try {
      if (args.length == 5) {
        int port;
        try {
          port = Integer.parseInt(args[2]);
        } catch (NumberFormatException e) {
          throw new IllegalArgumentException("Must provide valid port.");
        }

        TwitterAgent agent = new TwitterAgent(args[0], args[1], port, args[3], args[4]);
        agent.run();
      } else {
        System.out.println("usage: java TwitterAgent
  ");
      }
    } catch (Exception e) {
      System.err.println("Catastrophic failure: " + e);
      System.exit(1);
    }

    System.exit(0);
  }
}</pre>
<p>One issue with the current implementation should be mentioned: If you&#8217;ll restart the TwitterAgent all the messages will be resubmitted to your twitter account! If someone knows how to avoid this, please leave a comment.</p>
<p>Within in the next days, I&#8217;ll add some more little features (e.g. grab status updates and add them to a wave, twitter direct message gateway, &#8230;). What else could you think of?</p>
<p>This should be considered as a small demonstration and is far away from a Twitter and Google Wave integration <img src='http://blog.devylon.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.devylon.com/2009/08/simple-twitter-agent-for-the-google-wave-federation-server/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

