Class: MsRest2::ServiceClient
- Inherits:
-
Object
- Object
- MsRest2::ServiceClient
- Defined in:
- lib/ms_rest2/service_client.rb
Overview
Class which represents a point of access to the REST API.
Instance Attribute Summary collapse
-
#credentials ⇒ MsRest2::ServiceClientCredentials
The credentials object.
-
#middlewares ⇒ Hash{String=>String}
Default middlewares configuration for requests.
-
#request_headers ⇒ Hash{String=>String}
Default request headers for requests.
-
#user_agent_extended ⇒ Array
Strings to be appended to the user agent in the request.
Instance Method Summary collapse
-
#add_user_agent_information(additional_user_agent_information) ⇒ Object
Add additional information into User-Agent header.
-
#initialize(credentials = nil, options = nil) ⇒ ServiceClient
constructor
Creates and initialize new instance of the ServiceClient class.
-
#make_request_async(base_url, method, path, options = {}) ⇒ Concurrent::Promise
Promise object which holds the HTTP response.
Constructor Details
#initialize(credentials = nil, options = nil) ⇒ ServiceClient
Creates and initialize new instance of the ServiceClient class.
HTTP requests made by the service client.
30 31 32 33 34 35 36 |
# File 'lib/ms_rest2/service_client.rb', line 30 def initialize(credentials = nil, = nil) @credentials = credentials @request_headers = {} @middlewares = {middlewares: [[MsRest2::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]]} @user_agent_extended = [] @user_agent_extended.push("ms_rest2/#{MsRest2::VERSION}") end |
Instance Attribute Details
#credentials ⇒ MsRest2::ServiceClientCredentials
Returns the credentials object.
12 13 14 |
# File 'lib/ms_rest2/service_client.rb', line 12 def credentials @credentials end |
#middlewares ⇒ Hash{String=>String}
Returns default middlewares configuration for requests.
15 16 17 |
# File 'lib/ms_rest2/service_client.rb', line 15 def middlewares @middlewares end |
#request_headers ⇒ Hash{String=>String}
Returns default request headers for requests.
18 19 20 |
# File 'lib/ms_rest2/service_client.rb', line 18 def request_headers @request_headers end |
#user_agent_extended ⇒ Array
Returns strings to be appended to the user agent in the request.
21 22 23 |
# File 'lib/ms_rest2/service_client.rb', line 21 def user_agent_extended @user_agent_extended end |
Instance Method Details
#add_user_agent_information(additional_user_agent_information) ⇒ Object
Add additional information into User-Agent header. Example:
recommended format is Product/[version]
please refer https://github.com/Azure/azure-sdk-for-ruby/issues/517 for more information.
add_user_agent_information('fog-azure-rm/0.2.0')
71 72 73 |
# File 'lib/ms_rest2/service_client.rb', line 71 def add_user_agent_information(additional_user_agent_information) @user_agent_extended.push(additional_user_agent_information) end |
#make_request_async(base_url, method, path, options = {}) ⇒ Concurrent::Promise
Returns Promise object which holds the HTTP response.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/ms_rest2/service_client.rb', line 45 def make_request_async(base_url, method, path, = {}) = @middlewares.merge() [:credentials] = [:credentials] || @credentials [:user_agent_extended] = @user_agent_extended request = MsRest2::HttpOperationRequest.new(base_url, path, method, ) promise = request.run_promise do |req| [:credentials].sign_request(req) unless [:credentials].nil? end promise = promise.then do |http_response| response_content = http_response.body.to_s.empty? ? nil : http_response.body # Create response create_response(request, http_response, response_content) end promise.execute end |