Skip to content
Browse files

Implement Gems::Client#downloads

  • Loading branch information...
1 parent 1b147ca commit 37a2a47b87ccce29e53b91690321577721205eed @sferik sferik committed
Showing with 27 additions and 3 deletions.
  1. +3 −3 README.md
  2. +12 −0 lib/gems/client.rb
  3. +12 −0 spec/gems/client_spec.rb
View
6 README.md
@@ -28,12 +28,12 @@ Usage Examples
# Returns an array of gem version details
puts Gems.versions 'coulda'
+ # Returns the number of downloads by day for a particular gem version
+ puts Gems.downloads 'coulda', '0.6.3'
+
# Returns an array of gem dependency details for all versions of given gems
puts Gems.dependencies ['rails', 'thor'] [pending]
- # Returns the number of downloads by day for a particular gem version
- puts Gems.downloads 'coulda', '0.6.3' [pending]
-
# The following method requires password authentication
Gems.configure do |config| [pending]
config.username 'nick@gemcutter.org'
View
12 lib/gems/client.rb
@@ -38,5 +38,17 @@ def search(query, options={})
def versions(gem, options={})
get("/api/v1/versions/#{gem}.json", options)
end
+
+ # Returns the number of downloads by day for a particular gem version
+ #
+ # @param gem [String] The name of a gem.
+ # @param version [String] The version of a gem.
+ # @param options [Hash] A customizable set of options.
+ # @return [Hashie::Mash]
+ # @example
+ # Gems.downloads 'coulda', '0.6.3'
+ def downloads(gem, version, options={})
+ get("/api/v1/versions/#{gem}-#{version}/downloads.json", options)
+ end
end
end
View
12 spec/gems/client_spec.rb
@@ -40,4 +40,16 @@
versions.first.number.should == '0.6.3'
end
end
+
+ describe "#dependencies" do
+ before do
+ stub_get("/api/v1/versions/coulda-0.6.3/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 = @client.downloads 'coulda', '0.6.3'
+ a_get("/api/v1/versions/coulda-0.6.3/downloads.json").should have_been_made
+ downloads["2011-11-01"].should == 0
+ end
+ end
end

0 comments on commit 37a2a47

Please sign in to comment.
Something went wrong with that request. Please try again.