Class: Github::Request::OAuth2
- Inherits:
-
Faraday::Middleware
- Object
- Faraday::Middleware
- Github::Request::OAuth2
- Includes:
- Utils::Url
- Defined in:
- lib/github_api2/request/oauth2.rb
Constant Summary collapse
- ACCESS_TOKEN =
'access_token'.freeze
- AUTH_HEADER =
'Authorization'.freeze
Constants included from Utils::Url
Utils::Url::DEFAULT_QUERY_SEP, Utils::Url::KEY_VALUE_SEP
Instance Method Summary collapse
-
#call(env) ⇒ Object
dependency ‘oauth2’.
-
#initialize(app, *args) ⇒ OAuth2
constructor
A new instance of OAuth2.
- #query_params(url) ⇒ Object
Methods included from Utils::Url
#build_query, #escape, #escape_uri, #normalize, #parse_query, #parse_query_for_param, #unescape
Constructor Details
#initialize(app, *args) ⇒ OAuth2
Returns a new instance of OAuth2.
30 31 32 33 34 |
# File 'lib/github_api2/request/oauth2.rb', line 30 def initialize(app, *args) super app @app = app @token = args.shift end |
Instance Method Details
#call(env) ⇒ Object
dependency ‘oauth2’
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/github_api2/request/oauth2.rb', line 18 def call(env) # Extract parameters from the query params = { ACCESS_TOKEN => @token }.update query_params(env[:url]) if token = params[ACCESS_TOKEN] and !token.empty? env[:url].query = build_query params env[:request_headers].merge!(AUTH_HEADER => "token #{token}") end @app.call env end |
#query_params(url) ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/github_api2/request/oauth2.rb', line 36 def query_params(url) if url.query.nil? or url.query.empty? {} else parse_query url.query end end |