From bbd82f4d3ca4c22c1e594f51ffbf18cc4a1e916c Mon Sep 17 00:00:00 2001 From: Brooke Kuhlmann Date: Mon, 21 Apr 2025 19:57:20 -0600 Subject: [PATCH] Added configuration content Necessary to configure the client. --- lib/trmnl/api/configuration/content.rb | 12 +++++++++++ .../trmnl/api/configuration/content_spec.rb | 20 +++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 lib/trmnl/api/configuration/content.rb create mode 100644 spec/lib/trmnl/api/configuration/content_spec.rb diff --git a/lib/trmnl/api/configuration/content.rb b/lib/trmnl/api/configuration/content.rb new file mode 100644 index 0000000..de030b6 --- /dev/null +++ b/lib/trmnl/api/configuration/content.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +module TRMNL + module API + module Configuration + # Provides API client configuration content. + Content = Struct.new :content_type, :uri do + def headers = {"Content-Type" => content_type}.compact + end + end + end +end diff --git a/spec/lib/trmnl/api/configuration/content_spec.rb b/spec/lib/trmnl/api/configuration/content_spec.rb new file mode 100644 index 0000000..b3e31f8 --- /dev/null +++ b/spec/lib/trmnl/api/configuration/content_spec.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +require "spec_helper" + +RSpec.describe TRMNL::API::Configuration::Content do + subject :content do + described_class[uri: "https://trmnl.app/api", content_type: "application/json"] + end + + describe "#headers" do + it "answers HTTP headers when defined" do + expect(content.headers).to eq("Content-Type" => "application/json") + end + + it "answers empty hash when none are available" do + content.content_type = nil + expect(content.headers).to eq({}) + end + end +end