Sha256: 22d0133d5a04565b2516e790509db19b4d2b84b0c4a2cf94521f384c143f8c7d

Contents?: true

Size: 1011 Bytes

Versions: 6

Compression:

Stored size: 1011 Bytes

Contents

# frozen_string_literal: true

module OAuth
  # Superclass for tokens used by OAuth Clients
  class ConsumerToken < Token
    attr_accessor :consumer, :params
    attr_reader   :response

    def self.from_hash(consumer, hash)
      token = new(consumer, hash[:oauth_token], hash[:oauth_token_secret])
      token.params = hash
      token
    end

    def initialize(consumer, token = "", secret = "")
      super(token, secret)
      @consumer = consumer
      @params   = {}
    end

    # Make a signed request using given http_method to the path
    #
    #   @token.request(:get,  '/people')
    #   @token.request(:post, '/people', @person.to_xml, { 'Content-Type' => 'application/xml' })
    #
    def request(http_method, path, *arguments)
      @response = consumer.request(http_method, path, self, {}, *arguments)
    end

    # Sign a request generated elsewhere using Net:HTTP::Post.new or friends
    def sign!(request, options = {})
      consumer.sign!(request, self, options)
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
oauth-1.1.0 lib/oauth/tokens/consumer_token.rb
oauth-1.0.1 lib/oauth/tokens/consumer_token.rb
oauth-0.6.2 lib/oauth/tokens/consumer_token.rb
oauth-1.0.0 lib/oauth/tokens/consumer_token.rb
oauth-0.6.1 lib/oauth/tokens/consumer_token.rb
oauth-0.6.0 lib/oauth/tokens/consumer_token.rb