Module: VkLongpollBot::Request
- Defined in:
- lib/vk_longpoll_bot/request.rb
Overview
Some functions to send HTTP requests.
Class Method Summary collapse
-
.api(method_name, parameters, access_token, v = VK_API_CURRENT_VERSION) ⇒ Hash
GET request to VK API.
-
.longpoll(server, key, ts, wait = LONGPOLL_STANDART_WAIT) ⇒ Hash
GET request to longpoll server.
-
.to(url) ⇒ String
Regular GET HTTP request to given URI.
Class Method Details
.api(method_name, parameters, access_token, v = VK_API_CURRENT_VERSION) ⇒ Hash
GET request to VK API.
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/vk_longpoll_bot/request.rb', line 30 def self.api(method_name, parameters, access_token, v = VK_API_CURRENT_VERSION) response = JSON.parse self.to("#{VK_API_URL_BASE}/method/#{method_name}?access_token=#{access_token}&v=#{v.to_s}&#{URI.encode_www_form(parameters)}") if response["response"] response["response"] elsif response["error"] raise Exceptions::APIError.new(response) else raise Exceptions::ResponseError.new(response) end end |
.longpoll(server, key, ts, wait = LONGPOLL_STANDART_WAIT) ⇒ Hash
GET request to longpoll server.
50 51 52 |
# File 'lib/vk_longpoll_bot/request.rb', line 50 def self.longpoll(server, key, ts, wait = LONGPOLL_STANDART_WAIT) JSON.parse self.to("#{server}?act=a_check&key=#{key}&ts=#{ts}&wait=#{wait}") end |
.to(url) ⇒ String
Regular GET HTTP request to given URI.
16 17 18 19 |
# File 'lib/vk_longpoll_bot/request.rb', line 16 def self.to(url) uri = URI(url.to_s) Net::HTTP.get(uri) end |