rest 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rest (1.0.0)
4
+ rest (1.1.0)
5
5
  rest-client (>= 0.3.0)
6
6
 
7
7
  GEM
@@ -10,6 +10,7 @@ GEM
10
10
  ffi (1.0.11)
11
11
  mime-types (1.18)
12
12
  net-http-persistent (2.7)
13
+ quicky (0.0.1)
13
14
  rake (0.9.2.2)
14
15
  rest-client (1.6.7)
15
16
  mime-types (>= 1.16)
@@ -24,6 +25,7 @@ PLATFORMS
24
25
 
25
26
  DEPENDENCIES
26
27
  net-http-persistent
28
+ quicky
27
29
  rake
28
30
  rest!
29
31
  test-unit
data/README.md CHANGED
@@ -28,7 +28,7 @@ Supported http libraries are:
28
28
  Then use it:
29
29
 
30
30
  GET
31
- =========
31
+ ------
32
32
 
33
33
  @rest.get(url, options...)
34
34
 
@@ -38,7 +38,7 @@ options:
38
38
  - :headers => headers
39
39
 
40
40
  POST
41
- ======
41
+ -----
42
42
 
43
43
  @rest.post(url, options...)
44
44
 
@@ -48,7 +48,7 @@ options:
48
48
  - :headers => headers
49
49
 
50
50
  PUT
51
- ======
51
+ ------
52
52
 
53
53
  @rest.put(url, options...)
54
54
 
@@ -58,9 +58,15 @@ options:
58
58
  - :headers => headers
59
59
 
60
60
  DELETE
61
- ======
61
+ --------
62
62
 
63
63
  @rest.delete(url, options...)
64
64
 
65
+ Responses
66
+ =========
67
+
68
+ The response object you get back will always be consistent and will have the following functions:
65
69
 
70
+ response.code
71
+ response.body
66
72
 
@@ -19,9 +19,11 @@ module Rest
19
19
  end
20
20
  end
21
21
 
22
- def self.puts(s)
23
- Kernel.puts("rest gem: #{s}")
24
- end
22
+ require_relative 'wrappers/base_wrapper'
23
+
24
+ #def self.puts(s)
25
+ # Kernel.puts("rest gem: #{s}")
26
+ #end
25
27
 
26
28
  class Client
27
29
 
@@ -43,15 +45,15 @@ module Rest
43
45
  if @gem == :typhoeus
44
46
  require_relative 'wrappers/typhoeus_wrapper'
45
47
  @wrapper = Rest::Wrappers::TyphoeusWrapper.new
46
- Rest.puts "Using typhoeus gem."
48
+ @logger.debug "Using typhoeus gem."
47
49
  elsif @gem == :net_http_persistent
48
50
  require_relative 'wrappers/net_http_persistent_wrapper'
49
51
  @wrapper = Rest::Wrappers::NetHttpPersistentWrapper.new(self)
50
- Rest.puts "Using net-http-persistent gem."
52
+ @logger.debug "Using net-http-persistent gem."
51
53
  else
52
- require_relative 'wrappers/rest_client_wrapper'
53
54
  @wrapper = Rest::Wrappers::RestClientWrapper.new
54
- Rest.puts "Using rest-client gem. Please install 'typhoeus' or net-http-persistent gem for best performance."
55
+ hint = (options[:gem] ? "" : " Please install 'typhoeus' or net-http-persistent gem for best performance.")
56
+ @logger.debug "Using rest-client gem.#{hint}"
55
57
  end
56
58
  end
57
59
 
@@ -65,7 +67,6 @@ module Rest
65
67
  # try net-http-persistent
66
68
  require 'net/http/persistent'
67
69
  @gem = :net_http_persistent
68
-
69
70
  rescue LoadError => ex
70
71
  require 'rest_client'
71
72
  @gem = :rest_client
@@ -134,6 +135,14 @@ module Rest
134
135
  return res
135
136
  end
136
137
 
138
+ def post_file(url, req_hash={})
139
+ res = nil
140
+ perform_op do
141
+ res = @wrapper.post_file(url, req_hash)
142
+ end
143
+ return res
144
+ end
145
+
137
146
  def close
138
147
  @wrapper.close
139
148
  end
@@ -1,3 +1,3 @@
1
1
  module Rest
2
- VERSION = "1.1.0"
2
+ VERSION = "1.2.0"
3
3
  end
@@ -1,7 +1,32 @@
1
1
  class BaseWrapper
2
2
 
3
+ def post_file(url, req_hash={})
4
+ response = nil
5
+ begin
6
+ if req_hash[:body]
7
+ req_hash = req_hash.merge(req_hash[:body])
8
+ req_hash.delete(:body)
9
+ end
10
+
11
+ headers = {}
12
+ if req_hash[:headers]
13
+ headers = req_hash[:headers]
14
+ req_hash.delete(:headers)
15
+ end
16
+
17
+ r2 = RestClient.post(url, req_hash, headers)
18
+ response = Rest::Wrappers::RestClientResponseWrapper.new(r2)
19
+ rescue RestClient::Exception => ex
20
+ raise Rest::Wrappers::RestClientExceptionWrapper.new(ex)
21
+ end
22
+ response
23
+ end
24
+
3
25
  # if wrapper has a close/shutdown, override this
4
26
  def close
5
27
 
6
28
  end
7
- end
29
+ end
30
+
31
+ # we need it for post_file, ok as gem already depends on it
32
+ require_relative 'rest_client_wrapper'
@@ -1,5 +1,4 @@
1
1
  require 'net/http/persistent'
2
- require_relative 'base_wrapper'
3
2
 
4
3
  module Rest
5
4
 
@@ -155,4 +154,4 @@ module Rest
155
154
 
156
155
  end
157
156
 
158
- end
157
+ end
@@ -25,7 +25,7 @@ module Rest
25
25
 
26
26
  end
27
27
 
28
- class RestClientWrapper
28
+ class RestClientWrapper < BaseWrapper
29
29
 
30
30
  def default_headers
31
31
  {}
@@ -97,4 +97,4 @@ module Rest
97
97
 
98
98
  end
99
99
 
100
- end
100
+ end
@@ -11,7 +11,7 @@ module Rest
11
11
  end
12
12
  end
13
13
 
14
- class TyphoeusWrapper
14
+ class TyphoeusWrapper < BaseWrapper
15
15
 
16
16
  def default_typhoeus_options
17
17
  req_hash = {}
@@ -78,4 +78,4 @@ module Rest
78
78
 
79
79
  end
80
80
 
81
- end
81
+ end
@@ -17,12 +17,13 @@ Gem::Specification.new do |gem|
17
17
  gem.required_rubygems_version = ">= 1.3.6"
18
18
  gem.required_ruby_version = Gem::Requirement.new(">= 1.9")
19
19
  gem.add_runtime_dependency "rest-client", ">= 0.3.0"
20
+ gem.add_runtime_dependency "net-http-persistent"
20
21
 
21
22
  gem.add_development_dependency "test-unit"
22
23
  gem.add_development_dependency "rake"
23
24
  gem.add_development_dependency "uber_config"
24
25
  gem.add_development_dependency "typhoeus"
25
- gem.add_development_dependency "net-http-persistent"
26
+ gem.add_development_dependency "quicky"
26
27
 
27
28
  end
28
29
 
@@ -1,8 +1,8 @@
1
- # Put config.yml file in ~/Dropbox/configs/ironmq_gem/test/config.yml
2
-
3
1
  gem 'test-unit'
4
2
  require 'test/unit'
5
3
  require 'yaml'
4
+ require 'quicky'
5
+
6
6
  require_relative 'test_base'
7
7
 
8
8
  class TestTests < TestBase
@@ -13,30 +13,27 @@ class TestTests < TestBase
13
13
 
14
14
  def test_get_performance
15
15
 
16
- times = 100
16
+ times = 10
17
17
 
18
- collector = []
18
+ quicky = Quicky::Timer.new
19
19
 
20
- collector << run_perf(times, :typhoeus)
21
- collector << run_perf(times, :rest_client)
22
- collector << run_perf(times, :net_http_persistent)
20
+ to_run = [:typhoeus, :rest_client, :net_http_persistent]
21
+ to_run.each do |gem|
22
+ run_perf(quicky, times, gem)
23
+ end
23
24
 
24
- collector.each do |c|
25
- p c
25
+ quicky.results.each_pair do |k, v|
26
+ puts "#{k}: #{v.duration}"
26
27
  end
27
28
 
28
29
  end
29
30
 
30
- def run_perf(times, gem)
31
+ def run_perf(quicky, times, gem)
31
32
  puts "Starting #{gem} test..."
32
- t = Time.now
33
33
  client = Rest::Client.new(:gem => gem)
34
- times.times do |i|
34
+ quicky.loop(gem, times) do
35
35
  client.get("http://requestb.in/ydyd4nyd")
36
36
  end
37
- duration = Time.now.to_f - t.to_f
38
- puts "#{times} posts took #{duration}"
39
- {:gem=>gem, :duration=>duration}
40
37
  end
41
38
 
42
39
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rest
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-29 00:00:00.000000000 Z
12
+ date: 2012-07-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rest-client
@@ -27,6 +27,22 @@ dependencies:
27
27
  - - ! '>='
28
28
  - !ruby/object:Gem::Version
29
29
  version: 0.3.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: net-http-persistent
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
30
46
  - !ruby/object:Gem::Dependency
31
47
  name: test-unit
32
48
  requirement: !ruby/object:Gem::Requirement
@@ -92,7 +108,7 @@ dependencies:
92
108
  - !ruby/object:Gem::Version
93
109
  version: '0'
94
110
  - !ruby/object:Gem::Dependency
95
- name: net-http-persistent
111
+ name: quicky
96
112
  requirement: !ruby/object:Gem::Requirement
97
113
  none: false
98
114
  requirements: