Class: Factorix::API::MODDownloadAPI

Inherits:
Object
  • Object
show all
Defined in:
lib/factorix/api/mod_download_api.rb

Overview

API client for downloading MOD files with service authentication

Requires username and token authentication via ServiceCredential.

Instance Method Summary collapse

Constructor Details

#initializeMODDownloadAPI

Initialize with thread-safe credential loading

Parameters:

  • args (Hash)

    dependency injection arguments



25
26
27
28
# File 'lib/factorix/api/mod_download_api.rb', line 25

def initialize(...)
  super
  @service_credential_mutex = Mutex.new
end

Instance Method Details

#download(download_url, output, expected_sha1: nil, handler: nil) ⇒ void

This method returns an undefined value.

Download a MOD file to the specified output path

Parameters:

  • download_url (String)

    relative download URL from API response (e.g., “/download/mod-name/…”)

  • output (Pathname)

    output file path

  • expected_sha1 (String, nil) (defaults to: nil)

    expected SHA1 digest for verification (optional)

  • handler (Object, nil) (defaults to: nil)

    event handler for download progress (optional)

Raises:

  • (ArgumentError)

    if download_url is not a relative path starting with “/”

  • (DigestMismatchError)

    if SHA1 verification fails



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/factorix/api/mod_download_api.rb', line 39

def download(download_url, output, expected_sha1: nil, handler: nil)
  unless download_url.start_with?("/")
    logger.error("Invalid download_url", url: download_url)
    raise ArgumentError, "download_url must be a relative path starting with '/'"
  end

  uri = build_download_uri(download_url)
  downloader = Container[:downloader]
  downloader.subscribe(handler) if handler
  begin
    downloader.download(uri, output, expected_sha1:)
  ensure
    downloader.unsubscribe(handler) if handler
  end
end