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
This commit is contained in:
Brooke Kuhlmann
2026-03-18 12:02:19 -06:00
parent 859d8728ea
commit aeb68b32b3
3 changed files with 17 additions and 5 deletions
+6 -2
View File
@@ -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
+2 -2
View File
@@ -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"
+9 -1
View File
@@ -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