Advertisement
andreymal

vktest.rb

Feb 27th, 2016
327
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.64 KB | None | 0 0
  1. require 'uri'
  2. require 'json'
  3. require 'net/http'
  4.  
  5. class VK
  6.   def initialize(access_token=nil, v='5.45')
  7.     @access_token = access_token
  8.     @v = v
  9.   end
  10.  
  11.   def method_missing(name, options)
  12.     qname = name.to_s.sub('_', '.')
  13.     qstring = URI.encode_www_form({access_token: @access_token, v: @v}.merge(options))
  14.  
  15.     url = "https://api.vk.com/method/#{qname}.json"
  16.     http = Net::HTTP.new('api.vk.com', 443)
  17.     http.use_ssl = true
  18.  
  19.     request = Net::HTTP::Post.new(url)
  20.     request.body = qstring
  21.  
  22.     response = http.request(request)
  23.     JSON.parse(response.body)
  24.   end
  25. end
  26.  
  27. vk = VK.new
  28. puts vk.users_get(user_ids: 'durov,6')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement