Class: Mnenv::Chocolatey::Fetcher

Inherits:
Fetcher
  • Object
show all
Defined in:
lib/mnenv/chocolatey/fetcher.rb

Constant Summary collapse

API_URL =
'https://community.chocolatey.org/api/v2'
PACKAGE_NAME =
'metanorma'

Instance Attribute Summary

Attributes inherited from Fetcher

#repository

Instance Method Summary collapse

Methods inherited from Fetcher

#fetch_and_save, #initialize

Constructor Details

This class inherits a constructor from Mnenv::Fetcher

Instance Method Details

#fetch_allObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/mnenv/chocolatey/fetcher.rb', line 15

def fetch_all
  # Use OData v2 Packages endpoint with filter
  # Note: Use pre-encoded URL to avoid encoding issues
  search_url = "#{API_URL}/Packages()?%24filter=Id%20eq%20'#{PACKAGE_NAME}'"

  versions = []
  loop do
    uri = URI(search_url)
    xml_content = uri.open.read
    doc = Nokogiri::XML(xml_content)

    # Parse Atom feed entries using wildcard namespace
    doc.xpath('//*:entry').each do |entry|
      # Get properties using wildcard
      properties = entry.at_xpath('.//*:properties')
      next unless properties

      version_elem = properties.at_xpath('./*:Version')
      next unless version_elem

      version_string = version_elem.content&.strip
      next if version_string.empty?

      # Get IsPrerelease
      prerelease_elem = properties.at_xpath('./*:IsPrerelease')
      is_prerelease = prerelease_elem&.content == 'true'

      versions << ChocolateyVersion.new(
        version: version_string,
        package_name: PACKAGE_NAME,
        is_pre_release: is_prerelease
      )
    end

    # Check for next page link
    next_link = doc.at_xpath('//*:link[@rel="next"]')
    break unless next_link

    search_url = next_link['href']
    break unless search_url

    # Make relative URLs absolute and upgrade http to https
    search_url = search_url.start_with?('http') ? search_url : "#{API_URL}/#{search_url}"
    search_url = search_url.sub('http://', 'https://')
  end

  versions.sort_by(&:version)
end