Module: Occi::Api::Client::Http::Helpers
- Included in:
- ClientHttp
- Defined in:
- lib/occi/api/client/http/helpers.rb
Instance Method Summary collapse
- #configure_connection(options) ⇒ Object
- #get_auth(auth_options, fallback = false) ⇒ Object
- #get_logger(log_options) ⇒ Object
- #get_media_type(force_type = nil) ⇒ Object
- #preauthenticate ⇒ Object
-
#response_message(response) ⇒ String
Generates a human-readable response message based on the HTTP response code.
Instance Method Details
#configure_connection(options) ⇒ Object
15 16 17 18 |
# File 'lib/occi/api/client/http/helpers.rb', line 15 def configure_connection() # timeout is the only global connection option at the moment self.class.default_timeout [:timeout].to_i unless [:timeout].blank? end |
#get_auth(auth_options, fallback = false) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/occi/api/client/http/helpers.rb', line 21 def get_auth(, fallback = false) # select appropriate authN type @authn_plugin = case [:type] when "basic", "digest", "x509", "token" Http::AuthnPlugins.const_get([:type].capitalize).new( self, ) when "keystone" raise ::Occi::Api::Client::Errors::AuthnError, "This authN method is for fallback only!" unless fallback Http::AuthnPlugins::Keystone.new self, when "oauth2" Http::AuthnPlugins::Keystone.new self, when "none", nil Http::AuthnPlugins::Dummy.new self else raise ::Occi::Api::Client::Errors::AuthnError, "Unknown authN method [#{@auth_options[:type]}]!" end @authn_plugin.setup end |
#get_logger(log_options) ⇒ Object
7 8 9 10 11 12 |
# File 'lib/occi/api/client/http/helpers.rb', line 7 def get_logger() logger = super() self.class.debug_output $stderr if logger.level == Occi::Api::Log::DEBUG logger end |
#get_media_type(force_type = nil) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/occi/api/client/http/helpers.rb', line 68 def get_media_type(force_type = nil) # force media_type if provided unless force_type.blank? self.class.headers 'Accept' => force_type media_type = force_type else media_types = self.class.get(@endpoint.to_s).headers['accept'] Occi::Api::Log.debug("Available media types: #{media_types.inspect}") media_type = case media_types when /application\/occi\+json/ 'application/occi+json' when /text\/occi/ 'text/occi' else 'text/plain' end end media_type end |
#preauthenticate ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/occi/api/client/http/helpers.rb', line 48 def preauthenticate begin @authn_plugin.authenticate rescue ::Occi::Api::Client::Errors::AuthnError => e Occi::Api::Log.debug e. if @authn_plugin.fallbacks.any? # TODO: multiple fallbacks [:original_type] = [:type] [:type] = @authn_plugin.fallbacks.first = get_auth(, true) @authn_plugin.authenticate else raise e end end end |
#response_message(response) ⇒ String
Generates a human-readable response message based on the HTTP response code.
98 99 100 101 |
# File 'lib/occi/api/client/http/helpers.rb', line 98 def (response) @last_response = response "HTTP Response status: [#{response.code.to_s}] #{reason_phrase(response.code)}" end |