softlayer_api 1.0.1 → 1.0.2

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.
@@ -34,8 +34,9 @@
34
34
  # Set this if you want to use the same api for all clients and don't want to have to specify it when the client is created
35
35
  # - <tt>$SL_API_BASE_URL</tt>- The default URL used to access the SoftLayer API. This defaults to the value of SoftLayer::API_PUBLIC_ENDPOINT
36
36
  #
37
+
37
38
  module SoftLayer
38
- VERSION = "1.0.1"
39
+ VERSION = "1.0.2" # version history at the bottom of the file.
39
40
 
40
41
  # The base URL of the SoftLayer API's REST-like endpoints available to the public internet.
41
42
  API_PUBLIC_ENDPOINT = 'https://api.softlayer.com/rest/v3/'
@@ -59,3 +60,15 @@ module SoftLayer
59
60
  # The base URL used for the SoftLayer API's
60
61
  $SL_API_BASE_URL = SoftLayer::API_PUBLIC_ENDPOINT
61
62
  end # module SoftLayer
63
+
64
+ #
65
+ # History:
66
+ #
67
+ # 1.0 - 1.0.1 - Initial release. There was some confusion over getting the gem
68
+ # posted up to rubygems.org and the 1.0.1 release came about because of that
69
+ # confusion. There should be no real functionality differences there.
70
+ #
71
+ # 1.0.2 - We have some API routines that start with "get" but expect arguments
72
+ # anyway. The code now uses HTTP POST to send requests for which the user
73
+ # has provided arguments regardless of the name of the routine.
74
+ #
@@ -230,21 +230,12 @@ module SoftLayer
230
230
  # find out what URL will invoke the method (with the given parameters)
231
231
  request_url = url_to_call_method(method_name, parameters)
232
232
 
233
- # construct an HTTP request for that method with the given URL
234
- http_request = http_request_for_method(method_name, request_url);
235
- http_request.basic_auth(self.username, self.api_key)
236
-
237
233
  # marshall the arguments into the http_request
238
234
  request_body = marshall_arguments_for_call(args)
239
235
 
240
- # If you provide arguments to a call that is not supposed to have
241
- # arguments, this will print a warning to the console.
242
- if request_body && !http_request.request_body_permitted?
243
- $stderr.puts("Warning - The HTTP request for #{method_name} does not allow arguments to be passed to the server")
244
- else
245
- # Otherwise, add the arguments as the body of the request
246
- http_request.body = request_body
247
- end
236
+ # construct an HTTP request for that method with the given URL
237
+ http_request = http_request_for_method(method_name, request_url, request_body);
238
+ http_request.basic_auth(self.username, self.api_key)
248
239
 
249
240
  # Send the url request and recover the results. Parse the response (if any)
250
241
  # as JSON
@@ -289,21 +280,45 @@ module SoftLayer
289
280
  # and create a Net::HTTP request of that type. This is intended
290
281
  # to be used in the internal processing of method_missing and
291
282
  # need not be called directly.
292
- def http_request_for_method(method_name, method_url)
283
+ def http_request_for_method(method_name, method_url, request_body)
293
284
  content_type_header = {"Content-Type" => "application/json"}
294
285
 
295
286
  case method_name.to_s
296
287
  when /^get/
297
- Net::HTTP::Get.new(method_url.request_uri())
288
+ # if the user has provided some arguments to the call, we
289
+ # use a POST instead of a GET in spite of the method name.
290
+ if request_body && !request_body.empty?
291
+ url_request = Net::HTTP::Post.new(method_url.request_uri(), content_type_header)
292
+ else
293
+ url_request = Net::HTTP::Get.new(method_url.request_uri())
294
+ end
298
295
  when /^edit/
299
- Net::HTTP::Put.new(method_url.request_uri(), content_type_header)
296
+ url_request = Net::HTTP::Put.new(method_url.request_uri(), content_type_header)
300
297
  when /^delete/
301
- Net::HTTP::Delete.new(method_url.request_uri())
298
+ url_request = Net::HTTP::Delete.new(method_url.request_uri())
302
299
  when /^create/, /^add/, /^remove/, /^findBy/
303
- Net::HTTP::Post.new(method_url.request_uri(), content_type_header)
300
+ url_request = Net::HTTP::Post.new(method_url.request_uri(), content_type_header)
304
301
  else
305
- Net::HTTP::Get.new(method_url.request_uri())
302
+ # The name doesn't match one of our expected patterns... Use GET if
303
+ # there are no parameters, and POST if the user has given parameters.
304
+ if request_body && !request_body.empty?
305
+ url_request = Net::HTTP::Post.new(method_url.request_uri(), content_type_header)
306
+ else
307
+ url_request = Net::HTTP::Get.new(method_url.request_uri())
308
+ end
306
309
  end
310
+
311
+ # This warning should be obsolete as we should be using POST if the user
312
+ # has provided parameters. I'm going to leave it in, however, on the off
313
+ # chance that it catches a case we aren't expecting.
314
+ if request_body && !url_request.request_body_permitted?
315
+ $stderr.puts("Warning - The HTTP request for #{method_name} does not allow arguments to be passed to the server")
316
+ else
317
+ # Otherwise, add the arguments as the body of the request
318
+ url_request.body = request_body
319
+ end
320
+
321
+ url_request
307
322
  end
308
323
 
309
324
  # Connect to the network and request the content of the resource
@@ -314,7 +329,7 @@ module SoftLayer
314
329
  def issue_http_request(request_url, http_request, &block)
315
330
  # create and run an SSL request
316
331
  https = Net::HTTP.new(request_url.host, request_url.port)
317
- https.use_ssl = true
332
+ https.use_ssl = (request_url.scheme == "https")
318
333
 
319
334
  # This line silences an annoying warning message if you're in debug mode
320
335
  https.verify_mode = OpenSSL::SSL::VERIFY_NONE if $DEBUG
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: softlayer_api
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 1
10
- version: 1.0.1
9
+ - 2
10
+ version: 1.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - SoftLayer Development Team
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-07-30 00:00:00 -05:00
18
+ date: 2010-08-10 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency