grid_rest 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.rdoc CHANGED
@@ -1,4 +1,7 @@
1
1
  = CHANGELOG
2
+ == v0.0.3
3
+ * Transform empty RestClient false to empty string
4
+ * Serialize parameters for delete request
2
5
 
3
6
  == 2011-06-08 v0.0.2
4
7
  * Initialization fixes
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.2
1
+ 0.0.3
data/grid_rest.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{grid_rest}
8
- s.version = "0.0.2"
8
+ s.version = "0.0.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Benjamin ter Kuile"]
12
- s.date = %q{2011-06-08}
12
+ s.date = %q{2011-06-15}
13
13
  s.description = %q{grid_rest is a gem that makes your rails application interact with other backends through a REST interface. It is build in a situation where one rails application was talking to 2 java backends.
14
14
  The main development focus is JSON communication, but XML should be just as easy}
15
15
  s.email = %q{bterkuile@gmail.com}
data/lib/grid_rest.rb CHANGED
@@ -2,6 +2,7 @@ require 'rest_client'
2
2
  require 'active_support/all'
3
3
  require 'grid_rest/engine'
4
4
  module GridRest
5
+ RESERVED_REQUEST_PARAMETERS = %w[accept content_type headers method url payload timeout open_timeout raw_response verify_ssl ssl_client_cert ssl_client_key ssl_ca_file cookie cookies accept_encoding]
5
6
  mattr_accessor :grid_config, :log_file, :additional_parameters
6
7
  self.additional_parameters = { :default => {:global => {}, :get => {}, :post => {}, :put => {}, :delete => {}} }
7
8
  class GridConfig < HashWithIndifferentAccess
@@ -23,6 +24,10 @@ module GridRest
23
24
  end
24
25
  end
25
26
 
27
+ def self.default_parameters(params, type = :global, namespace = :default)
28
+ additional_parameters[namespace][type].update(params)
29
+ end
30
+
26
31
  def self.extend_class(klass)
27
32
  klass.send(:extend, GridRestExtensions)
28
33
  self.grid_config.namespaces.keys.each do |k|
@@ -200,20 +205,10 @@ module GridRest
200
205
  RestClient.put rest_url, rparams.update(additional_put_parameters)
201
206
  end
202
207
  when :delete then
203
- if rparams[:json_data]
204
- rparams[:json_data] = rparams[:json_data].merge(additional_delete_parameters).to_json if rparams[:json_data].is_a?(Hash)
205
- RestClient.delete rest_url, rparams[:json_data], :content_type => :json, :accept => :json
206
- elsif rparams[:xml_data]
207
- rparams[:xml_data] = rparams[:xml_data].merge(additional_delete_parameters).to_xml if rparams[:xml_data].is_a?(Hash)
208
- RestClient.delete rest_url, rparams[:xml_data], :content_type => :xml, :accept => :xml
209
- elsif rparams[:binary]
210
- RestClient.delete rest_url, rparams[:binary], :content_type => 'binary/octet-stream'
211
- else
212
- rparams[:headers] ||= {}
213
- rparams[:headers][:accept] = accept
214
- rparams[:multipart] = true
215
- RestClient.delete rest_url, rparams.update(additional_delete_parameters)
216
- end
208
+ rparams[:headers] ||= {}
209
+ rparams[:headers][:accept] = accept
210
+ new_uri = add_parameters_to_uri(rest_url, rparams.update(additional_delete_parameters))
211
+ RestClient.delete(new_uri, rparams)
217
212
  else
218
213
  raise "No proper method (#{method}) for a grid_rest_request call"
219
214
  end
@@ -224,6 +219,7 @@ module GridRest
224
219
  r = benchmark("decoding response JSON", :level => :debug ){ JSON.parse(r.body) rescue r }
225
220
  end
226
221
  # Singleton class extensions
222
+ r = "" if r == false # RestClient problem giving false on empty 204
227
223
  def r.valid?
228
224
  true
229
225
  end
@@ -240,6 +236,15 @@ module GridRest
240
236
  r
241
237
  end
242
238
 
239
+ def add_parameters_to_uri(uri, params)
240
+ uri << '?' unless uri.include?('?')
241
+ uri << '&' unless ['?', '&'].include?(uri.last)
242
+ uri_params = params.reject{|k, v| RESERVED_REQUEST_PARAMETERS.include?(k.to_s)}
243
+ uri << uri_params.map{|k, v| URI.encode("#{k}=#{v}")}.join('&')
244
+ uri_params.each{|k, v| params.delete(k)} # Remove added get parameters from the header params
245
+ uri
246
+ end
247
+
243
248
  def generate_url(url, rparams = {})
244
249
  host = GridRest.grid_config.namespaces[rparams[:grid_rest_namespace]].try('[]', 'host') || GridRest.grid_config['host']
245
250
  port = GridRest.grid_config.namespaces[rparams[:grid_rest_namespace]].try('[]', 'port') || GridRest.grid_config['port'] || 80
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 2
9
- version: 0.0.2
8
+ - 3
9
+ version: 0.0.3
10
10
  platform: ruby
11
11
  authors:
12
12
  - Benjamin ter Kuile
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-06-08 00:00:00 +02:00
17
+ date: 2011-06-15 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency