mirror of
https://github.com/usetrmnl/trmnl-api.git
synced 2026-04-29 13:35:13 -07:00
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:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user