A library for handling DID identifiers used in Bluesky AT Protocol

Revert (partially) "minor tweaks to operation/document parsing"

This reverts commit 70adf5008fe8985f9d7061e6a45e2ad13364bc8a.

+14 -9
+6 -4
lib/didkit/document.rb
··· 71 71 def parse_services(service_data) 72 72 raise FormatError, "Invalid service data" unless service_data.is_a?(Array) && service_data.all? { |x| x.is_a?(Hash) } 73 73 74 - service_data.map do |x| 74 + services = [] 75 + 76 + service_data.each do |x| 75 77 id, type, endpoint = x.values_at('id', 'type', 'serviceEndpoint') 76 78 77 79 if id.is_a?(String) && id.start_with?('#') && type.is_a?(String) && endpoint.is_a?(String) 78 - ServiceRecord.new(id.gsub(/^#/, ''), type, endpoint) 79 - else 80 - raise FormatError, "Invalid service data" 80 + services << ServiceRecord.new(id.gsub(/^#/, ''), type, endpoint) 81 81 end 82 82 end 83 + 84 + services 83 85 end 84 86 end 85 87 end
+8 -5
spec/document_spec.rb
··· 120 120 end 121 121 end 122 122 123 - context 'when some service entries are not valid' do 123 + context 'when service entries are partially valid' do 124 124 let(:services) { 125 125 [ 126 126 { 'id' => '#atproto_pds', 'type' => 'AtprotoPersonalDataServer', 'serviceEndpoint' => 'https://pds.dholms.xyz' }, ··· 133 133 134 134 let(:json) { base_json.merge('service' => services) } 135 135 136 - it 'should raise a format error' do 137 - expect { 138 - subject.new(did, json) 139 - }.to raise_error(DIDKit::FormatError) 136 + it 'should only keep the valid records' do 137 + doc = subject.new(did, json) 138 + 139 + doc.services.length.should == 2 140 + doc.services.map(&:key).should == ['atproto_pds', 'lycan'] 141 + doc.services.map(&:type).should == ['AtprotoPersonalDataServer', 'LycanService'] 142 + doc.services.map(&:endpoint).should == ['https://pds.dholms.xyz', 'https://lycan.feeds.blue'] 140 143 end 141 144 end 142 145 end