Class: Inferno::DSL::HTTPClientBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/inferno/dsl/http_client_builder.rb

Overview

This module contains the HTTP DSL available to test writers.

Instance Attribute Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name) ⇒ Object



47
48
49
50
51
# File 'lib/inferno/dsl/http_client_builder.rb', line 47

def method_missing(name, ...)
  return runnable.send(name, ...) if runnable.respond_to? name

  super
end

Instance Attribute Details

#runnableObject

Returns the value of attribute runnable.



7
8
9
# File 'lib/inferno/dsl/http_client_builder.rb', line 7

def runnable
  @runnable
end

Instance Method Details

#build(runnable, block) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/inferno/dsl/http_client_builder.rb', line 10

def build(runnable, block)
  self.runnable = runnable
  instance_exec(self, &block)

  params = { url: }
  params.merge!(headers:) if headers

  Faraday.new(params) do |f|
    f.request :url_encoded
    f.use FaradayMiddleware::FollowRedirects
  end
end

#headers(headers = nil) ⇒ void

This method returns an undefined value.

Define custom headers for a client

Parameters:

  • headers (Hash) (defaults to: nil)


42
43
44
# File 'lib/inferno/dsl/http_client_builder.rb', line 42

def headers(headers = nil)
  @headers ||= headers
end

#respond_to_missing?(name) ⇒ Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/inferno/dsl/http_client_builder.rb', line 54

def respond_to_missing?(name)
  runnable.respond_to?(name) || super
end

#url(url = nil) ⇒ void

This method returns an undefined value.

Define the base url for an HTTP client. A string or symbol can be provided. A string is interpreted as a url. A symbol is interpreted as the name of an input to the Runnable.

Parameters:

  • url (String, Symbol) (defaults to: nil)


29
30
31
32
33
34
35
36
# File 'lib/inferno/dsl/http_client_builder.rb', line 29

def url(url = nil)
  @url ||=
    if url.is_a? Symbol
      runnable.send(url)
    else
      url
    end
end