Parent

Class/Module Index [+]

Quicksearch

SimpleOAuth::Header

Constants

ATTRIBUTE_KEYS

Attributes

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

Public Class Methods

decode(value) click to toggle source
# File lib/simple_oauth/header.rb, line 18
def self.decode(value)
  URI.decode(value.to_s)
end
default_options() click to toggle source
# File lib/simple_oauth/header.rb, line 5
def self.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
# File lib/simple_oauth/header.rb, line 14
def self.encode(value)
  URI.encode(value.to_s, /[^a-z0-9\-\.\_\~]/)
end
new(method, url, params, oauth = {}) click to toggle source
# File lib/simple_oauth/header.rb, line 31
def initialize(method, url, params, oauth = {})
  @method = method.to_s.upcase
  @uri = URI.parse(url).tap do |uri|
    uri.scheme = uri.scheme.downcase
    uri.normalize!
    uri.fragment = nil
  end
  @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 22
def self.parse(header)
  header.to_s.sub(/^OAuth\s/, '').split(', ').inject({}) do |attributes, pair|
    match = pair.match(/^(\w+)\=\"([^\"]*)\"$/)
    attributes.merge(match[1].sub(/^oauth_/, '').to_sym => decode(match[2]))
  end
end

Public Instance Methods

signed_attributes() click to toggle source
# File lib/simple_oauth/header.rb, line 58
def signed_attributes
  attributes.merge(:oauth_signature => signature)
end
to_s() click to toggle source
# File lib/simple_oauth/header.rb, line 46
def to_s
  "OAuth #{normalized_attributes}"
end
url() click to toggle source
# File lib/simple_oauth/header.rb, line 42
def url
  @uri.dup.tap{|u| u.query = nil }.to_s
end
valid?(secrets = {}) click to toggle source
# File lib/simple_oauth/header.rb, line 50
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.