Class: Factorix::API::MODDownloadAPI

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

Overview

API client for downloading MOD files with service authentication

Requires username and token authentication via ServiceCredential.

Constant Summary collapse

BASE_URL =

Returns:

  • (String)
"https://mods.factorio.com"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize ⇒ MODDownloadAPI

Initialize with thread-safe credential loading

Parameters:

  • args (Hash) —

    dependency injection arguments

  • deps (Object)


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

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

Instance Attribute Details

#logger ⇒ Dry::Logger::Dispatcher (readonly)

Returns the value of attribute logger.



10
11
12
# File 'sig/factorix/api/mod_download_api.rbs', line 10

def logger
  @logger
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)

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

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