prusalink 0.1.0 → 0.1.1

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: 51c60c7c6eff2e6ac93c9bb3e3e95973f756dd33b01e5b7064667f9b3b460c9e
4
- data.tar.gz: 1986ff7d2a7ef7f183e0259003181b3fc912adfc44e1aad9b0978ebbbaf90e4c
3
+ metadata.gz: e56eee0dc3ba4c8a6a4ef23d4ee876a74108a4b9cf6105cbd3227749cbba406d
4
+ data.tar.gz: 625b138bcc66f1a54b1efa22f27fc2e5e686a4ec5b43d63e5feba73adb4b4e2b
5
5
  SHA512:
6
- metadata.gz: c1e9d55a44bb104802c96a1232383b13a7e589d61e2abee09349d05efd0718c6bb2711ee1f05dfc9c6888a6a2d45fbf8337204c44501821650dc6ff592e49a91
7
- data.tar.gz: 7d6a4f0e004066aeb8550b7368952548e616617c33c8b265ec110ec3ed60ce761b557cf0b732bf799bd9c7f2eb2f170e52cf6b9d5212144aae4d9c8a7fae6887
6
+ metadata.gz: d003b0cacdc0af494f10b8448f187277760bb9277cae92a083c02a250559a02641985f799732d94f4dd1c2a17541cce02147f425b22a30267b600e54bdbcdaab
7
+ data.tar.gz: 2db605cca6bb2c9c24b6272a01e2b8292b14ce14e93d5087739b1903f050504abe7951f92213e0b5eace8f28ffb73c7414e8ba4e4892702dce33002009d08d3b
data/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.1.1] - 2026-11-15
4
+
5
+ - Fix `Files::File#read_only` and `Files::Folder#read_only`, which were always `nil` on MK4, XL and MINI firmware. It sends `ro` instead of `read_only`
6
+ - Fix `Files.info` reporting `currently_printed: false` on MK4, XL and MINI firmware, which sends a `Currently-Printing` header instead of `Currently-Printed`
7
+ - Fix `Files.upload` raising a Sorbet `TypeError` on MK4, XL and MINI firmware, which answers with the uploaded file's JSON. It returns `true` again
8
+ - Raise `Prusalink::Exceptions::InvalidResponseError` instead of `JSON::ParserError` when the printer answers with invalid JSON, like XL firmware does for a job whose file was deleted
9
+ - Add `ServerVersion#server`, `#nozzle_diameter` and `#hostname`, which MK4, XL and MINI firmware send
10
+ - Add VCR cassettes recorded against a Prusa XL for every read-only endpoint
11
+
3
12
  ## [0.1.0] - 2026-11-15
4
13
 
5
14
  - Initial release: client with HTTP Digest auth, version, info, status, job, storage, transfer and files resources
@@ -86,6 +86,7 @@ module Prusalink
86
86
  # @raise [Exceptions::Error] a subclass matching the HTTP status when the request fails
87
87
  # @raise [Exceptions::TimeoutError] if the printer doesn't respond within the configured timeouts
88
88
  # @raise [Exceptions::ConnectionError] if the printer can't be reached
89
+ # @raise [Exceptions::InvalidResponseError] if the printer answers with invalid JSON
89
90
  sig do
90
91
  params(
91
92
  path: String,
@@ -158,12 +159,15 @@ module Prusalink
158
159
  return response.body.to_s unless parsed.is_a?(Hash)
159
160
 
160
161
  [parsed[:title], parsed[:text]].compact.join(": ").presence || response.body.to_s
161
- rescue JSON::ParserError
162
+ rescue Exceptions::InvalidResponseError
162
163
  response.body.to_s
163
164
  end
164
165
 
165
166
  def parse_json(body)
166
167
  transform_keys(JSON.parse(body))
168
+ rescue JSON::ParserError => e
169
+ # Seen on XL firmware: the job's JSON ends with a trailing comma when its file was deleted
170
+ raise Exceptions::InvalidResponseError, "The printer answered with invalid JSON (#{e.message}): #{body}"
167
171
  end
168
172
 
169
173
  def transform_keys(obj)
@@ -28,6 +28,8 @@ module Prusalink
28
28
  class ServiceUnavailableError < Error; end
29
29
  # Any other unexpected HTTP status
30
30
  class UnknownError < Error; end
31
+ # The printer answered with a body that isn't valid JSON
32
+ class InvalidResponseError < Error; end
31
33
  # The printer could not be reached (connection refused, host unreachable, DNS failure, ...)
32
34
  class ConnectionError < Error; end
33
35
  # The printer did not open the connection or respond within the configured timeouts
@@ -56,7 +56,8 @@ module Prusalink
56
56
 
57
57
  deserialize_config do
58
58
  nested :refs, Files::Refs
59
- rename type: :file_type
59
+ # MK4, XL and MINI firmware send `ro` instead of the OpenAPI spec's `read_only`
60
+ rename type: :file_type, ro: :read_only
60
61
  end
61
62
 
62
63
  # Whether the file can be printed (G-code, binary G-code or SL1)
@@ -50,7 +50,8 @@ module Prusalink
50
50
  auto_initialize!
51
51
 
52
52
  deserialize_config do
53
- rename type: :file_type
53
+ # MK4, XL and MINI firmware send `ro` instead of the OpenAPI spec's `read_only`
54
+ rename type: :file_type, ro: :read_only
54
55
  transform do |data|
55
56
  data[:children] = data[:children].map { |child| Files.build_entry(child) } if data[:children].is_a?(Array)
56
57
  end
@@ -134,7 +134,9 @@ module Prusalink
134
134
 
135
135
  {
136
136
  read_only: header_true?(headers["read-only"]),
137
- currently_printed: header_true?(headers["currently-printed"])
137
+ # The OpenAPI spec and PrusaLink on a Raspberry Pi send Currently-Printed.
138
+ # MK4, XL and MINI firmware send Currently-Printing.
139
+ currently_printed: header_true?(headers["currently-printed"] || headers["currently-printing"])
138
140
  }
139
141
  end
140
142
 
@@ -166,7 +168,9 @@ module Prusalink
166
168
  raise ArgumentError, "Can't upload a #{io.class} without a known size. Pass a path, a File or a StringIO"
167
169
  end
168
170
 
169
- put(path: path, params: io, headers: headers.merge("Content-Length" => T.unsafe(io).size.to_s))
171
+ # MK4, XL and MINI firmware answer 201 with the uploaded file's JSON, others answer without a body (true).
172
+ # Either way the upload succeeded, so this returns true rather than the JSON.
173
+ put(path: path, params: io, headers: headers.merge("Content-Length" => T.unsafe(io).size.to_s)).then { true }
170
174
  end
171
175
 
172
176
  # RFC 8941 boolean, the format PrusaLink expects in its headers
@@ -44,6 +44,20 @@ module Prusalink
44
44
  # @return [Hash] Optional capabilities, e.g. { upload_by_put: true }
45
45
  auto_attr :capabilities, type: Hash
46
46
 
47
+ # The next three fields are sent by MK4, XL and MINI firmware, but aren't in the OpenAPI spec.
48
+
49
+ # @!attribute [r] server
50
+ # @return [String] The PrusaLink server version, e.g. "2.1.2"
51
+ auto_attr :server, type: String
52
+
53
+ # @!attribute [r] nozzle_diameter
54
+ # @return [Float] The nozzle's diameter, in millimeters
55
+ auto_attr :nozzle_diameter, type: Float
56
+
57
+ # @!attribute [r] hostname
58
+ # @return [String] The printer's hostname on the network, e.g. "prusa-xl"
59
+ auto_attr :hostname, type: String
60
+
47
61
  # @!attribute [r] extra
48
62
  # @return [Hash] Any additional fields returned by the API
49
63
  auto_attr :extra, type: Hash
@@ -3,5 +3,5 @@
3
3
 
4
4
  module Prusalink
5
5
  # This gem's version
6
- VERSION = "0.1.0"
6
+ VERSION = "0.1.1"
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prusalink
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sophie Déziel