cfoundry 0.5.1.rc1 → 0.5.1.rc2

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,10 +3,10 @@ require "multi_json"
3
3
 
4
4
  module CFoundry
5
5
  # Base class for CFoundry errors (not from the server).
6
- class Error < RuntimeError;
6
+ class Error < RuntimeError
7
7
  end
8
8
 
9
- class Deprecated < Error;
9
+ class Deprecated < Error
10
10
  end
11
11
 
12
12
  class Mismatch < Error
@@ -20,6 +20,18 @@ module CFoundry
20
20
  end
21
21
  end
22
22
 
23
+ class InvalidTarget < Error
24
+ attr_reader :target
25
+
26
+ def initialize(target)
27
+ @target = target
28
+ end
29
+
30
+ def to_s
31
+ "Invalid target URI: #{@target}"
32
+ end
33
+ end
34
+
23
35
  class TargetRefused < Error
24
36
  # Error message.
25
37
  attr_reader :message
@@ -68,6 +68,10 @@ module CFoundry
68
68
  def request_uri(method, uri, options = {})
69
69
  uri = URI.parse(uri)
70
70
 
71
+ unless uri.is_a?(URI::HTTP)
72
+ raise InvalidTarget.new(@target)
73
+ end
74
+
71
75
  # keep original options in case there's a redirect to follow
72
76
  original_options = options.dup
73
77
  payload = options[:payload]
@@ -148,6 +152,8 @@ module CFoundry
148
152
  raise Timeout.new(method, uri, e)
149
153
  rescue SocketError, Errno::ECONNREFUSED => e
150
154
  raise TargetRefused, e.message
155
+ rescue URI::InvalidURIError
156
+ raise InvalidTarget.new(@target)
151
157
  end
152
158
 
153
159
  def construct_url(path)
@@ -1,4 +1,4 @@
1
1
  module CFoundry # :nodoc:
2
2
  # CFoundry library version number.
3
- VERSION = "0.5.1.rc1".freeze
3
+ VERSION = "0.5.1.rc2".freeze
4
4
  end
@@ -12,6 +12,14 @@ describe 'Errors' do
12
12
  its(:parent) { should eq parent }
13
13
  end
14
14
 
15
+ describe CFoundry::InvalidTarget do
16
+ let(:target) { "http://--foo-bar" }
17
+ subject { CFoundry::InvalidTarget.new(target) }
18
+
19
+ its(:to_s) { should eq "Invalid target URI: #{target}"}
20
+ its(:target) { should eq target }
21
+ end
22
+
15
23
  describe CFoundry::APIError do
16
24
  let(:request) { { :method => "GET", :url => "http://api.cloudfoundry.com/foo", :headers => {} } }
17
25
  let(:response_body) { "NOT FOUND" }
@@ -2,11 +2,12 @@ require 'spec_helper'
2
2
 
3
3
  describe CFoundry::RestClient do
4
4
  let(:token) { nil }
5
- let(:rest_client) { CFoundry::RestClient.new("https://api.cloudfoundry.com", token) }
5
+ let(:target) { "https://api.cloudfoundry.com" }
6
+ let(:rest_client) { CFoundry::RestClient.new(target, token) }
6
7
 
7
8
  describe '#request' do
8
9
  let(:path) { "some-path" }
9
- let(:url) { "https://api.cloudfoundry.com/some-path" }
10
+ let(:url) { "#{target}/#{path}" }
10
11
  let(:method) { "GET" }
11
12
  let(:options) { {} }
12
13
 
@@ -142,6 +143,30 @@ describe CFoundry::RestClient do
142
143
  end
143
144
 
144
145
  describe 'errors' do
146
+ context "when the target refuses the connection" do
147
+ let(:target) { "http://localhost:2358974958" }
148
+
149
+ it "raises CFoundry::TargetRefused" do
150
+ stub_request(:get, url).to_raise(Errno::ECONNREFUSED)
151
+ expect { subject }.to raise_error(CFoundry::TargetRefused)
152
+ end
153
+ end
154
+
155
+ context "when the target is not a HTTP(S) URI" do
156
+ let(:target) { "ftp://foo-bar.com" }
157
+
158
+ it "raises CFoundry::InvalidTarget" do
159
+ expect { subject }.to raise_error(CFoundry::InvalidTarget)
160
+ end
161
+ end
162
+
163
+ context "when the target URI is invalid" do
164
+ let(:target) { "@#*#^! rubby" }
165
+
166
+ it "raises CFoundry::InvalidTarget" do
167
+ expect { subject }.to raise_error(CFoundry::InvalidTarget)
168
+ end
169
+ end
145
170
  end
146
171
 
147
172
  describe "the return value" do
metadata CHANGED
@@ -1,184 +1,184 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: cfoundry
3
- version: !ruby/object:Gem::Version
4
- hash: 3470363275
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.1.rc2
5
5
  prerelease: 6
6
- segments:
7
- - 0
8
- - 5
9
- - 1
10
- - rc
11
- - 1
12
- version: 0.5.1.rc1
13
6
  platform: ruby
14
- authors:
7
+ authors:
15
8
  - Cloud Foundry Team
16
9
  - Alex Suraci
17
10
  autorequire:
18
11
  bindir: bin
19
12
  cert_chain: []
20
-
21
- date: 2013-02-20 00:00:00 Z
22
- dependencies:
23
- - !ruby/object:Gem::Dependency
24
- version_requirements: &id001 !ruby/object:Gem::Requirement
13
+ date: 2013-02-20 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: multipart-post
17
+ requirement: !ruby/object:Gem::Requirement
25
18
  none: false
26
- requirements:
19
+ requirements:
27
20
  - - ~>
28
- - !ruby/object:Gem::Version
29
- hash: 13
30
- segments:
31
- - 1
32
- - 1
33
- version: "1.1"
34
- prerelease: false
21
+ - !ruby/object:Gem::Version
22
+ version: '1.1'
35
23
  type: :runtime
36
- name: multipart-post
37
- requirement: *id001
38
- - !ruby/object:Gem::Dependency
39
- version_requirements: &id002 !ruby/object:Gem::Requirement
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
40
26
  none: false
41
- requirements:
27
+ requirements:
42
28
  - - ~>
43
- - !ruby/object:Gem::Version
44
- hash: 9
45
- segments:
46
- - 1
47
- - 3
48
- version: "1.3"
49
- prerelease: false
50
- type: :runtime
29
+ - !ruby/object:Gem::Version
30
+ version: '1.1'
31
+ - !ruby/object:Gem::Dependency
51
32
  name: multi_json
52
- requirement: *id002
53
- - !ruby/object:Gem::Dependency
54
- version_requirements: &id003 !ruby/object:Gem::Requirement
33
+ requirement: !ruby/object:Gem::Requirement
55
34
  none: false
56
- requirements:
35
+ requirements:
57
36
  - - ~>
58
- - !ruby/object:Gem::Version
59
- hash: 25
60
- segments:
61
- - 0
62
- - 9
63
- version: "0.9"
64
- prerelease: false
37
+ - !ruby/object:Gem::Version
38
+ version: '1.3'
65
39
  type: :runtime
40
+ prerelease: false
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ~>
45
+ - !ruby/object:Gem::Version
46
+ version: '1.3'
47
+ - !ruby/object:Gem::Dependency
66
48
  name: rubyzip
67
- requirement: *id003
68
- - !ruby/object:Gem::Dependency
69
- version_requirements: &id004 !ruby/object:Gem::Requirement
49
+ requirement: !ruby/object:Gem::Requirement
70
50
  none: false
71
- requirements:
51
+ requirements:
72
52
  - - ~>
73
- - !ruby/object:Gem::Version
74
- hash: 29
75
- segments:
76
- - 1
77
- - 3
78
- - 3
79
- version: 1.3.3
80
- prerelease: false
53
+ - !ruby/object:Gem::Version
54
+ version: '0.9'
81
55
  type: :runtime
56
+ prerelease: false
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ~>
61
+ - !ruby/object:Gem::Version
62
+ version: '0.9'
63
+ - !ruby/object:Gem::Dependency
82
64
  name: cf-uaa-lib
83
- requirement: *id004
84
- - !ruby/object:Gem::Dependency
85
- version_requirements: &id005 !ruby/object:Gem::Requirement
65
+ requirement: !ruby/object:Gem::Requirement
86
66
  none: false
87
- requirements:
67
+ requirements:
88
68
  - - ~>
89
- - !ruby/object:Gem::Version
90
- hash: 25
91
- segments:
92
- - 0
93
- - 9
94
- version: "0.9"
69
+ - !ruby/object:Gem::Version
70
+ version: 1.3.3
71
+ type: :runtime
95
72
  prerelease: false
96
- type: :development
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ~>
77
+ - !ruby/object:Gem::Version
78
+ version: 1.3.3
79
+ - !ruby/object:Gem::Dependency
97
80
  name: rake
98
- requirement: *id005
99
- - !ruby/object:Gem::Dependency
100
- version_requirements: &id006 !ruby/object:Gem::Requirement
81
+ requirement: !ruby/object:Gem::Requirement
101
82
  none: false
102
- requirements:
83
+ requirements:
103
84
  - - ~>
104
- - !ruby/object:Gem::Version
105
- hash: 21
106
- segments:
107
- - 2
108
- - 11
109
- version: "2.11"
110
- prerelease: false
85
+ - !ruby/object:Gem::Version
86
+ version: '0.9'
111
87
  type: :development
88
+ prerelease: false
89
+ version_requirements: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ~>
93
+ - !ruby/object:Gem::Version
94
+ version: '0.9'
95
+ - !ruby/object:Gem::Dependency
112
96
  name: rspec
113
- requirement: *id006
114
- - !ruby/object:Gem::Dependency
115
- version_requirements: &id007 !ruby/object:Gem::Requirement
97
+ requirement: !ruby/object:Gem::Requirement
116
98
  none: false
117
- requirements:
99
+ requirements:
118
100
  - - ~>
119
- - !ruby/object:Gem::Version
120
- hash: 29
121
- segments:
122
- - 1
123
- - 9
124
- version: "1.9"
125
- prerelease: false
101
+ - !ruby/object:Gem::Version
102
+ version: '2.11'
126
103
  type: :development
104
+ prerelease: false
105
+ version_requirements: !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ~>
109
+ - !ruby/object:Gem::Version
110
+ version: '2.11'
111
+ - !ruby/object:Gem::Dependency
127
112
  name: webmock
128
- requirement: *id007
129
- - !ruby/object:Gem::Dependency
130
- version_requirements: &id008 !ruby/object:Gem::Requirement
113
+ requirement: !ruby/object:Gem::Requirement
131
114
  none: false
132
- requirements:
115
+ requirements:
133
116
  - - ~>
134
- - !ruby/object:Gem::Version
135
- hash: 15
136
- segments:
137
- - 1
138
- - 0
139
- version: "1.0"
140
- prerelease: false
117
+ - !ruby/object:Gem::Version
118
+ version: '1.9'
141
119
  type: :development
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ none: false
123
+ requirements:
124
+ - - ~>
125
+ - !ruby/object:Gem::Version
126
+ version: '1.9'
127
+ - !ruby/object:Gem::Dependency
142
128
  name: rr
143
- requirement: *id008
144
- - !ruby/object:Gem::Dependency
145
- version_requirements: &id009 !ruby/object:Gem::Requirement
129
+ requirement: !ruby/object:Gem::Requirement
146
130
  none: false
147
- requirements:
148
- - - ">="
149
- - !ruby/object:Gem::Version
150
- hash: 3
151
- segments:
152
- - 0
153
- version: "0"
154
- prerelease: false
131
+ requirements:
132
+ - - ~>
133
+ - !ruby/object:Gem::Version
134
+ version: '1.0'
155
135
  type: :development
136
+ prerelease: false
137
+ version_requirements: !ruby/object:Gem::Requirement
138
+ none: false
139
+ requirements:
140
+ - - ~>
141
+ - !ruby/object:Gem::Version
142
+ version: '1.0'
143
+ - !ruby/object:Gem::Dependency
156
144
  name: gem-release
157
- requirement: *id009
158
- - !ruby/object:Gem::Dependency
159
- version_requirements: &id010 !ruby/object:Gem::Requirement
145
+ requirement: !ruby/object:Gem::Requirement
160
146
  none: false
161
- requirements:
162
- - - ">="
163
- - !ruby/object:Gem::Version
164
- hash: 3
165
- segments:
166
- - 0
167
- version: "0"
168
- prerelease: false
147
+ requirements:
148
+ - - ! '>='
149
+ - !ruby/object:Gem::Version
150
+ version: '0'
169
151
  type: :development
152
+ prerelease: false
153
+ version_requirements: !ruby/object:Gem::Requirement
154
+ none: false
155
+ requirements:
156
+ - - ! '>='
157
+ - !ruby/object:Gem::Version
158
+ version: '0'
159
+ - !ruby/object:Gem::Dependency
170
160
  name: timecop
171
- requirement: *id010
161
+ requirement: !ruby/object:Gem::Requirement
162
+ none: false
163
+ requirements:
164
+ - - ! '>='
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ type: :development
168
+ prerelease: false
169
+ version_requirements: !ruby/object:Gem::Requirement
170
+ none: false
171
+ requirements:
172
+ - - ! '>='
173
+ - !ruby/object:Gem::Version
174
+ version: '0'
172
175
  description:
173
- email:
176
+ email:
174
177
  - vcap-dev@googlegroups.com
175
178
  executables: []
176
-
177
179
  extensions: []
178
-
179
180
  extra_rdoc_files: []
180
-
181
- files:
181
+ files:
182
182
  - LICENSE
183
183
  - Rakefile
184
184
  - lib/cfoundry/auth_token.rb
@@ -269,40 +269,29 @@ files:
269
269
  - spec/support/v1_fake_helper.rb
270
270
  homepage: http://github.com/cloudfoundry/vmc-lib
271
271
  licenses: []
272
-
273
272
  post_install_message:
274
273
  rdoc_options: []
275
-
276
- require_paths:
274
+ require_paths:
277
275
  - lib
278
- required_ruby_version: !ruby/object:Gem::Requirement
276
+ required_ruby_version: !ruby/object:Gem::Requirement
279
277
  none: false
280
- requirements:
281
- - - ">="
282
- - !ruby/object:Gem::Version
283
- hash: 3
284
- segments:
285
- - 0
286
- version: "0"
287
- required_rubygems_version: !ruby/object:Gem::Requirement
278
+ requirements:
279
+ - - ! '>='
280
+ - !ruby/object:Gem::Version
281
+ version: '0'
282
+ required_rubygems_version: !ruby/object:Gem::Requirement
288
283
  none: false
289
- requirements:
290
- - - ">"
291
- - !ruby/object:Gem::Version
292
- hash: 25
293
- segments:
294
- - 1
295
- - 3
296
- - 1
284
+ requirements:
285
+ - - ! '>'
286
+ - !ruby/object:Gem::Version
297
287
  version: 1.3.1
298
288
  requirements: []
299
-
300
289
  rubyforge_project: cfoundry
301
- rubygems_version: 1.8.24
290
+ rubygems_version: 1.8.23
302
291
  signing_key:
303
292
  specification_version: 3
304
293
  summary: High-level library for working with the Cloud Foundry API.
305
- test_files:
294
+ test_files:
306
295
  - spec/cfoundry/auth_token_spec.rb
307
296
  - spec/cfoundry/baseclient_spec.rb
308
297
  - spec/cfoundry/client_spec.rb