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 +4 -4
- data/README.md +2 -1
- data/config/environment.rb +2 -1
- data/lib/url_checker/cli.rb +7 -3
- data/lib/url_checker/rescued_response.rb +0 -1
- data/lib/url_checker/single_checker.rb +14 -4
- data/lib/url_checker/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a2bf165ca3d374d6e4d02d052c6cfc30d25635fe
|
4
|
+
data.tar.gz: e9566829e980c1f4ba62d9fe2edf074af5faba70
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
-
|
10
|
+
- Ruby 2.4+
|
10
11
|
- Internet connection
|
11
12
|
|
12
13
|
## Getting started
|
data/config/environment.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
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'
|
data/lib/url_checker/cli.rb
CHANGED
@@ -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
|
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 <<
|
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
|
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
|
@@ -3,9 +3,10 @@
|
|
3
3
|
module UrlChecker
|
4
4
|
# Checks a single URL and returns the result
|
5
5
|
class SingleChecker
|
6
|
-
|
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
|
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
|
-
|
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
|
data/lib/url_checker/version.rb
CHANGED
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.
|
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-
|
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
|
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
|
26
|
+
version: '2.5'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: colorize
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|