Added IP address model

Necessary to model the response.

RuboCop is updated to ignore the variable name issues since this stems from the API design. The model translates the keys to prevent this design flaw from permeating further downstream at least.

Milestone: minor
This commit is contained in:
Brooke Kuhlmann
2025-12-11 14:53:55 -07:00
parent ae74630996
commit f54458f18f
4 changed files with 36 additions and 0 deletions
+3
View File
@@ -7,6 +7,9 @@ Metrics/ParameterLists:
Naming/VariableNumber:
Exclude:
- lib/trmnl/api/contracts/ip_address.rb
- lib/trmnl/api/models/ip_address.rb
- spec/lib/trmnl/api/models/ip_address_spec.rb
Style/IpAddresses:
Exclude:
- spec/lib/trmnl/api/types_spec.rb
- spec/lib/trmnl/api/models/ip_address_spec.rb
+1
View File
@@ -33,6 +33,7 @@ module TRMNL
register :current_screen, Models::CurrentScreen
register :display, Models::Display
register :firmware, Models::Firmware
register :ip_address, Models::IPAddress
register :model, Models::Model
register :setup, Models::Setup
end
+14
View File
@@ -0,0 +1,14 @@
# frozen_string_literal: true
module TRMNL
module API
module Models
# IPs API response.
IPAddress = Data.define :version_4, :version_6 do
def self.for attributes
new(**attributes.transform_keys(ipv4: :version_4, ipv6: :version_6))
end
end
end
end
end
@@ -0,0 +1,18 @@
# frozen_string_literal: true
require "spec_helper"
RSpec.describe TRMNL::API::Models::IPAddress do
describe ".for" do
it "answers record for attributes" do
attributes = {ipv4: ["192.168.1.10"], ipv6: ["1a00:100:100:1000::1"]}
expect(described_class.for(attributes)).to eq(
described_class[
version_4: ["192.168.1.10"],
version_6: ["1a00:100:100:1000::1"]
]
)
end
end
end