upton 0.2.8 → 0.2.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/upton.rb +14 -3
- data/spec/upton_spec.rb +18 -0
- 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: d9de3851524b4f26a558ad8400edf24d6bc39b49
|
4
|
+
data.tar.gz: 3183dc8c0f75a659722354e3b58f72ce1b55661d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8372d26f5f55208c657331b8778d22da42a61d437625b73bda5e85d757c6eb255ef128f47ced6bd2cc7a1cb65b3616cd7d4b93d3c443499786b0e1bef8c8cca6
|
7
|
+
data.tar.gz: b3e6c479b6b03e82dab3164cab8d27b88b7fa935e7e9d58317df6a11c7af3d419c65b7205133a3240f78e8cadc31d096fabd6ee57610ba5d552fbcea21d52e4a
|
data/lib/upton.rb
CHANGED
@@ -111,8 +111,9 @@ module Upton
|
|
111
111
|
|
112
112
|
# Folder name for stashes, if you want them to be stored somewhere else,
|
113
113
|
# e.g. under /tmp.
|
114
|
-
@stash_folder
|
115
|
-
|
114
|
+
if @stash_folder
|
115
|
+
FileUtils.mkdir_p(@stash_folder) unless Dir.exists?(@stash_folder)
|
116
|
+
end
|
116
117
|
end
|
117
118
|
|
118
119
|
##
|
@@ -207,7 +208,17 @@ module Upton
|
|
207
208
|
##
|
208
209
|
def get_page(url, stash=false, options={})
|
209
210
|
return EMPTY_STRING if url.empty?
|
210
|
-
|
211
|
+
global_options = {
|
212
|
+
:cache => stash,
|
213
|
+
:verbose => @verbose
|
214
|
+
}
|
215
|
+
if @stash_folder
|
216
|
+
global_options.merge!({
|
217
|
+
:cache_location => @stash_folder,
|
218
|
+
:readable_filenames => true
|
219
|
+
})
|
220
|
+
end
|
221
|
+
resp_and_cache = Downloader.new(url, global_options.merge(options)).get
|
211
222
|
if resp_and_cache[:from_resource]
|
212
223
|
puts "sleeping #{@sleep_time_between_requests} secs" if @verbose
|
213
224
|
sleep @sleep_time_between_requests
|
data/spec/upton_spec.rb
CHANGED
@@ -170,11 +170,29 @@ describe Upton do
|
|
170
170
|
it "should sleep after uncached requests" do
|
171
171
|
stub_request(:get, "www.example.com")
|
172
172
|
u = Upton::Scraper.new("http://www.example.com", '.whatever')
|
173
|
+
u.sleep_time_between_requests = 1 #don't sleep too long, that's annoying.
|
173
174
|
u.should_receive(:sleep)
|
174
175
|
stub = stub_request(:get, "http://www.example.com")
|
175
176
|
u.scrape
|
176
177
|
end
|
177
178
|
|
179
|
+
it "should save to the designated stash folder" do
|
180
|
+
custom_cache_folder = "#{Dir.tmpdir}/upton/test"
|
181
|
+
FileUtils.rm_rf(custom_cache_folder)
|
182
|
+
stub_request(:get, "www.example.com").
|
183
|
+
to_return(:body => '', :status => 200)
|
184
|
+
|
185
|
+
u = Upton::Scraper.new("http://www.example.com", '.whatever')
|
186
|
+
u.stash_folder = custom_cache_folder
|
187
|
+
u.debug = true
|
188
|
+
u.scrape do
|
189
|
+
1+1
|
190
|
+
end
|
191
|
+
puts [custom_cache_folder, custom_cache_folder + "/*", Dir.glob(custom_cache_folder)].inspect
|
192
|
+
files = Dir.glob(custom_cache_folder)
|
193
|
+
expect(files).not_to be_empty
|
194
|
+
end
|
195
|
+
|
178
196
|
it "should be silent if verbose if false" do
|
179
197
|
pending
|
180
198
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: upton
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeremy B. Merrill
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-10-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|