Class: OracleBMC::ApiClient
- Inherits:
-
Object
- Object
- OracleBMC::ApiClient
- Defined in:
- lib/oraclebmc/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 each Typhoeus request.
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) ⇒ 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.
32 33 34 35 36 37 38 39 40 |
# File 'lib/oraclebmc/api_client.rb', line 32 def initialize(config, signer) fail "Missing the required parameter 'config' when initializing ApiClient." if config.nil? fail "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.
17 18 19 |
# File 'lib/oraclebmc/api_client.rb', line 17 def config @config end |
#default_headers ⇒ Hash
Defines the headers to be used in HTTP requests of all API calls by default.
22 23 24 |
# File 'lib/oraclebmc/api_client.rb', line 22 def default_headers @default_headers end |
#request_option_overrides ⇒ Hash
Request options to be sent with each Typhoeus request. These options will override any defaults normally set by ApiClient. See https://github.com/typhoeus/ethon/blob/master/lib/ethon/curls/options.rb for some of the available options.
30 31 32 |
# File 'lib/oraclebmc/api_client.rb', line 30 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.
94 95 96 |
# File 'lib/oraclebmc/api_client.rb', line 94 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.
104 105 106 107 108 109 110 111 112 |
# File 'lib/oraclebmc/api_client.rb', line 104 def build_user_agent agent = "#{build_user_info} (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.
99 100 101 |
# File 'lib/oraclebmc/api_client.rb', line 99 def build_user_info return "Oracle-RubySDK/#{VERSION}" end |
#call_api(http_method, path, endpoint, opts) ⇒ Array<(Object, Fixnum, Hash)>
Call an API with given options.
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/oraclebmc/api_client.rb', line 54 def call_api(http_method, path, endpoint, opts) http_method = http_method.to_sym.downcase if http_method == :get # Wrap get calls in a lambda that can be called later for paging # and wait_until. proc = lambda { |page| if !page.nil? opts[:query_params] ||= {} opts[:query_params][:page] = page end return call_api_inner(http_method, path, endpoint, opts) } response = proc.call(nil) response.api_call = proc return response else # No need to wrap methods other than GET, just call them directly. return call_api_inner(http_method, path, endpoint, opts) end end |
#object_to_http_body(model) ⇒ String
Convert object (array, hash, object, etc) to JSON string.
82 83 84 85 86 87 88 89 90 91 |
# File 'lib/oraclebmc/api_client.rb', line 82 def object_to_http_body(model) return model if model.nil? || model.is_a?(String) local_body = nil 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 |