Class: Torrage
- Inherits:
-
Object
- Object
- Torrage
- Defined in:
- lib/torrage.rb
Constant Summary collapse
- BOUNDARY =
"349832898984244898448024464570528145"
Class Method Summary collapse
-
.cache_torrent(file) ⇒ Object
This method takes the full path to a torrent file, posts it to Torrage, and returns the info hash on success.
- .file_to_multipart(filename, content) ⇒ Object
Class Method Details
.cache_torrent(file) ⇒ Object
This method takes the full path to a torrent file, posts it to Torrage, and returns the info hash on success.
Remember to use File.expand_path if neccessary before calling this method
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/torrage.rb', line 12 def self.cache_torrent(file) params = [ Torrage.file_to_multipart(file.split("/")[-1], File.read(file)) ] query = params.collect { |p| "--" + BOUNDARY + "\r\n" + p } query = query.join("") + "--" + BOUNDARY + "--\r\n" uri = URI.parse("http://torrage.com/autoupload.php") http = Net::HTTP.start(uri.host, uri.port) res = http.request_post(uri.path, query, {"Content-Type" => "multipart/form-data; boundary="+ BOUNDARY}) err = res["X-Torrage-Error-Msg"] hash = res["X-Torrage-Infohash"] raise TorrageException, err if err hash end |
.file_to_multipart(filename, content) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/torrage.rb', line 30 def self.file_to_multipart(filename, content) return "Content-Disposition: form-data; name=\"torrent\"; filename=\"#{filename}\"\r\n" + "Content-Transfer-Encoding: binary\r\n" + "Content-Type: application/x-bittorrent\r\n" + "\r\n" + "#{content}\r\n" end |