Created
November 10, 2015 21:42
-
-
Save parndt/80eae3d5784938deb771 to your computer and use it in GitHub Desktop.
WHO DOES YOUR GEM WORK FOR?!
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
#!/usr/bin/env ruby | |
# Thanks, http://www.schneems.com/blogs/2015-09-30-reverse-rubygems/ | |
require 'net/https' | |
require 'json' | |
require 'uri' | |
gem_name = ENV["GEM_NAME"] | |
def rubygems_get(gem_name: "", endpoint: "") | |
path = File.join("/api/v1/gems/", gem_name, endpoint).chomp("/") + ".json" | |
uri = URI.parse("https://rubygems.org#{path}") | |
http = Net::HTTP.new(uri.host, uri.port) | |
http.use_ssl = true | |
http.verify_mode = OpenSSL::SSL::VERIFY_NONE # yikes | |
request = Net::HTTP::Get.new(uri.request_uri) | |
response = http.request(request) | |
JSON.parse(response.body) | |
end | |
results = rubygems_get(gem_name: gem_name, endpoint: "reverse_dependencies") | |
require 'ruby-progressbar' # `gem install ruby-progressbar` - probably move to bundler? | |
progress_bar = ProgressBar.create(total: results.length) | |
weighted_results = {} | |
results.each do |name| | |
begin | |
weighted_results[name] = rubygems_get(gem_name: name)["downloads"] | |
progress_bar.increment | |
rescue => e | |
puts "#{name} #{e.message}" | |
end | |
end | |
puts "\n" | |
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
FYI you can use bundler/inline to declare gems https://github.com/bundler/bundler/blob/master/lib/bundler/inline.rb