cfoundry 4.3.2.rc1 → 4.3.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,7 +5,7 @@ module CcApiStub
5
5
  class << self
6
6
  def succeed_to_load(options={})
7
7
  response_body = Helper.load_fixtures(options.delete(:fixture) || "fake_cc_#{object_name}", options)
8
- stub_get(object_endpoint, {}, response(200, response_body))
8
+ stub_get(object_endpoint(options[:id]), {}, response(200, response_body))
9
9
  end
10
10
 
11
11
  def succeed_to_create
@@ -15,7 +15,7 @@ module CcApiStub
15
15
 
16
16
  def succeed_to_update(options={})
17
17
  response_body = Helper.load_fixtures(:fake_cc_application, options)
18
- stub_put(object_endpoint, nil, response(200, response_body))
18
+ stub_put(object_endpoint(options[:id]), nil, response(200, response_body))
19
19
  end
20
20
 
21
21
  def succeed_to_map_route
@@ -45,8 +45,8 @@ module CcApiStub
45
45
 
46
46
  private
47
47
 
48
- def object_endpoint
49
- %r{/v2/apps/[^/]+$}
48
+ def object_endpoint(id = nil)
49
+ %r{/v2/apps/#{id}[^/]+$}
50
50
  end
51
51
  end
52
52
  end
@@ -24,8 +24,8 @@ module CcApiStub
24
24
 
25
25
  private
26
26
 
27
- def object_endpoint
28
- %r{/v2/domains/[^/]+$}
27
+ def object_endpoint(id = nil)
28
+ %r{/v2/domains/#{id}[^/]+$}
29
29
  end
30
30
  end
31
31
  end
@@ -91,16 +91,16 @@ module CcApiStub
91
91
  end
92
92
 
93
93
  def succeed_to_load(options={})
94
- response_body = CcApiStub::Helper.load_fixtures(options.delete(:fixture) || "fake_cc_#{object_name}", options)
95
- stub_get(object_endpoint, {}, response(200, response_body))
94
+ response_body = options[:response] || CcApiStub::Helper.load_fixtures(options.delete(:fixture) || "fake_cc_#{object_name}", options)
95
+ stub_get(object_endpoint(options[:id]), {}, response(200, response_body))
96
96
  end
97
97
 
98
- def fail_to_load
99
- stub_get(object_endpoint, {}, response(500))
98
+ def fail_to_load(options = {})
99
+ stub_get(object_endpoint(options[:id]), {}, response(500))
100
100
  end
101
101
 
102
102
  def succeed_to_load_many(options={})
103
- response_body = CcApiStub::Helper.load_fixtures(options.delete(:fixture) || "fake_cc_#{object_name.pluralize}", options)
103
+ response_body = options[:response] || CcApiStub::Helper.load_fixtures(options.delete(:fixture) || "fake_cc_#{object_name.pluralize}", options)
104
104
  stub_get(collection_endpoint, {}, response(200, response_body))
105
105
  end
106
106
 
@@ -118,12 +118,12 @@ module CcApiStub
118
118
  stub_post(collection_endpoint, {}, response(201, response_body))
119
119
  end
120
120
 
121
- def succeed_to_update(attributes = {})
122
- stub_put(object_endpoint, nil, response(200, {}))
121
+ def succeed_to_update(options = {})
122
+ stub_put(object_endpoint(options[:id]), nil, response(200, {}))
123
123
  end
124
124
 
125
- def succeed_to_delete
126
- stub_delete(object_endpoint, nil, response(200))
125
+ def succeed_to_delete(options = {})
126
+ stub_delete(object_endpoint(options[:id]), nil, response(200))
127
127
  end
128
128
 
129
129
  alias_method :succeed_to_leave, :succeed_to_delete
@@ -3,18 +3,18 @@ module CcApiStub
3
3
  extend Helper
4
4
 
5
5
  class << self
6
- def succeed_to_delete
7
- stub_delete(object_endpoint, {}, response(200, ""))
6
+ def succeed_to_delete(options = {})
7
+ stub_delete(object_endpoint(options[:id]), {}, response(200, ""))
8
8
  end
9
9
 
10
- def fail_to_delete
11
- stub_delete(object_endpoint, {}, response(500))
10
+ def fail_to_delete(options = {})
11
+ stub_delete(object_endpoint(options[:id]), {}, response(500))
12
12
  end
13
13
 
14
14
  private
15
15
 
16
- def object_endpoint
17
- %r{/v2/organizations/[^/]+/users/[^/]+$}
16
+ def object_endpoint(id = nil)
17
+ %r{/v2/organizations/[^/]+/users/#{id}[^/]+$}
18
18
  end
19
19
  end
20
20
  end
@@ -58,8 +58,8 @@ module CcApiStub
58
58
 
59
59
  private
60
60
 
61
- def object_endpoint
62
- %r{/v2/organizations/[^/]+$}
61
+ def object_endpoint(id = nil)
62
+ %r{/v2/organizations/#{id}[^/]+$}
63
63
  end
64
64
 
65
65
  def collection_endpoint
@@ -18,8 +18,8 @@ module CcApiStub
18
18
  %r{/v2/routes/?.*$}
19
19
  end
20
20
 
21
- def object_endpoint
22
- %r{/v2/routes/[^/]+$}
21
+ def object_endpoint(id = nil)
22
+ %r{/v2/routes/#{id}[^/]+$}
23
23
  end
24
24
  end
25
25
  end
@@ -10,8 +10,8 @@ module CcApiStub
10
10
 
11
11
  private
12
12
 
13
- def object_endpoint
14
- %r{/v2/service_bindings/[^/]+$}
13
+ def object_endpoint(id = nil)
14
+ %r{/v2/service_bindings/#{id}[^/]+$}
15
15
  end
16
16
 
17
17
  def collection_endpoint
@@ -10,8 +10,8 @@ module CcApiStub
10
10
 
11
11
  private
12
12
 
13
- def object_endpoint
14
- %r{/v2/service_instances/[^/]+$}
13
+ def object_endpoint(id = nil)
14
+ %r{/v2/service_instances/#{id}[^/]+$}
15
15
  end
16
16
 
17
17
  def collection_endpoint
@@ -5,7 +5,7 @@ module CcApiStub
5
5
  class << self
6
6
  def succeed_to_load(options={})
7
7
  response_body = Helper.load_fixtures(options.delete(:fixture) || "fake_cc_#{object_name}", options)
8
- stub_get(object_endpoint, {}, response(200, response_body))
8
+ stub_get(object_endpoint(options[:id]), {}, response(200, response_body))
9
9
  end
10
10
 
11
11
  def succeed_to_create
@@ -41,8 +41,8 @@ module CcApiStub
41
41
  %r{/v2/spaces$}
42
42
  end
43
43
 
44
- def object_endpoint
45
- %r{/v2/spaces/[^/]+$}
44
+ def object_endpoint(id = nil)
45
+ %r{/v2/spaces/#{id}[^/]+$}
46
46
  end
47
47
  end
48
48
  end
@@ -39,8 +39,8 @@ module CcApiStub
39
39
  stub_get(%r{/v2/users/[^/]+/summary(\?inline-relations-depth=\d)?$}, {}, response(200, response_body))
40
40
  end
41
41
 
42
- def fail_to_find
43
- stub_get(object_endpoint, {}, response(404, {:code => 20003, :description => "The user could not be found"}))
42
+ def fail_to_find(options = {})
43
+ stub_get(object_endpoint(options[:id]), {}, response(404, {:code => 20003, :description => "The user could not be found"}))
44
44
  end
45
45
 
46
46
  def succeed_to_create
@@ -52,12 +52,12 @@ module CcApiStub
52
52
  CcApiStub::Helper.fail_request(:post, 500, {}, /users/)
53
53
  end
54
54
 
55
- def succeed_to_replace_permissions
56
- stub_put(object_endpoint, {}, response(200, ""))
55
+ def succeed_to_replace_permissions(options = {})
56
+ stub_put(object_endpoint(options[:id]), {}, response(200, ""))
57
57
  end
58
58
 
59
- def fail_to_replace_permissions
60
- stub_put(object_endpoint, {}, response(500))
59
+ def fail_to_replace_permissions(options = {})
60
+ stub_put(object_endpoint(options[:id]), {}, response(500))
61
61
  end
62
62
 
63
63
  def organizations_fixture
@@ -77,8 +77,8 @@ module CcApiStub
77
77
  %r{/v2/users$}
78
78
  end
79
79
 
80
- def object_endpoint
81
- %r{/v2/users/[^/]+(/summary)?}
80
+ def object_endpoint(id = nil)
81
+ %r{/v2/users/#{id}[^/]+(/summary)?}
82
82
  end
83
83
  end
84
84
  end
@@ -36,6 +36,7 @@ module CFoundry::V2
36
36
  def files(guid, instance, *path)
37
37
  get("v2", "apps", guid, "instances", instance, "files", *path)
38
38
  end
39
+
39
40
  alias :file :files
40
41
 
41
42
  def stream_file(guid, instance, *path, &blk)
@@ -68,14 +69,20 @@ module CFoundry::V2
68
69
  :return_response => true)
69
70
  end
70
71
 
71
- def all_pages(paginated)
72
- payload = paginated[:resources]
72
+ def for_each(paginated, &block)
73
+ paginated[:resources].each &block
73
74
 
74
75
  while next_page = paginated[:next_url]
75
76
  paginated = get(next_page, :accept => :json)
76
- payload += paginated[:resources]
77
+ paginated[:resources].each &block
77
78
  end
79
+ end
78
80
 
81
+ def all_pages(paginated)
82
+ payload = []
83
+ for_each(paginated) do |resource|
84
+ payload << resource
85
+ end
79
86
  payload
80
87
  end
81
88
  end
@@ -38,6 +38,18 @@ module CFoundry
38
38
  :params => ModelMagic.params_from(args)
39
39
  )
40
40
  end
41
+
42
+ #
43
+ # def client.MODELs_for_each
44
+ #
45
+ define_method(:"#{plural}_for_each") do |*args, &block|
46
+ for_each(get("v2", plural,
47
+ :accept => :json,
48
+ :params => ModelMagic.params_from(args)
49
+ ),
50
+ &block
51
+ )
52
+ end
41
53
  end
42
54
 
43
55
 
@@ -94,6 +106,16 @@ module CFoundry
94
106
  }
95
107
  end
96
108
 
109
+ #
110
+ # def client.MODELs_for_each
111
+ #
112
+ define_method(:"#{plural}_for_each") do |*args, &block|
113
+ @base.send(:"#{plural}_for_each", *args) do |json|
114
+ result = send(:"make_#{singular}", json)
115
+ block.call(result)
116
+ end
117
+ end
118
+
97
119
  #
98
120
  # def client.MODEL_from
99
121
  #
@@ -1,4 +1,4 @@
1
1
  module CFoundry # :nodoc:
2
2
  # CFoundry library version number.
3
- VERSION = "4.3.2.rc1".freeze
3
+ VERSION = "4.3.3".freeze
4
4
  end
@@ -384,6 +384,33 @@ module CFoundry
384
384
  end
385
385
  end
386
386
  end
387
+
388
+ describe "for_each" do
389
+
390
+ before do
391
+ WebMock.stub_request(:get, /v2\/test_models/).to_return(:body => {
392
+ "prev_url" => nil,
393
+ "next_url" => "/v2/test_models?&page=2&results-per-page=50",
394
+ "resources" => [{:metadata => {:guid => '1'}}, {:metadata => {:guid => '2'}}]
395
+ }.to_json).times(1)
396
+
397
+ WebMock.stub_request(:get, /v2\/test_models\?page=2&results-per-page=50/).to_return(:body => {
398
+ "prev_url" => nil,
399
+ "next_url" => nil,
400
+ "resources" => [{:metadata => {:guid => '3'}}]
401
+ }.to_json).times(1)
402
+ end
403
+
404
+ it "yields each page to the given the block" do
405
+ results = []
406
+ client.test_models_for_each do |test_model|
407
+ results << test_model
408
+ end
409
+ results.collect {|r| r.guid}.should == %w{1 2 3}
410
+ results.first.should be_a TestModel
411
+ end
412
+ end
413
+
387
414
  end
388
415
  end
389
416
  end
@@ -1,3 +1,4 @@
1
- # errors
1
+ cf-errors
2
+ =========
2
3
 
3
- Shared error codes and messages for Cloud Foundry
4
+ Shared error codes and messages for Cloud Foundry
@@ -153,21 +153,6 @@
153
153
  http_code: 400
154
154
  message: "The service instance cannot be created because paid service plans are not allowed."
155
155
 
156
- 60008:
157
- name: ServiceInstanceDuplicateNotAllowed
158
- http_code: 400
159
- message: "An instance of this service is already present in this space. Some services only support one instance per space."
160
-
161
- 60009:
162
- name: ServiceInstanceNameTooLong
163
- http_code: 400
164
- message: "You have requested an invalid service instance name. Names are limited to 50 characters."
165
-
166
- 60010:
167
- name: ServiceInstanceOrganizationNotAuthorized
168
- http_code: 403
169
- message: A service instance for the selected plan cannot be created in this organization. The plan is visible because another organization you belong to has access to it.
170
-
171
156
  70001:
172
157
  name: RuntimeInvalid
173
158
  http_code: 400
@@ -218,11 +203,6 @@
218
203
  http_code: 404
219
204
  message: "The service binding could not be found: %s"
220
205
 
221
- 90005:
222
- name: UnbindableService
223
- http_code: 400
224
- message: "The service doesn't support binding."
225
-
226
206
  100001:
227
207
  name: AppInvalid
228
208
  http_code: 400
@@ -243,11 +223,6 @@
243
223
  http_code: 400
244
224
  message: "You have exceeded your organization's memory limit. Please login to your account and upgrade. If you are trying to scale down and you are receiving this error, you can either delete an app or contact support."
245
225
 
246
- 100006:
247
- name: AppMemoryInvalid
248
- http_code: 400
249
- message: "You have specified an invalid amount of memory for your application."
250
-
251
226
  110001:
252
227
  name: ServicePlanInvalid
253
228
  http_code: 400
@@ -378,11 +353,6 @@
378
353
  http_code: 400
379
354
  message: "Billing event query start_date and/or end_date are missing or invalid"
380
355
 
381
- 230002:
382
- name: EventNotFound
383
- http_code: 404
384
- message: "Event could not be found: %s"
385
-
386
356
  240001:
387
357
  name: QuotaDefinitionNotFound
388
358
  http_code: 404
@@ -412,28 +382,3 @@
412
382
  name: StackNotFound
413
383
  http_code: 404
414
384
  message: "The stack could not be found: %s"
415
-
416
- 260001:
417
- name: ServicePlanVisibilityInvalid
418
- http_code: 400
419
- message: "Service Plan Visibility is invalid: %s"
420
-
421
- 260002:
422
- name: ServicePlanVisibilityAlreadyExists
423
- http_code: 400
424
- message: "This combination of ServicePlan and Organization is already taken: %s"
425
-
426
- 270001:
427
- name: ServiceBrokerInvalid
428
- http_code: 400
429
- message: "Service Broker is invalid: %s"
430
-
431
- 270002:
432
- name: ServiceBrokerNameTaken
433
- http_code: 400
434
- message: "The service broker name is taken: %s"
435
-
436
- 270003:
437
- name: ServiceBrokerUrlTaken
438
- http_code: 400
439
- message: "The service broker url is taken: %s"
metadata CHANGED
@@ -1,8 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cfoundry
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.3.2.rc1
5
- prerelease: 6
4
+ version: 4.3.3
5
+ prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Cloud Foundry Team
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-08-12 00:00:00.000000000 Z
13
+ date: 2013-08-13 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activemodel
@@ -449,13 +449,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
449
449
  version: '0'
450
450
  segments:
451
451
  - 0
452
- hash: 1896093328470718340
452
+ hash: -4449691735648661788
453
453
  required_rubygems_version: !ruby/object:Gem::Requirement
454
454
  none: false
455
455
  requirements:
456
- - - ! '>'
456
+ - - ! '>='
457
457
  - !ruby/object:Gem::Version
458
- version: 1.3.1
458
+ version: '0'
459
+ segments:
460
+ - 0
461
+ hash: -4449691735648661788
459
462
  requirements: []
460
463
  rubyforge_project: cfoundry
461
464
  rubygems_version: 1.8.25