Over the last two weeks, I bought some tickets for the upcoming festival season and some concerts. I have no materialized ideas where I'll spend my summer holidays (thinking about a trip to Ukraine; Kiev, Crimea, Odessa), but I know which festivals and concerts I'll go to. For this year it will be Dredg (Melkweg), The Mars Volta (Paradiso), Hacking at Random (Vierhouten), Lowlands (Biddinghuizen) and Porcupine Tree (HMH)! Really looking forward to all these nice events!
Archive for April, 2009
As some people might know (mostly close friends and family), last year, I wrote a song. I wrote it for my (then) girlfriend, initially on acoustic guitar and I planned to only play it a couple of times for her and keep it a private thing. After some time, I decided to make a non-acoustic version and recorded different instruments using my computer. The only problem was that I didn't have a good microphone to record the vocals and the drums were very flat, since I punched them in using a keyboard. But nevertheless, I distributed amongst some friends and family. As a birthday present from my Russian family, I got a session in a professional recording studio in Russia to record the vocals. Back home I mixed those in and the thing got better. Since I really wanted the thing to be sort of complete, I bought an electronic drum kit and recorded the drums as well. Just before christmas, my girlfriend broke up with me and my song was put on a shelf. I didn't listen to it for some time, but a couple of weeks ago, I played it again and I figured that I should do something with it. Today I decided to just put it in the wild for everybody to hear. The song is released under Creative Commons License.
Listen to it and let me know what you think. You can download it here.
As written in a previous last post, I've been busy with Rails and SOAP. I've been figuring out how to pass hashes to my remote calls instead of an argument list.
The default API requires something like:
api_method :get_my_thingy, :expects => [:id => :int, :name => :string], :returns => [Thingy.struct]
When calling this (e.g. with a ruby soap thingy) it looks something like:
soap.getMyThingy(2, "foo")
But I would like to do:
soap.getMyThingy(:id => 2, :name => "foo")
For this to happen, I introduced an OptionStruct:
module ActionWebService class OptionStruct < ActionWebService::Struct member :id, :int member :name, :string end end
After this, the API should be like:
api_method :get_my_thingy, :expects => [OptionStruct], :returns => [Thingy.struct]
See my previous post for the Thingy.struct
Over the last couple of months I've been starting new business with two friends. With one pal, I've been working on and off over the last couple of years and last autumn we decided to join forces in software development. We started developing a system for festival management (initially inspired by the lack of good systems for managing complex film festivals) and over the last months our product has taken shape. We're currently doing all the legal stuff, but we've already launched our website at http://www.jewellabs.net. Work will be done on the site over the coming weeks (some people requested screenshots of our product so I guess we'll have to make those), but I'm pretty pleased for now.
If you have any questions/comments/remarks/business proposals, let me know!
For a project, I'm currently implementing a SOAP API in Rails. The Rails application will function as a SOAP server and I'm using the datanoise activewebservice plugin for this. Implementing a SOAP API is pretty easy with this, however, I ran into some problems with returning complete model objects.
I have a model called Customer that I want to expose via my API. After setting up the API controller, I specified the following in /app/services/customer_api.rb:
class CustomerAPI < ActionWebService::API::Base api_method :get, :expects => [:int], :returns => [Customer] end
Implemented with:
def get(id) return Customer.find(id) end
Requesting the WSDL nicely gives the definition of Customer, but when making a request for a specific customer errored with the message "Cannot map Customer to SOAP/OM.". It appears that boolean values (in Ruby presented as true/false) and emtpy values (presented in Ruby as nil), were the problem. SOAP wants them as "true", "false" and "".
I solved this by extending my models with a to_struct() method that returns all attributes in a Struct. I extended both ActiveRecord::Base instances to get the instance method to_struct() inside my models and I extended ActiveRecord::Base class so it would return a Struct. The latter is needed, since the SOAP plugin wants to know the attributes and types of the Struct, without actually creating one. Here's what I did:
To extend ActiveRecord::Base with class methods create a module and put the following in your /config/environment.rb:
require 'model_extensions' ActiveRecord::Base.send(:extend, ModelExtensions)
Then in the module:
module ModelExtensions
def struct
# Check if the DataStruct is already defined
begin
eval("#{self}::DataStruct")
rescue
# Define the DataStruct class and fill it with
# members that resemble the model
class_eval <<-EOF
class DataStruct < ActionWebService::Struct
#{self}.columns.map{|c| member c.name.to_s, c.type.to_s}
end
EOF
end
return eval("#{self}::DataStruct")
end
end
Now to create a DataStruct in a model, we define the following:
module ActiveRecord
class Base
def to_struct
# Get a DataStruct and instantiate
struct = self.class.struct.new
# Set the attributes after clean-up
self.attributes.each do |k,v|
v = (v.nil?) ? "" : ((v == true) ? "true" : (v == false) ? "false" : v)
struct.send("#{k}=", v)
end
return struct
end
end
end
To finish off, we change the API implementation a bit to the following:
class CustomerAPI < ActionWebService::API::Base api_method :get, :expects => [:int], :returns => [Customer.struct] end
Implemented with:
def get(id) return Customer.find(id).to_struct end
Recent Comments