linkey 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -1
- data/README.md +20 -13
- data/lib/linkey.rb +95 -1
- data/lib/linkey/cli.rb +2 -4
- data/lib/linkey/version.rb +1 -1
- metadata +2 -5
- data/lib/linkey/checker.rb +0 -19
- data/lib/linkey/html.rb +0 -18
- data/lib/linkey/ping.rb +0 -60
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 86d14f450e73a48c64384f8b3c25529f924de73d
|
4
|
+
data.tar.gz: 49780f9982c5a99e908c0a2f3df694792b430fa8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f03c5c58825a4e181eea31951cf6cfb1a2d3673e0ff94873e792d8e6f31b3a580dd434f83215098ab44aa9fbf4cb8d495eb881006ec557a57382133dbf428b99
|
7
|
+
data.tar.gz: 61f1aa607171502b5e761ae7c08846e50ca0821df1aa9ea3abce0d502a20d214d4a7c2bbf8c1c2c1f3d5f80bbbfbd37d34dba3c06b7c6b5a0660a5ed31fc59de
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -41,6 +41,21 @@ Once running, you'll see either a 200 with
|
|
41
41
|
or
|
42
42
|
`Status is NOT GOOD for URL`
|
43
43
|
|
44
|
+
## Script it
|
45
|
+
```ruby
|
46
|
+
require 'linkey'
|
47
|
+
|
48
|
+
url = 'http://www.live.bbc.co.uk/arabic'
|
49
|
+
base = 'http://www.live.bbc.co.uk'
|
50
|
+
reg = '/arabic'
|
51
|
+
filename = 'arabic.md'
|
52
|
+
|
53
|
+
page = Linkey::SaveLinks.new(url, filename)
|
54
|
+
status = Linkey::CheckResponse.new(url, base, reg, filename)
|
55
|
+
|
56
|
+
page.capture_links
|
57
|
+
status.check_links
|
58
|
+
```
|
44
59
|
## From a file
|
45
60
|
|
46
61
|
If you have a lot of URLs that you want to check all the time using from a file is an alternative option. This will utilise the smoke option, then point to a YAML file with the extension.
|
@@ -58,20 +73,12 @@ paths:
|
|
58
73
|
- /news/uk
|
59
74
|
```
|
60
75
|
|
61
|
-
Script it
|
62
|
-
```ruby
|
63
|
-
|
64
|
-
require 'linkey/html'
|
65
|
-
require 'linkey/ping'
|
66
76
|
|
67
|
-
|
68
|
-
base = 'http://www.live.bbc.co.uk'
|
69
|
-
reg = '/arabic'
|
70
|
-
filename = 'arabic.md'
|
77
|
+
Smoke test
|
71
78
|
|
72
|
-
|
73
|
-
|
79
|
+
```ruby
|
80
|
+
require 'linkey'
|
74
81
|
|
75
|
-
|
76
|
-
|
82
|
+
tests = Linkey::Checker.new("path/to.yaml")
|
83
|
+
tests.smoke
|
77
84
|
```
|
data/lib/linkey.rb
CHANGED
@@ -1,5 +1,99 @@
|
|
1
1
|
require "linkey/version"
|
2
|
+
require 'open-uri'
|
3
|
+
require 'yaml'
|
2
4
|
|
3
5
|
module Linkey
|
4
6
|
autoload :CLI, 'linkey/cli'
|
5
|
-
|
7
|
+
|
8
|
+
class CheckResponse
|
9
|
+
attr_accessor :url, :base, :reg, :file_name
|
10
|
+
|
11
|
+
def initialize(url, base, reg, file_name)
|
12
|
+
@url = url
|
13
|
+
@base = base
|
14
|
+
@reg = reg
|
15
|
+
@file_name = file_name
|
16
|
+
end
|
17
|
+
|
18
|
+
def check_links
|
19
|
+
array = []
|
20
|
+
links = File.read(file_name)
|
21
|
+
array << links
|
22
|
+
links(array)
|
23
|
+
end
|
24
|
+
|
25
|
+
def links(links)
|
26
|
+
links.each do |url_links|
|
27
|
+
scan(url_links)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def scan(page_links)
|
32
|
+
urls = page_links.scan(/^#{Regexp.quote(reg)}(?:|.+)?$/)
|
33
|
+
status(urls)
|
34
|
+
end
|
35
|
+
|
36
|
+
def status(urls)
|
37
|
+
@output = []
|
38
|
+
puts "Checking..."
|
39
|
+
urls.each do |page_path|
|
40
|
+
begin
|
41
|
+
gets = open(base + page_path)
|
42
|
+
status = gets.status.first
|
43
|
+
puts "Status is #{status} for #{base}#{page_path}"
|
44
|
+
rescue OpenURI::HTTPError
|
45
|
+
if status != 200
|
46
|
+
puts "Status is NOT GOOD for #{base}#{page_path}"
|
47
|
+
@output << page_path
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
check_for_broken
|
52
|
+
end
|
53
|
+
|
54
|
+
def check_for_broken
|
55
|
+
puts "Checking"
|
56
|
+
if @output.empty?
|
57
|
+
puts 'URL\'s are good, All Done!'
|
58
|
+
exit 0
|
59
|
+
else
|
60
|
+
puts 'Buddy, you got a broken link'
|
61
|
+
puts @output
|
62
|
+
exit 1
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
class SaveLinks
|
68
|
+
attr_accessor :url, :file_name
|
69
|
+
|
70
|
+
def initialize(url, file_name)
|
71
|
+
@url = url
|
72
|
+
@file_name = file_name
|
73
|
+
end
|
74
|
+
|
75
|
+
def js_file
|
76
|
+
File.expand_path('linkey/javascript/snap.js', File.dirname(__FILE__))
|
77
|
+
end
|
78
|
+
|
79
|
+
def capture_links
|
80
|
+
puts `phantomjs "#{js_file}" "#{url}" > "#{file_name}"`
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
class Checker < CheckResponse
|
85
|
+
|
86
|
+
def initialize(config)
|
87
|
+
@smoke_urls = YAML::load(File.open("#{config}"))
|
88
|
+
end
|
89
|
+
|
90
|
+
def base
|
91
|
+
@smoke_urls['base']
|
92
|
+
end
|
93
|
+
|
94
|
+
def self.smoke
|
95
|
+
urls = @smoke_urls['paths']
|
96
|
+
status(urls)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
data/lib/linkey/cli.rb
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
require 'thor'
|
2
|
-
require 'linkey
|
3
|
-
require 'linkey/ping'
|
4
|
-
require 'linkey/checker'
|
2
|
+
require 'linkey'
|
5
3
|
|
6
4
|
class Linkey::CLI < Thor
|
7
5
|
include Thor::Actions
|
@@ -18,7 +16,7 @@ class Linkey::CLI < Thor
|
|
18
16
|
status.check_links
|
19
17
|
end
|
20
18
|
|
21
|
-
desc "check URL Base_URL File", "A full linkey job"
|
19
|
+
desc "check URL Base_URL Regex File", "A full linkey job"
|
22
20
|
def check(url, base, reg, filename)
|
23
21
|
scan(url, filename)
|
24
22
|
status(url, base, reg, filename)
|
data/lib/linkey/version.rb
CHANGED
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: 0.
|
4
|
+
version: 0.3.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: 2014-
|
11
|
+
date: 2014-05-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -40,11 +40,8 @@ files:
|
|
40
40
|
- README.md
|
41
41
|
- bin/linkey
|
42
42
|
- lib/linkey.rb
|
43
|
-
- lib/linkey/checker.rb
|
44
43
|
- lib/linkey/cli.rb
|
45
|
-
- lib/linkey/html.rb
|
46
44
|
- lib/linkey/javascript/snap.js
|
47
|
-
- lib/linkey/ping.rb
|
48
45
|
- lib/linkey/version.rb
|
49
46
|
- linkey.gemspec
|
50
47
|
homepage: http://responsivenews.co.uk
|
data/lib/linkey/checker.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
require 'linkey'
|
2
|
-
require 'open-uri'
|
3
|
-
require 'yaml'
|
4
|
-
|
5
|
-
class Linkey::Checker < Linkey::CheckResponse
|
6
|
-
|
7
|
-
def initialize(config)
|
8
|
-
@smoke_urls = YAML::load(File.open("#{config}"))
|
9
|
-
end
|
10
|
-
|
11
|
-
def base
|
12
|
-
@smoke_urls['base']
|
13
|
-
end
|
14
|
-
|
15
|
-
def smoke
|
16
|
-
urls = @smoke_urls['paths']
|
17
|
-
status(urls)
|
18
|
-
end
|
19
|
-
end
|
data/lib/linkey/html.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
require 'linkey'
|
2
|
-
|
3
|
-
class Linkey::SaveLinks
|
4
|
-
attr_accessor :url, :file_name
|
5
|
-
|
6
|
-
def initialize(url, file_name)
|
7
|
-
@url = url
|
8
|
-
@file_name = file_name
|
9
|
-
end
|
10
|
-
|
11
|
-
def js_file
|
12
|
-
File.expand_path('javascript/snap.js', File.dirname(__FILE__))
|
13
|
-
end
|
14
|
-
|
15
|
-
def capture_links
|
16
|
-
puts `phantomjs "#{js_file}" "#{url}" > "#{file_name}"`
|
17
|
-
end
|
18
|
-
end
|
data/lib/linkey/ping.rb
DELETED
@@ -1,60 +0,0 @@
|
|
1
|
-
require 'linkey'
|
2
|
-
require 'open-uri'
|
3
|
-
|
4
|
-
class Linkey::CheckResponse
|
5
|
-
attr_accessor :url, :base, :reg, :file_name
|
6
|
-
|
7
|
-
def initialize(url, base, reg, file_name)
|
8
|
-
@url = url
|
9
|
-
@base = base
|
10
|
-
@reg = reg
|
11
|
-
@file_name = file_name
|
12
|
-
end
|
13
|
-
|
14
|
-
def check_links
|
15
|
-
array = []
|
16
|
-
links = File.read(file_name)
|
17
|
-
array << links
|
18
|
-
links(array)
|
19
|
-
end
|
20
|
-
|
21
|
-
def links(links)
|
22
|
-
links.each do |url_links|
|
23
|
-
scan(url_links)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def scan(page_links)
|
28
|
-
urls = page_links.scan(/^#{Regexp.quote(reg)}(?:|.+)?$/)
|
29
|
-
status(urls)
|
30
|
-
end
|
31
|
-
|
32
|
-
def status(urls)
|
33
|
-
@output = []
|
34
|
-
puts "Checking..."
|
35
|
-
urls.each do |page_path|
|
36
|
-
begin
|
37
|
-
gets = open(base + page_path)
|
38
|
-
status = gets.status.first
|
39
|
-
puts "Status is #{status} for #{base}#{page_path}"
|
40
|
-
rescue OpenURI::HTTPError
|
41
|
-
if status != 200
|
42
|
-
puts "Status is NOT GOOD for #{base}#{page_path}"
|
43
|
-
@output << page_path
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
check_for_broken
|
48
|
-
end
|
49
|
-
|
50
|
-
def check_for_broken
|
51
|
-
puts "Checking"
|
52
|
-
if @output.empty?
|
53
|
-
puts 'URL\'s are good, All Done!'
|
54
|
-
exit 0
|
55
|
-
else
|
56
|
-
puts 'Buddy, you got a broken link'
|
57
|
-
exit 1
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|