Class: OCI::ApiClient
- Inherits:
-
Object
- Object
- OCI::ApiClient
- Defined in:
- lib/oci/api_client.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
The Config object holding settings to be used in the API client.
-
#default_headers ⇒ Hash
Defines the headers to be used in HTTP requests of all API calls by default.
-
#request_option_overrides ⇒ Hash
Request options to be sent with Net::HTTP.
Instance Method Summary collapse
-
#build_request_id ⇒ Object
Builds the client info string to be sent with each request.
-
#build_user_agent ⇒ Object
Build the user agent string to be send with each request.
-
#build_user_info ⇒ Object
Builds the client info string to be sent with each request.
-
#call_api(http_method, path, endpoint, opts, &block) ⇒ Array<(Object, Fixnum, Hash)>
Call an API with given options.
-
#initialize(config, signer) ⇒ ApiClient
constructor
A new instance of ApiClient.
-
#object_to_http_body(model) ⇒ String
Convert object (array, hash, object, etc) to JSON string.
Constructor Details
#initialize(config, signer) ⇒ ApiClient
Returns a new instance of ApiClient.
33 34 35 36 37 38 39 40 41 |
# File 'lib/oci/api_client.rb', line 33 def initialize(config, signer) raise "Missing the required parameter 'config' when initializing ApiClient." if config.nil? raise "Missing the required parameter 'signer' when initializing ApiClient." if signer.nil? @config = config @signer = signer @default_headers = {} @request_option_overrides = {} end |
Instance Attribute Details
#config ⇒ Object
The Config object holding settings to be used in the API client.
18 19 20 |
# File 'lib/oci/api_client.rb', line 18 def config @config end |
#default_headers ⇒ Hash
Defines the headers to be used in HTTP requests of all API calls by default.
23 24 25 |
# File 'lib/oci/api_client.rb', line 23 def default_headers @default_headers end |
#request_option_overrides ⇒ Hash
Request options to be sent with Net::HTTP. These options will override any defaults normally set by ApiClient. See http://ruby-doc.org/stdlib-2.4.1/libdoc/net/http/rdoc/Net/HTTP.html#method-c-start for some of the available options.
31 32 33 |
# File 'lib/oci/api_client.rb', line 31 def request_option_overrides @request_option_overrides end |
Instance Method Details
#build_request_id ⇒ Object
Builds the client info string to be sent with each request.
93 94 95 |
# File 'lib/oci/api_client.rb', line 93 def build_request_id return SecureRandom.uuid.gsub!('-', '').upcase end |
#build_user_agent ⇒ Object
Build the user agent string to be send with each request.
103 104 105 106 107 108 109 110 111 |
# File 'lib/oci/api_client.rb', line 103 def build_user_agent agent = "#{build_user_info}#{OCI.sdk_name} (ruby #{RUBY_VERSION}; #{RUBY_PLATFORM})" if config.additional_user_agent agent = "#{agent} #{config.additional_user_agent}" end agent end |
#build_user_info ⇒ Object
Builds the client info string to be sent with each request.
98 99 100 |
# File 'lib/oci/api_client.rb', line 98 def build_user_info return "Oracle-RubySDK/#{VERSION}" end |
#call_api(http_method, path, endpoint, opts, &block) ⇒ Array<(Object, Fixnum, Hash)>
Call an API with given options.
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/oci/api_client.rb', line 57 def call_api(http_method, path, endpoint, opts, &block) http_method = http_method.to_sym.downcase return call_api_inner(http_method, path, endpoint, opts, &block) unless http_method == :get # Wrap get calls in a lambda that can be called later for paging # and wait_until. proc = lambda { |page| unless page.nil? opts[:query_params] ||= {} opts[:query_params][:page] = page end return call_api_inner(http_method, path, endpoint, opts, &block) } response = proc.call(nil) response.api_call = proc response end |
#object_to_http_body(model) ⇒ String
Convert object (array, hash, object, etc) to JSON string.
81 82 83 84 85 86 87 88 89 90 |
# File 'lib/oci/api_client.rb', line 81 def object_to_http_body(model) # to support IO-like object as well like StringIO return model if model.nil? || model.is_a?(String) || (model.respond_to?(:read) && model.respond_to?(:write)) if model.is_a?(Array) local_body = model.map{|m| object_to_hash(m) } else local_body = object_to_hash(model) end local_body.to_json end |