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.
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/tddium_client.rb', line 129 def initialize(host, port=nil, scheme='https', version=1, caller_version=nil, ={}) @debug = ENV['SOLANO_CLIENT_DEBUG']=='true' || false @client = HTTPClient.new if [:insecure] @client.ssl_config.verify_mode = OpenSSL::SSL::VERIFY_NONE end uri = URI.parse("") uri.host = host uri.port = port uri.scheme = scheme [:cookies].each do |name,value| = WebAgent::Cookie.new .name = name .value = value .url = uri @client..add() end if [:receive_timeout] then @client.receive_timeout = [:receive_timeout].to_i 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.
127 128 129 |
# File 'lib/tddium_client.rb', line 127 def client @client end |
Instance Method Details
#call_api(method, api_path, params = {}, api_key = nil, retries = 5, xid = nil) ⇒ Object
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
# File 'lib/tddium_client.rb', line 162 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 debug_msg({:method => method, :path => tddium_uri(api_path), :headers => headers, :body => call_params.to_json}) begin http = @client.send(method, tddium_uri(api_path), :body => call_params.to_json, :header => headers) rescue *ERRORS => e raise Error::APICert.new(e) if e. =~ /certificate verify failed/ 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 res = Result::API.new(http) debug_msg({:result => res.tddium_response}) return res end |
#caller_version ⇒ Object
188 189 190 |
# File 'lib/tddium_client.rb', line 188 def caller_version @tddium_config["caller_version"] end |
#caller_version=(version) ⇒ Object
192 193 194 |
# File 'lib/tddium_client.rb', line 192 def caller_version=(version) @tddium_config["caller_version"] = version end |
#xid_gen ⇒ Object
196 197 198 |
# File 'lib/tddium_client.rb', line 196 def xid_gen return SecureRandom.hex(8) end |