Class: Gem::Guardian::RubygemsClient
- Inherits:
-
Object
- Object
- Gem::Guardian::RubygemsClient
- Defined in:
- lib/gem/guardian/rubygems_client.rb
Constant Summary collapse
- DEFAULT_HOST =
"https://rubygems.org"
Instance Method Summary collapse
- #download_gem(dependency, destination) ⇒ Object
- #expected_sha256(dependency) ⇒ Object
-
#initialize(host: DEFAULT_HOST, http: Net::HTTP) ⇒ RubygemsClient
constructor
A new instance of RubygemsClient.
Constructor Details
#initialize(host: DEFAULT_HOST, http: Net::HTTP) ⇒ RubygemsClient
Returns a new instance of RubygemsClient.
12 13 14 15 |
# File 'lib/gem/guardian/rubygems_client.rb', line 12 def initialize(host: DEFAULT_HOST, http: Net::HTTP) @host = host.delete_suffix("/") @http = http end |
Instance Method Details
#download_gem(dependency, destination) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/gem/guardian/rubygems_client.rb', line 29 def download_gem(dependency, destination) body = get("/downloads/#{dependency.gem_filename}") File.binwrite(destination, body) destination rescue StandardError => e raise ArtifactFetchError, "Could not fetch #{dependency.gem_filename}: #{e.}" end |
#expected_sha256(dependency) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/gem/guardian/rubygems_client.rb', line 17 def expected_sha256(dependency) versions = JSON.parse(get("/api/v1/versions/#{dependency.name}.json")) version = versions.find do |item| item["number"] == dependency.version && platform_matches?(item["platform"], dependency.platform) end sha = version && (version["sha"] || version["sha256"] || version["checksum"]) raise ChecksumNotFound, "No SHA256 found for #{dependency.name} #{dependency.version} #{dependency.platform}" if blank?(sha) sha.downcase end |