octoprint 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 +7 -0
- data/CHANGELOG.md +10 -0
- data/LICENSE.txt +21 -0
- data/README.md +336 -0
- data/lib/octoprint/access/group.rb +88 -0
- data/lib/octoprint/access/groups.rb +166 -0
- data/lib/octoprint/access/login_response.rb +63 -0
- data/lib/octoprint/access/permission.rb +71 -0
- data/lib/octoprint/access/permissions.rb +29 -0
- data/lib/octoprint/access/user.rb +95 -0
- data/lib/octoprint/access/users.rb +347 -0
- data/lib/octoprint/auto_initializable.rb +219 -0
- data/lib/octoprint/base_resource.rb +139 -0
- data/lib/octoprint/client.rb +151 -0
- data/lib/octoprint/connection/options.rb +44 -0
- data/lib/octoprint/connection/settings.rb +35 -0
- data/lib/octoprint/connection.rb +74 -0
- data/lib/octoprint/deserializable.rb +483 -0
- data/lib/octoprint/exceptions.rb +30 -0
- data/lib/octoprint/files/file.rb +55 -0
- data/lib/octoprint/files/folder.rb +29 -0
- data/lib/octoprint/files/operation_result.rb +37 -0
- data/lib/octoprint/files/refs.rb +19 -0
- data/lib/octoprint/files.rb +238 -0
- data/lib/octoprint/job/information.rb +42 -0
- data/lib/octoprint/job/progress.rb +46 -0
- data/lib/octoprint/job.rb +140 -0
- data/lib/octoprint/languages/language_pack.rb +31 -0
- data/lib/octoprint/languages.rb +102 -0
- data/lib/octoprint/location.rb +23 -0
- data/lib/octoprint/logs/log_file.rb +59 -0
- data/lib/octoprint/logs/references.rb +28 -0
- data/lib/octoprint/logs.rb +98 -0
- data/lib/octoprint/printer/bed.rb +32 -0
- data/lib/octoprint/printer/chamber.rb +29 -0
- data/lib/octoprint/printer/command.rb +129 -0
- data/lib/octoprint/printer/custom_control/input.rb +45 -0
- data/lib/octoprint/printer/custom_control.rb +119 -0
- data/lib/octoprint/printer/error_information.rb +104 -0
- data/lib/octoprint/printer/heater.rb +113 -0
- data/lib/octoprint/printer/history_query.rb +25 -0
- data/lib/octoprint/printer/printhead.rb +105 -0
- data/lib/octoprint/printer/sd.rb +97 -0
- data/lib/octoprint/printer/state.rb +41 -0
- data/lib/octoprint/printer/state_flags.rb +70 -0
- data/lib/octoprint/printer/temperature_attributes.rb +70 -0
- data/lib/octoprint/printer/temperature_data.rb +53 -0
- data/lib/octoprint/printer/temperature_data_point.rb +73 -0
- data/lib/octoprint/printer/temperature_reading.rb +47 -0
- data/lib/octoprint/printer/temperature_state.rb +67 -0
- data/lib/octoprint/printer/tool.rb +154 -0
- data/lib/octoprint/printer.rb +126 -0
- data/lib/octoprint/printer_profiles/printer_profile.rb +40 -0
- data/lib/octoprint/printer_profiles.rb +158 -0
- data/lib/octoprint/server_information.rb +51 -0
- data/lib/octoprint/server_version.rb +52 -0
- data/lib/octoprint/settings/webcam.rb +135 -0
- data/lib/octoprint/settings.rb +133 -0
- data/lib/octoprint/slicing/profile.rb +65 -0
- data/lib/octoprint/slicing/slicer.rb +83 -0
- data/lib/octoprint/slicing.rb +227 -0
- data/lib/octoprint/system_commands/command.rb +41 -0
- data/lib/octoprint/system_commands.rb +110 -0
- data/lib/octoprint/timelapse/config.rb +68 -0
- data/lib/octoprint/timelapse/file_attributes.rb +50 -0
- data/lib/octoprint/timelapse/rendered.rb +51 -0
- data/lib/octoprint/timelapse/unrendered.rb +43 -0
- data/lib/octoprint/timelapse.rb +221 -0
- data/lib/octoprint/types.rb +140 -0
- data/lib/octoprint/util.rb +151 -0
- data/lib/octoprint/version.rb +7 -0
- data/lib/octoprint/wizard.rb +57 -0
- data/lib/octoprint.rb +57 -0
- data/rbi/octoprint/access/group.rbi +46 -0
- data/rbi/octoprint/access/login_response.rbi +22 -0
- data/rbi/octoprint/access/permission.rbi +34 -0
- data/rbi/octoprint/access/user.rbi +43 -0
- data/rbi/octoprint/connection/options.rbi +28 -0
- data/rbi/octoprint/connection/settings.rbi +19 -0
- data/rbi/octoprint/connection.rbi +13 -0
- data/rbi/octoprint/files/file.rbi +61 -0
- data/rbi/octoprint/files/folder.rbi +22 -0
- data/rbi/octoprint/files/operation_result.rbi +22 -0
- data/rbi/octoprint/files/refs.rbi +16 -0
- data/rbi/octoprint/job/information.rbi +22 -0
- data/rbi/octoprint/job/progress.rbi +25 -0
- data/rbi/octoprint/job.rbi +22 -0
- data/rbi/octoprint/languages/language_pack.rbi +19 -0
- data/rbi/octoprint/languages.rbi +13 -0
- data/rbi/octoprint/logs/log_file.rbi +19 -0
- data/rbi/octoprint/logs/references.rbi +13 -0
- data/rbi/octoprint/logs.rbi +13 -0
- data/rbi/octoprint/printer/bed.rbi +22 -0
- data/rbi/octoprint/printer/chamber.rbi +22 -0
- data/rbi/octoprint/printer/custom_control/input.rbi +22 -0
- data/rbi/octoprint/printer/custom_control.rbi +67 -0
- data/rbi/octoprint/printer/error_information.rbi +25 -0
- data/rbi/octoprint/printer/sd.rbi +13 -0
- data/rbi/octoprint/printer/state.rbi +19 -0
- data/rbi/octoprint/printer/state_flags.rbi +43 -0
- data/rbi/octoprint/printer/temperature_data.rbi +19 -0
- data/rbi/octoprint/printer/temperature_data_point.rbi +22 -0
- data/rbi/octoprint/printer/temperature_reading.rbi +19 -0
- data/rbi/octoprint/printer/temperature_state.rbi +22 -0
- data/rbi/octoprint/printer/tool.rbi +22 -0
- data/rbi/octoprint/printer.rbi +19 -0
- data/rbi/octoprint/printer_profiles/printer_profile.rbi +46 -0
- data/rbi/octoprint/printer_profiles.rbi +13 -0
- data/rbi/octoprint/server_information.rbi +16 -0
- data/rbi/octoprint/server_version.rbi +19 -0
- data/rbi/octoprint/settings/webcam.rbi +34 -0
- data/rbi/octoprint/slicing/profile.rbi +28 -0
- data/rbi/octoprint/slicing/slicer.rbi +31 -0
- data/rbi/octoprint/system_commands/command.rbi +25 -0
- data/rbi/octoprint/system_commands.rbi +16 -0
- data/rbi/octoprint/timelapse/config.rbi +31 -0
- data/rbi/octoprint/timelapse/rendered.rbi +31 -0
- data/rbi/octoprint/timelapse/unrendered.rbi +34 -0
- data/rbi/octoprint/timelapse.rbi +22 -0
- data/rbi/octoprint/util.rbi +19 -0
- data/rbi/octoprint.rbi +1848 -0
- metadata +264 -0
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
# typed: true
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require "faraday"
|
|
5
|
+
require "faraday/multipart"
|
|
6
|
+
|
|
7
|
+
module Octoprint
|
|
8
|
+
# Information about files on the server
|
|
9
|
+
#
|
|
10
|
+
# Octoprint's API doc: https://docs.octoprint.org/en/master/api/files.html
|
|
11
|
+
class Files < BaseResource
|
|
12
|
+
resource_path("/api/files")
|
|
13
|
+
attr_reader :files, :free, :total
|
|
14
|
+
|
|
15
|
+
def initialize(files:, free: nil, total: nil)
|
|
16
|
+
@files = files.map { |file| Files::File.deserialize(file) }
|
|
17
|
+
@free = free
|
|
18
|
+
@total = total
|
|
19
|
+
super()
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# Fetches the list of files at a location
|
|
23
|
+
#
|
|
24
|
+
# @param [Location] location The location to fetch the list of files from. Defaults to local.
|
|
25
|
+
# @param [Hash] options Additional parameters
|
|
26
|
+
#
|
|
27
|
+
# @return [Files]
|
|
28
|
+
#: (?location: Location, ?options: Hash[Symbol, untyped]) -> Files
|
|
29
|
+
def self.list(location: Location::Local, options: {})
|
|
30
|
+
fetch_resource location.serialize, options: options
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# Fetches a single file or folder
|
|
34
|
+
#
|
|
35
|
+
# @param [String] filename The name of the file to fetch
|
|
36
|
+
# @param [Location] location The location to fetch the file from
|
|
37
|
+
# @param [Hash] options Additional parameters
|
|
38
|
+
#
|
|
39
|
+
# @return [Files::File]
|
|
40
|
+
#: (
|
|
41
|
+
#| filename: String,
|
|
42
|
+
#| ?location: Location,
|
|
43
|
+
#| ?options: Hash[Symbol, untyped]?
|
|
44
|
+
#| ) -> Files::File
|
|
45
|
+
def self.get(filename:, location: Location::Local, options: {})
|
|
46
|
+
path = [location.serialize, filename].compact.join("/")
|
|
47
|
+
Files::File.deserialize(fetch_resource(path, deserialize: false, options: options))
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# Uploads a file
|
|
51
|
+
#
|
|
52
|
+
# @param [String] file_path The path to the file to upload.
|
|
53
|
+
# @param [Location] location The target location to which to upload the file.
|
|
54
|
+
# @option options [String] :path The path to upload the file to, relative to the location.
|
|
55
|
+
# @option options [Boolean] :select Whether to select the file directly after upload. Ignored when creating a
|
|
56
|
+
# folder.
|
|
57
|
+
# @option options [Boolean] :print Whether to start printing the file directly after upload. Ignored when
|
|
58
|
+
# creating a folder.
|
|
59
|
+
# @option options [String] :userdata An optional string that if specified will be interpreted as JSON and then
|
|
60
|
+
# saved along with the file as metadata (metadata key userdata). Ignored when
|
|
61
|
+
# creating a folder.
|
|
62
|
+
# @return [OperationResult]
|
|
63
|
+
#: (
|
|
64
|
+
#| String file_path,
|
|
65
|
+
#| ?location: Location,
|
|
66
|
+
#| ?options: {path: String?, select: bool?, print: bool?, userdata: String?}
|
|
67
|
+
#| ) -> OperationResult
|
|
68
|
+
def self.upload(file_path, location: Location::Local, options: { path: nil, select: nil, print: nil,
|
|
69
|
+
userdata: nil })
|
|
70
|
+
params = {
|
|
71
|
+
path: options[:path],
|
|
72
|
+
select: options[:select],
|
|
73
|
+
print: options[:print],
|
|
74
|
+
userdata: options[:userdata],
|
|
75
|
+
file: Faraday::UploadIO.new(file_path, "application/octet-stream")
|
|
76
|
+
}.compact
|
|
77
|
+
|
|
78
|
+
result = post(path: [@path, location.serialize].compact.join("/"), params: params)
|
|
79
|
+
OperationResult.deserialize(result)
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
# Creates a folder
|
|
83
|
+
#
|
|
84
|
+
# @param [String] foldername The name of the folder to create
|
|
85
|
+
# @param [Location] location The target location to which to upload the file.
|
|
86
|
+
# @param [String] path The path to create the folder in, relative to the location.
|
|
87
|
+
# @param [Hash] kargs Additional parameters
|
|
88
|
+
#
|
|
89
|
+
# @return [OperationResult]
|
|
90
|
+
#
|
|
91
|
+
# @example
|
|
92
|
+
# folder = Octoprint::Files.create_folder(foldername: "test")
|
|
93
|
+
# folder.name #=> "test"
|
|
94
|
+
# folder.origin #=> "local"
|
|
95
|
+
# folder.path #=> "test"
|
|
96
|
+
# folder.refs #=> {resource: "http://octoprint.local/api/files/local/test"}
|
|
97
|
+
#: (
|
|
98
|
+
#| foldername: String,
|
|
99
|
+
#| ?location: Location,
|
|
100
|
+
#| ?path: String?,
|
|
101
|
+
#| **Hash[Symbol, untyped] _kargs
|
|
102
|
+
#| ) -> OperationResult
|
|
103
|
+
def self.create_folder(foldername:, location: Location::Local, path: nil, **_kargs)
|
|
104
|
+
params = {
|
|
105
|
+
path: path,
|
|
106
|
+
foldername: foldername
|
|
107
|
+
}.compact
|
|
108
|
+
|
|
109
|
+
result = post(path: [@path, location.serialize].compact.join("/"), params: params,
|
|
110
|
+
options: { force_multipart: true })
|
|
111
|
+
|
|
112
|
+
OperationResult.deserialize(result)
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
# Issues a file command
|
|
116
|
+
#
|
|
117
|
+
# @param [String] filename The name of the file to issue the command to
|
|
118
|
+
# @param [String] command The command to issue (select, unselect, slice, copy, move)
|
|
119
|
+
# @param [Location] location The location of the file
|
|
120
|
+
# @param [Hash] options Additional command parameters
|
|
121
|
+
# @option options [Boolean] :print Whether to start printing after selection/slicing
|
|
122
|
+
# @option options [String] :destination Destination path for copy/move operations
|
|
123
|
+
# @option options [Hash] :profile Slicing profile for slice command
|
|
124
|
+
#
|
|
125
|
+
# @return [T.untyped] Response varies by command (204 No Content, 201 Created, or file data)
|
|
126
|
+
#: (
|
|
127
|
+
#| filename: String,
|
|
128
|
+
#| command: String,
|
|
129
|
+
#| ?location: Location,
|
|
130
|
+
#| ?options: Hash[Symbol, untyped]
|
|
131
|
+
#| ) -> untyped
|
|
132
|
+
def self.issue_command(filename:, command:, location: Location::Local, options: {})
|
|
133
|
+
path = [@path, location.serialize, filename].compact.join("/")
|
|
134
|
+
params = { command: command }.merge(options)
|
|
135
|
+
post(path: path, params: params)
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
# Selects a file for printing
|
|
139
|
+
#
|
|
140
|
+
# @param [String] filename The name of the file to select
|
|
141
|
+
# @param [Location] location The location of the file
|
|
142
|
+
# @param [Boolean] print Whether to start printing immediately after selection
|
|
143
|
+
#
|
|
144
|
+
# @return [T.untyped] 204 No Content on success
|
|
145
|
+
#: (
|
|
146
|
+
#| filename: String,
|
|
147
|
+
#| ?location: Location,
|
|
148
|
+
#| ?print: bool?
|
|
149
|
+
#| ) -> untyped
|
|
150
|
+
def self.select(filename:, location: Location::Local, print: nil)
|
|
151
|
+
options = print.nil? ? {} : { print: print }
|
|
152
|
+
issue_command(filename: filename, command: "select", location: location, options: options)
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
# Unselects the currently selected file
|
|
156
|
+
#
|
|
157
|
+
# @param [String] filename The name of the file to unselect
|
|
158
|
+
# @param [Location] location The location of the file
|
|
159
|
+
#
|
|
160
|
+
# @return [T.untyped] 204 No Content on success
|
|
161
|
+
#: (
|
|
162
|
+
#| filename: String,
|
|
163
|
+
#| ?location: Location
|
|
164
|
+
#| ) -> untyped
|
|
165
|
+
def self.unselect(filename:, location: Location::Local)
|
|
166
|
+
issue_command(filename: filename, command: "unselect", location: location, options: {})
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
# Slices an STL file into GCODE
|
|
170
|
+
#
|
|
171
|
+
# @param [String] filename The name of the STL file to slice
|
|
172
|
+
# @param [Location] location The location of the file
|
|
173
|
+
# @param [Boolean] print Whether to start printing after slicing
|
|
174
|
+
# @param [Hash] profile Slicing profile settings
|
|
175
|
+
#
|
|
176
|
+
# @return [T.untyped] 202 Accepted with file information
|
|
177
|
+
#: (
|
|
178
|
+
#| filename: String,
|
|
179
|
+
#| ?location: Location,
|
|
180
|
+
#| ?print: bool?,
|
|
181
|
+
#| ?profile: Hash[Symbol, untyped]?
|
|
182
|
+
#| ) -> untyped
|
|
183
|
+
def self.slice(filename:, location: Location::Local, print: nil, profile: nil)
|
|
184
|
+
options = {}
|
|
185
|
+
options[:print] = print unless print.nil?
|
|
186
|
+
options.merge!(profile) if profile
|
|
187
|
+
issue_command(filename: filename, command: "slice", location: location, options: options)
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
# Copies a file or folder
|
|
191
|
+
#
|
|
192
|
+
# @param [String] filename The name of the file or folder to copy
|
|
193
|
+
# @param [String] destination The destination path for the copy
|
|
194
|
+
# @param [Location] location The location of the source file
|
|
195
|
+
#
|
|
196
|
+
# @return [T.untyped] 201 Created with file information
|
|
197
|
+
#: (
|
|
198
|
+
#| filename: String,
|
|
199
|
+
#| destination: String,
|
|
200
|
+
#| ?location: Location
|
|
201
|
+
#| ) -> untyped
|
|
202
|
+
def self.copy(filename:, destination:, location: Location::Local)
|
|
203
|
+
issue_command(filename: filename, command: "copy", location: location, options: { destination: destination })
|
|
204
|
+
end
|
|
205
|
+
|
|
206
|
+
# Moves a file or folder
|
|
207
|
+
#
|
|
208
|
+
# @param [String] filename The name of the file or folder to move
|
|
209
|
+
# @param [String] destination The destination path for the move
|
|
210
|
+
# @param [Location] location The location of the source file
|
|
211
|
+
#
|
|
212
|
+
# @return [T.untyped] 201 Created with file information
|
|
213
|
+
#: (
|
|
214
|
+
#| filename: String,
|
|
215
|
+
#| destination: String,
|
|
216
|
+
#| ?location: Location
|
|
217
|
+
#| ) -> untyped
|
|
218
|
+
def self.move(filename:, destination:, location: Location::Local)
|
|
219
|
+
issue_command(filename: filename, command: "move", location: location, options: { destination: destination })
|
|
220
|
+
end
|
|
221
|
+
|
|
222
|
+
# Deletes a file
|
|
223
|
+
#
|
|
224
|
+
# @param [String] filename The name of the file to delete
|
|
225
|
+
# @param [Location] location The location of the file
|
|
226
|
+
#
|
|
227
|
+
# @return [T.untyped] 204 No Content on success
|
|
228
|
+
#: (
|
|
229
|
+
#| filename: String,
|
|
230
|
+
#| ?location: Location
|
|
231
|
+
#| ) -> untyped
|
|
232
|
+
def self.delete_file(filename:, location: Location::Local)
|
|
233
|
+
path = [@path, location.serialize, filename].compact.join("/")
|
|
234
|
+
delete(path: path)
|
|
235
|
+
end
|
|
236
|
+
end
|
|
237
|
+
# rubocop:enable Metrics/ClassLength
|
|
238
|
+
end
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# typed: true
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
module Octoprint
|
|
5
|
+
class Job
|
|
6
|
+
# Information regarding the target of the current print job.
|
|
7
|
+
#
|
|
8
|
+
# @example Access job information
|
|
9
|
+
# job = Octoprint::Job.get
|
|
10
|
+
# info = job.information
|
|
11
|
+
# puts "File: #{info.file[:name]}"
|
|
12
|
+
# puts "Estimated time: #{info.estimated_print_time} seconds"
|
|
13
|
+
#
|
|
14
|
+
# @see https://docs.octoprint.org/en/master/api/datamodel.html#sec-api-datamodel-jobs-job
|
|
15
|
+
class Information
|
|
16
|
+
include AutoInitializable
|
|
17
|
+
include Deserializable
|
|
18
|
+
|
|
19
|
+
# @!attribute [r] file
|
|
20
|
+
# @return [Hash] The file that is the target of the current print job
|
|
21
|
+
auto_attr :file, type: Hash
|
|
22
|
+
|
|
23
|
+
# @!attribute [r] estimated_print_time
|
|
24
|
+
# @return [Float, nil] The estimated print time for the file, in seconds
|
|
25
|
+
auto_attr :estimated_print_time, type: Types::NilableFloat
|
|
26
|
+
|
|
27
|
+
# @!attribute [r] last_print_time
|
|
28
|
+
# @return [Float, nil] The print time of the last print of the file, in seconds
|
|
29
|
+
auto_attr :last_print_time, type: Types::NilableFloat
|
|
30
|
+
|
|
31
|
+
# @!attribute [r] filament
|
|
32
|
+
# @return [Hash, nil] Information regarding the estimated filament usage
|
|
33
|
+
auto_attr :filament, type: Types::NilableHash
|
|
34
|
+
|
|
35
|
+
# @!attribute [r] extra
|
|
36
|
+
# @return [Hash] Any additional fields returned by the API
|
|
37
|
+
auto_attr :extra, type: Hash
|
|
38
|
+
|
|
39
|
+
auto_initialize!
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# typed: true
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
module Octoprint
|
|
5
|
+
class Job
|
|
6
|
+
# Information regarding the progress of the current print job.
|
|
7
|
+
#
|
|
8
|
+
# @example Access job progress
|
|
9
|
+
# job = Octoprint::Job.get
|
|
10
|
+
# progress = job.progress
|
|
11
|
+
# puts "Completion: #{progress.completion * 100}%"
|
|
12
|
+
# puts "Time left: #{progress.print_time_left} seconds"
|
|
13
|
+
#
|
|
14
|
+
# @see https://docs.octoprint.org/en/master/api/datamodel.html#progress-information
|
|
15
|
+
class Progress
|
|
16
|
+
include AutoInitializable
|
|
17
|
+
include Deserializable
|
|
18
|
+
|
|
19
|
+
# @!attribute [r] completion
|
|
20
|
+
# @return [Float] The completion percentage of the current print job
|
|
21
|
+
auto_attr :completion, type: Float
|
|
22
|
+
|
|
23
|
+
# @!attribute [r] filepos
|
|
24
|
+
# @return [Integer] Current position in the file being printed, in bytes
|
|
25
|
+
auto_attr :filepos, type: Integer
|
|
26
|
+
|
|
27
|
+
# @!attribute [r] print_time
|
|
28
|
+
# @return [Float] Time already spent printing, in seconds
|
|
29
|
+
auto_attr :print_time, type: Float
|
|
30
|
+
|
|
31
|
+
# @!attribute [r] print_time_left
|
|
32
|
+
# @return [Float] Estimate of time left to print, in seconds
|
|
33
|
+
auto_attr :print_time_left, type: Float
|
|
34
|
+
|
|
35
|
+
# @!attribute [r] print_time_left_origin
|
|
36
|
+
# @return [String] Origin of the current time left estimate
|
|
37
|
+
auto_attr :print_time_left_origin, type: String
|
|
38
|
+
|
|
39
|
+
# @!attribute [r] extra
|
|
40
|
+
# @return [Hash] Any additional fields returned by the API
|
|
41
|
+
auto_attr :extra, type: Hash
|
|
42
|
+
|
|
43
|
+
auto_initialize!
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
# typed: true
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
module Octoprint
|
|
5
|
+
# Information about the current print job.
|
|
6
|
+
#
|
|
7
|
+
# @example Get current job
|
|
8
|
+
# job = Octoprint::Job.get
|
|
9
|
+
# puts "State: #{job.state}"
|
|
10
|
+
# puts "Progress: #{job.progress.percent}%"
|
|
11
|
+
#
|
|
12
|
+
# @see https://docs.octoprint.org/en/master/api/job.html
|
|
13
|
+
class Job < BaseResource
|
|
14
|
+
include AutoInitializable
|
|
15
|
+
include Deserializable
|
|
16
|
+
|
|
17
|
+
resource_path("/api/job")
|
|
18
|
+
|
|
19
|
+
# @!attribute [r] information
|
|
20
|
+
# @return [Job::Information] Information about the target file
|
|
21
|
+
auto_attr :information, type: Information
|
|
22
|
+
|
|
23
|
+
# @!attribute [r] progress
|
|
24
|
+
# @return [Job::Progress] Information about print progress
|
|
25
|
+
auto_attr :progress, type: Progress
|
|
26
|
+
|
|
27
|
+
# @!attribute [r] state
|
|
28
|
+
# @return [String] Current state of the job
|
|
29
|
+
auto_attr :state, type: String
|
|
30
|
+
|
|
31
|
+
# @!attribute [r] error
|
|
32
|
+
# @return [String, nil] Error message if any
|
|
33
|
+
auto_attr :error, type: String
|
|
34
|
+
|
|
35
|
+
# @!attribute [r] extra
|
|
36
|
+
# @return [Hash] Any additional fields returned by the API
|
|
37
|
+
auto_attr :extra, type: Hash
|
|
38
|
+
|
|
39
|
+
auto_initialize!
|
|
40
|
+
|
|
41
|
+
deserialize_config do
|
|
42
|
+
transform do |data|
|
|
43
|
+
data[:information] = Information.deserialize(data[:job])
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# Retrieve information about the current job.
|
|
48
|
+
#
|
|
49
|
+
# @example Get current job
|
|
50
|
+
# job = Octoprint::Job.get
|
|
51
|
+
# puts "State: #{job.state}"
|
|
52
|
+
#
|
|
53
|
+
# @return [Job] Current job information
|
|
54
|
+
# @raise [Octoprint::Exceptions::Error] if the request fails
|
|
55
|
+
#: -> Job
|
|
56
|
+
def self.get
|
|
57
|
+
fetch_resource
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
# Issues a job command.
|
|
61
|
+
#
|
|
62
|
+
# @param command [String] The command to issue (start, cancel, restart, pause)
|
|
63
|
+
# @param options [Hash] Additional command parameters
|
|
64
|
+
# @option options [String] :action The action for the pause command (pause, resume, toggle)
|
|
65
|
+
#
|
|
66
|
+
# @return [T::Boolean] true on success (204 No Content)
|
|
67
|
+
# @raise [Octoprint::Exceptions::ConflictError] if the printer is not operational or job state doesn't match
|
|
68
|
+
#
|
|
69
|
+
# @example Start a print job
|
|
70
|
+
# Octoprint::Job.issue_command(command: "start")
|
|
71
|
+
#
|
|
72
|
+
# @example Pause with a specific action
|
|
73
|
+
# Octoprint::Job.issue_command(command: "pause", options: { action: "pause" })
|
|
74
|
+
#: (command: String, ?options: Hash[Symbol, untyped]) -> untyped
|
|
75
|
+
def self.issue_command(command:, options: {})
|
|
76
|
+
params = { command: command }.merge(options)
|
|
77
|
+
post(params: params)
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
# Start printing the currently selected file.
|
|
81
|
+
#
|
|
82
|
+
# @return [T::Boolean] true on success (204 No Content)
|
|
83
|
+
# @raise [Octoprint::Exceptions::ConflictError] if the printer is not operational or no file is selected
|
|
84
|
+
#
|
|
85
|
+
# @example
|
|
86
|
+
# Octoprint::Job.start
|
|
87
|
+
#: -> untyped
|
|
88
|
+
def self.start
|
|
89
|
+
issue_command(command: "start")
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
# Cancel the current print job.
|
|
93
|
+
#
|
|
94
|
+
# @return [T::Boolean] true on success (204 No Content)
|
|
95
|
+
# @raise [Octoprint::Exceptions::ConflictError] if the printer is not operational or not printing
|
|
96
|
+
#
|
|
97
|
+
# @example
|
|
98
|
+
# Octoprint::Job.cancel
|
|
99
|
+
#: -> untyped
|
|
100
|
+
def self.cancel
|
|
101
|
+
issue_command(command: "cancel")
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
# Restart the current print job from the beginning. Requires the job to be paused.
|
|
105
|
+
#
|
|
106
|
+
# @return [T::Boolean] true on success (204 No Content)
|
|
107
|
+
# @raise [Octoprint::Exceptions::ConflictError] if the printer is not operational or job is not paused
|
|
108
|
+
#
|
|
109
|
+
# @example
|
|
110
|
+
# Octoprint::Job.restart
|
|
111
|
+
#: -> untyped
|
|
112
|
+
def self.restart
|
|
113
|
+
issue_command(command: "restart")
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
# Pause the current print job.
|
|
117
|
+
#
|
|
118
|
+
# @return [T::Boolean] true on success (204 No Content)
|
|
119
|
+
# @raise [Octoprint::Exceptions::ConflictError] if the printer is not operational or not printing
|
|
120
|
+
#
|
|
121
|
+
# @example
|
|
122
|
+
# Octoprint::Job.pause
|
|
123
|
+
#: -> untyped
|
|
124
|
+
def self.pause
|
|
125
|
+
issue_command(command: "pause", options: { action: "pause" })
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
# Resume the current print job.
|
|
129
|
+
#
|
|
130
|
+
# @return [T::Boolean] true on success (204 No Content)
|
|
131
|
+
# @raise [Octoprint::Exceptions::ConflictError] if the printer is not operational or not paused
|
|
132
|
+
#
|
|
133
|
+
# @example
|
|
134
|
+
# Octoprint::Job.resume
|
|
135
|
+
#: -> untyped
|
|
136
|
+
def self.resume
|
|
137
|
+
issue_command(command: "pause", options: { action: "resume" })
|
|
138
|
+
end
|
|
139
|
+
end
|
|
140
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# typed: true
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
module Octoprint
|
|
5
|
+
class Languages
|
|
6
|
+
# Represents a single language pack available on the server
|
|
7
|
+
#
|
|
8
|
+
# A language pack contains translations for a specific component (like the core
|
|
9
|
+
# OctoPrint interface or a plugin) and includes information about which locales
|
|
10
|
+
# are available within that pack.
|
|
11
|
+
#
|
|
12
|
+
# @example Access language pack information
|
|
13
|
+
# pack = languages.language_packs["_core"]
|
|
14
|
+
# puts pack.display # => "Core"
|
|
15
|
+
# puts pack.identifier # => "_core"
|
|
16
|
+
# puts pack.languages # => ["fr", "de", "es"]
|
|
17
|
+
class LanguagePack
|
|
18
|
+
include Deserializable
|
|
19
|
+
include AutoInitializable
|
|
20
|
+
|
|
21
|
+
auto_attr :identifier, type: String, nilable: false
|
|
22
|
+
auto_attr :display, type: String, nilable: false
|
|
23
|
+
auto_attr :languages, type: Array, nilable: false
|
|
24
|
+
auto_attr :extra, type: Hash
|
|
25
|
+
|
|
26
|
+
auto_initialize!
|
|
27
|
+
|
|
28
|
+
# No configuration needed - camelCase conversion and extras collection are automatic!
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
# typed: true
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
module Octoprint
|
|
5
|
+
# Language pack management for OctoPrint server internationalization
|
|
6
|
+
#
|
|
7
|
+
# This class provides methods to manage language packs on the OctoPrint server.
|
|
8
|
+
# Language packs enable OctoPrint's user interface to be displayed in different
|
|
9
|
+
# languages. The API supports listing installed packs, uploading new language
|
|
10
|
+
# pack archives, and removing existing language packs.
|
|
11
|
+
#
|
|
12
|
+
# Language packs are organized by identifier (e.g., "_core", plugin names) and
|
|
13
|
+
# contain translations for specific locales (e.g., "fr", "de", "es").
|
|
14
|
+
#
|
|
15
|
+
# @example List all available language packs
|
|
16
|
+
# languages = Octoprint::Languages.list
|
|
17
|
+
# languages.language_packs.each do |pack_id, pack|
|
|
18
|
+
# puts "#{pack.display}: #{pack.languages.join(', ')}"
|
|
19
|
+
# end
|
|
20
|
+
#
|
|
21
|
+
# @example Upload a new language pack
|
|
22
|
+
# result = Octoprint::Languages.upload("path/to/language-pack.zip")
|
|
23
|
+
# puts "Uploaded #{result.length} language packs"
|
|
24
|
+
# result.each do |pack|
|
|
25
|
+
# puts "- #{pack.display} (#{pack.identifier}): #{pack.languages.join(', ')}"
|
|
26
|
+
# end
|
|
27
|
+
#
|
|
28
|
+
# @example Upload with specific locale
|
|
29
|
+
# result = Octoprint::Languages.upload("french.zip", locale: "fr")
|
|
30
|
+
# puts "Installed French translations for #{result.length} components"
|
|
31
|
+
#
|
|
32
|
+
# @example Remove a language pack
|
|
33
|
+
# Octoprint::Languages.delete_pack(locale: "fr", pack: "_core")
|
|
34
|
+
#
|
|
35
|
+
# Octoprint's API doc: https://docs.octoprint.org/en/1.11.2/api/languages.html
|
|
36
|
+
class Languages < BaseResource
|
|
37
|
+
include AutoInitializable
|
|
38
|
+
include Deserializable
|
|
39
|
+
|
|
40
|
+
resource_path("/api/languages")
|
|
41
|
+
|
|
42
|
+
auto_attr :language_packs, type: Hash, nilable: false
|
|
43
|
+
auto_attr :extra, type: Hash
|
|
44
|
+
|
|
45
|
+
auto_initialize!
|
|
46
|
+
|
|
47
|
+
deserialize_config do
|
|
48
|
+
transform do |data|
|
|
49
|
+
# Transform the hash of pack_id => pack_info into proper objects
|
|
50
|
+
if data[:language_packs].is_a?(Hash)
|
|
51
|
+
data[:language_packs] = data[:language_packs].transform_values do |pack_info|
|
|
52
|
+
LanguagePack.deserialize(pack_info)
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# Fetches the list of available language packs
|
|
59
|
+
#
|
|
60
|
+
# @return [Languages]
|
|
61
|
+
#: -> Languages
|
|
62
|
+
def self.list
|
|
63
|
+
fetch_resource
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
# Uploads a language pack
|
|
67
|
+
#
|
|
68
|
+
# @param [String] file_path The path to the language pack archive to upload
|
|
69
|
+
# @param [String] locale Optional. If provided, forces the locale the pack will be installed under
|
|
70
|
+
#
|
|
71
|
+
# @return [Array<LanguagePack>] List of installed language packs
|
|
72
|
+
#: (
|
|
73
|
+
#| String file_path,
|
|
74
|
+
#| ?locale: String?
|
|
75
|
+
#| ) -> Array[LanguagePack]
|
|
76
|
+
def self.upload(file_path, locale: nil)
|
|
77
|
+
params = {
|
|
78
|
+
file: Faraday::UploadIO.new(file_path, "application/octet-stream")
|
|
79
|
+
}
|
|
80
|
+
params[:locale] = locale if locale
|
|
81
|
+
|
|
82
|
+
result = post(params: params)
|
|
83
|
+
# Handle nested hash structure: {language_packs: {pack_id: pack_info}}
|
|
84
|
+
result[:language_packs].values.map { |pack| LanguagePack.deserialize(pack) }
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
# Deletes a language pack
|
|
88
|
+
#
|
|
89
|
+
# @param [String] locale The locale of the pack to delete
|
|
90
|
+
# @param [String] pack The identifier of the pack to delete
|
|
91
|
+
#
|
|
92
|
+
# @return [T.untyped] 204 No Content on success
|
|
93
|
+
#: (
|
|
94
|
+
#| locale: String,
|
|
95
|
+
#| pack: String
|
|
96
|
+
#| ) -> untyped
|
|
97
|
+
def self.delete_pack(locale:, pack:)
|
|
98
|
+
path = [@path, locale, pack].compact.join("/")
|
|
99
|
+
delete(path: path)
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# typed: true
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
module Octoprint
|
|
5
|
+
# The target location to which to upload the file.
|
|
6
|
+
#
|
|
7
|
+
# Currently only local and sdcard are supported here, with local referring to OctoPrint’s uploads folder and sdcard
|
|
8
|
+
# referring to the printer’s SD card.
|
|
9
|
+
#
|
|
10
|
+
# Octoprint's API doc: https://docs.octoprint.org/en/master/api/files.html
|
|
11
|
+
class Location < T::Enum
|
|
12
|
+
enums do
|
|
13
|
+
Local = new("local")
|
|
14
|
+
SDCard = new("sdcard")
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# @return [String] The location as used in API paths ("local" or "sdcard")
|
|
18
|
+
#: -> String
|
|
19
|
+
def to_s
|
|
20
|
+
@value.to_s
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# typed: true
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
module Octoprint
|
|
5
|
+
class Logs
|
|
6
|
+
# Individual log file representation
|
|
7
|
+
#
|
|
8
|
+
# Represents a single log file on the OctoPrint server with its metadata,
|
|
9
|
+
# including size, modification date, and download/resource references.
|
|
10
|
+
#
|
|
11
|
+
# @example Working with log file information
|
|
12
|
+
# logs = Octoprint::Logs.list
|
|
13
|
+
# log_file = logs.files.first
|
|
14
|
+
#
|
|
15
|
+
# puts log_file.name # => "octoprint.log"
|
|
16
|
+
# puts log_file.size # => 1048576 (in bytes)
|
|
17
|
+
# puts log_file.modification_time # => 2023-12-31 12:00:00 UTC
|
|
18
|
+
# puts log_file.to_s # => "octoprint.log (1048576 bytes, modified: 2023-12-31 12:00:00 UTC)"
|
|
19
|
+
#
|
|
20
|
+
# @example Accessing download and resource URLs
|
|
21
|
+
# log_file = logs.files.first
|
|
22
|
+
# if log_file.refs
|
|
23
|
+
# download_url = log_file.refs.download # Direct download URL
|
|
24
|
+
# resource_url = log_file.refs.resource # API resource URL
|
|
25
|
+
# end
|
|
26
|
+
class LogFile
|
|
27
|
+
include Deserializable
|
|
28
|
+
include AutoInitializable
|
|
29
|
+
|
|
30
|
+
auto_attr :name, type: String, nilable: false
|
|
31
|
+
auto_attr :size, type: Integer, nilable: false
|
|
32
|
+
auto_attr :date, type: Integer, nilable: false
|
|
33
|
+
auto_attr :refs, type: References
|
|
34
|
+
|
|
35
|
+
auto_initialize!
|
|
36
|
+
|
|
37
|
+
# Configure deserialization
|
|
38
|
+
deserialize_config do
|
|
39
|
+
nested :refs, References
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# Returns a human-readable string representation of the log file
|
|
43
|
+
#
|
|
44
|
+
# @return [String]
|
|
45
|
+
#: -> String
|
|
46
|
+
def to_s
|
|
47
|
+
"#{name} (#{size} bytes, modified: #{Time.at(date)})"
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# Convert Unix timestamp to Time object
|
|
51
|
+
#
|
|
52
|
+
# @return [Time] The file date as a Time object
|
|
53
|
+
#: -> Time
|
|
54
|
+
def modification_time
|
|
55
|
+
Time.at(date)
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|