class FactorioMods::Mod::Release

Attributes

downloads_count[RW]
factorio_version[RW]
file_name[RW]
file_size[RW]
game_version[RW]
id[RW]
info_json[RW]
released_at[R]
sha1[RW]
version[RW]

Public Class Methods

new(data = {}) click to toggle source
# File lib/factorio_mods/mod.rb, line 26
def initialize(data = {})
  data.each do |k, v|
    send "#{k}=".to_sym, v if respond_to? "#{k}=".to_sym
  end
end

Public Instance Methods

download() click to toggle source
# File lib/factorio_mods/mod.rb, line 32
def download
  Net::HTTP.get(download_url)
end
download_to(path) click to toggle source
# File lib/factorio_mods/mod.rb, line 36
def download_to(path)
  dir = ''
  if Dir.exist? path
    dir = path
    path = file_name
  end

  File.open(dir + path, 'wb') do |file|
    Net::HTTP.get_response(download_url) do |resp|
      resp.value
      resp.read_body { |data| file.write(data) }
    end
  end

  dir + path
end
download_url() click to toggle source
# File lib/factorio_mods/mod.rb, line 53
def download_url
  @download_url.dup.tap do |url|
    a = FactorioMods::Api::WebAuthentication
    url.query = "username=#{a.username}&token=#{a.token}" if a.token
  end
end
download_url=(url) click to toggle source
# File lib/factorio_mods/mod.rb, line 60
def download_url=(url)
  @download_url = URI(FactorioMods::Api::ModPortal::BASE_URL + url)
end
released_at=(time) click to toggle source
# File lib/factorio_mods/mod.rb, line 64
def released_at=(time)
  @released_at = Time.parse time
end