From aeb68b32b3dc775576260fcd86819b951aebbd08 Mon Sep 17 00:00:00 2001 From: Brooke Kuhlmann Date: Wed, 18 Mar 2026 11:21:42 -0600 Subject: [PATCH] Fixed palette model to use name and label attributes Use of `id` (a.k.a. name) and `name` (a.k.a. label) was confusing and not an accurate representation of what these attributes are. This corrects the API design mistakes by having the model transform these keys appropriately. Milestone: minor --- lib/trmnl/api/models/palette.rb | 8 ++++++-- spec/lib/trmnl/api/endpoints/palette_spec.rb | 4 ++-- spec/lib/trmnl/api/models/palette_spec.rb | 10 +++++++++- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/lib/trmnl/api/models/palette.rb b/lib/trmnl/api/models/palette.rb index bd53e2f..eb8969a 100644 --- a/lib/trmnl/api/models/palette.rb +++ b/lib/trmnl/api/models/palette.rb @@ -1,11 +1,15 @@ # frozen_string_literal: true +require "refinements/hash" + module TRMNL module API module Models # Models the data of the API response. - Palette = Struct.new :id, :name, :grays, :colors, :framework_class do - def self.for(attributes) = new(**attributes) + Palette = Struct.new :name, :label, :grays, :colors, :framework_class do + using Refinements::Hash + + def self.for(attributes) = new(**attributes.transform_keys(name: :label, id: :name)) end end end diff --git a/spec/lib/trmnl/api/endpoints/palette_spec.rb b/spec/lib/trmnl/api/endpoints/palette_spec.rb index 2a4c1b2..85aaa6c 100644 --- a/spec/lib/trmnl/api/endpoints/palette_spec.rb +++ b/spec/lib/trmnl/api/endpoints/palette_spec.rb @@ -39,8 +39,8 @@ RSpec.describe TRMNL::API::Endpoints::Palette do expect(result).to be_success( [ TRMNL::API::Models::Palette[ - id: "test", - name: "Test", + name: "test", + label: "Test", grays: 2, colors: %w[#000000 #FFFFFF], framework_class: "screen--1bit" diff --git a/spec/lib/trmnl/api/models/palette_spec.rb b/spec/lib/trmnl/api/models/palette_spec.rb index bd2b6b0..b56daa7 100644 --- a/spec/lib/trmnl/api/models/palette_spec.rb +++ b/spec/lib/trmnl/api/models/palette_spec.rb @@ -13,7 +13,15 @@ RSpec.describe TRMNL::API::Models::Palette do framework_class: "screen--1bit" } - expect(described_class.for(attributes)).to eq(described_class[**attributes]) + expect(described_class.for(attributes)).to eq( + described_class[ + name: "test", + label: "Test", + grays: 2, + colors: %w[#000000 #FFFFFF], + framework_class: "screen--1bit" + ] + ) end end end