class Greenmonster::FileDownloader
Attributes
file_name[R]
game_path[R]
Public Class Methods
new(file_name:, game_path:)
click to toggle source
# File lib/greenmonster/file_downloader.rb, line 5 def initialize(file_name:, game_path:) @file_name = file_name @game_path = game_path end
Public Instance Methods
pull()
click to toggle source
# File lib/greenmonster/file_downloader.rb, line 10 def pull return false if fetch.code != "200" write_file end
Private Instance Methods
encoded_response()
click to toggle source
# File lib/greenmonster/file_downloader.rb, line 34 def encoded_response fetch.body.force_encoding("utf-8") end
fetch()
click to toggle source
# File lib/greenmonster/file_downloader.rb, line 22 def fetch @fetch ||= HTTParty.get(remote_path).response end
local_path()
click to toggle source
# File lib/greenmonster/file_downloader.rb, line 26 def local_path "#{Greenmonster.local_data_location}/games/#{game_path}/#{file_name}" end
remote_path()
click to toggle source
# File lib/greenmonster/file_downloader.rb, line 30 def remote_path "#{Greenmonster::REMOTE_DATA_ROOT}/#{game_path}/#{file_name}" end
write_file()
click to toggle source
# File lib/greenmonster/file_downloader.rb, line 38 def write_file File.open(local_path, "w") do |file| file.write(encoded_response) end end