class ForestClient::Forest

Public Class Methods

new(org_id) click to toggle source
# File lib/forest-client.rb, line 17
def initialize(org_id)
    @org_id = org_id
end

Public Instance Methods

api_call(url) click to toggle source
# File lib/forest-client.rb, line 9
def api_call(url)
    url = "https://forest-api.herokuapp.com/api/#{url}"
    url = URI.escape(url)
    url = URI.parse(url)
    content = Net::HTTP.get(url)
    return JSON.parse(content)
end
get_printer(id) click to toggle source
# File lib/forest-client.rb, line 27
def get_printer(id)
    url = "printerGet?organizationId=#{@org_id}&printerId=#{id}"
    printer = api_call(url)
    return printer
end
get_printers() click to toggle source
# File lib/forest-client.rb, line 21
def get_printers
    url = "printerList?organizationId=#{@org_id}"
    printers = api_call(url)
    return printers['printers']
end
update_printer(printer) click to toggle source
# File lib/forest-client.rb, line 33
def update_printer(printer)
    id = printer['id']
    ip = printer['ipAddress']

    p = Printer.new(ip)
    url = 'printerUpdate'
    url += '?printerId=' + id
    url += '&model=' + p.get_model
    url += '&location=' + p.get_location
    url += '&serial=' + p.get_serial
    api_call(url)
    return
end
update_status(printer) click to toggle source
# File lib/forest-client.rb, line 47
def update_status(printer)
    id = printer['id']
    ip = printer['ipAddress']
    p = Printer.new(ip)

    url = 'statusCreate'
    url += '?printerId=' + id
    url += '&status=' + p.get_status
    url += '&pageCount=' + p.get_page_count.to_s

    trays = Array.new

    t = p.get_trays
    if t
        t.each { |tray|
            trays.push({
                'name' => tray[:name],
                'xdim' => tray[:x],
                'ydim' => tray[:y],
                'capacity' => tray[:capacity]
            })
        }
    end

    url += '&trays=' + trays.to_s.gsub!('=>', ':')

    consumables = Array.new

    c = p.get_consumables
    if c
        c.each { |cons|
            consumables.push({
                'name' => cons[:name],
                'level' => cons[:level],
                'capacity' => cons[:capacity],
                'percentage' => cons[:percentage]
             })
        }
    end

    url += '&consumables=' + consumables.to_s.gsub!('=>', ':')

    api_call url
end