Class: SimpleOAuth::Header

### Home Classes Methods

### In Files

- lib/simple_oauth/header.rb

### Parent

Object

### Methods

- ::decode
- ::default_options
- ::encode
- ::escape
- ::new
- ::parse
- ::unescape
- #signed_attributes
- #to_s
- #url
- #valid?

### Class/Module Index

Quicksearch

- SimpleOAuth
- SimpleOAuth::Header

No matching classes.

# SimpleOAuth::Header

### Constants

ATTRIBUTE_KEYS

### Attributes

method[R]
options[R]
params[R]

### Public Class Methods

decode(value) click to toggle source
Alias for: unescape
default_options() click to toggle source

    # File lib/simple_oauth/header.rb, line 12
    def default_options
      {
        :nonce => OpenSSL::Random.random_bytes(16).unpack('H*')[0],
        :signature_method => 'HMAC-SHA1',
        :timestamp => Time.now.to_i.to_s,
        :version => '1.0'
      }
    end

encode(value) click to toggle source
Alias for: escape
escape(value) click to toggle source

    # File lib/simple_oauth/header.rb, line 28
    def escape(value)
      uri_parser.escape(value.to_s, /[^a-z0-9\-\.\_\~]/)
    end

Also aliased as: encode
new(method, url, params, oauth = {}) click to toggle source

    # File lib/simple_oauth/header.rb, line 46
    def initialize(method, url, params, oauth = {})
      @method = method.to_s.upcase
      @uri = URI.parse(url.to_s)
      @uri.scheme = @uri.scheme.downcase
      @uri.normalize!
      @uri.fragment = nil
      @params = params
      @options = oauth.is_a?(Hash) ? self.class.default_options.merge(oauth) : self.class.parse(oauth)
    end

parse(header) click to toggle source

    # File lib/simple_oauth/header.rb, line 21
    def parse(header)
      header.to_s.sub(/^OAuth\s/, '').split(/,\s*/).inject({}) do |attributes, pair|
        match = pair.match(/^(\w+)\=\"([^\"]*)\"$/)
        attributes.merge(match[1].sub(/^oauth_/, '').to_sym => decode(match[2]))
      end
    end

unescape(value) click to toggle source

    # File lib/simple_oauth/header.rb, line 33
    def unescape(value)
      uri_parser.unescape(value.to_s)
    end

Also aliased as: decode

### Public Instance Methods

signed_attributes() click to toggle source

    # File lib/simple_oauth/header.rb, line 74
    def signed_attributes
      attributes.merge(:oauth_signature => signature)
    end

to_s() click to toggle source

    # File lib/simple_oauth/header.rb, line 62
    def to_s
      "OAuth #{normalized_attributes}"
    end

url() click to toggle source

    # File lib/simple_oauth/header.rb, line 56
    def url
      uri = @uri.dup
      uri.query = nil
      uri.to_s
    end

valid?(secrets = {}) click to toggle source

    # File lib/simple_oauth/header.rb, line 66
    def valid?(secrets = {})
      original_options = options.dup
      options.merge!(secrets)
      valid = options[:signature] == signature
      options.replace(original_options)
      valid
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.