Class: Artemis::Adapters::AbstractAdapter

Inherits:
GraphQL::Client::HTTP
  • Object
show all
Defined in:
lib/artemis/adapters/abstract_adapter.rb

Direct Known Subclasses

CurbAdapter, MultiDomainAdapter, NetHttpAdapter

Constant Summary collapse

EMPTY_HEADERS =
{}.freeze
DEFAULT_HEADERS =
{
  "Accept" => "application/json",
  "Content-Type" => "application/json"
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri, service_name:, timeout:, pool_size:, adapter_options: {}) ⇒ AbstractAdapter

Returns a new instance of AbstractAdapter.

Raises:

  • (ArgumentError)


18
19
20
21
22
23
24
25
26
# File 'lib/artemis/adapters/abstract_adapter.rb', line 18

def initialize(uri, service_name: , timeout: , pool_size: , adapter_options: {})
  raise ArgumentError, "url is required (given `#{uri.inspect}')" if uri.blank?

  super(uri) # Do not pass in the block to avoid getting #headers and #connection overridden.

  @service_name = service_name.to_s
  @timeout      = timeout
  @pool_size    = pool_size
end

Instance Attribute Details

#pool_sizeObject (readonly)

Returns the value of attribute pool_size.



9
10
11
# File 'lib/artemis/adapters/abstract_adapter.rb', line 9

def pool_size
  @pool_size
end

#service_nameObject (readonly)

Returns the value of attribute service_name.



9
10
11
# File 'lib/artemis/adapters/abstract_adapter.rb', line 9

def service_name
  @service_name
end

#timeoutObject (readonly)

Returns the value of attribute timeout.



9
10
11
# File 'lib/artemis/adapters/abstract_adapter.rb', line 9

def timeout
  @timeout
end

Instance Method Details

#connectionObject

Public: Extension point for subclasses to customize the Net:HTTP client

A subclass that inherits from AbstractAdapter should returns a Net::HTTP object or an object that responds to request that is given a Net::HTTP request object.



49
50
51
# File 'lib/artemis/adapters/abstract_adapter.rb', line 49

def connection
  raise "AbstractAdapter is an abstract class that can not be instantiated!"
end

#executeObject

Public: Make an HTTP request for GraphQL query.

A subclass that inherits from AbstractAdapter can override this method if it needs more flexibility for how it makes a request.

For more details, see GraphQL::Client::HTTP#execute.



41
42
43
# File 'lib/artemis/adapters/abstract_adapter.rb', line 41

def execute(*)
  super
end

#headers(_context) ⇒ Object

Public: Extension point for subclasses to set custom request headers.

Returns Hash of String header names and values.



31
32
33
# File 'lib/artemis/adapters/abstract_adapter.rb', line 31

def headers(_context)
  _context[:headers] || EMPTY_HEADERS
end