trmnl-api 0.9.0 → 0.10.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: cb8a2557d167924338d70a68b91207d89f48b72a44e66e252fd0760fc3ffc035
4
- data.tar.gz: 4c3329056c42c1b57347eb00b748f0baf384720c67aeacf938ce2dcecee4a2e3
3
+ metadata.gz: 168b5086d30774ef88cc9d12ae187ffa4da349bfe10456c64a5e2fe7e94372a3
4
+ data.tar.gz: d7c785269f0ddf0238d399a352cef774c9081bb6706a238cf9ead6bcc413ff0e
5
5
  SHA512:
6
- metadata.gz: 6b7a621e59c10820c52b5dbad143b03399544297fba3faa89078a938539ef53cbb7c823a1028f24930fa4edd56d21c2788a440bdf5b3310ccba8d8dac1fc7f06
7
- data.tar.gz: b67362a9aa48c7a4009e5b7f59201378c69bca85de6bb560e4c1b208ab6c5bc15c64e6edceb17d3d6a163b7f1fae00fffb3052c987cb9ee4a851c131b713ead9
6
+ metadata.gz: 4b6cdd52fa7cc10214220a4906298a1d2243d1da94f8854d1dd1eb67cdcd70a761655a717630bb561151e84c01b8926e7b9fac65e1cd84c9fb7590cddc164f7e
7
+ data.tar.gz: 732532ba60f51c994898d1a982f404ba0d38b419ccc2c6cc95b46548234c51e1b40eedeeda6b4047d81b46f03408b4fccaa8dc8bef3b85dbcef70c0a4a355576
checksums.yaml.gz.sig CHANGED
Binary file
data/README.adoc CHANGED
@@ -304,82 +304,81 @@ Success(
304
304
 
305
305
  Allows you to obtain information about link:https://usetrmnl.com/recipes[Recipes]. Example:
306
306
 
307
- ⚠️ This _does not_ use the {trmnl_api_link} like every other endpoint documented here. This is why you must customize the settings URI to point to the root of the TRMNL application instead of using the default API endpoint.
308
-
309
307
  [source,ruby]
310
308
  ----
311
309
  client = TRMNL::API.new { |settings| settings.uri = "https://usetrmnl.com" }
312
310
 
313
- client.recipes # Answers first page.
314
- client.recipes page: 10 # Answers page ten.
315
- client.recipes search: "comic" # Answers first page of comics.
316
- client.recipes "sort-by": "popularity" # Answers first page sorted by popularity.
311
+ client.recipes # Answers first page.
312
+ client.recipes page: 10 # Answers page ten.
313
+ client.recipes search: "comic" # Answers first page of comics.
314
+ client.recipes sort: "popularity" # Answers first page sorted by popularity.
317
315
 
318
316
  # Success(
319
- # #<data TRMNL::API::Models::Recipe:0x0000b4d0
320
- # current_page = 1,
321
- # data = [
322
- # #<Struct:TRMNL::API::Models::Recipes::Entry:0x0000b4f0
323
- # author = #<Struct:TRMNL::API::Models::Recipes::Author:0x0000b500
324
- # category = "travel",
325
- # description = "Displays upcoming...",
326
- # description_locales = {},
327
- # email_address = nil,
328
- # field_type = "author_bio",
329
- # github_url = "https://github.com/CaptainProton42/trmnl-bustimes-org",
330
- # keyname = "readme",
331
- # learn_more_url = nil,
332
- # name = "About This Plugin",
333
- # youtube_url = nil
334
- # >,
335
- # custom_fields = [
336
- # {
337
- # "keyname" => "readme",
338
- # "name" => "About This Plugin",
339
- # "category" => "travel",
340
- # "field_type" => "author_bio",
341
- # "description" => "Displays upcoming...",
342
- # "github_url" => "https://github.com/CaptainProton42/trmnl-bustimes-org"
343
- # },
344
- # {
345
- # "keyname" => "atco",
346
- # "field_type" => "string",
347
- # "name" => "Bus Stop",
348
- # "description" => "The <a href=\"https://mullinscr.github.io/naptan/atco_codes/\">ATCO</a> code for your bus stop.",
349
- # "help_text" => "You can find this..."
350
- # },
351
- # {
352
- # "keyname" => "bus",
353
- # "field_type" => "multi_string",
354
- # "name" => "Busses",
355
- # "description" => "Optionally, choose specific bus services you want to display departures for.",
356
- # "help_text" => "Use the name of the service, e.g. '10' or '3A'.",
357
- # "optional" => true
358
- # }
359
- # ],
360
- # icon_content_type = "image/png",
361
- # icon_url = "https://trmnl-public.s3.us-east-2.amazonaws.com/59lqujqwid1cvzsd7sr3erfuexur",
362
- # id = 222328,
363
- # name = "UK Bus Departures (bustimes.org)",
364
- # published_at = 2026-01-14 22:53:07.587 UTC,
365
- # screenshot_url = "https://trmnl.s3.us-east-2.amazonaws.com...",
366
- # statistics = #<data TRMNL::API::Models::Recipes::Statistics:0x0000b710
367
- # forks = 0,
368
- # installs = 1
369
- # >
370
- # >
371
- # ],
372
- # from = 1,
373
- # next_page_url = "/recipes.json?page=2",
374
- # per_page = 25,
375
- # prev_page_url = nil,
376
- # to = 25,
377
- # total = 658
378
- # >
317
+ # #<data TRMNL::API::Models::Recipe:0x00010fc0
318
+ # data = [
319
+ # #<Struct:TRMNL::API::Models::Recipes::Data:0x00010fe0
320
+ # author = #<Struct:TRMNL::API::Models::Recipes::Author:0x00010ff0
321
+ # category = nil,
322
+ # description = nil,
323
+ # description_locales = {},
324
+ # email_address = nil,
325
+ # field_type = nil,
326
+ # github_url = nil,
327
+ # keyname = nil,
328
+ # learn_more_url = nil,
329
+ # name = nil,
330
+ # youtube_url = nil
331
+ # >,
332
+ # custom_fields = [
333
+ # {
334
+ # "keyname" => "user_location",
335
+ # "field_type" => "string",
336
+ # "name" => "Weather Location",
337
+ # "placeholder" => "New York, NY",
338
+ # "description" => "Choose a location",
339
+ # "help_text" => "Please be precise...",
340
+ # "required" => true
341
+ # },
342
+ # {
343
+ # "keyname" => "metric",
344
+ # "name" => "Temperature Metric",
345
+ # "description" => "Celsius or Fahrenheit?",
346
+ # "field_type" => "select",
347
+ # "options" => [
348
+ # "Fahrenheit",
349
+ # "Celsius"
350
+ # ],
351
+ # "default" => "Fahrenheit"
352
+ # }
353
+ # ],
354
+ # icon_content_type = "image/png",
355
+ # icon_url = "https://trmnl-public.s3.us-east-2.amazonaws.com/ajjlbek4cabcvhk3s1lxggn8cgon",
356
+ # id = 49610,
357
+ # name = "Weather Chum",
358
+ # published_at = 2025-05-14 05:32:00 UTC,
359
+ # screenshot_url = "https://trmnl.s3.us-east-2.amazonaws.com...",
360
+ # statistics = #<data TRMNL::API::Models::Recipes::Statistics:0x00011170
361
+ # forks = 1710,
362
+ # installs = 1
363
+ # >
364
+ # >
365
+ # ],
366
+ # meta = #<data TRMNL::API::Models::Recipes::Meta:0x00016e20
367
+ # current_page = 1,
368
+ # from = 1,
369
+ # next_page_url = "/recipes.json?page=2&sort_by=popularity",
370
+ # per_page = 25,
371
+ # prev_page_url = nil,
372
+ # to = 25,
373
+ # total = 678
374
+ # >
375
+ # >
379
376
  # )
380
377
  ----
381
378
 
382
- You'll always get a `data` array with may or may not be filled. Pagination information is listed at the bottom.
379
+ ⚠️ This _does not_ use the {trmnl_api_link} like every other endpoint documented here. Instead, you must customize the settings URI to point to the root of the TRMNL application (i.e. `https://usetrmnl.com`) instead of using the default API endpoint.
380
+
381
+ You'll always get a `data` array which may or may not be filled and `meta` (metadata) for handling pagination information. You can also combine the `page`, `search`, and `page` parameters as you see fit.
383
382
 
384
383
  ==== Setup
385
384
 
@@ -2,6 +2,7 @@
2
2
 
3
3
  require "inspectable"
4
4
  require "pipeable"
5
+ require "refinements/hash"
5
6
 
6
7
  module TRMNL
7
8
  module API
@@ -17,9 +18,13 @@ module TRMNL
17
18
  include Inspectable[contract: :type]
18
19
  include Pipeable
19
20
 
20
- def call(**)
21
+ using Refinements::Hash
22
+
23
+ def call(**parameters)
24
+ parameters.transform_keys! sort: "sort-by"
25
+
21
26
  pipe(
22
- requester.get("recipes.json", **),
27
+ requester.get("recipes.json", **parameters),
23
28
  try(:parse, catch: JSON::ParserError),
24
29
  validate(contract, as: :to_h),
25
30
  to(model, :for)
@@ -4,7 +4,7 @@ module TRMNL
4
4
  module API
5
5
  module Models
6
6
  # Models the data of the API response.
7
- CurrentScreen = Data.define :refresh_rate, :image_url, :filename do
7
+ CurrentScreen = ::Data.define :refresh_rate, :image_url, :filename do
8
8
  def self.for(attributes) = new(**attributes)
9
9
  end
10
10
  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
+ Firmware = ::Data.define :url, :version do
8
8
  def self.for(attributes) = new(**attributes)
9
9
  end
10
10
  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
- IPAddress = Data.define :version_4, :version_6 do
7
+ IPAddress = ::Data.define :version_4, :version_6 do
8
8
  def self.for attributes
9
9
  new(**attributes.transform_keys(ipv4: :version_4, ipv6: :version_6))
10
10
  end
@@ -3,20 +3,20 @@
3
3
  module TRMNL
4
4
  module API
5
5
  module Models
6
- # Models the data of the API response.
7
- Recipe = Data.define(
8
- :data,
9
- :total,
10
- :from,
11
- :to,
12
- :per_page,
13
- :current_page,
14
- :prev_page_url,
15
- :next_page_url
16
- ) do
6
+ # Models the payload of the API response.
7
+ Recipe = ::Data.define :data, :meta do
17
8
  def self.for(**attributes)
18
- data = attributes[:data].map { Recipes::Entry.for(**it) }
19
- new(**attributes.merge!(data:))
9
+ meta = attributes.slice :from,
10
+ :to,
11
+ :current_page,
12
+ :per_page,
13
+ :total,
14
+ :prev_page_url,
15
+ :next_page_url
16
+
17
+ data = attributes[:data].map { Recipes::Data.for(**it) }
18
+
19
+ new meta: Recipes::Meta[**meta], data:
20
20
  end
21
21
  end
22
22
  end
@@ -5,7 +5,7 @@ module TRMNL
5
5
  module Models
6
6
  module Recipes
7
7
  # Models the data of the API response.
8
- Entry = Struct.new(
8
+ Data = Struct.new(
9
9
  :id,
10
10
  :name,
11
11
  :icon_url,
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TRMNL
4
+ module API
5
+ module Models
6
+ module Recipes
7
+ # Models the metadata of the API response.
8
+ Meta = ::Data.define(
9
+ :from,
10
+ :to,
11
+ :current_page,
12
+ :per_page,
13
+ :total,
14
+ :prev_page_url,
15
+ :next_page_url
16
+ ) do
17
+ def initialize from: 0,
18
+ to: 0,
19
+ current_page: 0,
20
+ per_page: 0,
21
+ total: 0,
22
+ prev_page_url: nil,
23
+ next_page_url: nil
24
+ super
25
+ end
26
+
27
+ def more? = to.positive? && to < total
28
+
29
+ def next_page = current_page + 1
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -5,7 +5,7 @@ module TRMNL
5
5
  module Models
6
6
  module Recipes
7
7
  # Models the statistics of the API response.
8
- Statistics = Data.define :installs, :forks
8
+ Statistics = ::Data.define :installs, :forks
9
9
  end
10
10
  end
11
11
  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
- Setup = Data.define :api_key, :friendly_id, :image_url, :message do
7
+ Setup = ::Data.define :api_key, :friendly_id, :image_url, :message do
8
8
  def self.for(attributes) = new(**attributes)
9
9
  end
10
10
  end
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.9.0"
5
+ spec.version = "0.10.0"
6
6
  spec.authors = ["TRMNL"]
7
7
  spec.email = ["engineering@usetrmnl.com"]
8
8
  spec.homepage = "https://github.com/usetrmnl/trmnl-api"
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.9.0
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - TRMNL
@@ -222,7 +222,8 @@ files:
222
222
  - lib/trmnl/api/models/palette.rb
223
223
  - lib/trmnl/api/models/recipe.rb
224
224
  - lib/trmnl/api/models/recipes/author.rb
225
- - lib/trmnl/api/models/recipes/entry.rb
225
+ - lib/trmnl/api/models/recipes/data.rb
226
+ - lib/trmnl/api/models/recipes/meta.rb
226
227
  - lib/trmnl/api/models/recipes/statistics.rb
227
228
  - lib/trmnl/api/models/setup.rb
228
229
  - lib/trmnl/api/requester.rb
metadata.gz.sig CHANGED
Binary file