jamesn-softlayer-ruby 0.6.1.0 → 0.6.3.0

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.
Files changed (3) hide show
  1. data/Changes +6 -0
  2. data/lib/softlayer.rb +64 -30
  3. metadata +2 -2
data/Changes CHANGED
@@ -1,4 +1,10 @@
1
1
 
2
+ Change since 0.6.1
3
+
4
+ Silenced the name space warning (I think this is a bug in soap4r)
5
+ Created an exception class that's really used as a proxy for soap exceptions. This exception is
6
+ raised in a few places where needed.
7
+
2
8
  Changes since 0.6.0.
3
9
 
4
10
  Implement SoftLayer::Base#call to make dynamic method calls possible.
data/lib/softlayer.rb CHANGED
@@ -47,7 +47,7 @@ module SoftLayer
47
47
  def SoftLayer::declareClasses(args)
48
48
  classes = args[:ruby]
49
49
  services = args[:soap]
50
-
50
+
51
51
  unless (services.nil? || services.empty?)
52
52
  services.each do |s|
53
53
  c = s.gsub(/_/,'::')
@@ -60,7 +60,7 @@ module SoftLayer
60
60
  k.cacheWSDL
61
61
  end
62
62
  end
63
-
63
+
64
64
  # Create a Ruby class to match an SLAPI WSDL endpoint.
65
65
  # Args:
66
66
  # +class+:: The name of the class to create in Ruby format.
@@ -111,11 +111,11 @@ module SoftLayer
111
111
  def on_simple_outbound
112
112
  @out
113
113
  end
114
-
114
+
115
115
  def [](k)
116
116
  return @out[k]
117
117
  end
118
-
118
+
119
119
  def []=(k,v)
120
120
  @out[k]=v
121
121
  end
@@ -123,7 +123,7 @@ module SoftLayer
123
123
 
124
124
  # A class to hold the object mask.
125
125
  class ObjectMask < SOAP::Header::SimpleHandler
126
-
126
+
127
127
  def initialize(tag, out)
128
128
  @out = out
129
129
  super(XSD::QName.new(nil, tag))
@@ -132,19 +132,19 @@ module SoftLayer
132
132
  def on_simple_outbound
133
133
  { 'mask' => @out }
134
134
  end
135
-
135
+
136
136
  def [](k)
137
137
  @out[k]
138
138
  end
139
-
139
+
140
140
  def []=(k,v)
141
141
  @out[k]=v
142
142
  end
143
143
  end
144
-
144
+
145
145
  class ResultLimit < SOAP::Header::SimpleHandler
146
146
  attr_accessor :limit, :offset
147
-
147
+
148
148
  # limit should be an array of two elements; limit and offset.
149
149
  def initialize(tag, limit)
150
150
  @limit = limit[0]
@@ -157,6 +157,23 @@ module SoftLayer
157
157
  end
158
158
  end
159
159
 
160
+
161
+ # An Exception proxy class
162
+ # This doesn't do anything yet, but it probably
163
+ # will at some point.
164
+ class Exception < RuntimeError
165
+
166
+ def initialize(args)
167
+ e = args[:exception]
168
+ message = args[:message] unless args[:message].nil?
169
+ message = e.message unless e.nil?
170
+ super(message)
171
+
172
+ @realException = e unless e.nil?
173
+ @realException = self if @realException.nil?
174
+ end
175
+ end
176
+
160
177
  # The Base class for our generated class.
161
178
  class BaseClass
162
179
 
@@ -190,7 +207,9 @@ module SoftLayer
190
207
  @authHeader = Param.new('authenticate', {'username' => @apiUser, 'apiKey' => @apiKey})
191
208
 
192
209
  self.class.cacheWSDL
193
- @slapi = @@wsdl[self.soapClass].create_rpc_driver
210
+ @slapi = @@wsdl[self.soapClass].create_rpc_driver unless @@wsdl[self.soapClass].nil?
211
+ raise SoftLayer::Exception.new(:message => 'WSDL endpoint not available.') if @slapi.nil?
212
+
194
213
  self.debug=args[:debug] unless args[:debug].nil?
195
214
  end
196
215
 
@@ -204,7 +223,7 @@ module SoftLayer
204
223
  @slapiObject = self.getObject if @slapiobject.nil?
205
224
  return @slapiObject[key.to_s]
206
225
  end
207
-
226
+
208
227
  def setObject(obj)
209
228
  @slapiObject = obj
210
229
  end
@@ -236,11 +255,11 @@ module SoftLayer
236
255
  end
237
256
  @slapiObject = nil
238
257
  end
239
-
258
+
240
259
  def objectMask
241
260
  return @objectMask
242
261
  end
243
-
262
+
244
263
  # Set an object wide result set (or clear it)
245
264
  # arg can be one of three things:
246
265
  # * nil clears the resultLimit
@@ -256,11 +275,11 @@ module SoftLayer
256
275
  @resultLimit = arg
257
276
  end
258
277
  end
259
-
278
+
260
279
  def resultLimit
261
280
  return @resultLimit
262
281
  end
263
-
282
+
264
283
 
265
284
  # Make a direct api call. Paramaters are a hash where the key is passed to ParamHeader as the tag, and the value
266
285
  # is passed as the tag content, unless it's a magic paramater.
@@ -273,7 +292,7 @@ module SoftLayer
273
292
  # is exhausted. If no limit is provided with the block a limit of [1,0] is assumed initially.
274
293
  # Aliased to #method_missing.
275
294
  def slapiCall(method, args = { }, &block)
276
-
295
+
277
296
  initParam = args[:initParam] unless args[:initParam].nil?
278
297
  args.delete(:initParam) unless args[:initParam].nil?
279
298
  initParam = Param.new("#{self.soapClass}InitParameters", { 'id' => initParam }) unless initParam.nil?
@@ -294,13 +313,13 @@ module SoftLayer
294
313
  @slapi.headerhandler << initParam unless @slapi.headerhandler.include?(@authHeader)
295
314
  @slapi.headerhandler << @objectMask unless @objectMask.nil?
296
315
  @slapi.headerhandler << resultLimit unless resultLimit.nil?
297
-
316
+
298
317
  if block_given?
299
318
  go=true
300
319
  resultLimit = ResultLimit.new('resultLimit', [1,0]) if resultLimit.nil? # this is broken.
301
320
  @slapi.headerhandler << resultLimit unless @slapi.headerhandler.include?(resultLimit)
302
321
  while(go) do
303
- res = @slapi.call(method.to_s)
322
+ res = realCall(method.to_s)
304
323
  yield(res) unless (res.nil? || (res.respond_to?(:empty) && res.empty?))
305
324
  go = false if res.nil?
306
325
  go = false if (res.respond_to?(:size) && (res.size < resultLimit.limit))
@@ -309,19 +328,17 @@ module SoftLayer
309
328
  headerClean(resultLimit,paramHeaders)
310
329
  return true
311
330
  else
312
- res = @slapi.call(method.to_s)
331
+ res = realCall(method.to_s)
313
332
  headerClean(resultLimit,paramHeaders)
314
333
  return res
315
334
  end
316
335
  end
317
336
 
318
- # Alias the above call method to #method_missing.
337
+ # Alias the above slapiCall to #method_missing.
319
338
  alias_method :method_missing, :slapiCall
320
-
321
- def call(method, args = { }, &block)
322
- return slapiCall(method, args, &block)
323
- end
324
-
339
+ # Alias slapiCall to #call specifically because of it's special paramter list.
340
+ alias_method :call, :slapiCall
341
+
325
342
  # Enable (or disable) debug. (paramater is the IO handler to write to)
326
343
  def debug=(dev)
327
344
  @slapi.wiredump_dev=(dev)
@@ -331,12 +348,16 @@ module SoftLayer
331
348
  # Returns false of we couldn't parse the WSDL.
332
349
  def self.cacheWSDL
333
350
  return unless @@wsdl[self.soapClass].nil?
334
-
351
+
335
352
  begin
353
+ # XXX: Silence soap4r's bogus use of Kernel#warn
354
+ v = $VERBOSE
355
+ $VERBOSE=nil
336
356
  @@wsdl[self.soapClass] = SOAP::WSDLDriverFactory.new(self.wsdlUrl)
357
+ $VERBOSE = v
337
358
  return true
338
359
  rescue => e
339
- return false
360
+ return SoftLayer::Exception.new(:exception => e)
340
361
  end
341
362
  end
342
363
 
@@ -354,14 +375,27 @@ module SoftLayer
354
375
  def self.soapClass
355
376
  self.name.to_s.gsub(/::/, '_')
356
377
  end
357
-
378
+
358
379
  private
359
-
380
+
360
381
  # Clean the headers out of the driver.
361
382
  def headerClean(rl,ha)
362
383
  @slapi.headerhandler.delete(rl)
363
384
  ha.each { |h| @slapi.headerhandler.delete(h) }
364
-
385
+ end
386
+
387
+ # This really calls the soap method.
388
+ # This catches all exceptions, creates a copy of our exception proxy class
389
+ # and copies the message. This insures exceptions make it up to user code
390
+ # as opposed to soap4r's tendancy to just exit when there's a soap exception.
391
+ # todo: Add header processing/clean up.
392
+ def realCall(m)
393
+ begin
394
+ return @slapi.call(m)
395
+ rescue => e
396
+ re = SoftLayer::Exception.new(:exception => e)
397
+ raise re
398
+ end
365
399
  end
366
400
 
367
401
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jamesn-softlayer-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1.0
4
+ version: 0.6.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Nuckolls
@@ -9,7 +9,7 @@ autorequire: softlayer
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-04-19 13:00:00 -07:00
12
+ date: 2009-04-19 21:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency