Class: Sliver::API

Inherits:
Object
  • Object
show all
Defined in:
lib/sliver/api.rb

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ API

Returns a new instance of API.



4
5
6
7
8
# File 'lib/sliver/api.rb', line 4

def initialize(&block)
  @endpoints = Sliver::Endpoints.new

  block.call self
end

Instance Method Details

#call(environment) ⇒ Object



10
11
12
13
14
# File 'lib/sliver/api.rb', line 10

def call(environment)
  endpoint = endpoints.find environment

  endpoint.nil? ? not_found : invoke(endpoint, environment)
end

#connect(method, path, action) ⇒ Object



20
21
22
# File 'lib/sliver/api.rb', line 20

def connect(method, path, action)
  endpoints.append Sliver::Path.new(method, path), action
end

#invoke(endpoint, environment) ⇒ Object



16
17
18
# File 'lib/sliver/api.rb', line 16

def invoke(endpoint, environment)
  endpoint.call environment
end