Class: OAuth::ConsumerToken — Documentation by YARD 0.9.45

# Class: OAuth::ConsumerToken

Inherits:
  Token
  - Object
  - Token
  - OAuth::ConsumerToken
  show all

Defined in:
  lib/oauth/tokens/consumer_token.rb

## Overview

Superclass for tokens used by OAuth Clients

## Direct Known Subclasses

AccessToken, RequestToken

## Instance Attribute Summary collapse

- #consumer ⇒ Object

  Returns the value of attribute consumer.

- #params ⇒ Object

  Returns the value of attribute params.

- #response ⇒ Object readonly

  Returns the value of attribute response.

### Attributes inherited from Token

#secret, #token

## Class Method Summary collapse

- .from_hash(consumer, hash) ⇒ Object

## Instance Method Summary collapse

- #initialize(consumer, token = "", secret = "") ⇒ ConsumerToken constructor

  A new instance of ConsumerToken.

- #request(http_method, path, *arguments) ⇒ Object

  Make a signed request using given http_method to the path.

- #sign!(request, options = {}) ⇒ Object

  Sign a request generated elsewhere using Net:HTTP::Post.new or friends.

### Methods inherited from Token

#to_query

### Methods included from Helper

_escape, escape, generate_key, generate_timestamp, normalize, normalize_nested_query, parse_header, stringify_keys, unescape

## Constructor Details

### #initialize(consumer, token = "", secret = "") ⇒ `ConsumerToken`

Returns a new instance of ConsumerToken.

    17
    18
    19
    20
    21
    # File 'lib/oauth/tokens/consumer_token.rb', line 17

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

## Instance Attribute Details

### #consumer ⇒ `Object`

Returns the value of attribute consumer.

    6
    7
    8
    # File 'lib/oauth/tokens/consumer_token.rb', line 6

    def consumer
      @consumer
    end

### #params ⇒ `Object`

Returns the value of attribute params.

    6
    7
    8
    # File 'lib/oauth/tokens/consumer_token.rb', line 6

    def params
      @params
    end

### #response ⇒ `Object` (readonly)

Returns the value of attribute response.

    7
    8
    9
    # File 'lib/oauth/tokens/consumer_token.rb', line 7

    def response
      @response
    end

## Class Method Details

### .from_hash(consumer, hash) ⇒ `Object`

    10
    11
    12
    13
    14
    # File 'lib/oauth/tokens/consumer_token.rb', line 10

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

## Instance Method Details

### #request(http_method, path, *arguments) ⇒ `Object`

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’ })

    28
    29
    30
    # File 'lib/oauth/tokens/consumer_token.rb', line 28

    def request(http_method, path, *arguments)
      @response = consumer.request(http_method, path, self, {}, *arguments)
    end

### #sign!(request, options = {}) ⇒ `Object`

Sign a request generated elsewhere using Net:HTTP::Post.new or friends

    33
    34
    35
    # File 'lib/oauth/tokens/consumer_token.rb', line 33

    def sign!(request, options = {})
      consumer.sign!(request, self, options)
    end