trmnl-api 0.13.0 → 0.15.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.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/README.adoc +61 -36
  4. data/lib/trmnl/api/client.rb +3 -3
  5. data/lib/trmnl/api/configuration/content.rb +16 -2
  6. data/lib/trmnl/api/configuration/loader.rb +9 -1
  7. data/lib/trmnl/api/container.rb +17 -14
  8. data/lib/trmnl/api/containers/register.rb +34 -0
  9. data/lib/trmnl/api/endpoints/category.rb +3 -3
  10. data/lib/trmnl/api/endpoints/current_screen.rb +3 -3
  11. data/lib/trmnl/api/endpoints/display.rb +3 -3
  12. data/lib/trmnl/api/endpoints/ip_address.rb +3 -3
  13. data/lib/trmnl/api/endpoints/{firmware.rb → latest_firmware.rb} +5 -5
  14. data/lib/trmnl/api/endpoints/model.rb +3 -3
  15. data/lib/trmnl/api/endpoints/palette.rb +3 -3
  16. data/lib/trmnl/api/endpoints/recipe.rb +3 -3
  17. data/lib/trmnl/api/endpoints/setup.rb +3 -3
  18. data/lib/trmnl/api/models/{firmware.rb → latest_firmware.rb} +1 -1
  19. data/lib/trmnl/api/models/model.rb +2 -1
  20. data/lib/trmnl/api/models/palette.rb +2 -1
  21. data/lib/trmnl/api/models/recipe.rb +3 -1
  22. data/lib/trmnl/api/requester.rb +5 -6
  23. data/lib/trmnl/api/{contracts → schemas}/category.rb +1 -1
  24. data/lib/trmnl/api/{contracts → schemas}/current_screen.rb +1 -1
  25. data/lib/trmnl/api/{contracts → schemas}/display.rb +1 -1
  26. data/lib/trmnl/api/{contracts → schemas}/ip_address.rb +1 -1
  27. data/lib/trmnl/api/{contracts/firmware.rb → schemas/latest_firmware.rb} +2 -2
  28. data/lib/trmnl/api/{contracts → schemas}/model.rb +2 -1
  29. data/lib/trmnl/api/{contracts → schemas}/palette.rb +1 -1
  30. data/lib/trmnl/api/{contracts → schemas}/recipe.rb +1 -1
  31. data/lib/trmnl/api/{contracts → schemas}/recipes/author.rb +1 -1
  32. data/lib/trmnl/api/{contracts → schemas}/setup.rb +1 -1
  33. data/trmnl-api.gemspec +3 -2
  34. data.tar.gz.sig +0 -0
  35. metadata +42 -27
  36. metadata.gz.sig +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1bf06832c324918b8f93b02b8a8700b617c57cd804e206b2b28b20dc0509c6f2
4
- data.tar.gz: 5547395a2b3fe1abb54de0cee20a58bbb438bdfc9786a5a602eef40a8b12e147
3
+ metadata.gz: 31b74fda2dfe3464acf9af9f49d56fd0836170d300229e32f46bbe3b468042ef
4
+ data.tar.gz: ce20f646705190666a4b1e59f04afafc94349e5099bad69b5392f015b26dccff
5
5
  SHA512:
6
- metadata.gz: e8c73489d9f1334bbd721aab3c7c6270b4bb791982112245b57a9a1305d1e8f6f108e82356dcecf25db970e644ee9de3b626b1db5b4b741edcd633ed262e4e03
7
- data.tar.gz: c511a0cd0e6ca2a15584ee84bf58b6f6556b503118b2a89075401e0c515217a9821ce1e249b1e77741e166bd432678e932d9d4416926174067381df50ebef848
6
+ metadata.gz: d51252433f8303f6c47d26dec1db210304086a90a3feb2de6470cee096cb223e08817c937de85ee3ccd202dd84cec6c5de1093841be805b58b9d4c3f9e53d250
7
+ data.tar.gz: 8633a2468b9397c236a15f3a531a256c414bfae4f1187b76916f9de150e394c2b10363ed6a7f3779fe5c112f23846bacfaec1e789367a17a5f36f43f64010a08
checksums.yaml.gz.sig CHANGED
Binary file
data/README.adoc CHANGED
@@ -62,13 +62,17 @@ See xref:_endpoints[Endpoints] for further details.
62
62
 
63
63
  === Configuration
64
64
 
65
- By default, you shouldn't need to change the default configuration but you can always use a block to adjust settings as desired. If you don't configure the client, then the following defaults will be used:
65
+ By default, you shouldn't need to change the default configuration but you can use a block to adjust settings as desired. If you don't configure the client, then the following defaults will be used:
66
66
 
67
67
  [source,ruby]
68
68
  ----
69
69
  client = TRMNL::API.new do |settings|
70
70
  settings.content_type = "application/json",
71
+ settings.timeout_connect = 2
72
+ settings.timeout_read = 10
73
+ settings.timeout_write = 10
71
74
  settings.uri = "https://trmnl.app/api"
75
+ settings.user_agent = "TRMNL API"
72
76
  end
73
77
  ----
74
78
 
@@ -77,7 +81,11 @@ end
77
81
  You can configure the client via the following environment variables:
78
82
 
79
83
  * `TRMNL_API_CONTENT_TYPE`: Defines the HTTP `Content-Type` header. You shouldn't need to change this but is here if you need it. Default: `"application/json"`.
84
+ * `TRMNL_API_TIMEOUT_CONNECT`: Defines the time, in seconds, for establishing a connection. Default: `2`.
85
+ * `TRMNL_API_TIMEOUT_READ`: Defines the time, in seconds, for reading content. Default: `10`.
86
+ * `TRMNL_API_TIMEOUT_WRITE`: Defines the time, in seconds, for writing content. Default: `10`.
80
87
  * `TRMNL_API_URI`: Defines the API URI. Default: `"https://trmnl.app/api"`.
88
+ * `TRMNL_API_USER_AGENT`: Defines the HTTP `User-Agent` header. You shouldn't need to change this but is here if you need need to customize this for upstream application identification. Default: `"TRMNL API"`. The fully computed user agent ends up being: `"http.rb/6.0.0 (TRMNL API)"` (only the value in parenthesis is configurable).
81
89
 
82
90
  Any/all environment changes will be applied unless you override these settings via the client configuration block shown above.
83
91
 
@@ -143,18 +151,6 @@ client.display token: "secret"
143
151
  # )
144
152
  ----
145
153
 
146
- ==== Firmware
147
-
148
- Allows you to obtain the current stable firmware version. Example:
149
-
150
- [source,ruby]
151
- ----
152
- client = TRMNL::API.new
153
- client.firmware
154
-
155
- # Success(#<data TRMNL::API::Models::Firmware url="https://trmnl-fw.s3.us-east-2.amazonaws.com/FW1.4.8.bin", version="1.4.8">)
156
- ----
157
-
158
154
  ==== IP Addresses
159
155
 
160
156
  Allows you obtain a list of public IP addresses for all TRMNL core servers because plugin poll requests will only originate from these IPs. Example:
@@ -178,6 +174,22 @@ client.ip_addresses
178
174
  # )
179
175
  ----
180
176
 
177
+ ==== Latest Firmware
178
+
179
+ Allows you to obtain the latest stable firmware version. Example:
180
+
181
+ [source,ruby]
182
+ ----
183
+ client = TRMNL::API.new
184
+ client.latest_firmware
185
+
186
+ # Success(
187
+ # #<data TRMNL::API::Models::LatestFirmware
188
+ # url="https://trmnl-fw.s3.us-east-2.amazonaws.com/FW1.4.8.bin",
189
+ # version="1.4.8">
190
+ # )
191
+ ----
192
+
181
193
  ==== Log
182
194
 
183
195
  Allows you to create a log entry (which is what the device reports when it captures an error). You must supply your device's API token as the `token`. Example:
@@ -228,34 +240,31 @@ client.models
228
240
 
229
241
  # Success(
230
242
  # [
231
- # #<data TRMNL::API::Models::Model
232
- # name="test",
233
- # label="Test",
234
- # description="A test.",
235
- # kind="trmnl",
236
- # colors=2,
237
- # bit_depth=1,
238
- # scale_factor=1,
239
- # rotation=90,
240
- # mime_type="image/png",
241
- # width=800,
242
- # height=480,
243
- # offset_x=10,
244
- # offset_y=15,
245
- # palette_names=["bw"],
246
- # css: {
247
- # classes: {
248
- # device: "screen--og_png",
249
- # size: "screen--md"
243
+ # #<Struct:TRMNL::API::Models::Model:0x00003c20
244
+ # bit_depth = 4,
245
+ # colors = 16,
246
+ # css = {
247
+ # classes: {
248
+ # density: "screen--density-2x",
249
+ # device: "screen--v2",
250
+ # size: "screen--lg"
250
251
  # },
251
252
  # variables: [
252
253
  # [
253
254
  # "--screen-w",
254
- # "800px"
255
+ # "1040px"
255
256
  # ],
256
257
  # [
257
258
  # "--screen-h",
258
- # "480px"
259
+ # "780px"
260
+ # ],
261
+ # [
262
+ # "--pixel-ratio",
263
+ # "1.8"
264
+ # ],
265
+ # [
266
+ # "--dither-pixel-ratio",
267
+ # "2.0"
259
268
  # ],
260
269
  # [
261
270
  # "--ui-scale",
@@ -266,7 +275,23 @@ client.models
266
275
  # "1.0"
267
276
  # ]
268
277
  # ]
269
- # }
278
+ # },
279
+ # description = "TRMNL X",
280
+ # height = 1404,
281
+ # kind = "trmnl",
282
+ # label = "TRMNL X",
283
+ # mime_type = "image/png",
284
+ # name = "v2",
285
+ # offset_x = 0,
286
+ # offset_y = 0,
287
+ # palette_names = [
288
+ # "gray-16",
289
+ # "gray-4",
290
+ # "bw"
291
+ # ],
292
+ # rotation = 0,
293
+ # scale_factor = 1.8,
294
+ # width = 1872
270
295
  # >
271
296
  # ]
272
297
  # )
@@ -328,7 +353,7 @@ client.recipes search: "comic" # Answers first page of comics.
328
353
  client.recipes sort: "popularity" # Answers first page sorted by popularity.
329
354
 
330
355
  # Success(
331
- # #<data TRMNL::API::Models::Recipe:0x00010fc0
356
+ # #<data TRMNL::API::Models::Recipe
332
357
  # data = [
333
358
  # #<Struct:TRMNL::API::Models::Recipes::Data:0x00010fe0
334
359
  # author = #<Struct:TRMNL::API::Models::Recipes::Author:0x00010ff0
@@ -13,8 +13,8 @@ module TRMNL
13
13
  categories: Endpoints::Category,
14
14
  current_screen: Endpoints::CurrentScreen,
15
15
  display: Endpoints::Display,
16
- firmware: Endpoints::Firmware,
17
16
  ip_addresses: Endpoints::IPAddress,
17
+ latest_firmware: Endpoints::LatestFirmware,
18
18
  log: Endpoints::Log,
19
19
  models: Endpoints::Model,
20
20
  palettes: Endpoints::Palette,
@@ -40,10 +40,10 @@ module TRMNL
40
40
 
41
41
  def display(**) = endpoints.fetch(__method__).call(**)
42
42
 
43
- def firmware = endpoints.fetch(__method__).call
44
-
45
43
  def ip_addresses = endpoints.fetch(__method__).call
46
44
 
45
+ def latest_firmware = endpoints.fetch(__method__).call
46
+
47
47
  def log(**) = endpoints.fetch(__method__).call(**)
48
48
 
49
49
  def models(**) = endpoints.fetch(__method__).call(**)
@@ -1,11 +1,25 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "http"
4
+
3
5
  module TRMNL
4
6
  module API
5
7
  module Configuration
6
8
  # Provides API client configuration content.
7
- Content = Struct.new :content_type, :uri do
8
- def headers = {"Content-Type" => content_type}.compact
9
+ Content = Struct.new(
10
+ :content_type,
11
+ :timeout_connect,
12
+ :timeout_read,
13
+ :timeout_write,
14
+ :uri,
15
+ :user_agent
16
+ ) do
17
+ def headers
18
+ agent = " (#{user_agent})" if user_agent
19
+ {content_type: content_type, user_agent: "http.rb/#{HTTP::VERSION}#{agent}"}.compact
20
+ end
21
+
22
+ def timeout = {connect: timeout_connect, read: timeout_read, write: timeout_write}
9
23
  end
10
24
  end
11
25
  end
@@ -13,13 +13,21 @@ module TRMNL
13
13
  def call
14
14
  model[
15
15
  content_type: environment.fetch("TRMNL_API_CONTENT_TYPE", "application/json"),
16
- uri: environment.fetch("TRMNL_API_URI", "https://trmnl.com/api")
16
+ timeout_connect: environment.fetch("TRMNL_API_TIMEOUT_CONNECT", 2).to_i,
17
+ timeout_read: environment.fetch("TRMNL_API_TIMEOUT_READ", 10).to_i,
18
+ timeout_write: environment.fetch("TRMNL_API_TIMEOUT_WRITE", 10).to_i,
19
+ uri: environment.fetch("TRMNL_API_URI", "https://trmnl.com/api"),
20
+ user_agent: "http.rb/#{HTTP::VERSION} (#{default_user_agent})"
17
21
  ]
18
22
  end
19
23
 
20
24
  private
21
25
 
22
26
  attr_reader :model, :environment
27
+
28
+ def default_user_agent
29
+ environment.fetch "TRMNL_API_USER_AGENT", TRMNL::API.name.gsub("::", " ")
30
+ end
23
31
  end
24
32
  end
25
33
  end
@@ -8,33 +8,36 @@ module TRMNL
8
8
  module API
9
9
  # Registers application dependencies.
10
10
  module Container
11
- extend Containable
11
+ extend Containable[register: Containers::Register]
12
12
 
13
13
  register(:settings, as: :fresh) { TRMNL::API::Configuration::Loader.new.call }
14
14
  register(:requester) { API::Requester.new }
15
15
  register(:logger) { Cogger.new id: "trmnl-api", formatter: :json }
16
16
 
17
17
  register :http do
18
- HTTP.default_options = HTTP::Options.new features: {logging: {logger: self[:logger]}}
19
- HTTP
18
+ settings = self[:settings]
19
+
20
+ HTTP.timeout(settings.timeout)
21
+ .headers(settings.headers)
22
+ .use(logging: {logger: self[:logger]})
20
23
  end
21
24
 
22
- namespace :contracts do
23
- register :category, Contracts::Category
24
- register :current_screen, Contracts::CurrentScreen
25
- register :display, Contracts::Display
26
- register :firmware, Contracts::Firmware
27
- register :ip_address, Contracts::IPAddress
28
- register :model, Contracts::Model
29
- register :palette, Contracts::Palette
30
- register :recipe, Contracts::Recipe
31
- register :setup, Contracts::Setup
25
+ namespace :schemas do
26
+ register :category, Schemas::Category
27
+ register :current_screen, Schemas::CurrentScreen
28
+ register :display, Schemas::Display
29
+ register :latest_firmware, Schemas::LatestFirmware
30
+ register :ip_address, Schemas::IPAddress
31
+ register :model, Schemas::Model
32
+ register :palette, Schemas::Palette
33
+ register :recipe, Schemas::Recipe
34
+ register :setup, Schemas::Setup
32
35
  end
33
36
 
34
37
  namespace :models do
35
38
  register :current_screen, Models::CurrentScreen
36
39
  register :display, Models::Display
37
- register :firmware, Models::Firmware
40
+ register :latest_firmware, Models::LatestFirmware
38
41
  register :ip_address, Models::IPAddress
39
42
  register :model, Models::Model
40
43
  register :palette, Models::Palette
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "containable"
4
+ require "refinements/array"
5
+
6
+ module TRMNL
7
+ module API
8
+ module Containers
9
+ # A custom Containable register that allows specific dependencies to be overwritten.
10
+ class Register < Containable::Register
11
+ using Refinements::Array
12
+
13
+ def initialize(*, allowed_keys: %w[http logger], **)
14
+ super(*, **)
15
+ @allowed_keys = allowed_keys
16
+ end
17
+
18
+ protected
19
+
20
+ def check_duplicate key, namespaced_key
21
+ return if allowed_keys.include? namespaced_key
22
+
23
+ message = "Dependency is already registered: #{key.inspect}."
24
+
25
+ fail KeyError, message if dependencies.key? namespaced_key
26
+ end
27
+
28
+ private
29
+
30
+ attr_reader :allowed_keys
31
+ end
32
+ end
33
+ end
34
+ end
@@ -8,16 +8,16 @@ module TRMNL
8
8
  module Endpoints
9
9
  # Handles API request/response.
10
10
  class Category
11
- include TRMNL::API::Dependencies[:requester, contract: "contracts.category"]
11
+ include TRMNL::API::Dependencies[:requester, schema: "schemas.category"]
12
12
 
13
- include Inspectable[contract: :type]
13
+ include Inspectable[schema: :type]
14
14
  include Pipeable
15
15
 
16
16
  def call
17
17
  pipe(
18
18
  requester.get("categories"),
19
19
  try(:parse, catch: JSON::ParserError),
20
- validate(contract, as: :to_h),
20
+ validate(schema, as: :to_h),
21
21
  as(:fetch, :data)
22
22
  )
23
23
  end
@@ -10,17 +10,17 @@ module TRMNL
10
10
  class CurrentScreen
11
11
  include TRMNL::API::Dependencies[
12
12
  :requester,
13
- contract: "contracts.current_screen",
13
+ schema: "schemas.current_screen",
14
14
  model: "models.current_screen"
15
15
  ]
16
16
 
17
- include Inspectable[contract: :type]
17
+ include Inspectable[schema: :type]
18
18
  include Pipeable
19
19
 
20
20
  def call token:
21
21
  pipe requester.get("current_screen", headers: {"Access-Token" => token}),
22
22
  try(:parse, catch: JSON::ParserError),
23
- validate(contract, as: :to_h),
23
+ validate(schema, as: :to_h),
24
24
  to(model, :for)
25
25
  end
26
26
  end
@@ -10,17 +10,17 @@ module TRMNL
10
10
  class Display
11
11
  include TRMNL::API::Dependencies[
12
12
  :requester,
13
- contract: "contracts.display",
13
+ schema: "schemas.display",
14
14
  model: "models.display"
15
15
  ]
16
16
 
17
- include Inspectable[contract: :type]
17
+ include Inspectable[schema: :type]
18
18
  include Pipeable
19
19
 
20
20
  def call token:
21
21
  pipe requester.get("display", headers: {"Access-Token" => token}),
22
22
  try(:parse, catch: JSON::ParserError),
23
- validate(contract, as: :to_h),
23
+ validate(schema, as: :to_h),
24
24
  to(model, :for)
25
25
  end
26
26
  end
@@ -10,17 +10,17 @@ module TRMNL
10
10
  class IPAddress
11
11
  include TRMNL::API::Dependencies[
12
12
  :requester,
13
- contract: "contracts.ip_address",
13
+ schema: "schemas.ip_address",
14
14
  model: "models.ip_address"
15
15
  ]
16
16
 
17
- include Inspectable[contract: :type]
17
+ include Inspectable[schema: :type]
18
18
  include Pipeable
19
19
 
20
20
  def call
21
21
  pipe requester.get("ips"),
22
22
  try(:parse, catch: JSON::ParserError),
23
- validate(contract, as: :to_h),
23
+ validate(schema, as: :to_h),
24
24
  as(:fetch, :data),
25
25
  to(model, :for)
26
26
  end
@@ -7,20 +7,20 @@ module TRMNL
7
7
  module API
8
8
  module Endpoints
9
9
  # Handles API request/response.
10
- class Firmware
10
+ class LatestFirmware
11
11
  include TRMNL::API::Dependencies[
12
12
  :requester,
13
- contract: "contracts.firmware",
14
- model: "models.firmware"
13
+ schema: "schemas.latest_firmware",
14
+ model: "models.latest_firmware"
15
15
  ]
16
16
 
17
- include Inspectable[contract: :type]
17
+ include Inspectable[schema: :type]
18
18
  include Pipeable
19
19
 
20
20
  def call
21
21
  pipe requester.get("firmware/latest"),
22
22
  try(:parse, catch: JSON::ParserError),
23
- validate(contract, as: :to_h),
23
+ validate(schema, as: :to_h),
24
24
  to(model, :for)
25
25
  end
26
26
  end
@@ -10,18 +10,18 @@ module TRMNL
10
10
  class Model
11
11
  include TRMNL::API::Dependencies[
12
12
  :requester,
13
- contract: "contracts.model",
13
+ schema: "schemas.model",
14
14
  model: "models.model"
15
15
  ]
16
16
 
17
- include Inspectable[contract: :type]
17
+ include Inspectable[schema: :type]
18
18
  include Pipeable
19
19
 
20
20
  def call
21
21
  pipe(
22
22
  requester.get("models"),
23
23
  try(:parse, catch: JSON::ParserError),
24
- validate(contract, as: :to_h),
24
+ validate(schema, as: :to_h),
25
25
  as(:fetch, :data),
26
26
  map { |data| model.for(**data) }
27
27
  )
@@ -10,18 +10,18 @@ module TRMNL
10
10
  class Palette
11
11
  include TRMNL::API::Dependencies[
12
12
  :requester,
13
- contract: "contracts.palette",
13
+ schema: "schemas.palette",
14
14
  model: "models.palette"
15
15
  ]
16
16
 
17
- include Inspectable[contract: :type]
17
+ include Inspectable[schema: :type]
18
18
  include Pipeable
19
19
 
20
20
  def call
21
21
  pipe(
22
22
  requester.get("palettes"),
23
23
  try(:parse, catch: JSON::ParserError),
24
- validate(contract, as: :to_h),
24
+ validate(schema, as: :to_h),
25
25
  as(:fetch, :data),
26
26
  map { |data| model.for(**data) }
27
27
  )
@@ -11,11 +11,11 @@ module TRMNL
11
11
  class Recipe
12
12
  include TRMNL::API::Dependencies[
13
13
  :requester,
14
- contract: "contracts.recipe",
14
+ schema: "schemas.recipe",
15
15
  model: "models.recipe"
16
16
  ]
17
17
 
18
- include Inspectable[contract: :type]
18
+ include Inspectable[schema: :type]
19
19
  include Pipeable
20
20
 
21
21
  using Refinements::Hash
@@ -26,7 +26,7 @@ module TRMNL
26
26
  pipe(
27
27
  requester.get("recipes.json", **parameters),
28
28
  try(:parse, catch: JSON::ParserError),
29
- validate(contract, as: :to_h),
29
+ validate(schema, as: :to_h),
30
30
  to(model, :for)
31
31
  )
32
32
  end
@@ -10,17 +10,17 @@ module TRMNL
10
10
  class Setup
11
11
  include TRMNL::API::Dependencies[
12
12
  :requester,
13
- contract: "contracts.setup",
13
+ schema: "schemas.setup",
14
14
  model: "models.setup"
15
15
  ]
16
16
 
17
- include Inspectable[contract: :type]
17
+ include Inspectable[schema: :type]
18
18
  include Pipeable
19
19
 
20
20
  def call id:
21
21
  pipe requester.get("setup", headers: {"ID" => id}),
22
22
  try(:parse, catch: JSON::ParserError),
23
- validate(contract, as: :to_h),
23
+ validate(schema, as: :to_h),
24
24
  to(model, :for)
25
25
  end
26
26
  end
@@ -4,7 +4,7 @@ module TRMNL
4
4
  module API
5
5
  module Models
6
6
  # Models the data of the API response.
7
- Firmware = ::Data.define :url, :version do
7
+ LatestFirmware = ::Data.define :url, :version do
8
8
  def self.for(attributes) = new(**attributes)
9
9
  end
10
10
  end
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "core"
3
4
  require "refinements/hash"
4
5
 
5
6
  module TRMNL
@@ -36,7 +37,7 @@ module TRMNL
36
37
  private
37
38
 
38
39
  def apply_defaults
39
- self[:palette_names] ||= []
40
+ self[:palette_names] ||= Core::EMPTY_ARRAY
40
41
 
41
42
  %i[colors bit_depth scale_factor rotation width height offset_x offset_y].each do |name|
42
43
  self[name] ||= 0
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "core"
3
4
  require "refinements/hash"
4
5
 
5
6
  module TRMNL
@@ -14,7 +15,7 @@ module TRMNL
14
15
  def initialize(**)
15
16
  super
16
17
  self[:grays] ||= 0
17
- self[:colors] ||= []
18
+ self[:colors] ||= Core::EMPTY_ARRAY
18
19
  freeze
19
20
  end
20
21
  end
@@ -1,11 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "core"
4
+
3
5
  module TRMNL
4
6
  module API
5
7
  module Models
6
8
  # Models the payload of the API response.
7
9
  Recipe = ::Data.define :data, :meta do
8
- def self.empty(meta: Recipes::Meta.new) = new(data: [], meta:)
10
+ def self.empty(meta: Recipes::Meta.new) = new(data: Core::EMPTY_ARRAY, meta:)
9
11
 
10
12
  def self.for(**attributes)
11
13
  meta = attributes.slice :from,
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "core"
3
4
  require "dry/monads"
4
5
  require "http"
5
6
 
@@ -10,22 +11,20 @@ module TRMNL
10
11
  include Dependencies[:settings, :http, :logger]
11
12
  include Dry::Monads[:result]
12
13
 
13
- HEADERS = {}.freeze
14
-
15
14
  def initialize(**)
16
15
  super
17
16
  yield settings if block_given?
18
17
  end
19
18
 
20
- def get(path, headers: HEADERS, **params) = call(__method__, path, headers, params:)
19
+ def get(path, headers: Core::EMPTY_HASH, **params) = call(__method__, path, headers, params:)
21
20
 
22
- def post(path, headers: HEADERS, **json) = call(__method__, path, headers, json:)
21
+ def post(path, headers: Core::EMPTY_HASH, **json) = call(__method__, path, headers, json:)
23
22
 
24
23
  private
25
24
 
26
25
  def call method, path, headers, **options
27
- http.headers(settings.headers.merge(headers))
28
- .public_send(method, uri(path), options)
26
+ http.headers(headers)
27
+ .public_send(method, uri(path), **options)
29
28
  .then { |response| response.status.success? ? Success(response) : Failure(response) }
30
29
  rescue HTTP::RequestError => error then handle_bad_request path, error
31
30
  rescue HTTP::ConnectionError => error then handle_bad_connection path, error
@@ -4,7 +4,7 @@ require "dry/schema"
4
4
 
5
5
  module TRMNL
6
6
  module API
7
- module Contracts
7
+ module Schemas
8
8
  # Validates API response.
9
9
  Category = Dry::Schema.JSON { required(:data).array(:string) }
10
10
  end
@@ -4,7 +4,7 @@ require "dry/schema"
4
4
 
5
5
  module TRMNL
6
6
  module API
7
- module Contracts
7
+ module Schemas
8
8
  # Validates API response.
9
9
  CurrentScreen = Dry::Schema.JSON do
10
10
  required(:refresh_rate).filled :integer
@@ -4,7 +4,7 @@ require "dry/schema"
4
4
 
5
5
  module TRMNL
6
6
  module API
7
- module Contracts
7
+ module Schemas
8
8
  # Validates API response.
9
9
  Display = Dry::Schema.JSON do
10
10
  required(:filename).filled :string
@@ -4,7 +4,7 @@ require "dry/schema"
4
4
 
5
5
  module TRMNL
6
6
  module API
7
- module Contracts
7
+ module Schemas
8
8
  # Validates API response.
9
9
  IPAddress = Dry::Schema.JSON do
10
10
  required(:data).hash do
@@ -4,9 +4,9 @@ require "dry/schema"
4
4
 
5
5
  module TRMNL
6
6
  module API
7
- module Contracts
7
+ module Schemas
8
8
  # Validates API response.
9
- Firmware = Dry::Schema.JSON do
9
+ LatestFirmware = Dry::Schema.JSON do
10
10
  required(:url).filled :string
11
11
  required(:version).filled :string
12
12
  end
@@ -4,7 +4,7 @@ require "dry/schema"
4
4
 
5
5
  module TRMNL
6
6
  module API
7
- module Contracts
7
+ module Schemas
8
8
  # Validates API response.
9
9
  Model = Dry::Schema.JSON do
10
10
  required(:data).array(:hash) do
@@ -24,6 +24,7 @@ module TRMNL
24
24
  required(:palette_ids).array(:string)
25
25
  optional(:css).hash do
26
26
  optional(:classes).hash do
27
+ required(:density).filled :string
27
28
  required(:device).filled :string
28
29
  required(:size).filled :string
29
30
  end
@@ -4,7 +4,7 @@ require "dry/schema"
4
4
 
5
5
  module TRMNL
6
6
  module API
7
- module Contracts
7
+ module Schemas
8
8
  # Validates API response.
9
9
  Palette = Dry::Schema.JSON do
10
10
  required(:data).array(:hash) do
@@ -4,7 +4,7 @@ require "dry/schema"
4
4
 
5
5
  module TRMNL
6
6
  module API
7
- module Contracts
7
+ module Schemas
8
8
  # Validates API response.
9
9
  Recipe = Dry::Schema.JSON do
10
10
  required(:data).array(:hash) do
@@ -4,7 +4,7 @@ require "dry/schema"
4
4
 
5
5
  module TRMNL
6
6
  module API
7
- module Contracts
7
+ module Schemas
8
8
  module Recipes
9
9
  # Validates API response.
10
10
  Author = Dry::Schema.JSON do
@@ -4,7 +4,7 @@ require "dry/schema"
4
4
 
5
5
  module TRMNL
6
6
  module API
7
- module Contracts
7
+ module Schemas
8
8
  # Validates API response.
9
9
  Setup = Dry::Schema.JSON do
10
10
  required(:api_key).filled :string
data/trmnl-api.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "trmnl-api"
5
- spec.version = "0.13.0"
5
+ spec.version = "0.15.0"
6
6
  spec.authors = ["TRMNL"]
7
7
  spec.email = ["engineering@trmnl.com"]
8
8
  spec.homepage = "https://github.com/usetrmnl/trmnl-api"
@@ -25,10 +25,11 @@ Gem::Specification.new do |spec|
25
25
 
26
26
  spec.add_dependency "cogger", "~> 2.0"
27
27
  spec.add_dependency "containable", "~> 2.0"
28
+ spec.add_dependency "core", "~> 3.2"
28
29
  spec.add_dependency "dry-monads", "~> 1.9"
29
30
  spec.add_dependency "dry-schema", "~> 1.14"
30
31
  spec.add_dependency "dry-types", "~> 1.8"
31
- spec.add_dependency "http", "~> 5.3"
32
+ spec.add_dependency "http", "~> 6.0"
32
33
  spec.add_dependency "infusible", "~> 5.0"
33
34
  spec.add_dependency "inspectable", "~> 1.0"
34
35
  spec.add_dependency "pipeable", "~> 2.0"
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.13.0
4
+ version: 0.15.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - TRMNL
@@ -9,9 +9,9 @@ bindir: bin
9
9
  cert_chain:
10
10
  - |
11
11
  -----BEGIN CERTIFICATE-----
12
- MIIENjCCAp6gAwIBAgIBAjANBgkqhkiG9w0BAQsFADBBMQ8wDQYDVQQDDAZicm9v
12
+ MIIENjCCAp6gAwIBAgIBAzANBgkqhkiG9w0BAQsFADBBMQ8wDQYDVQQDDAZicm9v
13
13
  a2UxGjAYBgoJkiaJk/IsZAEZFgphbGNoZW1pc3RzMRIwEAYKCZImiZPyLGQBGRYC
14
- aW8wHhcNMjUwMzIyMTQ1NDE3WhcNMjYwMzIyMTQ1NDE3WjBBMQ8wDQYDVQQDDAZi
14
+ aW8wHhcNMjYwMzI1MTI0OTEyWhcNMjcwMzI1MTI0OTEyWjBBMQ8wDQYDVQQDDAZi
15
15
  cm9va2UxGjAYBgoJkiaJk/IsZAEZFgphbGNoZW1pc3RzMRIwEAYKCZImiZPyLGQB
16
16
  GRYCaW8wggGiMA0GCSqGSIb3DQEBAQUAA4IBjwAwggGKAoIBgQCro8tj5/E1Hg88
17
17
  f4qfiwPVd2zJQHvdYt4GHVvuHRRgx4HGhJuNp+4BId08RBn7V6V1MW6MY3kezRBs
@@ -23,15 +23,15 @@ cert_chain:
23
23
  GUHU9MyIXbFOsnp3K3ADrAVjPWop8EZkmUR3MV/CUm00w2cZHCSGiXl1KMpiVKvk
24
24
  Ywr1gd2ZME4QLSo+EXUtLxDUa/W3xnBS8dBOuMMz02FPWYr3PN8CAwEAAaM5MDcw
25
25
  CQYDVR0TBAIwADALBgNVHQ8EBAMCBLAwHQYDVR0OBBYEFAFgmv0tYMZnItuPycSM
26
- F5wykJEVMA0GCSqGSIb3DQEBCwUAA4IBgQBlzRfyAYx/fCFjizS0Npxw4+4T3aYL
27
- hbXoDqQRWjxuhFZcXUymhz3r8/Ltyri9lSof8grzB+8/+mrMVms7Gwt5qolk6zdn
28
- FkySGy/jmpN12ldOHFbBEnyVBZNBvOBVb8zkkw8PhiHdBdXOUm4Jy39yJvBLfjcC
29
- iM1aeWPmgPy1GbvZU+leRGZLt6dRIR9oCDXcWLRjha8xLMoz6Yn9fJBYexBA3iEz
30
- h5S7pn4AX/JhVRiSyl8pAy4jEKydpyQrliH3gHkpNmUS/XDczP+9xX1bAB4BvqL2
31
- NCxMcQ+hiJNqCKpPgHxaOOHZfIxV33logIuPEQ8NryHAwZ9ZWnwtYDE8kQGGKskI
32
- Kkm6QT474hZl7MpwiJjWgW313CR7jUEekQahX1QxCxHPI7LSrKpno0plH3uWIOQp
33
- KUlkb9uyACBgyRO52ZHiDVI8YvtU5O/j9pSes9/3XgvBeC1onx4qWp+uRX7eVsYS
34
- GiijocTc3enZVrXERetaXj8/9XWs3fB3HWY=
26
+ F5wykJEVMA0GCSqGSIb3DQEBCwUAA4IBgQAG+ykjp+DIXSybGEtX+/ve974mYfN6
27
+ 8U7qcVfRM+qDSOZ+97iu30qUTbVAKIHlHCDKRn3SgOffDUB5VU2MsJBh/3TPKWBZ
28
+ anB/uzMcwOfru+qyA3b7ZFqZzRLWmR5FtPObFxc0gYMT3YvLNHk2Nb9Vjq/PoiGG
29
+ e75PXweDOokwDA5m1gMOz1rdp/dlGMXkSFQg94PPVyUKXgO4VzWTgePSDxOIL+v6
30
+ +OWV6AaEH9BaqxnmdA5ubi0L7bhl0gbN92FxpNO3kpTjww8kme856a+wCK3qyM5w
31
+ 7ZLbUexynDN0Au8eSpT2Bf6ztGmB1S9ffzDJsGX1/lkpMIB51e48Xe2+gzzOgemk
32
+ CdZaGupj6WkarnT8kh/cPtyA5ax4rGX6GOS8meGxzkv8Uy0JSEOYAp6wLfIisYZp
33
+ IJBIXIOkwKKJ0eB5YHrUSJxzpP4LlcIg/eTftaXmJdYjy+2VRrCZYDjfguyLmMjR
34
+ KR9w4/Fjvqy87kCHmxMWa6IL2Vzt1Clm2cA=
35
35
  -----END CERTIFICATE-----
36
36
  date: 1980-01-02 00:00:00.000000000 Z
37
37
  dependencies:
@@ -63,6 +63,20 @@ dependencies:
63
63
  - - "~>"
64
64
  - !ruby/object:Gem::Version
65
65
  version: '2.0'
66
+ - !ruby/object:Gem::Dependency
67
+ name: core
68
+ requirement: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - "~>"
71
+ - !ruby/object:Gem::Version
72
+ version: '3.2'
73
+ type: :runtime
74
+ prerelease: false
75
+ version_requirements: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - "~>"
78
+ - !ruby/object:Gem::Version
79
+ version: '3.2'
66
80
  - !ruby/object:Gem::Dependency
67
81
  name: dry-monads
68
82
  requirement: !ruby/object:Gem::Requirement
@@ -111,14 +125,14 @@ dependencies:
111
125
  requirements:
112
126
  - - "~>"
113
127
  - !ruby/object:Gem::Version
114
- version: '5.3'
128
+ version: '6.0'
115
129
  type: :runtime
116
130
  prerelease: false
117
131
  version_requirements: !ruby/object:Gem::Requirement
118
132
  requirements:
119
133
  - - "~>"
120
134
  - !ruby/object:Gem::Version
121
- version: '5.3'
135
+ version: '6.0'
122
136
  - !ruby/object:Gem::Dependency
123
137
  name: infusible
124
138
  requirement: !ruby/object:Gem::Requirement
@@ -190,24 +204,15 @@ files:
190
204
  - lib/trmnl/api/configuration/content.rb
191
205
  - lib/trmnl/api/configuration/loader.rb
192
206
  - lib/trmnl/api/container.rb
193
- - lib/trmnl/api/contracts/category.rb
194
- - lib/trmnl/api/contracts/current_screen.rb
195
- - lib/trmnl/api/contracts/display.rb
196
- - lib/trmnl/api/contracts/firmware.rb
197
- - lib/trmnl/api/contracts/ip_address.rb
198
- - lib/trmnl/api/contracts/model.rb
199
- - lib/trmnl/api/contracts/palette.rb
200
- - lib/trmnl/api/contracts/recipe.rb
201
- - lib/trmnl/api/contracts/recipes/author.rb
202
- - lib/trmnl/api/contracts/setup.rb
207
+ - lib/trmnl/api/containers/register.rb
203
208
  - lib/trmnl/api/dependencies.rb
204
209
  - lib/trmnl/api/endpoints/category.rb
205
210
  - lib/trmnl/api/endpoints/container.rb
206
211
  - lib/trmnl/api/endpoints/current_screen.rb
207
212
  - lib/trmnl/api/endpoints/dependencies.rb
208
213
  - lib/trmnl/api/endpoints/display.rb
209
- - lib/trmnl/api/endpoints/firmware.rb
210
214
  - lib/trmnl/api/endpoints/ip_address.rb
215
+ - lib/trmnl/api/endpoints/latest_firmware.rb
211
216
  - lib/trmnl/api/endpoints/log.rb
212
217
  - lib/trmnl/api/endpoints/model.rb
213
218
  - lib/trmnl/api/endpoints/palette.rb
@@ -216,8 +221,8 @@ files:
216
221
  - lib/trmnl/api/locale_reducer.rb
217
222
  - lib/trmnl/api/models/current_screen.rb
218
223
  - lib/trmnl/api/models/display.rb
219
- - lib/trmnl/api/models/firmware.rb
220
224
  - lib/trmnl/api/models/ip_address.rb
225
+ - lib/trmnl/api/models/latest_firmware.rb
221
226
  - lib/trmnl/api/models/model.rb
222
227
  - lib/trmnl/api/models/palette.rb
223
228
  - lib/trmnl/api/models/recipe.rb
@@ -227,6 +232,16 @@ files:
227
232
  - lib/trmnl/api/models/recipes/statistics.rb
228
233
  - lib/trmnl/api/models/setup.rb
229
234
  - lib/trmnl/api/requester.rb
235
+ - lib/trmnl/api/schemas/category.rb
236
+ - lib/trmnl/api/schemas/current_screen.rb
237
+ - lib/trmnl/api/schemas/display.rb
238
+ - lib/trmnl/api/schemas/ip_address.rb
239
+ - lib/trmnl/api/schemas/latest_firmware.rb
240
+ - lib/trmnl/api/schemas/model.rb
241
+ - lib/trmnl/api/schemas/palette.rb
242
+ - lib/trmnl/api/schemas/recipe.rb
243
+ - lib/trmnl/api/schemas/recipes/author.rb
244
+ - lib/trmnl/api/schemas/setup.rb
230
245
  - lib/trmnl/api/types.rb
231
246
  - trmnl-api.gemspec
232
247
  homepage: https://github.com/usetrmnl/trmnl-api
@@ -253,7 +268,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
253
268
  - !ruby/object:Gem::Version
254
269
  version: '0'
255
270
  requirements: []
256
- rubygems_version: 4.0.8
271
+ rubygems_version: 4.0.11
257
272
  specification_version: 4
258
273
  summary: A monadic TRMNL API client.
259
274
  test_files: []
metadata.gz.sig CHANGED
Binary file