Monday, June 29, 2009

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. :)

Tuesday, June 2, 2009

Stupid Currency Tricks: Group Currencies and Heroku

Like the last screencast, this one is a result of a feature request. About 9 months ago to the day, I met Johnny & Eva Barnett at Spiderhouse Coffee through Karen Gifford, the founder of ATEN. Johnny suggested a groups feature be added to oscurrency. This happened one week after Rich and I presented the idea of using insoshi for a currency server at One Web Day Austin and first started checking in code. Multiple improvements made to oscurrency have been a direct result of Johnny Barnett's help.

In February of this year, Benjamin Bradley suggested some interesting use cases for this feature. The barn raising idea was interesting enough that Guillaume Lebleu blogged about it. If we're going to have groups, we'll need group currencies, too! This idea of easily created currencies is one of the components of the open money initiative supported by Michael Linton, the creator of LETS (unmoney convergence video).



As luck would have it, there was already yuki's group_option branch for insoshi that was relatively easily merged into oscurrency.

However, if one of the goals is to make currencies easy to create, we need software that is easy to install that does the job. Unfortunately, the search support that is included in insoshi (and therefore in oscurrency) is a bit too much for heroku.

Therefore, I found a brand new, lightweight blogging software that accepts OpenID called roll_my_blog and forked a copy which would talk to the OsCurrency API. This blogging software is easily deployed to heroku and that is how we can easily install software to create new currencies, etc.

Bonus: There is now some video footage of the early days of the Austin Time Exchange (the summer of '06). Among others interviewed, you can see and hear from current board members Karen, Rich and Sheila.
Fork me on GitHub