trmnl-api 0.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f8a754ac699d2142cb950f2bc7739616181a33f085c99b244856f9115f823b6e
4
- data.tar.gz: 8a221272e414bed3c1c25a8517c91bbce9286655c51057d9487077abdad22d6c
3
+ metadata.gz: 278f09b420c7a49d0f325e0a1128c5fd5d9a133958a9131c00e18a0c80aca017
4
+ data.tar.gz: 6730afa2771d004abb699dff8877f27c60e4b0f79e0faf962c43569aa9a7338c
5
5
  SHA512:
6
- metadata.gz: fadb0d344109f6a8ae6b84f411ee7f7363c708daa823a68c5adcd875871dc41928526505241587fa3218a48ece69acc2142d787245c2ce41a28e0cb30e3d28b5
7
- data.tar.gz: 3ae4afaab60d62d8a1d8e6d776175031915cea50f237af2a025686c769a02651bc9137e2e3ffd4aa95bc24c925bc2f18b6a04161e33c1b8a683c1b7adb2467c4
6
+ metadata.gz: 12a21186fb3b4601fb4fd4d0032df1cc54b4f84682a95c84f4d704e62abfada39306f1ff2b723d17c04fc2fc6bda2917dde7ad9a511676cfa3619e118a011dcd
7
+ data.tar.gz: 578927511c6a842a0fc2941e2e658acf27b6a7926cef1974b29a3b1c6f062e39d18da5e793cdad886658566e410a0b3bb51379c538bc6a890b350d2cc2e359ee
checksums.yaml.gz.sig CHANGED
Binary file
data/README.adoc CHANGED
@@ -130,7 +130,7 @@ Allows you to obtain the current stable firmware version. Example:
130
130
  [source,ruby]
131
131
  ----
132
132
  client = TRMNL::API::Client.new
133
- client.call
133
+ client.firmware
134
134
 
135
135
  # Success(#<data TRMNL::API::Models::Firmware url="https://trmnl-fw.s3.us-east-2.amazonaws.com/FW1.4.8.bin", version="1.4.8">)
136
136
  ----
@@ -142,7 +142,7 @@ Allows you to create a log entry (which is what the device reports when it captu
142
142
  [source,ruby]
143
143
  ----
144
144
  client = TRMNL::API::Client.new
145
- client.call token: "secret",
145
+ client.log token: "secret",
146
146
  log: {
147
147
  logs_array: [
148
148
  {
@@ -174,6 +174,36 @@ client.call 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:
@@ -181,7 +211,7 @@ Allows you to obtain the setup response for when a new device is setup. You must
181
211
  [source,ruby]
182
212
  ----
183
213
  client = TRMNL::API::Client.new
184
- client.call id: "A1:B2:C3:D4:E5:F6"
214
+ client.setup id: "A1:B2:C3:D4:E5:F6"
185
215
 
186
216
  # Success(
187
217
  # #<data TRMNL::API::Models::Setup
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "inspectable"
4
+
3
5
  module TRMNL
4
6
  module API
5
7
  # Provides the primary client for making API requests.
@@ -11,9 +13,19 @@ module TRMNL
11
13
  endpoint_display: :display,
12
14
  endpoint_firmware: :firmware,
13
15
  endpoint_log: :log,
16
+ endpoint_models: :models,
14
17
  endpoint_setup: :setup
15
18
  ]
16
19
 
20
+ include Inspectable[
21
+ endpoint_current_screen: :class,
22
+ endpoint_display: :class,
23
+ endpoint_firmware: :class,
24
+ endpoint_log: :class,
25
+ endpoint_models: :class,
26
+ endpoint_setup: :class
27
+ ]
28
+
17
29
  def initialize(**)
18
30
  super
19
31
  yield settings if block_given?
@@ -27,6 +39,8 @@ module TRMNL
27
39
 
28
40
  def log(**) = endpoint_log.call(**)
29
41
 
42
+ def models(**) = endpoint_models.call(**)
43
+
30
44
  def setup(**) = endpoint_setup.call(**)
31
45
  end
32
46
  end
@@ -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
@@ -13,6 +13,7 @@ module TRMNL
13
13
  register(:display) { Display.new }
14
14
  register(:firmware) { Firmware.new }
15
15
  register(:log) { Log.new }
16
+ register(:models) { Model.new }
16
17
  register(:setup) { Setup.new }
17
18
  end
18
19
  end
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "inspectable"
3
4
  require "pipeable"
4
5
 
5
6
  module TRMNL
@@ -13,6 +14,7 @@ module TRMNL
13
14
  model: "models.current_screen"
14
15
  ]
15
16
 
17
+ include Inspectable[contract: :class]
16
18
  include Pipeable
17
19
 
18
20
  def call token:
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "inspectable"
3
4
  require "pipeable"
4
5
 
5
6
  module TRMNL
@@ -13,6 +14,7 @@ module TRMNL
13
14
  model: "models.display"
14
15
  ]
15
16
 
17
+ include Inspectable[contract: :class]
16
18
  include Pipeable
17
19
 
18
20
  def call token:
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "inspectable"
3
4
  require "pipeable"
4
5
 
5
6
  module TRMNL
@@ -13,6 +14,7 @@ module TRMNL
13
14
  model: "models.firmware"
14
15
  ]
15
16
 
17
+ include Inspectable[contract: :class]
16
18
  include Pipeable
17
19
 
18
20
  def call
@@ -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
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "inspectable"
3
4
  require "pipeable"
4
5
 
5
6
  module TRMNL
@@ -13,6 +14,7 @@ module TRMNL
13
14
  model: "models.setup"
14
15
  ]
15
16
 
17
+ include Inspectable[contract: :class]
16
18
  include Pipeable
17
19
 
18
20
  def call id:
@@ -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.1.0"
5
+ spec.version = "0.3.0"
6
6
  spec.authors = ["TRMNL"]
7
- spec.email = ["support@usetrmnl.com"]
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"
@@ -29,6 +29,7 @@ Gem::Specification.new do |spec|
29
29
  spec.add_dependency "dry-schema", "~> 1.14"
30
30
  spec.add_dependency "http", "~> 5.2"
31
31
  spec.add_dependency "infusible", "~> 4.3"
32
+ spec.add_dependency "inspectable", "~> 0.3"
32
33
  spec.add_dependency "pipeable", "~> 1.3"
33
34
  spec.add_dependency "zeitwerk", "~> 2.7"
34
35
 
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.1.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - TRMNL
@@ -119,6 +119,20 @@ dependencies:
119
119
  - - "~>"
120
120
  - !ruby/object:Gem::Version
121
121
  version: '4.3'
122
+ - !ruby/object:Gem::Dependency
123
+ name: inspectable
124
+ requirement: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - "~>"
127
+ - !ruby/object:Gem::Version
128
+ version: '0.3'
129
+ type: :runtime
130
+ prerelease: false
131
+ version_requirements: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - "~>"
134
+ - !ruby/object:Gem::Version
135
+ version: '0.3'
122
136
  - !ruby/object:Gem::Dependency
123
137
  name: pipeable
124
138
  requirement: !ruby/object:Gem::Requirement
@@ -148,7 +162,7 @@ dependencies:
148
162
  - !ruby/object:Gem::Version
149
163
  version: '2.7'
150
164
  email:
151
- - support@usetrmnl.com
165
+ - engineering@usetrmnl.com
152
166
  executables: []
153
167
  extensions: []
154
168
  extra_rdoc_files:
@@ -165,6 +179,7 @@ files:
165
179
  - lib/trmnl/api/contracts/current_screen.rb
166
180
  - lib/trmnl/api/contracts/display.rb
167
181
  - lib/trmnl/api/contracts/firmware.rb
182
+ - lib/trmnl/api/contracts/model.rb
168
183
  - lib/trmnl/api/contracts/setup.rb
169
184
  - lib/trmnl/api/dependencies.rb
170
185
  - lib/trmnl/api/endpoints/container.rb
@@ -173,10 +188,12 @@ files:
173
188
  - lib/trmnl/api/endpoints/display.rb
174
189
  - lib/trmnl/api/endpoints/firmware.rb
175
190
  - lib/trmnl/api/endpoints/log.rb
191
+ - lib/trmnl/api/endpoints/model.rb
176
192
  - lib/trmnl/api/endpoints/setup.rb
177
193
  - lib/trmnl/api/models/current_screen.rb
178
194
  - lib/trmnl/api/models/display.rb
179
195
  - lib/trmnl/api/models/firmware.rb
196
+ - lib/trmnl/api/models/model.rb
180
197
  - lib/trmnl/api/models/setup.rb
181
198
  - lib/trmnl/api/requester.rb
182
199
  - trmnl-api.gemspec
@@ -204,7 +221,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
204
221
  - !ruby/object:Gem::Version
205
222
  version: '0'
206
223
  requirements: []
207
- rubygems_version: 3.6.8
224
+ rubygems_version: 3.7.1
208
225
  specification_version: 4
209
226
  summary: A monadic TRMNL API client.
210
227
  test_files: []
metadata.gz.sig CHANGED
Binary file