Class: Vkponchik::Client
- Inherits:
-
Object
- Object
- Vkponchik::Client
- Defined in:
- lib/vkponchik/client.rb
Overview
API client class
Constant Summary collapse
- API_VERSION =
1- API_BASE =
'https://api.keksik.io'- API_HEADERS =
{ 'Content-Type' => 'application/json' }.freeze
Instance Method Summary collapse
-
#initialize(group, token) ⇒ Client
constructor
Initialize new client.
-
#request(method, **params) ⇒ Hash
Send POST request to API server.
Constructor Details
#initialize(group, token) ⇒ Client
Initialize new client
16 17 18 19 |
# File 'lib/vkponchik/client.rb', line 16 def initialize(group, token) @group = group @token = token end |
Instance Method Details
#request(method, **params) ⇒ Hash
Send POST request to API server
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/vkponchik/client.rb', line 25 def request(method, **params) params[:v] = API_VERSION params[:group] = @group params[:token] = @token uri = URI("#{API_BASE}/#{method}") re = Net::HTTP.post(uri, params.to_json, API_HEADERS) Response.new(JSON.parse(re.body)) rescue StandardError raise Vkponchik::Error, 'Request failure' end |