lib/spandx/gateways/nuget.rb in spandx-0.1.5 vs lib/spandx/gateways/nuget.rb in spandx-0.1.6

- old
+ new

@@ -4,12 +4,13 @@ module Gateways # https://api.nuget.org/v3-flatcontainer/#{name}/#{version}/#{name}.nuspec # https://api.nuget.org/v3-flatcontainer/#{package.name}/index.json # https://docs.microsoft.com/en-us/nuget/api/package-base-address-resource class Nuget - def initialize(http: Spandx.http) + def initialize(http: Spandx.http, catalogue:) @http = http + @catalogue = catalogue end def licenses_for(name, version) document = nuspec_for(name, version) @@ -17,39 +18,33 @@ guess_licenses_from(document) end private - attr_reader :http + attr_reader :http, :catalogue def nuspec_url_for(name, version) "https://api.nuget.org/v3-flatcontainer/#{name}/#{version}/#{name}.nuspec" end def nuspec_for(name, version) from_xml(http.get(nuspec_url_for(name, version)).body) end - def guess_license_in(content) - Licensee::ProjectFiles::LicenseFile.new(content).license.key.upcase - end - def from_xml(xml) Nokogiri::XML(xml).tap(&:remove_namespaces!) end def exact_licenses_from(document) - if (licenses = document.search('//package/metadata/license')).any? - return licenses.map(&:text) - end - - nil + licenses = document.search('//package/metadata/license') + licenses.map(&:text) if licenses.any? end def guess_licenses_from(document) + guess = Guess.new(catalogue) document .search('//package/metadata/licenseUrl') - .map { |node| guess_license_in(Spandx.http.get(node.text).body) } + .map { |node| guess.license_for(http.get(node.text).body) } end end end end