Class: RETS4R::Auth::ResponseHeader

Inherits:
Object
  • Object
show all
Defined in:
lib/rets4r/auth.rb

Constant Summary collapse

ACCEPTABLE_KEYS =
%w[realm domain nonce opaque stale algorithm qop]

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.parse(header) ⇒ Object



146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/rets4r/auth.rb', line 146

def self.parse(header)
  new.tap do |auth|
    auth.strategy = header[0, header.index(' ')].downcase.to_sym
    args = header[header.index(' '), header.length].strip.split(',')

    args.each do |arg|
      key, value = arg.split('=')
      key = key.downcase.strip
      value = value.tr('"', '').strip
      if ACCEPTABLE_KEYS.include? key
        auth.send("#{key}=".to_sym, value)
      else
        warn "#{caller.first}: warning: response header contained unknown value #{key}: \"#{value}\", skipping"
      end
    end
  end
end

Instance Method Details

#to_hObject

convert the header to a hash. Uses strings for keys, with ‘type containing the Examples:

header = 'Digest qop="auth", realm="REALM", nonce="2006-03-03T17:37:10", opaque="", stale="false", domain="test-domain"'
ResponseHeader.parse(header).to_h
=> { "type" => "digest", "qop" => "auth", "realm" => "REALM", "nonce" => "2006-03-03T17:37:10", "opaque" => "", "stale" => "false", "domain" => "test-domain"}


169
170
171
172
173
174
175
176
# File 'lib/rets4r/auth.rb', line 169

def to_h
  result = {}
  result['type'] = self.strategy
  ACCEPTABLE_KEYS.each do |key|
    result[key] = self.send(key)
  end
  result
end