Class: QMachineClient

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/qm/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {mothership: 'https://api.qmachine.org'}) ⇒ QMachineClient

Returns a new instance of QMachineClient.



28
29
30
31
32
# 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

Instance Method Details

#get_avar(opts = {}) ⇒ Object



34
35
36
37
38
39
40
41
# 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 = {}) ⇒ Object



43
44
45
46
47
48
49
50
# 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 = {}) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
# 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

#uuidObject



64
65
66
67
68
69
70
71
# 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