<?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>techno.blog(&#34;Dion&#34;) &#187; endpoint</title>
	<atom:link href="http://almaer.com/blog/tag/endpoint/feed" rel="self" type="application/rss+xml" />
	<link>http://almaer.com/blog</link>
	<description>blogging about life, the universe, and everything tech</description>
	<lastBuildDate>Tue, 28 Aug 2012 14:41:55 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Endpoint Resolver: Getting tinyurl out of the Twitter stream</title>
		<link>http://almaer.com/blog/endpoint-resolver-getting-tinyurl-out-of-the-twitter-stream</link>
		<comments>http://almaer.com/blog/endpoint-resolver-getting-tinyurl-out-of-the-twitter-stream#comments</comments>
		<pubDate>Sun, 22 Jun 2008 14:42:44 +0000</pubDate>
		<dc:creator>dion</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Tech]]></category>
		<category><![CDATA[Web Services]]></category>
		<category><![CDATA[endpoint]]></category>
		<category><![CDATA[greasemonkey]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://almaer.com/blog/endpoint-resolver-getting-tinyurl-out-of-the-twitter-stream</guid>
		<description><![CDATA[Sometimes you can get in the zone just enough to be productive on a plane. On my flight to Mexico City yesterday, I created Endpoint a project that contains a server proxy, JavaScript client, and Greasemonkey Script with a mission. The mission is to take a URL, work out if it is a redirect (via [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes you can get in the zone just enough to be productive on a plane. On my flight to Mexico City yesterday, I created <a href="http://almaer.com/endpoint">Endpoint</a> a project that contains a <a href="http://endpoint-resolver.googlecode.com/svn/trunk/resolver.php">server proxy</a>, <a href="http://almaer.com/endpoint/twitter-resolveurl.user.js">JavaScript client</a>, and <a href="http://almaer.com/endpoint/twitter-resolveurl.user.js">Greasemonkey Script</a> with a mission. The mission is to take a URL, work out if it is a redirect (via a <code>Location:</code> header), and then return the final endpoint for it.</p>
<p><b>Why did I do this?</b></p>
<p>I was brainstorming functionality for a Twitter client with James Strachan (he is working on <a href="http://gtwit.com/">gtwit</a>) and we talked about how annoying tinyurl / is.gd / snurl / you name it URLs are. They don&#8217;t tell you where you are going, and you could get Rick Rolled (if you are lucky) or much much worse.</p>
<p>So, I wanted to create a library, and one client (Greasemonkey) to test it out. Then anyone else could use it too to resolve directly from their Web pages.</p>
<p><b>How does it work</b></p>
<p>You load up the JavaScript via <code>script src</code> and then you can call resolve, passing the URL and a callback that will get the result. A few examples:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// Simple version</span>
Endpoint.<span style="color: #660066;">resolve</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'http://snurl.com/2luj3'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>url<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
  <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>url<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// Using the original URL to work out if it has changed</span>
Endpoint.<span style="color: #660066;">resolve</span><span style="color: #009900;">&#40;</span>
  document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'testurl'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">value</span><span style="color: #339933;">,</span> 
  <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>url<span style="color: #339933;">,</span> orig<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
    <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>url<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
    <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>Endpoint.<span style="color: #660066;">isRedirecting</span><span style="color: #009900;">&#40;</span>url<span style="color: #339933;">,</span> orig<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// How it is used in the Twitter Endpoint Resolver</span>
Endpoint.<span style="color: #660066;">resolve</span><span style="color: #009900;">&#40;</span>url<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>resulturl<span style="color: #339933;">,</span> originalurl<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>Endpoint.<span style="color: #660066;">isRedirecting</span><span style="color: #009900;">&#40;</span>resulturl<span style="color: #339933;">,</span> originalurl<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #000066; font-weight: bold;">return</span><span style="color: #339933;">;</span>
&nbsp;
  newtext <span style="color: #339933;">=</span> newtext.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span>originalurl<span style="color: #339933;">,</span> resulturl<span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;g&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  jQuery<span style="color: #009900;">&#40;</span>el<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span>newtext<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Under the hood, a bunch of stuff is happening. I would love to be able to just use <code>XMLHttpRequest</code> to dynamically hit the URL and look at the headers, but the same-origin policy stops me.</p>
<p>This is why I have the server proxy, which returns a JSONP callback.</p>
<p>When you call <code>resolve(url, callback)</code> the <code>script</code> tag is created on the fly and added to the DOM. The callback function is all handled to allow multiple calls, and then the chain unravels.</p>
<p>Here you can see it all in action, showing how my Twitter stream will go through and the URLs will dynamically change from their tinyurl versions to whereyouaregoing.com:</p>
<p><object width="425" height="350"><param name="movie" value="http://www.youtube.com/v/fxuUNEhOQwk"></param><embed src="http://www.youtube.com/v/fxuUNEhOQwk" type="application/x-shockwave-flash" width="425" height="350"></embed></object></p>
<p>I wanted to use App Engine to host the server proxy, but unfortunately I can&#8217;t work out how to do that yet. You have access to the <a href="http://code.google.com/appengine/docs/urlfetch/">URLFetch</a> API to access resources from App Engine. Unfortunately for me, one of the features is that it understands redirects and just goes on through to the full resource itself, with no way to get the endpoint from the <code>headers</code> in the response.</p>
<p>It was also interesting to read <a href="http://www.techcrunch.com/2008/06/21/surviving-the-net/">Steve Gilmor talk about these services</a> all be it in a post that is hard to actually understand ;)</p>
<p>Also, Simon Willison just put up a simple service on App Engine, <a href="http://json-time.appspot.com/">json-time</a>, that &#8220;exposes Python’s pytz timezone library over JSON.&#8221; I think that we will see a lot of these types of mini-Web services hosted on App Engine. Taking Python utility and making services from its goodness is an obvious choice.</p>
]]></content:encoded>
			<wfw:commentRss>http://almaer.com/blog/endpoint-resolver-getting-tinyurl-out-of-the-twitter-stream/feed</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
	</channel>
</rss>
