Sha256: 0ae9de63a1f690e6f8ebf7cfd6d00639ccad657b352cb01180176d7f95e51953

Contents?: true

Size: 1.13 KB

Versions: 5

Compression:

Stored size: 1.13 KB

Contents

# encoding: utf-8

require 'faraday'

module BitBucket
  class 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

5 entries across 5 versions & 2 rubygems

Version Path
codenamev_bitbucket_api-0.4.1 lib/bitbucket_rest_api/request/oauth.rb
codenamev_bitbucket_api-0.4.0 lib/bitbucket_rest_api/request/oauth.rb
reenhanced_bitbucket_api-0.3.2 lib/bitbucket_rest_api/request/oauth.rb
reenhanced_bitbucket_api-0.3.1 lib/bitbucket_rest_api/request/oauth.rb
reenhanced_bitbucket_api-0.3.0 lib/bitbucket_rest_api/request/oauth.rb