parallel_http 0.0.19 → 0.0.20

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.
Files changed (2) hide show
  1. data/lib/parallel_http.rb +5 -5
  2. metadata +2 -2
data/lib/parallel_http.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # encoding: UTF-8
1
2
  require 'eventmachine'
2
3
  require 'em-http-request'
3
4
  require 'iconv' if RUBY_VERSION.to_f < 1.9
@@ -23,14 +24,14 @@ class ParallelHttp
23
24
  @@results
24
25
  end
25
26
 
26
- def self.exec_result id, result, error=nil
27
+ def self.exec_result id, url, result, error=nil
27
28
  body = ''
28
29
  if RUBY_VERSION.to_f < 1.9
29
30
  body = Iconv.iconv('UTF-8//IGNORE', 'UTF-8', result.response).first
30
31
  else
31
32
  body = result.response.force_encoding('UTF-8').encode('UTF-16', :invalid => :replace, :replace => '').encode('UTF-8')
32
33
  end
33
- hsh = {:id => id, :response_code => result.response_header.status, :body => body}
34
+ hsh = {:id => id, :url => url, :response_code => result.response_header.status, :body => body}
34
35
  hsh.merge!(:error => error) if error
35
36
  @@results << hsh
36
37
  if @@request_size == @@results.size
@@ -39,17 +40,16 @@ class ParallelHttp
39
40
  end
40
41
 
41
42
  def self.single request, options
42
-
43
43
  puts "making a request #{request[:url]}, #{request[:verb]}, #{request[:options]}" if @@verbose
44
44
  opts = request[:options] || {}
45
45
  http = EventMachine::HttpRequest.new(request[:url], options).send(request[:verb].downcase, opts)
46
46
  http.callback do
47
47
  puts "SUCCESS: #{request[:id]}" if @@verbose
48
- ParallelHttp.exec_result(request[:id], http)
48
+ ParallelHttp.exec_result(request[:id], request[:url], http)
49
49
  end
50
50
  http.errback do |h|
51
51
  puts "FAILURE: #{request[:id]}" if @@verbose
52
- ParallelHttp.exec_result(request[:id], h, h.error)
52
+ ParallelHttp.exec_result(request[:id], request[:url], h, h.error)
53
53
  end
54
54
  end
55
55
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: parallel_http
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.19
4
+ version: 0.0.20
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -70,7 +70,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
70
70
  version: '0'
71
71
  requirements: []
72
72
  rubyforge_project:
73
- rubygems_version: 1.8.25
73
+ rubygems_version: 1.8.23
74
74
  signing_key:
75
75
  specification_version: 3
76
76
  summary: Parallel HTTP calls