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.



25
26
27
28
29
30
31
32
33
# File 'lib/atum/core/link.rb', line 25

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

Instance Method Details

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

Make a request to the server.

Raises:

  • (ArgumentError)

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



44
45
46
47
48
49
50
51
# File 'lib/atum/core/link.rb', line 44

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