public
Last active

find and copy the latest version of a gem

  • Download Gist
gistfile1.txt
1 2 3 4 5 6
$ latest haml
request: http://rubygems.org/api/v1/gems/haml.json
version: 3.0.25
 
# cmd+v
$ 3.0.25
latest.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
#!/usr/bin/env ruby
require "net/http"
require "uri"
require "json"
 
if gem = ARGV.first
uri = URI.parse("http://rubygems.org/api/v1/gems/#{gem}.json")
puts "request: #{uri}"
 
begin
response = Net::HTTP.get_response(uri)
version = JSON.parse(response.body)["version"]
puts "version: #{version}"
`echo "#{version}" | pbcopy`
rescue => e
puts "oops ..."
puts e
end
else
puts "what?"
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.