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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5e96ab8c59be65fdcffbbfe438034e1be3b1a0cd
4
- data.tar.gz: 1cbad9d0f4e0e5c52ff744a0dad9ddc9a0a6142f
3
+ metadata.gz: 86d14f450e73a48c64384f8b3c25529f924de73d
4
+ data.tar.gz: 49780f9982c5a99e908c0a2f3df694792b430fa8
5
5
  SHA512:
6
- metadata.gz: 83963de13343fe98bd2325436d1fe57e8ad392199dea6023da4869e8abc43fc6f5576eb2bec4fb1f5e43fbaa8d2e4cdc3b261e79a2567be5639301eec04c2338
7
- data.tar.gz: 661d450cd63434c01a64ad259fb327e6af67f0d2e60448af29f35a95692bfb483401df2d8093615af6ccdee6dbe2ca6be62aa4f629c4be6e49abce969962f270
6
+ metadata.gz: f03c5c58825a4e181eea31951cf6cfb1a2d3673e0ff94873e792d8e6f31b3a580dd434f83215098ab44aa9fbf4cb8d495eb881006ec557a57382133dbf428b99
7
+ data.tar.gz: 61f1aa607171502b5e761ae7c08846e50ca0821df1aa9ea3abce0d502a20d214d4a7c2bbf8c1c2c1f3d5f80bbbfbd37d34dba3c06b7c6b5a0660a5ed31fc59de
@@ -2,7 +2,7 @@ language: ruby
2
2
  rvm:
3
3
  - "2.0.0"
4
4
 
5
- script: "./bin/linkey check http://www.live.bbc.co.uk/news http://www.live.bbc.co.uk /news news.md"
5
+ script: "bundle exec bin/linkey check http://www.bbc.com/news http://www.bbc.com /news news.md"
6
6
 
7
7
  notifications:
8
8
  email:
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
- url = 'http://www.live.bbc.co.uk/arabic'
68
- base = 'http://www.live.bbc.co.uk'
69
- reg = '/arabic'
70
- filename = 'arabic.md'
77
+ Smoke test
71
78
 
72
- page = Linkey::SaveLinks.new(url, filename)
73
- status = Linkey::CheckResponse.new(url, base, reg, filename)
79
+ ```ruby
80
+ require 'linkey'
74
81
 
75
- page.capture_links
76
- status.check_links
82
+ tests = Linkey::Checker.new("path/to.yaml")
83
+ tests.smoke
77
84
  ```
@@ -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
- end
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
@@ -1,7 +1,5 @@
1
1
  require 'thor'
2
- require 'linkey/html'
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)
@@ -1,3 +1,3 @@
1
1
  module Linkey
2
- VERSION = '0.2.0'
2
+ VERSION = '0.3.0'
3
3
  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: 0.2.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-03-24 00:00:00.000000000 Z
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
@@ -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
@@ -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
@@ -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