rarbg 1.4.0 → 2.0.0

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
  SHA256:
3
- metadata.gz: d15b81ab8d45c3c01c9addc0bce085b59990b9124d80b32b44ad8948edfbb367
4
- data.tar.gz: 46b000569403255560866144cf09af78e8b9b6a25bc93bdfa0c6b27117697cd9
3
+ metadata.gz: 5911f31dd50a010daed44606e68eb58763b55f9c5868c1caa6548b6ce9f48d1f
4
+ data.tar.gz: cd9d585d2e854852090bea1dfad593544b79cf381ba0f9e639e5fd9fae00d527
5
5
  SHA512:
6
- metadata.gz: 95aa9133de0794c7b41c44ad000470a3a9d20eb6576ada2e4b850d907027c809979bf6b44fbcb8312e5fa8efb27ff93433df077b98a736b60727c69b2e035278
7
- data.tar.gz: 28185dbdf3875c246b2b76bc9a07d3100fa016970bffaae1673d568f64052ac74354f289290b36895533503f2c12295732d533224c7896a9d1f6e5b813662b08
6
+ metadata.gz: ca6baeeb1a4d8f6d6f78494ea469bf411c212baee4e4614a287eeec20c54225e3eea50fbd6c40fa91cf90dcd14bd67bdba5e4a1faa33482fd1797967df368d52
7
+ data.tar.gz: e0c233cf49ac9afb85a59078d5c0453b741d172ddc1122025f41d5d5fbcd394c3e4f2844f0331dba448763e74ce517b3d9223afc6a12084c99e77486761d706d
@@ -4,6 +4,21 @@ All notable changes to this project will be documented in this file.
4
4
  The format is based on [Keep a Changelog](https://keepachangelog.com/),
5
5
  and this project adheres to [Semantic Versioning](https://semver.org/).
6
6
 
7
+ ## 2.0.0 - 2020-01-22
8
+ [RubyGems](https://rubygems.org/gems/rarbg/versions/2.0.0) |
9
+ [Release](https://github.com/epistrephein/rarbg/releases/tag/v2.0.0) |
10
+ [Diff](https://github.com/epistrephein/rarbg/compare/v1.4.0...v2.0.0)
11
+
12
+ #### Changed
13
+ - Update Faraday to v1.0 and drop `faraday_middleware` dependency ([#17](https://github.com/epistrephein/rarbg/pull/17)).
14
+ - Update Ruby minimum version to 2.3 ([#17](https://github.com/epistrephein/rarbg/pull/17)).
15
+ - Rename attr_reader `conn` to `connection` ([#18](https://github.com/epistrephein/rarbg/pull/18)).
16
+ - Remove unnecessary files and attributes from gemspec ([#21](https://github.com/epistrephein/rarbg/pull/21)).
17
+ - Update version constraints for Rake, following v13.0 release ([#15](https://github.com/epistrephein/rarbg/pull/15)).
18
+ - Update version constraints for RuboCop in order to avoid breaking changes ([#16](https://github.com/epistrephein/rarbg/pull/16)).
19
+ - Tweak and reorder documentation ([#18](https://github.com/epistrephein/rarbg/pull/18)).
20
+
21
+
7
22
  ## 1.4.0 - 2019-06-05
8
23
  [RubyGems](https://rubygems.org/gems/rarbg/versions/1.4.0) |
9
24
  [Release](https://github.com/epistrephein/rarbg/releases/tag/v1.4.0) |
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2016-2019 Tommaso Barbato
3
+ Copyright (c) 2016-2020 Tommaso Barbato
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -20,14 +20,14 @@ $ gem install rarbg
20
20
  Or add it to your Gemfile and execute `bundle install`
21
21
 
22
22
  ```ruby
23
- gem 'rarbg', '~> 1.4'
23
+ gem 'rarbg', '~> 2.0'
24
24
  ```
25
25
 
26
26
  ## Usage
27
27
 
28
- This gem wraps all API methods available from [RARBG TorrentAPI](https://torrentapi.org/apidocs_v2.txt).
28
+ This gem wraps all API methods available from [RARBG TorrentAPI](https://torrentapi.org/apidocs_v2.txt?&app_id=rarbg-rubygem).
29
29
 
30
- An authentication token is automatically generated on first request, stored with timestamp and renewed every 800 seconds.
30
+ An authentication token is automatically generated on the first request, stored with a timestamp and renewed every 800 seconds.
31
31
 
32
32
  Rate limit (1req/2s) is automatically enforced.
33
33
 
@@ -91,7 +91,6 @@ RARBG::CATEGORIES
91
91
  # "Movies/XVID/720" => 48,
92
92
  # "Movies/x264" => 17,
93
93
  # ...
94
- # }
95
94
  ```
96
95
 
97
96
  #### Errors
@@ -1,11 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'faraday'
4
- require 'faraday_middleware'
4
+ require 'json'
5
5
 
6
6
  # Main namespace for RARBG.
7
7
  module RARBG
8
- # Default error class for the module.
8
+ # Default error class for the module. Wraps exceptions raised at API level.
9
9
  class APIError < StandardError; end
10
10
 
11
11
  # Base class for RARBG API.
@@ -22,26 +22,39 @@ module RARBG
22
22
  # Default API rate limit (seconds).
23
23
  RATE_LIMIT = 2.1
24
24
 
25
- # @return [Faraday::Connection] the Faraday connection object.
26
- attr_reader :conn
25
+ # The underlying `Faraday::Connection` object used to perform requests.
26
+ #
27
+ # @note For more info regarding this object refer to the
28
+ # {https://www.rubydoc.info/gems/faraday/Faraday Faraday documentation}.
29
+ #
30
+ # @return [Faraday::Connection] The Faraday connection object.
31
+ attr_reader :connection
32
+
33
+ # The monotonic timestamp of the last request performed.
34
+ # Used to comply with the endpoint rate limit based on {RATE_LIMIT}.
35
+ #
36
+ # @return [Float] The monotonic timestamp of the last request performed.
37
+ attr_reader :last_request
27
38
 
28
- # @return [String] the token used for authentication.
39
+ # The token used for authentication.
40
+ # This is generated and rate limited automatically when calling {#list}
41
+ # or {#search}, but can also be generated forcefully using {#token!}.
42
+ #
43
+ # @return [String] The token used for authentication.
29
44
  attr_reader :token
30
45
 
31
- # @return [Integer] the monotonic timestamp of the token request.
46
+ # The monotonic timestamp of the token request.
47
+ # Used to compute the next required token request based on {TOKEN_EXPIRATION}.
48
+ #
49
+ # @return [Float] The monotonic timestamp of the token request.
32
50
  attr_reader :token_time
33
51
 
34
- # @return [Integer] the monotonic timestamp of the last request performed.
35
- attr_reader :last_request
36
-
37
52
  # Initialize a new instance of `RARBG::API`.
38
53
  #
39
54
  # @example
40
55
  # rarbg = RARBG::API.new
41
56
  def initialize
42
- @conn = Faraday.new(url: API_ENDPOINT) do |conn|
43
- conn.request :json
44
- conn.response :json, content_type: /\bjson$/
57
+ @connection = Faraday.new(url: API_ENDPOINT) do |conn|
45
58
  conn.response :logger if $VERBOSE
46
59
  conn.adapter Faraday.default_adapter
47
60
 
@@ -55,47 +68,54 @@ module RARBG
55
68
 
56
69
  # List torrents.
57
70
  #
71
+ # @example List last 100 ranked torrents in `Movies/x264/1080` category
72
+ # rarbg = RARBG::API.new
73
+ # rarbg.list(limit: 100, ranked: true, category: [44])
74
+ #
75
+ # @example List torrents with at least 50 seeders
76
+ # rarbg = RARBG::API.new
77
+ # rarbg.list(min_seeders: 50)
78
+ #
58
79
  # @param params [Hash] A customizable set of parameters.
59
80
  #
60
81
  # @option params [Array<Integer>] :category Filter results by category.
61
82
  # @option params [Symbol] :format Format results.
62
- # Accepted values: `:json`, `:json_extended`. Default: `:json`.
83
+ # Accepted values: `:json`, `:json_extended`.
84
+ # Default: `:json`.
63
85
  # @option params [Integer] :limit Limit results number.
64
- # Accepted values: `25`, `50`, `100`. Default: `25`.
86
+ # Accepted values: `25`, `50`, `100`.
87
+ # Default: `25`.
65
88
  # @option params [Integer] :min_seeders Filter results by minimum seeders.
66
89
  # @option params [Integer] :min_leechers Filter results by minimum leechers.
67
90
  # @option params [Boolean] :ranked Include/exclude unranked torrents.
68
91
  # Default: `true`.
69
92
  # @option params [Symbol] :sort Sort results.
70
- # Accepted values: `:last`, `:seeders`, `:leechers`. Default: `:last`.
71
- #
72
- # @return [Array<Hash>] Return torrents that match the specified parameters.
93
+ # Accepted values: `:last`, `:seeders`, `:leechers`.
94
+ # Default: `:last`.
73
95
  #
74
- # @raise [ArgumentError] Exception raised if `params` is not an `Hash`.
75
- # @raise [RARBG::APIError] Exception raised when the request fails or the
76
- # endpoint responds with an error.
77
- # @raise [Faraday::Error] Exception raised on low-level connection errors
78
- # (e.g. timeouts).
96
+ # @return [Array<Hash>] Torrents that match the specified parameters.
79
97
  #
80
- # @example List last 100 ranked torrents in `Movies/x264/1080`
81
- # rarbg = RARBG::API.new
82
- # rarbg.list(limit: 100, ranked: true, category: [44])
83
- #
84
- # @example List torrents with at least 50 seeders
85
- # rarbg = RARBG::API.new
86
- # rarbg.list(min_seeders: 50)
98
+ # @raise [ArgumentError] If `params` is not an `Hash`.
99
+ # @raise [RARBG::APIError] If the request fails or the endpoint responds
100
+ # with an error.
101
+ # @raise [Faraday::Error] On low-level connection errors (e.g. timeouts).
87
102
  def list(params = {})
88
103
  raise ArgumentError, 'Expected params hash' unless params.is_a?(Hash)
89
104
 
90
- params.update(
91
- mode: 'list',
92
- token: token?
93
- )
105
+ params.update(mode: 'list', token: token?)
94
106
  call(params)
95
107
  end
96
108
 
97
109
  # Search torrents.
98
110
  #
111
+ # @example Search by IMDb ID, sorted by leechers and in extended format.
112
+ # rarbg = RARBG::API.new
113
+ # rarbg.search(imdb: 'tt2488496', sort: :leechers, format: :json_extended)
114
+ #
115
+ # @example Search unranked torrents by string, with at least 2 seeders.
116
+ # rarbg = RARBG::API.new
117
+ # rarbg.search(string: 'Star Wars', ranked: false, min_seeders: 2)
118
+ #
99
119
  # @param params [Hash] A customizable set of parameters.
100
120
  #
101
121
  # @option params [String] :string Search by string.
@@ -104,51 +124,41 @@ module RARBG
104
124
  # @option params [String] :themoviedb Search by The Movie DB id.
105
125
  # @option params [Array<Integer>] :category Filter results by category.
106
126
  # @option params [Symbol] :format Format results.
107
- # Accepted values: `:json`, `:json_extended`. Default: `:json`.
127
+ # Accepted values: `:json`, `:json_extended`.
128
+ # Default: `:json`.
108
129
  # @option params [Integer] :limit Limit results number.
109
- # Accepted values: `25`, `50`, `100`. Default: `25`.
130
+ # Accepted values: `25`, `50`, `100`.
131
+ # Default: `25`.
110
132
  # @option params [Integer] :min_seeders Filter results by minimum seeders.
111
133
  # @option params [Integer] :min_leechers Filter results by minimum leechers.
112
134
  # @option params [Boolean] :ranked Include/exclude unranked torrents.
113
135
  # Default: `true`.
114
136
  # @option params [Symbol] :sort Sort results.
115
- # Accepted values: `:last`, `:seeders`, `:leechers`. Default: `:last`.
137
+ # Accepted values: `:last`, `:seeders`, `:leechers`.
138
+ # Default: `:last`.
116
139
  #
117
- # @return [Array<Hash>] Return torrents that match the specified parameters.
140
+ # @return [Array<Hash>] Torrents that match the specified parameters.
118
141
  #
119
- # @raise [ArgumentError] Exception raised if `params` is not an `Hash`.
120
- # @raise [ArgumentError] Exception raised if no search type param is passed
142
+ # @raise [ArgumentError] If `params` is not an `Hash`.
143
+ # @raise [ArgumentError] If no search type param is passed
121
144
  # (among `string`, `imdb`, `tvdb`, `themoviedb`).
122
- # @raise [RARBG::APIError] Exception raised when the request fails or the
123
- # endpoint responds with an error.
124
- # @raise [Faraday::Error] Exception raised on low-level connection errors
125
- # (e.g. timeouts).
126
- #
127
- # @example Search by IMDb ID, sorted by leechers and in extended format.
128
- # rarbg = RARBG::API.new
129
- # rarbg.search(imdb: 'tt2488496', sort: :leechers, format: :json_extended)
130
- #
131
- # @example Search unranked torrents by string, with at least 2 seeders.
132
- # rarbg = RARBG::API.new
133
- # rarbg.search(string: 'Star Wars', ranked: false, min_seeders: 2)
145
+ # @raise [RARBG::APIError] If the request fails or the endpoint responds
146
+ # with an error.
147
+ # @raise [Faraday::Error] On low-level connection errors (e.g. timeouts).
134
148
  def search(params = {})
135
149
  raise ArgumentError, 'Expected params hash' unless params.is_a?(Hash)
136
150
 
137
- params.update(
138
- mode: 'search',
139
- token: token?
140
- )
151
+ params.update(mode: 'search', token: token?)
141
152
  call(params)
142
153
  end
143
154
 
144
155
  # Generate the authentication token.
145
156
  #
146
- # @return [String] Return the currently valid token.
147
- #
148
157
  # @example Generate the token immediately after object instantiation.
149
158
  # rarbg = RARBG::API.new
150
159
  # rarbg.token!
151
-
160
+ #
161
+ # @return [String] The currently valid authentication token.
152
162
  def token!
153
163
  token?
154
164
  end
@@ -184,6 +194,7 @@ module RARBG
184
194
  normalize.each_pair do |key, proc|
185
195
  params[key] = proc.call(params[key]) if params.key?(key)
186
196
  end
197
+
187
198
  params
188
199
  end
189
200
 
@@ -202,6 +213,7 @@ module RARBG
202
213
  SEARCH_KEYS.each do |k|
203
214
  params["search_#{k}"] = params.delete(k) if params.key?(k)
204
215
  end
216
+
205
217
  params
206
218
  end
207
219
 
@@ -217,20 +229,22 @@ module RARBG
217
229
  # Return or renew auth token.
218
230
  def token?
219
231
  if token.nil? || time >= (token_time.to_f + TOKEN_EXPIRATION)
220
- response = request(get_token: 'get_token')
221
- @token = response.fetch('token')
232
+ response = request(get_token: 'get_token')
233
+ @token = response.fetch('token')
222
234
  @token_time = time
223
235
  end
236
+
224
237
  token
225
238
  end
226
239
 
227
240
  # Perform API request.
228
241
  def request(params)
229
242
  rate_limit!(RATE_LIMIT)
230
- response = conn.get(nil, params)
243
+
244
+ response = connection.get(nil, params)
231
245
  @last_request = time
232
246
 
233
- return response.body if response.success?
247
+ return JSON.parse(response.body) if response.success?
234
248
 
235
249
  raise APIError, "#{response.reason_phrase} (#{response.status})"
236
250
  end
@@ -2,5 +2,5 @@
2
2
 
3
3
  module RARBG
4
4
  # Gem version.
5
- VERSION = '1.4.0'
5
+ VERSION = '2.0.0'
6
6
  end
@@ -15,12 +15,6 @@ Gem::Specification.new do |spec|
15
15
  spec.homepage = 'https://github.com/epistrephein/rarbg'
16
16
  spec.license = 'MIT'
17
17
 
18
- spec.files = `git ls-files -z`.split("\x0").reject do |f|
19
- f.match(%r{^(spec|docs)/})
20
- end
21
- spec.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
22
- spec.require_path = 'lib'
23
-
24
18
  spec.metadata = {
25
19
  'bug_tracker_uri' => 'https://github.com/epistrephein/rarbg/issues',
26
20
  'changelog_uri' => 'https://github.com/epistrephein/rarbg/blob/master/CHANGELOG.md',
@@ -29,16 +23,19 @@ Gem::Specification.new do |spec|
29
23
  'source_code_uri' => 'https://github.com/epistrephein/rarbg'
30
24
  }
31
25
 
32
- spec.required_ruby_version = '>= 2.0'
26
+ spec.files = Dir['lib/**/*.rb', 'rarbg.gemspec']
27
+ spec.files += Dir['README.md', 'CHANGELOG.md', 'LICENSE']
28
+ spec.require_path = 'lib'
29
+
30
+ spec.required_ruby_version = '>= 2.3'
33
31
 
34
- spec.add_runtime_dependency 'faraday', '~> 0.12'
35
- spec.add_runtime_dependency 'faraday_middleware', '~> 0.12'
32
+ spec.add_runtime_dependency 'faraday', '~> 1.0'
36
33
 
37
34
  spec.add_development_dependency 'bundler', '>= 1.15', '< 3.0'
38
35
  spec.add_development_dependency 'pry', '~> 0.10'
39
- spec.add_development_dependency 'rake', '~> 12.0'
36
+ spec.add_development_dependency 'rake', '>= 12.0', '< 14.0'
40
37
  spec.add_development_dependency 'rspec', '~> 3.6'
41
- spec.add_development_dependency 'rubocop', '~> 0.71'
38
+ spec.add_development_dependency 'rubocop', '~> 0.71', '< 0.77'
42
39
  spec.add_development_dependency 'simplecov', '~> 0.13'
43
40
  spec.add_development_dependency 'webmock', '~> 3.0'
44
41
  spec.add_development_dependency 'yard', '~> 0.9'
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: 1.4.0
4
+ version: 2.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: 2019-06-05 00:00:00.000000000 Z
11
+ date: 2020-01-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -16,28 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.12'
19
+ version: '1.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0.12'
27
- - !ruby/object:Gem::Dependency
28
- name: faraday_middleware
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '0.12'
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '0.12'
26
+ version: '1.0'
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: bundler
43
29
  requirement: !ruby/object:Gem::Requirement
@@ -76,16 +62,22 @@ dependencies:
76
62
  name: rake
77
63
  requirement: !ruby/object:Gem::Requirement
78
64
  requirements:
79
- - - "~>"
65
+ - - ">="
80
66
  - !ruby/object:Gem::Version
81
67
  version: '12.0'
68
+ - - "<"
69
+ - !ruby/object:Gem::Version
70
+ version: '14.0'
82
71
  type: :development
83
72
  prerelease: false
84
73
  version_requirements: !ruby/object:Gem::Requirement
85
74
  requirements:
86
- - - "~>"
75
+ - - ">="
87
76
  - !ruby/object:Gem::Version
88
77
  version: '12.0'
78
+ - - "<"
79
+ - !ruby/object:Gem::Version
80
+ version: '14.0'
89
81
  - !ruby/object:Gem::Dependency
90
82
  name: rspec
91
83
  requirement: !ruby/object:Gem::Requirement
@@ -107,6 +99,9 @@ dependencies:
107
99
  - - "~>"
108
100
  - !ruby/object:Gem::Version
109
101
  version: '0.71'
102
+ - - "<"
103
+ - !ruby/object:Gem::Version
104
+ version: '0.77'
110
105
  type: :development
111
106
  prerelease: false
112
107
  version_requirements: !ruby/object:Gem::Requirement
@@ -114,6 +109,9 @@ dependencies:
114
109
  - - "~>"
115
110
  - !ruby/object:Gem::Version
116
111
  version: '0.71'
112
+ - - "<"
113
+ - !ruby/object:Gem::Version
114
+ version: '0.77'
117
115
  - !ruby/object:Gem::Dependency
118
116
  name: simplecov
119
117
  requirement: !ruby/object:Gem::Requirement
@@ -162,37 +160,14 @@ executables: []
162
160
  extensions: []
163
161
  extra_rdoc_files: []
164
162
  files:
165
- - ".editorconfig"
166
- - ".github/CODEOWNERS"
167
- - ".github/ISSUE_TEMPLATE/BUG_REPORT.md"
168
- - ".github/ISSUE_TEMPLATE/FEATURE_REQUEST.md"
169
- - ".github/PULL_REQUEST_TEMPLATE.md"
170
- - ".gitignore"
171
- - ".hound.yml"
172
- - ".rspec"
173
- - ".rubocop.yml"
174
- - ".travis.yml"
175
- - ".yardopts"
176
163
  - CHANGELOG.md
177
- - CODE_OF_CONDUCT.md
178
- - CONTRIBUTING.md
179
- - Gemfile
180
164
  - LICENSE
181
165
  - README.md
182
- - Rakefile
183
- - bin/console
184
- - bin/setup
185
166
  - lib/rarbg.rb
186
167
  - lib/rarbg/api.rb
187
168
  - lib/rarbg/categories.rb
188
169
  - lib/rarbg/version.rb
189
170
  - rarbg.gemspec
190
- - spec/rarbg/list_spec.rb
191
- - spec/rarbg/rarbg_spec.rb
192
- - spec/rarbg/search_spec.rb
193
- - spec/rarbg/token_spec.rb
194
- - spec/spec_helper.rb
195
- - spec/stubs.rb
196
171
  homepage: https://github.com/epistrephein/rarbg
197
172
  licenses:
198
173
  - MIT
@@ -210,21 +185,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
210
185
  requirements:
211
186
  - - ">="
212
187
  - !ruby/object:Gem::Version
213
- version: '2.0'
188
+ version: '2.3'
214
189
  required_rubygems_version: !ruby/object:Gem::Requirement
215
190
  requirements:
216
191
  - - ">="
217
192
  - !ruby/object:Gem::Version
218
193
  version: '0'
219
194
  requirements: []
220
- rubygems_version: 3.0.3
195
+ rubygems_version: 3.0.6
221
196
  signing_key:
222
197
  specification_version: 4
223
198
  summary: RARBG API Ruby client.
224
- test_files:
225
- - spec/rarbg/list_spec.rb
226
- - spec/rarbg/rarbg_spec.rb
227
- - spec/rarbg/search_spec.rb
228
- - spec/rarbg/token_spec.rb
229
- - spec/spec_helper.rb
230
- - spec/stubs.rb
199
+ test_files: []