Sha256: 1f4c4f0d504a94e7a7adc7c3f4fa5a011b61469ddecdf2b6c5df7728e696345c

Contents?: true

Size: 1.03 KB

Versions: 4

Compression:

Stored size: 1.03 KB

Contents

require 'addressable/uri'
require 'base64'
require 'simple_oauth'

module Instapaper
  module HTTP
    class Headers
      def initialize(client, request_method, url, options = {})
        @client = client
        @request_method = request_method.to_sym
        @uri = Addressable::URI.parse(url)
        @options = options
      end

      def request_headers
        {
          user_agent: @client.user_agent,
          authorization: oauth_header,
        }
      end

      private

      def oauth_header
        SimpleOAuth::Header.new(@request_method, @uri, @options, credentials.merge(ignore_extra_keys: true))
      end

      # Authentication hash
      #
      # @return [Hash]
      def credentials
        if @client.credentials?
          {
            consumer_key: @client.consumer_key,
            consumer_secret: @client.consumer_secret,
            token: @client.oauth_token,
            token_secret: @client.oauth_token_secret,
          }
        else
          @client.consumer_credentials
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
instapaper-1.0.1 lib/instapaper/http/headers.rb
instapaper-1.0.0 lib/instapaper/http/headers.rb
instapaper-1.0.0.pre3 lib/instapaper/http/headers.rb
instapaper-1.0.0.pre2 lib/instapaper/http/headers.rb