Class: Print::MoonrakerService

Inherits:
Object
  • Object
show all
Defined in:
app/services/print/moonraker_service.rb

Constant Summary collapse

PROTOCOL =

i18n-tasks-use t("print_hosts.protocols.moonraker")

"moonraker".freeze
INPUT_TYPES =
[Mime[:gcode]].freeze

Instance Method Summary collapse

Constructor Details

#initialize(print_host:) ⇒ MoonrakerService

Returns a new instance of MoonrakerService.



10
11
12
# File 'app/services/print/moonraker_service.rb', line 10

def initialize(print_host:)
  @print_host = print_host
end

Instance Method Details

#ok? ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
17
18
19
20
# File 'app/services/print/moonraker_service.rb', line 14

def ok?
  response = connection.get(info_uri, {}, headers)
  Rails.logger.warn(response.inspect) unless response.success?
  response.success?
rescue
  false
end

#upload(file:, start_print: true) ⇒ Object

Raises:

  • (ArgumentError)


22
23
24
25
26
27
28
# File 'app/services/print/moonraker_service.rb', line 22

def upload(file:, start_print: true)
  raise ArgumentError unless file.mime_type.in? INPUT_TYPES
  raise PrintHost::NotReady unless ok?
  response = connection.post(upload_uri, payload(file: file, start_print: start_print), headers)
  Rails.logger.warn(response.inspect) unless response.success?
  response.success?
end