Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'uri'
- require 'json'
- require 'net/http'
- class VK
- def initialize(access_token=nil, v='5.45')
- @access_token = access_token
- @v = v
- end
- def method_missing(name, options)
- qname = name.to_s.sub('_', '.')
- norm_options = {access_token: @access_token, v: @v}
- options.each do |k, v|
- if v.is_a? Array
- norm_options[k] = v.join(',')
- else
- norm_options[k] = v
- end
- end
- qstring = URI.encode_www_form(norm_options)
- url = "https://api.vk.com/method/#{qname}.json"
- http = Net::HTTP.new('api.vk.com', 443)
- http.use_ssl = true
- request = Net::HTTP::Post.new(url)
- request.body = qstring
- response = http.request(request)
- JSON.parse(response.body)
- end
- end
- vk = VK.new
- puts vk.users_get(user_ids: ['durov', 6])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement