class QMachineClient

Public Class Methods

new(options = {mothership: 'https://api.qmachine.org'}) click to toggle source
# File lib/qm/client.rb, line 28
def initialize(options = {mothership: 'https://api.qmachine.org'})
  # This method runs when Ruby calls `QMachineClient.new`.
    @ms = options[:mothership]
    return
end

Public Instance Methods

get_avar(opts = {}) click to toggle source
# File lib/qm/client.rb, line 34
def get_avar(opts = {})
  # This method needs documentation.
    res = self.class.get("#{@ms}/box/#{opts[:box]}?key=#{opts[:key]}")
    if (res.code != 200) then
        raise "Error: #{res.code}"
    end
    return JSON.parse(res.body)
end
get_list(opts = {}) click to toggle source
# File lib/qm/client.rb, line 43
def get_list(opts = {})
  # This method needs documentation.
    res = self.class.get("#{@ms}/box/#{opts[:box]}?status=#{opts[:status]}")
    if (res.code != 200) then
        raise "Error: #{res.code}"
    end
    return JSON.parse(res.body)
end
set_avar(opts = {}) click to toggle source
# File lib/qm/client.rb, line 52
def set_avar(opts = {})
  # This method needs documentation.
    res = self.class.post("#{@ms}/box/#{opts[:box]}?key=#{opts[:key]}", {
        body: opts.to_json,
        headers: {'Content-Type' => 'application/json'}
    })
    if (res.code != 201) then
        raise "Error: #{res.code}"
    end
    return res.body
end
uuid() click to toggle source
# File lib/qm/client.rb, line 64
def uuid()
  # This method needs documentation.
    y = ''
    while (y.length < 32) do
        y += rand.to_s[/[0-9]+(?!.)/].to_i.to_s(16)
    end
    return y.slice(0, 32)
end