tangled
alpha
login
or
join now
mackuba.eu
/
didkit
1
fork
atom
A library for handling DID identifiers used in Bluesky AT Protocol
1
fork
atom
overview
issues
pulls
pipelines
added DID#account_status method
mackuba.eu
2 years ago
456b4818
fd92978c
+29
1 changed file
expand all
collapse all
unified
split
lib
didkit
did.rb
+29
lib/didkit/did.rb
···
69
69
end
70
70
end
71
71
72
72
+
def account_status
73
73
+
doc = get_document
74
74
+
return nil if doc.pds_endpoint.nil?
75
75
+
76
76
+
pds_host = URI(doc.pds_endpoint).origin
77
77
+
url = URI("#{pds_host}/xrpc/com.atproto.sync.getRepoStatus")
78
78
+
url.query = URI.encode_www_form(:did => @did)
79
79
+
80
80
+
response = get_response(url, { timeout: 15, max_redirects: 5 })
81
81
+
status = response.code.to_i
82
82
+
is_json = (response['Content-Type'] =~ /^application\/json(;.*)?$/)
83
83
+
84
84
+
if status == 200 && is_json
85
85
+
json = JSON.parse(response.body)
86
86
+
87
87
+
if json['active'] == true
88
88
+
:active
89
89
+
elsif json['active'] == false && json['status'].is_a?(String) && json['status'].length <= 100
90
90
+
json['status'].to_sym
91
91
+
else
92
92
+
raise APIError.new(response)
93
93
+
end
94
94
+
elsif status == 400 && is_json && JSON.parse(response.body)['error'] == 'RepoNotFound'
95
95
+
nil
96
96
+
else
97
97
+
raise APIError.new(response)
98
98
+
end
99
99
+
end
100
100
+
72
101
def account_exists?
73
102
doc = get_document
74
103
return false if doc.pds_endpoint.nil?