Skip to content

Commit

Permalink
Fix code example in getting started guide
Browse files Browse the repository at this point in the history
  • Loading branch information
ayushn21 committed Dec 28, 2024
1 parent fb408f4 commit 801f42e
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
Expand Up @@ -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
```

Expand Down

0 comments on commit 801f42e

Please sign in to comment.