Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix code example in getting started guide
Browse files Browse the repository at this point in the history
ayushn21 authored and ioquatix committed Jan 3, 2025
1 parent fb408f4 commit 2caba2f
Showing 1 changed file with 25 additions and 25 deletions.
50 changes: 25 additions & 25 deletions guides/getting-started/readme.md
Original file line number Diff line number Diff line change
@@ -27,34 +27,34 @@ Generally speaking, you should model your interface around representations. Each
require 'async/rest'

module DNS
class Query < Async::REST::Representation[Async::REST::Wrapper::JSON]
def question
value[:Question]
end
def answer
value[:Answer]
end
end
class Client < Async::REST::Resource
# This is the default endpoint to use unless otherwise specified:
ENDPOINT = Async::HTTP::Endpoint.parse('https://dns.google/resolve')
# Resolve a DNS query.
def resolve(name, type)
self.call(Query, name: name, type: type)
end
end
class Query < Async::REST::Representation[Async::REST::Wrapper::JSON]
def question
value[:Question]
end

def answer
value[:Answer]
end
end

class Client < Async::REST::Resource
# This is the default endpoint to use unless otherwise specified:
ENDPOINT = Async::HTTP::Endpoint.parse('https://dns.google/resolve')

# Resolve a DNS query.
def resolve(name, type)
Query.get(self.with(parameters: { name: name, type: type }))
end
end
end

DNS::Client.open do |client|
query = client.resolve('example.com', 'AAAA')
puts query.question
# {:name=>"example.com.", :type=>28}
puts query.answer
# {:name=>"example.com.", :type=>28, :TTL=>13108, :data=>"2606:2800:220:1:248:1893:25c8:1946"}
query = client.resolve('example.com', 'AAAA')

puts query.question
# {:name=>"example.com.", :type=>28}
puts query.answer
# {:name=>"example.com.", :type=>28, :TTL=>13108, :data=>"2606:2800:220:1:248:1893:25c8:1946"}
end
```

0 comments on commit 2caba2f

Please sign in to comment.