Skip to content

Commit 0c709af

Browse files
hsbtclaude
authored andcommitted
Include the platform in the downloads full name
downloads joined the gem name and version number by hand, so a Gems::Version for a non-ruby platform fetched the ruby build counts. full_name_of already builds the name the endpoint looks up. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
1 parent e663184 commit 0c709af

5 files changed

Lines changed: 13 additions & 6 deletions

File tree

‎lib/gems/api/download_endpoints.rb‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ def total_downloads
3131
# @example
3232
# Gems.downloads("rails_admin", "0.0.1").version_downloads
3333
def downloads(gem_name, version = nil)
34-
number = number_of(version) || latest_version(gem_name)
35-
Downloads.new(JSON.parse(get("/api/v1/downloads/#{name_of(gem_name)}-#{number}.json")))
34+
full_name = full_name_of(gem_name, version || latest_version(gem_name))
35+
Downloads.new(JSON.parse(get("/api/v1/downloads/#{full_name}.json")))
3636
end
3737

3838
# Returns the top 50 downloaded gem versions of all time

‎lib/gems/identifiers.rb‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def platform_of(version)
5353
# @param version [String, Version] a version number or version
5454
# @param platform [String, nil] the platform; defaults to the platform of a version object
5555
# @return [String] the full name
56-
def full_name_of(gem, version, platform)
56+
def full_name_of(gem, version, platform = nil)
5757
::Gem::NameTuple.new(name_of(gem), number_of(version), platform || platform_of(version)).full_name
5858
end
5959

‎sig/gems.rbs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ module Gems
300300
def name_of: (gem_identifier? gem) -> String?
301301
def number_of: (version_identifier? version) -> String?
302302
def platform_of: (version_identifier? version) -> String?
303-
def full_name_of: (gem_identifier gem, version_identifier version, String? platform) -> String
303+
def full_name_of: (gem_identifier gem, version_identifier version, ?String? platform) -> String
304304
def handle_of: (user_identifier owner) -> (String | Integer)?
305305
def url_of: (web_hook_identifier web_hook) -> String?
306306
def key_of: (api_key_identifier? api_key) -> String?

‎spec/gems/api/download_endpoints_spec.rb‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@
3737
expect([downloads.class, downloads.total, downloads.version_downloads]).to eq([Gems::Downloads, 3142, 3142])
3838
end
3939

40+
it "includes the platform of a version in the full name" do
41+
stub_get("/api/v1/downloads/nokogiri-1.15.0-java.json").to_return(body: fixture("rails_admin-0.0.0.json"))
42+
client.downloads("nokogiri", Gems::Version.new("number" => "1.15.0", "platform" => "java"))
43+
44+
expect(a_get("/api/v1/downloads/nokogiri-1.15.0-java.json")).to have_been_made
45+
end
46+
4047
it "defaults to the latest version" do
4148
stub_get("/api/v1/versions/rails_admin/latest.json").to_return(body: '{"version":"3.0.9"}')
4249
stub_get("/api/v1/downloads/rails_admin-3.0.9.json").to_return(body: fixture("rails_admin-0.0.0.json"))

‎spec/gems/identifiers_spec.rb‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545

4646
describe "#full_name_of" do
4747
it "joins the name and number" do
48-
expect(client.send(:full_name_of, "rails", "7.0.6", nil)).to eq("rails-7.0.6")
48+
expect(client.send(:full_name_of, "rails", "7.0.6")).to eq("rails-7.0.6")
4949
end
5050

5151
it "appends the platform" do
@@ -59,7 +59,7 @@
5959
it "defaults to the platform of a version" do
6060
version = Gems::Version.new("name" => "nokogiri", "number" => "1.15.0", "platform" => "java")
6161

62-
expect(client.send(:full_name_of, version, version, nil)).to eq("nokogiri-1.15.0-java")
62+
expect(client.send(:full_name_of, version, version)).to eq("nokogiri-1.15.0-java")
6363
end
6464

6565
it "prefers an explicit platform" do

0 commit comments

Comments
 (0)