Class: HTTP::TokenAuth::SchemeParser
- Inherits:
-
Object
- Object
- HTTP::TokenAuth::SchemeParser
- Defined in:
- lib/http/token_auth/scheme_parser.rb
Instance Method Summary collapse
Instance Method Details
#parse(string) ⇒ Object
7 8 9 10 11 12 13 14 |
# File 'lib/http/token_auth/scheme_parser.rb', line 7 def parse(string) scheme, attributes_string = split(string) raise SchemeParsingError, 'No attributes provided' if attributes_string.nil? raise SchemeParsingError, %(Unsupported scheme "#{scheme}") unless scheme == 'Token' parse_attributes(attributes_string) end |
#parse_attributes(string) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/http/token_auth/scheme_parser.rb', line 20 def parse_attributes(string) attributes = {} string.scan(/(\w+)="([^"]*)"/).each do |group| attributes[group[0].to_sym] = group[1] end attributes end |
#split(string) ⇒ Object
16 17 18 |
# File 'lib/http/token_auth/scheme_parser.rb', line 16 def split(string) string.split(' ', 2) end |