mirror of
https://github.com/usetrmnl/trmnl-api.git
synced 2026-04-29 13:35:13 -07:00
Refactored requester to inject dependencies
Reduces duplication by injecting what is already registered. Milestone: patch
This commit is contained in:
@@ -8,14 +8,13 @@ module TRMNL
|
||||
# Provides a low level configurable and monadic API client.
|
||||
# :reek:DataClump
|
||||
class Requester
|
||||
include Dependencies[:settings, :http]
|
||||
include Dry::Monads[:result]
|
||||
|
||||
HEADERS = {}.freeze
|
||||
|
||||
def initialize settings: TRMNL::API::Configuration::Loader.new.call, http: HTTP
|
||||
@settings = settings
|
||||
@http = http
|
||||
|
||||
def initialize(**)
|
||||
super
|
||||
yield settings if block_given?
|
||||
end
|
||||
|
||||
|
||||
@@ -7,7 +7,11 @@ RSpec.describe TRMNL::API::Requester do
|
||||
|
||||
subject(:requester) { described_class.new http: }
|
||||
|
||||
include_context "with application dependencies"
|
||||
|
||||
describe "#initialize" do
|
||||
let(:http) { HTTP }
|
||||
|
||||
it "initializes with block" do
|
||||
requester = described_class.new { |settings| settings.content_type = "application/xml" }
|
||||
body = requester.get("bogus").failure.to_s
|
||||
|
||||
Reference in New Issue
Block a user