tiny_http_parser 0.0.1 → 0.0.2
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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 94ad9fb242a775a1deb3b2c0b0a959a40ab87e56
|
4
|
+
data.tar.gz: 14aee4f270796bfddfc418a6050f0643e1758922
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 64d768d5f3bde08ec3d41906266709d07246f10044c49d5b43d4158bf0c8c7dd1ea6d4f5d8303633a4d6db41eca0b41e6848253763ea03e9007f0a23d32b5554
|
7
|
+
data.tar.gz: ce889124e1005b0fa1aa704ef216ff53e9cc2491a1ba9a9ae6f9bba359d7f1fa8afa38ca76cadb292ca25fa4166bdd80b5c57e6619cadd9f5939d744b3da69fb
|
data/README.md
CHANGED
@@ -21,7 +21,7 @@ Or install it yourself as:
|
|
21
21
|
require 'tiny_parser'
|
22
22
|
|
23
23
|
fetcher = FetcherFromEnum.new ['http://ya.ru','http://google.com']
|
24
|
-
fetcher.on_content_get do |content|
|
24
|
+
fetcher.on_content_get do |url, content, http_client|
|
25
25
|
puts '[+]'+ content.slice(0, 10)
|
26
26
|
end
|
27
27
|
|
data/lib/tiny_http_parser.rb
CHANGED
@@ -2,6 +2,7 @@ require "tiny_http_parser/version"
|
|
2
2
|
require 'tiny_http_parser/fetcher_base'
|
3
3
|
require 'tiny_http_parser/fetcher_from_enum'
|
4
4
|
require 'tiny_http_parser/proxy_circular_list'
|
5
|
+
require 'tiny_http_parser/repeatable_element'
|
5
6
|
|
6
7
|
module TinyHttpParser
|
7
8
|
# Your code goes here...
|
@@ -34,6 +34,7 @@ class FetcherBase
|
|
34
34
|
end
|
35
35
|
|
36
36
|
def perform
|
37
|
+
before_start if defined? before_start
|
37
38
|
raise 'no on_content_get block given' unless @content_block
|
38
39
|
http_client = HTTPClient.new
|
39
40
|
http_client = HTTPClient.new(get_proxy) if proxy_set?
|
@@ -46,7 +47,7 @@ class FetcherBase
|
|
46
47
|
rescue Exception => e
|
47
48
|
@exception_raised_block.call(e,url,http_client) if @exception_raised_block
|
48
49
|
else
|
49
|
-
@content_block.call content
|
50
|
+
@content_block.call url, content, http_client
|
50
51
|
end
|
51
52
|
http_client = HTTPClient.new(get_proxy) if proxy_set?
|
52
53
|
end
|
@@ -3,15 +3,12 @@ require_relative 'fetcher_base'
|
|
3
3
|
class FetcherFromEnum < FetcherBase
|
4
4
|
|
5
5
|
def initialize enumerable
|
6
|
-
@
|
7
|
-
@counter = 0
|
6
|
+
@data = RepeatableElement.new enumerable
|
8
7
|
end
|
9
8
|
|
10
9
|
def parse_url
|
11
|
-
return nil
|
12
|
-
|
13
|
-
@counter += 1
|
14
|
-
result
|
10
|
+
return nil unless item = @data.next
|
11
|
+
item
|
15
12
|
end
|
16
13
|
|
17
14
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
class RepeatableElement
|
2
|
+
|
3
|
+
@max_get = 3
|
4
|
+
|
5
|
+
def initialize elements
|
6
|
+
@elements = elements.map {|e| [e, 0] }
|
7
|
+
@index = 0
|
8
|
+
end
|
9
|
+
|
10
|
+
def next
|
11
|
+
reorganize_elements if @index >= @elements.length
|
12
|
+
return nil if @elements.length == 0
|
13
|
+
result = @elements[@index][0]
|
14
|
+
@elements[@index][1] += 1
|
15
|
+
@index +=1
|
16
|
+
result
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def reorganize_elements
|
22
|
+
@index = 0
|
23
|
+
@elements = []
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tiny_http_parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- gingray
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-01-
|
11
|
+
date: 2015-01-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -83,6 +83,7 @@ files:
|
|
83
83
|
- lib/tiny_http_parser/fetcher_base.rb
|
84
84
|
- lib/tiny_http_parser/fetcher_from_enum.rb
|
85
85
|
- lib/tiny_http_parser/proxy_circular_list.rb
|
86
|
+
- lib/tiny_http_parser/repeatable_element.rb
|
86
87
|
- lib/tiny_http_parser/version.rb
|
87
88
|
- tiny_http_parser.gemspec
|
88
89
|
homepage: ''
|