Sha256: a34627f583af722f1c6586b79ee787ac3a5ddb446fa06cc69c16753fceb133f1

Contents?: true

Size: 729 Bytes

Versions: 3

Compression:

Stored size: 729 Bytes

Contents

module LinkedIn
  module FaradayMiddleware
    class CredentialsRequest < Faraday::Middleware
      PARAM_NAME  = 'oauth2_access_token'.freeze

      extend Forwardable
      def_delegators :'Faraday::Utils', :parse_query, :build_query

      def initialize(app, credentials)
        super app
        @credentials = credentials
      end

      def call(env)
        params = query_params(env[:url]).reverse_merge PARAM_NAME => @credentials.access_token
        token = params[PARAM_NAME]

        env[:url].query = build_query params unless token.blank?

        @app.call env
      end

      private

      def query_params(url)
        return {} if url.query.blank?
        parse_query url.query
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
linkedin2-0.0.19 lib/linkedin/faraday_middleware/credentials_request.rb
linkedin2-0.0.18 lib/linkedin/faraday_middleware/credentials_request.rb
linkedin2-0.0.17 lib/linkedin/faraday_middleware/credentials_request.rb