Skip to content

Instantly share code, notes, and snippets.

@dimitarvp
Created June 18, 2011 08:32
Show Gist options
  • Save dimitarvp/1032920 to your computer and use it in GitHub Desktop.
Save dimitarvp/1032920 to your computer and use it in GitHub Desktop.
Get online info about any gem existing at rubygems.org
# Alternative way of getting all Gem details using the official Rubygems REST API (thanks @qrush)
require 'open-uri'
require 'active_support/json'
require 'awesome_print'
ap ActiveSupport::JSON.decode(open("http://rubygems.org/api/v1/gems/#{ARGV[0]}.json"))
# Web scraping approach (ugly, I know)
require 'open-uri'
require 'nokogiri'
ARGV.each do |gem|
puts '/' + '='*(gem.length+2) + '\\'
puts "| #{gem.upcase} |"
puts '\\' + '='*(gem.length+2) + '/'
html = Nokogiri::HTML.parse(open("http://rubygems.org/gems/#{gem}"))
info = html.xpath("//div[@id='markup']")
puts info.children.map { |x| x.text.strip }.join('')
puts
end
@qrush
Copy link

qrush commented Jun 19, 2011

Hi there,

You don't have to do this...we have an API!

http://guides.rubygems.org/rubygems-org-api/

Let me know if there's issues with the API or ping me in #rubygems on Freenode for help.

@dimitarvp
Copy link
Author

Thanks, I honestly had no idea about this cute REST API. :) Added another mini-script.

I can directly do this, too (works on Windows/Cygwin/Linux) --

ruby -r"awesome_print" -r"open-uri" -r"active_support/json" -e "ap ActiveSupport::JSON.decode(open('http://rubygems.org/api/v1/gems/rails.json'))"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment