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.
Files changed (122) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +10 -0
  3. data/LICENSE.txt +21 -0
  4. data/README.md +336 -0
  5. data/lib/octoprint/access/group.rb +88 -0
  6. data/lib/octoprint/access/groups.rb +166 -0
  7. data/lib/octoprint/access/login_response.rb +63 -0
  8. data/lib/octoprint/access/permission.rb +71 -0
  9. data/lib/octoprint/access/permissions.rb +29 -0
  10. data/lib/octoprint/access/user.rb +95 -0
  11. data/lib/octoprint/access/users.rb +347 -0
  12. data/lib/octoprint/auto_initializable.rb +219 -0
  13. data/lib/octoprint/base_resource.rb +139 -0
  14. data/lib/octoprint/client.rb +151 -0
  15. data/lib/octoprint/connection/options.rb +44 -0
  16. data/lib/octoprint/connection/settings.rb +35 -0
  17. data/lib/octoprint/connection.rb +74 -0
  18. data/lib/octoprint/deserializable.rb +483 -0
  19. data/lib/octoprint/exceptions.rb +30 -0
  20. data/lib/octoprint/files/file.rb +55 -0
  21. data/lib/octoprint/files/folder.rb +29 -0
  22. data/lib/octoprint/files/operation_result.rb +37 -0
  23. data/lib/octoprint/files/refs.rb +19 -0
  24. data/lib/octoprint/files.rb +238 -0
  25. data/lib/octoprint/job/information.rb +42 -0
  26. data/lib/octoprint/job/progress.rb +46 -0
  27. data/lib/octoprint/job.rb +140 -0
  28. data/lib/octoprint/languages/language_pack.rb +31 -0
  29. data/lib/octoprint/languages.rb +102 -0
  30. data/lib/octoprint/location.rb +23 -0
  31. data/lib/octoprint/logs/log_file.rb +59 -0
  32. data/lib/octoprint/logs/references.rb +28 -0
  33. data/lib/octoprint/logs.rb +98 -0
  34. data/lib/octoprint/printer/bed.rb +32 -0
  35. data/lib/octoprint/printer/chamber.rb +29 -0
  36. data/lib/octoprint/printer/command.rb +129 -0
  37. data/lib/octoprint/printer/custom_control/input.rb +45 -0
  38. data/lib/octoprint/printer/custom_control.rb +119 -0
  39. data/lib/octoprint/printer/error_information.rb +104 -0
  40. data/lib/octoprint/printer/heater.rb +113 -0
  41. data/lib/octoprint/printer/history_query.rb +25 -0
  42. data/lib/octoprint/printer/printhead.rb +105 -0
  43. data/lib/octoprint/printer/sd.rb +97 -0
  44. data/lib/octoprint/printer/state.rb +41 -0
  45. data/lib/octoprint/printer/state_flags.rb +70 -0
  46. data/lib/octoprint/printer/temperature_attributes.rb +70 -0
  47. data/lib/octoprint/printer/temperature_data.rb +53 -0
  48. data/lib/octoprint/printer/temperature_data_point.rb +73 -0
  49. data/lib/octoprint/printer/temperature_reading.rb +47 -0
  50. data/lib/octoprint/printer/temperature_state.rb +67 -0
  51. data/lib/octoprint/printer/tool.rb +154 -0
  52. data/lib/octoprint/printer.rb +126 -0
  53. data/lib/octoprint/printer_profiles/printer_profile.rb +40 -0
  54. data/lib/octoprint/printer_profiles.rb +158 -0
  55. data/lib/octoprint/server_information.rb +51 -0
  56. data/lib/octoprint/server_version.rb +52 -0
  57. data/lib/octoprint/settings/webcam.rb +135 -0
  58. data/lib/octoprint/settings.rb +133 -0
  59. data/lib/octoprint/slicing/profile.rb +65 -0
  60. data/lib/octoprint/slicing/slicer.rb +83 -0
  61. data/lib/octoprint/slicing.rb +227 -0
  62. data/lib/octoprint/system_commands/command.rb +41 -0
  63. data/lib/octoprint/system_commands.rb +110 -0
  64. data/lib/octoprint/timelapse/config.rb +68 -0
  65. data/lib/octoprint/timelapse/file_attributes.rb +50 -0
  66. data/lib/octoprint/timelapse/rendered.rb +51 -0
  67. data/lib/octoprint/timelapse/unrendered.rb +43 -0
  68. data/lib/octoprint/timelapse.rb +221 -0
  69. data/lib/octoprint/types.rb +140 -0
  70. data/lib/octoprint/util.rb +151 -0
  71. data/lib/octoprint/version.rb +7 -0
  72. data/lib/octoprint/wizard.rb +57 -0
  73. data/lib/octoprint.rb +57 -0
  74. data/rbi/octoprint/access/group.rbi +46 -0
  75. data/rbi/octoprint/access/login_response.rbi +22 -0
  76. data/rbi/octoprint/access/permission.rbi +34 -0
  77. data/rbi/octoprint/access/user.rbi +43 -0
  78. data/rbi/octoprint/connection/options.rbi +28 -0
  79. data/rbi/octoprint/connection/settings.rbi +19 -0
  80. data/rbi/octoprint/connection.rbi +13 -0
  81. data/rbi/octoprint/files/file.rbi +61 -0
  82. data/rbi/octoprint/files/folder.rbi +22 -0
  83. data/rbi/octoprint/files/operation_result.rbi +22 -0
  84. data/rbi/octoprint/files/refs.rbi +16 -0
  85. data/rbi/octoprint/job/information.rbi +22 -0
  86. data/rbi/octoprint/job/progress.rbi +25 -0
  87. data/rbi/octoprint/job.rbi +22 -0
  88. data/rbi/octoprint/languages/language_pack.rbi +19 -0
  89. data/rbi/octoprint/languages.rbi +13 -0
  90. data/rbi/octoprint/logs/log_file.rbi +19 -0
  91. data/rbi/octoprint/logs/references.rbi +13 -0
  92. data/rbi/octoprint/logs.rbi +13 -0
  93. data/rbi/octoprint/printer/bed.rbi +22 -0
  94. data/rbi/octoprint/printer/chamber.rbi +22 -0
  95. data/rbi/octoprint/printer/custom_control/input.rbi +22 -0
  96. data/rbi/octoprint/printer/custom_control.rbi +67 -0
  97. data/rbi/octoprint/printer/error_information.rbi +25 -0
  98. data/rbi/octoprint/printer/sd.rbi +13 -0
  99. data/rbi/octoprint/printer/state.rbi +19 -0
  100. data/rbi/octoprint/printer/state_flags.rbi +43 -0
  101. data/rbi/octoprint/printer/temperature_data.rbi +19 -0
  102. data/rbi/octoprint/printer/temperature_data_point.rbi +22 -0
  103. data/rbi/octoprint/printer/temperature_reading.rbi +19 -0
  104. data/rbi/octoprint/printer/temperature_state.rbi +22 -0
  105. data/rbi/octoprint/printer/tool.rbi +22 -0
  106. data/rbi/octoprint/printer.rbi +19 -0
  107. data/rbi/octoprint/printer_profiles/printer_profile.rbi +46 -0
  108. data/rbi/octoprint/printer_profiles.rbi +13 -0
  109. data/rbi/octoprint/server_information.rbi +16 -0
  110. data/rbi/octoprint/server_version.rbi +19 -0
  111. data/rbi/octoprint/settings/webcam.rbi +34 -0
  112. data/rbi/octoprint/slicing/profile.rbi +28 -0
  113. data/rbi/octoprint/slicing/slicer.rbi +31 -0
  114. data/rbi/octoprint/system_commands/command.rbi +25 -0
  115. data/rbi/octoprint/system_commands.rbi +16 -0
  116. data/rbi/octoprint/timelapse/config.rbi +31 -0
  117. data/rbi/octoprint/timelapse/rendered.rbi +31 -0
  118. data/rbi/octoprint/timelapse/unrendered.rbi +34 -0
  119. data/rbi/octoprint/timelapse.rbi +22 -0
  120. data/rbi/octoprint/util.rbi +19 -0
  121. data/rbi/octoprint.rbi +1848 -0
  122. metadata +264 -0
@@ -0,0 +1,52 @@
1
+ # typed: true
2
+ # frozen_string_literal: true
3
+
4
+ module Octoprint
5
+ # Version information about the OctoPrint server.
6
+ #
7
+ # @example Get server version
8
+ # version = Octoprint::ServerVersion.get
9
+ # puts "API: #{version.api}"
10
+ # puts "Server: #{version.server}"
11
+ # puts "Text: #{version.text}"
12
+ #
13
+ # @see https://docs.octoprint.org/en/master/api/version.html
14
+ class ServerVersion < BaseResource
15
+ include AutoInitializable
16
+ include Deserializable
17
+
18
+ resource_path("/api/version")
19
+
20
+ # @!attribute [r] api
21
+ # @return [String] The server's API version
22
+ auto_attr :api, type: String, nilable: false
23
+
24
+ # @!attribute [r] server
25
+ # @return [String] The server's version number
26
+ auto_attr :server, type: String, nilable: false
27
+
28
+ # @!attribute [r] text
29
+ # @return [String] Server version including the prefix "OctoPrint"
30
+ auto_attr :text, type: String, nilable: false
31
+
32
+ # @!attribute [r] extra
33
+ # @return [Hash] Any additional fields returned by the API
34
+ auto_attr :extra, type: Hash
35
+
36
+ auto_initialize!
37
+
38
+ # Retrieve information regarding server and API version.
39
+ #
40
+ # @example Get server version
41
+ # version = Octoprint::ServerVersion.get
42
+ # puts "API: #{version.api}"
43
+ # puts "Server: #{version.server}"
44
+ #
45
+ # @return [ServerVersion] Version information object
46
+ # @raise [Octoprint::Exceptions::Error] if the request fails
47
+ #: -> ServerVersion
48
+ def self.get
49
+ fetch_resource
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,135 @@
1
+ # typed: true
2
+ # frozen_string_literal: true
3
+
4
+ module Octoprint
5
+ class Settings
6
+ # Typed view of the webcam part of the OctoPrint settings.
7
+ #
8
+ # OctoPrint 1.9 added support for several webcams, provided by plugins. The
9
+ # settings then list them under `webcam.webcams` and name the default one in
10
+ # `webcam.defaultWebcam`. Older servers only expose the legacy flat keys
11
+ # (`webcam.streamUrl`, `webcam.snapshotUrl`, ...). This class reads the
12
+ # multi-webcam shape when it is present and falls back to the legacy keys.
13
+ #
14
+ # @example Get the webcam settings
15
+ # webcam = Octoprint::Settings.webcam
16
+ # puts webcam.stream_url if webcam.enabled
17
+ #
18
+ # @example Build it from settings you already fetched
19
+ # settings = Octoprint::Settings.get
20
+ # webcam = Octoprint::Settings::Webcam.from_settings(settings)
21
+ #
22
+ # @see https://docs.octoprint.org/en/master/api/settings.html
23
+ class Webcam
24
+ include AutoInitializable
25
+
26
+ # @!attribute [r] enabled
27
+ # @return [Boolean] Whether the webcam is enabled in the OctoPrint settings
28
+ auto_attr :enabled, type: T::Boolean, nilable: false
29
+
30
+ # @!attribute [r] stream_url
31
+ # @return [String, nil] URL of the webcam stream. Can be relative to the OctoPrint host
32
+ # (e.g. "/webcam/?action=stream"). nil when no stream is configured.
33
+ auto_attr :stream_url, type: String
34
+
35
+ # @!attribute [r] snapshot_url
36
+ # @return [String, nil] URL to fetch a still image from the webcam. nil when not configured.
37
+ auto_attr :snapshot_url, type: String
38
+
39
+ # @!attribute [r] name
40
+ # @return [String, nil] Identifier of the webcam (OctoPrint 1.9+ only)
41
+ auto_attr :name, type: String
42
+
43
+ # @!attribute [r] display_name
44
+ # @return [String, nil] Human readable name of the webcam (OctoPrint 1.9+ only)
45
+ auto_attr :display_name, type: String
46
+
47
+ # @!attribute [r] flip_h
48
+ # @return [Boolean, nil] Whether the image should be flipped horizontally
49
+ auto_attr :flip_h, type: T::Boolean
50
+
51
+ # @!attribute [r] flip_v
52
+ # @return [Boolean, nil] Whether the image should be flipped vertically
53
+ auto_attr :flip_v, type: T::Boolean
54
+
55
+ # @!attribute [r] rotate90
56
+ # @return [Boolean, nil] Whether the image should be rotated 90° counter-clockwise
57
+ auto_attr :rotate90, type: T::Boolean
58
+
59
+ # @!attribute [r] stream_ratio
60
+ # @return [String, nil] Aspect ratio of the stream ("16:9" or "4:3")
61
+ auto_attr :stream_ratio, type: String
62
+
63
+ auto_initialize!
64
+
65
+ # Builds the webcam settings from the hash returned by {Settings.get}.
66
+ #
67
+ # Uses the default webcam from the OctoPrint 1.9+ `webcams` list when there is
68
+ # one (or the first webcam if the default can't be found), and only falls back to
69
+ # the legacy `webcam` keys when the server has no `webcams` list. Empty URLs are
70
+ # returned as nil.
71
+ #
72
+ # @example
73
+ # settings = Octoprint::Settings.get
74
+ # webcam = Octoprint::Settings::Webcam.from_settings(settings)
75
+ #
76
+ # @param settings [Hash] The settings hash, as returned by {Settings.get}
77
+ # @return [Webcam]
78
+ #: (Hash[Symbol, untyped] settings) -> Webcam
79
+ def self.from_settings(settings)
80
+ legacy = settings[:webcam] || {}
81
+ camera = default_webcam(legacy)
82
+ attributes = camera ? webcam_attributes(camera) : legacy_attributes(legacy)
83
+
84
+ T.unsafe(self).new(enabled: legacy.fetch(:webcam_enabled) { attributes[:stream_url].present? }, **attributes)
85
+ end
86
+
87
+ # Picks the default webcam from the OctoPrint 1.9+ `webcams` list.
88
+ #
89
+ # @param legacy [Hash] The `webcam` section of the settings
90
+ # @return [Hash, nil] The default webcam's settings, or nil when there is no `webcams` list
91
+ #: (Hash[Symbol, untyped] legacy) -> Hash[Symbol, untyped]?
92
+ def self.default_webcam(legacy)
93
+ webcams = Array(legacy[:webcams])
94
+ webcams.find { |webcam| webcam[:name] == legacy[:default_webcam] } || webcams.first
95
+ end
96
+
97
+ # Reads the attributes of a webcam from the OctoPrint 1.9+ `webcams` list.
98
+ #
99
+ # The stream is only available for webcams that provide `compat` settings (or a
100
+ # stream in their `extras`, like the classic webcam). `snapshotDisplay` is only
101
+ # used when it is an HTTP URL, since plugins can put any text in it.
102
+ #
103
+ # @param camera [Hash] A webcam from the `webcams` list
104
+ # @return [Hash] The attributes of the webcam
105
+ #: (Hash[Symbol, untyped] camera) -> Hash[Symbol, untyped]
106
+ def self.webcam_attributes(camera)
107
+ compat = camera[:compat] || {}
108
+ extras = camera[:extras] || {}
109
+ snapshot_display = camera[:snapshot_display] if camera[:snapshot_display].to_s.match?(%r{\Ahttps?://}i)
110
+
111
+ {
112
+ stream_url: (compat[:stream] || extras[:stream]).presence,
113
+ snapshot_url: (compat[:snapshot] || snapshot_display).presence,
114
+ stream_ratio: compat[:stream_ratio] || extras[:stream_ratio],
115
+ **camera.slice(:name, :display_name, :flip_h, :flip_v, :rotate90)
116
+ }
117
+ end
118
+
119
+ # Reads the attributes from the legacy `webcam` keys of OctoPrint < 1.9.
120
+ #
121
+ # @param legacy [Hash] The `webcam` section of the settings
122
+ # @return [Hash] The attributes of the webcam
123
+ #: (Hash[Symbol, untyped] legacy) -> Hash[Symbol, untyped]
124
+ def self.legacy_attributes(legacy)
125
+ {
126
+ stream_url: legacy[:stream_url].presence,
127
+ snapshot_url: legacy[:snapshot_url].presence,
128
+ **legacy.slice(:stream_ratio, :flip_h, :flip_v, :rotate90)
129
+ }
130
+ end
131
+
132
+ private_class_method :default_webcam, :webcam_attributes, :legacy_attributes
133
+ end
134
+ end
135
+ end
@@ -0,0 +1,133 @@
1
+ # typed: true
2
+ # frozen_string_literal: true
3
+
4
+ module Octoprint
5
+ # The Settings API allows retrieval and saving of OctoPrint settings,
6
+ # regeneration of the system-wide API key, and fetching template data.
7
+ #
8
+ # @see https://docs.octoprint.org/en/1.11.2/api/settings.html OctoPrint Settings API Documentation
9
+ #
10
+ # @example Get current settings
11
+ # settings = Octoprint::Settings.get
12
+ # puts settings[:appearance][:name]
13
+ #
14
+ # @example Update settings
15
+ # Octoprint::Settings.save(appearance: { color: "blue" })
16
+ #
17
+ # @example Regenerate API key
18
+ # new_key = Octoprint::Settings.regenerate_api_key
19
+ # puts "New API key: #{new_key}"
20
+ class Settings < BaseResource
21
+ resource_path("/api/settings")
22
+
23
+ # Retrieves the current settings from the OctoPrint server.
24
+ #
25
+ # This method fetches all current OctoPrint settings. The response is returned
26
+ # as a Hash containing the entire settings structure.
27
+ #
28
+ # @example Get current settings
29
+ # settings = Octoprint::Settings.get
30
+ #
31
+ # # Access appearance settings
32
+ # puts settings[:appearance][:name]
33
+ #
34
+ # # Access feature flags
35
+ # puts settings[:feature][:temperature_graph]
36
+ #
37
+ # @return [Hash] The current settings as a hash
38
+ # @raise [Octoprint::Exceptions::Error] if the request fails
39
+ # @raise [Octoprint::Exceptions::AuthenticationError] if lacking SETTINGS_READ permission
40
+ #: -> Hash[Symbol, untyped]
41
+ def self.get
42
+ fetch_resource(deserialize: false)
43
+ end
44
+
45
+ # Retrieves the webcam settings as a typed object.
46
+ #
47
+ # Handles both the multi-webcam settings shape of OctoPrint 1.9+ and the legacy
48
+ # `webcam` keys of older versions. See {Settings::Webcam.from_settings} to build
49
+ # it from a settings hash you already fetched.
50
+ #
51
+ # @example Get the webcam stream URL
52
+ # webcam = Octoprint::Settings.webcam
53
+ # puts webcam.stream_url if webcam.enabled
54
+ #
55
+ # @return [Settings::Webcam] The webcam settings
56
+ # @raise [Octoprint::Exceptions::Error] if the request fails
57
+ # @raise [Octoprint::Exceptions::AuthenticationError] if lacking SETTINGS_READ permission
58
+ #: -> Settings::Webcam
59
+ def self.webcam
60
+ Webcam.from_settings(get)
61
+ end
62
+
63
+ # Saves settings to the OctoPrint server.
64
+ #
65
+ # This method updates OctoPrint settings with the provided values.
66
+ # You can provide either a full settings object or partial updates.
67
+ # The server will merge the provided settings with existing ones.
68
+ #
69
+ # @example Update appearance settings
70
+ # updated = Octoprint::Settings.save(
71
+ # appearance: {
72
+ # color: "blue",
73
+ # name: "My OctoPrint"
74
+ # }
75
+ # )
76
+ #
77
+ # @example Update multiple settings
78
+ # updated = Octoprint::Settings.save(
79
+ # appearance: { color: "green" },
80
+ # feature: { temperature_graph: false }
81
+ # )
82
+ #
83
+ # @param settings [Hash] The settings to update (can be partial)
84
+ # @return [Hash] The updated settings
85
+ # @raise [Octoprint::Exceptions::Error] if the request fails
86
+ # @raise [Octoprint::Exceptions::AuthenticationError] if lacking SETTINGS permission
87
+ #: (Hash[Symbol, untyped] settings) -> Hash[Symbol, untyped]
88
+ def self.save(settings)
89
+ post(params: settings)
90
+ end
91
+
92
+ # Regenerates the system-wide API key.
93
+ #
94
+ # This method generates a new system-wide API key. This requires admin rights.
95
+ # Note that after calling this method, the current API key will be invalidated
96
+ # and you'll need to use the new key for subsequent requests.
97
+ #
98
+ # @example Regenerate API key
99
+ # result = Octoprint::Settings.regenerate_api_key
100
+ # new_key = result[:api_key]
101
+ # puts "New API key: #{new_key}"
102
+ #
103
+ # @return [Hash] Hash containing the new API key ({ api_key: "new_key_value" })
104
+ # @raise [Octoprint::Exceptions::Error] if the request fails
105
+ # @raise [Octoprint::Exceptions::AuthenticationError] if lacking admin rights
106
+ #: -> Hash[Symbol, String]
107
+ def self.regenerate_api_key
108
+ post(path: "/api/settings/apikey")
109
+ end
110
+
111
+ # Fetches template data from the OctoPrint server.
112
+ #
113
+ # This method retrieves template component identifiers used by OctoPrint's UI.
114
+ # This requires admin rights and is primarily used for UI customization.
115
+ #
116
+ # Note: This endpoint is marked as beta in the OctoPrint API and may be subject
117
+ # to changes in future versions.
118
+ #
119
+ # @example Fetch template data
120
+ # templates = Octoprint::Settings.fetch_templates
121
+ # templates.each do |component, identifiers|
122
+ # puts "#{component}: #{identifiers.inspect}"
123
+ # end
124
+ #
125
+ # @return [Hash] Template component identifiers
126
+ # @raise [Octoprint::Exceptions::Error] if the request fails
127
+ # @raise [Octoprint::Exceptions::AuthenticationError] if lacking admin rights
128
+ #: -> Hash[Symbol, untyped]
129
+ def self.fetch_templates
130
+ fetch_resource("templates", deserialize: false)
131
+ end
132
+ end
133
+ end
@@ -0,0 +1,65 @@
1
+ # typed: true
2
+ # frozen_string_literal: true
3
+
4
+ module Octoprint
5
+ class Slicing
6
+ # A slicing profile of a slicer.
7
+ #
8
+ # Profiles returned in lists ({Slicing.list}, {Slicing.profiles}) don't include
9
+ # the profile's {#data}. Use {Slicing.get_profile} to retrieve it.
10
+ #
11
+ # @example Read a profile
12
+ # profile = Octoprint::Slicing.get_profile(slicer: "curalegacy", key: "high_quality")
13
+ # profile.key # => "high_quality"
14
+ # profile.display_name # => "High Quality"
15
+ # profile.default? # => false
16
+ # profile.data # => { layer_height: 0.1, ... }
17
+ #
18
+ # @see https://docs.octoprint.org/en/1.11.2/api/slicing.html#profile
19
+ class Profile
20
+ include Deserializable
21
+ include AutoInitializable
22
+
23
+ # @!attribute [r] key
24
+ # @return [String] The profile's identifier
25
+ auto_attr :key, type: String, nilable: false
26
+
27
+ # @!attribute [r] display_name
28
+ # @return [String, nil] The profile's human-readable name
29
+ auto_attr :display_name, type: String
30
+
31
+ # @!attribute [r] description
32
+ # @return [String, nil] The profile's description
33
+ auto_attr :description, type: String
34
+
35
+ # @!attribute [r] default
36
+ # @return [Boolean, nil] Whether this is the default profile of its slicer
37
+ auto_attr :default, type: T::Boolean
38
+
39
+ # @!attribute [r] resource
40
+ # @return [String, nil] The URL of the profile's API resource
41
+ auto_attr :resource, type: String
42
+
43
+ # @!attribute [r] data
44
+ # @return [Hash, nil] The slicer-specific profile settings. Only included by {Slicing.get_profile}
45
+ auto_attr :data, type: Hash
46
+
47
+ # @!attribute [r] extra
48
+ # @return [Hash, nil] Any additional fields returned by the API
49
+ auto_attr :extra, type: Hash
50
+
51
+ auto_initialize!
52
+
53
+ # Whether this is the default profile of its slicer.
54
+ #
55
+ # @example
56
+ # Octoprint::Slicing.get_profile(slicer: "curalegacy", key: "high_quality").default? # => false
57
+ #
58
+ # @return [Boolean] false when {#default} is nil
59
+ #: -> bool
60
+ def default?
61
+ default == true
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,83 @@
1
+ # typed: true
2
+ # frozen_string_literal: true
3
+
4
+ module Octoprint
5
+ class Slicing
6
+ # A slicer registered on the OctoPrint server, with its slicing profiles.
7
+ #
8
+ # @example Inspect a slicer
9
+ # slicer = Octoprint::Slicing.list[:curalegacy]
10
+ # slicer.key # => "curalegacy"
11
+ # slicer.display_name # => "CuraEngine Legacy"
12
+ # slicer.configured? # => true
13
+ # slicer.profiles.keys # => [:high_quality, :normal_quality]
14
+ #
15
+ # @see https://docs.octoprint.org/en/1.11.2/api/slicing.html#slicer
16
+ class Slicer
17
+ include Deserializable
18
+ include AutoInitializable
19
+
20
+ # @!attribute [r] key
21
+ # @return [String] The slicer's identifier
22
+ auto_attr :key, type: String, nilable: false
23
+
24
+ # @!attribute [r] display_name
25
+ # @return [String, nil] The slicer's human-readable name
26
+ auto_attr :display_name, type: String
27
+
28
+ # @!attribute [r] default
29
+ # @return [Boolean, nil] Whether this is the default slicer
30
+ auto_attr :default, type: T::Boolean
31
+
32
+ # @!attribute [r] configured
33
+ # @return [Boolean, nil] Whether the slicer is configured and ready to slice
34
+ auto_attr :configured, type: T::Boolean
35
+
36
+ # @!attribute [r] same_device
37
+ # @return [Boolean, nil] Whether the slicer runs on the same device as OctoPrint
38
+ auto_attr :same_device, type: T::Boolean
39
+
40
+ # @!attribute [r] extensions
41
+ # @return [Hash, nil] The file extensions the slicer accepts (+:source+) and produces (+:destination+)
42
+ auto_attr :extensions, type: Hash
43
+
44
+ # @!attribute [r] profiles
45
+ # @return [Hash{Symbol => Profile}] The slicer's profiles, by key. Profiles don't include their data
46
+ auto_attr :profiles, type: Hash, nilable: false
47
+
48
+ # @!attribute [r] extra
49
+ # @return [Hash, nil] Any additional fields returned by the API
50
+ auto_attr :extra, type: Hash
51
+
52
+ auto_initialize!
53
+
54
+ deserialize_config do
55
+ transform do |data|
56
+ data[:profiles] = Slicing.deserialize_profiles(data[:profiles])
57
+ end
58
+ end
59
+
60
+ # Whether this is the default slicer.
61
+ #
62
+ # @example
63
+ # Octoprint::Slicing.list[:curalegacy].default? # => true
64
+ #
65
+ # @return [Boolean] false when {#default} is nil
66
+ #: -> bool
67
+ def default?
68
+ default == true
69
+ end
70
+
71
+ # Whether the slicer is configured and ready to slice.
72
+ #
73
+ # @example
74
+ # Octoprint::Slicing.list[:curalegacy].configured? # => false
75
+ #
76
+ # @return [Boolean] false when {#configured} is nil
77
+ #: -> bool
78
+ def configured?
79
+ configured == true
80
+ end
81
+ end
82
+ end
83
+ end