Sha256: 72f05ebb125698aca0efb2d71a2143f9137201c9fbea48d3f0f6ded177f2e2fc

Contents?: true

Size: 664 Bytes

Versions: 2

Compression:

Stored size: 664 Bytes

Contents

module Flattr
  module Request
    class FlattrOAuth2 < Faraday::Middleware

      def call(env)
        if authorization_header
          env[:request_headers]['Authorization'] = authorization_header
        end
        @app.call(env)
      end

      def initialize(app, options)
        @app, @options = app, options
      end

      def authorization_header
        if @options[:access_token]
          "Bearer #{@options[:access_token]}"
        elsif @options[:client_id] && @options[:client_secret]
          "Basic #{base64_encode("#{@options[:client_id]}:#{@options[:client_secret]}")}"
        else
          nil
        end
      end

    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
flattr-0.2.3 lib/flattr/request/oauth2.rb
flattr-0.2.2 lib/flattr/request/oauth2.rb