curl 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of curl might be problematic. Click here for more details.

Files changed (3) hide show
  1. data/lib/curl.rb +39 -27
  2. data/lib/string_cleaner.rb +1 -1
  3. metadata +4 -20
@@ -32,6 +32,7 @@ class CURL
32
32
  attr_accessor :user_agent
33
33
 
34
34
  def initialize(keys={})
35
+ @socks_hostname = keys[:socks_hostname] ||= false
35
36
  @cache = ( keys[:cache] ? keys[:cache] : false )
36
37
  @cache_time = ( keys[:cache_time] ? keys[:cache_time] : 3600*24*1 ) # 1 day cache life
37
38
  @connect_timeout = keys[:connect_timeout] || 6
@@ -65,10 +66,11 @@ class CURL
65
66
  end
66
67
 
67
68
  def socks(socks_uri)
68
- socks = ( socks_uri.is_a?(URI) ? socks_uri : URI.parse("http://#{socks_uri}") )
69
- @setup_params = "#{@setup_params} --socks5-hostname \"#{socks.host}:#{socks.port}\" "
70
- @setup_params = "#{@setup_params} --proxy-user \"#{socks.user}:#{socks.password}\" " if socks.user
71
- @setup_params
69
+ socks = ( socks_uri.is_a?(URI) ? socks_uri : URI.parse("http://#{socks_uri}") )
70
+ s = @socks_hostname ? "--socks5-hostname" : "--socks5"
71
+ @setup_params = "#{@setup_params} #{s} \"#{socks.host}:#{socks.port}\" "
72
+ @setup_params = "#{@setup_params} --proxy-user \"#{socks.user}:#{socks.password}\" " if socks.user
73
+ @setup_params
72
74
  end
73
75
 
74
76
  def self.check(proxy)
@@ -100,6 +102,7 @@ class CURL
100
102
  ref = keys[:ref] ||= nil
101
103
  count = keys[:count] ||= 3
102
104
  encoding = keys[:encoding] ||= "utf-8"
105
+ raw = ( keys[:raw]==nil ? false : keys[:raw] )
103
106
 
104
107
  if @cache
105
108
  filename = cache_file(url)
@@ -114,7 +117,7 @@ class CURL
114
117
  return open(filename).read
115
118
  end
116
119
  else
117
- return get_raw(url, {:count=>count , :ref=>ref, :encoding=>encoding})
120
+ return get_raw(url, {:count=>count , :ref=>ref, :encoding=>encoding, :raw=>raw})
118
121
  end
119
122
 
120
123
  end
@@ -123,6 +126,7 @@ class CURL
123
126
  ref = keys[:ref] ||= nil
124
127
  count = keys[:count] ||= 3
125
128
  encoding = keys[:encoding] ||= "utf-8"
129
+ raw = ( keys[:raw]==nil ? false : keys[:raw] )
126
130
 
127
131
  cmd = "curl #{cookies_store} #{browser_type} #{@setup_params} #{ref} \"#{url}\" "
128
132
  if @debug
@@ -134,8 +138,13 @@ class CURL
134
138
  count -= 1
135
139
  result = self.get(url,count) if count > 0
136
140
  end
137
- result.force_encoding(encoding)
138
- ( encoding=="utf-8" ? result.clean : Iconv.new("UTF-8", "WINDOWS-1251").iconv(result) )
141
+ # result.force_encoding(encoding)
142
+ if raw
143
+ return result
144
+ else
145
+ return ( encoding=="utf-8" ? result.clean : Iconv.new("UTF-8", "WINDOWS-1251").iconv(result) )
146
+ end
147
+
139
148
  end
140
149
 
141
150
  # формат данных для поста
@@ -175,26 +184,29 @@ class CURL
175
184
  # }
176
185
  def send(url,post_data, ref = nil,count=5 )
177
186
 
178
- post_q = '' # " -F \"method\"=\"post\" "
179
- post_data.each do |key,val|
180
- pre = ""
181
- if key
182
- pre = "@" if key.scan("file").size>0 or key.scan("photo").size>0
183
- val = val.gsub('"','\"')
184
- post_q += " -F \"#{key}\"=#{pre}\"#{val}\" "
185
- end
186
- end
187
-
188
- cmd = "curl #{cookies_store} #{browser_type} #{post_q} #{@setup_params} #{ref} \"#{url}\" "
189
- puts cmd.red if @debug
190
-
191
- result = open_pipe(cmd)
192
- #if result.to_s.strip.size == 0
193
- # puts "empty result, left #{count} try".yellow if @debug
194
- # count -= 1
195
- # result = self.send(url,post_data,nil,count) if count > 0
196
- #end
197
- result
187
+ post_q = '' # " -F \"method\"=\"post\" "
188
+ post_data.each do |key,val|
189
+ pre = ""
190
+ if key
191
+ key = key.to_s
192
+ pre = "@" if key.scan("file").size>0 or key.scan("photo").size>0 or key.scan("@").size>0
193
+ key = key.to_s.gsub("@",'')
194
+ val = val.to_s
195
+ val = val.gsub('"','\"')
196
+ post_q += " -F \"#{key}\"=#{pre}\"#{val}\" "
197
+ end
198
+ end
199
+
200
+ cmd = "curl #{cookies_store} #{browser_type} #{post_q} #{@setup_params} #{ref} \"#{url}\" "
201
+ puts cmd.red if @debug
202
+
203
+ result = open_pipe(cmd)
204
+ #if result.to_s.strip.size == 0
205
+ # puts "empty result, left #{count} try".yellow if @debug
206
+ # count -= 1
207
+ # result = self.send(url,post_data,nil,count) if count > 0
208
+ #end
209
+ result
198
210
  end
199
211
 
200
212
 
@@ -178,4 +178,4 @@ module String::Cleaner
178
178
  end
179
179
  class String
180
180
  include String::Cleaner
181
- end
181
+ end
metadata CHANGED
@@ -1,12 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: curl
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 0
8
- - 8
9
- version: 0.0.8
4
+ prerelease:
5
+ version: 0.0.9
10
6
  platform: ruby
11
7
  authors:
12
8
  - tg0
@@ -14,7 +10,7 @@ autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
12
 
17
- date: 2010-12-07 00:00:00 +02:00
13
+ date: 2011-03-10 00:00:00 +02:00
18
14
  default_executable:
19
15
  dependencies:
20
16
  - !ruby/object:Gem::Dependency
@@ -25,10 +21,6 @@ dependencies:
25
21
  requirements:
26
22
  - - ">="
27
23
  - !ruby/object:Gem::Version
28
- segments:
29
- - 0
30
- - 2
31
- - 1
32
24
  version: 0.2.1
33
25
  type: :runtime
34
26
  version_requirements: *id001
@@ -40,10 +32,6 @@ dependencies:
40
32
  requirements:
41
33
  - - ">="
42
34
  - !ruby/object:Gem::Version
43
- segments:
44
- - 1
45
- - 1
46
- - 1
47
35
  version: 1.1.1
48
36
  type: :runtime
49
37
  version_requirements: *id002
@@ -74,21 +62,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
74
62
  requirements:
75
63
  - - ">="
76
64
  - !ruby/object:Gem::Version
77
- segments:
78
- - 0
79
65
  version: "0"
80
66
  required_rubygems_version: !ruby/object:Gem::Requirement
81
67
  none: false
82
68
  requirements:
83
69
  - - ">="
84
70
  - !ruby/object:Gem::Version
85
- segments:
86
- - 0
87
71
  version: "0"
88
72
  requirements: []
89
73
 
90
74
  rubyforge_project: curl
91
- rubygems_version: 1.3.7
75
+ rubygems_version: 1.5.2
92
76
  signing_key:
93
77
  specification_version: 3
94
78
  summary: shell CURL ruby wrapper.