Skip to content

Instantly share code, notes, and snippets.

@gorborukov
Created March 20, 2019 15:14
Show Gist options
  • Save gorborukov/37e56fa73aa1116f1dc637063d4eddb5 to your computer and use it in GitHub Desktop.
Save gorborukov/37e56fa73aa1116f1dc637063d4eddb5 to your computer and use it in GitHub Desktop.
Yandex Metrika API Ruby example
require 'net/http'
require 'json'
require 'openssl'
class Yandex
uri = URI('https://api-metrika.yandex.net/management/v1/counters')
Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https', :verify_mode => OpenSSL::SSL::VERIFY_NONE) do |http|
req = Net::HTTP::Post.new(uri)
req['Authorization'] = 'OAuth ВАШ_OAUTH_ТОКЕН'
req['Content-Type'] = 'application/x-yametrika+json'
req['Content-Length'] = '123'
json_data = {'counter'=>{'name'=>'test','site2'=>{'site'=>'ВАШ_URL'},'gdpr_agreement_accepted'=>1}}.to_json
req.body = json_data
response = http.request req
json = JSON.parse(response.body)
puts json['counter']['id']
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment