Browse files

Allow users to omit a version number

  • Loading branch information...
1 parent 64ab5f3 commit f9ff70ea7925d7c86440de9715ba79e339425a4f @sferik committed Jul 1, 2011
Showing with 106 additions and 46 deletions.
  1. +24 −23 README.md
  2. +6 −3 lib/gems/client.rb
  3. +76 −20 spec/gems/client_spec.rb
View
47 README.md
@@ -19,69 +19,70 @@ Usage Examples
require 'rubygems'
require 'gems'
- # Returns some basic information about the rails gem
+ # Returns some basic information about rails.
puts Gems.info 'rails'
- # Returns an array of active gems that match the query
+ # Returns an array of active gems that match the query.
puts Gems.search 'cucumber'
- # Returns an array of gem version details
+ # Returns an array of version details for coulda.
puts Gems.versions 'coulda'
- # Returns the number of downloads by day for a particular gem version
- # for the past 90 days
+ # Returns the number of downloads by day for a particular gem version for the past 90 days.
+ # Defaults to the latest version if no version is specified.
puts Gems.downloads 'coulda', '0.6.3'
- # Returns the number of downloads by day for a particular gem version
- # for the past year
+ # Returns the number of downloads by day for a particular gem version for the past year.
puts Gems.downloads 'coulda', '0.6.3', Date.today - 365, Date.today
- # Returns an array of gem dependency details for all versions of given gems
+ # Returns an array of gem dependency details for all versions of all the given gems.
puts Gems.dependencies ['rails', 'thor']
- # Retrieve your API key using HTTP basic authentication
+ # Retrieve your API key using HTTP basic authentication.
Gems.configure do |config|
config.username = 'nick@gemcutter.org'
config.password = 'schwwwwing'
end
Gems.api_key
- # You can also find your API key at https://rubygems.org/profile/edit
- # We will attempt to load your API key from ~/.gem/credentails
- # You may also specify a custom API key
+ # The following methods require authentication.
+ # By default, we load your API key from ~/.gem/credentails
+ # You can override this default by specifying a custom API key.
Gems.configure do |config|
config.key '701243f217cdf23b1370c7b66b65ca97'
end
- # List all gems that you own
+ # List all gems that you own.
puts Gems.gems
- # View all owners of a gem that you own
+ # View all owners of a gem that you own.
puts Gems.owners 'gemcutter'
- # Add an owner to a RubyGem you own, giving that user permission to manage it
+ # Add an owner to a RubyGem you own, giving that user permission to manage it.
Gems.add_owner 'josh@technicalpickles.com', 'gemcutter'
- # Remove a user's permission to manage a RubyGem you own
+ # Remove a user's permission to manage a RubyGem you own.
Gems.remove_owner 'josh@technicalpickles.com', 'gemcutter'
- # List the webhooks registered under your account
+ # List the webhooks registered under your account.
puts Gems.web_hooks
- # Add a webhook
+ # Add a webhook.
Gems.add_web_hook 'rails', 'http://example.com'
- # Remove a webhook
+ # Remove a webhook.
Gems.remove_web_hook 'rails', 'http://example.com'
# Test fire a webhook.
Gems.fire_web_hook 'rails', 'http://example.com'
- # Remove a gem from RubyGems.org's index
- Gems.yank 'bills', '0.0.1', :platform => 'x86-darwin-10'
+ # Remove a gem from RubyGems.org's index.
+ # Defaults to the latest version if no version is specified.
+ Gems.yank 'bills', '0.0.1'
- # Update a previously yanked gem back into RubyGems.org's index
- Gems.unyank 'bills', '0.0.1', :platform => 'x86-darwin-10'
+ # Update a previously yanked gem back into RubyGems.org's index.
+ # Defaults to the latest version if no version is specified.
+ Gems.unyank 'bills', '0.0.1'
Contributing
------------
View
9 lib/gems/client.rb
@@ -57,7 +57,8 @@ def versions(gem_name)
# @return [Hashie::Mash]
# @example
# Gems.downloads 'coulda', '0.6.3', Date.today - 30, Date.today
- def downloads(gem_name, gem_version, from=nil, to=Date.today)
+ def downloads(gem_name, gem_version=nil, from=nil, to=Date.today)
+ gem_version ||= info(gem_name).version
if from
get("/api/v1/versions/#{gem_name}-#{gem_version}/downloads/search", {:from => from.to_s, :to => to.to_s}, :json)
else
@@ -181,7 +182,8 @@ def fire_web_hook(gem_name, url)
# @return [String]
# @example
# Gems.yank("gemcutter", "0.2.1", {:platform => "x86-darwin-10"})
- def yank(gem_name, gem_version, options={})
+ def yank(gem_name, gem_version=nil, options={})
+ gem_version ||= info(gem_name).version
delete("/api/v1/gems/yank", options.merge(:gem_name => gem_name, :version => gem_version), :raw)
end
@@ -194,7 +196,8 @@ def yank(gem_name, gem_version, options={})
# @return [String]
# @example
# Gems.unyank("gemcutter", "0.2.1", {:platform => "x86-darwin-10"})
- def unyank(gem_name, gem_version, options={})
+ def unyank(gem_name, gem_version=nil, options={})
+ gem_version ||= info(gem_name).version
put("/api/v1/gems/unyank", options.merge(:gem_name => gem_name, :version => gem_version), :raw)
end
end
View
96 spec/gems/client_spec.rb
@@ -68,6 +68,22 @@
end
describe ".downloads" do
+ context "with no dates or version specified" do
+ before do
+ stub_get("/api/v1/gems/coulda.json").
+ to_return(:body => fixture("rails.json"))
+ stub_get("/api/v1/versions/coulda-3.0.9/downloads.json").
+ to_return(:body => fixture("downloads.json"))
+ end
+
+ it "should return the number of downloads by day for a particular gem version" do
+ downloads = Gems.downloads 'coulda'
+ a_get("/api/v1/versions/coulda-3.0.9/downloads.json").
+ should have_been_made
+ downloads["2011-06-22"].should == 8
+ end
+ end
+
context "with no dates specified" do
before do
stub_get("/api/v1/versions/coulda-0.6.3/downloads.json").
@@ -278,34 +294,74 @@
end
describe ".yank" do
- before do
- stub_delete("/api/v1/gems/yank").
- with(:query => {:gem_name => "gems", :version => "0.0.8"}).
- to_return(:body => fixture("yank"))
+ context "with no version specified" do
+ before do
+ stub_get("/api/v1/gems/gems.json").
+ to_return(:body => fixture("rails.json"))
+ stub_delete("/api/v1/gems/yank").
+ with(:query => {:gem_name => "gems", :version => "3.0.9"}).
+ to_return(:body => fixture("yank"))
+ end
+
+ it "should remove a gem from RubyGems.org's index" do
+ yank = Gems.yank("gems")
+ a_delete("/api/v1/gems/yank").
+ with(:query => {:gem_name => "gems", :version => "3.0.9"}).
+ should have_been_made
+ yank.should == "Successfully yanked gem: gems (0.0.8)"
+ end
end
- it "should remove a gem from RubyGems.org's index" do
- yank = Gems.yank("gems", "0.0.8")
- a_delete("/api/v1/gems/yank").
- with(:query => {:gem_name => "gems", :version => "0.0.8"}).
- should have_been_made
- yank.should == "Successfully yanked gem: gems (0.0.8)"
+ context "with a version specified" do
+ before do
+ stub_delete("/api/v1/gems/yank").
+ with(:query => {:gem_name => "gems", :version => "0.0.8"}).
+ to_return(:body => fixture("yank"))
+ end
+
+ it "should remove a gem from RubyGems.org's index" do
+ yank = Gems.yank("gems", "0.0.8")
+ a_delete("/api/v1/gems/yank").
+ with(:query => {:gem_name => "gems", :version => "0.0.8"}).
+ should have_been_made
+ yank.should == "Successfully yanked gem: gems (0.0.8)"
+ end
end
end
describe ".unyank" do
- before do
- stub_put("/api/v1/gems/unyank").
- with(:body => {:gem_name => "gems", :version => "0.0.8"}).
- to_return(:body => fixture("unyank"))
+ context "with no version specified" do
+ before do
+ stub_get("/api/v1/gems/gems.json").
+ to_return(:body => fixture("rails.json"))
+ stub_put("/api/v1/gems/unyank").
+ with(:body => {:gem_name => "gems", :version => "3.0.9"}).
+ to_return(:body => fixture("unyank"))
+ end
+
+ it "should update a previously yanked gem back into RubyGems.org's index" do
+ unyank = Gems.unyank("gems")
+ a_put("/api/v1/gems/unyank").
+ with(:body => {:gem_name => "gems", :version => "3.0.9"}).
+ should have_been_made
+ unyank.should == "Successfully unyanked gem: gems (0.0.8)"
+ end
end
- it "should update a previously yanked gem back into RubyGems.org's index" do
- unyank = Gems.unyank("gems", "0.0.8")
- a_put("/api/v1/gems/unyank").
- with(:body => {:gem_name => "gems", :version => "0.0.8"}).
- should have_been_made
- unyank.should == "Successfully unyanked gem: gems (0.0.8)"
+ context "with a version specified" do
+ before do
+ stub_put("/api/v1/gems/unyank").
+ with(:body => {:gem_name => "gems", :version => "0.0.8"}).
+ to_return(:body => fixture("unyank"))
+ end
+
+ it "should update a previously yanked gem back into RubyGems.org's index" do
+ unyank = Gems.unyank("gems", "0.0.8")
+ a_put("/api/v1/gems/unyank").
+ with(:body => {:gem_name => "gems", :version => "0.0.8"}).
+ should have_been_made
+ unyank.should == "Successfully unyanked gem: gems (0.0.8)"
+ end
end
end
end

0 comments on commit f9ff70e

Please sign in to comment.