Class: Artemis::Adapters::AbstractAdapter
- Inherits:
-
GraphQL::Client::HTTP
- Object
- GraphQL::Client::HTTP
- Artemis::Adapters::AbstractAdapter
- Defined in:
- lib/artemis/adapters/abstract_adapter.rb
Direct Known Subclasses
Constant Summary collapse
- EMPTY_HEADERS =
{}.freeze
- DEFAULT_HEADERS =
{ "Accept" => "application/json", "Content-Type" => "application/json" }.freeze
Instance Attribute Summary collapse
-
#pool_size ⇒ Object
readonly
Returns the value of attribute pool_size.
-
#service_name ⇒ Object
readonly
Returns the value of attribute service_name.
-
#timeout ⇒ Object
readonly
Returns the value of attribute timeout.
Instance Method Summary collapse
-
#connection ⇒ Object
Public: Extension point for subclasses to customize the Net:HTTP client.
-
#execute ⇒ Object
Public: Make an HTTP request for GraphQL query.
-
#headers(_context) ⇒ Object
Public: Extension point for subclasses to set custom request headers.
-
#initialize(uri, service_name:, timeout:, pool_size:, adapter_options: {}) ⇒ AbstractAdapter
constructor
A new instance of AbstractAdapter.
Constructor Details
#initialize(uri, service_name:, timeout:, pool_size:, adapter_options: {}) ⇒ AbstractAdapter
Returns a new instance of AbstractAdapter.
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_size ⇒ Object (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_name ⇒ Object (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 |
#timeout ⇒ Object (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
#connection ⇒ Object
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 |
#execute ⇒ Object
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 |