nibble 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f406c14b2c4986e07f3335d4f223a13f697441dc
4
+ data.tar.gz: 45329f76c3f3541886a1390e0f833e16ed307f25
5
+ SHA512:
6
+ metadata.gz: 6edc86abf32569ea4b1dfd4cdad2688f484546be71522acef13adf09de635e88ada1e90296436d8c9f805ac1ba060cba1af691ef8c52eeeea0de6e024274a3a2
7
+ data.tar.gz: 3d2977614b6f59cc05284e7911fe7ff739d910697837d4858223600b524dd9fab24efc479791f78891dde53a224e134271849f819ded37b3b73a37b9e6c8deee
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ *.bundle
10
+ *.so
11
+ *.o
12
+ *.a
13
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in nibble.gemspec
4
+ gemspec
5
+
6
+ gem "pry"
7
+ gem "pry-nav"
data/Gemfile.lock ADDED
@@ -0,0 +1,46 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ nibble (0.0.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ coderay (1.1.0)
10
+ diff-lcs (1.2.5)
11
+ faraday (0.9.0)
12
+ multipart-post (>= 1.2, < 3)
13
+ method_source (0.8.2)
14
+ multipart-post (2.0.0)
15
+ pry (0.10.1)
16
+ coderay (~> 1.1.0)
17
+ method_source (~> 0.8.1)
18
+ slop (~> 3.4)
19
+ pry-nav (0.2.4)
20
+ pry (>= 0.9.10, < 0.11.0)
21
+ rake (10.4.2)
22
+ rspec (3.1.0)
23
+ rspec-core (~> 3.1.0)
24
+ rspec-expectations (~> 3.1.0)
25
+ rspec-mocks (~> 3.1.0)
26
+ rspec-core (3.1.7)
27
+ rspec-support (~> 3.1.0)
28
+ rspec-expectations (3.1.2)
29
+ diff-lcs (>= 1.2.0, < 2.0)
30
+ rspec-support (~> 3.1.0)
31
+ rspec-mocks (3.1.3)
32
+ rspec-support (~> 3.1.0)
33
+ rspec-support (3.1.2)
34
+ slop (3.6.0)
35
+
36
+ PLATFORMS
37
+ ruby
38
+
39
+ DEPENDENCIES
40
+ bundler (~> 1.7)
41
+ faraday (~> 0.9)
42
+ nibble!
43
+ pry
44
+ pry-nav
45
+ rake (~> 10.0)
46
+ rspec (~> 3.0)
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 phoet
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # Nibble
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'nibble'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install nibble
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/[my-github-username]/nibble/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/bin/nibble ADDED
@@ -0,0 +1,5 @@
1
+ #! /usr/bin/env ruby
2
+ $:.unshift(File.expand_path('../lib', File.dirname(__FILE__)))
3
+
4
+ require 'nibble'
5
+ Nibble.run(ARGV)
data/examples/admin.rb ADDED
@@ -0,0 +1,6 @@
1
+ puts get_version
2
+ puts status
3
+ puts display_cache
4
+ puts clear_cache
5
+ puts sleep
6
+ puts wakeup
@@ -0,0 +1,5 @@
1
+ ---
2
+ :connection:
3
+ :ip: 10.0.1.200
4
+ :ttl:
5
+ :voice: andreas
data/examples/ears.rb ADDED
@@ -0,0 +1,8 @@
1
+ 5.times do
2
+ ears left: Kernel.rand(0..10), right: Kernel.rand(0..10)
3
+ Kernel.sleep(2)
4
+ end
5
+
6
+ ears_random
7
+ Kernel.sleep(2)
8
+ ears_reset
data/examples/leds.rb ADDED
@@ -0,0 +1,8 @@
1
+ colors = %w(FF0000 00FF00 0000FF FFFF00 00FFFF FF00FF)
2
+
3
+ colors.each do |color|
4
+ leds color: color, pulse: 1, speed: Kernel.rand(300..1500)
5
+ Kernel.sleep 2
6
+ end
7
+
8
+ leds
data/examples/sound.rb ADDED
@@ -0,0 +1,12 @@
1
+ # sound_list['sounds'].shuffle.first(3).each do |sound|
2
+ # sound(id: sound['id'])
3
+ # end
4
+
5
+ puts sound url: 'http://streaming.radio.rtl.fr/rtl-1-44-96'
6
+
7
+ Kernel.sleep 30
8
+ sound_control cmd: 'pause'
9
+ Kernel.sleep 5
10
+ sound_control cmd: 'pause'
11
+ Kernel.sleep 5
12
+ sound_control cmd: 'quit'
data/examples/tts.rb ADDED
@@ -0,0 +1,14 @@
1
+ voice_list['voices'].each do |mapping|
2
+ case mapping['lang']
3
+ when 'fr', 'ca', 'be'
4
+ say "bonjour je m'apelle #{mapping['id']}", voice: mapping['id']
5
+ when 'de'
6
+ say "hallo, ich heiße #{mapping['id']}", voice: mapping['id']
7
+ when 'us', 'uk'
8
+ say "hi, my name is #{mapping['id']}", voice: mapping['id']
9
+ when 'it'
10
+ say "ciao, mi chiamo #{mapping['id']}", voice: mapping['id']
11
+ else
12
+ say "my name is #{mapping['id']} and this is #{mapping['lang']}"
13
+ end
14
+ end
data/lib/nibble.rb ADDED
@@ -0,0 +1,20 @@
1
+ require "nibble/version"
2
+ require "nibble/config"
3
+ require "nibble/client"
4
+
5
+ module Nibble
6
+ def self.run(args)
7
+ abort("usage: #{__FILE__} --generate-config OR config.yml script.rb") if args.size < 1
8
+
9
+ if ARGV.first == "--generate-config"
10
+ Config.dump
11
+ else
12
+ Config.load(args.first)
13
+
14
+ script = File.read(args.last)
15
+
16
+ client = Client.new
17
+ client.instance_eval(script)
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,32 @@
1
+ require "json"
2
+ require "faraday"
3
+
4
+ module Nibble
5
+ class Client
6
+ def initialize
7
+ @conn = Faraday.new(url: "http://#{Config[:connection][:ip]}") do |faraday|
8
+ faraday.request(:url_encoded)
9
+ faraday.response(:logger)
10
+ faraday.adapter(Faraday.default_adapter)
11
+ end
12
+ end
13
+
14
+ METHODS = %i(leds tts ears ears_mode ears_random ears_reset squeezebox radio_list sound_list sound sound_control wakeup sleep get_version status voice_list display_cache clear_cache)
15
+ METHODS.each do |method|
16
+ define_method(method) do |*args|
17
+ options = args.first || {}
18
+ options = (Config.defaults[method] || {}).merge(options)
19
+ execute(method, options)
20
+ end
21
+ end
22
+
23
+ def say(text, options = {})
24
+ tts(options.merge(text: text))
25
+ end
26
+
27
+ def execute(method, options = {})
28
+ response = @conn.get("/cgi-bin/#{method}", options)
29
+ JSON.parse(response.body)
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,43 @@
1
+ require "yaml"
2
+
3
+ module Nibble
4
+ class Config
5
+ def self.dump(path = "config.yml")
6
+ File.open(path, 'w') do |f|
7
+ puts "writing defaults to #{File.absolute_path(f)}"
8
+
9
+ f.write(YAML.dump(defaults))
10
+ end
11
+ end
12
+
13
+ def self.load(path)
14
+ @config = deep_merge(defaults, YAML.load(File.read(path)))
15
+ end
16
+
17
+ def self.defaults
18
+ {
19
+ connection: {ip: "10.0.1.200"},
20
+ wakeup: {silent: 0},
21
+ ttl: {voice: "andreas", nocache: 0, mute: 0},
22
+ leds: {color: "00FF00", color2: "00FF00", pulse: 0, speed: 700, no_memory: 0},
23
+ ears: {noreset: 1, left: 0, right: 0},
24
+ }
25
+ end
26
+
27
+ def self.[](key)
28
+ @config[key]
29
+ end
30
+
31
+ def self.deep_merge(target, hash)
32
+ hash.keys.each do |key|
33
+ if hash[key].is_a? Hash and target[key].is_a? Hash
34
+ target[key] = deep_merge(target[key], hash[key])
35
+ next
36
+ end
37
+
38
+ target[key] = hash[key]
39
+ end
40
+ target
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,3 @@
1
+ module Nibble
2
+ VERSION = "0.0.1"
3
+ end
data/nibble.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'nibble/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "nibble"
8
+ spec.version = Nibble::VERSION
9
+ spec.authors = ["phoet"]
10
+ spec.email = ["phoetmail@googlemail.com"]
11
+ spec.summary = %q{OpenKarotz ruby bindings}
12
+ spec.description = spec.summary
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "faraday", "~> 0.9"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.7"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "rspec", "~> 3.0"
26
+ end
@@ -0,0 +1,89 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause this
4
+ # file to always be loaded, without a need to explicitly require it in any files.
5
+ #
6
+ # Given that it is always loaded, you are encouraged to keep this file as
7
+ # light-weight as possible. Requiring heavyweight dependencies from this file
8
+ # will add to the boot time of your test suite on EVERY test run, even for an
9
+ # individual file that may not need all of that loaded. Instead, consider making
10
+ # a separate helper file that requires the additional dependencies and performs
11
+ # the additional setup, and require it from the spec files that actually need it.
12
+ #
13
+ # The `.rspec` file also contains a few flags that are not defaults but that
14
+ # users commonly want.
15
+ #
16
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
17
+ RSpec.configure do |config|
18
+ # rspec-expectations config goes here. You can use an alternate
19
+ # assertion/expectation library such as wrong or the stdlib/minitest
20
+ # assertions if you prefer.
21
+ config.expect_with :rspec do |expectations|
22
+ # This option will default to `true` in RSpec 4. It makes the `description`
23
+ # and `failure_message` of custom matchers include text for helper methods
24
+ # defined using `chain`, e.g.:
25
+ # be_bigger_than(2).and_smaller_than(4).description
26
+ # # => "be bigger than 2 and smaller than 4"
27
+ # ...rather than:
28
+ # # => "be bigger than 2"
29
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
30
+ end
31
+
32
+ # rspec-mocks config goes here. You can use an alternate test double
33
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
34
+ config.mock_with :rspec do |mocks|
35
+ # Prevents you from mocking or stubbing a method that does not exist on
36
+ # a real object. This is generally recommended, and will default to
37
+ # `true` in RSpec 4.
38
+ mocks.verify_partial_doubles = true
39
+ end
40
+
41
+ # The settings below are suggested to provide a good initial experience
42
+ # with RSpec, but feel free to customize to your heart's content.
43
+ =begin
44
+ # These two settings work together to allow you to limit a spec run
45
+ # to individual examples or groups you care about by tagging them with
46
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
47
+ # get run.
48
+ config.filter_run :focus
49
+ config.run_all_when_everything_filtered = true
50
+
51
+ # Limits the available syntax to the non-monkey patched syntax that is recommended.
52
+ # For more details, see:
53
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
54
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
55
+ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
56
+ config.disable_monkey_patching!
57
+
58
+ # This setting enables warnings. It's recommended, but in some cases may
59
+ # be too noisy due to issues in dependencies.
60
+ config.warnings = true
61
+
62
+ # Many RSpec users commonly either run the entire suite or an individual
63
+ # file, and it's useful to allow more verbose output when running an
64
+ # individual spec file.
65
+ if config.files_to_run.one?
66
+ # Use the documentation formatter for detailed output,
67
+ # unless a formatter has already been configured
68
+ # (e.g. via a command-line flag).
69
+ config.default_formatter = 'doc'
70
+ end
71
+
72
+ # Print the 10 slowest examples and example groups at the
73
+ # end of the spec run, to help surface which specs are running
74
+ # particularly slow.
75
+ config.profile_examples = 10
76
+
77
+ # Run specs in random order to surface order dependencies. If you find an
78
+ # order dependency and want to debug it, you can fix the order by providing
79
+ # the seed, which is printed after each run.
80
+ # --seed 1234
81
+ config.order = :random
82
+
83
+ # Seed global randomization in this process using the `--seed` CLI option.
84
+ # Setting this allows you to use `--seed` to deterministically reproduce
85
+ # test failures related to randomization by passing the same `--seed` value
86
+ # as the one that triggered the failure.
87
+ Kernel.srand config.seed
88
+ =end
89
+ end
metadata ADDED
@@ -0,0 +1,122 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nibble
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - phoet
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-12-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.9'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.9'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.7'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ description: OpenKarotz ruby bindings
70
+ email:
71
+ - phoetmail@googlemail.com
72
+ executables:
73
+ - nibble
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - ".rspec"
79
+ - Gemfile
80
+ - Gemfile.lock
81
+ - LICENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - bin/nibble
85
+ - examples/admin.rb
86
+ - examples/config.yml
87
+ - examples/ears.rb
88
+ - examples/leds.rb
89
+ - examples/sound.rb
90
+ - examples/tts.rb
91
+ - lib/nibble.rb
92
+ - lib/nibble/client.rb
93
+ - lib/nibble/config.rb
94
+ - lib/nibble/version.rb
95
+ - nibble.gemspec
96
+ - spec/spec_helper.rb
97
+ homepage: ''
98
+ licenses:
99
+ - MIT
100
+ metadata: {}
101
+ post_install_message:
102
+ rdoc_options: []
103
+ require_paths:
104
+ - lib
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ requirements: []
116
+ rubyforge_project:
117
+ rubygems_version: 2.2.2
118
+ signing_key:
119
+ specification_version: 4
120
+ summary: OpenKarotz ruby bindings
121
+ test_files:
122
+ - spec/spec_helper.rb