Skip to content

Instantly share code, notes, and snippets.

@kevinlinxc
Last active August 15, 2022 22:55
Show Gist options
  • Save kevinlinxc/9fc3fa6603eb43613d5427d885e5c351 to your computer and use it in GitHub Desktop.
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
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