class Academical::HttpClient::AuthHandler
AuthHandler
takes care of devising the auth type and using it
Constants
- HTTP_HEADER
Public Class Methods
new(app, auth = {}, options = {})
click to toggle source
Calls superclass method
# File lib/academical/http_client/auth_handler.rb, line 12 def initialize(app, auth = {}, options = {}) @auth = auth super(app) end
Public Instance Methods
call(env)
click to toggle source
# File lib/academical/http_client/auth_handler.rb, line 17 def call(env) if !@auth.empty? auth = get_auth_type flag = false if auth == HTTP_HEADER env = http_header(env) flag = true end if !flag raise StandardError.new "Unable to calculate authorization method. Please check" end else raise StandardError.new "Server requires authentication to proceed further. Please check" end @app.call(env) end
get_auth_type()
click to toggle source
Calculating the Authentication Type
# File lib/academical/http_client/auth_handler.rb, line 38 def get_auth_type() if @auth.has_key?(:http_header) return HTTP_HEADER end return -1 end
http_header(env)
click to toggle source
Authorization with HTTP header
# File lib/academical/http_client/auth_handler.rb, line 48 def http_header(env) env[:request_headers]["Authorization"] = "Bearer #{@auth[:http_header]}" return env end
merge_query(env, query)
click to toggle source
# File lib/academical/http_client/auth_handler.rb, line 62 def merge_query(env, query) query = query.update query_params(env[:url]) env[:url].query = Faraday::Utils.build_query(query) return env end
query_params(url)
click to toggle source
# File lib/academical/http_client/auth_handler.rb, line 54 def query_params(url) if url.query.nil? or url.query.empty? {} else Faraday::Utils.parse_query(url.query) end end