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



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

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

#command(type, **params) ⇒ Object



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

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

#get_user_config(key) ⇒ Object



27
28
29
30
# File 'lib/geewiz/client.rb', line 27

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

#readObject



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

def read = @input.readline

#read_responseObject



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

def read_response = JSON.parse(read)

#set(**options) ⇒ Object



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

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

#var(name, value) ⇒ Object



32
33
34
35
# File 'lib/geewiz/client.rb', line 32

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