Skip to content

Instantly share code, notes, and snippets.

@markrebec
Created September 30, 2015 16:00
Show Gist options
  • Save markrebec/3b83dc343fc8bfd9a344 to your computer and use it in GitHub Desktop.
Save markrebec/3b83dc343fc8bfd9a344 to your computer and use it in GitHub Desktop.
Reverse Gem Dependency Lookup
require 'net/http'
require 'json'
gem_name = ARGV[0]
def rubygems_get(gem_name: "", endpoint: "")
path = File.join("/api/v1/gems/", gem_name, endpoint).chomp("/") + ".json"
JSON.parse(Net::HTTP.get("rubygems.org", path))
end
results = rubygems_get(gem_name: gem_name, endpoint: "reverse_dependencies")
weighted_results = {}
results.each do |name|
begin
weighted_results[name] = rubygems_get(gem_name: name)["downloads"]
rescue => e
puts "#{name} #{e.message}"
end
end
weighted_results.sort {|(k1, v1), (k2, v2)| v2 <=> v1 }.first(50).each_with_index do |(k, v), i|
puts "#{i}) #{k}: #{v}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment