Class: VtApi::Endpoint

Inherits:
Object
  • Object
show all
Defined in:
lib/vt_api/internal/endpoint.rb

Overview

API endpoint interface class.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri, method, params = {}) ⇒ Endpoint

Initialize new endpoint.

Interface parameters are described as in example below.

Examples:

{
    foo: true, # this describes required parameter
    bar: false # this describes a parameter that can be omitted
}

Parameters:

  • uri (Object)

    Relative URL of the endpoint.

  • method (Object)

    HTTP method to be used for the endpoint.

  • params (Object) (defaults to: {})

    Endpoint parameters interface.



22
23
24
25
26
# File 'lib/vt_api/internal/endpoint.rb', line 22

def initialize(uri, method, params = {})
	@uri    = uri
	@method = method
	@params = params
end

Instance Attribute Details

#methodObject

Returns the value of attribute method.



8
9
10
# File 'lib/vt_api/internal/endpoint.rb', line 8

def method
  @method
end

#uriObject

Returns the value of attribute uri.



8
9
10
# File 'lib/vt_api/internal/endpoint.rb', line 8

def uri
  @uri
end

Instance Method Details

#missing_params(passed_params) ⇒ Array

Get a list of missing parameters.

Parameters:

  • passed_params (Hash)

Returns:

  • (Array)


44
45
46
47
48
49
50
51
52
# File 'lib/vt_api/internal/endpoint.rb', line 44

def missing_params(passed_params)
	missing = []

	@params.each do |param, required|
		missing << param if required && passed_params[param].nil?
	end

	missing
end

#params_valid?(passed_params) ⇒ Boolean

Check whether given parameters match endpoint interface.

Parameters:

  • passed_params (Hash)

Returns:

  • (Boolean)


32
33
34
35
36
37
38
# File 'lib/vt_api/internal/endpoint.rb', line 32

def params_valid?(passed_params)
	@params.each do |param, required|
		return false if required && passed_params[param].nil?
	end

	true
end