softlayer_api 1.0.5 → 1.0.6
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.
- data/lib/softlayer/base.rb +3 -2
- data/lib/softlayer/service.rb +8 -27
- data/test/SoftLayer_Service.rb +0 -39
- metadata +10 -5
data/lib/softlayer/base.rb
CHANGED
@@ -36,7 +36,7 @@
|
|
36
36
|
#
|
37
37
|
|
38
38
|
module SoftLayer
|
39
|
-
VERSION = "1.0.
|
39
|
+
VERSION = "1.0.6" # version history at the bottom of the file.
|
40
40
|
|
41
41
|
# The base URL of the SoftLayer API's REST-like endpoints available to the public internet.
|
42
42
|
API_PUBLIC_ENDPOINT = 'https://api.softlayer.com/rest/v3/'
|
@@ -78,4 +78,5 @@ end # module SoftLayer
|
|
78
78
|
# 1.0.4 - Fixed a bug where the result_limit and result_offset object filters were just not working.
|
79
79
|
#
|
80
80
|
# 1.0.5 - Fixed a bug where empty hashes and empty arrays would not generate meaningful object masks
|
81
|
-
#
|
81
|
+
#
|
82
|
+
# 1.0.6 - Make all API calls with either a GET or a POST as the HTTP verb.
|
data/lib/softlayer/service.rb
CHANGED
@@ -316,34 +316,15 @@ module SoftLayer
|
|
316
316
|
def http_request_for_method(method_name, method_url, request_body = nil)
|
317
317
|
content_type_header = {"Content-Type" => "application/json"}
|
318
318
|
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
if request_body && !request_body.empty?
|
324
|
-
url_request = Net::HTTP::Post.new(method_url.request_uri(), content_type_header)
|
325
|
-
else
|
326
|
-
url_request = Net::HTTP::Get.new(method_url.request_uri())
|
327
|
-
end
|
328
|
-
when /^edit/
|
329
|
-
url_request = Net::HTTP::Put.new(method_url.request_uri(), content_type_header)
|
330
|
-
when /^delete/
|
331
|
-
url_request = Net::HTTP::Delete.new(method_url.request_uri())
|
332
|
-
when /^create/, /^add/, /^remove/, /^findBy/
|
333
|
-
url_request = Net::HTTP::Post.new(method_url.request_uri(), content_type_header)
|
334
|
-
else
|
335
|
-
# The name doesn't match one of our expected patterns... Use GET if
|
336
|
-
# there are no parameters, and POST if the user has given parameters.
|
337
|
-
if request_body && !request_body.empty?
|
338
|
-
url_request = Net::HTTP::Post.new(method_url.request_uri(), content_type_header)
|
339
|
-
else
|
340
|
-
url_request = Net::HTTP::Get.new(method_url.request_uri())
|
341
|
-
end
|
319
|
+
if request_body && !request_body.empty?
|
320
|
+
url_request = Net::HTTP::Post.new(method_url.request_uri(), content_type_header)
|
321
|
+
else
|
322
|
+
url_request = Net::HTTP::Get.new(method_url.request_uri())
|
342
323
|
end
|
343
324
|
|
344
|
-
|
345
|
-
|
346
|
-
|
325
|
+
# This warning should be obsolete as we should be using POST if the user
|
326
|
+
# has provided parameters. I'm going to leave it in, however, on the off
|
327
|
+
# chance that it catches a case we aren't expecting.
|
347
328
|
if request_body && !url_request.request_body_permitted?
|
348
329
|
$stderr.puts("Warning - The HTTP request for #{method_name} does not allow arguments to be passed to the server")
|
349
330
|
else
|
@@ -351,7 +332,7 @@ module SoftLayer
|
|
351
332
|
url_request.body = request_body
|
352
333
|
end
|
353
334
|
|
354
|
-
|
335
|
+
url_request
|
355
336
|
end
|
356
337
|
|
357
338
|
# Connect to the network and request the content of the resource
|
data/test/SoftLayer_Service.rb
CHANGED
@@ -303,45 +303,6 @@ describe SoftLayer::Service, "#result_offset" do
|
|
303
303
|
end
|
304
304
|
end
|
305
305
|
|
306
|
-
describe SoftLayer::Service, "#http_request_for_method" do
|
307
|
-
it "should generate a GET request for methods staring with get" do
|
308
|
-
service = SoftLayer::Service.new("SoftLayer_Account", :username => "sample_username", :api_key => "blah")
|
309
|
-
url_request = service.http_request_for_method(:getObject, URI.parse("http://bogus.com"))
|
310
|
-
url_request.should_not be_nil
|
311
|
-
url_request.should be_kind_of(Net::HTTP::Get)
|
312
|
-
end
|
313
|
-
|
314
|
-
it "should generate a POST request for methods starting with crate" do
|
315
|
-
service = SoftLayer::Service.new("SoftLayer_Account", :username => "sample_username", :api_key => "blah")
|
316
|
-
url_request = service.http_request_for_method(:createSomeTicket, URI.parse("http://bogus.com"))
|
317
|
-
url_request.should_not be_nil
|
318
|
-
url_request.should be_kind_of(Net::HTTP::Post)
|
319
|
-
end
|
320
|
-
|
321
|
-
it "should generate a PUT request for methods starting with edit" do
|
322
|
-
service = SoftLayer::Service.new("SoftLayer_Account", :username => "sample_username", :api_key => "blah")
|
323
|
-
url_request = service.http_request_for_method(:editFoo, URI.parse("http://bogus.com"))
|
324
|
-
url_request.should_not be_nil
|
325
|
-
url_request.should be_kind_of(Net::HTTP::Put)
|
326
|
-
|
327
|
-
# I know of at least one service (I think it's the ticket service) that uses "edit" as
|
328
|
-
# a method name. Make sure that the lack of additional characters doesn't throw off
|
329
|
-
# the service
|
330
|
-
service = SoftLayer::Service.new("SoftLayer_Account", :username => "sample_username", :api_key => "blah")
|
331
|
-
url_request = service.http_request_for_method(:edit, URI.parse("http://bogus.com"))
|
332
|
-
url_request.should_not be_nil
|
333
|
-
url_request.should be_kind_of(Net::HTTP::Put)
|
334
|
-
end
|
335
|
-
|
336
|
-
it "should generate a DELETE request for methods starting with delete" do
|
337
|
-
service = SoftLayer::Service.new("SoftLayer_Account", :username => "sample_username", :api_key => "blah")
|
338
|
-
url_request = service.http_request_for_method(:deleteObject, URI.parse("http://bogus.com"))
|
339
|
-
|
340
|
-
url_request.should_not be_nil
|
341
|
-
url_request.should be_kind_of(Net::HTTP::Delete)
|
342
|
-
end
|
343
|
-
end
|
344
|
-
|
345
306
|
describe SoftLayer::Service, "#marshall_arguments_for_call" do
|
346
307
|
service = SoftLayer::Service.new("SoftLayer_Account", :username => "sample_username", :api_key => "blah")
|
347
308
|
request_body = service.marshall_arguments_for_call(["first", 3, {"cow" => "chicken"}])
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: softlayer_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-03-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: json
|
16
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,7 +21,12 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
25
30
|
description: The softlayer_api gem offers a convenient mechanism for invoking the
|
26
31
|
services of the SoftLayer API from Ruby.
|
27
32
|
email: sldn@softlayer.com
|
@@ -62,7 +67,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
62
67
|
version: '0'
|
63
68
|
requirements: []
|
64
69
|
rubyforge_project:
|
65
|
-
rubygems_version: 1.8.
|
70
|
+
rubygems_version: 1.8.24
|
66
71
|
signing_key:
|
67
72
|
specification_version: 3
|
68
73
|
summary: Library for accessing the SoftLayer portal API
|