blinkman 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +66 -0
- data/Rakefile +6 -0
- data/blinkman.gemspec +25 -0
- data/lib/blinkman/action.rb +24 -0
- data/lib/blinkman/adapter/base.rb +20 -0
- data/lib/blinkman/adapter/shell.rb +30 -0
- data/lib/blinkman/adapter.rb +15 -0
- data/lib/blinkman/bot.rb +59 -0
- data/lib/blinkman/configurable.rb +34 -0
- data/lib/blinkman/event.rb +11 -0
- data/lib/blinkman/handler.rb +9 -0
- data/lib/blinkman/message/base.rb +14 -0
- data/lib/blinkman/message/shell.rb +9 -0
- data/lib/blinkman/version.rb +3 -0
- data/lib/blinkman.rb +15 -0
- metadata +135 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 031cc2b8460c42863bb3f50fc5d8d0b68e9bf131
|
4
|
+
data.tar.gz: 72d5d17e19e22d80799e44b8de6addc852c22c8e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 98bad2a0d27f668c1423030d9915e973fbbedce3fb591bbb4778974d58ff3738763c9180841d969b3feb22879a9049ea2993210ba45a4414d482c5cc32f64a78
|
7
|
+
data.tar.gz: af006aa0af670fdfad9c56559a19b0da73b8e2876cf11b7d1346563665eac2a7245137d14b5e490fc75d42a0b9f99c781e2dc9a4cb53afb688fe3f816e93cfcc
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
+
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
|
6
|
+
|
7
|
+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
+
|
9
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
+
|
11
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
+
|
13
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Kinoshita.Yasuhiro
|
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/README.md
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
# Blinkman
|
2
|
+
|
3
|
+
Blinkman is DSL for [Blink(1)](https://blink1.thingm.com/)
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'blinkman'
|
11
|
+
```
|
12
|
+
|
13
|
+
Default Blinkman uses commandline interface. If you want to connect other services, add adapter plugin for your Gemfile.
|
14
|
+
ex.
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
gem 'blinkman-slack'
|
18
|
+
```
|
19
|
+
|
20
|
+
And then execute:
|
21
|
+
|
22
|
+
$ bundle install
|
23
|
+
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
Write ruby script file like this:
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
require 'blinkman'
|
31
|
+
|
32
|
+
bot = Blinkman::Bot.new do
|
33
|
+
blink red 2.times, during(250), when_if { message.body == 'hello' }
|
34
|
+
end
|
35
|
+
|
36
|
+
bot.listen
|
37
|
+
```
|
38
|
+
|
39
|
+
and execute:
|
40
|
+
|
41
|
+
$ bundle exec ruby example.rb
|
42
|
+
|
43
|
+
This example uses commandline adapter (default adapter). Type 'hello' in shell then blink blink(1) red twice.
|
44
|
+
|
45
|
+
$ > hello # blink red
|
46
|
+
|
47
|
+
If you want to exit, type 'exit'
|
48
|
+
|
49
|
+
$ > exit
|
50
|
+
|
51
|
+
|
52
|
+
## Development
|
53
|
+
|
54
|
+
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.
|
55
|
+
|
56
|
+
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 tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
57
|
+
|
58
|
+
## Contributing
|
59
|
+
|
60
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/kinoppyd/blinkman. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
|
61
|
+
|
62
|
+
|
63
|
+
## License
|
64
|
+
|
65
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
66
|
+
|
data/Rakefile
ADDED
data/blinkman.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'blinkman/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "blinkman"
|
8
|
+
spec.version = Blinkman::VERSION
|
9
|
+
spec.authors = ["Kinoshita.Yasuhiro"]
|
10
|
+
spec.email = ["WhoIsDissolvedGirl+github@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Blinkman is the DSL for blink(1)}
|
13
|
+
spec.description = %q{Blinkman is the DSL for blink(1)}
|
14
|
+
spec.homepage = ""
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_dependency "rb-blink1", "~> 0.0.7"
|
21
|
+
spec.add_dependency "bundler", "~> 1.10"
|
22
|
+
spec.add_dependency "dotenv", "~> 2.1"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
spec.add_development_dependency "rspec"
|
25
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Blinkman
|
2
|
+
class Action
|
3
|
+
require 'blink1'
|
4
|
+
|
5
|
+
attr_reader :color_code, :times, :during
|
6
|
+
|
7
|
+
def initialize(color_code, times, during = 1000)
|
8
|
+
@color_code = color_code
|
9
|
+
@times = times
|
10
|
+
@during = during
|
11
|
+
end
|
12
|
+
|
13
|
+
def invoke
|
14
|
+
color_code = @color_code
|
15
|
+
times = @times.count.to_i
|
16
|
+
during = @during
|
17
|
+
|
18
|
+
Blink1.open do |blink1|
|
19
|
+
blink1.delay_millis = blink1.millis = during / times
|
20
|
+
blink1.blink(color_code[:r], color_code[:g], color_code[:b], times)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Blinkman
|
2
|
+
module Adapter
|
3
|
+
class Base
|
4
|
+
attr_reader :bot
|
5
|
+
class << self
|
6
|
+
def inherited(klass)
|
7
|
+
Adapter.adapter_classes.push(klass)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def initialize(bot)
|
12
|
+
@bot = bot
|
13
|
+
end
|
14
|
+
|
15
|
+
def listen
|
16
|
+
raise NotImplementedError.new
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Blinkman
|
2
|
+
module Adapter
|
3
|
+
class Shell < Base
|
4
|
+
require 'readline'
|
5
|
+
|
6
|
+
attr_reader :stopped
|
7
|
+
|
8
|
+
PROMPT = '> '
|
9
|
+
|
10
|
+
def initialize(bot)
|
11
|
+
@stopped = false
|
12
|
+
super
|
13
|
+
end
|
14
|
+
|
15
|
+
def listen
|
16
|
+
while ! stopped
|
17
|
+
bot.on_receive(read)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def read
|
22
|
+
Message::Shell.new(
|
23
|
+
Readline.readline(PROMPT, true).tap do |line|
|
24
|
+
@stopped = (line == 'exit')
|
25
|
+
end
|
26
|
+
)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/blinkman/bot.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'dotenv'
|
2
|
+
|
3
|
+
module Blinkman
|
4
|
+
class Bot
|
5
|
+
|
6
|
+
LED_COLORS = {
|
7
|
+
:red => {r: 255, g: 0, b: 0},
|
8
|
+
:green => {r: 0, g: 255, b: 0},
|
9
|
+
:blue => {r: 0, g: 0, b: 255},
|
10
|
+
}
|
11
|
+
|
12
|
+
attr_reader :handlers
|
13
|
+
|
14
|
+
def initialize(&block)
|
15
|
+
Dotenv.load
|
16
|
+
::Bundler.require(:default)
|
17
|
+
@adapter = Adapter.adapter_classes.last.new(self)
|
18
|
+
@handlers = []
|
19
|
+
instance_eval(&block) if block
|
20
|
+
end
|
21
|
+
|
22
|
+
def listen
|
23
|
+
@adapter.listen
|
24
|
+
end
|
25
|
+
|
26
|
+
def on_receive(message)
|
27
|
+
selected_handler = handlers.find { |handler| handler.event.match?(message) }
|
28
|
+
selected_handler.action.invoke if selected_handler
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def blink(handler)
|
34
|
+
@handlers.push(handler)
|
35
|
+
end
|
36
|
+
|
37
|
+
# add methods for each colors
|
38
|
+
LED_COLORS.each_pair do |color_name, color_code|
|
39
|
+
define_method(color_name) do |times, during, event|
|
40
|
+
led(LED_COLORS[__method__.to_sym], times, during, event)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def led(color_code, times, during, event)
|
45
|
+
Handler.new(
|
46
|
+
Action.new(color_code, times, during),
|
47
|
+
event
|
48
|
+
)
|
49
|
+
end
|
50
|
+
|
51
|
+
def during(millisec)
|
52
|
+
millisec
|
53
|
+
end
|
54
|
+
|
55
|
+
def when_if(&block)
|
56
|
+
Event.new(&block)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Blinkman
|
2
|
+
module Configurable
|
3
|
+
|
4
|
+
def initialize(*arg, &block)
|
5
|
+
self.class.class_variable_get(:@@configured_keys).each do |key|
|
6
|
+
upcased_key = key.upcase
|
7
|
+
raise RuntimeError.new("key #{upcased_key} in ENV required") unless ENV.has_key?(upcased_key)
|
8
|
+
end
|
9
|
+
super(*arg, &block)
|
10
|
+
end
|
11
|
+
|
12
|
+
class << self
|
13
|
+
def included(klass)
|
14
|
+
klass.send(:class_variable_set, :@@configured_keys, [])
|
15
|
+
|
16
|
+
class << klass
|
17
|
+
def configure(key, opts = {})
|
18
|
+
opts = { optional: false }.merge(opts)
|
19
|
+
|
20
|
+
if ! opts[:optional]
|
21
|
+
keys = send(:class_variable_get, :@@configured_keys)
|
22
|
+
keys << key
|
23
|
+
send(:class_variable_set, :@@configured_keys, keys)
|
24
|
+
end
|
25
|
+
|
26
|
+
define_method(key.downcase) do
|
27
|
+
ENV[__method__.to_s.upcase]
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/blinkman.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require "blinkman/version"
|
2
|
+
require 'blink1'
|
3
|
+
|
4
|
+
module Blinkman
|
5
|
+
require 'blinkman/bot'
|
6
|
+
require 'blinkman/event'
|
7
|
+
require 'blinkman/action'
|
8
|
+
require 'blinkman/handler'
|
9
|
+
require 'blinkman/adapter'
|
10
|
+
require 'blinkman/adapter/base'
|
11
|
+
require 'blinkman/adapter/shell'
|
12
|
+
require 'blinkman/message/base'
|
13
|
+
require 'blinkman/message/shell'
|
14
|
+
require 'blinkman/configurable'
|
15
|
+
end
|
metadata
ADDED
@@ -0,0 +1,135 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: blinkman
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kinoshita.Yasuhiro
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-05-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rb-blink1
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.0.7
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.0.7
|
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.10'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.10'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: dotenv
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.1'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.1'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: Blinkman is the DSL for blink(1)
|
84
|
+
email:
|
85
|
+
- WhoIsDissolvedGirl+github@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".rspec"
|
92
|
+
- ".travis.yml"
|
93
|
+
- CODE_OF_CONDUCT.md
|
94
|
+
- Gemfile
|
95
|
+
- LICENSE.txt
|
96
|
+
- README.md
|
97
|
+
- Rakefile
|
98
|
+
- blinkman.gemspec
|
99
|
+
- lib/blinkman.rb
|
100
|
+
- lib/blinkman/action.rb
|
101
|
+
- lib/blinkman/adapter.rb
|
102
|
+
- lib/blinkman/adapter/base.rb
|
103
|
+
- lib/blinkman/adapter/shell.rb
|
104
|
+
- lib/blinkman/bot.rb
|
105
|
+
- lib/blinkman/configurable.rb
|
106
|
+
- lib/blinkman/event.rb
|
107
|
+
- lib/blinkman/handler.rb
|
108
|
+
- lib/blinkman/message/base.rb
|
109
|
+
- lib/blinkman/message/shell.rb
|
110
|
+
- lib/blinkman/version.rb
|
111
|
+
homepage: ''
|
112
|
+
licenses:
|
113
|
+
- MIT
|
114
|
+
metadata: {}
|
115
|
+
post_install_message:
|
116
|
+
rdoc_options: []
|
117
|
+
require_paths:
|
118
|
+
- lib
|
119
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - ">="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0'
|
124
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
125
|
+
requirements:
|
126
|
+
- - ">="
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
version: '0'
|
129
|
+
requirements: []
|
130
|
+
rubyforge_project:
|
131
|
+
rubygems_version: 2.4.5
|
132
|
+
signing_key:
|
133
|
+
specification_version: 4
|
134
|
+
summary: Blinkman is the DSL for blink(1)
|
135
|
+
test_files: []
|