Class: Atum::Core::Link

Inherits:
Object
  • Object
show all
Defined in:
lib/atum/core/link.rb

Overview

A link invokes requests with an HTTP server.

Constant Summary collapse

LIMIT_INCREMENT =

The amount limit is increased on each successive fetch in pagination

50

Instance Method Summary collapse

Constructor Details

#initialize(url, link_schema, options = {}) ⇒ Link

Instantiate a link.

Parameters:

  • url (String)

    The URL to use when making requests. Include the username and password to use with HTTP basic auth.

  • link_schema (LinkSchema)

    The schema for this link.

  • options (Hash) (defaults to: {})

    Configuration for the link. Possible keys include:

    • default_headers: Optionally, a set of headers to include in every request made by the client. Default is no custom headers.



21
22
23
24
25
26
# File 'lib/atum/core/link.rb', line 21

def initialize(url, link_schema, options = {})
  root_url, @path_prefix = unpack_url(url)
  @connection = Faraday.new(url: root_url)
  @link_schema = link_schema
  @headers = options[:default_headers] || {}
end

Instance Method Details

#run(*parameters) ⇒ String, ...

Make a request to the server.

Parameters:

  • parameters (Array)

    The list of parameters to inject into the path. A request body can be passed as the final parameter and will always be converted to JSON before being transmitted.

Returns:

  • (String, Object, Enumerator)

    A string for text responses, an object for JSON responses, or an enumerator for list responses.

Raises:

  • (ArgumentError)

    Raised if either too many or too few parameters were provided.



37
38
39
40
41
42
43
44
# File 'lib/atum/core/link.rb', line 37

def run(*parameters)
  options = parameters.pop
  raise ArgumentError, 'options must be a hash' unless options.is_a?(Hash)

  options = default_options.deep_merge(options)
  path = build_path(*parameters)
  Request.new(@connection, @link_schema.method, path, options).request
end