Class: Purl::EcosystemsURL
- Inherits:
-
Object
- Object
- Purl::EcosystemsURL
- Defined in:
- lib/purl/ecosystems_url.rb
Constant Summary collapse
- API_BASE =
"https://packages.ecosyste.ms/api/v1"- NAMESPACED_PACKAGE_TYPES =
%w[npm composer maven golang swift elm clojars].freeze
Class Method Summary collapse
- .api_url(purl) ⇒ Object
- .package_api_url(purl) ⇒ Object
- .registry_name(purl) ⇒ Object
- .version_api_url(purl) ⇒ Object
Instance Method Summary collapse
- #api_url ⇒ Object
-
#initialize(purl) ⇒ EcosystemsURL
constructor
A new instance of EcosystemsURL.
- #package_api_url ⇒ Object
- #registry_name ⇒ Object
- #version_api_url ⇒ Object
Constructor Details
#initialize(purl) ⇒ EcosystemsURL
Returns a new instance of EcosystemsURL.
24 25 26 |
# File 'lib/purl/ecosystems_url.rb', line 24 def initialize(purl) @purl = purl.is_a?(PackageURL) ? purl : PackageURL.parse(purl.to_s) end |
Class Method Details
.api_url(purl) ⇒ Object
12 13 14 |
# File 'lib/purl/ecosystems_url.rb', line 12 def self.api_url(purl) new(purl).api_url end |
.package_api_url(purl) ⇒ Object
16 17 18 |
# File 'lib/purl/ecosystems_url.rb', line 16 def self.package_api_url(purl) new(purl).package_api_url end |
.registry_name(purl) ⇒ Object
8 9 10 |
# File 'lib/purl/ecosystems_url.rb', line 8 def self.registry_name(purl) new(purl).registry_name end |
.version_api_url(purl) ⇒ Object
20 21 22 |
# File 'lib/purl/ecosystems_url.rb', line 20 def self.version_api_url(purl) new(purl).version_api_url end |
Instance Method Details
#api_url ⇒ Object
42 43 44 |
# File 'lib/purl/ecosystems_url.rb', line 42 def api_url @purl.version ? version_api_url : package_api_url end |
#package_api_url ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/purl/ecosystems_url.rb', line 46 def package_api_url registry = registry_name return nil unless registry name = package_name_for_api "#{API_BASE}/registries/#{registry}/packages/#{encode_path_segment(name)}" end |
#registry_name ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/purl/ecosystems_url.rb', line 28 def registry_name # Check for explicit ecosystems_registry in config first type_config = Purl.type_config(@purl.type) return type_config["ecosystems_registry"] if type_config&.dig("ecosystems_registry") # Fall back to extracting host from registry_url return nil unless @purl.supports_registry_url? host = URI.parse(@purl.registry_url).host host.sub(/^www\./, "") rescue URI::InvalidURIError, RegistryError nil end |
#version_api_url ⇒ Object
54 55 56 57 58 59 60 61 |
# File 'lib/purl/ecosystems_url.rb', line 54 def version_api_url registry = registry_name return nil unless registry return nil unless @purl.version name = package_name_for_api "#{API_BASE}/registries/#{registry}/packages/#{encode_path_segment(name)}/versions/#{encode_path_segment(@purl.version)}" end |