Module: BaseAtlasClient
- Included in:
- Exercises
- Defined in:
- lib/client/base_atlas_client.rb
Instance Method Summary collapse
-
#auth_header ⇒ Hash
Set the API Authorization Header.
- #convert_keys(options) ⇒ Object
-
#convert_response(response, name) ⇒ Object
This needs a better name.
-
#handle_timeouts ⇒ Object
Handle API timeouts.
- #success?(code) ⇒ Boolean
- #whitelist_params(options, whitelist) ⇒ Object
Instance Method Details
#auth_header ⇒ Hash
Set the API Authorization Header
35 36 37 |
# File 'lib/client/base_atlas_client.rb', line 35 def auth_header { "authorization" => 'Token token=' + @api_key } end |
#convert_keys(options) ⇒ Object
39 40 41 42 |
# File 'lib/client/base_atlas_client.rb', line 39 def convert_keys() .keys.each {|k| [k.to_s] = .delete(k) if k.kind_of?(Symbol)} end |
#convert_response(response, name) ⇒ Object
This needs a better name
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# 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 ⇒ Object
Handle API timeouts
5 6 7 8 9 10 11 |
# File 'lib/client/base_atlas_client.rb', line 5 def handle_timeouts begin yield rescue Net::OpenTimeout, Net::ReadTimeout {} end end |
#success?(code) ⇒ Boolean
28 29 30 |
# File 'lib/client/base_atlas_client.rb', line 28 def success?(code) code.between?(200, 299) end |
#whitelist_params(options, whitelist) ⇒ Object
44 45 46 |
# File 'lib/client/base_atlas_client.rb', line 44 def whitelist_params(, whitelist) .select {|k, v| whitelist.include?(k)} end |