tiny_http_parser 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -1
- data/lib/tiny_http_parser/fetcher_base.rb +7 -11
- data/lib/tiny_http_parser/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 641084bffe174f3a2c5849ee9cdc916e875d4598
|
4
|
+
data.tar.gz: c1ee6d0fea9f1ceb1693b75e1ab701020ba37936
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c62f28dbb03e571a542b73e700ecf2c03499f1c618cf441435f0715b0367a24c4de933b6ad4945c1f7422fedb6fb7040b69fafb686c63e9ef92f4dbc2466a514
|
7
|
+
data.tar.gz: feb7bd9028ddbd8caff72b5058009080e9a9e0d07af3368aadd3d7824c535cdc26c34fb11740f7f5d766a3ad5f62c16b2d46d864990fa976bab01e5a15f9497a
|
data/README.md
CHANGED
@@ -18,6 +18,7 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
## Usage
|
20
20
|
|
21
|
+
```ruby
|
21
22
|
require 'tiny_parser'
|
22
23
|
|
23
24
|
fetcher = FetcherFromEnum.new ['http://ya.ru','http://google.com']
|
@@ -30,7 +31,7 @@ fetcher.on_exception_raised do |e|
|
|
30
31
|
end
|
31
32
|
|
32
33
|
fetcher.perform
|
33
|
-
|
34
|
+
```
|
34
35
|
## Contributing
|
35
36
|
|
36
37
|
1. Fork it ( https://github.com/[my-github-username]/tiny_http_parser/fork )
|
@@ -1,4 +1,5 @@
|
|
1
|
-
require 'httpclient'
|
1
|
+
# require 'httpclient'
|
2
|
+
require 'faraday'
|
2
3
|
class FetcherBase
|
3
4
|
|
4
5
|
def initialize
|
@@ -21,8 +22,8 @@ class FetcherBase
|
|
21
22
|
raise 'abstract method called exception'
|
22
23
|
end
|
23
24
|
|
24
|
-
def
|
25
|
-
@
|
25
|
+
def on_action &block
|
26
|
+
@on_action = block if block_given?
|
26
27
|
end
|
27
28
|
|
28
29
|
def configure &block
|
@@ -35,21 +36,16 @@ class FetcherBase
|
|
35
36
|
|
36
37
|
def perform
|
37
38
|
before_start if defined? before_start
|
38
|
-
raise 'no
|
39
|
-
http_client =
|
40
|
-
http_client = HTTPClient.new(get_proxy) if proxy_set?
|
39
|
+
raise 'no on_action block given' unless @on_action
|
40
|
+
http_client = Faraday.new
|
41
41
|
while true do
|
42
42
|
url = parse_url
|
43
43
|
break unless url
|
44
|
-
content_block.call(http_client) if @configure_block
|
45
44
|
begin
|
46
|
-
|
45
|
+
@on_action.call url, http_client
|
47
46
|
rescue Exception => e
|
48
47
|
@exception_raised_block.call(e,url,http_client) if @exception_raised_block
|
49
|
-
else
|
50
|
-
@content_block.call url, content, http_client
|
51
48
|
end
|
52
|
-
http_client = HTTPClient.new(get_proxy) if proxy_set?
|
53
49
|
end
|
54
50
|
end
|
55
51
|
end
|