mirror of
https://github.com/usetrmnl/trmnl-api.git
synced 2026-04-29 13:35:13 -07:00
Fixed model palette IDs as names
These are not IDs but names so this corrects the mistake that the API makes including providing a safe default (i.e. empty array) when the names are missing. Milestone: minor
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "refinements/hash"
|
||||
|
||||
module TRMNL
|
||||
module API
|
||||
module Models
|
||||
@@ -18,10 +20,10 @@ module TRMNL
|
||||
:height,
|
||||
:offset_x,
|
||||
:offset_y,
|
||||
:palette_ids,
|
||||
:palette_names,
|
||||
:css
|
||||
) do
|
||||
def self.for(attributes) = new(**attributes)
|
||||
def self.for(attributes) = new(**attributes.transform_keys(palette_ids: :palette_names))
|
||||
|
||||
def initialize(**)
|
||||
super
|
||||
@@ -34,6 +36,8 @@ module TRMNL
|
||||
private
|
||||
|
||||
def apply_defaults
|
||||
self[:palette_names] ||= []
|
||||
|
||||
%i[colors bit_depth scale_factor rotation width height offset_x offset_y].each do |name|
|
||||
self[name] ||= 0
|
||||
end
|
||||
|
||||
@@ -71,7 +71,7 @@ RSpec.describe TRMNL::API::Endpoints::Model do
|
||||
height: 480,
|
||||
offset_x: 10,
|
||||
offset_y: 15,
|
||||
palette_ids: %w[bw grey-4],
|
||||
palette_names: %w[bw grey-4],
|
||||
css: {
|
||||
classes: {
|
||||
device: "screen--v2",
|
||||
|
||||
@@ -36,7 +36,34 @@ RSpec.describe TRMNL::API::Models::Model do
|
||||
end
|
||||
|
||||
it "answers record for attributes" do
|
||||
expect(described_class.for(attributes)).to eq(described_class[**attributes])
|
||||
expect(described_class.for(attributes)).to eq(
|
||||
described_class[
|
||||
name: "test",
|
||||
label: "Test",
|
||||
description: "A test.",
|
||||
kind: "trmnl",
|
||||
colors: 2,
|
||||
bit_depth: 1,
|
||||
scale_factor: 1,
|
||||
rotation: 90,
|
||||
mime_type: "image/png",
|
||||
width: 800,
|
||||
height: 480,
|
||||
offset_x: 10,
|
||||
offset_y: 15,
|
||||
palette_names: %w[bw grey-4],
|
||||
css: {
|
||||
classes: {
|
||||
device: "screen--v2",
|
||||
size: "screen--lg"
|
||||
},
|
||||
variables: [
|
||||
%w[--screen-w 1040px],
|
||||
%w[--screen-h 780px]
|
||||
]
|
||||
}
|
||||
]
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -56,7 +83,7 @@ RSpec.describe TRMNL::API::Models::Model do
|
||||
height: 0,
|
||||
offset_x: 0,
|
||||
offset_y: 0,
|
||||
palette_ids: nil,
|
||||
palette_names: [],
|
||||
css: nil
|
||||
)
|
||||
end
|
||||
@@ -84,7 +111,7 @@ RSpec.describe TRMNL::API::Models::Model do
|
||||
height: 0,
|
||||
offset_x: 0,
|
||||
offset_y: 0,
|
||||
palette_ids: nil,
|
||||
palette_names: [],
|
||||
css: nil
|
||||
)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user