curl 0.0.6 → 0.0.7
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.
Potentially problematic release.
This version of curl might be problematic. Click here for more details.
- data/lib/curl.rb +24 -12
- metadata +3 -3
data/lib/curl.rb
CHANGED
@@ -33,14 +33,18 @@ class CURL
|
|
33
33
|
|
34
34
|
def initialize(keys={})
|
35
35
|
@cache = ( keys[:cache] ? keys[:cache] : false )
|
36
|
+
@cache_time = ( keys[:cache_time] ? keys[:cache_time] : 3600*24*1 ) # 1 day cache life
|
37
|
+
@connect_timeout = keys[:connect_timeout] || 6
|
38
|
+
@max_time = keys[:max_time] || 8
|
39
|
+
@retry = keys[:retry] || 1
|
36
40
|
@cookies_enable = ( keys[:cookies_disable] ? false : true )
|
37
41
|
@user_agent = AGENT_ALIASES["Google"]#AGENT_ALIASES[AGENT_ALIASES.keys[rand(6)]]
|
38
42
|
FileUtils.makedirs("/tmp/curl/")
|
39
43
|
@cookies_file = keys[:cookies] || "/tmp/curl/curl_#{rand}_#{rand}.jar"
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
+
# @cookies_file = "/home/ruslan/curl.jar"
|
45
|
+
#--header "Accept-Encoding: deflate"
|
46
|
+
# @setup_params = ' --header "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" --header "Accept-Language: en-us,en;q=0.5" --header "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7" '
|
47
|
+
@setup_params = ' --connect-timeout #{@connect_timeout} --max-time #{@max_time} --retry #{@retry} --location --compressed --silent -k '
|
44
48
|
# @setup_params = ' --location --silent '
|
45
49
|
yield self if block_given?
|
46
50
|
end
|
@@ -92,12 +96,16 @@ class CURL
|
|
92
96
|
cache_path(url)+"/#{Digest::MD5.hexdigest(url)}.html"
|
93
97
|
end
|
94
98
|
|
95
|
-
def get(url,
|
99
|
+
def get(url, keys={})
|
100
|
+
ref = keys[:ref] ||= nil
|
101
|
+
count = keys[:count] ||= 3
|
102
|
+
encoding = keys[:encoding] ||= "utf-8"
|
103
|
+
|
96
104
|
if @cache
|
97
105
|
filename = cache_file(url)
|
98
|
-
unless File.exists?(filename)
|
106
|
+
unless File.exists?(filename) && (File.exists?(filename) && File.ctime(filename) > Time.now-@cache_time)
|
99
107
|
FileUtils.mkdir_p(cache_path(url))
|
100
|
-
result = get_raw(url,count,ref) #+" --output \"#{filename}\" ")
|
108
|
+
result = get_raw(url, {:count=>count, :ref=>ref, :encoding=>encoding} ) #+" --output \"#{filename}\" ")
|
101
109
|
puts "cache to file '#{filename}'" if @debug
|
102
110
|
File.open(filename,"w"){|f| f.puts result}
|
103
111
|
return result
|
@@ -106,13 +114,17 @@ class CURL
|
|
106
114
|
return open(filename).read
|
107
115
|
end
|
108
116
|
else
|
109
|
-
return get_raw(url,count,ref)
|
117
|
+
return get_raw(url, {:count=>count , :ref=>ref, :encoding=>encoding})
|
110
118
|
end
|
111
119
|
|
112
120
|
end
|
113
121
|
|
114
|
-
def get_raw(url,
|
115
|
-
|
122
|
+
def get_raw(url, keys={})
|
123
|
+
ref = keys[:ref] ||= nil
|
124
|
+
count = keys[:count] ||= 3
|
125
|
+
encoding = keys[:encoding] ||= "utf-8"
|
126
|
+
|
127
|
+
cmd = "curl #{cookies_store} #{browser_type} #{@setup_params} #{ref} \"#{url}\" "
|
116
128
|
if @debug
|
117
129
|
puts cmd.red
|
118
130
|
end
|
@@ -122,8 +134,8 @@ class CURL
|
|
122
134
|
count -= 1
|
123
135
|
result = self.get(url,count) if count > 0
|
124
136
|
end
|
125
|
-
result.
|
126
|
-
|
137
|
+
result.force_encoding(encoding)
|
138
|
+
( encoding=="utf-8" ? result.clean : Iconv.new("UTF-8", "WINDOWS-1251").iconv(result) )
|
127
139
|
end
|
128
140
|
|
129
141
|
# формат данных для поста
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 7
|
9
|
+
version: 0.0.7
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- tg0
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-
|
17
|
+
date: 2010-12-07 00:00:00 +02:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|