A library for handling DID identifiers used in Bluesky AT Protocol

added DID#account_status method

+29
+29
lib/didkit/did.rb
··· 69 69 end 70 70 end 71 71 72 + def account_status 73 + doc = get_document 74 + return nil if doc.pds_endpoint.nil? 75 + 76 + pds_host = URI(doc.pds_endpoint).origin 77 + url = URI("#{pds_host}/xrpc/com.atproto.sync.getRepoStatus") 78 + url.query = URI.encode_www_form(:did => @did) 79 + 80 + response = get_response(url, { timeout: 15, max_redirects: 5 }) 81 + status = response.code.to_i 82 + is_json = (response['Content-Type'] =~ /^application\/json(;.*)?$/) 83 + 84 + if status == 200 && is_json 85 + json = JSON.parse(response.body) 86 + 87 + if json['active'] == true 88 + :active 89 + elsif json['active'] == false && json['status'].is_a?(String) && json['status'].length <= 100 90 + json['status'].to_sym 91 + else 92 + raise APIError.new(response) 93 + end 94 + elsif status == 400 && is_json && JSON.parse(response.body)['error'] == 'RepoNotFound' 95 + nil 96 + else 97 + raise APIError.new(response) 98 + end 99 + end 100 + 72 101 def account_exists? 73 102 doc = get_document 74 103 return false if doc.pds_endpoint.nil?