cfoundry 0.3.6 → 0.3.7

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.
@@ -78,25 +78,25 @@ module CFoundry
78
78
 
79
79
  RestClient::Request.execute(req) do |response, request|
80
80
  if @trace
81
- puts '>>>'
82
- puts "PROXY: #{RestClient.proxy}" if RestClient.proxy
83
- puts "REQUEST: #{req[:method]} #{req[:url]}"
84
- puts "RESPONSE_HEADERS:"
81
+ $stderr.puts '>>>'
82
+ $stderr.puts "PROXY: #{RestClient.proxy}" if RestClient.proxy
83
+ $stderr.puts "REQUEST: #{req[:method]} #{req[:url]}"
84
+ $stderr.puts "RESPONSE_HEADERS:"
85
85
  response.headers.each do |key, value|
86
- puts " #{key} : #{value}"
86
+ $stderr.puts " #{key} : #{value}"
87
87
  end
88
- puts "REQUEST_HEADERS:"
88
+ $stderr.puts "REQUEST_HEADERS:"
89
89
  request.headers.each do |key, value|
90
- puts " #{key} : #{value}"
90
+ $stderr.puts " #{key} : #{value}"
91
91
  end
92
- puts "REQUEST_BODY: #{req[:payload]}" if req[:payload]
93
- puts "RESPONSE: [#{response.code}]"
92
+ $stderr.puts "REQUEST_BODY: #{req[:payload]}" if req[:payload]
93
+ $stderr.puts "RESPONSE: [#{response.code}]"
94
94
  begin
95
- puts JSON.pretty_generate(JSON.parse(response.body))
95
+ $stderr.puts JSON.pretty_generate(JSON.parse(response.body))
96
96
  rescue
97
- puts "#{response.body}"
97
+ $stderr.puts "#{response.body}"
98
98
  end
99
- puts '<<<'
99
+ $stderr.puts '<<<'
100
100
  end
101
101
 
102
102
  handle_response(response, accept)
@@ -114,7 +114,7 @@ module CFoundry::V1
114
114
  def update!(what = {})
115
115
  # bleh. have to set these here (normally in :meta) or they'll get lost.
116
116
  what[:debug] = debug_mode
117
- what[:staging] = (what[:staging] || {}).merge(manifest[:staging])
117
+ what[:staging] = (what[:staging] || {}).merge(manifest[:staging] || {})
118
118
  what[:staging][:command] = command if command
119
119
 
120
120
  @client.base.update_app(@name, manifest.merge(what))
@@ -233,6 +233,8 @@ module CFoundry::V1
233
233
 
234
234
  # Application framework.
235
235
  def framework
236
+ return unless manifest[:staging]
237
+
236
238
  Framework.new(
237
239
  manifest[:staging][:framework] ||
238
240
  manifest[:staging][:model])
@@ -253,6 +255,8 @@ module CFoundry::V1
253
255
 
254
256
  # Application runtime.
255
257
  def runtime
258
+ return unless manifest[:staging]
259
+
256
260
  Framework.new(
257
261
  manifest[:staging][:runtime] ||
258
262
  manifest[:staging][:stack])
@@ -276,6 +280,8 @@ module CFoundry::V1
276
280
  #
277
281
  # Used for standalone apps.
278
282
  def command
283
+ return unless manifest[:staging] || manifest[:meta]
284
+
279
285
  manifest[:staging][:command] ||
280
286
  manifest[:meta][:command]
281
287
  end
@@ -289,6 +295,8 @@ module CFoundry::V1
289
295
 
290
296
  # Application memory.
291
297
  def memory
298
+ return unless manifest[:resources]
299
+
292
300
  manifest[:resources][:memory]
293
301
  end
294
302
 
@@ -53,6 +53,14 @@ module CFoundry::V1
53
53
  end
54
54
  end
55
55
 
56
+ def current_space
57
+ nil
58
+ end
59
+
60
+ def current_organization
61
+ nil
62
+ end
63
+
56
64
 
57
65
  # Retrieve target metadata.
58
66
  def info
@@ -19,7 +19,7 @@ module CFoundry::V2
19
19
  class App < Model
20
20
  attribute :name
21
21
  attribute :production
22
- to_one :app_space
22
+ to_one :space
23
23
  to_one :runtime
24
24
  to_one :framework
25
25
  attribute :environment_json, :default => {}
@@ -36,9 +36,6 @@ module CFoundry::V2
36
36
  alias :services :service_bindings
37
37
  alias :services= :service_bindings=
38
38
 
39
- alias :space :app_space
40
- alias :space= :app_space=
41
-
42
39
  private :environment_json, :environment_json=
43
40
 
44
41
  def env
@@ -46,7 +46,7 @@ module CFoundry::V2
46
46
  end
47
47
 
48
48
 
49
- [ :app, :organization, :app_space, :user, :runtime, :framework,
49
+ [ :app, :organization, :space, :user, :runtime, :framework,
50
50
  :service, :service_plan, :service_binding, :service_instance
51
51
  ].each do |obj|
52
52
  plural = "#{obj}s"
@@ -87,12 +87,6 @@ module CFoundry::V2
87
87
  end
88
88
  end
89
89
 
90
- alias :spaces :app_spaces
91
- alias :space :app_space
92
- alias :update_space :update_app_space
93
- alias :delete_space :delete_app_space
94
- alias :create_space :create_app_space
95
-
96
90
  private
97
91
 
98
92
  def handle_response(response, accept)
@@ -123,7 +123,7 @@ module CFoundry::V2
123
123
  end
124
124
 
125
125
 
126
- [ :app, :organization, :app_space, :user, :runtime, :framework,
126
+ [ :app, :organization, :space, :user, :runtime, :framework,
127
127
  :service, :service_plan, :service_binding, :service_instance
128
128
  ].each do |singular|
129
129
  klass = singular.to_s.capitalize.gsub(/(.)_(.)/) do
@@ -132,21 +132,21 @@ module CFoundry::V2
132
132
 
133
133
  plural = :"#{singular}s"
134
134
 
135
- has_app_space =
136
- CFoundry::V2.const_get(klass).method_defined? :app_space
135
+ has_space =
136
+ CFoundry::V2.const_get(klass).method_defined? :space
137
137
 
138
138
  define_method(singular) do |*args|
139
- id, _ = args
140
- CFoundry::V2.const_get(klass).new(id, self)
139
+ guid, _ = args
140
+ CFoundry::V2.const_get(klass).new(guid, self)
141
141
  end
142
142
 
143
143
  define_method(plural) do |*args|
144
144
  depth, query = args
145
145
  depth ||= 1
146
146
 
147
- if has_app_space
147
+ if has_space && current_space
148
148
  query ||= {}
149
- query[:app_space_guid] ||= current_space.id
149
+ query[:space_guid] ||= current_space.guid
150
150
  end
151
151
 
152
152
  @base.send(plural, depth, query)[:resources].collect do |json|
@@ -201,8 +201,5 @@ module CFoundry::V2
201
201
  json)
202
202
  end
203
203
  end
204
-
205
- alias :spaces :app_spaces
206
- alias :space :app_space
207
204
  end
208
205
  end
@@ -43,7 +43,7 @@ module CFoundry::V2
43
43
  @manifest ||= {}
44
44
  @manifest[:entity] ||= {}
45
45
  @manifest[:entity][:"#{name}_guid"] =
46
- @diff[:"#{name}_guid"] = x.id
46
+ @diff[:"#{name}_guid"] = x.guid
47
47
  }
48
48
  end
49
49
 
@@ -74,14 +74,14 @@ module CFoundry::V2
74
74
  define_method(:"add_#{singular}") { |x|
75
75
  @client.base.request_path(
76
76
  :put,
77
- ["v2", "#{object_name}s", @id, plural, x.id],
77
+ ["v2", "#{object_name}s", @guid, plural, x.guid],
78
78
  nil => :json)
79
79
  }
80
80
 
81
81
  define_method(:"remove_#{singular}") {
82
82
  @client.base.request_path(
83
83
  :delete,
84
- ["v2", "#{object_name}s", @id, plural, x.id],
84
+ ["v2", "#{object_name}s", @guid, plural, x.guid],
85
85
  nil => :json)
86
86
  }
87
87
 
@@ -89,15 +89,15 @@ module CFoundry::V2
89
89
  @manifest ||= {}
90
90
  @manifest[:entity] ||= {}
91
91
  @manifest[:entity][:"#{singular}_guids"] =
92
- @diff[:"#{singular}_guids"] = xs.collect(&:id)
92
+ @diff[:"#{singular}_guids"] = xs.collect(&:guid)
93
93
  }
94
94
  end
95
95
  end
96
96
 
97
- attr_reader :id
97
+ attr_reader :guid
98
98
 
99
- def initialize(id, client, manifest = nil)
100
- @id = id
99
+ def initialize(guid, client, manifest = nil)
100
+ @guid = guid
101
101
  @client = client
102
102
  @manifest = manifest
103
103
  @diff = {}
@@ -105,11 +105,11 @@ module CFoundry::V2
105
105
 
106
106
  def manifest
107
107
  # inline depth of 2 for fewer requests
108
- @manifest ||= @client.base.send(object_name, @id, 2)
108
+ @manifest ||= @client.base.send(object_name, @guid, 2)
109
109
  end
110
110
 
111
111
  def inspect
112
- "\#<#{self.class.name} '#@id'>"
112
+ "\#<#{self.class.name} '#@guid'>"
113
113
  end
114
114
 
115
115
  def object_name
@@ -125,19 +125,19 @@ module CFoundry::V2
125
125
  :"create_#{object_name}",
126
126
  self.class.defaults.merge(@manifest[:entity]))
127
127
 
128
- @id = @manifest[:metadata][:guid]
128
+ @guid = @manifest[:metadata][:guid]
129
129
 
130
130
  true
131
131
  end
132
132
 
133
133
  def update!(diff = @diff)
134
- @client.base.send(:"update_#{object_name}", @id, diff)
134
+ @client.base.send(:"update_#{object_name}", @guid, diff)
135
135
 
136
136
  @manifest = nil
137
137
  end
138
138
 
139
139
  def delete!
140
- @client.base.send(:"delete_#{object_name}", @id)
140
+ @client.base.send(:"delete_#{object_name}", @guid)
141
141
 
142
142
  if @manifest
143
143
  @manifest.delete :metadata
@@ -145,14 +145,14 @@ module CFoundry::V2
145
145
  end
146
146
 
147
147
  def exists?
148
- @client.base.send(object_name, @id)
148
+ @client.base.send(object_name, @guid)
149
149
  true
150
150
  rescue CFoundry::APIError # TODO: NotFound would be better
151
151
  false
152
152
  end
153
153
 
154
154
  def ==(other)
155
- other.is_a?(self.class) && @id == other.id
155
+ other.is_a?(self.class) && @guid == other.guid
156
156
  end
157
157
  end
158
158
  end
@@ -3,13 +3,11 @@ require "cfoundry/v2/model"
3
3
  module CFoundry::V2
4
4
  class Organization < Model
5
5
  attribute :name
6
- to_many :app_spaces
6
+ to_many :spaces
7
7
  to_many :domains
8
8
  to_many :users
9
9
  to_many :managers, :as => :user
10
10
  to_many :billing_managers, :as => :user
11
11
  to_many :auditors, :as => :user
12
-
13
- alias :spaces :app_spaces
14
12
  end
15
13
  end
@@ -3,13 +3,10 @@ require "cfoundry/v2/model"
3
3
  module CFoundry::V2
4
4
  class ServiceInstance < Model
5
5
  attribute :name
6
- to_one :app_space
6
+ to_one :space
7
7
  to_one :service_plan
8
8
  to_many :service_bindings
9
9
  attribute :credentials
10
10
  attribute :vendor_data, :default => ""
11
-
12
- alias :space :app_space
13
- alias :space= :app_space=
14
11
  end
15
12
  end
@@ -1,7 +1,7 @@
1
1
  require "cfoundry/v2/model"
2
2
 
3
3
  module CFoundry::V2
4
- class AppSpace < Model
4
+ class Space < Model
5
5
  attribute :name
6
6
  to_one :organization
7
7
  to_many :developers, :as => :user
@@ -2,24 +2,28 @@ require "cfoundry/v2/model"
2
2
 
3
3
  module CFoundry::V2
4
4
  class User < Model
5
- to_many :app_spaces
5
+ to_many :spaces
6
6
  to_many :organizations
7
7
  to_many :managed_organizations, :as => :organization
8
8
  to_many :billing_managed_organizations, :as => :organization
9
9
  to_many :audited_organizations, :as => :organization
10
- to_many :managed_app_spaces, :as => :app_space
11
- to_many :audited_app_spaces, :as => :app_space
10
+ to_many :managed_spaces, :as => :space
11
+ to_many :audited_spaces, :as => :space
12
12
  attribute :admin
13
- to_one :default_app_space, :as => :app_space
13
+ to_one :default_space, :as => :space
14
14
 
15
15
  attribute :guid # guid is explicitly set for users
16
16
 
17
- alias :admin? :admin
17
+ def guid
18
+ @guid
19
+ end
18
20
 
19
- alias :spaces :app_spaces
20
- alias :managed_spaces :managed_app_spaces
21
- alias :audited_spaces :audited_app_spaces
22
- alias :default_space :default_app_space
21
+ def guid=(x)
22
+ @guid = x
23
+ super
24
+ end
25
+
26
+ alias :admin? :admin
23
27
 
24
28
  # optional metadata from UAA
25
29
  attr_accessor :emails, :name
@@ -1,4 +1,4 @@
1
1
  module CFoundry # :nodoc:
2
2
  # CFoundry library version number.
3
- VERSION = "0.3.6"
3
+ VERSION = "0.3.7"
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: 31
4
+ hash: 29
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 6
10
- version: 0.3.6
9
+ - 7
10
+ version: 0.3.7
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-07-17 00:00:00 Z
18
+ date: 2012-07-19 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: rest-client