From c200ae5491667bb617255867813ff56af537d8c9 Mon Sep 17 00:00:00 2001 From: Brooke Kuhlmann Date: Thu, 11 Dec 2025 13:59:02 -0700 Subject: [PATCH] Added palette model Necessary to build a record out of the API response. Milestone: minor --- lib/trmnl/api/container.rb | 1 + lib/trmnl/api/models/palette.rb | 12 ++++++++++++ spec/lib/trmnl/api/models/palette_spec.rb | 19 +++++++++++++++++++ 3 files changed, 32 insertions(+) create mode 100644 lib/trmnl/api/models/palette.rb create mode 100644 spec/lib/trmnl/api/models/palette_spec.rb diff --git a/lib/trmnl/api/container.rb b/lib/trmnl/api/container.rb index 3d13410..6c53c16 100644 --- a/lib/trmnl/api/container.rb +++ b/lib/trmnl/api/container.rb @@ -36,6 +36,7 @@ module TRMNL register :firmware, Models::Firmware register :ip_address, Models::IPAddress register :model, Models::Model + register :palette, Models::Palette register :setup, Models::Setup end end diff --git a/lib/trmnl/api/models/palette.rb b/lib/trmnl/api/models/palette.rb new file mode 100644 index 0000000..7a1e7a0 --- /dev/null +++ b/lib/trmnl/api/models/palette.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +module TRMNL + module API + module Models + # IPs API response. + Palette = Data.define :id, :name, :grays, :colors, :framework_class do + def self.for(attributes) = new(**attributes) + end + end + end +end diff --git a/spec/lib/trmnl/api/models/palette_spec.rb b/spec/lib/trmnl/api/models/palette_spec.rb new file mode 100644 index 0000000..bd2b6b0 --- /dev/null +++ b/spec/lib/trmnl/api/models/palette_spec.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +require "spec_helper" + +RSpec.describe TRMNL::API::Models::Palette do + describe ".for" do + it "answers record for attributes" do + attributes = { + id: "test", + name: "Test", + grays: 2, + colors: %w[#000000 #FFFFFF], + framework_class: "screen--1bit" + } + + expect(described_class.for(attributes)).to eq(described_class[**attributes]) + end + end +end