diff --git a/.hound.yml b/.hound.yml index 432d63d..daf72ed 100644 --- a/.hound.yml +++ b/.hound.yml @@ -2,4 +2,4 @@ fail_on_violations: true rubocop: config_file: .rubocop.yml - version: 0.71.0 + version: 0.75.0 diff --git a/.rubocop.yml b/.rubocop.yml index 7a9d738..35673c1 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -3,9 +3,6 @@ AllCops: DisplayCopNames: true DisplayStyleGuide: true -Gemspec/RequiredRubyVersion: - Enabled: false - Layout/AlignHash: EnforcedHashRocketStyle: table EnforcedColonStyle: table diff --git a/.travis.yml b/.travis.yml index c187a50..3761421 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,5 @@ --- language: ruby -sudo: false script: bundle exec rspec rvm: - ruby-head diff --git a/CHANGELOG.md b/CHANGELOG.md index 71ceb4c..80ff3f8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/). [Diff](https://github.com/epistrephein/rarbg/compare/v1.4.0...master) #### Changed +- Update Faraday to v1.0 and drop `faraday_middleware` dependency ([#17](https://github.com/epistrephein/rarbg/pull/17)). +- Update Ruby minimum version to 2.3 ([#17](https://github.com/epistrephein/rarbg/pull/17)). - Rename attr_reader `conn` to `connection` ([#18](https://github.com/epistrephein/rarbg/pull/18)). - Remove unnecessary files and attributes from gemspec ([#21](https://github.com/epistrephein/rarbg/pull/21)). - Update version constraints for Rake, following v13.0 release ([#15](https://github.com/epistrephein/rarbg/pull/15)). diff --git a/README.md b/README.md index 126d850..d9b0517 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ gem 'rarbg', '~> 1.4' This gem wraps all API methods available from [RARBG TorrentAPI](https://torrentapi.org/apidocs_v2.txt?&app_id=rarbg-rubygem). -An authentication token is automatically generated on first request, stored with timestamp and renewed every 800 seconds. +An authentication token is automatically generated on the first request, stored with a timestamp and renewed every 800 seconds. Rate limit (1req/2s) is automatically enforced. diff --git a/lib/rarbg/api.rb b/lib/rarbg/api.rb index 38cb1fc..8ffdd74 100644 --- a/lib/rarbg/api.rb +++ b/lib/rarbg/api.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true require 'faraday' -require 'faraday_middleware' +require 'json' # Main namespace for RARBG. module RARBG @@ -55,8 +55,6 @@ class API # rarbg = RARBG::API.new def initialize @connection = Faraday.new(url: API_ENDPOINT) do |conn| - conn.request :json - conn.response :json, content_type: /\bjson$/ conn.response :logger if $VERBOSE conn.adapter Faraday.default_adapter @@ -104,10 +102,7 @@ def initialize def list(params = {}) raise ArgumentError, 'Expected params hash' unless params.is_a?(Hash) - params.update( - mode: 'list', - token: token? - ) + params.update(mode: 'list', token: token?) call(params) end @@ -153,10 +148,7 @@ def list(params = {}) def search(params = {}) raise ArgumentError, 'Expected params hash' unless params.is_a?(Hash) - params.update( - mode: 'search', - token: token? - ) + params.update(mode: 'search', token: token?) call(params) end @@ -202,6 +194,7 @@ def validate(params) normalize.each_pair do |key, proc| params[key] = proc.call(params[key]) if params.key?(key) end + params end @@ -220,6 +213,7 @@ def validate_search!(params) SEARCH_KEYS.each do |k| params["search_#{k}"] = params.delete(k) if params.key?(k) end + params end @@ -235,20 +229,22 @@ def normalize # Return or renew auth token. def token? if token.nil? || time >= (token_time.to_f + TOKEN_EXPIRATION) - response = request(get_token: 'get_token') - @token = response.fetch('token') + response = request(get_token: 'get_token') + @token = response.fetch('token') @token_time = time end + token end # Perform API request. def request(params) rate_limit!(RATE_LIMIT) - response = connection.get(nil, params) + + response = connection.get(nil, params) @last_request = time - return response.body if response.success? + return JSON.parse(response.body) if response.success? raise APIError, "#{response.reason_phrase} (#{response.status})" end diff --git a/rarbg.gemspec b/rarbg.gemspec index 9d4eb3d..be60add 100644 --- a/rarbg.gemspec +++ b/rarbg.gemspec @@ -27,10 +27,9 @@ Gem::Specification.new do |spec| spec.files += Dir['README.md', 'CHANGELOG.md', 'LICENSE'] spec.require_path = 'lib' - spec.required_ruby_version = '>= 2.0' + spec.required_ruby_version = '>= 2.3' - spec.add_runtime_dependency 'faraday', '~> 0.12' - spec.add_runtime_dependency 'faraday_middleware', '~> 0.12' + spec.add_runtime_dependency 'faraday', '~> 1.0' spec.add_development_dependency 'bundler', '>= 1.15', '< 3.0' spec.add_development_dependency 'pry', '~> 0.10'