Sha256: 1f634fe5f5f843e9e8cff578a95be90d37aa368d280eae551bd478166d8bdd1d

Contents?: true

Size: 791 Bytes

Versions: 9

Compression:

Stored size: 791 Bytes

Contents

# frozen_string_literal: true

module Spandx
  module Ruby
    class Gateway < ::Spandx::Core::Gateway
      # https://guides.rubygems.org/rubygems-org-api-v2/
      def initialize(http: Spandx.http)
        @http = http
      end

      def licenses_for(dependency)
        details_on(dependency.name, dependency.version)['licenses'] || []
      end

      def matches?(dependency)
        dependency.package_manager == :rubygems
      end

      private

      attr_reader :http

      def details_on(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

      def parse(json)
        JSON.parse(json)
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
spandx-0.13.4 lib/spandx/ruby/gateway.rb
spandx-0.13.3 lib/spandx/ruby/gateway.rb
spandx-0.13.2 lib/spandx/ruby/gateway.rb
spandx-0.13.1 lib/spandx/ruby/gateway.rb
spandx-0.13.0 lib/spandx/ruby/gateway.rb
spandx-0.12.3 lib/spandx/ruby/gateway.rb
spandx-0.12.2 lib/spandx/ruby/gateway.rb
spandx-0.12.1 lib/spandx/ruby/gateway.rb
spandx-0.12.0 lib/spandx/ruby/gateway.rb