linkey 1.3.0 → 1.4.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: 7cf7d38db7c5c755398ed59a5523d7d33051e1d8
4
- data.tar.gz: 8b4751d3e83b5021b1a794b99e7389d51003f960
3
+ metadata.gz: aecb337d1fc6a5912ddbfdb8d5ab85571680eb19
4
+ data.tar.gz: 7f3e4c32377465f87300ef4324e3fa9612c4b836
5
5
  SHA512:
6
- metadata.gz: 6c9780f42a16f54e4f9c5a272e72ecd5b3d0fe798e834ec1d9722709f533e965e4a9e5a8d338df667334d07bd7e630d14b1434e14bdac343a0a03f125cbbc181
7
- data.tar.gz: 4dea5a21089542399ae016d129ca922fb9ed36071a404d2b1d78f12187aa8927e3fc0070b0c8690d97de64ab11c5529605a3143c246a897f2c7bd336194895d5
6
+ metadata.gz: 749aa652254f43d038ca1199d8b8a4107612a0381847b38c0b33e451185d355cd30f0b2f66ff95fc6924687b3f836ae69c47874d1a872ac3e4834b1dc92a48b0
7
+ data.tar.gz: 36b71fc3fa9d8e7c3f83d796a511da1a21884b8f42495804e9a5cff80c1c11ad6dd4d456c782392b99e79c1e663634ce473ceff2ccc6b400960b70aa548b7508
@@ -28,7 +28,7 @@ module Linkey
28
28
 
29
29
  def scan(page_links)
30
30
  urls = page_links.scan(/^#{Regexp.quote(reg)}(?:|.+)?$/)
31
- Getter.status(urls, base)
31
+ Getter.new(urls, base).check
32
32
  end
33
33
  end
34
34
 
@@ -63,63 +63,87 @@ module Linkey
63
63
  options = @smoke_urls["headers"]
64
64
  headers = Hash[*options]
65
65
  @smoke_urls["status_code"] ? status_code = @smoke_urls["status_code"] : status_code = 200
66
- Getter.status(urls, base, { :headers => headers }, status_code)
66
+ Getter.new(urls, base, { :headers => headers }, status_code).check
67
67
  end
68
68
  end
69
69
 
70
70
  class Getter
71
- HYDRA = Typhoeus::Hydra.new(:max_concurrency => 100)
71
+ def initialize(paths, base, headers = {}, status = 200)
72
+ @paths = paths
73
+ @base = base
74
+ @headers = headers
75
+ @status = status
76
+ end
72
77
 
73
- def self.status(urls, base, headers = {}, status_code = 200)
74
- @output = []
78
+ def check
75
79
  puts "Checking..."
76
80
 
77
- options = { :followlocation => true, :ssl_verifypeer => false, :headers => headers[:headers] }
78
-
79
- requests = urls.map do |page_paths|
81
+ paths.each do |path|
80
82
  begin
81
- request = Typhoeus::Request.new(base + page_paths, options)
82
- HYDRA.queue(request)
83
- request
83
+ Typhoeus::Request.new(url(path), options).tap do |req|
84
+ req.on_complete { |r| parse_response(r, status) }
85
+ HYDRA.queue req
86
+ end
84
87
  rescue
85
- puts "Error with URL #{page_paths}, please check config"
88
+ puts "Error with URL #{path}, please check config"
86
89
  end
87
90
  end
88
91
 
89
92
  HYDRA.run
90
-
91
- requests.map do |request|
92
- begin
93
- status = request.response.code
94
- url = request.response.options[:effective_url]
95
- make_request(url, status, status_code)
96
- rescue
97
- puts "Unable to get status code"
98
- end
99
- end
100
-
101
93
  check_for_broken
102
94
  end
103
95
 
104
- def self.make_request(url, status, status_code)
105
- if status != status_code
106
- puts "Status is NOT GOOD for #{url}, response is #{status}"
107
- @output << url
108
- else
109
- puts "Status is #{status} for #{url}"
110
- end
111
- end
96
+ private
112
97
 
113
- def self.check_for_broken
98
+ attr_reader :base, :headers, :paths, :status
99
+
100
+ HYDRA = Typhoeus::Hydra.new(:max_concurrency => 100)
101
+
102
+ def check_for_broken
114
103
  puts "Checking"
115
- if @output.empty?
104
+ if output.empty?
116
105
  puts 'URL\'s are good, All Done!'
117
106
  exit 0
118
107
  else
119
108
  puts "Buddy, you got a bad link"
120
- puts @output
109
+ puts output
121
110
  exit 1
122
111
  end
123
112
  end
113
+
114
+ def make_request(url, status, status_code)
115
+ if status != status_code
116
+ puts "Status is NOT GOOD for #{url}, response is #{status}"
117
+ output << url
118
+ else
119
+ puts "Status is #{status} for #{url}"
120
+ end
121
+ end
122
+
123
+ def options
124
+ {
125
+ :followlocation => true,
126
+ :ssl_verifypeer => false,
127
+ :headers => headers[:headers]
128
+ }
129
+ end
130
+
131
+ def output
132
+ @output ||= []
133
+ end
134
+
135
+ def parse_response(resp, status)
136
+ make_request(
137
+ resp.options[:effective_url],
138
+ resp.code,
139
+ status
140
+ )
141
+ rescue
142
+ puts "Unable to get status code"
143
+ end
144
+
145
+ def url(path)
146
+ "#{base}#{path}"
147
+ end
124
148
  end
125
149
  end
@@ -1,3 +1,3 @@
1
1
  module Linkey
2
- VERSION = "1.3.0"
2
+ VERSION = "1.4.0"
3
3
  end
@@ -19,4 +19,6 @@ Gem::Specification.new do |spec|
19
19
 
20
20
  spec.add_runtime_dependency "thor"
21
21
  spec.add_runtime_dependency "typhoeus"
22
+
23
+ spec.add_development_dependency "pry"
22
24
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: linkey
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dave Blooman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-18 00:00:00.000000000 Z
11
+ date: 2015-02-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  description: Linkey
42
56
  email:
43
57
  - david.blooman@gmail.com