Class: StrikeApi::Torrent
- Inherits:
-
Object
- Object
- StrikeApi::Torrent
- Defined in:
- lib/strike_api/torrent.rb
Instance Attribute Summary collapse
-
#category ⇒ Object
readonly
Returns the value of attribute category.
-
#download_count ⇒ Object
readonly
Returns the value of attribute download_count.
-
#file_count ⇒ Object
readonly
Returns the value of attribute file_count.
-
#file_info ⇒ Object
readonly
Returns the value of attribute file_info.
-
#hash ⇒ Object
readonly
Returns the value of attribute hash.
-
#leeches ⇒ Object
readonly
Returns the value of attribute leeches.
-
#magnet_uri ⇒ Object
readonly
Returns the value of attribute magnet_uri.
-
#seeds ⇒ Object
readonly
Returns the value of attribute seeds.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
-
#sub_category ⇒ Object
readonly
Returns the value of attribute sub_category.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
-
#upload_date ⇒ Object
readonly
Returns the value of attribute upload_date.
-
#uploader_username ⇒ Object
readonly
Returns the value of attribute uploader_username.
Class Method Summary collapse
-
.catagoriesAvailable ⇒ Object
Returns list of categories available.
-
.find(torrentHash) ⇒ Object
Allows for both a single torrentHash via a string and multiple via an array of torrentHash strings.
- .search(*input) ⇒ Object
-
.subCatagoriesAvailable ⇒ Object
Returns list of sub categories available.
- .top(input) ⇒ Object
Instance Method Summary collapse
-
#initialize(attributes) ⇒ Torrent
constructor
Constructor for torrent objects.
Constructor Details
#initialize(attributes) ⇒ Torrent
Constructor for torrent objects
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/strike_api/torrent.rb', line 12 def initialize(attributes) @hash = attributes["torrent_hash"] @title = attributes["torrent_title"] @category = attributes["torrent_category"] @sub_category = attributes["sub_category"] @seeds = attributes["seeds"] @leeches = attributes["leeches"] @file_count = attributes["file_count"] @size = attributes["size"] # @download_count = attributes["download_count"] # Shown in documentation, not implemented in the API. @upload_date = attributes["upload_date"] @uploader_username = attributes["uploader_username"] @magnet_uri = attributes["magnet_uri"] if(attributes.has_key?("file_info")) # file info is only included in hash searches (the find method) file_names = attributes["file_info"]["file_names"].to_a file_lengths = attributes["file_info"]["file_lengths"].to_a @file_info = Array.new file_names.each_with_index do |item, i| @file_info[i] = [file_names[i],file_lengths[i]] end end end |
Instance Attribute Details
#category ⇒ Object (readonly)
Returns the value of attribute category.
9 10 11 |
# File 'lib/strike_api/torrent.rb', line 9 def category @category end |
#download_count ⇒ Object (readonly)
Returns the value of attribute download_count.
9 10 11 |
# File 'lib/strike_api/torrent.rb', line 9 def download_count @download_count end |
#file_count ⇒ Object (readonly)
Returns the value of attribute file_count.
9 10 11 |
# File 'lib/strike_api/torrent.rb', line 9 def file_count @file_count end |
#file_info ⇒ Object (readonly)
Returns the value of attribute file_info.
9 10 11 |
# File 'lib/strike_api/torrent.rb', line 9 def file_info @file_info end |
#hash ⇒ Object (readonly)
Returns the value of attribute hash.
9 10 11 |
# File 'lib/strike_api/torrent.rb', line 9 def hash @hash end |
#leeches ⇒ Object (readonly)
Returns the value of attribute leeches.
9 10 11 |
# File 'lib/strike_api/torrent.rb', line 9 def leeches @leeches end |
#magnet_uri ⇒ Object (readonly)
Returns the value of attribute magnet_uri.
9 10 11 |
# File 'lib/strike_api/torrent.rb', line 9 def magnet_uri @magnet_uri end |
#seeds ⇒ Object (readonly)
Returns the value of attribute seeds.
9 10 11 |
# File 'lib/strike_api/torrent.rb', line 9 def seeds @seeds end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
9 10 11 |
# File 'lib/strike_api/torrent.rb', line 9 def size @size end |
#sub_category ⇒ Object (readonly)
Returns the value of attribute sub_category.
9 10 11 |
# File 'lib/strike_api/torrent.rb', line 9 def sub_category @sub_category end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
9 10 11 |
# File 'lib/strike_api/torrent.rb', line 9 def title @title end |
#upload_date ⇒ Object (readonly)
Returns the value of attribute upload_date.
9 10 11 |
# File 'lib/strike_api/torrent.rb', line 9 def upload_date @upload_date end |
#uploader_username ⇒ Object (readonly)
Returns the value of attribute uploader_username.
9 10 11 |
# File 'lib/strike_api/torrent.rb', line 9 def uploader_username @uploader_username end |
Class Method Details
.catagoriesAvailable ⇒ Object
Returns list of categories available
92 93 94 |
# File 'lib/strike_api/torrent.rb', line 92 def self.catagoriesAvailable return ["Anime","Applications","Books","Games","Movies","Music","Other","TV","XXX"] end |
.find(torrentHash) ⇒ Object
Allows for both a single torrentHash via a string and multiple via an array of torrentHash strings. Regardless of input, the output will be in the form of an array.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/strike_api/torrent.rb', line 37 def self.find(torrentHash) hashListStr = "" torrentHash = Array(torrentHash) if(torrentHash.length > 50) raise "Strike API accepts a maximum of 50 hashes per query" end torrentHash.length.times do |i| hashListStr += torrentHash[i] + "," end response = HTTParty.get("#{API_URL}/info/?hashes=#{hashListStr}") errorChecker(response) torrentsJSON = JSON.parse(response.body) torrentsJSON["torrents"].map { |attributes| new(attributes) } end |
.search(*input) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/strike_api/torrent.rb', line 52 def self.search(*input) searchPhrase = CGI::escape(input[0].strip) case input.length when 1 response = HTTParty.get("#{API_URL}/search/?phrase=#{searchPhrase}") when 2 if(categoryChecker(input[1]) == "category") # second input is a category response = HTTParty.get("#{API_URL}/search/?phrase=#{searchPhrase}&category=#{input[1]}") elsif(categoryChecker(input[1]) == "subCategory") # second input is a sub category response = HTTParty.get("#{API_URL}/search/?phrase=#{searchPhrase}&subcategory=#{input[1]}") else # second input is neither a category or sub category raise "The category/sub category entered is not valid" end when 3 # assumes order is searchPhrase,category,subCategory if(categoryChecker(input[1]) != "category") raise "The category is not valid" elsif(categoryChecker(input[2]) != "subCategory") raise "The sub category is not valid" end response = HTTParty.get("#{API_URL}/search/?phrase=#{searchPhrase}&category=#{input[1]}&subcategory=#{input[2]}") else raise "Invalid number of parameters: input <= 3" end errorChecker(response) torrentsJSON = JSON.parse(response.body) torrentsJSON["torrents"].map { |attributes| new(attributes) } end |
.subCatagoriesAvailable ⇒ Object
Returns list of sub categories available
97 98 99 |
# File 'lib/strike_api/torrent.rb', line 97 def self.subCatagoriesAvailable return ["Highres Movies","Hentai","HD Video","Handheld","Games","Fiction","English-translated","Ebooks","Dubbed Movies","Documentary","Concerts","Comics","Books","Bollywood","Audio books","Asian","Anime Music Video","Animation","Android","Academic","AAC","3D Movies","XBOX360","Windows","Wii","Wallpapers","Video","Unsorted","UNIX","UltraHD","Tutorials","Transcode","Trailer","Textbooks","Subtitles","Soundtrack","Sound clips","Radio Shows","PSP","PS3","PS2","Poetry","Pictures","PC","Other XXX","Other TV","Other Music","Other Movies","Other Games","Other Books","Other Applications","Other Anime","Non-fiction","Newspapers","Music videos","Mp3","Movie clips","Magazines","Mac","Lossless","Linux","Karaoke","iOS"] end |
.top(input) ⇒ Object
80 81 82 83 84 85 86 87 88 89 |
# File 'lib/strike_api/torrent.rb', line 80 def self.top(input) searchPhrase = CGI::escape(input.strip) if((categoryChecker(input) != "category") && input.strip.downcase != "all") # all is also a valid top category raise "The category is not valid" end response = HTTParty.get("#{API_URL}/top/?category=#{input}") errorChecker(response) torrentsJSON = JSON.parse(response.body) torrentsJSON["torrents"].map { |attributes| new(attributes) } end |