strike_api 1.0.5 → 1.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2f52d0ba495cca0b1700a7c530780d736087dd7a
4
- data.tar.gz: 4436491a814f90e98d43247a2d1a4b89c69a517d
3
+ metadata.gz: 1031c8008c91709432a93f169653e93f09c73c00
4
+ data.tar.gz: 0da2024794b5751dde0d152abf7e3556cc7f7eb4
5
5
  SHA512:
6
- metadata.gz: c0d48f748a531b55e35f69cbf764487eaba97361ecb1f21175e881752395bf6802340cb167e372527d36396194c152558200ddd9f6265191fe4518fa733c3bb9
7
- data.tar.gz: db2f904919f5a2435f2d8471d04ae12dddc435eda5c6c3e23d98dc61bce81fee3b0d6309398545a7aa53eb27580ef9a3a60f8e5fe7f54fd4fd36b16fc8aef265
6
+ metadata.gz: 75b479f836b0a0adc14d486161d0152cf6072a32ce7797dbdb37256feed7dc95224b1b40872971edfbdce381f0dc7a14514960bb59b24a7e39687a05d97ccd37
7
+ data.tar.gz: 29eafb2d367c71687548f5368cfdc61c85339901ab5cbbc70a40db0019df98d0ed5c63eb0235d73d221ff8fb960755e11712ba9c6667b0962c6930d0e67091d4
data/.editorconfig CHANGED
@@ -2,7 +2,8 @@
2
2
  root = true
3
3
 
4
4
  [*]
5
- indent_style = tab
5
+ indent_style = space
6
+ indent_size = 2
6
7
  end_of_line = lf
7
8
  charset = utf-8
8
9
  trim_trailing_whitespace = true
data/README.md CHANGED
@@ -27,7 +27,7 @@ Or install it yourself as:
27
27
  ```ruby
28
28
  # Param 1: torrent hash string or array of torrent hash strings
29
29
  # Returns: array of torrent objects (objects include file_info data)
30
- torrentInfoArray = StrikeApi::Torrent.find(yourTorrentHash)
30
+ torrent_info_Array = StrikeAPI::Torrent.find(yourTorrentHash)
31
31
  ```
32
32
 
33
33
  ### Search
@@ -35,18 +35,18 @@ torrentInfoArray = StrikeApi::Torrent.find(yourTorrentHash)
35
35
  ```ruby
36
36
  # Param 1: search phrase, example: "ubuntu iso"
37
37
  # Returns: array of torrent objects
38
- searchResults = StrikeApi::Torrent.search(yourSearchPhrase)
38
+ search_results = StrikeAPI::Torrent.search(search_phrase)
39
39
 
40
40
  # Param 1: search phrase, example: "ubuntu iso"
41
- # Param 2: category or sub category, examples: "Music", "Documentary"
41
+ # Param 2: category or subcategory, examples: "Music", "Documentary"
42
42
  # Returns: array of torrent objects
43
- searchResults = StrikeApi::Torrent.search(yourSearchPhrase, yourCatagoryOrSubCategory)
43
+ search_results = StrikeAPI::Torrent.search(search_phrase, category_or_subcategory)
44
44
 
45
45
  # Param 1: search phrase, example: "ubuntu iso"
46
46
  # Param 2: category, example: "Applications"
47
- # Param 3: sub category, example: "Windows"
47
+ # Param 3: subcategory, example: "Windows"
48
48
  # Returns: array of torrent objects
49
- searchResults = StrikeApi::Torrent.search(yourSearchPhrase, yourCatagory, yourSubCategory)
49
+ search_results = StrikeAPI::Torrent.search(search_phrase, category, subcategory)
50
50
  ```
51
51
 
52
52
  ### Top torrents
@@ -54,17 +54,17 @@ searchResults = StrikeApi::Torrent.search(yourSearchPhrase, yourCatagory, yourSu
54
54
  ```ruby
55
55
  # Param 1: category, examples: "Books", "all"
56
56
  # Returns: top 100 torrents
57
- topResults = StrikeApi::Torrent.top(yourCatagory)
57
+ top_results = StrikeAPI::Torrent.top(category)
58
58
  ```
59
59
 
60
60
  ### Categories and sub categories
61
61
 
62
62
  ```ruby
63
63
  # Returns: array of valid categories
64
- categoryArray = StrikeApi::Torrent.catagoriesAvailable()
64
+ category_array = StrikeAPI::Torrent.categories_available()
65
65
 
66
- # Returns: array of valid sub categories
67
- subCategoryArray = StrikeApi::Torrent.subCatagoriesAvailable()
66
+ # Returns: array of valid subcategories
67
+ subcategory_array = StrikeAPI::Torrent.subcategories_available()
68
68
  ```
69
69
 
70
70
  See tests for more usage examples.
@@ -74,6 +74,12 @@ See tests for more usage examples.
74
74
  1. Better commenting
75
75
  2. ~~Provide usage examples in readme~~
76
76
 
77
+ ## Testing
78
+
79
+ ```
80
+ rake test
81
+ ```
82
+
77
83
  ## Contributing
78
84
 
79
85
  1. Fork it ( https://github.com/marshallford/strike_api/fork )
data/Rakefile CHANGED
@@ -1,2 +1,8 @@
1
- require "bundler/gem_tasks"
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
2
3
 
4
+ Rake::TestTask.new do |t|
5
+ t.pattern = 'test/**/*_test.rb'
6
+ end
7
+
8
+ task :default => [:test]
@@ -2,133 +2,137 @@ require 'httparty'
2
2
  require 'json'
3
3
  require 'cgi'
4
4
 
5
- API_URL = "https://getstrike.net/api/v2/torrents"
5
+ API_URL = 'https://getstrike.net/api/v2/torrents'
6
6
 
7
- module StrikeApi
8
- class Torrent
9
- attr_reader :hash, :title, :category, :sub_category, :seeds, :leeches, :file_count, :size, :download_count, :upload_date, :uploader_username, :magnet_uri, :file_info
7
+ module StrikeAPI
8
+ class Torrent
9
+ attr_reader :hash, :title, :category, :subcategory, :seeds, :leeches, :file_count, :size, :download_count, :upload_date, :uploader_username, :magnet_uri, :file_info
10
10
 
11
- # Constructor for torrent objects
12
- def initialize(attributes)
13
- @hash = attributes["torrent_hash"]
14
- @title = attributes["torrent_title"]
15
- @category = attributes["torrent_category"]
16
- @sub_category = attributes["sub_category"]
17
- @seeds = attributes["seeds"]
18
- @leeches = attributes["leeches"]
19
- @file_count = attributes["file_count"]
20
- @size = attributes["size"]
21
- # @download_count = attributes["download_count"] # Shown in documentation, not implemented in the API.
22
- @upload_date = attributes["upload_date"]
23
- @uploader_username = attributes["uploader_username"]
24
- @magnet_uri = attributes["magnet_uri"]
25
- if(attributes.has_key?("file_info")) # file info is only included in hash searches (the find method)
26
- file_names = attributes["file_info"]["file_names"].to_a
27
- file_lengths = attributes["file_info"]["file_lengths"].to_a
28
- @file_info = Array.new
29
- file_names.each_with_index do |item, i|
30
- @file_info[i] = [file_names[i],file_lengths[i]]
31
- end
32
- end
33
- end
11
+ # Constructor for torrent objects
12
+ def initialize(attributes)
13
+ @hash = attributes['torrent_hash']
14
+ @title = attributes['torrent_title']
15
+ @category = attributes['torrent_category']
16
+ @subcategory = attributes['sub_category']
17
+ @seeds = attributes['seeds']
18
+ @leeches = attributes['leeches']
19
+ @file_count = attributes['file_count']
20
+ @size = attributes['size']
21
+ # @download_count = attributes['download_count'] # Shown in API documentation, not implemented in the API.
22
+ @upload_date = attributes['upload_date']
23
+ @uploader_username = attributes['uploader_username']
24
+ @magnet_uri = attributes['magnet_uri']
25
+ # file info is only included in hash searches (the find method)
26
+ if(attributes.has_key?('file_info'))
27
+ file_names = attributes['file_info']['file_names'].to_a
28
+ file_lengths = attributes['file_info']['file_lengths'].to_a
29
+ @file_info = Array.new
30
+ file_names.each_with_index do |item, i|
31
+ @file_info[i] = [file_names[i],file_lengths[i]]
32
+ end
33
+ end
34
+ end
34
35
 
35
- # Allows for both a single torrentHash via a string and multiple via an array of torrentHash strings.
36
- # Regardless of input, the output will be in the form of an array.
37
- def self.find(torrentHash)
38
- hashListStr = ""
39
- torrentHash = Array(torrentHash)
40
- if(torrentHash.length > 50)
41
- raise "Strike API accepts a maximum of 50 hashes per query"
42
- end
43
- torrentHash.length.times do |i|
44
- hashListStr += torrentHash[i] + ","
45
- end
46
- response = HTTParty.get("#{API_URL}/info/?hashes=#{hashListStr}")
47
- errorChecker(response)
48
- torrentsJSON = JSON.parse(response.body)
49
- torrentsJSON["torrents"].map { |attributes| new(attributes) }
50
- end
36
+ # Allows for both a single torrent_hash via a string and multiple via an array of torrent_hash strings.
37
+ # Regardless of input, the output will be in the form of an array.
38
+ def self.find(torrent_hash)
39
+ hash_list_str = ''
40
+ torrent_hash = Array(torrent_hash)
41
+ if(torrent_hash.length > 50)
42
+ raise 'Strike API accepts a maximum of 50 hashes per query'
43
+ end
44
+ torrent_hash.length.times do |i|
45
+ hash_list_str += torrent_hash[i] + ','
46
+ end
47
+ response = HTTParty.get("#{API_URL}/info/?hashes=#{hash_list_str}")
48
+ error_checker(response)
49
+ torrents_json = JSON.parse(response.body)
50
+ torrents_json['torrents'].map { |attributes| new(attributes) }
51
+ end
51
52
 
52
- def self.search(*input)
53
- searchPhrase = CGI::escape(input[0].strip)
54
- case input.length
55
- when 1
56
- response = HTTParty.get("#{API_URL}/search/?phrase=#{searchPhrase}")
57
- when 2
58
- if(categoryChecker(input[1]) == "category") # second input is a category
59
- response = HTTParty.get("#{API_URL}/search/?phrase=#{searchPhrase}&category=#{input[1]}")
60
- elsif(categoryChecker(input[1]) == "subCategory") # second input is a sub category
61
- response = HTTParty.get("#{API_URL}/search/?phrase=#{searchPhrase}&subcategory=#{input[1]}")
62
- else # second input is neither a category or sub category
63
- raise "The category/sub category entered is not valid"
64
- end
65
- when 3 # assumes order is searchPhrase,category,subCategory
66
- if(categoryChecker(input[1]) != "category")
67
- raise "The category is not valid"
68
- elsif(categoryChecker(input[2]) != "subCategory")
69
- raise "The sub category is not valid"
70
- end
71
- response = HTTParty.get("#{API_URL}/search/?phrase=#{searchPhrase}&category=#{input[1]}&subcategory=#{input[2]}")
72
- else
73
- raise "Invalid number of parameters: input <= 3"
74
- end
75
- errorChecker(response)
76
- torrentsJSON = JSON.parse(response.body)
77
- torrentsJSON["torrents"].map { |attributes| new(attributes) }
78
- end
53
+ def self.search(*input)
54
+ search_phrase = CGI::escape(input[0].strip)
55
+ case input.length
56
+ when 1
57
+ response = HTTParty.get("#{API_URL}/search/?phrase=#{search_phrase}")
58
+ when 2
59
+ if(category_checker(input[1]) == 'category') # second input is a category
60
+ response = HTTParty.get("#{API_URL}/search/?phrase=#{search_phrase}&category=#{input[1]}")
61
+ elsif(category_checker(input[1]) == 'subcategory') # second input is a sub category
62
+ response = HTTParty.get("#{API_URL}/search/?phrase=#{search_phrase}&subcategory=#{input[1]}")
63
+ else # second input is neither a category or sub category
64
+ raise 'The category/subcategory entered is not valid'
65
+ end
66
+ when 3 # assumes order is search_phrase,category,subcategory
67
+ if(category_checker(input[1]) != 'category')
68
+ raise 'The category is not valid'
69
+ elsif(category_checker(input[2]) != 'subcategory')
70
+ raise 'The subcategory is not valid'
71
+ end
72
+ response = HTTParty.get("#{API_URL}/search/?phrase=#{search_phrase}&category=#{input[1]}&subcategory=#{input[2]}")
73
+ else
74
+ raise 'Invalid number of parameters: input <= 3'
75
+ end
76
+ error_checker(response)
77
+ torrents_json = JSON.parse(response.body)
78
+ torrents_json['torrents'].map { |attributes| new(attributes) }
79
+ end
79
80
 
80
- def self.top(input)
81
- searchPhrase = CGI::escape(input.strip)
82
- if((categoryChecker(input) != "category") && input.strip.downcase != "all") # all is also a valid top category
83
- raise "The category is not valid"
84
- end
85
- response = HTTParty.get("#{API_URL}/top/?category=#{input}")
86
- errorChecker(response)
87
- torrentsJSON = JSON.parse(response.body)
88
- torrentsJSON["torrents"].map { |attributes| new(attributes) }
89
- end
81
+ def self.top(input)
82
+ search_phrase = CGI::escape(input.strip)
83
+ if((category_checker(input) != 'category') && input.strip.downcase != 'all') # all is also a valid top category
84
+ raise 'The category is not valid'
85
+ end
86
+ response = HTTParty.get("#{API_URL}/top/?category=#{input}")
87
+ error_checker(response)
88
+ torrents_json = JSON.parse(response.body)
89
+ torrents_json['torrents'].map { |attributes| new(attributes) }
90
+ end
90
91
 
91
- # Returns list of categories available
92
- def self.catagoriesAvailable
93
- return ["Anime","Applications","Books","Games","Movies","Music","Other","TV","XXX"]
94
- end
92
+ # Returns list of categories available
93
+ def self.categories_available
94
+ return ['Anime','Applications','Books','Games','Movies','Music','Other','TV','XXX']
95
+ end
95
96
 
96
- # Returns list of sub categories available
97
- def self.subCatagoriesAvailable
98
- 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"]
99
- end
97
+ # Returns list of sub categories available
98
+ def self.subcategories_available
99
+ 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']
100
+ end
100
101
 
101
- def self.categoryChecker(str)
102
- downcasedCategories = catagoriesAvailable().map(&:downcase)
103
- downcasedSubCategories = subCatagoriesAvailable().map(&:downcase)
104
- if(downcasedCategories.include? str.strip.downcase)
105
- return "category"
106
- elsif(downcasedSubCategories.include? str.strip.downcase)
107
- return "subCategory"
108
- else
109
- return -1
110
- end
111
- end
112
- # Checks for 4XX errors and onward. Examples: 404, 502, 522
113
- def self.errorChecker(response)
114
- code = response.code
115
- message = response.message
116
- if (valid_json?(response.body) && JSON.parse(response.body)["message"])
117
- message = JSON.parse(response.body)["message"]
118
- end
119
- if(code >= 400)
120
- raise "Strike API error: #{code} - #{message}"
121
- end
122
- end
123
- # Checks for valid json
124
- def self.valid_json?(json)
125
- begin
126
- JSON.parse(json)
127
- return true
128
- rescue Exception => e
129
- return false
130
- end
131
- end
132
- private_class_method :errorChecker, :categoryChecker, :valid_json?
133
- end
102
+ def self.category_checker(str)
103
+ downcased_categories = categories_available().map(&:downcase)
104
+ downcased_subcategories = subcategories_available().map(&:downcase)
105
+ if(downcased_categories.include? str.strip.downcase)
106
+ return 'category'
107
+ elsif(downcased_subcategories.include? str.strip.downcase)
108
+ return 'subcategory'
109
+ else
110
+ return -1
111
+ end
112
+ end
113
+
114
+ # Checks for 4XX errors and onward. Examples: 404, 502, 522
115
+ def self.error_checker(response)
116
+ code = response.code
117
+ message = response.message
118
+ if (valid_json?(response.body) && JSON.parse(response.body)['message'])
119
+ message = JSON.parse(response.body)['message']
120
+ end
121
+ if(code >= 400)
122
+ raise "Strike API error: #{code} - #{message}"
123
+ end
124
+ end
125
+
126
+ # Checks for valid json
127
+ def self.valid_json?(json)
128
+ begin
129
+ JSON.parse(json)
130
+ return true
131
+ rescue Exception => e
132
+ return false
133
+ end
134
+ end
135
+
136
+ private_class_method :error_checker, :category_checker, :valid_json?
137
+ end
134
138
  end
@@ -1,3 +1,3 @@
1
- module StrikeApi
2
- VERSION = "1.0.5"
1
+ module StrikeAPI
2
+ VERSION = '1.0.6'
3
3
  end
data/lib/strike_api.rb CHANGED
@@ -1,2 +1,2 @@
1
- require_relative "strike_api/version"
2
- require_relative "strike_api/torrent"
1
+ require_relative 'strike_api/version'
2
+ require_relative 'strike_api/torrent'
data/strike_api.gemspec CHANGED
@@ -4,25 +4,25 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'strike_api/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
- spec.name = "strike_api"
8
- spec.version = StrikeApi::VERSION
9
- spec.authors = ["Marshall Ford","Brett Chastain"]
10
- spec.email = ["inbox@marshallford.me"]
7
+ spec.name = 'strike_api'
8
+ spec.version = StrikeAPI::VERSION
9
+ spec.authors = ['Marshall Ford','Brett Chastain']
10
+ spec.email = ['inbox@marshallford.me']
11
11
  spec.summary = %q{Wrapper for the Strike API.}
12
- spec.description = %q{API wrapper for the Strike Search website (https://getstrike.net/torrents/)}
13
- spec.homepage = "https://github.com/marshallford/strike_api"
14
- spec.license = "MIT"
12
+ spec.description = %q{Wrapper for the Strike Search website/API (https://getstrike.net/torrents/)}
13
+ spec.homepage = 'https://github.com/marshallford/strike_api'
14
+ spec.license = 'MIT'
15
15
 
16
16
  spec.files = `git ls-files -z`.split("\x0")
17
17
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
- spec.require_paths = ["lib"]
19
+ spec.require_paths = ['lib']
20
20
 
21
- spec.add_development_dependency "bundler"
22
- spec.add_development_dependency "rake"
23
- spec.add_development_dependency "minitest"
24
- spec.add_development_dependency "vcr"
25
- spec.add_development_dependency "webmock"
26
- spec.add_dependency "httparty"
27
- spec.add_dependency "json"
21
+ spec.add_development_dependency 'bundler'
22
+ spec.add_development_dependency 'rake'
23
+ spec.add_development_dependency 'minitest'
24
+ spec.add_development_dependency 'vcr'
25
+ spec.add_development_dependency 'webmock'
26
+ spec.add_dependency 'httparty'
27
+ spec.add_dependency 'json'
28
28
  end
data/test/test_helper.rb CHANGED
@@ -4,6 +4,6 @@ require 'webmock/minitest'
4
4
  require 'vcr'
5
5
 
6
6
  VCR.configure do |c|
7
- c.cassette_library_dir = "test/fixtures"
8
- c.hook_into :webmock
7
+ c.cassette_library_dir = 'test/fixtures'
8
+ c.hook_into :webmock
9
9
  end
@@ -1,275 +1,274 @@
1
1
  require './test/test_helper'
2
2
 
3
3
  class StrikeTorrentTest < Minitest::Test
4
+ def test_exists
5
+ assert StrikeAPI::Torrent
6
+ end
4
7
 
5
- def test_exists
6
- assert StrikeApi::Torrent
7
- end
8
+ def test_find_single_torrent
9
+ VCR.use_cassette('test_find_single_torrent') do
10
+ result = StrikeAPI::Torrent.find('156B69B8643BD11849A5D8F2122E13FBB61BD041')[0]
11
+ assert_equal StrikeAPI::Torrent, result.class
12
+ assert_equal '156B69B8643BD11849A5D8F2122E13FBB61BD041', result.hash
13
+ assert_equal 'Slackware 14.1 x86_64 DVD ISO', result.title
14
+ assert_equal 'Applications', result.category
15
+ assert_equal '', result.subcategory
16
+ assert_equal 192, result.seeds
17
+ assert_equal 9, result.leeches
18
+ assert_equal 4, result.file_count
19
+ assert_equal 2437393940, result.size
20
+ # assert_equal 40, result.download_count
21
+ assert_equal 'Feb 24, 2014', result.upload_date
22
+ assert_equal 'Nusantara', result.uploader_username
23
+ assert_equal 'magnet:?xt=urn:btih:156B69B8643BD11849A5D8F2122E13FBB61BD041&dn=Slackware+14.1+x86_64+DVD+ISO&tr=udp://open.demonii.com:1337&tr=udp://tracker.coppersurfer.tk:6969&tr=udp://tracker.leechers-paradise.org:6969&tr=udp://exodus.desync.com:6969', result.magnet_uri
24
+ assert_equal 'slackware64-14.1-iso\\slackware64-14.1-install-dvd.iso', result.file_info[0][0] # first file, filename
25
+ assert_equal 2438987776, result.file_info[0][1] # first file, file length
26
+ end
27
+ end
8
28
 
9
- def test_find_single_torrent
10
- VCR.use_cassette('test_find_single_torrent') do
11
- result = StrikeApi::Torrent.find("156B69B8643BD11849A5D8F2122E13FBB61BD041")[0]
12
- assert_equal StrikeApi::Torrent, result.class
13
- assert_equal "156B69B8643BD11849A5D8F2122E13FBB61BD041", result.hash
14
- assert_equal "Slackware 14.1 x86_64 DVD ISO", result.title
15
- assert_equal "Applications", result.category
16
- assert_equal "", result.sub_category
17
- assert_equal 192, result.seeds
18
- assert_equal 9, result.leeches
19
- assert_equal 4, result.file_count
20
- assert_equal 2437393940, result.size
21
- # assert_equal 40, result.download_count
22
- assert_equal "Feb 24, 2014", result.upload_date
23
- assert_equal "Nusantara", result.uploader_username
24
- assert_equal "magnet:?xt=urn:btih:156B69B8643BD11849A5D8F2122E13FBB61BD041&dn=Slackware+14.1+x86_64+DVD+ISO&tr=udp:\/\/open.demonii.com:1337&tr=udp:\/\/tracker.coppersurfer.tk:6969&tr=udp:\/\/tracker.leechers-paradise.org:6969&tr=udp:\/\/exodus.desync.com:6969", result.magnet_uri
25
- assert_equal "slackware64-14.1-iso\\slackware64-14.1-install-dvd.iso", result.file_info[0][0] # first file, filename
26
- assert_equal 2438987776, result.file_info[0][1] # first file, file length
27
- end
28
- end
29
+ def test_find_array
30
+ VCR.use_cassette('test_find_array') do
31
+ result = StrikeAPI::Torrent.find(['156B69B8643BD11849A5D8F2122E13FBB61BD041','B425907E5755031BDA4A8D1B6DCCACA97DA14C04'])
32
+ result1 = result[0]
33
+ result2 = result[1]
34
+ # Torrent 1: Slackware ISO
35
+ assert_equal StrikeAPI::Torrent, result1.class
36
+ assert_equal '156B69B8643BD11849A5D8F2122E13FBB61BD041', result1.hash
37
+ assert_equal 'Slackware 14.1 x86_64 DVD ISO', result1.title
38
+ assert_equal 'Applications', result1.category
39
+ assert_equal '', result1.subcategory
40
+ assert_equal 192, result1.seeds
41
+ assert_equal 9, result1.leeches
42
+ assert_equal 4, result1.file_count
43
+ assert_equal 2437393940, result1.size
44
+ # assert_equal 40, result1.download_count
45
+ assert_equal 'Feb 24, 2014', result1.upload_date
46
+ assert_equal 'Nusantara', result1.uploader_username
47
+ assert_equal 'magnet:?xt=urn:btih:156B69B8643BD11849A5D8F2122E13FBB61BD041&dn=Slackware+14.1+x86_64+DVD+ISO&tr=udp://open.demonii.com:1337&tr=udp://tracker.coppersurfer.tk:6969&tr=udp://tracker.leechers-paradise.org:6969&tr=udp://exodus.desync.com:6969', result1.magnet_uri
48
+ assert_equal 'slackware64-14.1-iso\\slackware64-14.1-install-dvd.iso', result1.file_info[0][0] # first file, filename
49
+ assert_equal 2438987776, result1.file_info[0][1] # first file, file length
50
+ # Torrent 2: Arch ISO
51
+ assert_equal StrikeAPI::Torrent, result2.class
52
+ assert_equal 'B425907E5755031BDA4A8D1B6DCCACA97DA14C04', result2.hash
53
+ assert_equal 'Arch Linux 2015.01.01 (x86/x64)', result2.title
54
+ assert_equal 'Applications', result2.category
55
+ assert_equal '', result2.subcategory
56
+ assert_equal 645, result2.seeds
57
+ assert_equal 13, result2.leeches
58
+ assert_equal 1, result2.file_count
59
+ assert_equal 615514112, result2.size
60
+ # assert_equal 40, result2.download_count
61
+ assert_equal 'Jan 6, 2015', result2.upload_date
62
+ assert_equal 'The_Doctor-', result2.uploader_username
63
+ assert_equal 'magnet:?xt=urn:btih:B425907E5755031BDA4A8D1B6DCCACA97DA14C04&dn=Arch+Linux+2015.01.01+%28x86%2Fx64%29&tr=udp://open.demonii.com:1337&tr=udp://tracker.coppersurfer.tk:6969&tr=udp://tracker.leechers-paradise.org:6969&tr=udp://exodus.desync.com:6969', result2.magnet_uri
64
+ assert_equal 'archlinux-2015.01.01-dual.iso', result2.file_info[0][0] # first file, filename
65
+ assert_equal 615514112, result2.file_info[0][1] # first file, file length
66
+ end
67
+ end
29
68
 
30
- def test_find_array
31
- VCR.use_cassette('test_find_array') do
32
- result = StrikeApi::Torrent.find(["156B69B8643BD11849A5D8F2122E13FBB61BD041","B425907E5755031BDA4A8D1B6DCCACA97DA14C04"])
33
- result1 = result[0]
34
- result2 = result[1]
35
- # Torrent 1: Slackware ISO
36
- assert_equal StrikeApi::Torrent, result1.class
37
- assert_equal "156B69B8643BD11849A5D8F2122E13FBB61BD041", result1.hash
38
- assert_equal "Slackware 14.1 x86_64 DVD ISO", result1.title
39
- assert_equal "Applications", result1.category
40
- assert_equal "", result1.sub_category
41
- assert_equal 192, result1.seeds
42
- assert_equal 9, result1.leeches
43
- assert_equal 4, result1.file_count
44
- assert_equal 2437393940, result1.size
45
- # assert_equal 40, result1.download_count
46
- assert_equal "Feb 24, 2014", result1.upload_date
47
- assert_equal "Nusantara", result1.uploader_username
48
- assert_equal "magnet:?xt=urn:btih:156B69B8643BD11849A5D8F2122E13FBB61BD041&dn=Slackware+14.1+x86_64+DVD+ISO&tr=udp:\/\/open.demonii.com:1337&tr=udp:\/\/tracker.coppersurfer.tk:6969&tr=udp:\/\/tracker.leechers-paradise.org:6969&tr=udp:\/\/exodus.desync.com:6969", result1.magnet_uri
49
- assert_equal "slackware64-14.1-iso\\slackware64-14.1-install-dvd.iso", result1.file_info[0][0] # first file, filename
50
- assert_equal 2438987776, result1.file_info[0][1] # first file, file length
51
- # Torrent 2: Arch ISO
52
- assert_equal StrikeApi::Torrent, result2.class
53
- assert_equal "B425907E5755031BDA4A8D1B6DCCACA97DA14C04", result2.hash
54
- assert_equal "Arch Linux 2015.01.01 (x86\/x64)", result2.title
55
- assert_equal "Applications", result2.category
56
- assert_equal "", result2.sub_category
57
- assert_equal 645, result2.seeds
58
- assert_equal 13, result2.leeches
59
- assert_equal 1, result2.file_count
60
- assert_equal 615514112, result2.size
61
- # assert_equal 40, result2.download_count
62
- assert_equal "Jan 6, 2015", result2.upload_date
63
- assert_equal "The_Doctor-", result2.uploader_username
64
- assert_equal "magnet:?xt=urn:btih:B425907E5755031BDA4A8D1B6DCCACA97DA14C04&dn=Arch+Linux+2015.01.01+%28x86%2Fx64%29&tr=udp:\/\/open.demonii.com:1337&tr=udp:\/\/tracker.coppersurfer.tk:6969&tr=udp:\/\/tracker.leechers-paradise.org:6969&tr=udp:\/\/exodus.desync.com:6969", result2.magnet_uri
65
- assert_equal "archlinux-2015.01.01-dual.iso", result2.file_info[0][0] # first file, filename
66
- assert_equal 615514112, result2.file_info[0][1] # first file, file length
67
- end
68
- end
69
+ def test_find_no_torrents
70
+ VCR.use_cassette('test_find_no_torrents') do
71
+ begin
72
+ result = StrikeAPI::Torrent.find('156B69B8643BD1184D041')[0]
73
+ rescue => e
74
+ assert_equal 'Strike API error: 404 - No torrents found with provided hashes', e.message
75
+ end
76
+ end
77
+ end
69
78
 
70
- def test_find_no_torrents
71
- VCR.use_cassette('test_find_no_torrents') do
72
- begin
73
- result = StrikeApi::Torrent.find("156B69B8643BD1184D041")[0]
74
- rescue => e
75
- assert_equal "Strike API error: 404 - No torrents found with provided hashes", e.message
76
- end
77
- end
78
- end
79
+ def test_find_empty
80
+ VCR.use_cassette('test_find_empty') do
81
+ begin
82
+ result = StrikeAPI::Torrent.find('')[0]
83
+ rescue => e
84
+ assert_equal 'Strike API error: 404 - No torrents found with provided hashes', e.message
85
+ end
86
+ end
87
+ end
79
88
 
80
- def test_find_empty
81
- VCR.use_cassette('test_find_empty') do
82
- begin
83
- result = StrikeApi::Torrent.find("")[0]
84
- rescue => e
85
- assert_equal "Strike API error: 404 - No torrents found with provided hashes", e.message
86
- end
87
- end
88
- end
89
+ def test_search_no_torrents
90
+ VCR.use_cassette('test_search_no_torrents') do
91
+ begin
92
+ result = StrikeAPI::Torrent.search('123456789abcdefg')[0]
93
+ rescue => e
94
+ assert_equal 'Strike API error: 404 - No torrents found.', e.message
95
+ end
96
+ end
97
+ end
89
98
 
90
- def test_search_no_torrents
91
- VCR.use_cassette('test_search_no_torrents') do
92
- begin
93
- result = StrikeApi::Torrent.search("123456789abcdefg")[0]
94
- rescue => e
95
- assert_equal "Strike API error: 404 - No torrents found.", e.message
96
- end
97
- end
98
- end
99
+ def test_search_empty
100
+ VCR.use_cassette('test_search_empty') do
101
+ begin
102
+ result = StrikeAPI::Torrent.search('')[0]
103
+ rescue => e
104
+ assert_equal 'Strike API error: 404 - Please enter a phrease.', e.message
105
+ end
106
+ end
107
+ end
99
108
 
100
- def test_search_empty
101
- VCR.use_cassette('test_search_empty') do
102
- begin
103
- result = StrikeApi::Torrent.search("")[0]
104
- rescue => e
105
- assert_equal "Strike API error: 404 - Please enter a phrease.", e.message
106
- end
107
- end
108
- end
109
+ def test_search
110
+ VCR.use_cassette('test_search') do
111
+ result = StrikeAPI::Torrent.search('Slackware 14.1 x86_64 DVD ISO')
112
+ assert_equal 1, result.length
113
+ assert result.kind_of?(Array)
114
+ assert result.first.kind_of?(StrikeAPI::Torrent)
115
+ assert !result[0].file_info # file_info information is not given in search results
116
+ end
117
+ end
109
118
 
110
- def test_search
111
- VCR.use_cassette('test_search') do
112
- result = StrikeApi::Torrent.search("Slackware 14.1 x86_64 DVD ISO")
113
- assert_equal 1, result.length
114
- assert result.kind_of?(Array)
115
- assert result.first.kind_of?(StrikeApi::Torrent)
116
- assert !result[0].file_info # file_info information is not given in search results
117
- end
118
- end
119
+ def test_search_category
120
+ VCR.use_cassette('test_search_category') do
121
+ result = StrikeAPI::Torrent.search('windows', 'Applications')
122
+ assert_equal 100, result.length
123
+ assert result.kind_of?(Array)
124
+ assert result.first.kind_of?(StrikeAPI::Torrent)
125
+ assert !result[0].file_info # file_info information is not given in search results
126
+ end
127
+ end
119
128
 
120
- def test_search_category
121
- VCR.use_cassette('test_search_category') do
122
- result = StrikeApi::Torrent.search("windows", "Applications")
123
- assert_equal 100, result.length
124
- assert result.kind_of?(Array)
125
- assert result.first.kind_of?(StrikeApi::Torrent)
126
- assert !result[0].file_info # file_info information is not given in search results
127
- end
128
- end
129
+ def test_search_subcategory
130
+ VCR.use_cassette('test_search_subCategory') do
131
+ result = StrikeAPI::Torrent.search('windows', 'Windows')
132
+ assert_equal 100, result.length
133
+ assert result.kind_of?(Array)
134
+ assert result.first.kind_of?(StrikeAPI::Torrent)
135
+ assert !result[0].file_info # file_info information is not given in search results
136
+ end
137
+ end
129
138
 
130
- def test_search_subCategory
131
- VCR.use_cassette('test_search_subCategory') do
132
- result = StrikeApi::Torrent.search("windows", "Windows")
133
- assert_equal 100, result.length
134
- assert result.kind_of?(Array)
135
- assert result.first.kind_of?(StrikeApi::Torrent)
136
- assert !result[0].file_info # file_info information is not given in search results
137
- end
138
- end
139
+ def test_search_category_subcategory
140
+ VCR.use_cassette('test_search_category_subCategory') do
141
+ result = StrikeAPI::Torrent.search('windows', 'Applications', 'Windows')
142
+ assert_equal 100, result.length
143
+ assert result.kind_of?(Array)
144
+ assert result.first.kind_of?(StrikeAPI::Torrent)
145
+ assert !result[0].file_info # file_info information is not given in search results
146
+ end
147
+ end
139
148
 
140
- def test_search_category_subCategory
141
- VCR.use_cassette('test_search_category_subCategory') do
142
- result = StrikeApi::Torrent.search("windows", "Applications", "Windows")
143
- assert_equal 100, result.length
144
- assert result.kind_of?(Array)
145
- assert result.first.kind_of?(StrikeApi::Torrent)
146
- assert !result[0].file_info # file_info information is not given in search results
147
- end
148
- end
149
+ def test_search_more_than_three_params
150
+ VCR.use_cassette('test_search_more_than_three_params') do
151
+ begin
152
+ result = StrikeAPI::Torrent.search('windows', 'Applications', 'Windows','Test')
153
+ rescue => e
154
+ assert_equal 'Invalid number of parameters: input <= 3', e.message
155
+ end
156
+ end
157
+ end
149
158
 
150
- def test_search_more_than_three_params
151
- VCR.use_cassette('test_search_more_than_three_params') do
152
- begin
153
- result = StrikeApi::Torrent.search("windows", "Applications", "Windows","Test")
154
- rescue => e
155
- assert_equal "Invalid number of parameters: input <= 3", e.message
156
- end
157
- end
158
- end
159
+ def test_search_invalid_two_inputs
160
+ VCR.use_cassette('test_search_invalid_two_inputs') do
161
+ begin
162
+ result = StrikeAPI::Torrent.search('windows', 'asdasdasd')
163
+ rescue => e
164
+ assert_equal 'The category/subcategory entered is not valid', e.message
165
+ end
166
+ end
167
+ end
159
168
 
160
- def test_search_invalid_two_inputs
161
- VCR.use_cassette('test_search_invalid_two_inputs') do
162
- begin
163
- result = StrikeApi::Torrent.search("windows", "asdasdasd")
164
- rescue => e
165
- assert_equal "The category/sub category entered is not valid", e.message
166
- end
167
- end
168
- end
169
+ def test_search_invalid_category
170
+ VCR.use_cassette('test_search_invalid_category') do
171
+ begin
172
+ result = StrikeAPI::Torrent.search('windows', 'asdasdasd','Windows')
173
+ rescue => e
174
+ assert_equal 'The category is not valid', e.message
175
+ end
176
+ end
177
+ end
169
178
 
170
- def test_search_invalid_category
171
- VCR.use_cassette('test_search_invalid_category') do
172
- begin
173
- result = StrikeApi::Torrent.search("windows", "asdasdasd","Windows")
174
- rescue => e
175
- assert_equal "The category is not valid", e.message
176
- end
177
- end
178
- end
179
+ def test_search_invalid_subcategory
180
+ VCR.use_cassette('test_search_invalid_subcategory') do
181
+ begin
182
+ result = StrikeAPI::Torrent.search('windows', 'Applications','asdasdsdsa')
183
+ rescue => e
184
+ assert_equal 'The subcategory is not valid', e.message
185
+ end
186
+ end
187
+ end
179
188
 
180
- def test_search_invalid_subcategory
181
- VCR.use_cassette('test_search_invalid_subcategory') do
182
- begin
183
- result = StrikeApi::Torrent.search("windows", "Applications","asdasdsdsa")
184
- rescue => e
185
- assert_equal "The sub category is not valid", e.message
186
- end
187
- end
188
- end
189
+ def test_site_down_cloudflare
190
+ VCR.use_cassette('test_site_down_cloudflare') do
191
+ begin
192
+ result = StrikeAPI::Torrent.search('Slackware 14.1 x86_64 DVD ISO')
193
+ rescue => e
194
+ assert_equal 'Strike API error: 522 - Origin Connection Time-out', e.message
195
+ end
196
+ end
197
+ end
189
198
 
190
- def test_site_down_cloudflare
191
- VCR.use_cassette('test_site_down_cloudflare') do
192
- begin
193
- result = StrikeApi::Torrent.search("Slackware 14.1 x86_64 DVD ISO")
194
- rescue => e
195
- assert_equal "Strike API error: 522 - Origin Connection Time-out", e.message
196
- end
197
- end
198
- end
199
+ def test_filter_string
200
+ VCR.use_cassette('test_filter_string') do
201
+ flag = true
202
+ result = StrikeAPI::Torrent.search('windows -windows8', 'Applications', 'Windows')
203
+ assert_equal 100, result.length
204
+ assert result.kind_of?(Array)
205
+ assert result.first.kind_of?(StrikeAPI::Torrent)
206
+ filteredStr = 'windows 8'
207
+ result.each do |torrent|
208
+ if(torrent.title.strip.downcase.include? filteredStr.strip.downcase)
209
+ flag = false
210
+ end
211
+ end
212
+ assert_equal true, flag
213
+ end
214
+ end
199
215
 
200
- def test_filter_string
201
- VCR.use_cassette('test_filter_string') do
202
- flag = true
203
- result = StrikeApi::Torrent.search("windows -windows8", "Applications", "Windows")
204
- assert_equal 100, result.length
205
- assert result.kind_of?(Array)
206
- assert result.first.kind_of?(StrikeApi::Torrent)
207
- filteredStr = "windows 8"
208
- result.each do |torrent|
209
- if(torrent.title.strip.downcase.include? filteredStr.strip.downcase)
210
- flag = false
211
- end
212
- end
213
- assert_equal true, flag
214
- end
215
- end
216
+ def test_filter_string_no_filter
217
+ VCR.use_cassette('test_filter_string_no_filter') do
218
+ flag = true
219
+ result = StrikeAPI::Torrent.search('windows', 'Applications', 'Windows')
220
+ assert_equal 100, result.length
221
+ assert result.kind_of?(Array)
222
+ assert result.first.kind_of?(StrikeAPI::Torrent)
223
+ filteredStr = 'windows 8'
224
+ result.each do |torrent|
225
+ if(torrent.title.strip.downcase.include? filteredStr.strip.downcase)
226
+ flag = false
227
+ end
228
+ end
229
+ assert_equal false, flag
230
+ end
231
+ end
216
232
 
217
- def test_filter_string_no_filter
218
- VCR.use_cassette('test_filter_string_no_filter') do
219
- flag = true
220
- result = StrikeApi::Torrent.search("windows", "Applications", "Windows")
221
- assert_equal 100, result.length
222
- assert result.kind_of?(Array)
223
- assert result.first.kind_of?(StrikeApi::Torrent)
224
- filteredStr = "windows 8"
225
- result.each do |torrent|
226
- if(torrent.title.strip.downcase.include? filteredStr.strip.downcase)
227
- flag = false
228
- end
229
- end
230
- assert_equal false, flag
231
- end
232
- end
233
+ def test_top
234
+ VCR.use_cassette('test_top') do
235
+ result = StrikeAPI::Torrent.top('Books')
236
+ assert_equal 100, result.length
237
+ assert result.kind_of?(Array)
238
+ assert result.first.kind_of?(StrikeAPI::Torrent)
239
+ assert !result[0].file_info
240
+ end
241
+ end
233
242
 
234
- def test_top
235
- VCR.use_cassette('test_top') do
236
- result = StrikeApi::Torrent.top("Books")
237
- assert_equal 100, result.length
238
- assert result.kind_of?(Array)
239
- assert result.first.kind_of?(StrikeApi::Torrent)
240
- assert !result[0].file_info
241
- end
242
- end
243
+ def test_top_invalid_category
244
+ VCR.use_cassette('test_top_invalid_category') do
245
+ begin
246
+ result = StrikeAPI::Torrent.top('abc123')
247
+ rescue => e
248
+ assert_equal 'The category is not valid', e.message
249
+ end
250
+ end
251
+ end
243
252
 
244
- def test_top_invalid_category
245
- VCR.use_cassette('test_top_invalid_category') do
246
- begin
247
- result = StrikeApi::Torrent.top("abc123")
248
- rescue => e
249
- assert_equal "The category is not valid", e.message
250
- end
251
- end
252
- end
253
+ def test_top_all_category
254
+ VCR.use_cassette('test_top_all_category') do
255
+ result = StrikeAPI::Torrent.top('all')
256
+ assert_equal 100, result.length
257
+ assert result.kind_of?(Array)
258
+ assert result.first.kind_of?(StrikeAPI::Torrent)
259
+ assert !result[0].file_info
260
+ end
261
+ end
253
262
 
254
- def test_top_all_category
255
- VCR.use_cassette('test_top_all_category') do
256
- result = StrikeApi::Torrent.top("all")
257
- assert_equal 100, result.length
258
- assert result.kind_of?(Array)
259
- assert result.first.kind_of?(StrikeApi::Torrent)
260
- assert !result[0].file_info
261
- end
262
- end
263
+ def test_categories_available
264
+ result = StrikeAPI::Torrent.categories_available
265
+ assert result.kind_of?(Array)
266
+ assert result.first.kind_of?(String)
267
+ end
263
268
 
264
- def test_catagoriesAvailable
265
- result = StrikeApi::Torrent.catagoriesAvailable
266
- assert result.kind_of?(Array)
267
- assert result.first.kind_of?(String)
268
- end
269
-
270
- def test_subCatagoriesAvailable
271
- result = StrikeApi::Torrent.subCatagoriesAvailable
272
- assert result.kind_of?(Array)
273
- assert result.first.kind_of?(String)
274
- end
269
+ def test_subcategories_available
270
+ result = StrikeAPI::Torrent.subcategories_available
271
+ assert result.kind_of?(Array)
272
+ assert result.first.kind_of?(String)
273
+ end
275
274
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: strike_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
4
+ version: 1.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marshall Ford
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-05-08 00:00:00.000000000 Z
12
+ date: 2015-09-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -109,7 +109,7 @@ dependencies:
109
109
  - - ">="
110
110
  - !ruby/object:Gem::Version
111
111
  version: '0'
112
- description: API wrapper for the Strike Search website (https://getstrike.net/torrents/)
112
+ description: Wrapper for the Strike Search website/API (https://getstrike.net/torrents/)
113
113
  email:
114
114
  - inbox@marshallford.me
115
115
  executables: []
@@ -163,7 +163,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
163
163
  version: '0'
164
164
  requirements: []
165
165
  rubyforge_project:
166
- rubygems_version: 2.4.6
166
+ rubygems_version: 2.4.8
167
167
  signing_key:
168
168
  specification_version: 4
169
169
  summary: Wrapper for the Strike API.