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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/sitemap-parser.rb +13 -8
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5cf7f24d9633d44bd80514db606dafa869de8e8a
4
- data.tar.gz: 5dc60886285798683a43f21e81f44f7afdbafc19
3
+ metadata.gz: 2fa6305d37f26f50d25958b2ed0dc3583c2981f6
4
+ data.tar.gz: 6396cedcddfb8a8f7e130d48b5ef9807fb1bf417
5
5
  SHA512:
6
- metadata.gz: 07241173a5e14eb552827d48b75a3caa27c5b40f1e3eaf39db588a7009d1c8f65b7c302072eef7d9e6a9ce6bce0b7ad94ec36130039a42640d159e8ddcea140f
7
- data.tar.gz: c3a5d2fa4b2e182eb0b335cb04ba65839d213690fad73f12d3055b85e2ad10da5133aa88fa6baab304576dd0d04fd870de793c1b73c849f08cfaaf691f90b238
6
+ metadata.gz: 2cdb21d278b7f3956dd311c1bdfe858c73f55406152f5c8b41cb56bf96ebb728ec9f8fc4bcaa44f6b35cff26066d518505b39f5b99d5369f58c4cefef423dbf7
7
+ data.tar.gz: ab3455e3efcabe7b8e06068484f548dfa0e2472e8176fd208577b087f19f28a2577d86e09b59d38f63dbdf16d5148a646a0869705a13623887808d41889745d7
@@ -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
- request = Typhoeus::Request.new(@url, followlocation: true)
13
- request.on_complete do |response|
14
- if response.success?
15
- return response.body
16
- else
17
- return nil
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.1.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-04 00:00:00.000000000 Z
11
+ date: 2014-03-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri