Sha256: 3dac6644f8f90d19bcdd869eb2ae076a003e39f24bac4d71f0098c73f3f91253

Contents?: true

Size: 1.15 KB

Versions: 6

Compression:

Stored size: 1.15 KB

Contents

# encoding: utf-8

require 'faraday'

module BitBucket
  module Request
    class OAuth < Faraday::Middleware
      include BitBucket::Utils::Url

      AUTH_HEADER  = 'Authorization'.freeze

      dependency 'simple_oauth'

      def call(env)
        # Extract parameters from the query
        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

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

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

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
bitbucket_rest_api-0.1.7 lib/bitbucket_rest_api/request/oauth.rb
reenhanced_bitbucket_api-0.1.6 lib/bitbucket_rest_api/request/oauth.rb
bitbucket_rest_api-0.1.5 lib/bitbucket_rest_api/request/oauth.rb
bitbucket_rest_api-0.1.4 lib/bitbucket_rest_api/request/oauth.rb
bitbucket_rest_api-0.1.2 lib/bitbucket_rest_api/request/oauth.rb
bitbucket_rest_api-0.1.1 lib/bitbucket_rest_api/request/oauth.rb