softlayer_api 1.0.3 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/softlayer/base.rb +3 -1
- data/lib/softlayer/service.rb +23 -18
- data/test/SoftLayer_Service.rb +22 -7
- metadata +4 -11
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.4" # 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/'
|
@@ -75,3 +75,5 @@ end # module SoftLayer
|
|
75
75
|
# 1.0.3 - Added a request filter to add result limits to request. Submitted by
|
76
76
|
# JN. Thanks!
|
77
77
|
#
|
78
|
+
# 1.0.4 - Fixed a bug where the result_limit and result_offset object filters were just not working.
|
79
|
+
#
|
data/lib/softlayer/service.rb
CHANGED
@@ -93,7 +93,6 @@ module SoftLayer
|
|
93
93
|
self.parameters[:result_limit]
|
94
94
|
end
|
95
95
|
|
96
|
-
|
97
96
|
def result_offset(offset)
|
98
97
|
self.parameters[:result_offset] = offset
|
99
98
|
self
|
@@ -210,7 +209,13 @@ module SoftLayer
|
|
210
209
|
def result_limit(limit)
|
211
210
|
proxy = APIParameterFilter.new
|
212
211
|
proxy.target = self
|
213
|
-
return proxy.result_limit
|
212
|
+
return proxy.result_limit(limit)
|
213
|
+
end
|
214
|
+
|
215
|
+
def result_offset(offset)
|
216
|
+
proxy = APIParameterFilter.new
|
217
|
+
proxy.target = self
|
218
|
+
return proxy.result_offset(offset)
|
214
219
|
end
|
215
220
|
|
216
221
|
# This is the primary mechanism by which requests are made. If you call
|
@@ -308,18 +313,18 @@ module SoftLayer
|
|
308
313
|
# and create a Net::HTTP request of that type. This is intended
|
309
314
|
# to be used in the internal processing of method_missing and
|
310
315
|
# need not be called directly.
|
311
|
-
def http_request_for_method(method_name, method_url, request_body)
|
316
|
+
def http_request_for_method(method_name, method_url, request_body = nil)
|
312
317
|
content_type_header = {"Content-Type" => "application/json"}
|
313
318
|
|
314
319
|
case method_name.to_s
|
315
320
|
when /^get/
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
321
|
+
# if the user has provided some arguments to the call, we
|
322
|
+
# use a POST instead of a GET in spite of the method name.
|
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
|
323
328
|
when /^edit/
|
324
329
|
url_request = Net::HTTP::Put.new(method_url.request_uri(), content_type_header)
|
325
330
|
when /^delete/
|
@@ -327,16 +332,16 @@ module SoftLayer
|
|
327
332
|
when /^create/, /^add/, /^remove/, /^findBy/
|
328
333
|
url_request = Net::HTTP::Post.new(method_url.request_uri(), content_type_header)
|
329
334
|
else
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
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
|
337
342
|
end
|
338
343
|
|
339
|
-
|
344
|
+
# This warning should be obsolete as we should be using POST if the user
|
340
345
|
# has provided parameters. I'm going to leave it in, however, on the off
|
341
346
|
# chance that it catches a case we aren't expecting.
|
342
347
|
if request_body && !url_request.request_body_permitted?
|
data/test/SoftLayer_Service.rb
CHANGED
@@ -245,13 +245,6 @@ describe SoftLayer::Service, "#call_softlayer_api_with_params" do
|
|
245
245
|
service.call_softlayer_api_with_params(:getObject, SoftLayer::APIParameterFilter.new.object_mask("cow ", " duck", "chicken", "bull dog"), []);
|
246
246
|
end
|
247
247
|
|
248
|
-
it "should warn about calling a get method with arguments" do
|
249
|
-
service = SoftLayer::Service.new("SoftLayer_Account", :username => "sample_username", :api_key => "blah")
|
250
|
-
service.should_receive(:issue_http_request).with(any_args())
|
251
|
-
$stderr.should_receive(:puts).with("Warning - The HTTP request for getObject does not allow arguments to be passed to the server")
|
252
|
-
service.getObject("Hello", "Bindigo")
|
253
|
-
end
|
254
|
-
|
255
248
|
it "should return the parsed JSON when completing successfully" do
|
256
249
|
service = SoftLayer::Service.new("SoftLayer_Account", :username => "sample_username", :api_key => "blah")
|
257
250
|
service.should_receive(:issue_http_request).with(any_args()).and_return('{"successful":"Yipeee!", "array":[1,2,3], "bool":true}')
|
@@ -288,6 +281,28 @@ describe SoftLayer::Service, "#object_mask" do
|
|
288
281
|
end
|
289
282
|
end
|
290
283
|
|
284
|
+
describe SoftLayer::Service, "#result_limit" do
|
285
|
+
it "should return an APIParameterFilter with itself as the target" do
|
286
|
+
service = SoftLayer::Service.new("SoftLayer_Account", :username => "sample_username", :api_key => "blah")
|
287
|
+
filter = service.result_limit(10)
|
288
|
+
|
289
|
+
filter.should_not be_nil
|
290
|
+
filter.target.should === service
|
291
|
+
filter.server_result_limit.should == 10
|
292
|
+
end
|
293
|
+
end
|
294
|
+
|
295
|
+
describe SoftLayer::Service, "#result_offset" do
|
296
|
+
it "should return an APIParameterFilter with itself as the target" do
|
297
|
+
service = SoftLayer::Service.new("SoftLayer_Account", :username => "sample_username", :api_key => "blah")
|
298
|
+
filter = service.result_offset(5)
|
299
|
+
|
300
|
+
filter.should_not be_nil
|
301
|
+
filter.target.should === service
|
302
|
+
filter.server_result_offset.should == 5
|
303
|
+
end
|
304
|
+
end
|
305
|
+
|
291
306
|
describe SoftLayer::Service, "#http_request_for_method" do
|
292
307
|
it "should generate a GET request for methods staring with get" do
|
293
308
|
service = SoftLayer::Service.new("SoftLayer_Account", :username => "sample_username", :api_key => "blah")
|
metadata
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: softlayer_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash: 17
|
5
4
|
prerelease: false
|
6
5
|
segments:
|
7
6
|
- 1
|
8
7
|
- 0
|
9
|
-
-
|
10
|
-
version: 1.0.
|
8
|
+
- 4
|
9
|
+
version: 1.0.4
|
11
10
|
platform: ruby
|
12
11
|
authors:
|
13
12
|
- SoftLayer Development Team
|
@@ -15,18 +14,16 @@ autorequire:
|
|
15
14
|
bindir: bin
|
16
15
|
cert_chain: []
|
17
16
|
|
18
|
-
date: 2011-
|
17
|
+
date: 2011-09-20 00:00:00 -05:00
|
19
18
|
default_executable:
|
20
19
|
dependencies:
|
21
20
|
- !ruby/object:Gem::Dependency
|
22
21
|
name: json
|
23
22
|
prerelease: false
|
24
23
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
24
|
requirements:
|
27
25
|
- - ">="
|
28
26
|
- !ruby/object:Gem::Version
|
29
|
-
hash: 3
|
30
27
|
segments:
|
31
28
|
- 0
|
32
29
|
version: "0"
|
@@ -64,27 +61,23 @@ rdoc_options: []
|
|
64
61
|
require_paths:
|
65
62
|
- lib
|
66
63
|
required_ruby_version: !ruby/object:Gem::Requirement
|
67
|
-
none: false
|
68
64
|
requirements:
|
69
65
|
- - ">="
|
70
66
|
- !ruby/object:Gem::Version
|
71
|
-
hash: 3
|
72
67
|
segments:
|
73
68
|
- 0
|
74
69
|
version: "0"
|
75
70
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
|
-
none: false
|
77
71
|
requirements:
|
78
72
|
- - ">="
|
79
73
|
- !ruby/object:Gem::Version
|
80
|
-
hash: 3
|
81
74
|
segments:
|
82
75
|
- 0
|
83
76
|
version: "0"
|
84
77
|
requirements: []
|
85
78
|
|
86
79
|
rubyforge_project:
|
87
|
-
rubygems_version: 1.3.
|
80
|
+
rubygems_version: 1.3.6
|
88
81
|
signing_key:
|
89
82
|
specification_version: 3
|
90
83
|
summary: Library for accessing the SoftLayer portal API
|