url-checker 1.1.2 → 1.2.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
  SHA1:
3
- metadata.gz: 1dee2307b6ba536e8d6746743fd93fd4a493f83d
4
- data.tar.gz: f1e7aaa8199849dbb915e87ba17568390a2d5ac2
3
+ metadata.gz: a2bf165ca3d374d6e4d02d052c6cfc30d25635fe
4
+ data.tar.gz: e9566829e980c1f4ba62d9fe2edf074af5faba70
5
5
  SHA512:
6
- metadata.gz: c71406d935de3fa0f8accec18e37de3ce76588a287cf63c2c7bbba29921f8bc55b0ee8bcf0ca8648400645015575117c82ba776797265029eae02075e235fab1
7
- data.tar.gz: dd7c89e550ae86e0493795c7868c3844f389f947ef53b8986722af0e222ca5026b8639ffd0304cab80b298b5d87a8f4757253163bbfbe7e8a799cc7726c7dcb0
6
+ metadata.gz: 3e98501fccf4a9032e663d95b88a4bca92071aa3b077f9b96c0fdb077e3c6803d1b730a0397bb312b3539f7f80985eb88571937542e9e9eec02d34f2dea12017
7
+ data.tar.gz: 0cb02fb2699afa40ab8ae7ed5800499b538a84dc69184ccbe02fcdf68ab7654f03096477705b46e3f43d64f4d521cdc20654c82acf751a70d44f501ae6f107a4
data/README.md CHANGED
@@ -1,4 +1,5 @@
1
1
  [![Code Climate](https://codeclimate.com/github/HarlemSquirrel/url-checker/badges/gpa.svg)](https://codeclimate.com/github/HarlemSquirrel/url-checker)
2
+ [![Build Status](https://travis-ci.org/HarlemSquirrel/url-checker.svg?branch=master)](https://travis-ci.org/HarlemSquirrel/url-checker)
2
3
 
3
4
  # URL Checker
4
5
 
@@ -6,7 +7,7 @@ A Ruby CLI for checking a list of URLs from a CSV file. Checkout the [RubGems pa
6
7
 
7
8
  ## Requirements
8
9
 
9
- - >= Ruby 2.4.0
10
+ - Ruby 2.4+
10
11
  - Internet connection
11
12
 
12
13
  ## Getting started
@@ -1,10 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "addressable/uri"
3
+ require 'addressable/uri'
4
4
  require 'benchmark'
5
5
  require 'colorize'
6
6
  require 'csv'
7
7
  require 'net/http'
8
+ require 'openssl'
8
9
 
9
10
  require_relative '../lib/url_checker'
10
11
  require_relative '../lib/url_checker/cli'
@@ -4,7 +4,7 @@ module UrlChecker
4
4
  # The main class
5
5
  class Cli
6
6
  BAD_CALL_MSG = "Please call with one CSV file with URLs in the first column\n"
7
- RESULTS_HEADERS = %w(Response URL).freeze
7
+ RESULTS_HEADERS = %w[Response URL].freeze
8
8
 
9
9
  attr_reader :file_path, :results_file_path
10
10
 
@@ -38,11 +38,15 @@ module UrlChecker
38
38
  display_result response
39
39
  end
40
40
 
41
+ def check_url_thread(url)
42
+ Thread.new { check_url(url) }
43
+ end
44
+
41
45
  def check_urls_from_csv
42
46
  threads = []
43
47
  CSV.foreach(file_path) do |row|
44
48
  url = row[0]
45
- threads << Thread.new { check_url url } if url.match?(/\Ahttp/)
49
+ threads << check_url_thread(url) if url.is_a?(String) && url.match?(/\Ahttp/)
46
50
  end
47
51
  threads.each(&:join)
48
52
  end
@@ -53,7 +57,7 @@ module UrlChecker
53
57
  end
54
58
 
55
59
  def display_result(response)
56
- msg = " #{response.code} #{response.message} #{response.uri.to_s}\n"
60
+ msg = " #{response.code} #{response.message} #{response.uri}\n"
57
61
  case response
58
62
  when Net::HTTPSuccess, Net::HTTPRedirection
59
63
  print msg.green
@@ -6,7 +6,6 @@ module UrlChecker
6
6
  attr_reader :code, :message, :uri
7
7
 
8
8
  def initialize(code:, message:, uri:)
9
- raise TypeError, 'uri is not a URI' unless uri.is_a? Addressable::URI
10
9
  @code = code
11
10
  @message = message
12
11
  @uri = uri
@@ -3,9 +3,10 @@
3
3
  module UrlChecker
4
4
  # Checks a single URL and returns the result
5
5
  class SingleChecker
6
- SCHEMES = %w[http https]
6
+ INVALID_URI_MSG = 'must begin with http and contain only valid characters'
7
+ SCHEMES = %w[http https].freeze
7
8
 
8
- attr_reader :url_string, :uri
9
+ attr_reader :url_string
9
10
 
10
11
  def initialize(url:)
11
12
  @url_string = url
@@ -18,7 +19,6 @@ module UrlChecker
18
19
  private
19
20
 
20
21
  def check_url
21
- @uri = Addressable::URI.parse url_string
22
22
  return invalid_uri_response unless valid_url?
23
23
  response = Net::HTTP.get_response uri
24
24
  response.uri ||= uri # sometimes the uri is not set
@@ -32,7 +32,11 @@ module UrlChecker
32
32
  end
33
33
 
34
34
  def invalid_uri_response
35
- rescued_response('Invalid URL', 'URL must begin with http')
35
+ UrlChecker::RecuedResponse.new(
36
+ code: 'Invalid URL',
37
+ message: INVALID_URI_MSG,
38
+ uri: url_string
39
+ )
36
40
  end
37
41
 
38
42
  def rescued_response(code, message)
@@ -45,6 +49,12 @@ module UrlChecker
45
49
 
46
50
  def valid_url?
47
51
  SCHEMES.include? uri.scheme
52
+ rescue Addressable::URI::InvalidURIError
53
+ false
54
+ end
55
+
56
+ def uri
57
+ @uri ||= Addressable::URI.parse url_string
48
58
  end
49
59
  end
50
60
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module UrlChecker
4
- VERSION = '1.1.2'
4
+ VERSION = '1.2.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: url-checker
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin McCormack
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-18 00:00:00.000000000 Z
11
+ date: 2017-08-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 2.5.1
19
+ version: '2.5'
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: 2.5.1
26
+ version: '2.5'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: colorize
29
29
  requirement: !ruby/object:Gem::Requirement