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.
-
#subcategory ⇒ Object
readonly
Returns the value of attribute subcategory.
-
#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
-
.categories_available ⇒ Object
Returns list of categories available.
-
.find(torrent_hash) ⇒ Object
Allows for both a single torrent_hash via a string and multiple via an array of torrent_hash strings.
- .search(*input) ⇒ Object
-
.subcategories_available ⇒ 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 34 |
# File 'lib/strike_api/torrent.rb', line 12 def initialize(attributes) @hash = attributes['torrent_hash'] @title = attributes['torrent_title'] @category = attributes['torrent_category'] @subcategory = attributes['sub_category'] @seeds = attributes['seeds'] @leeches = attributes['leeches'] @file_count = attributes['file_count'] @size = attributes['size'] # @download_count = attributes['download_count'] # Shown in API documentation, not implemented in the API. @upload_date = attributes['upload_date'] @uploader_username = attributes['uploader_username'] @magnet_uri = attributes['magnet_uri'] # file info is only included in hash searches (the find method) if(attributes.has_key?('file_info')) 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 |
#subcategory ⇒ Object (readonly)
Returns the value of attribute subcategory.
9 10 11 |
# File 'lib/strike_api/torrent.rb', line 9 def subcategory @subcategory 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
.categories_available ⇒ Object
Returns list of categories available
94 95 96 |
# File 'lib/strike_api/torrent.rb', line 94 def self.categories_available return ['Anime','Applications','Books','Games','Movies','Music','Other','TV','XXX'] end |
.find(torrent_hash) ⇒ Object
Allows for both a single torrent_hash via a string and multiple via an array of torrent_hash strings. Regardless of input, the output will be in the form of an array.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/strike_api/torrent.rb', line 38 def self.find(torrent_hash) hash_list_str = '' torrent_hash = Array(torrent_hash) if(torrent_hash.length > 50) raise 'Strike API accepts a maximum of 50 hashes per query' end torrent_hash.length.times do |i| hash_list_str += torrent_hash[i] + ',' end url = "#{API_URL}/info/?hashes=#{hash_list_str}" response = HTTParty.get(URI.escape(url)) error_checker(response) torrents_json = JSON.parse(response.body) torrents_json['torrents'].map { |attributes| new(attributes) } end |
.search(*input) ⇒ Object
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 79 80 |
# File 'lib/strike_api/torrent.rb', line 54 def self.search(*input) case input.length when 1 url = "#{API_URL}/search/?phrase=#{input[0]}" when 2 if(category_checker(input[1]) == 'category') # second input is a category url = "#{API_URL}/search/?phrase=#{input[0]}&category=#{input[1]}" elsif(category_checker(input[1]) == 'subcategory') # second input is a sub category url = "#{API_URL}/search/?phrase=#{input[0]}&subcategory=#{input[1]}" else # second input is neither a category or sub category raise 'The category/subcategory entered is not valid' end when 3 # assumes order is input[0],category,subcategory if(category_checker(input[1]) != 'category') raise 'The category is not valid' elsif(category_checker(input[2]) != 'subcategory') raise 'The subcategory is not valid' end url = "#{API_URL}/search/?phrase=#{input[0]}&category=#{input[1]}&subcategory=#{input[2]}" else raise 'Invalid number of parameters: input <= 3' end response = HTTParty.get(URI.escape(url)) error_checker(response) torrents_json = JSON.parse(response.body) torrents_json['torrents'].map { |attributes| new(attributes) } end |
.subcategories_available ⇒ Object
Returns list of sub categories available
99 100 101 |
# File 'lib/strike_api/torrent.rb', line 99 def self.subcategories_available 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
82 83 84 85 86 87 88 89 90 91 |
# File 'lib/strike_api/torrent.rb', line 82 def self.top(input) if((category_checker(input) != 'category') && input.strip.downcase != 'all') # all is also a valid top category raise 'The category is not valid' end url = "#{API_URL}/top/?category=#{input}" response = HTTParty.get(URI.escape(url)) error_checker(response) torrents_json = JSON.parse(response.body) torrents_json['torrents'].map { |attributes| new(attributes) } end |