module BaseAtlasClient
Public Instance Methods
auth_header()
click to toggle source
Set the API Authorization Header
@return [Hash] The authorization header
# File lib/client/base_atlas_client.rb, line 35 def auth_header { "authorization" => 'Token token=' + @api_key } end
convert_keys(options)
click to toggle source
# File lib/client/base_atlas_client.rb, line 39 def convert_keys(options) options.keys.each {|k| options[k.to_s] = options.delete(k) if k.kind_of?(Symbol)} options end
convert_response(response, name)
click to toggle source
This needs a better name
# File lib/client/base_atlas_client.rb, line 14 def convert_response(response, name) if success?(response.code) body = response.body.is_a?(String) ? JSON.parse(response.body) : response.body if body.is_a?(Array) body.map {|hash| AtlasClassFactory.build_response_object(hash, name)} else AtlasClassFactory.build_response_object(body, name) end else return response end end
handle_timeouts() { || ... }
click to toggle source
Handle API timeouts
# File lib/client/base_atlas_client.rb, line 5 def handle_timeouts begin yield rescue Net::OpenTimeout, Net::ReadTimeout {} end end
success?(code)
click to toggle source
# File lib/client/base_atlas_client.rb, line 28 def success?(code) code.between?(200, 299) end
whitelist_params(options, whitelist)
click to toggle source
# File lib/client/base_atlas_client.rb, line 44 def whitelist_params(options, whitelist) options.select {|k, v| whitelist.include?(k)} end