Last active
August 15, 2022 22:55
-
-
Save kevinlinxc/9fc3fa6603eb43613d5427d885e5c351 to your computer and use it in GitHub Desktop.
Get a list of direct dependencies for a gem using the RubyGems.org API
This file contains hidden or 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
def get_dependencies(gem_name) | |
# query rubygems.org api for dependencies of gem_name | |
# return array of dependencies | |
# requires uri, net/http, and json | |
uri = URI("https://rubygems.org/api/v1/gems/#{gem_name}.json") | |
response = Net::HTTP.get_response(uri) | |
res = JSON.parse(response.body) if response.is_a?(Net::HTTPSuccess) | |
res["dependencies"]["runtime"].map { |dep| dep["name"] } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment