Skip to content

Commit 2dbedda

Browse files
committed
--proxy
1 parent 1842908 commit 2dbedda

File tree

6 files changed

+24
-3
lines changed

6 files changed

+24
-3
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,9 @@ noko.css("table")[4].css("td").select { |i| i[:width].to_i > 80 }.map(&:text)
175175

176176
#### (unreleased)
177177

178-
* Added support for `--limit` and `xml`
178+
* Support for `--limit`, `--proxy` and the `xml` variable
179179
* Dedup - warn and ignore if row[:url] has already been emitted
180+
* Auto gunzip if contents are compressed
180181

181182
#### 2.0.1 (May 2018)
182183

bin/sinew

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ options = Slop.parse do |o|
1515
o.bool '-q', '--quiet', 'suppress some output'
1616
o.integer '-l', '--limit', 'quit after emitting this many rows'
1717
o.string '-c', '--cache', 'set custom cache directory', default: "#{ENV['HOME']}/.sinew"
18+
o.string '--proxy', 'use host[:port] as HTTP proxy'
1819
o.bool '--version', 'show version and exit'
1920
o.on('--help', 'show this help') do
2021
puts o

lib/sinew/main.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ def initialize(options)
1515
@runtime_options = RuntimeOptions.new
1616
@request_tm = Time.at(0)
1717
@request_count = 0
18+
19+
if options[:proxy]
20+
addr, port = options[:proxy].split(':')
21+
runtime_options.httparty_options[:http_proxyaddr] = addr
22+
runtime_options.httparty_options[:http_proxyport] = port || 80
23+
end
1824
end
1925

2026
def run

lib/sinew/request.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ def initialize(sinew, method, url, options = {})
2828
def perform
2929
validate!
3030

31-
# merge global/options headers
31+
# merge optons
32+
options = self.options.merge(sinew.runtime_options.httparty_options)
33+
34+
# merge headers
3235
headers = sinew.runtime_options.headers
3336
headers = headers.merge(options[:headers]) if options[:headers]
3437
options[:headers] = headers

lib/sinew/runtime_options.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ class RuntimeOptions
77
attr_accessor :retries
88
attr_accessor :rate_limit
99
attr_accessor :headers
10+
attr_accessor :httparty_options
1011
attr_accessor :before_generate_cache_key
1112

1213
def initialize
@@ -15,6 +16,7 @@ def initialize
1516
self.headers = {
1617
'User-Agent' => "sinew/#{VERSION}",
1718
}
19+
self.httparty_options = {}
1820
self.before_generate_cache_key = ->(i) { i }
1921

2022
# for testing

sample.sinew

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,9 @@
1-
get 'https://postmates.com/sitemap/sitemap_all_merchants_latest.xml.gz'
1+
get 'http://httpbin.org'
2+
noko.css('ul li a').each do |a|
3+
row = {}
4+
row[:url] = a[:href]
5+
row[:title] = a.text
6+
csv_emit(row)
7+
end
8+
9+
get 'http://httpbin.org/redirect/2'

0 commit comments

Comments
 (0)