rarbg 1.2.0 → 1.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6ae0fc9cbd49bc0297737148b66e9c08164e1ebb4e0e1e7237d0e0c3385d4165
4
- data.tar.gz: 76ae543821aa6204da813588d4020bfaf8d9f0462f88cea1c7e8299ee9b84fac
3
+ metadata.gz: 5bdc20e4ab04f39d219c9144799d7ffddba69c0dd316c1ed41d239e286967714
4
+ data.tar.gz: ebe32eb45fcd60fb2d21f78c7d3ea1c3115875e36039f82c7f6b29643f4cc4f4
5
5
  SHA512:
6
- metadata.gz: c486d18f7621cfa1aa6305145dda201e60c5a05a4c53637efe68908efcb296adb7094af575ab77253c6286098269a1daaa5561ad140d9274a40786de9ebe2c50
7
- data.tar.gz: f1974c700b3f66ec529e123a92ae8619fca9c9f014f9a7b7d6d3381b0aa95890e05f70706f3e20a62bacaa677a0b758cab3885a634e300a24fdc634310640f95
6
+ metadata.gz: 2ad332920510625f62afb67c6f81eb016f8c2f2654ee34ac5669b5c282925fb098b6b31bdcf6bcfcebc10aa6067883814c8b863b479ea22d252e818ad2dc0eb7
7
+ data.tar.gz: e1e2e06a31ad858b5ab4c4fa7f92e326d69add29e5e88fae6c28e707132b472e89bd6c2bc4d040351bb93a32c46beb174f0749a5973aae18a89b267969fb61bb
@@ -0,0 +1,5 @@
1
+ fail_on_violations: true
2
+
3
+ rubocop:
4
+ config_file: .rubocop.yml
5
+ version: 0.59.2
@@ -13,6 +13,12 @@ Layout/AlignHash:
13
13
  Layout/FirstParameterIndentation:
14
14
  EnforcedStyle: consistent
15
15
 
16
+ Layout/IndentArray:
17
+ EnforcedStyle: consistent
18
+
19
+ Layout/IndentHash:
20
+ EnforcedStyle: consistent
21
+
16
22
  Metrics/BlockLength:
17
23
  Exclude:
18
24
  - '*.gemspec'
@@ -20,6 +26,9 @@ Metrics/BlockLength:
20
26
  - 'describe'
21
27
  - 'context'
22
28
 
29
+ Metrics/ClassLength:
30
+ Enabled: false
31
+
23
32
  Metrics/LineLength:
24
33
  Max: 90
25
34
 
@@ -3,7 +3,7 @@ language: ruby
3
3
  cache: bundler
4
4
  script: bundle exec rspec
5
5
  rvm:
6
- - 2.6.0
6
+ - 2.6.1
7
7
  - 2.5.3
8
8
  - 2.4.5
9
9
  - 2.3.8
@@ -4,6 +4,25 @@ 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
+ ## 1.3.0 - 2019-02-07
8
+ [RubyGems](https://rubygems.org/gems/rarbg/versions/1.3.0) |
9
+ [Release](https://github.com/epistrephein/rarbg/releases/tag/v1.3.0) |
10
+ [Diff](https://github.com/epistrephein/rarbg/compare/v1.2.0...v1.3.0)
11
+
12
+ #### Fixed
13
+ - Return an empty array when endpoint responds with a `Can't find` error on
14
+ `imdb`/`themoviedb`/`tvdb` search ([#6](https://github.com/epistrephein/rarbg/pull/6)).
15
+ - Parse JSON only for responses with `application/json` Content-Type, preventing
16
+ error responses to raise a `ParsingError` ([#4](https://github.com/epistrephein/rarbg/pull/4)).
17
+
18
+ #### Added
19
+ - Add `token!` public method for standalone token generation
20
+ ([#3](https://github.com/epistrephein/rarbg/pull/3)).
21
+
22
+ #### Changed
23
+ - Reduce Faraday connection timeout to 30 seconds.
24
+
25
+
7
26
  ## 1.2.0 - 2019-01-02
8
27
  [RubyGems](https://rubygems.org/gems/rarbg/versions/1.2.0) |
9
28
  [Release](https://github.com/epistrephein/rarbg/releases/tag/v1.2.0) |
@@ -48,7 +48,8 @@ changes with `rake spec`.
48
48
 
49
49
  We also use [RuboCop](https://docs.rubocop.org/en/latest/) to enforce code style.
50
50
  The configuration file used for this project lives in `.rubocop.yml`. You can check
51
- the code style of your changes with `rake rubocop`.
51
+ the code style of your changes with `rake rubocop`.
52
+ Pull Requests on GitHub are automatically linted with RuboCop via [Hound](https://houndci.com/).
52
53
 
53
54
  The default Rake task, runnable using `rake`, performs code linting via Rubocop
54
55
  and then runs the RSpec tests.
data/README.md CHANGED
@@ -20,7 +20,7 @@ $ gem install rarbg
20
20
  Or add it to your Gemfile and execute `bundle install`
21
21
 
22
22
  ```ruby
23
- gem 'rarbg', '~> 1.2'
23
+ gem 'rarbg', '~> 1.3'
24
24
  ```
25
25
 
26
26
  ## Usage
@@ -31,6 +31,8 @@ An authentication token is automatically generated on first request, stored with
31
31
 
32
32
  Rate limit (1req/2s) is automatically enforced.
33
33
 
34
+ Check out the [full documentation](https://epistrephein.github.io/rarbg) for details on all methods and parameters.
35
+
34
36
  #### Getting started
35
37
 
36
38
  Require the gem and initialize a new `RARBG::API` object.
@@ -7,10 +7,10 @@ require 'rarbg/api'
7
7
  # Module namespace shortcut methods.
8
8
  module RARBG
9
9
  class << self
10
- %i[list search].each do |m|
11
- define_method(m) do |*args|
10
+ %i[list search token!].each do |method|
11
+ define_method(method) do |*args|
12
12
  @rarbg ||= RARBG::API.new
13
- @rarbg.send(m, *args)
13
+ @rarbg.send(method, *args)
14
14
  end
15
15
  end
16
16
  end
@@ -38,6 +38,13 @@ module RARBG
38
38
  SEARCH_KEYS = %w[string imdb tvdb themoviedb].freeze
39
39
  private_constant :SEARCH_KEYS
40
40
 
41
+ # Endpoint error strings to return as no results.
42
+ NO_RESULTS_ERRORS_REGEXPS = Regexp.union([
43
+ /no results found/i,
44
+ /can'?t find .+? in database/i
45
+ ])
46
+ private_constant :NO_RESULTS_ERRORS_REGEXPS
47
+
41
48
  # Initialize a new instance of `RARBG::API`.
42
49
  #
43
50
  # @example
@@ -45,11 +52,11 @@ module RARBG
45
52
  def initialize
46
53
  @conn = Faraday.new(url: API_ENDPOINT) do |conn|
47
54
  conn.request :json
48
- conn.response :json
55
+ conn.response :json, content_type: /\bjson$/
49
56
  conn.response :logger if $VERBOSE
50
57
  conn.adapter Faraday.default_adapter
51
58
 
52
- conn.options.timeout = 90
59
+ conn.options.timeout = 30
53
60
  conn.options.open_timeout = 10
54
61
 
55
62
  conn.headers[:user_agent] = APP_ID
@@ -63,22 +70,23 @@ module RARBG
63
70
  #
64
71
  # @option params [Array<Integer>] :category Filter results by category.
65
72
  # @option params [Symbol] :format Format results.
66
- # Valid values: `:json`, `:json_extended`. Default: `:json`.
73
+ # Accepted values: `:json`, `:json_extended`. Default: `:json`.
67
74
  # @option params [Integer] :limit Limit results number.
68
- # Valid values: `25`, `50`, `100`. Default: `25`.
75
+ # Accepted values: `25`, `50`, `100`. Default: `25`.
69
76
  # @option params [Integer] :min_seeders Filter results by minimum seeders.
70
77
  # @option params [Integer] :min_leechers Filter results by minimum leechers.
71
78
  # @option params [Boolean] :ranked Include/exclude unranked torrents.
72
79
  # Default: `true`.
73
80
  # @option params [Symbol] :sort Sort results.
74
- # Valid values: `:last`, `:seeders`, `:leechers`. Default: `:last`.
81
+ # Accepted values: `:last`, `:seeders`, `:leechers`. Default: `:last`.
75
82
  #
76
83
  # @return [Array<Hash>] Return torrents that match the specified parameters.
77
84
  #
78
85
  # @raise [ArgumentError] Exception raised if `params` is not an `Hash`.
79
- # @raise [RARBG::APIError] Exception raised when request fails or endpoint
80
- # responds with an error.
81
- # @raise [Faraday::Error] Exception raised on low-level connection errors.
86
+ # @raise [RARBG::APIError] Exception raised when the request fails or the
87
+ # endpoint responds with an error.
88
+ # @raise [Faraday::Error] Exception raised on low-level connection errors
89
+ # (e.g. timeouts).
82
90
  #
83
91
  # @example List last 100 ranked torrents in `Movies/x264/1080`
84
92
  # rarbg = RARBG::API.new
@@ -107,24 +115,25 @@ module RARBG
107
115
  # @option params [String] :themoviedb Search by The Movie DB id.
108
116
  # @option params [Array<Integer>] :category Filter results by category.
109
117
  # @option params [Symbol] :format Format results.
110
- # Valid values: `:json`, `:json_extended`. Default: `:json`.
118
+ # Accepted values: `:json`, `:json_extended`. Default: `:json`.
111
119
  # @option params [Integer] :limit Limit results number.
112
- # Valid values: `25`, `50`, `100`. Default: `25`.
120
+ # Accepted values: `25`, `50`, `100`. Default: `25`.
113
121
  # @option params [Integer] :min_seeders Filter results by minimum seeders.
114
122
  # @option params [Integer] :min_leechers Filter results by minimum leechers.
115
123
  # @option params [Boolean] :ranked Include/exclude unranked torrents.
116
124
  # Default: `true`.
117
125
  # @option params [Symbol] :sort Sort results.
118
- # Valid values: `:last`, `:seeders`, `:leechers`. Default: `:last`.
126
+ # Accepted values: `:last`, `:seeders`, `:leechers`. Default: `:last`.
119
127
  #
120
128
  # @return [Array<Hash>] Return torrents that match the specified parameters.
121
129
  #
122
130
  # @raise [ArgumentError] Exception raised if `params` is not an `Hash`.
123
131
  # @raise [ArgumentError] Exception raised if no search type param is passed
124
132
  # (among `string`, `imdb`, `tvdb`, `themoviedb`).
125
- # @raise [RARBG::APIError] Exception raised when request fails or endpoint
126
- # responds with an error.
127
- # @raise [Faraday::Error] Exception raised on low-level connection errors.
133
+ # @raise [RARBG::APIError] Exception raised when the request fails or the
134
+ # endpoint responds with an error.
135
+ # @raise [Faraday::Error] Exception raised on low-level connection errors
136
+ # (e.g. timeouts).
128
137
  #
129
138
  # @example Search by IMDb ID, sorted by leechers and in extended format.
130
139
  # rarbg = RARBG::API.new
@@ -143,13 +152,25 @@ module RARBG
143
152
  call(params)
144
153
  end
145
154
 
155
+ # Generate the authentication token.
156
+ #
157
+ # @return [String] Return the currently valid token.
158
+ #
159
+ # @example Generate the token immediately after object instantiation.
160
+ # rarbg = RARBG::API.new
161
+ # rarbg.token!
162
+
163
+ def token!
164
+ token?
165
+ end
166
+
146
167
  private
147
168
 
148
169
  # Wrap requests for error handling.
149
170
  def call(params)
150
171
  response = request(validate(params))
151
172
 
152
- return [] if response['error'] == 'No results found'
173
+ return [] if response['error'] =~ NO_RESULTS_ERRORS_REGEXPS
153
174
  raise APIError, response['error'] if response.key?('error')
154
175
 
155
176
  response.fetch('torrent_results', [])
@@ -2,5 +2,5 @@
2
2
 
3
3
  module RARBG
4
4
  # Gem version.
5
- VERSION = '1.2.0'
5
+ VERSION = '1.3.0'
6
6
  end
@@ -52,6 +52,21 @@ RSpec.describe 'RARBG::API#search' do
52
52
  end
53
53
  end
54
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
+
55
70
  context 'when search request parameters is not an hash' do
56
71
  before(:example) do
57
72
  stub_search(
@@ -51,4 +51,26 @@ RSpec.describe RARBG::API do
51
51
  expect { @rarbg.list }.to raise_error(Faraday::ConnectionFailed)
52
52
  end
53
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
54
76
  end
@@ -1,12 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # WebMock stubs for RSpec.
3
4
  module Stubs
4
5
  API_ENDPOINT = RARBG::API::API_ENDPOINT
5
6
 
6
7
  def stub_token(token)
7
8
  stub_request(:get, API_ENDPOINT)
8
9
  .with(query: hash_including('get_token' => 'get_token'))
9
- .to_return(status: 200, body: { token: token }.to_json)
10
+ .to_return(status: 200, body: { token: token }.to_json,
11
+ headers: { 'Content-Type' => 'application/json' })
10
12
  end
11
13
 
12
14
  def stub_list(token, params = {}, result = {})
@@ -15,7 +17,8 @@ module Stubs
15
17
  mode: 'list',
16
18
  token: token
17
19
  )))
18
- .to_return(status: 200, body: result.to_json)
20
+ .to_return(status: 200, body: result.to_json,
21
+ headers: { 'Content-Type' => 'application/json' })
19
22
  end
20
23
 
21
24
  def stub_search(token, params = {}, result = {})
@@ -24,7 +27,8 @@ module Stubs
24
27
  mode: 'search',
25
28
  token: token
26
29
  )))
27
- .to_return(status: 200, body: result.to_json)
30
+ .to_return(status: 200, body: result.to_json,
31
+ headers: { 'Content-Type' => 'application/json' })
28
32
  end
29
33
 
30
34
  def stub_error(status, error)
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.2.0
4
+ version: 1.3.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-01-02 00:00:00.000000000 Z
11
+ date: 2019-02-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -162,6 +162,7 @@ files:
162
162
  - ".github/ISSUE_TEMPLATE/FEATURE_REQUEST.md"
163
163
  - ".github/PULL_REQUEST_TEMPLATE.md"
164
164
  - ".gitignore"
165
+ - ".hound.yml"
165
166
  - ".rspec"
166
167
  - ".rubocop.yml"
167
168
  - ".travis.yml"