N
N
NakedFace2016-03-03 16:00:10
ruby
NakedFace, 2016-03-03 16:00:10

How to send a GET request to Yandex Ruby?

There is such a request, take from the Yandex API
GET /api2/admin/dkim/status?domain=domain.com&secretkey=yes HTTP/1.1
Host: pddimp.yandex.ru
PddToken: 123456789ABCDEF0000000000000000000000000000000000000
How can it be sent via Ruby?
Thank you.
Tried like this

require 'net/http'
require 'rubygems'
require 'json'

url = 'https://pddimp.yandex.ru/api2/admin/dkim/status?domain=domain.com&secretkey=yes'
uri = URI.parse(url)

request = Net::HTTP::Get.new(uri.path)
request['PddToken'] = 'some token'

response = Net::HTTP.new(uri.host,uri.port) do |http|
  http.request(request)
end
p response

So:
headers = {"PddToken" => "some token"}
http = Net::HTTP.new(uri.host,uri.port)

response = http.get(uri.path,headers)
puts response.code
puts response.body

And even like this:
uri = URI('pddimp.yandex.ru/api2/admin/dkim/status?domain=domain.com&secretkey=yes')
params = { "PddToken" => "some token" }
uri.query = URI.encode_www_form(params)

res = Net::HTTP.get_response(uri)
puts res.body if res.is_a?(Net::HTTPSuccess)

Naturally, the domain and token wrote their own

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
vadimstroganov, 2016-03-04
@vadimstroganov

Use the rest-client gem

request = RestClient.get("http://pddimp.yandex.ru/api2/admin/dkim/status?domain=domain.com&secretkey=yes",
                    :params => { :"PddToken" => "some token" })

M
musicov2, 2018-02-19
@musikov2

It turned out not without torment to use the cURL utility to manage the DNS. The torment arose because of the crooked Yandex help.
1. Read about cURL on Wikipedia https://ru.wikipedia.org/wiki/CURL
2. Installed curl in Windows using the help from here: How to install/configure and use cURL in Windows? https :
//curl.haxx.se/dlwiz/ ?type=bin&os=Win64&flav... 3. Launched get request and received an adequate response (Attention - there must be double quotes!!!) GET curl -H "PddToken: TKJ*****BCQ" " https://pddimp.yandex.ru/api2/admin/dns/list?domai ... " POST
curl -H "PddToken: TKJ****************" -d "domain=*******.ru&type=A&content=194.**.**.**" " https://pddimp.yandex.ru/api2/admin/dns/add "
Happy as an elephant!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question