Sha256: 94e36a62b0933898962497b8e1085054a8dab5bdf0f7b16181f811d309e25d26

Contents?: true

Size: 1.41 KB

Versions: 1

Compression:

Stored size: 1.41 KB

Contents

# frozen_string_literal: true

module EatabitRails
  class Printer
    attr_reader(
      :id,
      :name,
      :enabled,
      :pickup_minutes,
      :delivery_minutes,
      :state,
      :online,
      :paper,
      :fulfillment,
      :sound,
      :light,
      :autoprint
    )

    def initialize(attributes)
      @id = attributes['id']
      @name = attributes['name']
      @enabled = attributes['enabled']
      @pickup_minutes = attributes['pickup_minutes']
      @delivery_minutes = attributes['delivery_minutes']
      @state = attributes['state']
      @online = attributes['online']
      @paper = attributes['paper']
      @fulfillment = attributes['fulfillment']
      @sound = attributes['sound']
      @light = attributes['light']
      @autoprint = attributes['autoprint']
    end

    def self.find(id)
      printer_uri = EatabitRails::REST::Uri.new.printer(id)
      params = EatabitRails::REST::Uri.default_params
      response = RestClient.get(printer_uri, params)
      attributes = JSON.parse(response.body)['printer']

      new(attributes)
    end

    def self.update(id, printer_attributes)
      printer_uri = EatabitRails::REST::Uri.new.printer(id)
      params = EatabitRails::REST::Uri.default_params
      response = RestClient.put(
        printer_uri,
        params.merge!(printer_attributes)
      )
      attributes = JSON.parse(response.body)['printer']

      new(attributes)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
eatabit_rails-0.2.1 lib/eatabit_rails/printer.rb