Class: Vkit::CLI::API::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/vkit/cli/api/client.rb

Constant Summary collapse

DEFAULT_TIMEOUT =
15

Instance Method Summary collapse

Constructor Details

#initialize(base_url:, token:) ⇒ Client

Returns a new instance of Client.

Raises:

  • (ArgumentError)


13
14
15
16
17
18
19
# File 'lib/vkit/cli/api/client.rb', line 13

def initialize(base_url:, token:)
  raise ArgumentError, "base_url required" if base_url.nil?
  raise ArgumentError, "token required" if token.nil?

  @base_url = base_url.chomp("/")
  @token    = token
end

Instance Method Details

#get(path, params: {}) ⇒ Object



21
22
23
# File 'lib/vkit/cli/api/client.rb', line 21

def get(path, params: {})
  request(method: :get, path: path, body: params.empty? ? nil : params)
end

#patch(path, body:) ⇒ Object



33
34
35
# File 'lib/vkit/cli/api/client.rb', line 33

def patch(path, body:)
  request(method: :patch, path: path, body: body)
end

#post(path, body:) ⇒ Object



25
26
27
# File 'lib/vkit/cli/api/client.rb', line 25

def post(path, body:)
  request(method: :post, path: path, body: body)
end

#put(path, body:) ⇒ Object



29
30
31
# File 'lib/vkit/cli/api/client.rb', line 29

def put(path, body:)
  request(method: :put, path: path, body: body)
end