ImgIn Ruby Gem

Malgusto web

This was a project I did while at Dev Bootcamp, it was made with a four person team in a couple of days. We decided to create a gem that help to populate mockup site designs with related images, it looked easy: run a google image search with the query, get the images links from there and insert that into your view using Imgin::Image.get( 'sloths', 'medium' ).

It looked easy

Yes, but problems arise, Google masks its Image search results with a lot of characters, and it wasn't clear how the thing was encoded. We looked at different solutions like the Flickr API, but time was scarce and there was also the problem of bandwidth limitations. Since this was a Gem, if people uses it to call Flickr we could be banned from the service pretty soon.

Yahoo to the rescue

It was all lost, but then someone pointed to Yahoo search, its search results were a lot less obfuscated than Google ones, it still took a while to decipher it, but I copied the queries and pasted it in Sublime text, where colouring and find and replace helped to refine the query.

Nokogiri

Once I figured out how the queries URL worked, it was just a matter of running the queries through the Nokogiri gem, parsing the links to the images using some Regex mojo, putting that into an array and returning a random one. The good thing is that the links saved in the array were to the actual images, not to Yahoo search, so you end up with images in your mockups from a lot of different sources, and chances of being banned for making too many calls to a service.

The gem is published although we haven-t touched it since then, you can take a look at it here source code is here

Make me an offer I can't refuse

You can reach me at: jose[at]josemenor.com

Or through your favourite social thing