Browse files

Merge pull request #208 from spodlecki/removing-httpclient

Remove httpclient due to deprecation warning for #timeout
  • Loading branch information...
2 parents aae4292 + 14794f8 commit 6e551927ec29cf82f56dd0f6a558c254b5faad63 @johnmcaliley johnmcaliley committed Feb 3, 2016
Showing with 21 additions and 11 deletions.
  1. +1 −1 .travis.yml
  2. +3 −0 gemfiles/rails32.gemfile
  3. +3 −0 gemfiles/rails40.gemfile
  4. +0 −2 impressionist.gemspec
  5. +11 −8 lib/impressionist/bots.rb
  6. +3 −0 tests/test_app/Gemfile
View
2 .travis.yml
@@ -2,7 +2,7 @@ language: ruby
before_script:
- cd tests/test_app
- bundle exec rails g impressionist -f
- - bundle exec rake db:migrate
+ - bundle exec rake db:create db:migrate RAILS_ENV=test
- cd ..
rvm:
- 1.9.3
View
3 gemfiles/rails32.gemfile
@@ -22,6 +22,9 @@ group :test do
gem 'simplecov'
gem 'systemu'
gem 'friendly_id', '~> 4.0.9'
+
+ # test/unit has been removed by default in Ruby 2.2.x+
+ gem 'test-unit'
end
gemspec :path => '../'
View
3 gemfiles/rails40.gemfile
@@ -22,6 +22,9 @@ group :test do
gem 'simplecov'
gem 'systemu'
gem 'friendly_id', '~> 5.1.0'
+
+ # test/unit has been removed by default in Ruby 2.2.x+
+ gem 'test-unit'
end
gemspec :path => '../'
View
2 impressionist.gemspec
@@ -18,8 +18,6 @@ Gem::Specification.new do |s|
s.require_path = 'lib'
s.required_rubygems_version = Gem::Requirement.new('>= 1.3.6') if s.respond_to? :required_rubygems_version=
- s.add_dependency 'httpclient', '~> 2.2'
s.add_dependency 'nokogiri', '~> 1.6'
-
s.add_development_dependency 'bundler', '~> 1.0'
end
View
19 lib/impressionist/bots.rb
@@ -1,18 +1,21 @@
-require 'httpclient'
+require 'timeout'
+require 'net/http'
require 'nokogiri'
module Impressionist
module Bots
LIST_URL = "http://www.user-agents.org/allagents.xml"
def self.consume
- response = HTTPClient.new.get_content(LIST_URL)
- doc = Nokogiri::XML(response)
- list = []
- doc.xpath('//user-agent').each do |agent|
- type = agent.xpath("Type").text
- list << agent.xpath("String").text.gsub("&lt;","<") if ["R","S"].include?(type) #gsub hack for badly formatted data
+ Timeout.timeout(4) do
+ response = Net::HTTP.get(URI.parse(LIST_URL))
+ doc = Nokogiri::XML(response)
+ list = []
+ doc.xpath('//user-agent').each do |agent|
+ type = agent.xpath("Type").text
+ list << agent.xpath("String").text.gsub("&lt;","<") if ["R","S"].include?(type) #gsub hack for badly formatted data
+ end
+ list
end
- list
end
end
end
View
3 tests/test_app/Gemfile
@@ -36,6 +36,9 @@ group :development, :test do
gem 'autotest-notification'
gem 'rspec-rails', '~> 2.14.0'
gem 'spork'
+
+ # test/unit has been removed by default in Ruby 2.2.x+
+ gem 'test-unit'
end
group :test do

0 comments on commit 6e55192

Please sign in to comment.