Skip to content

Instantly share code, notes, and snippets.

@rubiii
Created April 10, 2011 12:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rubiii/912307 to your computer and use it in GitHub Desktop.
Save rubiii/912307 to your computer and use it in GitHub Desktop.
find and copy the latest version of a gem
$ latest haml
Request: http://rubygems.org/api/v1/gems/haml.json
Version: 3.0.25
# cmd+v
$ 3.0.25
$ latest doesnotexist
Request: http://rubygems.org/api/v1/gems/doesnotexist.json
It will be mine. Oh yes. It will be mine.
#!/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
if e.message =~ /could not be found/
puts "It will be mine. Oh yes. It will be mine."
else
puts "Oops ..."
puts e
end
end
else
puts "gem?"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment