Sha256: 04fe3313386d7e2bd31736cee386c192c18c32d5f55a4a17e4a7830f3cdd45b2

Contents?: true

Size: 1.05 KB

Versions: 28

Compression:

Stored size: 1.05 KB

Contents

# frozen_string_literal: true

require 'net/http'
require 'openssl'

module LicenseFinder
  class PyPI
    CONNECTION_ERRORS = [
      EOFError,
      Errno::ECONNREFUSED,
      Errno::ECONNRESET,
      Errno::ECONNRESET,
      Errno::EHOSTUNREACH,
      Errno::EINVAL,
      Net::OpenTimeout,
      Net::ProtocolError,
      Net::ReadTimeout,
      OpenSSL::OpenSSLError,
      OpenSSL::SSL::SSLError,
      SocketError,
      Timeout::Error
    ].freeze

    class << self
      def definition(name, version)
        response = request("https://pypi.org/pypi/#{name}/#{version}/json")
        response.is_a?(Net::HTTPSuccess) ? JSON.parse(response.body).fetch('info', {}) : {}
      rescue *CONNECTION_ERRORS
        {}
      end

      def request(location, limit = 10)
        uri = URI(location)
        http = Net::HTTP.new(uri.host, uri.port)
        http.use_ssl = true
        response = http.get(uri.request_uri).response
        response.is_a?(Net::HTTPRedirection) && limit.positive? ? request(response['location'], limit - 1) : response
      end
    end
  end
end

Version data entries

28 entries across 28 versions & 2 rubygems

Version Path
license_finder-7.0.1 lib/license_finder/package_utils/pypi.rb
license_finder-7.0.0 lib/license_finder/package_utils/pypi.rb
license_finder-6.15.0 lib/license_finder/package_utils/pypi.rb
gitlab-license_finder-6.14.2.1 lib/license_finder/package_utils/pypi.rb
license_finder-6.14.2 lib/license_finder/package_utils/pypi.rb
license_finder-6.14.1 lib/license_finder/package_utils/pypi.rb
license_finder-6.13.0 lib/license_finder/package_utils/pypi.rb
license_finder-6.12.2 lib/license_finder/package_utils/pypi.rb
license_finder-6.12.1 lib/license_finder/package_utils/pypi.rb
license_finder-6.12.0 lib/license_finder/package_utils/pypi.rb
license_finder-6.11.0 lib/license_finder/package_utils/pypi.rb
license_finder-6.10.1 lib/license_finder/package_utils/pypi.rb
license_finder-6.10.0 lib/license_finder/package_utils/pypi.rb
license_finder-6.9.0 lib/license_finder/package_utils/pypi.rb
license_finder-6.8.2 lib/license_finder/package_utils/pypi.rb
license_finder-6.8.1 lib/license_finder/package_utils/pypi.rb
license_finder-6.8.0 lib/license_finder/package_utils/pypi.rb
license_finder-6.7.0 lib/license_finder/package_utils/pypi.rb
license_finder-6.6.2 lib/license_finder/package_utils/pypi.rb
license_finder-6.6.1 lib/license_finder/package_utils/pypi.rb