Meet UrlyBird

By: Kriselda Rabino

Tags:

  • gem
  • uri
  • ruby
  • parsing
  • addressable

Whatever the nature of projects landing on globaldev's lap, there's always a common motive: helping our members find that special someone easier. We've learnt that sometimes it's the little ideas that make a big difference. We've also learnt that sometimes those ideas aren't quite as little or simple as we'd first expect.

One of our recent enhancements was to enable auto-login functionality from all email comms. A seemingly trivial job of parsing content, appending login tokens to any relevant site links and a bit of cryptographic fun on the side.

However, after a quick awakening regarding:

  1. our large store of custom email assets;
  2. the various email sourcing apps to update (each with their own content rendering phases); and
  3. the not so straight-forward concept of URL manipulation
...sticking auto_loginify_link functions everywhere was not going to cut it.

That's where a little birdie flew in. Our latest public release, UrlyBird is a nifty little gem that makes the process of modifying any URI-like object in place nice and easy. Simply pass UrlyBird your content, tell him your preferences (e.g. Need to filter by hostname or extension? Would you like links in anchors only or is this a plain text version?) and hand him a block of things you'd like to do with any relevant matches.

In action

# The content you want to parse and add some additional query params to
content = <<-EOL
<a href="http://urlybird.com/">Worms</a>
Worms: http://urlybird.com/search?q=worms
EOL

# UrlyBird at your service
content = UrlyBird.seek(content) do |url|
  url.query_values = (url.query_values || {}).merge(:q1 => 'one')
end

# Check your shiny, new content
puts content
The above will print:
<a href="http://urlybird.com/?q1=one">Worms</a>
Worms: http://urlybird.com/search?q=worms&q1=one
All in one fell swoop!

Credit goes to SporkMonger for the Addressable gem, which helped us overcome a few hurdles we had with the URI implementation in Ruby's standard lib.

UrlyBird has been successfully supporting our link rendering needs to date and is now available to all via RubyGems (gem install urlybird). You can find the code up on GitHub here. Improvements are always welcome. If you have any queries or contributions, we'd love to hear from you.


About the Author

Kriselda Rabino

Kriselda is a Senior Engineer at Venntro. She has a passion for all things making, whether it be code blocks in her syntax editor or shapes on the latin dancefloor.