cfoundry-IronFoundry 0.3.39 → 0.3.40

Sign up to get free protection for your applications and to get access to all the features.
@@ -104,12 +104,19 @@ module CFoundry
104
104
  proxy_uri = URI.parse(req[:url]).find_proxy()
105
105
  RestClient.proxy = proxy_uri.to_s if proxy_uri
106
106
 
107
- RestClient::Request.execute(req) do |response, request|
107
+ RestClient::Request.execute(req) do |response, request, result, &block|
108
108
  time = Time.now - before
109
109
 
110
- print_trace(req, request, response, caller) if @trace
111
- log_request(time, req, response)
112
- handle_response(response, accept)
110
+ print_trace(request, response, caller) if @trace
111
+ log_request(time, request, response)
112
+
113
+ if [:get, :head].include?(method) && \
114
+ [301, 302, 307].include?(response.code) && \
115
+ accept != :headers
116
+ response.follow_redirection(request, result, &block)
117
+ else
118
+ handle_response(response, accept)
119
+ end
113
120
  end
114
121
  rescue SocketError, Errno::ECONNREFUSED => e
115
122
  raise TargetRefused, e.message
@@ -178,11 +185,14 @@ module CFoundry
178
185
 
179
186
  def log_data(time, request, response)
180
187
  { :time => time,
181
- :request => request,
188
+ :request => {
189
+ :method => request.method,
190
+ :url => request.url,
191
+ :headers => request.headers
192
+ },
182
193
  :response => {
183
194
  :code => response.code,
184
- :headers => response.headers,
185
- :body => response
195
+ :headers => response.headers
186
196
  }
187
197
  }
188
198
  end
@@ -232,10 +242,10 @@ module CFoundry
232
242
  end
233
243
  end
234
244
 
235
- def print_trace(req, request, response, locs)
245
+ def print_trace(request, response, locs)
236
246
  $stderr.puts ">>>"
237
247
  $stderr.puts "PROXY: #{RestClient.proxy}" if RestClient.proxy
238
- $stderr.puts "REQUEST: #{req[:method]} #{req[:url]}"
248
+ $stderr.puts "REQUEST: #{request.method} #{request.url}"
239
249
  $stderr.puts "RESPONSE_HEADERS:"
240
250
  response.headers.each do |key, value|
241
251
  $stderr.puts " #{key} : #{value}"
@@ -244,7 +254,7 @@ module CFoundry
244
254
  request.headers.each do |key, value|
245
255
  $stderr.puts " #{key} : #{value}"
246
256
  end
247
- $stderr.puts "REQUEST_BODY: #{req[:payload]}" if req[:payload]
257
+ $stderr.puts "REQUEST_BODY: #{request.payload}" if request.payload
248
258
  $stderr.puts "RESPONSE: [#{response.code}]"
249
259
  begin
250
260
  parsed_body = MultiJson.load(response.body)
@@ -277,7 +287,7 @@ module CFoundry
277
287
  json = accept == :json
278
288
 
279
289
  case response.code
280
- when 200, 201, 204, 302
290
+ when 200, 201, 204, 301, 302, 307
281
291
  if accept == :headers
282
292
  return response.headers
283
293
  end
@@ -30,5 +30,9 @@ module CFoundry
30
30
  def to_json(*args)
31
31
  @hash.to_json(*args)
32
32
  end
33
+
34
+ def to_hash
35
+ @hash
36
+ end
33
37
  end
34
38
  end
@@ -156,7 +156,7 @@ module CFoundry::V1
156
156
  json = accept == :json
157
157
 
158
158
  case response.code
159
- when 200, 204, 302
159
+ when 200, 201, 204, 301, 302, 307
160
160
  if accept == :headers
161
161
  return response.headers
162
162
  end
@@ -64,7 +64,9 @@ module CFoundry::V2
64
64
  environment_json)
65
65
  end
66
66
 
67
- alias :env= :environment_json=
67
+ def env=(x)
68
+ self.environment_json = x.to_hash
69
+ end
68
70
 
69
71
  def debug_mode # TODO v2
70
72
  nil
@@ -111,7 +113,9 @@ module CFoundry::V2
111
113
  alias :create_route :create_routes
112
114
 
113
115
  def uri
114
- uris[0]
116
+ if route = routes.first
117
+ "#{route.host}.#{route.domain.name}"
118
+ end
115
119
  end
116
120
  alias :url :uri
117
121
 
@@ -139,7 +139,7 @@ module CFoundry::V2
139
139
  json = accept == :json
140
140
 
141
141
  case response.code
142
- when 200, 201, 204, 302
142
+ when 200, 201, 204, 301, 302, 307
143
143
  if accept == :headers
144
144
  return response.headers
145
145
  end
@@ -173,11 +173,14 @@ module CFoundry::V2
173
173
  end
174
174
 
175
175
  if has_name
176
- define_method(:"#{singular}_by_name") do |name|
176
+ define_method(:"#{singular}_by_name") do |name, *args|
177
+ depth, _ = args
178
+ depth ||= 1
179
+
177
180
  if has_space && current_space
178
- current_space.send(plural, 1, :name => name).first
181
+ current_space.send(plural, depth, :name => name).first
179
182
  else
180
- send(plural, 1, :name => name).first
183
+ send(plural, depth, :name => name).first
181
184
  end
182
185
  end
183
186
  end
@@ -1,4 +1,4 @@
1
1
  module CFoundry # :nodoc:
2
2
  # CFoundry library version number.
3
- VERSION = "0.3.39"
3
+ VERSION = "0.3.40"
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cfoundry-IronFoundry
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.39
4
+ version: 0.3.40
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-10-04 00:00:00.000000000 Z
13
+ date: 2012-10-09 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rest-client