Class: Print::OdysseyService
- Inherits:
-
Object
- Object
- Print::OdysseyService
- Defined in:
- app/services/print/odyssey_service.rb
Constant Summary collapse
- PROTOCOL =
i18n-tasks-use t("print_hosts.protocols.odyssey")
"odyssey".freeze
- INPUT_TYPES =
[Mime[:sl1]].freeze
Instance Method Summary collapse
-
#initialize(print_host:) ⇒ OdysseyService
constructor
A new instance of OdysseyService.
- #ok? ⇒ Boolean
- #print(file:) ⇒ Object
- #upload(file:, start_print: true) ⇒ Object
Constructor Details
#initialize(print_host:) ⇒ OdysseyService
Returns a new instance of OdysseyService.
10 11 12 |
# File 'app/services/print/odyssey_service.rb', line 10 def initialize(print_host:) @print_host = print_host end |
Instance Method Details
#ok? ⇒ Boolean
14 15 16 17 18 19 20 21 |
# File 'app/services/print/odyssey_service.rb', line 14 def ok? response = connection.get(info_uri, {}, {}) Rails.logger.warn(response.inspect) unless response.success? response.success? rescue => ex Rails.logger.warn(ex.) false end |
#print(file:) ⇒ Object
36 37 38 39 |
# File 'app/services/print/odyssey_service.rb', line 36 def print(file:) response = Faraday.new.post("#{@print_host.endpoint}/print/start?filename=#{CGI.escapeURIComponent(file.filename)}") Rails.logger.warn(response.inspect) unless response.success? end |
#upload(file:, start_print: true) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'app/services/print/odyssey_service.rb', line 23 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) ) Rails.logger.warn(response.inspect) unless response.success? uploaded = response.success? print(file: file) if start_print uploaded end |