Class: Geewiz::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/geewiz/client.rb

Overview

Client class for interacting with Geewiz.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input: $stdin, output: $stdout) ⇒ Client

Returns a new instance of Client.



6
7
8
9
10
11
# File 'lib/geewiz/client.rb', line 6

def initialize(input: $stdin, output: $stdout)
  @input = input
  @output = output
  @output.sync = true
  @vars = VarCache.new(self)
end

Instance Attribute Details

#varsObject (readonly)

Returns the value of attribute vars.



4
5
6
# File 'lib/geewiz/client.rb', line 4

def vars
  @vars
end

Instance Method Details

#card(id = nil, vars: {}, **params) ⇒ Object



29
30
31
32
33
# File 'lib/geewiz/client.rb', line 29

def card(id = nil, vars: {}, **params)
  vars.each { |name, value| var(name, value) }
  command "card", **params, **(id ? { id: id } : {}), responseFormat: "json"
  read_response
end

#command(type, **params) ⇒ Object



13
14
15
# File 'lib/geewiz/client.rb', line 13

def command(type, **params)
  @output.print "@#{[type, params].to_json}\n"
end

#get_user_config(key) ⇒ Object



35
36
37
38
# File 'lib/geewiz/client.rb', line 35

def get_user_config(key)
  command "get-user-config", key: key, responseFormat: "json"
  read_response
end

#readObject



17
18
19
# File 'lib/geewiz/client.rb', line 17

def read
  @input.readline
end

#read_responseObject



21
22
23
# File 'lib/geewiz/client.rb', line 21

def read_response
  JSON.parse(read)
end

#set(**options) ⇒ Object



25
26
27
# File 'lib/geewiz/client.rb', line 25

def set(**options)
  command("set", **options)
end

#var(name, value) ⇒ Object



40
41
42
43
# File 'lib/geewiz/client.rb', line 40

def var(name, value)
  command("var", name: name, value: value)
  vars.store name, value
end