sitemap-parser 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/sitemap-parser.rb +13 -8
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2fa6305d37f26f50d25958b2ed0dc3583c2981f6
|
4
|
+
data.tar.gz: 6396cedcddfb8a8f7e130d48b5ef9807fb1bf417
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2cdb21d278b7f3956dd311c1bdfe858c73f55406152f5c8b41cb56bf96ebb728ec9f8fc4bcaa44f6b35cff26066d518505b39f5b99d5369f58c4cefef423dbf7
|
7
|
+
data.tar.gz: ab3455e3efcabe7b8e06068484f548dfa0e2472e8176fd208577b087f19f28a2577d86e09b59d38f63dbdf16d5148a646a0869705a13623887808d41889745d7
|
data/lib/sitemap-parser.rb
CHANGED
@@ -3,21 +3,26 @@ require 'typhoeus'
|
|
3
3
|
|
4
4
|
class SitemapParser
|
5
5
|
|
6
|
-
def initialize(url)
|
6
|
+
def initialize(url, opts = {})
|
7
7
|
@url = url
|
8
|
+
@options = {:followlocation => true}.merge(opts)
|
8
9
|
end
|
9
10
|
|
10
11
|
def raw_sitemap
|
11
12
|
@raw_sitemap ||= begin
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
13
|
+
if @url =~ /\Ahttp/i
|
14
|
+
request = Typhoeus::Request.new(@url, followlocation: @options[:followlocation])
|
15
|
+
request.on_complete do |response|
|
16
|
+
if response.success?
|
17
|
+
return response.body
|
18
|
+
else
|
19
|
+
return nil
|
20
|
+
end
|
18
21
|
end
|
22
|
+
request.run
|
23
|
+
elsif File.exist?(@url) && @url =~ /[\\\/]sitemap\.xml\Z/i
|
24
|
+
open(@url) { |f| f.read }
|
19
25
|
end
|
20
|
-
request.run
|
21
26
|
end
|
22
27
|
end
|
23
28
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sitemap-parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Balter
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-03-
|
11
|
+
date: 2014-03-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|