Retryable

Today I wanted to use the retry keyword in Ruby to retry a section of code when an error is raised. In the process I came up with a simple bit of code for handling retries easily in any class, including a callback for putting any necessary fixes in place before executing the retry:

And here is how it might be used:

Give it a try using the following:

ruby retryable_test.rb

What do you think? How can this be improved?

No Comments

Testing REST APIs with Cucumber and Rack::Test

Corey Haines has been staying here in South France with me for the last few days and we had been meaning to pair up on some coding tasks, but hadn’t been able to until today. I had in my mind already what I wanted to work on and he was happy to oblige. Our task was to set up some cucumber features that would describe the DNSimple REST API properly, allowing all of the available end points to be tested. I had worked on this in the past trying to use Webrat, but since moving the DNSimple code to Rails 3 I’ve switched to Capybara none of the old code worked. Additionally the old code was only able to handle GET requests and never properly handled POST, PUT and DELETE, nor did it handle the various content types supported by the API.

This evening Corey and I sat down and started looking into how we could make the tests live again. First we attempted to use Capybara directly, but ran into issues when trying to set HTTP headers. The DNSimple API uses Basic HTTP Authentication and thus we needed to set the header for that. We also need to set the Content-Type and Accept headers to ensure that Rails handles the input and output correctly. After peeling back some layers of the Capybara onion we landed upon Rack::Test. When using Rack, Capybara delegates request and response handling down to Rack::Test. At this point we decided to see if we could use Rack::Test directly in our step definitions, and it worked like a charm.

Rack::Test has a module called Rack::Test::Methods that can be mixed into a class to provide it with methods for get, post, put, delete as well as last_request, last_response, header and more. We mixed Rack::Test::Methods into the Cucumber world at the top of our API steps file like so:

Then our steps could simply call the Rack::Test methods directly. For example, here’s how to send the HTTP Basic Auth header:

And to set content type and accept headers:

And finally to actually send requests and test the responses. The entire api_steps.rb as it is right now looks like this:

And here is an example of a Cucumber feature that uses the API steps:

I doubt we’ve ended up with the ultimate final set of steps that can be used repeatedly for testing RESTful APIs, however I think it is an excellent start. I’m still on the fence about how to check the response body, specifically whether it is better to match the response body as a string or to actually parse it and write custom steps for each of the different types of objects, but time will tell.

As usual pairing with Corey resulted in some good code, a usable solution and something that I think others will benefit from as well.

, , , , ,

14 Comments

Cucumber and Resque Jobs

Recently I’ve begun using Resque on more and more of my projects. Resque is a very well-implemented queueing system for Rails background jobs. I also use Cucumber to describe the expected behavior of the applications I write. Cucumber expects a sequence of steps that are executed synchronously so mixing in an asynchronous task is a bit of a problem. The good news is that I’ve come up with an easy way to take those background tasks and force them to run immediately as a synchronous job with very little code.

This file goes in features/support and opens up the Resque module to replace the enqueue method with one that delegates immediately to the worker. This is a simple and effective technique and works like a charm.

, , ,

1 Comment

Social Networking or What I Really Want

Since Diaspora released it’s alpha code I’ve been thinking about what I want to get from the Internet and social networking that I am not getting now. The catalyst for this thinking is the simple question: “do I need Diaspora, and if not, then what do I really need?”

Diaspora wants to be “The privacy aware, personally controlled, do-it-all, open source social network.” A noble goal, I suppose, however what I’ve come to realize is that this doesn’t really matter to me. What really matters to me is: 1.) reinforcing my existing relationships with family and friends (for both business and non-business situations) and 2.) find people that I would like to be friends with by virtue of shared interests. How do I reinforce these relationships? Through communication. When does communication occur? Two examples include 1.) on special dates, for example on a family member’s birthday or the launch of a friend’s business and 2.) as part of open discussions where I can contribute and add value through useful information, humor or commiseration. Indeed communication can even occur at random times “just because”. The point is that there are various times where communication can occur due to time, context and/or both.

Now that I’ve expressed what I want, it’s time to take a look at what is already available – I don’t live in a fantasy world where I can randomly rebuild my entire social network – the network already is, I just want to better harness it.

Facebook

Of all of the places where I have a network, Facebook is probably the closest in vision to what I want, but it falls down in a few significant areas. First of all, my network on Facebook consists mostly of former high school friends. While I don’t mind occasionally getting back in touch with some of them, they do not represent my network that matters most to me (which consists of my family and the friends I’ve made since leaving college, most of whom are on Twitter). The other thing that bothers me about Facebook is the insistance on “real-time” interactions. I find little value out of the stream of updates from my Facebook friends, largely due to the fact that most of them are not people I expect to communicate with on a daily basis. Another problem I have with Facebook is their “platform” nature. I have two platforms that matter to me: OS X (and iOS I suppose) and the web. I really don’t want Facebook to deliver apps, I never have – I want Facebook to deliver the stories from my friends and family that will help me stay in touch. In addition to these two biggies I have several other smaller issues with Facebook, such as their less-than-stellar API and cluttered interface, but I could get past those if Facebook delivered what I really needed.

Twitter

I use Twitter a lot more than I use Facebook which I think is largely due to the fact that the people I follow on Twitter are closer to my actual network, with a few significant exceptions. Where Twitter shines is the ease of getting messages in and out. If all I wanted was a real-time feed of what my friend’s are doing and thinking and writing about then I could pretty much just use Twitter and be done with it, and for some time now this is mostly what I’ve done (and for that matter may end up being what I continue doing). All is not double rainbows though. First Twitter is fairly timezone sensitive – I miss a lot of really interesting stuff because I am in a timezone that is almost inverted from many of my friends and family. Often Twitter is like a novel where I only catch some parts of the story – I can usually fill in the rest but I am still missing a lot of the story. The other issue I have with Twitter is that there is very little context since everything is pretty much a real-time feed from the people I follow. I believe that Twitter lists were supposed to add some context, and perhaps searching does as well, but I feel like I have to jump through hoops to view Twitter in different contexts. Facebook does not do any better at this, but since I use it so little I don’t feel the pain the same way. Context is king and right now I think no social network that I use does this well.

LinkedIn

LinkedIn does one thing very well: when I think about my business network I think LinkedIn. That’s a big deal. I have not yet connected to my entire business network on LinkedIn, but I have connected with a significant portion of it. LinkedIn is not very sticky for me, but I still get significant value out of it on occasion, so I’m ok with that (and I hope they are as well). According to their blog, they’ve been in the black since 2007, so hopefully they’ll be able to continue on the path that they’re on and if they do they’ll likely remain a part of my various networks.

Gmail and Google

If I were to agree certain media outlets, Google hasn’t yet figured out how to be an active part of my social network. Naturally I disagree – Google is a significant part of my social network, just through more traditional channels like email. My Gmail contacts represent most if not all of my active social network, both friends and family. My Gmail contacts also has a lot of junk in it, but the real network is there, buried in the chaff. Google has also become part of my instant communication network through GTalk. Unlike Facebook’s chat, GTalk is something I actually use all the time. I could also see a time in the future where Google Voice becomes part of my toolset for communicating with my network, especially as these three channels, email, IM and voice, come together. Given how good Google is at indexing things they also happen to be the goto source for non real-time information about my network.

So why does the media get down on Google when it comes to Social Networking? I think it’s largely because it’s implicit – Google does it but it isn’t “the feature”, rather it is just part of all of their applications now. Had Buzz come out earlier Google could have very well been what Twitter is for me now, but it didn’t and it hasn’t, so I can’t write off everything and just use Google (I’m not sure I would even want to, but it’s almost possible so it’s worth at least thinking about).

Everything Else

Even with those “big” players I still end up with parts of my social network scattered all over the place. In addition to Facebook, Twitter, LinkedIn and Google I also have chunks of my network on Skype, Geni, Tripit, Gowalla and even in my Apple Address Book. I use Skype on a daily basis for communicating with friends and family. I use Geni for keeping up-to-date on more distant family members. I have a tiny little network on TripIt for seeing who is travelling where and I have a slightly larger network on Gowalla to see who is doing what. When I used my phone my Apple Address Book was essential, although this is less so now that I’m in Europe and haven’t activated my phone here. The bottom line is that my network and my channels of communication are scattered across multiple services: that’s reality.

Back to the Point

As I mentioned at the start of this post, what really matters to me is: 1.) reinforcing my existing relationships with family and friends (for both business and non-business situations) and 2.) find people that I would like to be friends with by virtue of shared interests. No one service does this for me, rather it is the combination of numerous services that does it. The other key point is that my network already exists, I don’t want nor can I rebuild it all in a single environment, distributed or not. Ultimately that means Diaspora is probably not for me.

So what now? I have some ideas which I may or may not put in another post. For the moment I’ll continue using Twitter as my main mode of “random” communication, I’ll continue to use the tools I have from Google for most of my directed communication and I’ll continue failing at staying in touch with everyone I want to stay in touch with as often as I’d like until I find a better way to do it.

If you have thoughts or comments on what you want from social networking, please do feel free to comment here.

,

1 Comment

SuperFeedr and PubSubHubBub

One of the challenges I deal with on a daily basis is trying to keep the feed data flowing into chi.mp home pages. It is very challenging to consume tens-of-thousands of feeds in a reliable fashion. For a long time we did this internally out of necessity. Now though we no longer need to manage this internally thanks to Superfeedr.

I started considering the idea of using Superfeedr well over six months ago, but still had concerns about their stability and viability – ultimately I got over that and realized that I need to outsource this part of chi.mp. This week I finally pushed out code for chi.mp that uses SuperFeedr’s PubSubHubBub hub to receive feed updates. Initially I used their XMPP interface, however after repeated encouragement from Julien @ Superfeedr I made the switch over to PubSubHubBub with only a small amount of work.

I still have to move a bunch of feeds over to use Superfeedr but I feel at least part of the burden of managing all of these various feeds beginning to leave my shoulders, and for that I am very thankful.

, , , , ,

No Comments

Back and Shipping In

Return from the abyss. In today’s video blog I talk about where I’ve been and give you some thoughts about what I’ll be presenting in my next video blog entries. Oh, and I mention DNSimple of course.

Also available on YouTube.

3 Comments

Ship It! DNSimple.com Is Launched

The last couple of weeks I’ve been working hard on putting the finishing touches on DNSimple, a new hosted domain name management service for small businesses and entrepreneurs. After working on domain services for more than 10 years, both as a domain registrar back in the late ’90s and through operating a domain registry and registrar for several years, it’s time for me to put together a DNS service that caters to the needs of other entrepreneurs like me.

What are the specifics? For $10/month you can to manage up to 50 domains using DNSimple. Each domain can have as many records as you need. Our DNS servers are updated almost instantly as you add records to your domain. We support TTL times as low as 1 minute. Repetitive changes can be set up as templates and we already include a default template for setting up Google MX records for domains that host their mail at Google.

I look forward to getting feedback on what you think of the service, what could be improved and what if anything would keep you from adopting it. You can either contact me via email or send me a message on Twitter. Thanks!

, , , ,

6 Comments

Company Organization

Tonight I talk about defining a company organizational structure. Even if you’re going to do all the jobs at the beginning, you’ll be better off knowing what you’re getting into.

And on YouTube: http://www.youtube.com/watch?v=51xTFOpQNcs

,

1 Comment

Motivation

Today’s video blog entry is a quick one on motivation, presented to you as a means to get myself motivated.

And on YouTube: http://www.youtube.com/watch?v=L5JGEWjYycQ

, ,

1 Comment

Keep Costs Low

In this video blog entry I talk about how to keep your costs down by using free software, low cost services and by learning instead of paying someone else to the job.

As always, find it on YouTube as well: http://www.youtube.com/watch?v=gL0mUtVOqf0

No Comments