Created
March 20, 2019 15:14
-
-
Save gorborukov/37e56fa73aa1116f1dc637063d4eddb5 to your computer and use it in GitHub Desktop.
Yandex Metrika API Ruby example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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