Class: LazyAnt::Endpoint

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

Overview

Endpoint Definition

(in dsl) api :echo do

get '/echo'
param :hello, default: 'world', required: true, rename: 'SHIT_KEY'

end

client.echo(hello: ‘test’)

> GET ‘/echo?SHIT_KEY=test’

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Endpoint

Returns a new instance of Endpoint.



17
18
19
20
# File 'lib/lazy_ant/endpoint.rb', line 17

def initialize(*args)
  @query = default_query.merge(args.extract_options!)
  @url = build_url(*args)
end

Class Method Details

.inherited(child) ⇒ Object



84
85
86
# File 'lib/lazy_ant/endpoint.rb', line 84

def inherited(child)
  child.params = {}
end

.param(name, options = {}) ⇒ Object



80
81
82
# File 'lib/lazy_ant/endpoint.rb', line 80

def param(name, options = {})
  params[name] = options
end

Instance Method Details

#execute(connection) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/lazy_ant/endpoint.rb', line 22

def execute(connection)
  @query = connection.params.merge(@query)
  validate!
  connection.send(verb, @url, renamed_query) do |req|
    req.params.clear if [:put, :post].include?(req.method)
  end
end