rest-client-components 1.2.0 → 1.3.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: fd1cc995e369066b6686c91d17cf68c1ea59f07c
4
+ data.tar.gz: 7c62b70ec84a6c420b3731faeaf4d774676ae90a
5
+ SHA512:
6
+ metadata.gz: 23f8f1859e018cb09bd7feeed978e26e6224ee988113ee35ea325481f5ad011a5161862d289d8f5e97bedd14e35ef0762998ff98360075d9b62e3f1a5684bfd7
7
+ data.tar.gz: 10c77068694bad651be3e3248c1f98b8dc40f7befbe2c53e7f2d491e2c1e8740d6eadfebb99c5f9e8c1d9123d2945dcfe62505eff65df89456b69ccc28f52530
@@ -43,7 +43,7 @@ Example with Rack::Cache, and Rack::CommonLogger
43
43
 
44
44
  RestClient.enable Rack::CommonLogger
45
45
  # Enable the cache Rack middleware, and store both meta and entity data in files:
46
- # See http://tomayko.com/src/rack-cache/configuration for the list of available options
46
+ # See http://rtomayko.github.io/rack-cache/configuration for the list of available options
47
47
  RestClient.enable Rack::Cache,
48
48
  :metastore => 'file:/tmp/cache/meta',
49
49
  :entitystore => 'file:/tmp/cache/body'
@@ -81,4 +81,4 @@ Now, you just need to make your resources cacheable, so unless you've already ta
81
81
 
82
82
  = COPYRIGHT
83
83
 
84
- Copyright (c) 2009-2010 Cyril Rohr. See LICENSE for details.
84
+ Copyright (c) 2009-2010 Cyril Rohr. See LICENSE for details.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.2.0
1
+ 1.3.0
@@ -7,7 +7,7 @@ module RestClient
7
7
  def initialize(app)
8
8
  @app = app
9
9
  end
10
-
10
+
11
11
  def call(env)
12
12
  status, header, body = @app.call(env)
13
13
  net_http_response = RestClient::MockNetHTTPResponse.new(body, status, header)
@@ -16,7 +16,7 @@ module RestClient
16
16
  response = RestClient::Response.create(content, net_http_response, {})
17
17
  if block = env['restclient.hash'][:block]
18
18
  block.call(response)
19
- # only raise error if response is not successful
19
+ # only raise error if response is not successful
20
20
  elsif !(200...300).include?(response.code) && e = env['restclient.hash'][:error]
21
21
  raise e
22
22
  else
@@ -29,20 +29,25 @@ module RestClient
29
29
  class <<self
30
30
  attr_reader :components
31
31
  end
32
-
32
+
33
33
  # Enable a Rack component. You may enable as many components as you want.
34
- # e.g.
34
+ #
35
+ # Examples:
36
+ #
35
37
  # Transparent HTTP caching:
36
- # RestClient.enable Rack::Cache,
38
+ #
39
+ # RestClient.enable Rack::Cache,
37
40
  # :verbose => true,
38
41
  # :metastore => 'file:/var/cache/rack/meta'
39
42
  # :entitystore => 'file:/var/cache/rack/body'
40
- #
43
+ #
41
44
  # Transparent logging of HTTP requests (commonlog format):
45
+ #
42
46
  # RestClient.enable Rack::CommonLogger, STDOUT
43
- #
44
- # Please refer to the documentation of each rack component for the list of available options.
45
- #
47
+ #
48
+ # Please refer to the documentation of each rack component for the list of
49
+ # available options.
50
+ #
46
51
  def self.enable(component, *args)
47
52
  # remove any existing component of the same class
48
53
  disable(component)
@@ -52,47 +57,49 @@ module RestClient
52
57
  @components.unshift [component, args]
53
58
  end
54
59
  end
55
-
60
+
56
61
  # Disable a component
62
+ #
57
63
  # RestClient.disable Rack::Cache
58
64
  # => array of remaining components
59
65
  def self.disable(component)
60
66
  @components.delete_if{|(existing_component, options)| component == existing_component}
61
67
  end
62
-
63
- # Returns true if the given component is enabled, false otherwise
68
+
69
+ # Returns true if the given component is enabled, false otherwise.
70
+ #
64
71
  # RestClient.enable Rack::Cache
65
72
  # RestClient.enabled?(Rack::Cache)
66
73
  # => true
67
74
  def self.enabled?(component)
68
75
  !@components.detect{|(existing_component, options)| component == existing_component}.nil?
69
76
  end
70
-
77
+
71
78
  def self.reset
72
- # hash of the enabled components
79
+ # hash of the enabled components
73
80
  @components = [[RestClient::Rack::Compatibility]]
74
81
  end
75
-
82
+
76
83
  def self.debeautify_headers(headers = {}) # :nodoc:
77
84
  headers.inject({}) do |out, (key, value)|
78
- out[key.to_s.gsub(/_/, '-').split("-").map{|w| w.capitalize}.join("-")] = value.to_s
79
- out
80
- end
85
+ out[key.to_s.gsub(/_/, '-').split("-").map{|w| w.capitalize}.join("-")] = value.to_s
86
+ out
87
+ end
81
88
  end
82
-
89
+
83
90
  reset
84
-
85
- # Reopen the RestClient::Request class to add a level of indirection in order to create the stack of Rack middleware.
86
- #
87
- class Request
88
- alias_method :original_execute, :execute
89
- def execute(&block)
91
+
92
+ # Reopen the RestClient::Request class to add a level of indirection in
93
+ # order to create the stack of Rack middleware.
94
+ class Request
95
+ alias_method :original_execute, :execute
96
+ def execute(&block)
90
97
  uri = URI.parse(@url)
91
98
  # minimal rack spec
92
- env = {
99
+ env = {
93
100
  "restclient.hash" => {
94
- :request => self,
95
- :error => nil,
101
+ :request => self,
102
+ :error => nil,
96
103
  :block => block
97
104
  },
98
105
  "REQUEST_METHOD" => @method.to_s.upcase,
@@ -136,29 +143,30 @@ module RestClient
136
143
  response
137
144
  end
138
145
  end
139
-
140
- module Payload
141
- class Base
142
- def rewind(*args)
143
- @stream.rewind(*args)
146
+
147
+ module Payload
148
+ class Base
149
+ def rewind(*args)
150
+ @stream.rewind(*args)
144
151
  end
145
-
152
+
146
153
  def gets(*args)
147
154
  @stream.gets(*args)
148
155
  end
149
-
156
+
150
157
  def each(&block)
151
158
  @stream.each(&block)
152
159
  end
153
160
  end
154
161
  end
155
-
156
- # A class that mocks the behaviour of a Net::HTTPResponse class.
157
- # It is required since RestClient::Response must be initialized with a class that responds to :code and :to_hash.
162
+
163
+ # A class that mocks the behaviour of a Net::HTTPResponse class. It is
164
+ # required since RestClient::Response must be initialized with a class that
165
+ # responds to :code and :to_hash.
158
166
  class MockNetHTTPResponse
159
167
  attr_reader :body, :header, :status
160
168
  alias_method :code, :status
161
-
169
+
162
170
  def initialize(body, status, header)
163
171
  @body = body
164
172
  @status = status
@@ -171,9 +179,9 @@ module RestClient
171
179
  out[key] = [value]
172
180
  out
173
181
  }
174
- end
182
+ end
175
183
  end
176
-
184
+
177
185
  RACK_APP = Proc.new { |env|
178
186
  begin
179
187
  # get the original request, replace headers with those of env, and execute it
@@ -184,21 +192,19 @@ module RestClient
184
192
  }
185
193
  env_headers['Content-Type'] = env['CONTENT_TYPE'] if env['CONTENT_TYPE']
186
194
  env_headers['Content-Length'] = env['CONTENT_LENGTH'] if env['CONTENT_LENGTH']
187
- # hack, should probably avoid to call #read on rack.input..
188
- payload = if (env['rack.input'].size > 0)
189
- env['rack.input'].rewind
190
- Payload.generate(env['rack.input'].read)
191
- else
192
- nil
193
- end
195
+
196
+ env['rack.input'].rewind
197
+ payload = env['rack.input'].read
198
+ payload = (payload.empty? ? nil : Payload.generate(payload))
194
199
  request.instance_variable_set "@payload", payload
200
+
195
201
  headers = request.make_headers(env_headers)
196
202
  request.processed_headers.update(headers)
197
203
  response = request.original_execute
198
- rescue RestClient::ExceptionWithResponse => e
204
+ rescue RestClient::ExceptionWithResponse => e
199
205
  # re-raise the error if the response is nil (RestClient does not
200
- # differentiate between a RestClient::RequestTimeout due to a 408
201
- # status code, and a RestClient::RequestTimeout due to a Timeout::Error)
206
+ # differentiate between a RestClient::RequestTimeout due to a 408 status
207
+ # code, and a RestClient::RequestTimeout due to a Timeout::Error)
202
208
  raise e if e.response.nil?
203
209
  env['restclient.hash'][:error] = e
204
210
  response = e.response
@@ -207,7 +213,8 @@ module RestClient
207
213
  response.headers.delete(:status)
208
214
  header = RestClient.debeautify_headers( response.headers )
209
215
  body = response.to_s
210
- # return the real content-length since RestClient does not do it when decoding gzip responses
216
+ # return the real content-length since RestClient does not do it when
217
+ # decoding gzip responses
211
218
  header['Content-Length'] = body.length.to_s if header.has_key?('Content-Length')
212
219
  [response.code, header, [body]]
213
220
  }
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{rest-client-components}
8
- s.version = "1.2.0"
8
+ s.version = "1.3.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Cyril Rohr"]
@@ -47,16 +47,16 @@ Gem::Specification.new do |s|
47
47
  s.specification_version = 3
48
48
 
49
49
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
50
- s.add_runtime_dependency(%q<rest-client>, [">= 1.6.0", "< 1.7.0"])
50
+ s.add_runtime_dependency(%q<rest-client>, [">= 1.6.0"])
51
51
  s.add_runtime_dependency(%q<rack>, [">= 1.0.1"])
52
52
  s.add_development_dependency(%q<webmock>, [">= 0"])
53
53
  else
54
- s.add_dependency(%q<rest-client>, [">= 1.6.0", "< 1.7.0"])
54
+ s.add_dependency(%q<rest-client>, [">= 1.6.0"])
55
55
  s.add_dependency(%q<rack>, [">= 1.0.1"])
56
56
  s.add_dependency(%q<webmock>, [">= 0"])
57
57
  end
58
58
  else
59
- s.add_dependency(%q<rest-client>, [">= 1.6.0", "< 1.7.0"])
59
+ s.add_dependency(%q<rest-client>, [">= 1.6.0"])
60
60
  s.add_dependency(%q<rack>, [">= 1.0.1"])
61
61
  s.add_dependency(%q<webmock>, [">= 0"])
62
62
  end
metadata CHANGED
@@ -1,87 +1,67 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: rest-client-components
3
- version: !ruby/object:Gem::Version
4
- hash: 2840920021394413258
5
- prerelease: false
6
- segments:
7
- - 1
8
- - 2
9
- - 0
10
- version: 1.2.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.3.0
11
5
  platform: ruby
12
- authors:
6
+ authors:
13
7
  - Cyril Rohr
14
8
  autorequire:
15
9
  bindir: bin
16
10
  cert_chain: []
17
-
18
- date: 2010-07-22 00:00:00 +02:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
11
+ date: 2010-07-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
22
14
  name: rest-client
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
27
17
  - - ">="
28
- - !ruby/object:Gem::Version
29
- hash: 2657083326512599250
30
- segments:
31
- - 1
32
- - 6
33
- - 0
18
+ - !ruby/object:Gem::Version
34
19
  version: 1.6.0
35
- - - <
36
- - !ruby/object:Gem::Version
37
- hash: 158014003617880386
38
- segments:
39
- - 1
40
- - 7
41
- - 0
42
- version: 1.7.0
43
20
  type: :runtime
44
- version_requirements: *id001
45
- - !ruby/object:Gem::Dependency
46
- name: rack
47
21
  prerelease: false
48
- requirement: &id002 !ruby/object:Gem::Requirement
49
- none: false
50
- requirements:
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 1.6.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: rack
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
51
31
  - - ">="
52
- - !ruby/object:Gem::Version
53
- hash: 3196562863265611407
54
- segments:
55
- - 1
56
- - 0
57
- - 1
32
+ - !ruby/object:Gem::Version
58
33
  version: 1.0.1
59
34
  type: :runtime
60
- version_requirements: *id002
61
- - !ruby/object:Gem::Dependency
62
- name: webmock
63
35
  prerelease: false
64
- requirement: &id003 !ruby/object:Gem::Requirement
65
- none: false
66
- requirements:
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 1.0.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: webmock
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
67
45
  - - ">="
68
- - !ruby/object:Gem::Version
69
- hash: -1411813972297755852
70
- segments:
71
- - 0
72
- version: "0"
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
73
48
  type: :development
74
- version_requirements: *id003
75
- description: RestClient on steroids ! Easily add one or more Rack middleware around RestClient to add functionalities such as transparent caching (Rack::Cache), transparent logging, etc.
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: RestClient on steroids ! Easily add one or more Rack middleware around
56
+ RestClient to add functionalities such as transparent caching (Rack::Cache), transparent
57
+ logging, etc.
76
58
  email: cyril.rohr@gmail.com
77
59
  executables: []
78
-
79
60
  extensions: []
80
-
81
- extra_rdoc_files:
61
+ extra_rdoc_files:
82
62
  - LICENSE
83
63
  - README.rdoc
84
- files:
64
+ files:
85
65
  - LICENSE
86
66
  - README.rdoc
87
67
  - Rakefile
@@ -93,43 +73,36 @@ files:
93
73
  - rest-client-components.gemspec
94
74
  - spec/components_spec.rb
95
75
  - spec/spec_helper.rb
96
- has_rdoc: true
97
76
  homepage: http://github.com/crohr/rest-client-components
98
77
  licenses: []
99
-
78
+ metadata: {}
100
79
  post_install_message:
101
- rdoc_options:
102
- - --charset=UTF-8
103
- require_paths:
80
+ rdoc_options:
81
+ - "--charset=UTF-8"
82
+ require_paths:
104
83
  - lib
105
- required_ruby_version: !ruby/object:Gem::Requirement
106
- none: false
107
- requirements:
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
108
86
  - - ">="
109
- - !ruby/object:Gem::Version
110
- hash: -1411813972297755852
111
- segments:
112
- - 0
113
- version: "0"
114
- required_rubygems_version: !ruby/object:Gem::Requirement
115
- none: false
116
- requirements:
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
117
91
  - - ">="
118
- - !ruby/object:Gem::Version
119
- hash: -1411813972297755852
120
- segments:
121
- - 0
122
- version: "0"
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
123
94
  requirements: []
124
-
125
95
  rubyforge_project:
126
- rubygems_version: 1.3.7
96
+ rubygems_version: 2.2.2
127
97
  signing_key:
128
98
  specification_version: 3
129
- summary: RestClient on steroids ! Easily add one or more Rack middleware around RestClient to add functionalities such as transparent caching (Rack::Cache), transparent logging, etc.
130
- test_files:
99
+ summary: RestClient on steroids ! Easily add one or more Rack middleware around RestClient
100
+ to add functionalities such as transparent caching (Rack::Cache), transparent logging,
101
+ etc.
102
+ test_files:
131
103
  - spec/components_spec.rb
132
104
  - spec/spec_helper.rb
133
105
  - examples/beautify_html.rb
134
106
  - examples/caching.rb
135
107
  - examples/parsing.rb
108
+ has_rdoc: