trmnl-api 0.0.0 → 0.1.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 +63 -48
- data/lib/trmnl/api/client.rb +18 -24
- data/lib/trmnl/api/container.rb +3 -2
- data/lib/trmnl/api/endpoints/container.rb +20 -0
- data/lib/trmnl/api/endpoints/current_screen.rb +3 -3
- data/lib/trmnl/api/endpoints/dependencies.rb +11 -0
- data/lib/trmnl/api/endpoints/display.rb +7 -2
- data/lib/trmnl/api/endpoints/firmware.rb +7 -2
- data/lib/trmnl/api/endpoints/log.rb +2 -2
- data/lib/trmnl/api/endpoints/setup.rb +7 -2
- data/lib/trmnl/api/requester.rb +38 -0
- data/lib/trmnl/api.rb +2 -0
- data/trmnl-api.gemspec +1 -1
- data.tar.gz.sig +0 -0
- metadata +4 -1
- 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: f8a754ac699d2142cb950f2bc7739616181a33f085c99b244856f9115f823b6e
|
4
|
+
data.tar.gz: 8a221272e414bed3c1c25a8517c91bbce9286655c51057d9487077abdad22d6c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fadb0d344109f6a8ae6b84f411ee7f7363c708daa823a68c5adcd875871dc41928526505241587fa3218a48ece69acc2142d787245c2ce41a28e0cb30e3d28b5
|
7
|
+
data.tar.gz: 3ae4afaab60d62d8a1d8e6d776175031915cea50f237af2a025686c769a02651bc9137e2e3ffd4aa95bc24c925bc2f18b6a04161e33c1b8a683c1b7adb2467c4
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/README.adoc
CHANGED
@@ -48,14 +48,28 @@ require "trmnl/api"
|
|
48
48
|
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
49
|
|
50
50
|
``` ruby
|
51
|
-
|
51
|
+
client = TRMNL::API::Client.new
|
52
|
+
|
53
|
+
case client.display token: "secret"
|
52
54
|
in Success(payload) then puts payload
|
53
55
|
in Failure(response) then puts response
|
54
|
-
else puts "Unknown
|
56
|
+
else puts "Unknown response."
|
55
57
|
end
|
56
58
|
```
|
57
59
|
|
58
|
-
See
|
60
|
+
See xref:_endpoints[Endpoints] for further details.
|
61
|
+
|
62
|
+
=== Configuration
|
63
|
+
|
64
|
+
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
|
+
|
66
|
+
[source,ruby]
|
67
|
+
----
|
68
|
+
client = TRMNL::API::Client.new do |settings|
|
69
|
+
settings.content_type = "application/json",
|
70
|
+
settings.uri = "https://trmnl.app/api"
|
71
|
+
end
|
72
|
+
----
|
59
73
|
|
60
74
|
=== Environment
|
61
75
|
|
@@ -64,16 +78,18 @@ You can configure the client via the following environment variables:
|
|
64
78
|
* `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".
|
65
79
|
* `TRMNL_API_URI`: Defines the API URI. Default: "https://trmnl.app/api".
|
66
80
|
|
67
|
-
Any/all environment changes will be applied
|
81
|
+
Any/all environment changes will be applied unless you override these settings via the client configuration block shown above.
|
82
|
+
|
83
|
+
=== Endpoints
|
68
84
|
|
69
|
-
|
85
|
+
==== Current Screen
|
70
86
|
|
71
87
|
Allows you to obtain current screen being displayed for your device. You must supply your device's API token as the `token`. Example:
|
72
88
|
|
73
89
|
[source,ruby]
|
74
90
|
----
|
75
|
-
|
76
|
-
|
91
|
+
client = TRMNL::API::Client.new
|
92
|
+
client.current_screen token: "secret"
|
77
93
|
|
78
94
|
# Success(
|
79
95
|
# #<data TRMNL::API::Models::CurrentScreen
|
@@ -84,14 +100,14 @@ endpoint.call token: "secret"
|
|
84
100
|
# )
|
85
101
|
----
|
86
102
|
|
87
|
-
|
103
|
+
==== Display
|
88
104
|
|
89
|
-
Allows you to obtain current screen being displayed for your device. You must supply your device's API token as the `token`. Example:
|
105
|
+
Allows you to obtain current screen being displayed for your device with additional information not provided by the xref:_current_screen[Current Screen] endpoint. You must supply your device's API token as the `token`. Example:
|
90
106
|
|
91
107
|
[source,ruby]
|
92
108
|
----
|
93
|
-
|
94
|
-
|
109
|
+
client = TRMNL::API::Client.new
|
110
|
+
client.display token: "secret"
|
95
111
|
|
96
112
|
# Success(
|
97
113
|
# #<struct TRMNL::API::Models::Display
|
@@ -107,73 +123,72 @@ endpoint.call token: "secret"
|
|
107
123
|
# )
|
108
124
|
----
|
109
125
|
|
110
|
-
|
126
|
+
==== Firmware
|
111
127
|
|
112
128
|
Allows you to obtain the current stable firmware version. Example:
|
113
129
|
|
114
130
|
[source,ruby]
|
115
131
|
----
|
116
|
-
|
117
|
-
|
132
|
+
client = TRMNL::API::Client.new
|
133
|
+
client.call
|
118
134
|
|
119
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">)
|
120
136
|
----
|
121
137
|
|
122
|
-
|
138
|
+
==== Log
|
123
139
|
|
124
140
|
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:
|
125
141
|
|
126
142
|
[source,ruby]
|
127
143
|
----
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
144
|
+
client = TRMNL::API::Client.new
|
145
|
+
client.call token: "secret",
|
146
|
+
log: {
|
147
|
+
logs_array: [
|
148
|
+
{
|
149
|
+
log_id: 1,
|
150
|
+
creation_timestamp: 1742022124,
|
151
|
+
log_message: "returned code is not OK: 404",
|
152
|
+
log_codeline: 597,
|
153
|
+
device_status_stamp: {
|
154
|
+
wifi_status: "connected",
|
155
|
+
wakeup_reason: "timer",
|
156
|
+
current_fw_version: "1.4.7",
|
157
|
+
free_heap_size: 160656,
|
158
|
+
special_function: "none",
|
159
|
+
refresh_rate: 30,
|
160
|
+
battery_voltage: 4.772,
|
161
|
+
time_since_last_sleep_start: 31,
|
162
|
+
wifi_rssi_level: -54
|
163
|
+
},
|
164
|
+
additional_info: {
|
165
|
+
retry_attempt: 1
|
166
|
+
},
|
167
|
+
log_sourcefile: "src/bl.cpp"
|
168
|
+
}
|
169
|
+
]
|
170
|
+
}
|
155
171
|
|
156
172
|
# Success(#<HTTP::Response/1.1 204 No Content...)
|
157
173
|
----
|
158
174
|
|
159
175
|
You'll either get a 204 No Content or 200 OK response depending on if the device exists or not.
|
160
176
|
|
161
|
-
|
177
|
+
==== Setup
|
162
178
|
|
163
179
|
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:
|
164
180
|
|
165
|
-
|
166
181
|
[source,ruby]
|
167
182
|
----
|
168
|
-
|
169
|
-
|
183
|
+
client = TRMNL::API::Client.new
|
184
|
+
client.call id: "A1:B2:C3:D4:E5:F6"
|
170
185
|
|
171
186
|
# Success(
|
172
187
|
# #<data TRMNL::API::Models::Setup
|
173
188
|
# api_key="secret",
|
174
|
-
# friendly_id="
|
189
|
+
# friendly_id="F51FDE",
|
175
190
|
# image_url="https://usetrmnl.com/images/setup/setup-logo.bmp",
|
176
|
-
# message="Register at usetrmnl.com/signup with Device ID '
|
191
|
+
# message="Register at usetrmnl.com/signup with Device ID 'F51FDE'"
|
177
192
|
# >
|
178
193
|
# )
|
179
194
|
----
|
data/lib/trmnl/api/client.rb
CHANGED
@@ -1,39 +1,33 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "dry/monads"
|
4
|
-
require "http"
|
5
|
-
|
6
3
|
module TRMNL
|
7
4
|
module API
|
8
|
-
# Provides
|
9
|
-
# :reek:DataClump
|
5
|
+
# Provides the primary client for making API requests.
|
10
6
|
class Client
|
11
|
-
include
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
7
|
+
include Dependencies[:settings]
|
8
|
+
|
9
|
+
include Endpoints::Dependencies[
|
10
|
+
endpoint_current_screen: :current_screen,
|
11
|
+
endpoint_display: :display,
|
12
|
+
endpoint_firmware: :firmware,
|
13
|
+
endpoint_log: :log,
|
14
|
+
endpoint_setup: :setup
|
15
|
+
]
|
16
|
+
|
17
|
+
def initialize(**)
|
18
|
+
super
|
19
19
|
yield settings if block_given?
|
20
20
|
end
|
21
21
|
|
22
|
-
def
|
22
|
+
def current_screen(**) = endpoint_current_screen.call(**)
|
23
23
|
|
24
|
-
def
|
24
|
+
def display(**) = endpoint_display.call(**)
|
25
25
|
|
26
|
-
|
26
|
+
def firmware = endpoint_firmware.call
|
27
27
|
|
28
|
-
|
28
|
+
def log(**) = endpoint_log.call(**)
|
29
29
|
|
30
|
-
|
31
|
-
def call method, path, headers, **options
|
32
|
-
http.headers(settings.headers.merge(headers))
|
33
|
-
.public_send(method, "#{settings.uri}/#{path}", options)
|
34
|
-
.then { |response| response.status.success? ? Success(response) : Failure(response) }
|
35
|
-
end
|
36
|
-
# rubocop:enable Metrics/ParameterLists
|
30
|
+
def setup(**) = endpoint_setup.call(**)
|
37
31
|
end
|
38
32
|
end
|
39
33
|
end
|
data/lib/trmnl/api/container.rb
CHANGED
@@ -10,11 +10,12 @@ module TRMNL
|
|
10
10
|
module Container
|
11
11
|
extend Containable
|
12
12
|
|
13
|
-
register(:
|
13
|
+
register(:settings) { TRMNL::API::Configuration::Loader.new.call }
|
14
|
+
register(:requester) { API::Requester.new }
|
14
15
|
register(:logger) { Cogger.new id: "trmnl-api", formatter: :json }
|
15
16
|
|
16
17
|
register :http do
|
17
|
-
HTTP.default_options =
|
18
|
+
HTTP.default_options = HTTP::Options.new features: {logging: {logger: self[:logger]}}
|
18
19
|
HTTP
|
19
20
|
end
|
20
21
|
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "containable"
|
4
|
+
|
5
|
+
module TRMNL
|
6
|
+
module API
|
7
|
+
module Endpoints
|
8
|
+
# Registers all endpoints.
|
9
|
+
module Container
|
10
|
+
extend Containable
|
11
|
+
|
12
|
+
register(:current_screen) { CurrentScreen.new }
|
13
|
+
register(:display) { Display.new }
|
14
|
+
register(:firmware) { Firmware.new }
|
15
|
+
register(:log) { Log.new }
|
16
|
+
register(:setup) { Setup.new }
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -7,8 +7,8 @@ module TRMNL
|
|
7
7
|
module Endpoints
|
8
8
|
# Handles API request/response.
|
9
9
|
class CurrentScreen
|
10
|
-
include Dependencies[
|
11
|
-
:
|
10
|
+
include TRMNL::API::Dependencies[
|
11
|
+
:requester,
|
12
12
|
contract: "contracts.current_screen",
|
13
13
|
model: "models.current_screen"
|
14
14
|
]
|
@@ -16,7 +16,7 @@ module TRMNL
|
|
16
16
|
include Pipeable
|
17
17
|
|
18
18
|
def call token:
|
19
|
-
pipe
|
19
|
+
pipe requester.get("current_screen", headers: {"Access-Token" => token}),
|
20
20
|
try(:parse, catch: JSON::ParserError),
|
21
21
|
validate(contract, as: :to_h),
|
22
22
|
to(model, :for)
|
@@ -7,11 +7,16 @@ module TRMNL
|
|
7
7
|
module Endpoints
|
8
8
|
# Handles API request/response.
|
9
9
|
class Display
|
10
|
-
include Dependencies[
|
10
|
+
include TRMNL::API::Dependencies[
|
11
|
+
:requester,
|
12
|
+
contract: "contracts.display",
|
13
|
+
model: "models.display"
|
14
|
+
]
|
15
|
+
|
11
16
|
include Pipeable
|
12
17
|
|
13
18
|
def call token:
|
14
|
-
pipe
|
19
|
+
pipe requester.get("display", headers: {"Access-Token" => token}),
|
15
20
|
try(:parse, catch: JSON::ParserError),
|
16
21
|
validate(contract, as: :to_h),
|
17
22
|
to(model, :for)
|
@@ -7,11 +7,16 @@ module TRMNL
|
|
7
7
|
module Endpoints
|
8
8
|
# Handles API request/response.
|
9
9
|
class Firmware
|
10
|
-
include Dependencies[
|
10
|
+
include TRMNL::API::Dependencies[
|
11
|
+
:requester,
|
12
|
+
contract: "contracts.firmware",
|
13
|
+
model: "models.firmware"
|
14
|
+
]
|
15
|
+
|
11
16
|
include Pipeable
|
12
17
|
|
13
18
|
def call
|
14
|
-
pipe
|
19
|
+
pipe requester.get("firmware/latest"),
|
15
20
|
try(:parse, catch: JSON::ParserError),
|
16
21
|
validate(contract, as: :to_h),
|
17
22
|
to(model, :for)
|
@@ -5,9 +5,9 @@ module TRMNL
|
|
5
5
|
module Endpoints
|
6
6
|
# Handles API request/response.
|
7
7
|
class Log
|
8
|
-
include Dependencies[:
|
8
|
+
include TRMNL::API::Dependencies[:requester]
|
9
9
|
|
10
|
-
def call(token:, **) =
|
10
|
+
def call(token:, **) = requester.post("log", headers: {"Access-Token" => token}, **)
|
11
11
|
end
|
12
12
|
end
|
13
13
|
end
|
@@ -7,11 +7,16 @@ module TRMNL
|
|
7
7
|
module Endpoints
|
8
8
|
# Handles API request/response.
|
9
9
|
class Setup
|
10
|
-
include Dependencies[
|
10
|
+
include TRMNL::API::Dependencies[
|
11
|
+
:requester,
|
12
|
+
contract: "contracts.setup",
|
13
|
+
model: "models.setup"
|
14
|
+
]
|
15
|
+
|
11
16
|
include Pipeable
|
12
17
|
|
13
18
|
def call id:
|
14
|
-
pipe
|
19
|
+
pipe requester.get("setup", headers: {"ID" => id}),
|
15
20
|
try(:parse, catch: JSON::ParserError),
|
16
21
|
validate(contract, as: :to_h),
|
17
22
|
to(model, :for)
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "dry/monads"
|
4
|
+
require "http"
|
5
|
+
|
6
|
+
module TRMNL
|
7
|
+
module API
|
8
|
+
# Provides a low level configurable and monadic API client.
|
9
|
+
# :reek:DataClump
|
10
|
+
class Requester
|
11
|
+
include Dependencies[:settings, :http]
|
12
|
+
include Dry::Monads[:result]
|
13
|
+
|
14
|
+
HEADERS = {}.freeze
|
15
|
+
|
16
|
+
def initialize(**)
|
17
|
+
super
|
18
|
+
yield settings if block_given?
|
19
|
+
end
|
20
|
+
|
21
|
+
def get(path, headers: HEADERS, **params) = call(__method__, path, headers, params:)
|
22
|
+
|
23
|
+
def post(path, headers: HEADERS, **json) = call(__method__, path, headers, json:)
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
attr_reader :settings, :http
|
28
|
+
|
29
|
+
# rubocop:todo Metrics/ParameterLists
|
30
|
+
def call method, path, headers, **options
|
31
|
+
http.headers(settings.headers.merge(headers))
|
32
|
+
.public_send(method, "#{settings.uri}/#{path}", options)
|
33
|
+
.then { |response| response.status.success? ? Success(response) : Failure(response) }
|
34
|
+
end
|
35
|
+
# rubocop:enable Metrics/ParameterLists
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/lib/trmnl/api.rb
CHANGED
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.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- TRMNL
|
@@ -167,7 +167,9 @@ files:
|
|
167
167
|
- lib/trmnl/api/contracts/firmware.rb
|
168
168
|
- lib/trmnl/api/contracts/setup.rb
|
169
169
|
- lib/trmnl/api/dependencies.rb
|
170
|
+
- lib/trmnl/api/endpoints/container.rb
|
170
171
|
- lib/trmnl/api/endpoints/current_screen.rb
|
172
|
+
- lib/trmnl/api/endpoints/dependencies.rb
|
171
173
|
- lib/trmnl/api/endpoints/display.rb
|
172
174
|
- lib/trmnl/api/endpoints/firmware.rb
|
173
175
|
- lib/trmnl/api/endpoints/log.rb
|
@@ -176,6 +178,7 @@ files:
|
|
176
178
|
- lib/trmnl/api/models/display.rb
|
177
179
|
- lib/trmnl/api/models/firmware.rb
|
178
180
|
- lib/trmnl/api/models/setup.rb
|
181
|
+
- lib/trmnl/api/requester.rb
|
179
182
|
- trmnl-api.gemspec
|
180
183
|
homepage: https://github.com/usetrmnl/trmnl-api
|
181
184
|
licenses:
|
metadata.gz.sig
CHANGED
Binary file
|