rarbg 0.1.4 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,54 @@
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(:context) 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 'has last request > token_time' do
29
+ expect(@rarbg.last_request - @rarbg.token_time).to be > 2
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
+ end
@@ -0,0 +1,26 @@
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
+ WebMock.disable_net_connect!(allow_localhost: true)
15
+ config.include(Stubs)
16
+
17
+ # Enable flags like --only-failures and --next-failure
18
+ config.example_status_persistence_file_path = '.rspec_status'
19
+
20
+ # Disable RSpec exposing methods globally on `Module` and `main`
21
+ config.disable_monkey_patching!
22
+
23
+ config.expect_with :rspec do |c|
24
+ c.syntax = :expect
25
+ end
26
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Stubs
4
+ BASE_URL = 'https://torrentapi.org/pubapi_v2.php'
5
+ APP_ID = 'rarbg-rubygem'
6
+
7
+ def stub_token(token)
8
+ stub_request(:get, BASE_URL)
9
+ .with(query: hash_including('get_token' => 'get_token'))
10
+ .to_return(status: 200, body: { token: token }.to_json)
11
+ end
12
+
13
+ def stub_list(token, params = {}, result = {})
14
+ stub_request(:get, BASE_URL)
15
+ .with(query: hash_including(params.update(
16
+ mode: 'list',
17
+ token: token
18
+ )))
19
+ .to_return(status: 200, body: result.to_json)
20
+ end
21
+
22
+ def stub_search(token, params = {}, result = {})
23
+ stub_request(:get, BASE_URL)
24
+ .with(query: hash_including(params.update(
25
+ mode: 'search',
26
+ token: token
27
+ )))
28
+ .to_return(status: 200, body: result.to_json)
29
+ end
30
+
31
+ def stub_error(status, error)
32
+ stub_request(:get, BASE_URL)
33
+ .with(query: hash_including({}))
34
+ .to_return(status: [status, error])
35
+ end
36
+
37
+ def stub_timeout
38
+ stub_request(:get, BASE_URL)
39
+ .with(query: hash_including({}))
40
+ .to_timeout
41
+ end
42
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rarbg
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tommaso Barbato
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-12-22 00:00:00.000000000 Z
11
+ date: 2018-04-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -38,17 +38,142 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0.10'
41
- description: A ruby wrapper for RARBG torrentapi.
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.16'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.16'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '12.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '12.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: simplecov
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: webmock
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '3.3'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '3.3'
125
+ - !ruby/object:Gem::Dependency
126
+ name: yard
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '0.9'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '0.9'
139
+ description: Ruby wrapper for RARBG Torrent API.
42
140
  email: epistrephein@gmail.com
43
141
  executables: []
44
142
  extensions: []
45
143
  extra_rdoc_files: []
46
144
  files:
145
+ - ".editorconfig"
146
+ - ".gitignore"
147
+ - ".rspec"
148
+ - ".travis.yml"
149
+ - ".yardopts"
150
+ - CHANGELOG.md
151
+ - CODE_OF_CONDUCT.md
152
+ - Gemfile
153
+ - LICENSE
154
+ - README.md
155
+ - Rakefile
156
+ - bin/console
157
+ - bin/setup
47
158
  - lib/rarbg.rb
159
+ - lib/rarbg/api.rb
160
+ - lib/rarbg/version.rb
161
+ - rarbg.gemspec
162
+ - spec/rarbg/list_spec.rb
163
+ - spec/rarbg/rarbg_spec.rb
164
+ - spec/rarbg/search_spec.rb
165
+ - spec/rarbg/token_spec.rb
166
+ - spec/spec_helper.rb
167
+ - spec/stubs.rb
48
168
  homepage: https://github.com/epistrephein/rarbg
49
169
  licenses:
50
170
  - MIT
51
- metadata: {}
171
+ metadata:
172
+ bug_tracker_uri: https://github.com/epistrephein/rarbg/issues
173
+ changelog_uri: https://github.com/epistrephein/rarbg/blob/master/CHANGELOG.md
174
+ documentation_uri: http://www.rubydoc.info/gems/rarbg
175
+ homepage_uri: https://github.com/epistrephein/rarbg
176
+ source_code_uri: https://github.com/epistrephein/rarbg
52
177
  post_install_message:
53
178
  rdoc_options: []
54
179
  require_paths:
@@ -57,7 +182,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
57
182
  requirements:
58
183
  - - ">="
59
184
  - !ruby/object:Gem::Version
60
- version: '0'
185
+ version: '2.0'
61
186
  required_rubygems_version: !ruby/object:Gem::Requirement
62
187
  requirements:
63
188
  - - ">="
@@ -68,5 +193,11 @@ rubyforge_project:
68
193
  rubygems_version: 2.6.14
69
194
  signing_key:
70
195
  specification_version: 4
71
- summary: Ruby wrapper for RARBG torrentapi
72
- test_files: []
196
+ summary: RARBG Ruby client.
197
+ test_files:
198
+ - spec/rarbg/list_spec.rb
199
+ - spec/rarbg/rarbg_spec.rb
200
+ - spec/rarbg/search_spec.rb
201
+ - spec/rarbg/token_spec.rb
202
+ - spec/spec_helper.rb
203
+ - spec/stubs.rb