<?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>Justin Leitgeb &#187; sinatra</title>
	<atom:link href="http://justinleitgeb.com/tag/sinatra/feed/" rel="self" type="application/rss+xml" />
	<link>http://justinleitgeb.com</link>
	<description>Perspectives on Ruby and OOP from a developer in NY</description>
	<lastBuildDate>Sun, 05 Sep 2010 04:43:23 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>iPhone app development with Ruby web services</title>
		<link>http://justinleitgeb.com/2009/09/iphone-app-development-with-ruby-web-services/</link>
		<comments>http://justinleitgeb.com/2009/09/iphone-app-development-with-ruby-web-services/#comments</comments>
		<pubDate>Tue, 08 Sep 2009 13:00:48 +0000</pubDate>
		<dc:creator>Justin Leitgeb</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[sinatra]]></category>

		<guid isPermaLink="false">http://justinleitgeb.com/?p=65</guid>
		<description><![CDATA[The availability of elegant Web service frameworks like Sinatra, key-value storage systems such as Tokyo Cabinet, and tools such as Core Data in the iPhone development kit can be composed to create flexible and scalable web services that extend to mobile devices, as I found in my recent development of SubwayDelay.]]></description>
			<content:encoded><![CDATA[<p>I recently submitted SubwayDelay, an application I wrote to help NYC subway riders figure out the best train to take, to the App review process.  The application should be available in the App Store in about two weeks.  In this blog post, I&#8217;ll discuss some things that I learned while creating the application, which interacts with a web service built in Ruby.  In particular, I&#8217;ll touch on creating web services with Sinatra and key-value storage systems, and on using some of the new features of iPhone OS 3.0, including Core Data.  Finally, I&#8217;ll give some pointers on navigating the technical material from Apple related to more obscure parts of the App submission process.</p>
<h2>Sinatra + Tokyo Cabinet</h2>
<p>SubwayDelay requires a server to communicate with the iPhone application.  Instead of going with the popular Ruby on Rails stack, I decided to use a lighter-weight alternative called Sinatra.  Sinatra is great when you don&#8217;t need the overhead of Rails&#8230; it&#8217;s easy to figure out what&#8217;s going on in the framework since the codebase is small, and I&#8217;ve successfully used it in several cases where a web service component is needed.  For the user-visible web pages, I used Haml and Sass instead of the usual ERB since I find those DSL implementations a bit more succinct.</p>
<p>More importantly, in this application I was faced with data that would steadily increase in size.  I wanted to make sure that application performance remained constant, without becoming steadily worse as the size of data increased.  With AT&amp;T&#8217;s current network woes, the last thing I wanted was to cause users to wait extra time for their app to load because of slow delivery speed of my web stack!</p>
<p>For readers interested in things like computational complexity, this meant that I was looking to make sure that the algorithms would be able to complete in <a href="http://en.wikipedia.org/wiki/Constant_time" target="_blank">constant time</a>.  In order to achieve this, I realized that a Hash-type data store would come in handy.  I used Tokyo Cabinet with Tokyo Tyrant, which serializes and deserializes small Ruby Hash objects as my application needs them.</p>
<p>The result was an application that was extremely quick to develop, and which should have great scaling properties.</p>
<h2>Core Data on iPhone</h2>
<p>When I was approximately halfway through developing my iPhone application, which stores user preferences, Apple released iPhone OS 3.0.  Among many improvements to the toolkit was Core Data, a feature which had only been available previously on Mac OS X for desktop computers.  Essentially, Core Data is an Object-Relational Mapping system.  It enables the user to set up a backend data store using sqlite, and helps with flushing changes, selecting objects, and instantiating the correct models for your application.</p>
<p>I realized immediately that it was exactly what I was looking for to handle storing the basic data that I needed to maintain.  I took a step back, realizing that it would probably delay the release by a few days, and dug into the Core Data learning materials on the Apple Developers web site and the sample applications.  In the end, the slight detour was well worth the effort.  I have an application that adheres to the data store that Apple suggests, and the fact that Core Data integrates well into the strict MVC framework on the iPhone was icing on the cake.  I&#8217;d recommend a similar approach to anyone currently working on an iPhone application.</p>
<h2>Apple Developer Docs and App Submission</h2>
<p>As a Ruby developer, I&#8217;m used to being able to Google just about any problem that I come across and find a solution on the web.  With the iPhone, this isn&#8217;t necessarily the case.  The NDA that Apple had in place during early App development stifled some important discussion.  Now that this has been lifted, the Internet is starting to fill up with more useful information for the iPhone developer.  In particular I&#8217;ve been impressed with <a href="http://stackoverflow.com" target="_blank">StackOverflow.com</a> for relevant and helpful exchanges among developers.</p>
<p>There are still substantial deficits in information on the web, though, especially in things like the provisioning process.  It also complicates matters a bit because I believe that Apple has made some very slight changes to their tools, rendering some public web pages obsolete.  What I found in the end is that if you follow the yellow brick road laid out by Apple, things tend to fall into place.  Having trouble getting your keys in place to release the application?  Read the HowTo guide in iTunes Connect a couple of times and nine out of ten times the suggested approach will just work.  Afterwards, maybe there will be some useful information to be gleaned by general Googling, but try to restrain yourself and you may end up fixing things faster by just reading the Apple docs closely.  They really are very well written and comprehensive.</p>
<h2>Conclusion</h2>
<p>The availability of elegant Web service frameworks like Sinatra, key-value storage systems such as Tokyo Cabinet, and tools such as Core Data in the iPhone development kit can be composed to create flexible and scalable web services that extend to mobile devices, as I found in my recent development of <a href="http://subwaydelay.com" target="_blank">SubwayDelay</a>.  Any other tools that have come in handy for you in building apps using a similar stack?  Let me know in the comments.</p>
]]></content:encoded>
			<wfw:commentRss>http://justinleitgeb.com/2009/09/iphone-app-development-with-ruby-web-services/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
