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
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
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 |
#read ⇒ Object
15 |
# File 'lib/geewiz/client.rb', line 15 def read = @input.readline |
#read_response ⇒ Object
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(**) = command("set", **) |
#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 |