heroku / insoshi / oauth / oauthactiveresource / screencast

Stupid Currency Tricks: Payment Dropbox with OAuthActiveResource

OAuth support with the OsCurrency API was first demonstrated in January. Ruby on Rails developers may have noticed that I didn’t use ActiveResource with OAuth. Instead, in both the January screencast and the Twitter OAuth Consumer screencast, we coded in raw JSON. This was a bummer because, as easy as it is to write JSON, it is difficult to test, maintain and support. It would be much better if we could use ActiveResource.

The good news is that Johannes Wagener has shared his OAuthActiveResource gem. The OAuthActiveResource gem was originally used for the Soundcloud API for music drop boxes. If we can have drop boxes for music, we can have drop boxes for complementary currency.

Excited about this possibility, I created the oscurrency-ruby-api-wrapper gem to support payment drop boxes.

It is very simple code but I did run into two problems. First, I could not use the latest 0.3.5 version of the OAuth ruby gem due to this issue with posting data that is not a hash so I had to use the 0.3.4 oauth gem on the client side. Second, the OAuthActiveResource gem currently does not use the conventional way to create a resource that is a child of another. For instance, with the soundcloud api, it posts to comments.xml instead of tracks/:track_id/comments.xml. Rather than fork the OAuthActiveResource gem to change this, I changed the site class method definition in my Exchange class which is a child of Person.

Like the previous screencast, we’re using my fork of the Roll My Blog app and Heroku to show off the payment drop box.

In this demo, each payment is associated with a blog article but you could obviously associate each payment with a product instead. In the Payment::create method, I specify the edit method of the payment as the callback url when sending the visitor to the server to approve the payment.

callback_url = edit_article_payment_url(@article,@payment)

As I mention in the screencast, I didn’t make any changes at all to the OsCurrency server for this demo. The big thing that is missing is that the OsCurrency server should display the amount of the payment to the blog visitor and make sure the exchange created by the blogging software does not exceed what was authorized by the blog visitor. I will leave that for next time.

Also, I recorded some of my notes about the IIW2009a event at the Computer History Museum in Mountain View on the EFF Austin Blog. Rich and I will be speaking at the Lonestar Ruby Conference (August 27-29). If you are a Rubyist, this is a great conference that gets better every year. 🙂


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s