Class: TddiumClient::InternalClient
- Inherits:
-
Object
- Object
- TddiumClient::InternalClient
- Defined in:
- lib/tddium_client.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Instance Method Summary collapse
- #call_api(method, api_path, params = {}, api_key = nil, retries = 5, xid = nil) ⇒ Object
- #caller_version ⇒ Object
- #caller_version=(version) ⇒ Object
-
#initialize(host, port = nil, scheme = 'https', version = 1, caller_version = nil, options = {}) ⇒ InternalClient
constructor
A new instance of InternalClient.
- #xid_gen ⇒ Object
Constructor Details
#initialize(host, port = nil, scheme = 'https', version = 1, caller_version = nil, options = {}) ⇒ InternalClient
Returns a new instance of InternalClient.
109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/tddium_client.rb', line 109 def initialize(host, port=nil, scheme='https', version=1, caller_version=nil, ={}) @client = HTTPClient.new if [:insecure] @client.ssl_config.verify_mode = OpenSSL::SSL::VERIFY_NONE end @tddium_config = {"host" => host, "port" => port, "scheme" => scheme, "version" => version, "caller_version" => caller_version} end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
107 108 109 |
# File 'lib/tddium_client.rb', line 107 def client @client end |
Instance Method Details
#call_api(method, api_path, params = {}, api_key = nil, retries = 5, xid = nil) ⇒ Object
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/tddium_client.rb', line 122 def call_api(method, api_path, params = {}, api_key = nil, retries = 5, xid=nil) headers = {'Content-Type' => 'application/json'} headers.merge!(API_KEY_HEADER => api_key) if api_key headers.merge!(CLIENT_VERSION_HEADER => version_header) xid ||= xid_gen call_params = params.merge({:xid => xid}) tries = 0 begin http = @client.send(method, tddium_uri(api_path), :body => call_params.to_json, :header => headers) rescue Errno::ECONNREFUSED, Errno::ETIMEDOUT, Timeout::Error, OpenSSL::SSL::SSLError, OpenSSL::SSL::Session::SessionError, HTTPClient::TimeoutError, HTTPClient::BadResponseError tries += 1 delay = (tries>>1)*0.05*rand() Kernel.sleep(delay) retry if retries > 0 && tries <= retries end raise Error::Timeout if retries >= 0 && tries > retries Result::API.new(http) end |
#caller_version ⇒ Object
146 147 148 |
# File 'lib/tddium_client.rb', line 146 def caller_version @tddium_config["caller_version"] end |
#caller_version=(version) ⇒ Object
150 151 152 |
# File 'lib/tddium_client.rb', line 150 def caller_version=(version) @tddium_config["caller_version"] = version end |
#xid_gen ⇒ Object
154 155 156 |
# File 'lib/tddium_client.rb', line 154 def xid_gen return SecureRandom.hex(8) end |