@@ -133,6 +133,9 @@ class Service
133133 # The base URL for requests that are passed to the server. Cannot be emtpy or nil.
134134 attr_accessor :endpoint_url
135135
136+ # The User-Agent header sent to SoftLayer API.
137+ attr_accessor :user_agent
138+
136139 # Initialize an instance of the Client class. You pass in the service name
137140 # and optionally hash arguments specifying how the client should access the
138141 # SoftLayer API.
@@ -162,23 +165,16 @@ def initialize(service_name, options = {})
162165 # public endpoint
163166 self . endpoint_url = options [ :endpoint_url ] || $SL_API_BASE_URL || API_PUBLIC_ENDPOINT
164167
168+ @user_agent = { "User-Agent" => options [ :user_agent ] || "SoftLayer API Ruby Client #{ SoftLayer ::VERSION } " }
169+
165170 if ( $DEBUG)
166171 @method_missing_call_depth = 0
167172 end
168173 end #initalize
169174
170- # User this to set or get a user agent string for this API client.
171- #
172- # user_agent_string()
173- # => "SoftLayer API Ruby Client #{SoftLayer::Version}"
174- #
175- # user_agent_string('agentName using this gem vX.Y.Z')
176- # => "agentName using this gem vX.Y.Z"
177- #
178- def user_agent_header ( set = nil )
179- @user_agent_header = set unless set . nil?
180- @user_agent_header ||= "SoftLayer API Ruby Client #{ SoftLayer ::VERSION } "
181- { "User-Agent" => @user_agent_header }
175+ # Use this to set the user agent string for this API client.
176+ def user_agent = ( set )
177+ self . user_agent [ 'User-Agent' ] = set
182178 end
183179
184180 # Use this as part of a method call chain to identify a particular
@@ -339,9 +335,9 @@ def http_request_for_method(method_name, method_url, request_body = nil)
339335 end
340336
341337 if request_body && !request_body . empty?
342- url_request = Net ::HTTP ::Post . new ( method_url . request_uri ( ) , content_type_header . merge ( self . user_agent_header ) )
338+ url_request = Net ::HTTP ::Post . new ( method_url . request_uri ( ) , content_type_header . merge ( self . user_agent ) )
343339 else
344- url_request = Net ::HTTP ::Get . new ( method_url . request_uri ( ) , self . user_agent_header )
340+ url_request = Net ::HTTP ::Get . new ( method_url . request_uri ( ) , self . user_agent )
345341 end
346342
347343 # This warning should be obsolete as we should be using POST if the user
0 commit comments