AmazonEchoJS 0.0.01

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 50dad1e8e3025cbeaae048cbc6013a6a0c3c7801
4
+ data.tar.gz: 1c74553f6bd9ea8554873aea5eb617bb23b87ecd
5
+ SHA512:
6
+ metadata.gz: 5a7f5f11408be5260aac83e3ed692a8fae13ba3746c8c8cb09263434ab23db926b908f02875c2a7a8033ec3e1b19367d6378f54613d83083351b94855926c501
7
+ data.tar.gz: 1305d4721e2a296400dc6b6c3ba9c9936aa15e0a9f2740319ff74ee365e34ef3cdc7d76318d1e97c7116a89bdefce3d4173f3c7543d959c7dd1d3f18dc6274d9
data/.gitignore ADDED
@@ -0,0 +1,16 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+ .gems/
16
+ .rbenv-gemsets
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'AmazonEchoJS/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "AmazonEchoJS"
8
+ spec.version = AmazonEchoJS::VERSION
9
+ spec.authors = ["Kelly Mahan"]
10
+ spec.email = ["kmahan@kmahan.com"]
11
+ spec.summary = %q{AmazonEchoJS is an executable to monitor Amazon echo for voice commands.}
12
+ spec.description = %q{AmazonEchoJS is an executable to monitor Amazon echo for voice commands.}
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 "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ end
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in AmazonEchoJS.gemspec
4
+ gemspec
5
+ gem 'headless'
6
+ # gem 'selenium-webdriver'
7
+ # gem 'watir'
8
+ gem 'watir-webdriver'
9
+ gem 'winker'
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Kelly Mahan
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,37 @@
1
+ # AmazonEchoJS
2
+
3
+ AmazonEchoJS is an executable to monitor Amazon echo for voice commands.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'AmazonEchoJS'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install AmazonEchoJS
20
+
21
+ ## Usage
22
+
23
+ to run echo_monitor you must provide the username, password, and callback url
24
+
25
+ echo_monitor email@domain.com 1234567890 'http://localhost:4567/command'
26
+
27
+ ## Thanks
28
+
29
+ Thanks to Zach Feldmon @zachfeldmon for his original inspiration with his project https://github.com/zachfeldman/alexa-home
30
+
31
+ ## Contributing
32
+
33
+ 1. Fork it ( https://github.com/[my-github-username]/AmazonEchoJS/fork )
34
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
35
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
36
+ 4. Push to the branch (`git push origin my-new-feature`)
37
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'AmazonEchoJS'
5
+
6
+ if ARGV.count!=3
7
+ puts "to run echo_monitor you must provide the username, password, and callback url"
8
+ puts "echo_monitor email@domain.com 1234567890 'http://localhost:4567/command'"
9
+ exit
10
+ end
11
+ echo = AmazonEchoJS::Echo.new(ARGV[0], ARGV[1], ARGV[2])
12
+ puts "Starting up monitor"
13
+ echo.keep_alive
@@ -0,0 +1,12 @@
1
+
2
+ require 'headless'
3
+ #require 'selenium-webdriver'
4
+
5
+
6
+ module AmazonEchoJS
7
+
8
+ end
9
+
10
+
11
+ require "AmazonEchoJS/version"
12
+ require "AmazonEchoJS/echo"
@@ -0,0 +1,109 @@
1
+
2
+ require 'watir-webdriver'
3
+ require "watir-webdriver/wait"
4
+
5
+ module AmazonEchoJS
6
+ class Echo
7
+
8
+ ECHO_URL = 'http://echo.amazon.com/spa/index.html#settings/dialogs'
9
+ REFRESH_TIME_IN_MINUTES = 32
10
+
11
+ attr_accessor :browser, :last_command, :running, :username, :password, :callback_url
12
+
13
+ def initialize(username, password, callback_url)
14
+ @callback_url = callback_url
15
+ @username = username
16
+ @password = password
17
+ @last_command = ""
18
+ @running = true #allows us to enter first keep_alive loop
19
+ #keep_alive
20
+ end
21
+
22
+ def kill
23
+ if @running
24
+ (@browser.close rescue nil) if @browser
25
+ @running = false
26
+ @browser = nil
27
+ end
28
+ end
29
+
30
+ def keep_alive
31
+ while @running
32
+ begin
33
+ kill
34
+ sleep(1)
35
+ open_browser
36
+ start_watcher
37
+ sleep(60*REFRESH_TIME_IN_MINUTES)
38
+ rescue Exception => e
39
+ puts e.message
40
+ ensure
41
+ kill
42
+ puts "Killed browser."
43
+ @running = false
44
+ end
45
+ end
46
+ end
47
+
48
+ def open_browser
49
+ @running = true
50
+
51
+ # was unable to get phantomjs to see ajax updates. This would be the prefered browser to handle headless monitoring.
52
+ # capabilities = Selenium::WebDriver::Remote::Capabilities.phantomjs("phantomjs.page.settings.userAgent" => "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1468.0 Safari/537.36")
53
+ # driver = Selenium::WebDriver.for :phantomjs, :desired_capabilities => capabilities
54
+ # @browser = Watir::Browser.new driver
55
+ @browser = Watir::Browser.new
56
+ @browser.goto ECHO_URL
57
+ Watir::Wait.until { waiting_to_load }
58
+ if @browser.url.match(/www\.amazon\.com\/ap\/signin/)
59
+ login
60
+ end
61
+ end
62
+
63
+ def waiting_to_load
64
+ loaded=false
65
+ timeout = Time.now+30
66
+ while !loaded && Time.now < timeout
67
+ begin
68
+ loaded = @browser.text.include?('History') || @browser.text.include?("Sign in")
69
+ rescue Selenium::WebDriver::Error::NoSuchElementError => e
70
+ puts e.message
71
+ sleep 1
72
+ retry
73
+ rescue Exception => e
74
+ puts e.message
75
+ return false
76
+ end
77
+ sleep 1
78
+ end
79
+ return true
80
+ end
81
+
82
+ def login
83
+ email = @browser.text_field(name: 'email')
84
+ email.wait_until_present
85
+ email.set @username
86
+ @browser.text_field(name: 'password').set @password
87
+ @browser.button(id: "signInSubmit-input").click
88
+ sleep 1
89
+ @browser.goto ECHO_URL
90
+ end
91
+
92
+ def start_watcher
93
+
94
+ Watir::Wait.until { waiting_to_load }
95
+ @browser.execute_script("
96
+ var lastCommand = '"+@last_command+"';
97
+ $(document).ajaxComplete(function(){
98
+ command = $('.dd-title.d-dialog-title').first().text()
99
+ if(lastCommand != command){
100
+ $.get('#{@callback_url}?q='+command)
101
+ lastCommand = command;
102
+ console.log(command);
103
+ }
104
+ })
105
+ ")
106
+ puts "Started Watcher JS."
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,3 @@
1
+ module AmazonEchoJS
2
+ VERSION = "0.0.01"
3
+ end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: AmazonEchoJS
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.01
5
+ platform: ruby
6
+ authors:
7
+ - Kelly Mahan
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-04-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: AmazonEchoJS is an executable to monitor Amazon echo for voice commands.
42
+ email:
43
+ - kmahan@kmahan.com
44
+ executables:
45
+ - echo_monitor.rb
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ".gitignore"
50
+ - AmazonEchoJS.gemspec
51
+ - Gemfile
52
+ - LICENSE.txt
53
+ - README.md
54
+ - Rakefile
55
+ - bin/echo_monitor.rb
56
+ - lib/AmazonEchoJS.rb
57
+ - lib/AmazonEchoJS/echo.rb
58
+ - lib/AmazonEchoJS/version.rb
59
+ homepage: ''
60
+ licenses:
61
+ - MIT
62
+ metadata: {}
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubyforge_project:
79
+ rubygems_version: 2.2.2
80
+ signing_key:
81
+ specification_version: 4
82
+ summary: AmazonEchoJS is an executable to monitor Amazon echo for voice commands.
83
+ test_files: []