Class: StubRequests::Endpoint

Inherits:
Object
  • Object
show all
Includes:
Comparable, ArgumentValidation
Defined in:
lib/stub_requests/endpoint.rb

Overview

Class Endpoint provides registration of stubbed endpoints

Since:

  • 0.1.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ArgumentValidation

#validate!

Constructor Details

#initialize(endpoint_id, verb, uri_template, default_options = {}) ⇒ Endpoint

An endpoint for a specific Service

Parameters:

  • endpoint_id (Symbol)

    a descriptive id for the endpoint

  • verb (Symbol)

    a HTTP verb

  • uri_template (String)

    how to reach the endpoint

  • default_options (optional, Hash<Symbol>) (defaults to: {})

Options Hash (default_options):

  • :request (optional, Hash<Symbol>)

    for request_stub.with

  • :response (optional, Hash<Symbol>)

    for request_stub.to_return

  • :error (optional, Array, Exception, StandardError, String)

    for request_stub.to_raise

  • :timeout (optional, TrueClass)

    for request_stub.to_timeout

Since:

  • 0.1.0



50
51
52
53
54
55
56
57
58
59
# File 'lib/stub_requests/endpoint.rb', line 50

def initialize(endpoint_id, verb, uri_template, default_options = {})
  validate! endpoint_id,  is_a: Symbol
  validate! verb,         is_a: Symbol
  validate! uri_template, is_a: String

  @id              = endpoint_id
  @verb            = verb
  @uri_template    = uri_template
  @default_options = default_options
end

Instance Attribute Details

#default_optionsObject

Since:

  • 0.1.0



36
37
38
# File 'lib/stub_requests/endpoint.rb', line 36

def default_options
  @default_options
end

#idObject

Since:

  • 0.1.0



20
21
22
# File 'lib/stub_requests/endpoint.rb', line 20

def id
  @id
end

#uri_templateObject

Since:

  • 0.1.0



30
31
32
# File 'lib/stub_requests/endpoint.rb', line 30

def uri_template
  @uri_template
end

#verbObject

Since:

  • 0.1.0



25
26
27
# File 'lib/stub_requests/endpoint.rb', line 25

def verb
  @verb
end

Instance Method Details

#<=>(other) ⇒ Object

Since:

  • 0.1.0



81
82
83
# File 'lib/stub_requests/endpoint.rb', line 81

def <=>(other)
  id <=> other.id
end

#hashObject

Since:

  • 0.1.0



85
86
87
# File 'lib/stub_requests/endpoint.rb', line 85

def hash
  [id, self.class].hash
end

#to_sString

Returns a descriptive string of this endpoint

Returns:

Since:

  • 0.1.0



96
97
98
# File 'lib/stub_requests/endpoint.rb', line 96

def to_s
  "#<#{self.class} id=:#{id} verb=:#{verb} uri_template='#{uri_template}'>"
end

#update(verb, uri_template, default_options) ⇒ Endpoint

Updates this endpoint

Parameters:

  • verb (Symbol)

    a HTTP verb

  • uri_template (String)

    how to reach the endpoint

  • default_options (optional, Hash<Symbol>)

Options Hash (default_options):

  • :request (optional, Hash<Symbol>)

    for request_stub.with

  • :response (optional, Hash<Symbol>)

    for request_stub.to_return

  • :error (optional, Array, Exception, StandardError, String)

    for request_stub.to_raise

  • :timeout (optional, TrueClass)

    for request_stub.to_timeout

Returns:

  • (Endpoint)

    returns the updated endpoint

Since:

  • 0.1.0



74
75
76
77
78
79
# File 'lib/stub_requests/endpoint.rb', line 74

def update(verb, uri_template, default_options)
  @verb            = verb
  @uri_template    = uri_template
  @default_options = default_options
  self
end