class TorrentSearch::Services::Download
Public Class Methods
new(path, torrent)
click to toggle source
# File lib/torrent_search/services/download.rb, line 6 def initialize(path, torrent) @path = path @torrent = torrent end
Public Instance Methods
filename()
click to toggle source
# File lib/torrent_search/services/download.rb, line 24 def filename File.join(@path, "#{@torrent.filename}.torrent") end
perform(view)
click to toggle source
# File lib/torrent_search/services/download.rb, line 11 def perform(view) if success? save! view.success else view.failure response, @torrent.href end end
success?()
click to toggle source
# File lib/torrent_search/services/download.rb, line 20 def success? response.code == 200 end
Private Instance Methods
response()
click to toggle source
# File lib/torrent_search/services/download.rb, line 35 def response @response ||= HTTParty.get(@torrent.href) end
save!()
click to toggle source
# File lib/torrent_search/services/download.rb, line 29 def save! File.open(filename, "wb") do |file| file.write response.parsed_response end end