trmnl-api 0.8.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 +4 -4
- checksums.yaml.gz.sig +0 -0
- data/README.adoc +94 -13
- data/lib/trmnl/api/client.rb +38 -35
- data/lib/trmnl/api/container.rb +3 -1
- data/lib/trmnl/api/contracts/recipe.rb +36 -0
- data/lib/trmnl/api/contracts/recipes/author.rb +48 -0
- data/lib/trmnl/api/endpoints/container.rb +1 -0
- data/lib/trmnl/api/endpoints/recipe.rb +36 -0
- data/lib/trmnl/api/locale_reducer.rb +14 -0
- data/lib/trmnl/api/models/current_screen.rb +2 -2
- data/lib/trmnl/api/models/display.rb +1 -1
- data/lib/trmnl/api/models/firmware.rb +2 -2
- data/lib/trmnl/api/models/ip_address.rb +2 -2
- data/lib/trmnl/api/models/model.rb +1 -1
- data/lib/trmnl/api/models/palette.rb +2 -2
- data/lib/trmnl/api/models/recipe.rb +24 -0
- data/lib/trmnl/api/models/recipes/author.rb +28 -0
- data/lib/trmnl/api/models/recipes/data.rb +31 -0
- data/lib/trmnl/api/models/recipes/meta.rb +34 -0
- data/lib/trmnl/api/models/recipes/statistics.rb +12 -0
- data/lib/trmnl/api/models/setup.rb +2 -2
- data/lib/trmnl/api/requester.rb +7 -3
- data/trmnl-api.gemspec +1 -1
- data.tar.gz.sig +0 -0
- metadata +11 -2
- 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: 168b5086d30774ef88cc9d12ae187ffa4da349bfe10456c64a5e2fe7e94372a3
|
|
4
|
+
data.tar.gz: d7c785269f0ddf0238d399a352cef774c9081bb6706a238cf9ead6bcc413ff0e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4b6cdd52fa7cc10214220a4906298a1d2243d1da94f8854d1dd1eb67cdcd70a761655a717630bb561151e84c01b8926e7b9fac65e1cd84c9fb7590cddc164f7e
|
|
7
|
+
data.tar.gz: 732532ba60f51c994898d1a982f404ba0d38b419ccc2c6cc95b46548234c51e1b40eedeeda6b4047d81b46f03408b4fccaa8dc8bef3b85dbcef70c0a4a355576
|
checksums.yaml.gz.sig
CHANGED
|
Binary file
|
data/README.adoc
CHANGED
|
@@ -3,17 +3,18 @@
|
|
|
3
3
|
:figure-caption!:
|
|
4
4
|
|
|
5
5
|
:trmnl_link: link:https://usetrmnl.com[TRMNL]
|
|
6
|
+
:trmnl_api_link: link:https://usetrmnl.com/api-docs/index.html[TRMNL API]
|
|
6
7
|
:dry_monads_link: link:https://dry-rb.org/gems/dry-monads[Dry Monads]
|
|
7
8
|
|
|
8
9
|
= TRMNL API
|
|
9
10
|
|
|
10
|
-
A monadic {
|
|
11
|
+
A monadic {trmnl_api_link} client. You can use this client in your own code to interact with our APIs for any/all devices that you own.
|
|
11
12
|
|
|
12
13
|
toc::[]
|
|
13
14
|
|
|
14
15
|
== Features
|
|
15
16
|
|
|
16
|
-
* Provides {
|
|
17
|
+
* Provides {trmnl_api_link} access.
|
|
17
18
|
|
|
18
19
|
== Requirements
|
|
19
20
|
|
|
@@ -48,7 +49,7 @@ require "trmnl/api"
|
|
|
48
49
|
This client provides access to multiple endpoints. Each endpoint will answer either a `Success` or `Failure` (as provided by {dry_monads_link}) based on result of the API call. This allows you pattern match in your own code when using each endpoint. Example:
|
|
49
50
|
|
|
50
51
|
``` ruby
|
|
51
|
-
client = TRMNL::API
|
|
52
|
+
client = TRMNL::API.new
|
|
52
53
|
|
|
53
54
|
case client.display token: "secret"
|
|
54
55
|
in Success(payload) then puts payload
|
|
@@ -65,7 +66,7 @@ By default, you shouldn't need to change the default configuration but you can a
|
|
|
65
66
|
|
|
66
67
|
[source,ruby]
|
|
67
68
|
----
|
|
68
|
-
client = TRMNL::API
|
|
69
|
+
client = TRMNL::API.new do |settings|
|
|
69
70
|
settings.content_type = "application/json",
|
|
70
71
|
settings.uri = "https://trmnl.app/api"
|
|
71
72
|
end
|
|
@@ -88,7 +89,7 @@ Allows you to obtain the list of approved plugin categories. Example:
|
|
|
88
89
|
|
|
89
90
|
[source,ruby]
|
|
90
91
|
----
|
|
91
|
-
client = TRMNL::API
|
|
92
|
+
client = TRMNL::API.new
|
|
92
93
|
client.categories
|
|
93
94
|
|
|
94
95
|
# Success(
|
|
@@ -106,7 +107,7 @@ Allows you to obtain current screen being displayed for your device. You must su
|
|
|
106
107
|
|
|
107
108
|
[source,ruby]
|
|
108
109
|
----
|
|
109
|
-
client = TRMNL::API
|
|
110
|
+
client = TRMNL::API.new
|
|
110
111
|
client.current_screen token: "secret"
|
|
111
112
|
|
|
112
113
|
# Success(
|
|
@@ -124,7 +125,7 @@ Allows you to obtain current screen being displayed for your device with additio
|
|
|
124
125
|
|
|
125
126
|
[source,ruby]
|
|
126
127
|
----
|
|
127
|
-
client = TRMNL::API
|
|
128
|
+
client = TRMNL::API.new
|
|
128
129
|
client.display token: "secret"
|
|
129
130
|
|
|
130
131
|
# Success(
|
|
@@ -147,7 +148,7 @@ Allows you to obtain the current stable firmware version. Example:
|
|
|
147
148
|
|
|
148
149
|
[source,ruby]
|
|
149
150
|
----
|
|
150
|
-
client = TRMNL::API
|
|
151
|
+
client = TRMNL::API.new
|
|
151
152
|
client.firmware
|
|
152
153
|
|
|
153
154
|
# Success(#<data TRMNL::API::Models::Firmware url="https://trmnl-fw.s3.us-east-2.amazonaws.com/FW1.4.8.bin", version="1.4.8">)
|
|
@@ -159,7 +160,7 @@ Allows you obtain a list of public IP addresses for all TRMNL core servers becau
|
|
|
159
160
|
|
|
160
161
|
[source,ruby]
|
|
161
162
|
----
|
|
162
|
-
client = TRMNL::API
|
|
163
|
+
client = TRMNL::API.new
|
|
163
164
|
client.ip_addresses
|
|
164
165
|
|
|
165
166
|
# Success(
|
|
@@ -182,7 +183,7 @@ Allows you to create a log entry (which is what the device reports when it captu
|
|
|
182
183
|
|
|
183
184
|
[source,ruby]
|
|
184
185
|
----
|
|
185
|
-
client = TRMNL::API
|
|
186
|
+
client = TRMNL::API.new
|
|
186
187
|
client.log token: "secret",
|
|
187
188
|
log: {
|
|
188
189
|
logs_array: [
|
|
@@ -221,7 +222,7 @@ Allows you to obtain the model information for all devices and screens. Example:
|
|
|
221
222
|
|
|
222
223
|
[source,ruby]
|
|
223
224
|
----
|
|
224
|
-
client = TRMNL::API
|
|
225
|
+
client = TRMNL::API.new
|
|
225
226
|
client.models
|
|
226
227
|
|
|
227
228
|
# Success(
|
|
@@ -276,7 +277,7 @@ Allows you to obtain palettes details. The IDs correlate to the `palette_ids` as
|
|
|
276
277
|
|
|
277
278
|
[source,ruby]
|
|
278
279
|
----
|
|
279
|
-
client = TRMNL::API
|
|
280
|
+
client = TRMNL::API.new
|
|
280
281
|
client.palettes
|
|
281
282
|
|
|
282
283
|
Success(
|
|
@@ -299,13 +300,93 @@ Success(
|
|
|
299
300
|
)
|
|
300
301
|
----
|
|
301
302
|
|
|
303
|
+
==== Recipes
|
|
304
|
+
|
|
305
|
+
Allows you to obtain information about link:https://usetrmnl.com/recipes[Recipes]. Example:
|
|
306
|
+
|
|
307
|
+
[source,ruby]
|
|
308
|
+
----
|
|
309
|
+
client = TRMNL::API.new { |settings| settings.uri = "https://usetrmnl.com" }
|
|
310
|
+
|
|
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.
|
|
315
|
+
|
|
316
|
+
# Success(
|
|
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
|
+
# >
|
|
376
|
+
# )
|
|
377
|
+
----
|
|
378
|
+
|
|
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.
|
|
382
|
+
|
|
302
383
|
==== Setup
|
|
303
384
|
|
|
304
385
|
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:
|
|
305
386
|
|
|
306
387
|
[source,ruby]
|
|
307
388
|
----
|
|
308
|
-
client = TRMNL::API
|
|
389
|
+
client = TRMNL::API.new
|
|
309
390
|
client.setup id: "A1:B2:C3:D4:E5:F6"
|
|
310
391
|
|
|
311
392
|
# Success(
|
data/lib/trmnl/api/client.rb
CHANGED
|
@@ -7,53 +7,56 @@ module TRMNL
|
|
|
7
7
|
# Provides the primary client for making API requests.
|
|
8
8
|
class Client
|
|
9
9
|
include Dependencies[:settings]
|
|
10
|
+
include Inspectable[:endpoints]
|
|
11
|
+
|
|
12
|
+
ENDPOINTS = {
|
|
13
|
+
categories: Endpoints::Category,
|
|
14
|
+
current_screen: Endpoints::CurrentScreen,
|
|
15
|
+
display: Endpoints::Display,
|
|
16
|
+
firmware: Endpoints::Firmware,
|
|
17
|
+
ip_addresses: Endpoints::IPAddress,
|
|
18
|
+
log: Endpoints::Log,
|
|
19
|
+
models: Endpoints::Model,
|
|
20
|
+
palettes: Endpoints::Palette,
|
|
21
|
+
recipes: Endpoints::Recipe,
|
|
22
|
+
setup: Endpoints::Setup
|
|
23
|
+
}.freeze
|
|
24
|
+
|
|
25
|
+
def initialize(requester: Requester, endpoints: ENDPOINTS, **)
|
|
26
|
+
super(**)
|
|
10
27
|
|
|
11
|
-
include Endpoints::Dependencies[
|
|
12
|
-
endpoint_categories: :categories,
|
|
13
|
-
endpoint_current_screen: :current_screen,
|
|
14
|
-
endpoint_display: :display,
|
|
15
|
-
endpoint_firmware: :firmware,
|
|
16
|
-
endpoint_ip_addresses: :ip_addresses,
|
|
17
|
-
endpoint_log: :log,
|
|
18
|
-
endpoint_models: :models,
|
|
19
|
-
endpoint_palettes: :palettes,
|
|
20
|
-
endpoint_setup: :setup
|
|
21
|
-
]
|
|
22
|
-
|
|
23
|
-
include Inspectable[
|
|
24
|
-
endpoint_categories: :type,
|
|
25
|
-
endpoint_current_screen: :type,
|
|
26
|
-
endpoint_display: :type,
|
|
27
|
-
endpoint_firmware: :type,
|
|
28
|
-
endpoint_ip_addresses: :type,
|
|
29
|
-
endpoint_log: :type,
|
|
30
|
-
endpoint_models: :type,
|
|
31
|
-
endpoint_palettes: :type,
|
|
32
|
-
endpoint_setup: :type
|
|
33
|
-
]
|
|
34
|
-
|
|
35
|
-
def initialize(**)
|
|
36
|
-
super
|
|
37
28
|
yield settings if block_given?
|
|
29
|
+
|
|
30
|
+
requester = requester.new(settings:)
|
|
31
|
+
|
|
32
|
+
@endpoints = endpoints.each.with_object({}) do |(key, value), all|
|
|
33
|
+
all[key] = value.new requester:
|
|
34
|
+
end
|
|
38
35
|
end
|
|
39
36
|
|
|
40
|
-
def categories =
|
|
37
|
+
def categories = endpoints.fetch(__method__).call
|
|
38
|
+
|
|
39
|
+
def current_screen(**) = endpoints.fetch(__method__).call(**)
|
|
40
|
+
|
|
41
|
+
def display(**) = endpoints.fetch(__method__).call(**)
|
|
42
|
+
|
|
43
|
+
def firmware = endpoints.fetch(__method__).call
|
|
41
44
|
|
|
42
|
-
def
|
|
45
|
+
def ip_addresses = endpoints.fetch(__method__).call
|
|
43
46
|
|
|
44
|
-
def
|
|
47
|
+
def log(**) = endpoints.fetch(__method__).call(**)
|
|
45
48
|
|
|
46
|
-
def
|
|
49
|
+
def models(**) = endpoints.fetch(__method__).call(**)
|
|
47
50
|
|
|
48
|
-
def
|
|
51
|
+
def palettes = endpoints.fetch(__method__).call
|
|
49
52
|
|
|
50
|
-
def
|
|
53
|
+
def recipes(**) = endpoints.fetch(__method__).call(**)
|
|
51
54
|
|
|
52
|
-
def
|
|
55
|
+
def setup(**) = endpoints.fetch(__method__).call(**)
|
|
53
56
|
|
|
54
|
-
|
|
57
|
+
private
|
|
55
58
|
|
|
56
|
-
|
|
59
|
+
attr_reader :endpoints
|
|
57
60
|
end
|
|
58
61
|
end
|
|
59
62
|
end
|
data/lib/trmnl/api/container.rb
CHANGED
|
@@ -10,7 +10,7 @@ module TRMNL
|
|
|
10
10
|
module Container
|
|
11
11
|
extend Containable
|
|
12
12
|
|
|
13
|
-
register(:settings) { TRMNL::API::Configuration::Loader.new.call }
|
|
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
|
|
|
@@ -27,6 +27,7 @@ module TRMNL
|
|
|
27
27
|
register :ip_address, Contracts::IPAddress
|
|
28
28
|
register :model, Contracts::Model
|
|
29
29
|
register :palette, Contracts::Palette
|
|
30
|
+
register :recipe, Contracts::Recipe
|
|
30
31
|
register :setup, Contracts::Setup
|
|
31
32
|
end
|
|
32
33
|
|
|
@@ -37,6 +38,7 @@ module TRMNL
|
|
|
37
38
|
register :ip_address, Models::IPAddress
|
|
38
39
|
register :model, Models::Model
|
|
39
40
|
register :palette, Models::Palette
|
|
41
|
+
register :recipe, Models::Recipe
|
|
40
42
|
register :setup, Models::Setup
|
|
41
43
|
end
|
|
42
44
|
end
|
|
@@ -0,0 +1,36 @@
|
|
|
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
|
+
Recipe = Dry::Schema.JSON do
|
|
10
|
+
required(:data).array(:hash) do
|
|
11
|
+
required(:id).filled :integer
|
|
12
|
+
required(:name).filled :string
|
|
13
|
+
required(:screenshot_url).filled :string
|
|
14
|
+
required(:published_at).filled :time
|
|
15
|
+
optional(:icon_url).maybe :string
|
|
16
|
+
optional(:icon_content_type).maybe :string
|
|
17
|
+
required(:author_bio).maybe Recipes::Author
|
|
18
|
+
required(:custom_fields).array(:hash)
|
|
19
|
+
|
|
20
|
+
required(:stats).filled :hash do
|
|
21
|
+
required(:installs).filled :integer
|
|
22
|
+
required(:forks).filled :integer
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
required(:total).filled :integer
|
|
27
|
+
required(:from).filled :integer
|
|
28
|
+
required(:to).filled :integer
|
|
29
|
+
required(:per_page).filled :integer
|
|
30
|
+
required(:current_page).filled :integer
|
|
31
|
+
required(:prev_page_url).maybe :string
|
|
32
|
+
required(:next_page_url).maybe :string
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "dry/schema"
|
|
4
|
+
|
|
5
|
+
module TRMNL
|
|
6
|
+
module API
|
|
7
|
+
module Contracts
|
|
8
|
+
module Recipes
|
|
9
|
+
# Validates API response.
|
|
10
|
+
Author = Dry::Schema.JSON do
|
|
11
|
+
required(:keyname).filled :string
|
|
12
|
+
required(:name).filled :string
|
|
13
|
+
required(:field_type).filled :string
|
|
14
|
+
optional(:category).filled :string
|
|
15
|
+
optional(:description).filled :string
|
|
16
|
+
optional(:"description-de").filled :string
|
|
17
|
+
optional(:"description-nl").filled :string
|
|
18
|
+
optional(:"description-fr").filled :string
|
|
19
|
+
optional(:"description-en").filled :string
|
|
20
|
+
optional(:"description-en-GB").filled :string
|
|
21
|
+
optional(:"description-es-ES").filled :string
|
|
22
|
+
optional(:"description-it").filled :string
|
|
23
|
+
optional(:"description-no").filled :string
|
|
24
|
+
optional(:"description-da").filled :string
|
|
25
|
+
optional(:"description-ja").filled :string
|
|
26
|
+
optional(:"description-de-AT").filled :string
|
|
27
|
+
optional(:"description-ko").filled :string
|
|
28
|
+
optional(:"description-sv").filled :string
|
|
29
|
+
optional(:"description-pt-BR").filled :string
|
|
30
|
+
optional(:"description-zh-HK").filled :string
|
|
31
|
+
optional(:"description-pl").filled :string
|
|
32
|
+
optional(:"description-uk").filled :string
|
|
33
|
+
optional(:"description-zh-CN").filled :string
|
|
34
|
+
optional(:"description-hu").filled :string
|
|
35
|
+
optional(:"description-he").filled :string
|
|
36
|
+
optional(:"description-sk").filled :string
|
|
37
|
+
optional(:"description-ru").filled :string
|
|
38
|
+
optional(:"description-is").filled :string
|
|
39
|
+
optional(:"description-id").filled :string
|
|
40
|
+
optional(:email_address).filled :string
|
|
41
|
+
optional(:learn_more_url).filled :string
|
|
42
|
+
optional(:github_url).filled :string
|
|
43
|
+
optional(:youtube_url).filled :string
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "inspectable"
|
|
4
|
+
require "pipeable"
|
|
5
|
+
require "refinements/hash"
|
|
6
|
+
|
|
7
|
+
module TRMNL
|
|
8
|
+
module API
|
|
9
|
+
module Endpoints
|
|
10
|
+
# Handles API request/response.
|
|
11
|
+
class Recipe
|
|
12
|
+
include TRMNL::API::Dependencies[
|
|
13
|
+
:requester,
|
|
14
|
+
contract: "contracts.recipe",
|
|
15
|
+
model: "models.recipe"
|
|
16
|
+
]
|
|
17
|
+
|
|
18
|
+
include Inspectable[contract: :type]
|
|
19
|
+
include Pipeable
|
|
20
|
+
|
|
21
|
+
using Refinements::Hash
|
|
22
|
+
|
|
23
|
+
def call(**parameters)
|
|
24
|
+
parameters.transform_keys! sort: "sort-by"
|
|
25
|
+
|
|
26
|
+
pipe(
|
|
27
|
+
requester.get("recipes.json", **parameters),
|
|
28
|
+
try(:parse, catch: JSON::ParserError),
|
|
29
|
+
validate(contract, as: :to_h),
|
|
30
|
+
to(model, :for)
|
|
31
|
+
)
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module TRMNL
|
|
4
|
+
module API
|
|
5
|
+
LocaleReducer = lambda do |attributes, prefix: "description-"|
|
|
6
|
+
attributes.each.with_object({}) do |(key, value), all|
|
|
7
|
+
next unless key.start_with? prefix
|
|
8
|
+
|
|
9
|
+
attributes.delete key
|
|
10
|
+
all[key.to_s.delete_prefix(prefix)] = value
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
module TRMNL
|
|
4
4
|
module API
|
|
5
5
|
module Models
|
|
6
|
-
# Models API response.
|
|
7
|
-
CurrentScreen = Data.define :refresh_rate, :image_url, :filename do
|
|
6
|
+
# Models the data of the API response.
|
|
7
|
+
CurrentScreen = ::Data.define :refresh_rate, :image_url, :filename do
|
|
8
8
|
def self.for(attributes) = new(**attributes)
|
|
9
9
|
end
|
|
10
10
|
end
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
module TRMNL
|
|
4
4
|
module API
|
|
5
5
|
module Models
|
|
6
|
-
#
|
|
7
|
-
IPAddress = Data.define :version_4, :version_6 do
|
|
6
|
+
# Models the data of the API response.
|
|
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,8 +3,8 @@
|
|
|
3
3
|
module TRMNL
|
|
4
4
|
module API
|
|
5
5
|
module Models
|
|
6
|
-
#
|
|
7
|
-
Palette =
|
|
6
|
+
# Models the data of the API response.
|
|
7
|
+
Palette = Struct.new :id, :name, :grays, :colors, :framework_class do
|
|
8
8
|
def self.for(attributes) = new(**attributes)
|
|
9
9
|
end
|
|
10
10
|
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module TRMNL
|
|
4
|
+
module API
|
|
5
|
+
module Models
|
|
6
|
+
# Models the payload of the API response.
|
|
7
|
+
Recipe = ::Data.define :data, :meta do
|
|
8
|
+
def self.for(**attributes)
|
|
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
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module TRMNL
|
|
4
|
+
module API
|
|
5
|
+
module Models
|
|
6
|
+
module Recipes
|
|
7
|
+
# Models the author of the API response.
|
|
8
|
+
Author = Struct.new(
|
|
9
|
+
:keyname,
|
|
10
|
+
:name,
|
|
11
|
+
:field_type,
|
|
12
|
+
:category,
|
|
13
|
+
:description,
|
|
14
|
+
:description_locales,
|
|
15
|
+
:email_address,
|
|
16
|
+
:learn_more_url,
|
|
17
|
+
:github_url,
|
|
18
|
+
:youtube_url
|
|
19
|
+
) do
|
|
20
|
+
def self.for(locale_reducer: LocaleReducer, **attributes)
|
|
21
|
+
description_locales = locale_reducer.call attributes
|
|
22
|
+
new(description_locales:, **attributes)
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module TRMNL
|
|
4
|
+
module API
|
|
5
|
+
module Models
|
|
6
|
+
module Recipes
|
|
7
|
+
# Models the data of the API response.
|
|
8
|
+
Data = Struct.new(
|
|
9
|
+
:id,
|
|
10
|
+
:name,
|
|
11
|
+
:icon_url,
|
|
12
|
+
:icon_content_type,
|
|
13
|
+
:screenshot_url,
|
|
14
|
+
:author,
|
|
15
|
+
:custom_fields,
|
|
16
|
+
:statistics,
|
|
17
|
+
:published_at
|
|
18
|
+
) do
|
|
19
|
+
def self.for(**attributes)
|
|
20
|
+
new(
|
|
21
|
+
**attributes.merge!(
|
|
22
|
+
author: Author.for(**attributes.delete(:author_bio)),
|
|
23
|
+
statistics: Statistics[**attributes.delete(:stats)]
|
|
24
|
+
)
|
|
25
|
+
)
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -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
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
module TRMNL
|
|
4
4
|
module API
|
|
5
5
|
module Models
|
|
6
|
-
# Models API response.
|
|
7
|
-
Setup = Data.define :api_key, :friendly_id, :image_url, :message do
|
|
6
|
+
# Models the data of the API response.
|
|
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/lib/trmnl/api/requester.rb
CHANGED
|
@@ -23,18 +23,20 @@ module TRMNL
|
|
|
23
23
|
|
|
24
24
|
private
|
|
25
25
|
|
|
26
|
-
attr_reader :settings, :http
|
|
27
|
-
|
|
28
26
|
def call method, path, headers, **options
|
|
29
27
|
http.headers(settings.headers.merge(headers))
|
|
30
28
|
.public_send(method, uri(path), options)
|
|
31
29
|
.then { |response| response.status.success? ? Success(response) : Failure(response) }
|
|
30
|
+
rescue HTTP::RequestError => error then handle_bad_request path, error
|
|
32
31
|
rescue HTTP::ConnectionError => error then handle_bad_connection path, error
|
|
33
32
|
rescue HTTP::TimeoutError => error then handle_timeout path, error
|
|
34
33
|
rescue OpenSSL::SSL::SSLError => error then handle_bad_ssl path, error
|
|
35
34
|
end
|
|
36
35
|
|
|
37
|
-
def
|
|
36
|
+
def handle_bad_request path, error
|
|
37
|
+
logger.debug { error.message }
|
|
38
|
+
Failure "Unable to make request: #{uri(path).inspect}. Is the URI valid?"
|
|
39
|
+
end
|
|
38
40
|
|
|
39
41
|
def handle_bad_connection path, error
|
|
40
42
|
logger.debug { error.message }
|
|
@@ -51,6 +53,8 @@ module TRMNL
|
|
|
51
53
|
Failure "Unable to secure connection: #{uri(path).inspect}. " \
|
|
52
54
|
"Is your certificate or SSL valid?"
|
|
53
55
|
end
|
|
56
|
+
|
|
57
|
+
def uri(path) = "#{settings.uri}/#{path}"
|
|
54
58
|
end
|
|
55
59
|
end
|
|
56
60
|
end
|
data/trmnl-api.gemspec
CHANGED
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.10.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- TRMNL
|
|
@@ -197,6 +197,8 @@ files:
|
|
|
197
197
|
- lib/trmnl/api/contracts/ip_address.rb
|
|
198
198
|
- lib/trmnl/api/contracts/model.rb
|
|
199
199
|
- lib/trmnl/api/contracts/palette.rb
|
|
200
|
+
- lib/trmnl/api/contracts/recipe.rb
|
|
201
|
+
- lib/trmnl/api/contracts/recipes/author.rb
|
|
200
202
|
- lib/trmnl/api/contracts/setup.rb
|
|
201
203
|
- lib/trmnl/api/dependencies.rb
|
|
202
204
|
- lib/trmnl/api/endpoints/category.rb
|
|
@@ -209,13 +211,20 @@ files:
|
|
|
209
211
|
- lib/trmnl/api/endpoints/log.rb
|
|
210
212
|
- lib/trmnl/api/endpoints/model.rb
|
|
211
213
|
- lib/trmnl/api/endpoints/palette.rb
|
|
214
|
+
- lib/trmnl/api/endpoints/recipe.rb
|
|
212
215
|
- lib/trmnl/api/endpoints/setup.rb
|
|
216
|
+
- lib/trmnl/api/locale_reducer.rb
|
|
213
217
|
- lib/trmnl/api/models/current_screen.rb
|
|
214
218
|
- lib/trmnl/api/models/display.rb
|
|
215
219
|
- lib/trmnl/api/models/firmware.rb
|
|
216
220
|
- lib/trmnl/api/models/ip_address.rb
|
|
217
221
|
- lib/trmnl/api/models/model.rb
|
|
218
222
|
- lib/trmnl/api/models/palette.rb
|
|
223
|
+
- lib/trmnl/api/models/recipe.rb
|
|
224
|
+
- lib/trmnl/api/models/recipes/author.rb
|
|
225
|
+
- lib/trmnl/api/models/recipes/data.rb
|
|
226
|
+
- lib/trmnl/api/models/recipes/meta.rb
|
|
227
|
+
- lib/trmnl/api/models/recipes/statistics.rb
|
|
219
228
|
- lib/trmnl/api/models/setup.rb
|
|
220
229
|
- lib/trmnl/api/requester.rb
|
|
221
230
|
- lib/trmnl/api/types.rb
|
|
@@ -244,7 +253,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
244
253
|
- !ruby/object:Gem::Version
|
|
245
254
|
version: '0'
|
|
246
255
|
requirements: []
|
|
247
|
-
rubygems_version: 4.0.
|
|
256
|
+
rubygems_version: 4.0.4
|
|
248
257
|
specification_version: 4
|
|
249
258
|
summary: A monadic TRMNL API client.
|
|
250
259
|
test_files: []
|
metadata.gz.sig
CHANGED
|
Binary file
|