Class: Geewiz::Client
- Inherits:
-
Object
- Object
- Geewiz::Client
- Defined in:
- lib/geewiz/client.rb
Overview
Client class for interacting with Geewiz.
Instance Attribute Summary collapse
-
#vars ⇒ Object
readonly
Returns the value of attribute vars.
Instance Method Summary collapse
- #card(id = nil, vars: {}, **params) ⇒ Object
- #command(type, **params) ⇒ Object
- #get_user_config(key) ⇒ Object
-
#initialize(input: $stdin, output: $stdout) ⇒ Client
constructor
A new instance of Client.
- #read ⇒ Object
- #read_response ⇒ Object
- #set(**options) ⇒ Object
- #var(name, value) ⇒ Object
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
#vars ⇒ Object (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 |
#read ⇒ Object
17 18 19 |
# File 'lib/geewiz/client.rb', line 17 def read @input.readline end |
#read_response ⇒ Object
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(**) command("set", **) 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 |