cfoundry 0.3.39 → 0.3.40

Sign up to get free protection for your applications and to get access to all the features.
@@ -101,12 +101,19 @@ module CFoundry
101
101
 
102
102
  before = Time.now
103
103
 
104
- RestClient::Request.execute(req) do |response, request|
104
+ RestClient::Request.execute(req) do |response, request, result, &block|
105
105
  time = Time.now - before
106
106
 
107
- print_trace(req, request, response, caller) if @trace
108
- log_request(time, req, response)
109
- handle_response(response, accept)
107
+ print_trace(request, response, caller) if @trace
108
+ log_request(time, request, response)
109
+
110
+ if [:get, :head].include?(method) && \
111
+ [301, 302, 307].include?(response.code) && \
112
+ accept != :headers
113
+ response.follow_redirection(request, result, &block)
114
+ else
115
+ handle_response(response, accept)
116
+ end
110
117
  end
111
118
  rescue SocketError, Errno::ECONNREFUSED => e
112
119
  raise TargetRefused, e.message
@@ -175,11 +182,14 @@ module CFoundry
175
182
 
176
183
  def log_data(time, request, response)
177
184
  { :time => time,
178
- :request => request,
185
+ :request => {
186
+ :method => request.method,
187
+ :url => request.url,
188
+ :headers => request.headers
189
+ },
179
190
  :response => {
180
191
  :code => response.code,
181
- :headers => response.headers,
182
- :body => response
192
+ :headers => response.headers
183
193
  }
184
194
  }
185
195
  end
@@ -229,10 +239,10 @@ module CFoundry
229
239
  end
230
240
  end
231
241
 
232
- def print_trace(req, request, response, locs)
242
+ def print_trace(request, response, locs)
233
243
  $stderr.puts ">>>"
234
244
  $stderr.puts "PROXY: #{RestClient.proxy}" if RestClient.proxy
235
- $stderr.puts "REQUEST: #{req[:method]} #{req[:url]}"
245
+ $stderr.puts "REQUEST: #{request.method} #{request.url}"
236
246
  $stderr.puts "RESPONSE_HEADERS:"
237
247
  response.headers.each do |key, value|
238
248
  $stderr.puts " #{key} : #{value}"
@@ -241,7 +251,7 @@ module CFoundry
241
251
  request.headers.each do |key, value|
242
252
  $stderr.puts " #{key} : #{value}"
243
253
  end
244
- $stderr.puts "REQUEST_BODY: #{req[:payload]}" if req[:payload]
254
+ $stderr.puts "REQUEST_BODY: #{request.payload}" if request.payload
245
255
  $stderr.puts "RESPONSE: [#{response.code}]"
246
256
  begin
247
257
  parsed_body = MultiJson.load(response.body)
@@ -274,7 +284,7 @@ module CFoundry
274
284
  json = accept == :json
275
285
 
276
286
  case response.code
277
- when 200, 201, 204, 302
287
+ when 200, 201, 204, 301, 302, 307
278
288
  if accept == :headers
279
289
  return response.headers
280
290
  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,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cfoundry
3
3
  version: !ruby/object:Gem::Version
4
- hash: 93
4
+ hash: 67
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 39
10
- version: 0.3.39
9
+ - 40
10
+ version: 0.3.40
11
11
  platform: ruby
12
12
  authors:
13
13
  - Alex Suraci
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-10-03 00:00:00 Z
18
+ date: 2012-10-05 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: rest-client