Skip to content

Commit

Permalink
Fix some errors, update README
Browse files Browse the repository at this point in the history
  • Loading branch information
nbulaj committed Dec 8, 2017
1 parent 2ebe4a5 commit f619182
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 10 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ validating proxy lists from the different providers. [Checkout examples](#standa

## Table of Contents

- [Dependencies](#dependencies)
- [Installation](#installation)
- [Example of usage](#example-of-usage)
- [In Ruby application](#in-ruby-application)
Expand All @@ -29,6 +30,18 @@ validating proxy lists from the different providers. [Checkout examples](#standa
- [Contributing](#contributing)
- [License](#license)

## Dependencies

ProxyFetcher gem itself requires only Ruby `>= 2.0.0`.

However, it requires an adapter to parse HTML. If you do not specify any specific adapter, then it will use
default one - [Nokogiri](https://github.com/sparklemotion/nokogiri). It's OK for any Ruby on Rails project
(because they uses it by default).

But if you want to use some specific adapter (for example your Ruby application uses [Oga](https://gitlab.com/yorickpeterse/oga),
then you need to manually add your dependencies to your project and configure ProxyFetcher to use another adapter. Moreover,
you can implement your own adapter if it your use-case. Take a look at the [Configuration](#configuration) section for more details.

## Installation

If using bundler, first add 'proxy_fetcher' to your Gemfile:
Expand Down
2 changes: 1 addition & 1 deletion lib/proxy_fetcher/document/adapters/abstract_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def proxy_node
def self.setup!(*args)
install_requirements!(*args)
rescue LoadError => error
raise Exceptions::AdapterSetupError.new(self.class.name, error.message)
raise Exceptions::AdapterSetupError.new(name, error.message)
end
end
end
Expand Down
8 changes: 2 additions & 6 deletions lib/proxy_fetcher/exceptions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def initialize(*)

class AdapterSetupError < Error
def initialize(adapter_name, reason)
adapter = demodulize(adapter_name.remove('Adapter'))
adapter = demodulize(adapter_name.gsub('Adapter', ''))

super("can't setup '#{adapter}' adapter during the following error:\n\t#{reason}'")
end
Expand All @@ -62,11 +62,7 @@ def demodulize(path)
path = path.to_s
index = path.rindex('::')

if index
path[(index + 2)..-1]
else
path
end
index ? path[(index + 2)..-1] : path
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion proxy_fetcher.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ require 'proxy_fetcher/version'
Gem::Specification.new do |gem|
gem.name = 'proxy_fetcher'
gem.version = ProxyFetcher.gem_version
gem.date = '2017-12-05'
gem.date = '2017-12-08'
gem.summary = 'Ruby gem for dealing with proxy lists from different providers'
gem.description = 'This gem can help your Ruby application to make HTTP(S) requests ' \
'using proxies by fetching and validating proxy lists from the different providers.'
Expand Down
21 changes: 19 additions & 2 deletions spec/proxy_fetcher/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,33 @@ def self.connectable?(*)
end

context 'custom provider' do
it 'failed on registration if provider class already registered' do
it 'fails on registration if provider class already registered' do
expect { ProxyFetcher::Configuration.register_provider(:xroxy, Class.new) }
.to raise_error(ProxyFetcher::Exceptions::RegisteredProvider)
end

it "failed on proxy list fetching if provider doesn't registered" do
it "fails on proxy list fetching if provider doesn't registered" do
ProxyFetcher.config.provider = :not_existing_provider

expect { ProxyFetcher::Manager.new }
.to raise_error(ProxyFetcher::Exceptions::UnknownProvider)
end
end

context 'custom HTML parsing adapter' do
it "fails if adapter can't be installed" do
old_config = ProxyFetcher.config.dup

class CustomAdapter < ProxyFetcher::Document::AbstractAdapter
def self.install_requirements!
require 'not_existing_gem'
end
end

expect { ProxyFetcher.config.adapter = CustomAdapter }
.to raise_error(ProxyFetcher::Exceptions::AdapterSetupError)

ProxyFetcher.instance_variable_set('@config', old_config)
end
end
end

0 comments on commit f619182

Please sign in to comment.