rhack 1.2.8 → 1.2.9

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: 59733c3e455fc7bc060d4d5aaa5c72d867902175
4
- data.tar.gz: 0b5ba10c17f10d1a61abdd54b2825b997aa33ae5
3
+ metadata.gz: c9a23976006b8b0d6d4f852d88ee3a22c53ae383
4
+ data.tar.gz: 0845633001556509c181211fbe2f08246a66d3d4
5
5
  SHA512:
6
- metadata.gz: 6e2ac91fcc005974dbf5ede8276398197b60bee078a00f058f2d96f50e6cc22106bf9a18593aaaadddb8fd21555cdce05eb556563a5add4f86bfc1c94a01a897
7
- data.tar.gz: 8d02020626a8cc572dc700208b885f0c29e1dade67d62a2f80decffc28a07ecd359e56741b4acc086f37a3204ba657125d7dff348732f520cd5766316b0bea3d
6
+ metadata.gz: d01df2fffd1955bdfc118529a86ab8937225a5c5f8d528738fc823f2a2bb347b4a364c3c610bca079f63bccca6a2d1eb8a5988b3cd7ecb9cbc45e8fd347e0804
7
+ data.tar.gz: 3e2ee98e26b2a6e2d47e45375ab337284a495ccf9cc4e2c7a643c9c45fecfb6b732ad794ce145a13fe94d635847b682f851fd46be098d8df4efae58b65e33184
data/lib/rhack/frame.rb CHANGED
@@ -31,7 +31,7 @@ module RHACK
31
31
  #if scouts = (opts[:scouts] || opts[:threads])
32
32
  # args[-1] = scouts
33
33
  #end
34
- opts = args.find_by_class Hash
34
+ opts = args.find_by_class(Hash) || {}
35
35
  scouts_count = opts[:scouts] || opts[:threads] || 10
36
36
  @opts = {:eval => Johnson::Enabled, :redir => true, :cp => true, :result => Page}.merge!(opts)
37
37
  if args[0].is String
@@ -123,7 +123,8 @@ module RHACK
123
123
  L.log [body, mp, url, opts]
124
124
  zip = opts.delete :zip
125
125
  verb = opts.delete :verb
126
- post = put = verb == :put
126
+ put = verb == :put
127
+ post = put || verb == :post
127
128
  many = order = orders = false
128
129
 
129
130
  if put
@@ -142,9 +143,13 @@ module RHACK
142
143
  # L.debug "URL #{url.inspect} has been passed as second argument instead of third"
143
144
  # But if we have only one argument actually passed
144
145
  # except for options hash then believe it's GET
145
- elsif body.is String or body.kinda [String]
146
- L.debug "first parameter (#{body.inspect}) was implicitly taken as url#{' '+body.class if body.kinda Array}, but last paramter is of type #{url.class}, too" if url
147
- url = body.dup
146
+ elsif body.is String or body.kinda [String] # mp is boolean
147
+ if post
148
+ url = url.dup if url
149
+ else
150
+ L.debug "first parameter (#{body.inspect}) was implicitly taken as url#{' '+body.class if body.kinda Array}, but last paramter is of type #{url.class}, too" if url
151
+ url = body.dup
152
+ end
148
153
  elsif !body
149
154
  url = nil
150
155
  else
@@ -181,8 +186,8 @@ module RHACK
181
186
  (#{args.inspect[1..-2]})"
182
187
  end
183
188
  else
184
- unless body.is Hash
185
- raise TypeError, "body of POST request must be a hash, params was
189
+ unless body.is Hash or body.is String
190
+ raise TypeError, "body of POST request must be a hash or a string params was
186
191
  (#{args.inspect[1..-2]})"
187
192
  end
188
193
  end
@@ -216,11 +221,15 @@ module RHACK
216
221
 
217
222
  (opts[:headers] ||= {})['X-Requested-With'] = 'XMLHttpRequest' if opts[:xhr]
218
223
  if opts[:content_type]
219
- if mime_type = Mime::Type.lookup_by_extension(opts[:content_type])
220
- (opts[:headers] ||= {})['Content-Type'] = mime_type
224
+ if opts[:content_type].is Symbol
225
+ if mime_type = Mime::Types.of(opts[:content_type])[0]
226
+ (opts[:headers] ||= {})['Content-Type'] = mime_type.content_type
227
+ else
228
+ raise ArgumentError, "failed to detect Mime::Type by extension: #{opts[:content_type]}
229
+ (#{args.inspect[1..-2]})"
230
+ end
221
231
  else
222
- raise ArgumentError, "failed to detect Mime::Type by extension: #{opts[:content_type]}
223
- (#{args.inspect[1..-2]})"
232
+ (opts[:headers] ||= {})['Content-Type'] = opts[:content_type]
224
233
  end
225
234
  end
226
235
 
data/lib/rhack/scout.rb CHANGED
@@ -133,22 +133,37 @@ module RHACK
133
133
  uri
134
134
  end
135
135
 
136
- def mkBody(params, multipart=nil)
136
+ def mkBody(params, multipart=false)
137
137
  if multipart
138
138
  @http.multipart_post_body = @body = params.map {|k, v|
139
139
  v = v.call if v.is Proc
140
- if k =~ /^f:/
141
- Curl::PostField.file(k[2..-1], "application/octet-stream",
142
- "#{randstr(16, :hex)}.jpg", v+randstr )
143
- elsif k =~ /^p:/
144
- Curl::PostField.file(k[2..-1], "application/octet-stream",
145
- File.basename(f), read(v) )
140
+ if v[%r(^file://(.+))] or v.is Hash
141
+ path = $1 || v[:path]
142
+ name = v.is(Hash) && v[:name] ||
143
+ File.basename(path)
144
+ content_type = v.is(Hash) && v[:content_type].to_s ||
145
+ (Mime::Types.of(path)[0] || {}).content_type ||
146
+ "application/octet-stream"
147
+ Curl::PostField.file(k, type, name, read(path))
146
148
  else
147
149
  Curl::PostField.content(k.to_s, v.to_s)
148
150
  end
149
151
  }
150
152
  else
151
- @http.post_body = @body = params.urlencode
153
+ @http.post_body = case params
154
+ when IO
155
+ @body = params.read
156
+ params.close
157
+ @body
158
+ when String
159
+ @body = if params[%r(^file://(.+))]
160
+ read $1
161
+ else
162
+ params
163
+ end
164
+ else
165
+ @body = params.urlencode
166
+ end
152
167
  end
153
168
  end
154
169
 
@@ -312,6 +327,9 @@ module RHACK
312
327
  def loadPost(*argv, &callback)
313
328
  hash, multipart, uri, opts = argv.get_opts [@body, @http.multipart_form_post?, @path], :headers => {}, :redir => false, :relvl => 2
314
329
  @http.delete = false
330
+ unless hash.is Hash # not parameterized
331
+ opts[:headers] = opts[:headers].reverse_merge 'Content-Type' => 'application/octet-stream'
332
+ end
315
333
  mkBody hash, multipart.b
316
334
  @last_method = :post
317
335
  if block_given?
data/lib/rhack/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module RHACK
2
- VERSION = '1.2.8'
2
+ VERSION = '1.2.9'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rhack
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.8
4
+ version: 1.2.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergey Baev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-23 00:00:00.000000000 Z
11
+ date: 2014-08-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -186,7 +186,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
186
186
  version: '0'
187
187
  requirements: []
188
188
  rubyforge_project:
189
- rubygems_version: 2.2.2
189
+ rubygems_version: 2.4.1
190
190
  signing_key:
191
191
  specification_version: 4
192
192
  summary: Curl-based web-client framework created for developing web-scrapers/bots