Class: BitBucket::Request::OAuth

Inherits:
Faraday::Middleware
  • Object
show all
Includes:
Utils::Url
Defined in:
lib/bitbucket_rest_api/request/oauth.rb

Constant Summary collapse

AUTH_HEADER =
'Authorization'.freeze

Constants included from Utils::Url

Utils::Url::DEFAULT_QUERY_SEP, Utils::Url::KEY_VALUE_SEP

Instance Method Summary collapse

Methods included from Utils::Url

#build_query, #escape, #parse_query, #parse_query_for_param, #unescape

Constructor Details

#initialize(app, *args) ⇒ OAuth

Returns a new instance of OAuth.



36
37
38
39
40
41
42
# File 'lib/bitbucket_rest_api/request/oauth.rb', line 36

def initialize(app, *args)
  super app
  @app = app
  @consumer = args.shift
  @token = args.shift
  @secret = args.shift
end

Instance Method Details

#call(env) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/bitbucket_rest_api/request/oauth.rb', line 14

def call(env)
  # Extract parameters from the query
  request = Rack::Request.new env
  env[:url] = URI.parse(request.url) if env[:url].nil?
  params = {  }.update query_params(env[:url])

  if (@token and @secret) and (!@token.empty? and !@secret.empty?)
    access_token = ::OAuth::AccessToken.new(@consumer, @token, @secret)
    env[:url].query = build_query params

    puts oauth_helper.header
    puts oauth_helper.header.class
    env[:request_headers].merge!(AUTH_HEADER => oauth_helper.header)
  end

    env[:url].query = build_query params



  @app.call env
end

#query_params(url) ⇒ Object



44
45
46
47
48
49
50
# File 'lib/bitbucket_rest_api/request/oauth.rb', line 44

def query_params(url)
  if url.query.nil? or url.query.empty?
    {}
  else
    parse_query url.query
  end
end