Module: T411::Torrents

Extended by:
Torrents
Included in:
T411, Torrents
Defined in:
lib/t411/torrents.rb

Class Method Summary collapse

Class Method Details

.details(id) ⇒ Object



20
21
22
# File 'lib/t411/torrents.rb', line 20

def self.details(id)
  T411::Api.request_data(URI.parse($t411_base_url + "/torrents/details/#{id}"))
end

.download(id, path = Dir.pwd) ⇒ Object



24
25
26
27
28
# File 'lib/t411/torrents.rb', line 24

def self.download(id,path = Dir.pwd)
  File.open("#{path}/#{id}.torrent", 'ab+') do |line|
    line.puts T411::Api.request_data(URI.parse($t411_base_url + "/torrents/download/#{id}"))
  end
end

.search(query, options = {}) ⇒ Object



13
14
15
16
17
18
# File 'lib/t411/torrents.rb', line 13

def self.search(query, options={})
  options = {limit: 100, cid: nil}.merge(options)
  path = "/torrents/search/#{query.gsub(' ','+')}?&limit=#{options[:limit]}&cid=#{options[:cid]}" if options[:cid] != nil && options[:cid].is_a?(Integer) || path = "/torrents/search/#{query.gsub(' ','+')}?&limit=#{options[:limit]}"
  req = Net::HTTP::Get.new(path); req['Authorization'] = T411::Api.shared_token
  Net::HTTP.new($t411_base_url.gsub('http://','')).request(req).body
end