module HkpClient::Util
Utilities to be considered as kinda private API.
Public Instance Methods
parse_search_response_entries(src_string)
click to toggle source
rubocop:disable Metrics/MethodLength
# File lib/hkp_client.rb, line 95 def parse_search_response_entries(src_string) src_string.each_line.reduce([]) do |found_keys, line| case line when /\Apub:/ key = response_line_to_hash(line, PUB_ENTRY_FIELDS) key[:uids] = [] found_keys << key when /\Auid:/ uid = response_line_to_hash(line, UID_ENTRY_FIELDS) uid[:name] = CGI.unescape(uid[:name]) found_keys.last[:uids] << uid end found_keys end end
response_body_or_error_or_nil(resp)
click to toggle source
# File lib/hkp_client.rb, line 83 def response_body_or_error_or_nil(resp) if resp.success? resp.body elsif resp.status == 404 nil else raise Error, "Server responded with #{resp.status}" end end
response_line_to_hash(line, field_names)
click to toggle source
rubocop:enable Metrics/MethodLength
# File lib/hkp_client.rb, line 112 def response_line_to_hash(line, field_names) _line_type, *fields = line.strip.split(":") fields.push(nil) while fields.length < field_names.length [field_names, fields].transpose.to_h end