cfoundry 0.3.20 → 0.3.21

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,5 @@
1
1
  require "restclient"
2
- require "json"
2
+ require "multi_json"
3
3
 
4
4
  module CFoundry
5
5
  class BaseClient # :nodoc:
@@ -30,7 +30,7 @@ module CFoundry
30
30
  private
31
31
 
32
32
  def parse_json(x)
33
- JSON.parse(x, :symbolize_names => true)
33
+ MultiJson.load(x, :symbolize_keys => true)
34
34
  end
35
35
 
36
36
  def request(method, path, options = {})
@@ -54,7 +54,7 @@ module CFoundry
54
54
  unless payload.is_a?(String)
55
55
  case type
56
56
  when :json
57
- payload = payload.to_json
57
+ payload = MultiJson.dump(payload)
58
58
  when :form
59
59
  payload = encode_params(payload)
60
60
  end
@@ -93,7 +93,8 @@ module CFoundry
93
93
  $stderr.puts "REQUEST_BODY: #{req[:payload]}" if req[:payload]
94
94
  $stderr.puts "RESPONSE: [#{response.code}]"
95
95
  begin
96
- $stderr.puts JSON.pretty_generate(JSON.parse(response.body))
96
+ parsed_body = MultiJson.load(response.body)
97
+ $stderr.puts MultiJson.dump(parsed_body, :pretty => true)
97
98
  rescue
98
99
  $stderr.puts "#{response.body}"
99
100
  end
@@ -127,7 +128,7 @@ module CFoundry
127
128
  def encode_params(hash, escape = true)
128
129
  hash.keys.map do |k|
129
130
  v = hash[k]
130
- v = v.to_json if v.is_a?(Hash)
131
+ v = MultiJson.dump(v) if v.is_a?(Hash)
131
132
  v = URI.escape(v.to_s, /[^#{URI::PATTERN::UNRESERVED}]/) if escape
132
133
  "#{k}=#{v}"
133
134
  end.join("&")
@@ -74,7 +74,7 @@ module CFoundry
74
74
  when 411, 500, 504
75
75
  begin
76
76
  raise_error(parse_json(response))
77
- rescue JSON::ParserError
77
+ rescue MultiJson::DecodeError
78
78
  raise BadResponse.new(response.code, response)
79
79
  end
80
80
 
@@ -70,6 +70,12 @@ module CFoundry::V1
70
70
  "#<App '#@name'>"
71
71
  end
72
72
 
73
+ # Basic equality test by name.
74
+ def eql?(other)
75
+ other.is_a?(self.class) && other.name == @name
76
+ end
77
+ alias :== :eql?
78
+
73
79
  # Delete the application from the target.
74
80
  #
75
81
  # Keeps the metadata, but clears target-specific state from it.
@@ -300,7 +306,7 @@ module CFoundry::V1
300
306
  end
301
307
 
302
308
  def binds?(instance)
303
- services.any? { |s| s == instance.name }
309
+ services.include? instance
304
310
  end
305
311
 
306
312
  # Retrieve file listing under path for the first instance of the application.
@@ -1,4 +1,4 @@
1
- require "json"
1
+ require "multi_json"
2
2
 
3
3
  require "cfoundry/baseclient"
4
4
  require "cfoundry/uaaclient"
@@ -105,7 +105,6 @@ module CFoundry::V1
105
105
  end
106
106
 
107
107
  def delete_app(name)
108
- # TODO: no JSON response?
109
108
  delete("apps", name)
110
109
  true
111
110
  end
@@ -121,7 +120,7 @@ module CFoundry::V1
121
120
  def upload_app(name, zipfile, resources = [])
122
121
  payload = {
123
122
  :_method => "put",
124
- :resources => resources.to_json,
123
+ :resources => MultiJson.dump(resources),
125
124
  :multipart => true,
126
125
  :application =>
127
126
  if zipfile.is_a? File
@@ -185,7 +184,7 @@ module CFoundry::V1
185
184
  when 411, 500, 504
186
185
  begin
187
186
  raise_error(parse_json(response))
188
- rescue JSON::ParserError
187
+ rescue MultiJson::DecodeError
189
188
  raise CFoundry::BadResponse.new(response.code, response)
190
189
  end
191
190
 
@@ -9,6 +9,11 @@ module CFoundry::V1
9
9
  @detection = detection
10
10
  end
11
11
 
12
+ def eql?(other)
13
+ other.is_a?(self.class) && other.name == @name
14
+ end
15
+ alias :== :eql?
16
+
12
17
  def apps
13
18
  [] # not supported by v1
14
19
  end
@@ -8,6 +8,11 @@ module CFoundry::V1
8
8
  @debug_modes = debug_modes
9
9
  end
10
10
 
11
+ def eql?(other)
12
+ other.is_a?(self.class) && other.name == @name
13
+ end
14
+ alias :== :eql?
15
+
11
16
  def apps
12
17
  [] # not supported by v1
13
18
  end
@@ -9,6 +9,11 @@ module CFoundry::V1
9
9
  @type = nil
10
10
  end
11
11
 
12
+ def eql?(other)
13
+ other.is_a?(self.class) && other.label == @label
14
+ end
15
+ alias :== :eql?
16
+
12
17
  def provider
13
18
  "core"
14
19
  end
@@ -41,6 +41,12 @@ module CFoundry::V1
41
41
  "#<ServiceInstance '#@name'>"
42
42
  end
43
43
 
44
+ # Basic equality test by name.
45
+ def eql?(other)
46
+ other.is_a?(self.class) && other.name == @name
47
+ end
48
+ alias :== :eql?
49
+
44
50
  # Delete the service from the target.
45
51
  def delete!
46
52
  @client.base.delete_service(@name)
@@ -23,6 +23,12 @@ module CFoundry::V1
23
23
  "#<User '#@email'>"
24
24
  end
25
25
 
26
+ # Basic equality test by email.
27
+ def eql?(other)
28
+ other.is_a?(self.class) && other.email == @email
29
+ end
30
+ alias :== :eql?
31
+
26
32
  # Delete the user from the target.
27
33
  def delete!
28
34
  @client.base.delete_user(@email)
@@ -1,5 +1,5 @@
1
1
  require "tmpdir"
2
- require "json"
2
+ require "multi_json"
3
3
 
4
4
  require "cfoundry/zip"
5
5
  require "cfoundry/upload_helpers"
@@ -42,7 +42,7 @@ module CFoundry::V2
42
42
  def env
43
43
  @env ||= CFoundry::ChattyHash.new(
44
44
  method(:env=),
45
- JSON.parse(environment_json))
45
+ MultiJson.load(environment_json))
46
46
  end
47
47
 
48
48
  def env=(hash)
@@ -1,4 +1,4 @@
1
- require "json"
1
+ require "multi_json"
2
2
  require "base64"
3
3
 
4
4
  require "cfoundry/baseclient"
@@ -84,7 +84,7 @@ module CFoundry::V2
84
84
 
85
85
  def upload_app(guid, zipfile, resources = [])
86
86
  payload = {
87
- :resources => resources.to_json,
87
+ :resources => MultiJson.dump(resources),
88
88
  :multipart => true,
89
89
  :application =>
90
90
  if zipfile.is_a? File
@@ -149,7 +149,7 @@ module CFoundry::V2
149
149
  begin
150
150
  info = parse_json(response)
151
151
  raise CFoundry::APIError.new(info[:code], info[:description])
152
- rescue JSON::ParserError
152
+ rescue MultiJson::DecodeError
153
153
  raise CFoundry::BadResponse.new(response.code, response)
154
154
  end
155
155
 
@@ -1,3 +1,4 @@
1
+ require "multi_json"
1
2
  require "base64"
2
3
 
3
4
  require "cfoundry/v2/base"
@@ -61,6 +62,7 @@ module CFoundry::V2
61
62
  # printed out.
62
63
  def trace=(bool)
63
64
  @base.trace = bool
65
+ @base.uaa.trace = bool if @base.uaa
64
66
  end
65
67
 
66
68
  # The currently authenticated user.
@@ -199,7 +201,7 @@ module CFoundry::V2
199
201
  def token_data
200
202
  tok = Base64.decode64(@base.token.sub(/^bearer\s+/, ""))
201
203
  tok.sub!(/\{.+?\}/, "") # clear algo
202
- JSON.parse(tok[/\{.+?\}/], :symbolize_names => true)
204
+ MultiJson.load(tok[/\{.+?\}/], :symbolize_keys => true)
203
205
 
204
206
  # normally i don't catch'em all, but can't expect all tokens to be the
205
207
  # proper format, so just silently fail as this is not critical
@@ -1,3 +1,5 @@
1
+ require "multi_json"
2
+
1
3
  module CFoundry::V2
2
4
  class Model
3
5
  class << self
@@ -155,7 +157,7 @@ module CFoundry::V2
155
157
  end
156
158
  end
157
159
  elsif k.to_s.end_with?("_json") && v.is_a?(String)
158
- payload[k] = JSON.parse(v)
160
+ payload[k] = MultiJson.load(v)
159
161
  elsif k.to_s.end_with?("_url")
160
162
  else
161
163
  payload[k] = v
@@ -189,6 +191,8 @@ module CFoundry::V2
189
191
  if @manifest
190
192
  @manifest.delete :metadata
191
193
  end
194
+
195
+ true
192
196
  end
193
197
 
194
198
  def exists?
@@ -2,9 +2,6 @@ require "cfoundry/v2/model"
2
2
 
3
3
  module CFoundry::V2
4
4
  class ServiceBinding < Model
5
- attribute :credentials
6
- attribute :binding_options, :default => {}
7
- attribute :gateway_data, :default => {}
8
5
  to_one :app
9
6
  to_one :service_instance
10
7
  end
@@ -6,7 +6,5 @@ module CFoundry::V2
6
6
  to_one :space
7
7
  to_one :service_plan
8
8
  to_many :service_bindings
9
- attribute :credentials
10
- attribute :gateway_data, :default => {}
11
9
  end
12
10
  end
@@ -1,4 +1,4 @@
1
1
  module CFoundry # :nodoc:
2
2
  # CFoundry library version number.
3
- VERSION = "0.3.20"
3
+ VERSION = "0.3.21"
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: 59
4
+ hash: 57
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 20
10
- version: 0.3.20
9
+ - 21
10
+ version: 0.3.21
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-08-15 00:00:00 Z
18
+ date: 2012-08-21 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: rest-client
@@ -34,19 +34,19 @@ dependencies:
34
34
  type: :runtime
35
35
  version_requirements: *id001
36
36
  - !ruby/object:Gem::Dependency
37
- name: json_pure
37
+ name: multi_json
38
38
  prerelease: false
39
39
  requirement: &id002 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ~>
43
43
  - !ruby/object:Gem::Version
44
- hash: 5
44
+ hash: 23
45
45
  segments:
46
46
  - 1
47
+ - 3
47
48
  - 6
48
- - 5
49
- version: 1.6.5
49
+ version: 1.3.6
50
50
  type: :runtime
51
51
  version_requirements: *id002
52
52
  - !ruby/object:Gem::Dependency