dashed 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/Gemfile +4 -0
- data/LICENSE +21 -0
- data/README.md +23 -0
- data/Rakefile +1 -0
- data/dashed.gemspec +33 -0
- data/lib/dashed/button.rb +51 -0
- data/lib/dashed/version.rb +3 -0
- data/lib/dashed.rb +5 -0
- metadata +98 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: abf6c258a667ad13afa5024a783996c0a33e58ed
|
4
|
+
data.tar.gz: fd2a822b40c71af696495ea180556ad138011070
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 07d65b0d2380e80f0bcee109d8fd3cf2127fd7793421d3c7feda765c631cd4cd098fe0af878586b346d6548f94537551646a0650284fc86540bb3f9a677e525d
|
7
|
+
data.tar.gz: 1fae0fadf682f8191f1b7847ebc03eca01fe551e908f011958d1df81d1183be9ab4f66d86d205b11a12a0c58eb4289bacd7560fd86a35a1861d8a0851a806790
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Justin Kenyon
|
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,23 @@
|
|
1
|
+
# Dashed
|
2
|
+
|
3
|
+
Dashed is a Ruby library for interacting with Amazon Dash button presses.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Just add `dashed` to your gemfile and then run `bundle install`.
|
8
|
+
|
9
|
+
Dashed has to be run with root permissions in order to listen to your network
|
10
|
+
devices to pick up your dash button.
|
11
|
+
|
12
|
+
## Usage
|
13
|
+
|
14
|
+
```
|
15
|
+
Dashed::Button.new("ff:ff:ff:ff:ff", "dummylan0") do
|
16
|
+
puts "I was pressed!"
|
17
|
+
end
|
18
|
+
```
|
19
|
+
|
20
|
+
## Contributing
|
21
|
+
|
22
|
+
Bug reports and pull requests are welcome on GitHub at
|
23
|
+
https://github.com/kenyonj/dashed.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/dashed.gemspec
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'dashed/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "dashed"
|
8
|
+
spec.version = Dashed::VERSION
|
9
|
+
spec.authors = ["Justin Kenyon", "Blake Williams"]
|
10
|
+
spec.email = ["kenyonj@gmail.com", "blake@blakewilliams.me"]
|
11
|
+
|
12
|
+
spec.summary = %q{Library for interacting with Amazon Dash buttons}
|
13
|
+
spec.description = %q{Library for interacting with Amazon Dash buttons}
|
14
|
+
spec.homepage = "https://github.com/kenyonj/dashed"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
18
|
+
# delete this section to allow pushing this gem to any host.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
21
|
+
else
|
22
|
+
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
23
|
+
end
|
24
|
+
|
25
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
|
+
spec.bindir = "exe"
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ["lib"]
|
29
|
+
|
30
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
31
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
32
|
+
spec.add_dependency "pcaprub", "~> 0.12.0"
|
33
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require "pcaprub"
|
2
|
+
require "time"
|
3
|
+
|
4
|
+
module Dashed
|
5
|
+
class Button
|
6
|
+
TIMEOUT = 45
|
7
|
+
SNAPLENGTH = 65535
|
8
|
+
|
9
|
+
attr_accessor :timeout
|
10
|
+
attr_reader :last_press, :mac_address
|
11
|
+
|
12
|
+
def initialize(mac_address, interface, timeout = TIMEOUT)
|
13
|
+
@mac_address = mac_address
|
14
|
+
@interface = interface
|
15
|
+
@timeout = timeout
|
16
|
+
@last_press = nil
|
17
|
+
end
|
18
|
+
|
19
|
+
def on_press
|
20
|
+
capture.each_packet do |packet|
|
21
|
+
sender_mac = parse_arp_sender_mac(packet)
|
22
|
+
if sender_mac == mac_address && !duplicate_arp?
|
23
|
+
@last_press = Time.now
|
24
|
+
yield if block_given?
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def capture
|
32
|
+
return @capture if @capture
|
33
|
+
|
34
|
+
@capture = PCAPRUB::Pcap.open_live(@interface, SNAPLENGTH, true, 0)
|
35
|
+
@capture.setfilter("arp")
|
36
|
+
end
|
37
|
+
|
38
|
+
def duplicate_arp?
|
39
|
+
last_press && (last_press - Time.now).abs < 45
|
40
|
+
end
|
41
|
+
|
42
|
+
def parse_arp_sender_mac(packet)
|
43
|
+
arp = packet.
|
44
|
+
data.
|
45
|
+
unpack("C*").
|
46
|
+
map { |i| i.to_s(16) }.
|
47
|
+
map { |i| if i.length == 1 then "0#{i}" else i end}
|
48
|
+
arp.slice(6, 6).join(":")
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
data/lib/dashed.rb
ADDED
metadata
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dashed
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Justin Kenyon
|
8
|
+
- Blake Williams
|
9
|
+
autorequire:
|
10
|
+
bindir: exe
|
11
|
+
cert_chain: []
|
12
|
+
date: 2015-10-02 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '1.10'
|
21
|
+
type: :development
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '1.10'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rake
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '10.0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '10.0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: pcaprub
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - "~>"
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: 0.12.0
|
49
|
+
type: :runtime
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - "~>"
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: 0.12.0
|
56
|
+
description: Library for interacting with Amazon Dash buttons
|
57
|
+
email:
|
58
|
+
- kenyonj@gmail.com
|
59
|
+
- blake@blakewilliams.me
|
60
|
+
executables: []
|
61
|
+
extensions: []
|
62
|
+
extra_rdoc_files: []
|
63
|
+
files:
|
64
|
+
- ".gitignore"
|
65
|
+
- Gemfile
|
66
|
+
- LICENSE
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- dashed.gemspec
|
70
|
+
- lib/dashed.rb
|
71
|
+
- lib/dashed/button.rb
|
72
|
+
- lib/dashed/version.rb
|
73
|
+
homepage: https://github.com/kenyonj/dashed
|
74
|
+
licenses:
|
75
|
+
- MIT
|
76
|
+
metadata:
|
77
|
+
allowed_push_host: https://rubygems.org
|
78
|
+
post_install_message:
|
79
|
+
rdoc_options: []
|
80
|
+
require_paths:
|
81
|
+
- lib
|
82
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
requirements: []
|
93
|
+
rubyforge_project:
|
94
|
+
rubygems_version: 2.4.5.1
|
95
|
+
signing_key:
|
96
|
+
specification_version: 4
|
97
|
+
summary: Library for interacting with Amazon Dash buttons
|
98
|
+
test_files: []
|