Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fetch YAML response for downloads

Progress toward #4 (removing multi_json dependency).
  • Loading branch information...
commit 7f9db195905d73dbca97759f8298b42f855a2a15 1 parent 0a3143b
@sferik authored
View
6 lib/gems/client.rb
@@ -83,11 +83,11 @@ def total_downloads(gem_name=nil, gem_version=nil)
def downloads(gem_name, gem_version=nil, from=nil, to=Date.today)
gem_version ||= info(gem_name)['version']
response = if from
- get("/api/v1/versions/#{gem_name}-#{gem_version}/downloads/search.json", {:from => from.to_s, :to => to.to_s})
+ get("/api/v1/versions/#{gem_name}-#{gem_version}/downloads/search.yaml", {:from => from.to_s, :to => to.to_s})
else
- get("/api/v1/versions/#{gem_name}-#{gem_version}/downloads.json")
+ get("/api/v1/versions/#{gem_name}-#{gem_version}/downloads.yaml")
end
- MultiJson.decode(response)
+ YAML.load(response)
end
# Returns an array of hashes for all versions of given gems
View
0  spec/fixtures/add_owner.json → spec/fixtures/add_owner
File renamed without changes
View
1  spec/fixtures/downloads.json
@@ -1 +0,0 @@
-{"2011-03-27":0,"2011-03-28":1,"2011-03-29":0,"2011-03-30":1,"2011-03-31":0,"2011-04-01":0,"2011-04-02":0,"2011-04-03":1,"2011-04-04":1,"2011-04-05":1,"2011-04-06":4,"2011-04-07":5,"2011-04-08":1,"2011-04-09":2,"2011-04-10":4,"2011-04-11":3,"2011-04-12":8,"2011-04-13":5,"2011-04-14":14,"2011-04-15":1,"2011-04-16":1,"2011-04-17":4,"2011-04-18":1,"2011-04-19":15,"2011-04-20":4,"2011-04-21":16,"2011-04-22":6,"2011-04-23":5,"2011-04-24":4,"2011-04-25":9,"2011-04-26":7,"2011-04-27":11,"2011-04-28":12,"2011-04-29":6,"2011-04-30":7,"2011-05-01":5,"2011-05-02":9,"2011-05-03":11,"2011-05-04":6,"2011-05-05":6,"2011-05-06":4,"2011-05-07":5,"2011-05-08":8,"2011-05-09":11,"2011-05-10":5,"2011-05-11":2,"2011-05-12":1,"2011-05-13":3,"2011-05-14":8,"2011-05-15":10,"2011-05-16":7,"2011-05-17":4,"2011-05-18":2,"2011-05-19":5,"2011-05-20":2,"2011-05-21":5,"2011-05-22":7,"2011-05-23":8,"2011-05-24":11,"2011-05-25":9,"2011-05-26":3,"2011-05-27":0,"2011-05-28":2,"2011-05-29":2,"2011-05-30":7,"2011-05-31":2,"2011-06-01":7,"2011-06-02":4,"2011-06-03":5,"2011-06-04":1,"2011-06-05":25,"2011-06-06":6,"2011-06-07":9,"2011-06-08":13,"2011-06-09":1,"2011-06-10":4,"2011-06-11":5,"2011-06-12":10,"2011-06-13":3,"2011-06-14":10,"2011-06-15":10,"2011-06-16":27,"2011-06-17":4,"2011-06-18":0,"2011-06-19":8,"2011-06-20":14,"2011-06-21":23,"2011-06-22":8,"2011-06-23":0,"2011-06-24":0}
View
91 spec/fixtures/downloads.yaml
@@ -0,0 +1,91 @@
+--- !omap
+- "2011-04-28": 12
+- "2011-04-29": 6
+- "2011-04-30": 7
+- "2011-05-01": 5
+- "2011-05-02": 9
+- "2011-05-03": 11
+- "2011-05-04": 6
+- "2011-05-05": 6
+- "2011-05-06": 4
+- "2011-05-07": 5
+- "2011-05-08": 8
+- "2011-05-09": 11
+- "2011-05-10": 5
+- "2011-05-11": 2
+- "2011-05-12": 1
+- "2011-05-13": 3
+- "2011-05-14": 8
+- "2011-05-15": 10
+- "2011-05-16": 7
+- "2011-05-17": 4
+- "2011-05-18": 2
+- "2011-05-19": 5
+- "2011-05-20": 2
+- "2011-05-21": 5
+- "2011-05-22": 7
+- "2011-05-23": 8
+- "2011-05-24": 11
+- "2011-05-25": 9
+- "2011-05-26": 3
+- "2011-05-27": 0
+- "2011-05-28": 2
+- "2011-05-29": 2
+- "2011-05-30": 7
+- "2011-05-31": 2
+- "2011-06-01": 7
+- "2011-06-02": 4
+- "2011-06-03": 5
+- "2011-06-04": 1
+- "2011-06-05": 25
+- "2011-06-06": 6
+- "2011-06-07": 9
+- "2011-06-08": 13
+- "2011-06-09": 1
+- "2011-06-10": 4
+- "2011-06-11": 5
+- "2011-06-12": 10
+- "2011-06-13": 3
+- "2011-06-14": 10
+- "2011-06-15": 10
+- "2011-06-16": 27
+- "2011-06-17": 4
+- "2011-06-18": 0
+- "2011-06-19": 8
+- "2011-06-20": 14
+- "2011-06-21": 23
+- "2011-06-22": 8
+- "2011-06-23": 0
+- "2011-06-24": 1
+- "2011-06-25": 0
+- "2011-06-26": 2
+- "2011-06-27": 7
+- "2011-06-28": 6
+- "2011-06-29": 2
+- "2011-06-30": 4
+- "2011-07-01": 21
+- "2011-07-02": 8
+- "2011-07-03": 8
+- "2011-07-04": 3
+- "2011-07-05": 10
+- "2011-07-06": 7
+- "2011-07-07": 6
+- "2011-07-08": 5
+- "2011-07-09": 4
+- "2011-07-10": 2
+- "2011-07-11": 10
+- "2011-07-12": 2
+- "2011-07-13": 5
+- "2011-07-14": 4
+- "2011-07-15": 1
+- "2011-07-16": 0
+- "2011-07-17": 0
+- "2011-07-18": 0
+- "2011-07-19": 0
+- "2011-07-20": 0
+- "2011-07-21": 31
+- "2011-07-22": 2
+- "2011-07-23": 1
+- "2011-07-24": 2
+- "2011-07-25": 0
+- "2011-07-26": 0
View
1  spec/fixtures/owners.json
@@ -1 +0,0 @@
-[{"email":"sferik@gmail.com"}]
View
0  spec/fixtures/remove_owner.json → spec/fixtures/remove_owner
File renamed without changes
View
30 spec/gems/client_spec.rb
@@ -106,13 +106,15 @@
before do
stub_get("/api/v1/gems/coulda.yaml").
to_return(:body => fixture("rails.yaml"))
- stub_get("/api/v1/versions/coulda-3.0.9/downloads.json").
- to_return(:body => fixture("downloads.json"))
+ stub_get("/api/v1/versions/coulda-3.0.9/downloads.yaml").
+ to_return(:body => fixture("downloads.yaml"))
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").
+ a_get("/api/v1/gems/coulda.yaml").
+ should have_been_made
+ a_get("/api/v1/versions/coulda-3.0.9/downloads.yaml").
should have_been_made
downloads['2011-06-22'].should == 8
end
@@ -120,13 +122,13 @@
context "with no dates specified" do
before do
- stub_get("/api/v1/versions/coulda-0.6.3/downloads.json").
- to_return(:body => fixture("downloads.json"))
+ stub_get("/api/v1/versions/coulda-0.6.3/downloads.yaml").
+ to_return(:body => fixture("downloads.yaml"))
end
it "should return the number of downloads by day for a particular gem version" do
downloads = Gems.downloads 'coulda', '0.6.3'
- a_get("/api/v1/versions/coulda-0.6.3/downloads.json").
+ a_get("/api/v1/versions/coulda-0.6.3/downloads.yaml").
should have_been_made
downloads['2011-06-22'].should == 8
end
@@ -134,14 +136,14 @@
context "with from date specified" do
before do
- stub_get("/api/v1/versions/coulda-0.6.3/downloads/search.json").
+ stub_get("/api/v1/versions/coulda-0.6.3/downloads/search.yaml").
with(:query => {"from" => "2011-01-01", "to" => Date.today.to_s}).
- to_return(:body => fixture("downloads.json"))
+ to_return(:body => fixture("downloads.yaml"))
end
it "should return the number of downloads by day for a particular gem version" do
downloads = Gems.downloads 'coulda', '0.6.3', Date.parse('2011-01-01')
- a_get("/api/v1/versions/coulda-0.6.3/downloads/search.json").
+ a_get("/api/v1/versions/coulda-0.6.3/downloads/search.yaml").
with(:query => {"from" => "2011-01-01", "to" => Date.today.to_s}).
should have_been_made
downloads['2011-06-22'].should == 8
@@ -150,14 +152,14 @@
context "with from and to dates specified" do
before do
- stub_get("/api/v1/versions/coulda-0.6.3/downloads/search.json").
+ stub_get("/api/v1/versions/coulda-0.6.3/downloads/search.yaml").
with(:query => {"from" => "2011-01-01", "to" => "2011-06-28"}).
- to_return(:body => fixture("downloads.json"))
+ to_return(:body => fixture("downloads.yaml"))
end
it "should return the number of downloads by day for a particular gem version" do
downloads = Gems.downloads 'coulda', '0.6.3', Date.parse('2011-01-01'), Date.parse('2011-06-28')
- a_get("/api/v1/versions/coulda-0.6.3/downloads/search.json").
+ a_get("/api/v1/versions/coulda-0.6.3/downloads/search.yaml").
with(:query => {"from" => "2011-01-01", "to" => "2011-06-28"}).
should have_been_made
downloads['2011-06-22'].should == 8
@@ -231,7 +233,7 @@
before do
stub_post("/api/v1/gems/gems/owners").
with(:body => {:email => "sferik@gmail.com"}).
- to_return(:body => fixture("add_owner.json"))
+ to_return(:body => fixture("add_owner"))
end
it "should add an owner to a RubyGem" do
@@ -247,7 +249,7 @@
before do
stub_delete("/api/v1/gems/gems/owners").
with(:query => {:email => "sferik@gmail.com"}).
- to_return(:body => fixture("remove_owner.json"))
+ to_return(:body => fixture("remove_owner"))
end
it "should remove an owner from a RubyGem" do
Please sign in to comment.
Something went wrong with that request. Please try again.