geewiz 0.1.1 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d1f5049589b6ab231bba0aab5d7d437da6240845b83d92e2af6e4ad2930d8105
4
- data.tar.gz: dd0b70dcf9b924f46d595bd19bba021dabc5b407f6024f7f009b91d00a4cb2ea
3
+ metadata.gz: 470c2e0206995689b82812d1d2a357e9baf0f818ec89cc27153c597c6e6231cf
4
+ data.tar.gz: 392f167bcfa145c10c67a2c70789041b8dec625283b25f6606a6e3b305326479
5
5
  SHA512:
6
- metadata.gz: 862ddeb1f9b44362af4761bd23796a23aa623ae681a8d44c4e494385ff45d9fd497dfea448d77127aea30716aea66749629281975f4bd7e4d4be7e6254e86d8a
7
- data.tar.gz: ba0beadf1268fe38d63227a8286fc7a9d9d1dbe00cc41790ca2ca1a31f334169ff4bd86dab7a1c48c2b80dac73c24055d72f04e4f08f995a5b1f39079e18c304
6
+ metadata.gz: d52dc1c3183b15bfb9bd1564f3ac7f8b1abeada4d5b5de47fb54a8226a21f48bd171a73803a5a0adad5e8ce681fb61822f331b2035826c21af95081434cc7e0e
7
+ data.tar.gz: 210d522fdb5488dbabfb77cd8896fa09a98851518cdcc193e786550c7cc7a0432d4aea5cfb2c8465a878b3b48d590083a0bb48bc16b3bd012f6d25260eaa5a74
data/README.md CHANGED
@@ -1,32 +1,136 @@
1
1
  # Geewiz
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/geewiz`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
3
+ SDK for interacting with Geewiz. Works with Ruby 2.6 (the version that currently come preinstalled on MacOS) and above.
6
4
 
7
5
  ## Installation
8
6
 
9
- Install the gem and add to the application's Gemfile by executing:
7
+ ### For use with MacOS's system Ruby 2.6.0 using `bundler`
8
+
9
+ To start a new project using MacOS's preinstalled Ruby:
10
+
11
+ Make a new directory for your project
12
+
13
+ ```bash
14
+ mkdir my-new-project
15
+ cd my-new-project
16
+ ```
17
+
18
+ Configure Bundler to use the `vendor/bundle` directory for your gems instead of installing them system wide, which requires root access:
19
+
20
+ ```bash
21
+ bundle config --local path vendor/bundle
22
+
23
+ # Ignore the bundled gems in git
24
+ echo /vendor/ >> .gitignore
25
+ ```
26
+
27
+ Create a new Gemfile
10
28
 
11
- $ bundle add geewiz
29
+ ```bash
30
+ # Make a new Gemfile
31
+ bundle init
12
32
 
13
- If bundler is not being used to manage dependencies, install the gem by executing:
33
+ # Add the gem to the Gemfile
34
+ bundle add geewiz
35
+ ```
36
+
37
+ To use the gem in your project:
38
+
39
+ ```ruby
40
+ require 'bundler/setup'
41
+ require 'geewiz'
42
+
43
+ Geewiz.card "hello-world-card"
44
+ ```
45
+
46
+ ### For most other cases:
47
+
48
+ ```bash
49
+ bundle add geewiz
50
+ ```
51
+
52
+ or
53
+
54
+ ```bash
55
+ gem install geewiz
56
+ ```
14
57
 
15
- $ gem install geewiz
16
58
 
17
59
  ## Usage
18
60
 
19
- TODO: Write usage instructions here
61
+ ### Requiring the gem
62
+
63
+ ```ruby
64
+ require 'bundler/setup' # you may need to require this if you're using bundler
65
+
66
+ require 'geewiz'
67
+ ```
68
+
69
+ ### Showing a card
70
+
71
+ ```ruby
72
+ # show a card with the id "my_card_id"
73
+ result = Geewiz.card :my_card_id
74
+ result = Geewiz.card "another-card-id" # all data going to Geewiz is json encoded, so either symbols or strings are fine
75
+
76
+ # show a card with the id "my_card_id" override `type` and `selectOne` parameters
77
+ result = Geewiz.card :my_card_id, type: "selectOne", items: ["one", "two", "three"]
78
+
79
+ # show a card with no id
80
+ result = Geewiz.card type: "selectOne", items: ["one", "two", "three"]
81
+
82
+ # `vars:` can be used to send variables to Geewiz before showing a card
83
+ # (it's a bit cleaner than using `Geewiz.vars[]=` directly)
84
+ result = Geewiz.card :my_card, vars: { my_var: "my value", another_var: "another value" }
85
+
86
+ # if card doesn't have an input, or you don't need the input:
87
+ Geewiz.card :my_card_without_input
88
+ ```
89
+
90
+ ### Setting a variable
91
+
92
+ ```ruby
93
+ Geewiz.vars[:my_var] = "my value"
94
+ Geewiz.vars['my-var-with-dashes'] = "my value" # strings are fine as variable names
95
+
96
+ # you can use the variables in Ruby
97
+ Geewiz.vars[:username] = load_username_from_db
98
+
99
+ if Geewiz.vars[:username] == 'nicholaides'
100
+ # ...
101
+ end
102
+
103
+ # this also works for setting one variable
104
+ Geewiz.var :my_var, "my value"
105
+ ```
106
+
107
+ ### Setting the title of the app
108
+
109
+ ```ruby
110
+ Geewiz.set title: "my app"
111
+ ```
112
+
113
+ ### Getting user config
114
+
115
+ ```ruby
116
+ config_value = Geewiz.get_user_config :my_key
117
+ ```
20
118
 
21
- ## Development
119
+ ### Using the global client (simplest way to use the gem)
22
120
 
23
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
121
+ ```ruby
122
+ Geewiz.card :my_card_id
123
+ ```
24
124
 
25
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
125
+ ### Using a non-global client (better for testing/mocking)
26
126
 
27
- ## Contributing
127
+ ```ruby
128
+ geewiz = Geewiz::Client.new
28
129
 
29
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/geewiz.
130
+ geewiz.set title: "my app"
131
+ geewiz.vars[:my_var] = "my value"
132
+ result = geewiz.card :my_card_id
133
+ ```
30
134
 
31
135
  ## License
32
136
 
data/lib/geewiz/client.rb CHANGED
@@ -10,27 +10,39 @@ module Geewiz
10
10
  @vars = VarCache.new(self)
11
11
  end
12
12
 
13
- def command(type, **params) = @output.print "@#{[type, params].to_json}\n"
13
+ def command(type, **params)
14
+ @output.print "@#{[type, params].to_json}\n"
15
+ end
14
16
 
15
- def read = @input.readline
17
+ def read
18
+ @input.readline
19
+ end
16
20
 
17
- def read_response = JSON.parse(read)
21
+ def read_response
22
+ JSON.parse(read)
23
+ end
18
24
 
19
- def set(**options) = command("set", **options)
25
+ def set(**options)
26
+ command("set", **options)
27
+ end
20
28
 
21
29
  def card(id = nil, vars: {}, **params)
30
+ if params[:responseFormat] && params[:responseFormat].to_s != "json"
31
+ raise Error, "responseFormat cannot be set to anything other than json"
32
+ end
33
+
22
34
  vars.each { |name, value| var(name, value) }
23
- command "card", **params, **(id ? { id: } : {}), responseFormat: "json"
35
+ command "card", **params, **(id ? { id: id } : {}), responseFormat: "json"
24
36
  read_response
25
37
  end
26
38
 
27
39
  def get_user_config(key)
28
- command "get-user-config", key:, responseFormat: "json"
40
+ command "get-user-config", key: key, responseFormat: "json"
29
41
  read_response
30
42
  end
31
43
 
32
44
  def var(name, value)
33
- command("var", name:, value:)
45
+ command("var", name: name, value: value)
34
46
  vars.store name, value
35
47
  end
36
48
  end
@@ -6,7 +6,9 @@ module Geewiz
6
6
  @vars = {}
7
7
  end
8
8
 
9
- def [](name) = @vars[name.to_s]
9
+ def [](name)
10
+ @vars[name.to_s]
11
+ end
10
12
 
11
13
  def []=(*args)
12
14
  @client.var(*args)
@@ -1,3 +1,3 @@
1
1
  module Geewiz
2
- VERSION = "0.1.1".freeze
2
+ VERSION = "0.1.3".freeze
3
3
  end
data/lib/geewiz.rb CHANGED
@@ -11,17 +11,31 @@ module Geewiz
11
11
 
12
12
  module_function
13
13
 
14
- def initialize_client(...)
15
- @client = Client.new(...)
14
+ def initialize_client(*args, **options)
15
+ @client = Client.new(*args, **options)
16
16
  end
17
17
 
18
- def client(...)
19
- @client ||= initialize_client(...)
18
+ def client(*args, **options)
19
+ @client ||= initialize_client(*args, **options)
20
20
  end
21
21
 
22
- def set(...) = client.set(...)
23
- def card(...) = client.card(...)
24
- def get_user_config(...) = client.get_user_config(...)
25
- def var(...) = client.var(...)
26
- def vars(...) = client.vars(...)
22
+ def set(*args, **options)
23
+ client.set(*args, **options)
24
+ end
25
+
26
+ def card(*args, **options)
27
+ client.card(*args, **options)
28
+ end
29
+
30
+ def get_user_config(*args, **options)
31
+ client.get_user_config(*args, **options)
32
+ end
33
+
34
+ def var(*args, **options)
35
+ client.var(*args, **options)
36
+ end
37
+
38
+ def vars
39
+ client.vars
40
+ end
27
41
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: geewiz
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Nicholaides
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-08-10 00:00:00.000000000 Z
11
+ date: 2024-08-19 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Geewiz SDK for Ruby
14
14
  email:
@@ -17,9 +17,7 @@ executables: []
17
17
  extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
- - LICENSE.txt
21
20
  - README.md
22
- - geewiz.gemspec
23
21
  - lib/geewiz.rb
24
22
  - lib/geewiz/client.rb
25
23
  - lib/geewiz/var_cache.rb
@@ -39,14 +37,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
39
37
  requirements:
40
38
  - - ">="
41
39
  - !ruby/object:Gem::Version
42
- version: 3.1.0
40
+ version: 2.6.0
43
41
  required_rubygems_version: !ruby/object:Gem::Requirement
44
42
  requirements:
45
43
  - - ">="
46
44
  - !ruby/object:Gem::Version
47
45
  version: '0'
48
46
  requirements: []
49
- rubygems_version: 3.3.27
47
+ rubygems_version: 3.5.11
50
48
  signing_key:
51
49
  specification_version: 4
52
50
  summary: Geewiz SDK for Ruby
data/LICENSE.txt DELETED
@@ -1,21 +0,0 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2024 Mike Nicholaides
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in
13
- all copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- THE SOFTWARE.
data/geewiz.gemspec DELETED
@@ -1,38 +0,0 @@
1
- require_relative "lib/geewiz/version"
2
-
3
- Gem::Specification.new do |spec|
4
- spec.name = "geewiz"
5
- spec.version = Geewiz::VERSION
6
- spec.authors = ["Mike Nicholaides"]
7
- spec.email = ["mike@nicholaides.com"]
8
-
9
- spec.summary = "Geewiz SDK for Ruby"
10
- spec.description = "Geewiz SDK for Ruby"
11
- # spec.homepage = "TODO: Put your gem's website or public repo URL here."
12
- spec.license = "MIT"
13
- spec.required_ruby_version = ">= 3.1.0"
14
-
15
- spec.metadata["allowed_push_host"] = "https://rubygems.org"
16
- spec.metadata["rubygems_mfa_required"] = "true"
17
-
18
- # spec.metadata["homepage_uri"] = spec.homepage
19
- # spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
20
- # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
21
-
22
- # Specify which files should be added to the gem when it is released.
23
- # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
24
- spec.files = Dir.chdir(__dir__) do
25
- `git ls-files -z`.split("\x0").reject do |f|
26
- (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
27
- end
28
- end - %w[.rspec .rubocop.yml .rubocop_todo.yml Gemfile Gemfile.lock Rakefile]
29
- spec.bindir = "exe"
30
- spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
31
- spec.require_paths = ["lib"]
32
-
33
- # Uncomment to register a new dependency of your gem
34
- # spec.add_dependency "example-gem", "~> 1.0"
35
-
36
- # For more information and examples about making a new gem, check out our
37
- # guide at: https://bundler.io/guides/creating_gem.html
38
- end