Created
June 18, 2011 08:32
-
-
Save dimitarvp/1032920 to your computer and use it in GitHub Desktop.
Get online info about any gem existing at rubygems.org
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
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
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.