Module: SimpleOAuth::Encoding

Included in:
Header
Defined in:
lib/simple_oauth/encoding.rb

Overview

OAuth percent-encoding utilities

Provides methods for encoding and decoding values according to the OAuth specification. These methods can be used as module functions or extended into a class.

Examples:

Using as module functions

SimpleOAuth::Encoding.escape("hello world") # => "hello%20world"

Extending into a class

class MyClass
  extend SimpleOAuth::Encoding
end
MyClass.escape("hello world") # => "hello%20world"

Constant Summary collapse

UNRESERVED_CHARS =

Characters that don't need to be escaped per OAuth spec

/[^a-z0-9\-._~]/i

Instance Method Summary collapse

Instance Method Details

#escape(value) ⇒ String Also known as: encode

Percent-encodes a value according to OAuth specification

Examples:

SimpleOAuth::Encoding.escape("hello world")
# => "hello%20world"

Parameters:

  • value (String, #to_s)

    the value to encode

Returns:

  • (String)

    the percent-encoded value



30
31
32
# File 'lib/simple_oauth/encoding.rb', line 30

def escape(value)
  URI::RFC2396_PARSER.escape(value.to_s, UNRESERVED_CHARS)
end

#unescape(value) ⇒ String Also known as: decode

Decodes a percent-encoded value

Examples:

SimpleOAuth::Encoding.unescape("hello%20world")
# => "hello world"

Parameters:

  • value (String, #to_s)

    the value to decode

Returns:

  • (String)

    the decoded value



43
44
45
# File 'lib/simple_oauth/encoding.rb', line 43

def unescape(value)
  URI::RFC2396_PARSER.unescape(value.to_s)
end