Class: Factorix::API::GameDownloadAPI
- Inherits:
-
Object
- Object
- Factorix::API::GameDownloadAPI
- Defined in:
- lib/factorix/api/game_download_api.rb
Overview
API client for downloading Factorio game files
Corresponds to: wiki.factorio.com/Download_API
Constant Summary collapse
- BUILDS =
Valid build types
%w[alpha expansion demo headless].freeze
- PLATFORMS =
Valid platforms
%w[win64 win64-manual osx linux64].freeze
- CHANNELS =
Valid release channels
%w[stable experimental].freeze
Instance Method Summary collapse
-
#download(version:, build:, platform:, output:, handler: nil) ⇒ void
Download the game to the specified output path.
-
#initialize ⇒ GameDownloadAPI
constructor
Initialize with thread-safe credential loading.
-
#latest_releases ⇒ Hash{Symbol => Hash}
Fetch latest release information.
-
#latest_version(channel:, build:) ⇒ String?
Get the latest version for a specific channel and build.
-
#resolve_filename(version:, build:, platform:) ⇒ String
Resolve the download filename by making a HEAD request.
Constructor Details
#initialize ⇒ GameDownloadAPI
Initialize with thread-safe credential loading
42 43 44 45 |
# File 'lib/factorix/api/game_download_api.rb', line 42 def initialize(...) super @service_credential_mutex = Mutex.new end |
Instance Method Details
#download(version:, build:, platform:, output:, handler: nil) ⇒ void
This method returns an undefined value.
Download the game to the specified output path
97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/factorix/api/game_download_api.rb', line 97 def download(version:, build:, platform:, output:, handler: nil) validate_build!(build) validate_platform!(platform) uri = build_download_uri(version, build, platform) downloader = Container[:downloader] downloader.subscribe(handler) if handler begin downloader.download(uri, output) ensure downloader.unsubscribe(handler) if handler end end |
#latest_releases ⇒ Hash{Symbol => Hash}
Fetch latest release information
55 56 57 58 59 60 |
# File 'lib/factorix/api/game_download_api.rb', line 55 def latest_releases logger.debug "Fetching latest releases" uri = URI.join(API_BASE_URL, "/api/latest-releases") response = client.get(uri) JSON.parse((+response.body).force_encoding(Encoding::UTF_8), symbolize_names: true) end |
#latest_version(channel:, build:) ⇒ String?
Get the latest version for a specific channel and build
67 68 69 70 |
# File 'lib/factorix/api/game_download_api.rb', line 67 def latest_version(channel:, build:) releases = latest_releases releases.dig(channel.to_sym, build.to_sym) end |
#resolve_filename(version:, build:, platform:) ⇒ String
Resolve the download filename by making a HEAD request
79 80 81 82 83 84 85 86 |
# File 'lib/factorix/api/game_download_api.rb', line 79 def resolve_filename(version:, build:, platform:) validate_build!(build) validate_platform!(platform) uri = build_download_uri(version, build, platform) response = client.head(uri) File.basename(response.uri.path) end |