trmnl-api 0.0.0 → 0.2.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 +27 -23
- 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 +5 -3
- data/lib/trmnl/api/endpoints/dependencies.rb +11 -0
- data/lib/trmnl/api/endpoints/display.rb +9 -2
- data/lib/trmnl/api/endpoints/firmware.rb +9 -2
- data/lib/trmnl/api/endpoints/log.rb +2 -2
- data/lib/trmnl/api/endpoints/setup.rb +9 -2
- data/lib/trmnl/api/requester.rb +38 -0
- data/lib/trmnl/api.rb +2 -0
- data/trmnl-api.gemspec +2 -1
- data.tar.gz.sig +0 -0
- metadata +19 -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: 569d9d6bbfd5690691f558a31079e9837b9c39141c02e5f43e44bd58cfbf2663
|
4
|
+
data.tar.gz: e77c972a0cebebc856605a9fb3c4b7fc99bb6c475f786900e7eba0e3b508875e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 26a8717e1cdd331584bc6f390bfc07ef30b072b2f9a5a406c562fd5eee369576b17b149f762ca4f9e48b0c763891e92618e0823eae384d549392910e917b1e8d
|
7
|
+
data.tar.gz: 5b9cfef970999778d870a606961a6dd54de4233eb2343a72b07ff11d26729d91652a324a99fda045998d6f706b91cf078e77ba077d047798ce77e058a162cdef
|
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.firmware
|
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.log 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.setup 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,43 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "
|
4
|
-
require "http"
|
3
|
+
require "inspectable"
|
5
4
|
|
6
5
|
module TRMNL
|
7
6
|
module API
|
8
|
-
# Provides
|
9
|
-
# :reek:DataClump
|
7
|
+
# Provides the primary client for making API requests.
|
10
8
|
class Client
|
11
|
-
include
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
9
|
+
include Dependencies[:settings]
|
10
|
+
|
11
|
+
include Endpoints::Dependencies[
|
12
|
+
endpoint_current_screen: :current_screen,
|
13
|
+
endpoint_display: :display,
|
14
|
+
endpoint_firmware: :firmware,
|
15
|
+
endpoint_log: :log,
|
16
|
+
endpoint_setup: :setup
|
17
|
+
]
|
18
|
+
|
19
|
+
include Inspectable[
|
20
|
+
endpoint_current_screen: :class,
|
21
|
+
endpoint_display: :class,
|
22
|
+
endpoint_firmware: :class,
|
23
|
+
endpoint_log: :class,
|
24
|
+
endpoint_setup: :class
|
25
|
+
]
|
26
|
+
|
27
|
+
def initialize(**)
|
28
|
+
super
|
19
29
|
yield settings if block_given?
|
20
30
|
end
|
21
31
|
|
22
|
-
def
|
32
|
+
def current_screen(**) = endpoint_current_screen.call(**)
|
23
33
|
|
24
|
-
def
|
34
|
+
def display(**) = endpoint_display.call(**)
|
25
35
|
|
26
|
-
|
36
|
+
def firmware = endpoint_firmware.call
|
27
37
|
|
28
|
-
|
38
|
+
def log(**) = endpoint_log.call(**)
|
29
39
|
|
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
|
40
|
+
def setup(**) = endpoint_setup.call(**)
|
37
41
|
end
|
38
42
|
end
|
39
43
|
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
|
@@ -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
|
@@ -7,16 +8,17 @@ module TRMNL
|
|
7
8
|
module Endpoints
|
8
9
|
# Handles API request/response.
|
9
10
|
class CurrentScreen
|
10
|
-
include Dependencies[
|
11
|
-
:
|
11
|
+
include TRMNL::API::Dependencies[
|
12
|
+
:requester,
|
12
13
|
contract: "contracts.current_screen",
|
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:
|
19
|
-
pipe
|
21
|
+
pipe requester.get("current_screen", headers: {"Access-Token" => token}),
|
20
22
|
try(:parse, catch: JSON::ParserError),
|
21
23
|
validate(contract, as: :to_h),
|
22
24
|
to(model, :for)
|
@@ -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
|
@@ -7,11 +8,17 @@ module TRMNL
|
|
7
8
|
module Endpoints
|
8
9
|
# Handles API request/response.
|
9
10
|
class Display
|
10
|
-
include Dependencies[
|
11
|
+
include TRMNL::API::Dependencies[
|
12
|
+
:requester,
|
13
|
+
contract: "contracts.display",
|
14
|
+
model: "models.display"
|
15
|
+
]
|
16
|
+
|
17
|
+
include Inspectable[contract: :class]
|
11
18
|
include Pipeable
|
12
19
|
|
13
20
|
def call token:
|
14
|
-
pipe
|
21
|
+
pipe requester.get("display", headers: {"Access-Token" => token}),
|
15
22
|
try(:parse, catch: JSON::ParserError),
|
16
23
|
validate(contract, as: :to_h),
|
17
24
|
to(model, :for)
|
@@ -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
|
@@ -7,11 +8,17 @@ module TRMNL
|
|
7
8
|
module Endpoints
|
8
9
|
# Handles API request/response.
|
9
10
|
class Firmware
|
10
|
-
include Dependencies[
|
11
|
+
include TRMNL::API::Dependencies[
|
12
|
+
:requester,
|
13
|
+
contract: "contracts.firmware",
|
14
|
+
model: "models.firmware"
|
15
|
+
]
|
16
|
+
|
17
|
+
include Inspectable[contract: :class]
|
11
18
|
include Pipeable
|
12
19
|
|
13
20
|
def call
|
14
|
-
pipe
|
21
|
+
pipe requester.get("firmware/latest"),
|
15
22
|
try(:parse, catch: JSON::ParserError),
|
16
23
|
validate(contract, as: :to_h),
|
17
24
|
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
|
@@ -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
|
@@ -7,11 +8,17 @@ module TRMNL
|
|
7
8
|
module Endpoints
|
8
9
|
# Handles API request/response.
|
9
10
|
class Setup
|
10
|
-
include Dependencies[
|
11
|
+
include TRMNL::API::Dependencies[
|
12
|
+
:requester,
|
13
|
+
contract: "contracts.setup",
|
14
|
+
model: "models.setup"
|
15
|
+
]
|
16
|
+
|
17
|
+
include Inspectable[contract: :class]
|
11
18
|
include Pipeable
|
12
19
|
|
13
20
|
def call id:
|
14
|
-
pipe
|
21
|
+
pipe requester.get("setup", headers: {"ID" => id}),
|
15
22
|
try(:parse, catch: JSON::ParserError),
|
16
23
|
validate(contract, as: :to_h),
|
17
24
|
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
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |spec|
|
4
4
|
spec.name = "trmnl-api"
|
5
|
-
spec.version = "0.
|
5
|
+
spec.version = "0.2.0"
|
6
6
|
spec.authors = ["TRMNL"]
|
7
7
|
spec.email = ["support@usetrmnl.com"]
|
8
8
|
spec.homepage = "https://github.com/usetrmnl/trmnl-api"
|
@@ -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.
|
4
|
+
version: 0.2.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
|
@@ -167,7 +181,9 @@ files:
|
|
167
181
|
- lib/trmnl/api/contracts/firmware.rb
|
168
182
|
- lib/trmnl/api/contracts/setup.rb
|
169
183
|
- lib/trmnl/api/dependencies.rb
|
184
|
+
- lib/trmnl/api/endpoints/container.rb
|
170
185
|
- lib/trmnl/api/endpoints/current_screen.rb
|
186
|
+
- lib/trmnl/api/endpoints/dependencies.rb
|
171
187
|
- lib/trmnl/api/endpoints/display.rb
|
172
188
|
- lib/trmnl/api/endpoints/firmware.rb
|
173
189
|
- lib/trmnl/api/endpoints/log.rb
|
@@ -176,6 +192,7 @@ files:
|
|
176
192
|
- lib/trmnl/api/models/display.rb
|
177
193
|
- lib/trmnl/api/models/firmware.rb
|
178
194
|
- lib/trmnl/api/models/setup.rb
|
195
|
+
- lib/trmnl/api/requester.rb
|
179
196
|
- trmnl-api.gemspec
|
180
197
|
homepage: https://github.com/usetrmnl/trmnl-api
|
181
198
|
licenses:
|
@@ -201,7 +218,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
201
218
|
- !ruby/object:Gem::Version
|
202
219
|
version: '0'
|
203
220
|
requirements: []
|
204
|
-
rubygems_version: 3.6.
|
221
|
+
rubygems_version: 3.6.9
|
205
222
|
specification_version: 4
|
206
223
|
summary: A monadic TRMNL API client.
|
207
224
|
test_files: []
|
metadata.gz.sig
CHANGED
Binary file
|