polipus 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/lib/polipus.rb +1 -1
- data/lib/polipus/http.rb +16 -14
- data/lib/polipus/version.rb +1 -1
- data/spec/polipus/http_spec.rb +5 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ac053145ab327da9f8807deb635759ebb81019f1
|
4
|
+
data.tar.gz: 4b9cbdf6a33783f9443ebe07c3c424e887c348ee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: faedd0cc2b0c085fcda3337ab52b06abb7fe9b07f51df3ecff4bedfdbd97c40df939a12e5cd52253e6006aa22862f6bb372957c9eeb2a01496089652163eeb02
|
7
|
+
data.tar.gz: c62335cefa15204d304407a2248b62faa2e29aa060bf4513e42a984cb04b32ce5f11df69025c9a9760c6c611ff976bdf78cf9e82f4b8a47d1c9927ab4afa90fc
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 0.5.1 (2015-07-17)
|
4
|
+
|
5
|
+
[Compare changes in gem](https://github.com/taganaka/polipus/compare/0.5.0...0.5.1)
|
6
|
+
|
7
|
+
* Propagate user_data values from Redis message to fetched pages
|
8
|
+
|
3
9
|
## 0.5.0 (2015-07-08)
|
4
10
|
|
5
11
|
[Compare changes in gem](https://github.com/taganaka/polipus/compare/0.4.0...0.5.0)
|
data/lib/polipus.rb
CHANGED
@@ -200,7 +200,7 @@ module Polipus
|
|
200
200
|
|
201
201
|
execute_plugin 'on_before_download'
|
202
202
|
|
203
|
-
pages = http.fetch_pages(url, page.referer, page.depth)
|
203
|
+
pages = http.fetch_pages(url, page.referer, page.depth, page.user_data)
|
204
204
|
if pages.count > 1
|
205
205
|
rurls = pages.map { |e| e.url.to_s }.join(' --> ')
|
206
206
|
@logger.info { "Got redirects! #{rurls}" }
|
data/lib/polipus/http.rb
CHANGED
@@ -35,37 +35,39 @@ module Polipus
|
|
35
35
|
# Fetch a single Page from the response of an HTTP request to *url*.
|
36
36
|
# Just gets the final destination page.
|
37
37
|
#
|
38
|
-
def fetch_page(url, referer = nil, depth = nil)
|
39
|
-
fetch_pages(url, referer, depth).last
|
38
|
+
def fetch_page(url, referer = nil, depth = nil, user_data = nil)
|
39
|
+
fetch_pages(url, referer, depth, user_data).last
|
40
40
|
end
|
41
41
|
|
42
42
|
#
|
43
43
|
# Create new Pages from the response of an HTTP request to *url*,
|
44
44
|
# including redirects
|
45
45
|
#
|
46
|
-
def fetch_pages(url, referer = nil, depth = nil)
|
46
|
+
def fetch_pages(url, referer = nil, depth = nil, user_data = nil)
|
47
47
|
url = URI(url)
|
48
48
|
pages = []
|
49
49
|
get(url, referer) do |response, code, location, redirect_to, response_time|
|
50
50
|
handle_compression response
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
51
|
+
page = Page.new(location, body: response.body,
|
52
|
+
code: code,
|
53
|
+
headers: response.to_hash,
|
54
|
+
referer: referer,
|
55
|
+
depth: depth,
|
56
|
+
redirect_to: redirect_to,
|
57
|
+
response_time: response_time,
|
58
|
+
fetched_at: Time.now.to_i)
|
59
|
+
page.user_data = user_data unless user_data.nil?
|
60
|
+
pages << page
|
59
61
|
end
|
60
|
-
|
61
62
|
pages
|
62
63
|
rescue *RESCUABLE_ERRORS => e
|
63
64
|
if verbose?
|
64
65
|
puts e.inspect
|
65
66
|
puts e.backtrace
|
66
67
|
end
|
67
|
-
|
68
|
-
|
68
|
+
page = Page.new(url, error: e, referer: referer, depth: depth)
|
69
|
+
page.user_data = user_data unless user_data.nil?
|
70
|
+
[page]
|
69
71
|
end
|
70
72
|
|
71
73
|
#
|
data/lib/polipus/version.rb
CHANGED
data/spec/polipus/http_spec.rb
CHANGED
@@ -8,11 +8,15 @@ describe Polipus::HTTP do
|
|
8
8
|
it 'should download a page' do
|
9
9
|
VCR.use_cassette('http_test') do
|
10
10
|
http = Polipus::HTTP.new
|
11
|
-
|
11
|
+
user_data = {
|
12
|
+
'mydata' => 'myvalue'
|
13
|
+
}
|
14
|
+
page = http.fetch_page('http://sfbay.craigslist.org/apa/', '', 0, user_data)
|
12
15
|
expect(page).to be_an_instance_of(Polipus::Page)
|
13
16
|
expect(page.doc.search('title').text.strip).to eq 'SF bay area apts/housing for rent classifieds - craigslist'
|
14
17
|
expect(page.fetched_at).not_to be_nil
|
15
18
|
expect(page.fetched?).to be_truthy
|
19
|
+
expect(page.user_data).to eq user_data
|
16
20
|
end
|
17
21
|
end
|
18
22
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: polipus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Francesco Laurita
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-07-
|
11
|
+
date: 2015-07-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -385,3 +385,4 @@ test_files:
|
|
385
385
|
- spec/polipus/url_tracker_spec.rb
|
386
386
|
- spec/polipus_spec.rb
|
387
387
|
- spec/spec_helper.rb
|
388
|
+
has_rdoc:
|