Class: Request::TokenAuthentication

Inherits:
Faraday::Middleware
  • Object
show all
Defined in:
lib/gh/faraday.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, token, options = {}) ⇒ TokenAuthentication

Returns a new instance of TokenAuthentication.



71
72
73
74
75
76
77
78
79
80
81
# File 'lib/gh/faraday.rb', line 71

def initialize(app, token, options={})
  super(app)

  # values = ["token=#{token.to_s.inspect}"]
  #         options.each do |key, value|
  #           values << "#{key}=#{value.to_s.inspect}"
  #         end
  #         comma = ",\n#{' ' * ('Authorization: Token '.size)}"
  #         @header_value = "Token #{values * comma}"
  @header_value = "token #{token}"
end

Instance Method Details

#call(env) ⇒ Object



83
84
85
86
87
88
# File 'lib/gh/faraday.rb', line 83

def call(env)
  unless env[:request_headers]['Authorization']
    env[:request_headers]['Authorization'] = @header_value
  end
  @app.call(env)
end