Class: FulfilApi::Client
- Inherits:
-
Object
- Object
- FulfilApi::Client
- Defined in:
- lib/fulfil_api/client.rb
Class Method Summary collapse
-
.connection_for(cache_key) ⇒ Faraday::Connection
Looks up a memoized Faraday::Connection for the given cache key, or builds and stores one by yielding the block.
-
.reset_connection_cache! ⇒ void
Clears the memoized connection cache.
Instance Method Summary collapse
-
#delete(relative_path) ⇒ Array, ...
Performs an HTTP DELETE request to a Fulfil API endpoint.
-
#get(relative_path, url_parameters: nil) ⇒ Array, ...
Performs an HTTP GET request to a Fulfil API endpoint.
-
#initialize(configuration) ⇒ Client
constructor
A new instance of Client.
-
#post(relative_path, body: {}) ⇒ Array, ...
Performs an HTTP POST request to a Fulfil API endpoint.
-
#put(relative_path, body: nil) ⇒ Array, ...
Performs an HTTP PUT request to a Fulfil API endpoint.
Constructor Details
#initialize(configuration) ⇒ Client
Returns a new instance of Client.
39 40 41 |
# File 'lib/fulfil_api/client.rb', line 39 def initialize(configuration) @configuration = configuration end |
Class Method Details
.connection_for(cache_key) ⇒ Faraday::Connection
Looks up a memoized Faraday::Connection for the given cache key, or
builds and stores one by yielding the block.
The cache is process-wide, so the underlying ‘net_http_persistent` adapter
can actually reuse its TCP/TLS connection pool across requests. Without
this, each `FulfilApi.client` call would instantiate a fresh Faraday
connection, defeating the purpose of the persistent adapter.
23 24 25 26 27 |
# File 'lib/fulfil_api/client.rb', line 23 def connection_for(cache_key) @connection_cache_mutex.synchronize do @connection_cache[cache_key] ||= yield end end |
.reset_connection_cache! ⇒ void
This method returns an undefined value.
Clears the memoized connection cache. Intended for use in test suites
that need to isolate connection state between tests.
33 34 35 |
# File 'lib/fulfil_api/client.rb', line 33 def reset_connection_cache! @connection_cache_mutex.synchronize { @connection_cache.clear } end |
Instance Method Details
#delete(relative_path) ⇒ Array, ...
Performs an HTTP DELETE request to a Fulfil API endpoint.
47 48 49 |
# File 'lib/fulfil_api/client.rb', line 47 def delete(relative_path) request(:delete, relative_path) end |
#get(relative_path, url_parameters: nil) ⇒ Array, ...
Performs an HTTP GET request to a Fulfil API endpoint.
56 57 58 |
# File 'lib/fulfil_api/client.rb', line 56 def get(relative_path, url_parameters: nil) request(:get, relative_path, url_parameters) end |
#post(relative_path, body: {}) ⇒ Array, ...
Performs an HTTP POST request to a Fulfil API endpoint.
65 66 67 |
# File 'lib/fulfil_api/client.rb', line 65 def post(relative_path, body: {}) request(:post, relative_path, body) end |
#put(relative_path, body: nil) ⇒ Array, ...
Performs an HTTP PUT request to a Fulfil API endpoint.
74 75 76 77 78 |
# File 'lib/fulfil_api/client.rb', line 74 def put(relative_path, body: nil) return request(:put, relative_path) if body.nil? request(:put, relative_path, body) end |