lib/spandx/rubygems/gateway.rb in spandx-0.10.1 vs lib/spandx/rubygems/gateway.rb in spandx-0.11.0
- old
+ new
@@ -7,23 +7,22 @@
def initialize(http: Spandx.http)
@http = http
end
def licenses_for(name, version)
- found = index.licenses_for(name: name, version: version)
+ found = cache.licenses_for(name: name, version: version)
found.any? ? found : details_on(name, version)['licenses'] || []
end
private
attr_reader :http
- def index
- @index ||= OfflineIndex.new(:rubygems)
+ def cache
+ @cache ||= ::Spandx::Core::Cache.new(:rubygems, url: 'https://github.com/mokhan/spandx-rubygems.git')
end
def details_on(name, version)
- Spandx.logger.debug("Cache miss: #{name}-#{version}")
url = "https://rubygems.org/api/v2/rubygems/#{name}/versions/#{version}.json"
response = http.get(url, default: {})
http.ok?(response) ? parse(response.body) : {}
end