Class: TddiumClient::InternalClient

Inherits:
Object
  • Object
show all
Defined in:
lib/tddium_client.rb

Direct Known Subclasses

Client

Instance Attribute Summary collapse

Instance Method Summary collapse

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
# File 'lib/tddium_client.rb', line 129

def initialize(host, port=nil, scheme='https', version=1, caller_version=nil, options={})
@debug = ENV['SOLANO_CLIENT_DEBUG']=='true' || false
@client = HTTPClient.new
if options[: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

#clientObject (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

Raises:



143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/tddium_client.rb', line 143

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.message =~ /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_versionObject



169
170
171
# File 'lib/tddium_client.rb', line 169

def caller_version
  @tddium_config["caller_version"]
end

#caller_version=(version) ⇒ Object



173
174
175
# File 'lib/tddium_client.rb', line 173

def caller_version=(version)
  @tddium_config["caller_version"] = version
end

#xid_genObject



177
178
179
# File 'lib/tddium_client.rb', line 177

def xid_gen
  return SecureRandom.hex(8)
end