trmnl-api 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/README.adoc +30 -0
- data/lib/trmnl/api/client.rb +4 -0
- data/lib/trmnl/api/container.rb +2 -0
- data/lib/trmnl/api/contracts/model.rb +28 -0
- data/lib/trmnl/api/endpoints/container.rb +1 -0
- data/lib/trmnl/api/endpoints/model.rb +32 -0
- data/lib/trmnl/api/models/model.rb +67 -0
- data/lib/trmnl/api.rb +1 -1
- data/trmnl-api.gemspec +2 -2
- data.tar.gz.sig +0 -0
- metadata +6 -3
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 278f09b420c7a49d0f325e0a1128c5fd5d9a133958a9131c00e18a0c80aca017
|
4
|
+
data.tar.gz: 6730afa2771d004abb699dff8877f27c60e4b0f79e0faf962c43569aa9a7338c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 12a21186fb3b4601fb4fd4d0032df1cc54b4f84682a95c84f4d704e62abfada39306f1ff2b723d17c04fc2fc6bda2917dde7ad9a511676cfa3619e118a011dcd
|
7
|
+
data.tar.gz: 578927511c6a842a0fc2941e2e658acf27b6a7926cef1974b29a3b1c6f062e39d18da5e793cdad886658566e410a0b3bb51379c538bc6a890b350d2cc2e359ee
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/README.adoc
CHANGED
@@ -174,6 +174,36 @@ client.log token: "secret",
|
|
174
174
|
|
175
175
|
You'll either get a 204 No Content or 200 OK response depending on if the device exists or not.
|
176
176
|
|
177
|
+
==== Models
|
178
|
+
|
179
|
+
Allows you to obtain the model information for all devices and screens. Example:
|
180
|
+
|
181
|
+
[source,ruby]
|
182
|
+
----
|
183
|
+
client = TRMNL::API::Client.new
|
184
|
+
client.models
|
185
|
+
|
186
|
+
# Success(
|
187
|
+
# #<data TRMNL::API::Models::Model
|
188
|
+
# name="test",
|
189
|
+
# label="Test",
|
190
|
+
# description="A test.",
|
191
|
+
# colors=2,
|
192
|
+
# bit_depth=1,
|
193
|
+
# scale_factor=1,
|
194
|
+
# rotation=90,
|
195
|
+
# mime_type="image/png",
|
196
|
+
# width=800,
|
197
|
+
# height=480,
|
198
|
+
# offset_x=10,
|
199
|
+
# offset_y=15,
|
200
|
+
# published_at="2025-07-16T18:18:11+00:00"
|
201
|
+
# >
|
202
|
+
# )
|
203
|
+
----
|
204
|
+
|
205
|
+
ℹ️ The `scale_factor` can be an integer or float.
|
206
|
+
|
177
207
|
==== Setup
|
178
208
|
|
179
209
|
Allows you to obtain the setup response for when a new device is setup. You must supply your device's MAC Address as the `id`. Example:
|
data/lib/trmnl/api/client.rb
CHANGED
@@ -13,6 +13,7 @@ module TRMNL
|
|
13
13
|
endpoint_display: :display,
|
14
14
|
endpoint_firmware: :firmware,
|
15
15
|
endpoint_log: :log,
|
16
|
+
endpoint_models: :models,
|
16
17
|
endpoint_setup: :setup
|
17
18
|
]
|
18
19
|
|
@@ -21,6 +22,7 @@ module TRMNL
|
|
21
22
|
endpoint_display: :class,
|
22
23
|
endpoint_firmware: :class,
|
23
24
|
endpoint_log: :class,
|
25
|
+
endpoint_models: :class,
|
24
26
|
endpoint_setup: :class
|
25
27
|
]
|
26
28
|
|
@@ -37,6 +39,8 @@ module TRMNL
|
|
37
39
|
|
38
40
|
def log(**) = endpoint_log.call(**)
|
39
41
|
|
42
|
+
def models(**) = endpoint_models.call(**)
|
43
|
+
|
40
44
|
def setup(**) = endpoint_setup.call(**)
|
41
45
|
end
|
42
46
|
end
|
data/lib/trmnl/api/container.rb
CHANGED
@@ -23,6 +23,7 @@ module TRMNL
|
|
23
23
|
register :current_screen, Contracts::CurrentScreen
|
24
24
|
register :display, Contracts::Display
|
25
25
|
register :firmware, Contracts::Firmware
|
26
|
+
register :model, Contracts::Model
|
26
27
|
register :setup, Contracts::Setup
|
27
28
|
end
|
28
29
|
|
@@ -30,6 +31,7 @@ module TRMNL
|
|
30
31
|
register :current_screen, Models::CurrentScreen
|
31
32
|
register :display, Models::Display
|
32
33
|
register :firmware, Models::Firmware
|
34
|
+
register :model, Models::Model
|
33
35
|
register :setup, Models::Setup
|
34
36
|
end
|
35
37
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "dry/schema"
|
4
|
+
|
5
|
+
module TRMNL
|
6
|
+
module API
|
7
|
+
module Contracts
|
8
|
+
# Validates API response.
|
9
|
+
Model = Dry::Schema.JSON do
|
10
|
+
required(:data).array(:hash) do
|
11
|
+
required(:name).filled :string
|
12
|
+
required(:label).filled :string
|
13
|
+
required(:description).filled :string
|
14
|
+
required(:colors).filled :integer
|
15
|
+
required(:bit_depth).filled :integer
|
16
|
+
required(:scale_factor) { filled? > int? | float? }
|
17
|
+
required(:rotation).filled :integer
|
18
|
+
required(:mime_type).filled :string
|
19
|
+
required(:width).filled :integer
|
20
|
+
required(:height).filled :integer
|
21
|
+
required(:offset_x).filled :integer
|
22
|
+
required(:offset_y).filled :integer
|
23
|
+
required(:published_at).filled :time
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "inspectable"
|
4
|
+
require "pipeable"
|
5
|
+
|
6
|
+
module TRMNL
|
7
|
+
module API
|
8
|
+
module Endpoints
|
9
|
+
# Handles API request/response.
|
10
|
+
class Model
|
11
|
+
include TRMNL::API::Dependencies[
|
12
|
+
:requester,
|
13
|
+
contract: "contracts.model",
|
14
|
+
model: "models.model"
|
15
|
+
]
|
16
|
+
|
17
|
+
include Inspectable[contract: :class]
|
18
|
+
include Pipeable
|
19
|
+
|
20
|
+
def call
|
21
|
+
pipe(
|
22
|
+
requester.get("models"),
|
23
|
+
try(:parse, catch: JSON::ParserError),
|
24
|
+
validate(contract, as: :to_h),
|
25
|
+
as(:fetch, :data),
|
26
|
+
map { |data| model.for(**data) }
|
27
|
+
)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module TRMNL
|
4
|
+
module API
|
5
|
+
module Models
|
6
|
+
# Models data for API display responses.
|
7
|
+
Model = Struct.new(
|
8
|
+
:name,
|
9
|
+
:label,
|
10
|
+
:description,
|
11
|
+
:colors,
|
12
|
+
:bit_depth,
|
13
|
+
:scale_factor,
|
14
|
+
:rotation,
|
15
|
+
:mime_type,
|
16
|
+
:width,
|
17
|
+
:height,
|
18
|
+
:offset_x,
|
19
|
+
:offset_y,
|
20
|
+
:published_at
|
21
|
+
) do
|
22
|
+
def self.for(attributes) = new(**attributes)
|
23
|
+
|
24
|
+
def initialize(**)
|
25
|
+
super
|
26
|
+
apply_defaults
|
27
|
+
freeze
|
28
|
+
end
|
29
|
+
|
30
|
+
def to_json(*) = to_h.to_json(*)
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def apply_defaults
|
35
|
+
%i[colors bit_depth scale_factor rotation width height offset_x offset_y].each do |name|
|
36
|
+
self[name] ||= 0
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
# TODO: Remove when finished.
|
45
|
+
__END__
|
46
|
+
|
47
|
+
# frozen_string_literal: true
|
48
|
+
|
49
|
+
module Kagi
|
50
|
+
module API
|
51
|
+
module Models
|
52
|
+
# Models the search payload.
|
53
|
+
Search = Data.define :meta, :data do
|
54
|
+
def self.for(**attributes)
|
55
|
+
new(
|
56
|
+
**attributes.merge!(
|
57
|
+
meta: Content::Meta.for(**attributes[:meta]),
|
58
|
+
data: attributes[:data].map { Content::Search.for(**it) }
|
59
|
+
)
|
60
|
+
)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
|
data/lib/trmnl/api.rb
CHANGED
@@ -16,7 +16,7 @@ module TRMNL
|
|
16
16
|
# Main namespace.
|
17
17
|
module API
|
18
18
|
def self.loader registry = Zeitwerk::Registry
|
19
|
-
@loader ||= registry.loaders.find { |loader| loader.tag == "trmnl-api" }
|
19
|
+
@loader ||= registry.loaders.each.find { |loader| loader.tag == "trmnl-api" }
|
20
20
|
end
|
21
21
|
|
22
22
|
def self.new(&) = Client.new(&)
|
data/trmnl-api.gemspec
CHANGED
@@ -2,9 +2,9 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |spec|
|
4
4
|
spec.name = "trmnl-api"
|
5
|
-
spec.version = "0.
|
5
|
+
spec.version = "0.3.0"
|
6
6
|
spec.authors = ["TRMNL"]
|
7
|
-
spec.email = ["
|
7
|
+
spec.email = ["engineering@usetrmnl.com"]
|
8
8
|
spec.homepage = "https://github.com/usetrmnl/trmnl-api"
|
9
9
|
spec.summary = "A monadic TRMNL API client."
|
10
10
|
spec.license = "MIT"
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: trmnl-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- TRMNL
|
@@ -162,7 +162,7 @@ dependencies:
|
|
162
162
|
- !ruby/object:Gem::Version
|
163
163
|
version: '2.7'
|
164
164
|
email:
|
165
|
-
-
|
165
|
+
- engineering@usetrmnl.com
|
166
166
|
executables: []
|
167
167
|
extensions: []
|
168
168
|
extra_rdoc_files:
|
@@ -179,6 +179,7 @@ files:
|
|
179
179
|
- lib/trmnl/api/contracts/current_screen.rb
|
180
180
|
- lib/trmnl/api/contracts/display.rb
|
181
181
|
- lib/trmnl/api/contracts/firmware.rb
|
182
|
+
- lib/trmnl/api/contracts/model.rb
|
182
183
|
- lib/trmnl/api/contracts/setup.rb
|
183
184
|
- lib/trmnl/api/dependencies.rb
|
184
185
|
- lib/trmnl/api/endpoints/container.rb
|
@@ -187,10 +188,12 @@ files:
|
|
187
188
|
- lib/trmnl/api/endpoints/display.rb
|
188
189
|
- lib/trmnl/api/endpoints/firmware.rb
|
189
190
|
- lib/trmnl/api/endpoints/log.rb
|
191
|
+
- lib/trmnl/api/endpoints/model.rb
|
190
192
|
- lib/trmnl/api/endpoints/setup.rb
|
191
193
|
- lib/trmnl/api/models/current_screen.rb
|
192
194
|
- lib/trmnl/api/models/display.rb
|
193
195
|
- lib/trmnl/api/models/firmware.rb
|
196
|
+
- lib/trmnl/api/models/model.rb
|
194
197
|
- lib/trmnl/api/models/setup.rb
|
195
198
|
- lib/trmnl/api/requester.rb
|
196
199
|
- trmnl-api.gemspec
|
@@ -218,7 +221,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
218
221
|
- !ruby/object:Gem::Version
|
219
222
|
version: '0'
|
220
223
|
requirements: []
|
221
|
-
rubygems_version: 3.
|
224
|
+
rubygems_version: 3.7.1
|
222
225
|
specification_version: 4
|
223
226
|
summary: A monadic TRMNL API client.
|
224
227
|
test_files: []
|
metadata.gz.sig
CHANGED
Binary file
|