rarbg 1.4.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +15 -0
- data/LICENSE +1 -1
- data/README.md +3 -4
- data/lib/rarbg/api.rb +76 -62
- data/lib/rarbg/version.rb +1 -1
- data/rarbg.gemspec +8 -11
- metadata +21 -52
- data/.editorconfig +0 -12
- data/.github/CODEOWNERS +0 -4
- data/.github/ISSUE_TEMPLATE/BUG_REPORT.md +0 -25
- data/.github/ISSUE_TEMPLATE/FEATURE_REQUEST.md +0 -18
- data/.github/PULL_REQUEST_TEMPLATE.md +0 -14
- data/.gitignore +0 -44
- data/.hound.yml +0 -5
- data/.rspec +0 -4
- data/.rubocop.yml +0 -36
- data/.travis.yml +0 -21
- data/.yardopts +0 -8
- data/CODE_OF_CONDUCT.md +0 -74
- data/CONTRIBUTING.md +0 -96
- data/Gemfile +0 -4
- data/Rakefile +0 -13
- data/bin/console +0 -8
- data/bin/setup +0 -7
- data/spec/rarbg/list_spec.rb +0 -111
- data/spec/rarbg/rarbg_spec.rb +0 -30
- data/spec/rarbg/search_spec.rb +0 -138
- data/spec/rarbg/token_spec.rb +0 -76
- data/spec/spec_helper.rb +0 -36
- data/spec/stubs.rb +0 -45
data/spec/rarbg/rarbg_spec.rb
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe RARBG do
|
4
|
-
it 'has a version number' do
|
5
|
-
expect(RARBG::VERSION).not_to be nil
|
6
|
-
expect(RARBG::VERSION).to match(/(\d+\.)(\d+\.)(\d+)(-?[\S]+)?/)
|
7
|
-
end
|
8
|
-
|
9
|
-
it 'has a category list' do
|
10
|
-
expect(RARBG::CATEGORIES).to be_kind_of(Hash)
|
11
|
-
expect(RARBG::CATEGORIES).to include(/Movies/, /TV/, /Music/)
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'has an app id' do
|
15
|
-
expect(RARBG::API::APP_ID).not_to be nil
|
16
|
-
expect(RARBG::API::APP_ID).to be_kind_of(String)
|
17
|
-
end
|
18
|
-
|
19
|
-
it 'has the correct API endpoint' do
|
20
|
-
expect(RARBG::API::API_ENDPOINT).to eq('https://torrentapi.org/pubapi_v2.php')
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'has a token expiration' do
|
24
|
-
expect(RARBG::API::TOKEN_EXPIRATION).to be_kind_of(Numeric)
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'has a rate limit' do
|
28
|
-
expect(RARBG::API::RATE_LIMIT).to be_kind_of(Numeric)
|
29
|
-
end
|
30
|
-
end
|
data/spec/rarbg/search_spec.rb
DELETED
@@ -1,138 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe 'RARBG::API#search' do
|
4
|
-
before(:all) do
|
5
|
-
@rarbg = RARBG::API.new
|
6
|
-
@token = SecureRandom.hex(5)
|
7
|
-
end
|
8
|
-
|
9
|
-
before(:each) do
|
10
|
-
stub_token(@token)
|
11
|
-
end
|
12
|
-
|
13
|
-
context 'when search request succeeds' do
|
14
|
-
before(:example) do
|
15
|
-
stub_search(
|
16
|
-
@token, {},
|
17
|
-
{ torrent_results: [
|
18
|
-
{
|
19
|
-
filename: 'first stubbed name',
|
20
|
-
category: 'first stubbed category',
|
21
|
-
download: 'first stubbed magnet link'
|
22
|
-
},
|
23
|
-
{
|
24
|
-
filename: 'second stubbed name',
|
25
|
-
category: 'second stubbed category',
|
26
|
-
download: 'second stubbed magnet link'
|
27
|
-
}
|
28
|
-
] }
|
29
|
-
)
|
30
|
-
end
|
31
|
-
|
32
|
-
it 'returns an array of hashes' do
|
33
|
-
expect(@rarbg.search(string: 'a search string')).to all(be_an(Hash))
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'returns hashes with filename and download link' do
|
37
|
-
expect(@rarbg.search(imdb: 'tt0000000'))
|
38
|
-
.to all include('filename').and include('download')
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
context 'when search request returns no result' do
|
43
|
-
before(:example) do
|
44
|
-
stub_search(
|
45
|
-
@token, {},
|
46
|
-
{ error: 'No results found' }
|
47
|
-
)
|
48
|
-
end
|
49
|
-
|
50
|
-
it 'returns an empty array' do
|
51
|
-
expect(@rarbg.search(string: 'awrongquery')).to eq([])
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
context 'when search request returns an id error' do
|
56
|
-
let(:type) { %i[imdb themoviedb tvdb].sample }
|
57
|
-
|
58
|
-
before(:example) do
|
59
|
-
stub_search(
|
60
|
-
@token, {},
|
61
|
-
{ error: "Cant find #{type} in database. Are you sure this #{type} exists?" }
|
62
|
-
)
|
63
|
-
end
|
64
|
-
|
65
|
-
it 'returns an empty array' do
|
66
|
-
expect(@rarbg.search(type => '9999999')).to eq([])
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
context 'when search request parameters is not an hash' do
|
71
|
-
before(:example) do
|
72
|
-
stub_search(
|
73
|
-
@token
|
74
|
-
)
|
75
|
-
end
|
76
|
-
|
77
|
-
it 'raises an ArgumentError exception' do
|
78
|
-
expect { @rarbg.search('string') }.to raise_error(
|
79
|
-
ArgumentError, 'Expected params hash'
|
80
|
-
)
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
context 'when search request is missing search type' do
|
85
|
-
before(:example) do
|
86
|
-
stub_search(
|
87
|
-
@token
|
88
|
-
)
|
89
|
-
end
|
90
|
-
|
91
|
-
it 'raises an ArgumentError exception' do
|
92
|
-
expect { @rarbg.search(category: [45, 46], sort: :last) }
|
93
|
-
.to raise_error(ArgumentError)
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
context 'when search request has invalid parameters' do
|
98
|
-
before(:example) do
|
99
|
-
stub_search(
|
100
|
-
@token, {},
|
101
|
-
{ error: 'Invalid sort' }
|
102
|
-
)
|
103
|
-
end
|
104
|
-
|
105
|
-
it 'raises a RARBG::APIError exception' do
|
106
|
-
expect { @rarbg.search(string: 'string', sort: 'wrongsort') }
|
107
|
-
.to raise_error(RARBG::APIError, 'Invalid sort')
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
context 'when search request fails' do
|
112
|
-
before(:example) do
|
113
|
-
stub_error(503, 'Service unavailable')
|
114
|
-
end
|
115
|
-
|
116
|
-
it 'raises a RARBG::APIError exception' do
|
117
|
-
expect { @rarbg.search(string: 'string') }.to raise_error(
|
118
|
-
RARBG::APIError, 'Service unavailable (503)'
|
119
|
-
)
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
|
-
context 'when called from top level namespace' do
|
124
|
-
let(:rarbg_module) { RARBG.clone }
|
125
|
-
|
126
|
-
before(:example) do
|
127
|
-
stub_search(
|
128
|
-
@token
|
129
|
-
)
|
130
|
-
end
|
131
|
-
|
132
|
-
it 'instantiates an API object' do
|
133
|
-
expect { rarbg_module.search(string: 'string') }
|
134
|
-
.to change { rarbg_module.instance_variable_get(:@rarbg).class }
|
135
|
-
.to(RARBG::API)
|
136
|
-
end
|
137
|
-
end
|
138
|
-
end
|
data/spec/rarbg/token_spec.rb
DELETED
@@ -1,76 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe RARBG::API do
|
4
|
-
before(:all) do
|
5
|
-
@rarbg = RARBG::API.new
|
6
|
-
@token = SecureRandom.hex(5)
|
7
|
-
end
|
8
|
-
|
9
|
-
context 'when token request succeeds' do
|
10
|
-
before(:each) do
|
11
|
-
stub_token(@token)
|
12
|
-
stub_list(@token)
|
13
|
-
@rarbg.list
|
14
|
-
end
|
15
|
-
|
16
|
-
it 'has a token' do
|
17
|
-
expect(@rarbg.token).not_to be nil
|
18
|
-
end
|
19
|
-
|
20
|
-
it 'stores the returned token' do
|
21
|
-
expect(@rarbg.token).to eq(@token)
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'has a token timestamp' do
|
25
|
-
expect(@rarbg.token_time).to be_a(Numeric)
|
26
|
-
end
|
27
|
-
|
28
|
-
it 'respects rate limit' do
|
29
|
-
expect(@rarbg.last_request - @rarbg.token_time).to be >= RARBG::API::RATE_LIMIT
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
context 'when token request fails' do
|
34
|
-
before(:example) do
|
35
|
-
stub_error(500, 'Internal Server Error')
|
36
|
-
end
|
37
|
-
|
38
|
-
it 'raises a RARBG::APIError exception' do
|
39
|
-
expect { @rarbg.list }.to raise_error(
|
40
|
-
RARBG::APIError, 'Internal Server Error (500)'
|
41
|
-
)
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
context 'when token request timeouts' do
|
46
|
-
before(:example) do
|
47
|
-
stub_timeout
|
48
|
-
end
|
49
|
-
|
50
|
-
it 'raises a Faraday::ConnectionFailed exception' do
|
51
|
-
expect { @rarbg.list }.to raise_error(Faraday::ConnectionFailed)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
context 'when forcing the token generation' do
|
56
|
-
before(:example) do
|
57
|
-
stub_token(
|
58
|
-
@token
|
59
|
-
)
|
60
|
-
end
|
61
|
-
|
62
|
-
it 'returns the currently valid token' do
|
63
|
-
expect(@rarbg.token!).to eq(@token)
|
64
|
-
end
|
65
|
-
|
66
|
-
context 'when called from top level namespace' do
|
67
|
-
let(:rarbg_module) { RARBG.clone }
|
68
|
-
|
69
|
-
it 'instantiates an API object' do
|
70
|
-
expect { rarbg_module.token! }
|
71
|
-
.to change { rarbg_module.instance_variable_get(:@rarbg).class }
|
72
|
-
.to(RARBG::API)
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
data/spec/spec_helper.rb
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'simplecov'
|
4
|
-
SimpleCov.start
|
5
|
-
|
6
|
-
require 'bundler/setup'
|
7
|
-
require 'webmock/rspec'
|
8
|
-
require 'securerandom'
|
9
|
-
require 'rarbg'
|
10
|
-
|
11
|
-
require_relative 'stubs'
|
12
|
-
|
13
|
-
RSpec.configure do |config|
|
14
|
-
# Attach WebMock and its stubbed requests.
|
15
|
-
WebMock.disable_net_connect!(allow_localhost: true)
|
16
|
-
config.include(Stubs)
|
17
|
-
|
18
|
-
# Enable flags like --only-failures and --next-failure.
|
19
|
-
config.example_status_persistence_file_path = '.rspec_status'
|
20
|
-
|
21
|
-
# Disable RSpec exposing methods globally on `Module` and `main`.
|
22
|
-
config.disable_monkey_patching!
|
23
|
-
|
24
|
-
# Enable temporarily focused examples and groups.
|
25
|
-
config.filter_run_when_matching :focus
|
26
|
-
|
27
|
-
# Use expect syntax.
|
28
|
-
config.expect_with :rspec do |c|
|
29
|
-
c.syntax = :expect
|
30
|
-
end
|
31
|
-
|
32
|
-
# Stub RATE_LIMIT to speed up tests.
|
33
|
-
config.before(:example) do
|
34
|
-
stub_const('RARBG::API::RATE_LIMIT', 0.1)
|
35
|
-
end
|
36
|
-
end
|
data/spec/stubs.rb
DELETED
@@ -1,45 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# WebMock stubs for RSpec.
|
4
|
-
module Stubs
|
5
|
-
API_ENDPOINT = RARBG::API::API_ENDPOINT
|
6
|
-
|
7
|
-
def stub_token(token)
|
8
|
-
stub_request(:get, API_ENDPOINT)
|
9
|
-
.with(query: hash_including('get_token' => 'get_token'))
|
10
|
-
.to_return(status: 200, body: { token: token }.to_json,
|
11
|
-
headers: { 'Content-Type' => 'application/json' })
|
12
|
-
end
|
13
|
-
|
14
|
-
def stub_list(token, params = {}, result = {})
|
15
|
-
stub_request(:get, API_ENDPOINT)
|
16
|
-
.with(query: hash_including(params.update(
|
17
|
-
mode: 'list',
|
18
|
-
token: token
|
19
|
-
)))
|
20
|
-
.to_return(status: 200, body: result.to_json,
|
21
|
-
headers: { 'Content-Type' => 'application/json' })
|
22
|
-
end
|
23
|
-
|
24
|
-
def stub_search(token, params = {}, result = {})
|
25
|
-
stub_request(:get, API_ENDPOINT)
|
26
|
-
.with(query: hash_including(params.update(
|
27
|
-
mode: 'search',
|
28
|
-
token: token
|
29
|
-
)))
|
30
|
-
.to_return(status: 200, body: result.to_json,
|
31
|
-
headers: { 'Content-Type' => 'application/json' })
|
32
|
-
end
|
33
|
-
|
34
|
-
def stub_error(status, error)
|
35
|
-
stub_request(:get, API_ENDPOINT)
|
36
|
-
.with(query: hash_including({}))
|
37
|
-
.to_return(status: [status, error])
|
38
|
-
end
|
39
|
-
|
40
|
-
def stub_timeout
|
41
|
-
stub_request(:get, API_ENDPOINT)
|
42
|
-
.with(query: hash_including({}))
|
43
|
-
.to_timeout
|
44
|
-
end
|
45
|
-
end
|