简体   繁体   中英

Get all dependencies of a specific version of a Gem on RubyGems

Using RubyGems API, I need to request all versions of a gem (with api/v1/versions/[gem].json), and after that, for each versions, list all dependencies, like the result of api/v1/gems/[gem].json.

I looked, and the best way is to call api/v1/versions/[gem]-[version].json on a specific version, but it doesn't provide the dependencies for this version.

Is there another way to get all dependencies of a gem for a specific version ?

I found the solution. The best (and only way) is to use the dependency file of a gem, who list all dependencies of each version of the gem. To get this file, it's necessary to call the dependency address of the API : http://guides.rubygems.org/rubygems-org-api/#misc-methods (the last one).

After that, this few line do all the stuff to get dependencies of a specific version :

  url          = URI("https://rubygems.org/api/v1/dependencies?gems=#{gem_name}")
  dependencies = Net::HTTP.get(url)
  data         = Marshal.load(dependencies).each do |dependency|
    break dependency if dependency[:number] == gem_version
  end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM