Skip to content

Commit 1c978ad

Browse files
committed
Merged in changes from 2.2.0
2 parents f5a9f9e + f7ee991 commit 1c978ad

8 files changed

Lines changed: 61 additions & 5 deletions

File tree

CHANGELOG.textile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
* Added a method to reboot servers.
77
* The routine to retreive the open tickets on an account has been moved from the Ticket class. The set of open tickets is now a dynamic property of an account object.
88

9+
*2.2*
10+
* Added the ability to set a timout for network requests. The timeout is given when a client is created by passing the :timeout hash parameter when creating a client. The value of the parameter is an integer number of seconds.
11+
912
*2.1.1*
1013
* Virtual server upgrades no longer raise exceptions
1114
* Formalized the RDoc documentation process. Added overview and welcome documentation and changed the README so it directs folks to the new documentation.

lib/softlayer/Client.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ class Client
3232

3333
# A string passsed as the value for the User-Agent header when requests are sent to SoftLayer API.
3434
attr_accessor :user_agent
35+
36+
# An integer value (in seconds). The number of seconds to wait for HTTP requests to the network API
37+
# until they timeout. This value can be nil in which case the timeout will be the default value for
38+
# the library handling network communication (often 30 seconds)
39+
attr_reader :network_timeout
3540

3641
##
3742
# The client class maintains an (optional) default client. The default client
@@ -60,6 +65,7 @@ def self.default_client=(new_default)
6065
# * <b>+:api_key+</b> - The API key used to authenticate the user with the API
6166
# * <b>+:enpoint_url+</b> - The API endpoint the client should connect to. This defaults to API_PUBLIC_ENDPOINT
6267
# * <b>+:user_agent+</b> - A string that is passed along as the user agent when the client sends requests to the server
68+
# * <b>+:timeout+</b> - An integer number of seconds to wait until network requests time out. Corresponds to the network_timeout property of the client
6369
#
6470
# If these arguments are not provided then the client will try to locate them using other
6571
# sources including global variables, and the SoftLayer config file (if one exists)
@@ -79,6 +85,8 @@ def initialize(options = {})
7985
@endpoint_url = settings[:endpoint_url] || API_PUBLIC_ENDPOINT
8086

8187
@user_agent = settings[:user_agent] || "softlayer_api gem/#{SoftLayer::VERSION} (Ruby #{RUBY_PLATFORM}/#{RUBY_VERSION})"
88+
89+
@network_timeout = settings[:timeout] if settings.has_key?(:timeout)
8290

8391
raise "A SoftLayer Client requires a username" if !@username || @username.empty?
8492
raise "A SoftLayer Client requires an api_key" if !@api_key || @api_key.empty?

lib/softlayer/Config.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ module SoftLayer
3838
# [softlayer]
3939
# username = joeusername
4040
# api_key = DEADBEEFBADF00D
41+
# timeout = 60
4142
#
4243
# = Environment Variables
4344
#
@@ -94,6 +95,7 @@ def Config.file_settings(*additional_files)
9495
result[:username] = softlayer_section['username'] if softlayer_section['username']
9596
result[:endpoint_url] = softlayer_section['endpoint_url'] if softlayer_section['endpoint_url']
9697
result[:api_key] = softlayer_section['api_key'] if softlayer_section['api_key']
98+
result[:timeout] = softlayer_section['timeout'] if softlayer_section['timeout']
9799
end
98100
end
99101
end

lib/softlayer/ObjectMaskParser.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def parse(mask_string)
4242

4343
recognize_token(@tokenizer, :eos, "Extraneous text after object mask: ")
4444

45-
if property && (property.name != "mask" && propertyName != "filterMask")
45+
if property && (property.name != "mask" && property.name != "filterMask")
4646
raise ObjectMaskParserError, "Object Mask must begin with a 'mask' or 'filterMask' root property"
4747
end
4848

lib/softlayer/Service.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,9 +296,9 @@ def to_ary
296296

297297
def xmlrpc_client()
298298
if !@xmlrpc_client
299-
@xmlrpc_client = XMLRPC::Client.new2(URI.join(@client.endpoint_url,@service_name).to_s)
299+
@xmlrpc_client = XMLRPC::Client.new2(URI.join(@client.endpoint_url,@service_name).to_s, nil, @client.network_timeout)
300300

301-
# this is a workaround for a bug in later versions of the XML-RPC client in Ruby Core.
301+
# This is a workaround for a bug in later versions of the XML-RPC client in Ruby Core.
302302
# see https://bugs.ruby-lang.org/issues/8182
303303
@xmlrpc_client.http_header_extra = {
304304
"Accept-Encoding" => "identity",

spec/Client_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,16 @@
9595
end.to raise_error
9696
end
9797

98+
it 'initializes by default with nil as the timeout' do
99+
client = SoftLayer::Client.new(:username => 'fake_user', :api_key => 'fake_key', :endpoint_url => 'http://fakeurl.org/')
100+
expect(client.network_timeout).to be_nil
101+
end
102+
103+
it 'Accepts a timeout given as a config parameter' do
104+
client = SoftLayer::Client.new(:username => 'fake_user', :api_key => 'fake_key', :endpoint_url => 'http://fakeurl.org/', :timeout => 60)
105+
expect(client.network_timeout).to eq 60
106+
end
107+
98108
it 'gets the default endpoint even if none is provided' do
99109
$SL_API_BASE_URL = nil
100110
client = SoftLayer::Client.new(:username => 'fake_user', :api_key => 'fake_key')

spec/ObjectMaskParser_spec.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,27 @@
3838
expect { result = subject.parse("mask[two,children], bob") }.to raise_error
3939
end
4040

41+
it "should parse a mask with fiterMask" do
42+
result = nil
43+
expect { result = subject.parse("filterMask.simple1") }.to_not raise_error
44+
45+
expect(result.name).to eq 'filterMask'
46+
expect(result.children[0].name).to eq 'simple1'
47+
end
48+
49+
it "should parse a mask set with fiterMask" do
50+
result = nil
51+
expect { result = subject.parse("[filterMask.simple1, filterMask.simple2]") }.to_not raise_error
52+
53+
expect(result.count).to eq 2
54+
expect(result[0].name).to eq 'filterMask'
55+
expect(result[0].children.count).to eq 1
56+
expect(result[0].children[0].name).to eq "simple1"
57+
58+
expect(result[1].name).to eq 'filterMask'
59+
expect(result[1].children.count).to eq 1
60+
expect(result[1].children[0].name).to eq "simple2"
61+
end
4162
end
4263

4364
describe SoftLayer::ObjectMaskParser, "#parse_property_set" do

spec/Service_spec.rb

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,23 @@
6161
client = SoftLayer::Client.new() # authentication is taken from the globals
6262
expect { SoftLayer::Service.new("SoftLayer_Account", :client => client, :username => "sample_username", :api_key => "blah") }.to raise_error(RuntimeError)
6363
end
64-
6564
end #describe #new
6665
end
6766

68-
describe SoftLayer::Service do
67+
describe SoftLayer::Service, "xmlrpc client" do
68+
before(:each) do
69+
SoftLayer::Service.send(:public, :xmlrpc_client)
70+
end
71+
72+
it "Constructs an XMLRPC client with a given timeout value based on the timeout of the client" do
73+
client = SoftLayer::Client.new(:username => 'fake_user', :api_key => 'fake_key', :timeout => 60)
74+
ticket_service = client[:Ticket]
75+
xmlrpc = ticket_service.xmlrpc_client()
76+
expect(xmlrpc.timeout).to eq 60
77+
end
78+
end
79+
80+
describe SoftLayer::Service, "parameter filters" do
6981
let (:service) do
7082
SoftLayer::Service.new("SoftLayer_Ticket", :username => "sample_username", :api_key => "blah")
7183
end

0 commit comments

Comments
 (0)