2012-09-24

Activity Streams for Ruby

Finally started taking the time to really dig in to Ruby... it really is a beautiful language. In order to really start cutting my teeth on it, I decided to write up something useful: An Activity Streams implementation. It still has a long ways to go until it's ready to be released into the wild, but so far it's coming along nicely.

I decided to go with a domain-specific language approach for generating activity streams objects. For example:

  include ActivityStreams

  activity = activity {
    verb :post
    actor person { 
      display_name 'James'
    }
    object note {
      display_name 'Having fun with ruby'
    }
    updated now
    published now
    start_time now
    end_time now + 3.hours
  }

  puts activity

Which yields:

  {
    "objectType":"activity",
    "verb":"post",
    "actor":{
      "objectType":"person",
      "display_name":"James"
    },
    "updated":"2012-09-24T15:18:20Z",
    "published":"2012-09-24T15:18:20Z",
    "start-time":"2012-09-24T15:18:20Z",
    "end-time":"2012-09-24T18:18:20Z"
  }

Will have more details later once I get a bit further down the road with it. Will be having the code up on my github repo soon.

Update: Ok, the initial code is in github... be kind, I'm still fairly new to Ruby and still learning it's various idioms and quirks.. Here's an example:

And here's the source: https://github.com/jasnell/js.strea.ms

No comments:

Post a Comment