Sha256: 11ba277afdaaaefb89c729eb34798431243b11d14310b143f67ff28e9e6ecac0

Contents?: true

Size: 1006 Bytes

Versions: 7

Compression:

Stored size: 1006 Bytes

Contents

# frozen_string_literal: true

module Spandx
  module Python
    class Source
      attr_reader :name, :uri, :verify_ssl

      def initialize(source)
        @name = source['name']
        @uri = URI.parse(source['url'])
        @verify_ssl = source['verify_ssl']
      end

      def host
        @uri.host
      end

      def uri_for(name, version)
        "https://#{host}/pypi/#{name}/#{version}/json"
      end

      def lookup(name, version, http: Spandx.http)
        response = http.get(uri_for(name, version))
        if http.ok?(response)
          JSON.parse(response.body)
        else
          {}
        end
      end

      class << self
        def sources_from(json)
          meta = json['_meta']
          meta['sources'].map do |hash|
            new(hash)
          end
        end

        def default
          new(
            'name' => 'pypi',
            'url' => 'https://pypi.org/simple',
            'verify_ssl' => true
          )
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
spandx-0.13.2 lib/spandx/python/source.rb
spandx-0.13.1 lib/spandx/python/source.rb
spandx-0.13.0 lib/spandx/python/source.rb
spandx-0.12.3 lib/spandx/python/source.rb
spandx-0.12.2 lib/spandx/python/source.rb
spandx-0.12.1 lib/spandx/python/source.rb
spandx-0.12.0 lib/spandx/python/source.rb