···1314## Installation
150016 gem install didkit
0000171819## Usage
2021-Use the `DIDKit::Resolver` class to look up DIDs and handles.
22-23-To look up a handle:
2425```rb
26-resolver = DIDKit::Resolver.new
27-resolver.resolve_handle('nytimes.com')
28- # => #<DIDKit::DID:0x00000001035956b0 @did="did:plc:eclio37ymobqex2ncko63h4r", @type=:plc, @resolved_by=:dns>
29```
3031-This returns an object of `DIDKit::DID` class (aliased as just `DID`), which tells you:
3233- the DID as a string (`#to_s` or `#did`)
34- the DID type (`#type`, `:plc` or `:web`)
35- if the handle was resolved via a DNS entry or a `.well-known` file (`#resolved_by`, `:dns` or `:http`)
3637-To go in the other direction – to find an assigned and verified handle given a DID – use `get_validated_handle` (pass DID as a string or an object):
3839```rb
40-resolver.get_validated_handle('did:plc:ewvi7nxzyoun6zhxrhs64oiz')
41- # => "atproto.com"
42```
4344-You can also load the DID document using `resolve_did`:
4546```rb
47-doc = resolver.resolve_did('did:plc:ragtjsm2j2vknwkz3zp4oxrd')
48- # => #<DIDKit::Document:0x0000000105d751f8 @did=#<DIDKit::DID:...>, @json={...}>
4950-doc.handles
51- # => ["pfrazee.com"]
5253-doc.pds_endpoint
54- # => "https://morel.us-east.host.bsky.network"
55```
5657-There are also some helper methods in the `DID` class that create a `Resolver` for you to save you some typing:
5859-```rb
60-did = DID.resolve_handle('jay.bsky.team')
61- # => #<DIDKit::DID:0x000000010615ed28 @did="did:plc:oky5czdrnfjpqslsw2a5iclo", @type=:plc, @resolved_by=:dns>
6263-did.to_s
64- # => "did:plc:oky5czdrnfjpqslsw2a5iclo"
6566-did.get_document
67- # => #<DIDKit::Document:0x00000001066d4898 @did=#<DIDKit::DID:...>, @json={...}>
0000006869-did.get_validated_handle
70- # => "jay.bsky.team"
00071```
72-7374### Configuration
7576-You can override the nameserver used for DNS lookups by setting the `nameserver` property in `Resolver`, e.g. to use Google's or CloudFlare's global DNS:
7778-```
79-resolver.nameserver = '8.8.8.8'
80-```
00008100000000000008283## Credits
84
···1314## Installation
1516+From the command line:
17+18 gem install didkit
19+20+Or, add this to your `Gemfile`:
21+22+ gem 'didkit', '~> 0.3'
232425## Usage
2627+The simplest way to use the gem is through the `DIDKit::DID` class, aliased as just `DID`:
002829```rb
30+did = DID.resolve_handle('jay.bsky.team')
31+ # => #<DIDKit::DID:0x0... @did="did:plc:oky5czdrnfjpqslsw2a5iclo",
32+ # @resolved_by=:dns, @type=:plc>
33```
3435+This returns a `DID` object, which tells you:
3637- the DID as a string (`#to_s` or `#did`)
38- the DID type (`#type`, `:plc` or `:web`)
39- if the handle was resolved via a DNS entry or a `.well-known` file (`#resolved_by`, `:dns` or `:http`)
4041+To go in the other direction – to find an assigned and verified handle given a DID – create a `DID` from a DID string and call `get_verified_handle`:
4243```rb
44+DID.new('did:plc:ewvi7nxzyoun6zhxrhs64oiz').get_verified_handle
45+ # => "atproto.com"
46```
4748+You can also load the DID JSON document using `#document`, which returns a `DIDKit::Document` (`DID` caches the document, so don't worry about calling this method multiple times):
4950```rb
51+did = DID.new('did:plc:ragtjsm2j2vknwkz3zp4oxrd')
05253+did.document.handles
54+ # => ["pfrazee.com"]
5556+did.document.pds_host
57+ # => "morel.us-east.host.bsky.network"
58```
5906061+### Checking account status
006263+`DIDKit::DID` also includes a few methods for checking the status of a given account (repo), which call the `com.atproto.sync.getRepoStatus` endpoint on the account's assigned PDS:
06465+```rb
66+did = DID.new('did:plc:ch7azdejgddtlijyzurfdihn')
67+did.account_status
68+ # => :takendown
69+did.account_active?
70+ # => false
71+did.account_exists?
72+ # => true
7374+did = DID.new('did:plc:44ybard66vv44zksje25o7dz')
75+did.account_status
76+ # => :active
77+did.account_active?
78+ # => true
79```
08081### Configuration
8283+You can customize some things about the DID/handle lookups by using the `DIDKit::Resolver` class, which the methods in `DID` use behind the scenes.
8485+Currently available options include:
86+87+- `:nameserver` - override the nameserver used for DNS lookups, e.g. to use Google's or CloudFlare's DNS
88+- `:timeout` - change the connection/response timeout for HTTP requests (default: 15 s)
89+- `:max_redirects` - change allowed maximum number of redirects (default: 5)
90+91+Example:
9293+```rb
94+resolver = DIDKit::Resolver.new(nameserver: '8.8.8.8', timeout: 30)
95+96+did = resolver.resolve_handle('nytimes.com')
97+ # => #<DIDKit::DID:0x0... @did="did:plc:eclio37ymobqex2ncko63h4r",
98+ # @resolved_by=:dns, @type=:plc>
99+100+resolver.resolve_did(did)
101+ # => #<DIDKit::Document:0x0... @did=#<DIDKit::DID:...>, @json={...}>
102+103+resolver.get_verified_handle(did)
104+ # => 'nytimes.com'
105+```
106107## Credits
108