Class: Apipony::Endpoint

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

Overview

Model a response endpoint.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(method, url, &block) ⇒ Endpoint

Returns a new instance of Endpoint.



19
20
21
22
23
24
# File 'lib/apipony/endpoint.rb', line 19

def initialize(method, url, &block)
  @method = method
  @url = set_base_url(url)

  instance_eval(&block) if block_given?
end

Instance Attribute Details

#descriptionObject

A short description of what this endpoint does and why it may be useful.



13
14
15
# File 'lib/apipony/endpoint.rb', line 13

def description
  @description
end

#methodObject

What HTTP verb to use to access this endpoint



6
7
8
# File 'lib/apipony/endpoint.rb', line 6

def method
  @method
end

#requestObject

:nodoc:



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

def request
  @request
end

#responseObject

:nodoc:



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

def response
  @response
end

#urlObject

The URl of this endpoint



9
10
11
# File 'lib/apipony/endpoint.rb', line 9

def url
  @url
end

Instance Method Details

#idObject

Create a unique identifier for this endpoint



40
41
42
# File 'lib/apipony/endpoint.rb', line 40

def id
  File.join(@method.to_s, @url)
end

#request_with(&block) ⇒ Object

DSL method to start describind a request



34
35
36
# File 'lib/apipony/endpoint.rb', line 34

def request_with(&block)
  @request = Apipony::Request.new(&block)
end

#response_with(status, **params, &block) ⇒ Object

DSL method to start describing a response



28
29
30
# File 'lib/apipony/endpoint.rb', line 28

def response_with(status, **params, &block)
  @response = Apipony::Response.new(status, **params, &block)
end