dreaming_god 0.1.1
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 +15 -0
- data/.rspec +2 -0
- data/.rvmrc +1 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +48 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/db/config.yml +21 -0
- data/db/development.sqlite3 +0 -0
- data/db/migrate/20170321162704_create_db_sessions.rb +9 -0
- data/db/migrate/20170322154419_create_db_people.rb +20 -0
- data/db/migrate/20170330032303_create_db_places.rb +28 -0
- data/db/migrate/20170330042636_create_db_things.rb +27 -0
- data/db/schema.rb +85 -0
- data/dreaming_god.gemspec +42 -0
- data/lib/dreaming_god.rb +28 -0
- data/lib/dreaming_god/session.rb +233 -0
- data/lib/dreaming_god/version.rb +3 -0
- metadata +179 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0697114eb0867f9642526ee0b7fafa1f98050e70
|
4
|
+
data.tar.gz: ad7d6fdce2f0555c8b9c1b7a01b00e2304362671
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 903be5a967ab931e1391890b78e72d4937acf82159b116f6d22424fd5187c126cda11240a2bb7743388b63f05bc1404b5807ae3156147913bf3c9ed65bb0802d
|
7
|
+
data.tar.gz: 4db6f6a1415809822a004e6900ceaaf67fd475d7666f4ee03284986f24bd8455772a27d6a5ce4da2ba07a901420e86205b661b982e6ca13ce2e75693da6a48c8
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm use --create ruby-2.2.2@dreaming_god
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Rodney Degracia
|
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,48 @@
|
|
1
|
+
# DreamingGod
|
2
|
+
|
3
|
+
An Alexa skill bridge to a database.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'dreaming_god'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install dreaming_god
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
json = "...JSON received from Amazon"
|
25
|
+
Alexagram.raw_json = json
|
26
|
+
@session = DreamingGod::Session.new(Alexagram.session)
|
27
|
+
@session.imagine(Alexagram.request)
|
28
|
+
```
|
29
|
+
|
30
|
+
You will need to make sure that your database has the same database schema that dreaming_god expects.
|
31
|
+
|
32
|
+
## Development
|
33
|
+
|
34
|
+
Make sure you have installed RVM (Ruby Version Manager) onto your workstation
|
35
|
+
|
36
|
+
After checking out the repo, run `bin/setup` to install dependencies. Set up the database, run `rake db:migrate` Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
37
|
+
|
38
|
+
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).
|
39
|
+
|
40
|
+
## Contributing
|
41
|
+
|
42
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/rdegraci/dreaming_god.
|
43
|
+
|
44
|
+
|
45
|
+
## License
|
46
|
+
|
47
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
48
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "dreaming_god"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/db/config.yml
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
development:
|
2
|
+
adapter: sqlite3
|
3
|
+
database: db/development.sqlite3
|
4
|
+
pool: 5
|
5
|
+
timeout: 5000
|
6
|
+
|
7
|
+
# production:
|
8
|
+
# adapter: mysql
|
9
|
+
# encoding: utf8
|
10
|
+
# reconnect: false
|
11
|
+
# database: somedatabase_dev
|
12
|
+
# pool: 5
|
13
|
+
# username: root
|
14
|
+
# password:
|
15
|
+
# socket: /var/run/mysqld/mysqld.sock
|
16
|
+
|
17
|
+
test: &test
|
18
|
+
adapter: sqlite3
|
19
|
+
database: ':memory:'
|
20
|
+
pool: 5
|
21
|
+
timeout: 5000
|
Binary file
|
@@ -0,0 +1,20 @@
|
|
1
|
+
class CreateDbPeople < ActiveRecord::Migration[5.0]
|
2
|
+
def change
|
3
|
+
create_table :db_people do |t|
|
4
|
+
|
5
|
+
t.string :label #name
|
6
|
+
t.integer :age
|
7
|
+
t.integer :height #inches
|
8
|
+
t.string :hair_color
|
9
|
+
t.string :eye_color
|
10
|
+
t.boolean :alive
|
11
|
+
t.float :weight
|
12
|
+
t.float :mass
|
13
|
+
t.string :gender
|
14
|
+
t.text :description
|
15
|
+
t.string :people_type # human readable type such as man, woman, boy, girl etc
|
16
|
+
|
17
|
+
t.timestamps
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
class CreateDbPlaces < ActiveRecord::Migration[5.0]
|
2
|
+
def change
|
3
|
+
create_table :db_places do |t|
|
4
|
+
|
5
|
+
t.string :label #name
|
6
|
+
t.float :latitude
|
7
|
+
t.float :longitude
|
8
|
+
t.string :zip_code
|
9
|
+
t.string :street_number
|
10
|
+
t.string :street
|
11
|
+
t.float :area # square miles
|
12
|
+
t.boolean :earth
|
13
|
+
t.boolean :space
|
14
|
+
t.string :country
|
15
|
+
t.string :state
|
16
|
+
t.integer :north
|
17
|
+
t.integer :south
|
18
|
+
t.integer :east
|
19
|
+
t.integer :west
|
20
|
+
t.integer :up
|
21
|
+
t.integer :down
|
22
|
+
t.text :description
|
23
|
+
t.string :place_type # human readable type such as city, ocean, street, etc
|
24
|
+
|
25
|
+
t.timestamps
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
class CreateDbThings < ActiveRecord::Migration[5.0]
|
2
|
+
def change
|
3
|
+
create_table :db_things do |t|
|
4
|
+
t.string :label #name
|
5
|
+
t.float :mass
|
6
|
+
t.boolean :edible
|
7
|
+
t.boolean :visible
|
8
|
+
t.boolean :wearable
|
9
|
+
t.boolean :container
|
10
|
+
t.boolean :containable
|
11
|
+
t.boolean :transportable
|
12
|
+
t.boolean :transport
|
13
|
+
t.boolean :platform
|
14
|
+
t.boolean :platformable
|
15
|
+
t.boolean :damageable
|
16
|
+
t.boolean :damager # able to damage
|
17
|
+
t.integer :cost
|
18
|
+
t.boolean :takeable #able to be taken
|
19
|
+
t.boolean :dropable
|
20
|
+
|
21
|
+
t.text :description
|
22
|
+
t.string :thing_type # human readable type such as food, jewel, utensil, etc
|
23
|
+
|
24
|
+
t.timestamps
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/db/schema.rb
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
# This file is auto-generated from the current state of the database. Instead
|
2
|
+
# of editing this file, please use the migrations feature of Active Record to
|
3
|
+
# incrementally modify your database, and then regenerate this schema definition.
|
4
|
+
#
|
5
|
+
# Note that this schema.rb definition is the authoritative source for your
|
6
|
+
# database schema. If you need to create the application database on another
|
7
|
+
# system, you should be using db:schema:load, not running all the migrations
|
8
|
+
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
|
9
|
+
# you'll amass, the slower it'll run and the greater likelihood for issues).
|
10
|
+
#
|
11
|
+
# It's strongly recommended that you check this file into your version control system.
|
12
|
+
|
13
|
+
ActiveRecord::Schema.define(version: 20170330042636) do
|
14
|
+
|
15
|
+
create_table "db_people", force: :cascade do |t|
|
16
|
+
t.string "label"
|
17
|
+
t.integer "age"
|
18
|
+
t.integer "height"
|
19
|
+
t.string "hair_color"
|
20
|
+
t.string "eye_color"
|
21
|
+
t.boolean "alive"
|
22
|
+
t.float "weight"
|
23
|
+
t.float "mass"
|
24
|
+
t.string "gender"
|
25
|
+
t.text "description"
|
26
|
+
t.string "people_type"
|
27
|
+
t.datetime "created_at", null: false
|
28
|
+
t.datetime "updated_at", null: false
|
29
|
+
end
|
30
|
+
|
31
|
+
create_table "db_places", force: :cascade do |t|
|
32
|
+
t.string "label"
|
33
|
+
t.float "latitude"
|
34
|
+
t.float "longitude"
|
35
|
+
t.string "zip_code"
|
36
|
+
t.string "street_number"
|
37
|
+
t.string "street"
|
38
|
+
t.float "area"
|
39
|
+
t.boolean "earth"
|
40
|
+
t.boolean "space"
|
41
|
+
t.string "country"
|
42
|
+
t.string "state"
|
43
|
+
t.integer "north"
|
44
|
+
t.integer "south"
|
45
|
+
t.integer "east"
|
46
|
+
t.integer "west"
|
47
|
+
t.integer "up"
|
48
|
+
t.integer "down"
|
49
|
+
t.text "description"
|
50
|
+
t.string "place_type"
|
51
|
+
t.datetime "created_at", null: false
|
52
|
+
t.datetime "updated_at", null: false
|
53
|
+
end
|
54
|
+
|
55
|
+
create_table "db_sessions", force: :cascade do |t|
|
56
|
+
t.string "sessionId"
|
57
|
+
t.string "userId"
|
58
|
+
t.datetime "created_at", null: false
|
59
|
+
t.datetime "updated_at", null: false
|
60
|
+
end
|
61
|
+
|
62
|
+
create_table "db_things", force: :cascade do |t|
|
63
|
+
t.string "label"
|
64
|
+
t.float "mass"
|
65
|
+
t.boolean "edible"
|
66
|
+
t.boolean "visible"
|
67
|
+
t.boolean "wearable"
|
68
|
+
t.boolean "container"
|
69
|
+
t.boolean "containable"
|
70
|
+
t.boolean "transportable"
|
71
|
+
t.boolean "transport"
|
72
|
+
t.boolean "platform"
|
73
|
+
t.boolean "platformable"
|
74
|
+
t.boolean "damageable"
|
75
|
+
t.boolean "damager"
|
76
|
+
t.integer "cost"
|
77
|
+
t.boolean "takeable"
|
78
|
+
t.boolean "dropable"
|
79
|
+
t.text "description"
|
80
|
+
t.string "thing_type"
|
81
|
+
t.datetime "created_at", null: false
|
82
|
+
t.datetime "updated_at", null: false
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'dreaming_god/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "dreaming_god"
|
8
|
+
spec.version = DreamingGod::VERSION
|
9
|
+
spec.authors = ["Rodney Degracia"]
|
10
|
+
spec.email = ["rdegraci@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{An Alexa voice skill bridge to a database }
|
13
|
+
spec.description = %q{Manipulate a database using Amazon Alexa skill voice commands, eventually to be used to create syllogisms}
|
14
|
+
spec.homepage = "https://www.github.com/rdegraci/dreaming_god"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing 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 " \
|
23
|
+
"public gem pushes."
|
24
|
+
end
|
25
|
+
|
26
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
27
|
+
f.match(%r{^(test|spec|features)/})
|
28
|
+
end
|
29
|
+
spec.bindir = "exe"
|
30
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
31
|
+
spec.require_paths = ["lib"]
|
32
|
+
|
33
|
+
spec.add_development_dependency "bundler", "~> 1.14"
|
34
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
35
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
36
|
+
spec.add_development_dependency "standalone_migrations", "~>5.0"
|
37
|
+
spec.add_development_dependency "sqlite3", "~>1.3"
|
38
|
+
spec.add_development_dependency "database_cleaner", "~>1.5"
|
39
|
+
spec.add_dependency "alexagram", "~>1.0"
|
40
|
+
spec.add_dependency "activerecord", "~>5.0"
|
41
|
+
|
42
|
+
end
|
data/lib/dreaming_god.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require "dreaming_god/version"
|
2
|
+
require "dreaming_god/session"
|
3
|
+
require 'alexagram'
|
4
|
+
require 'active_record'
|
5
|
+
|
6
|
+
|
7
|
+
module DreamingGod
|
8
|
+
@raw_json
|
9
|
+
|
10
|
+
def self.raw_json
|
11
|
+
@raw_json
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
def self.raw_json= json
|
16
|
+
@raw_json = json
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.dream
|
20
|
+
Alexagram.raw_json = @raw_json
|
21
|
+
session = Alexagram.session
|
22
|
+
|
23
|
+
@dream_session = DreamingGod::Session.new(session)
|
24
|
+
@dream_session.imagine(Alexagram.request)
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
end
|
@@ -0,0 +1,233 @@
|
|
1
|
+
module DreamingGod
|
2
|
+
|
3
|
+
class Session
|
4
|
+
|
5
|
+
def initialize session
|
6
|
+
@session = session
|
7
|
+
@db_session = "Db#{self.class.to_s.split(':').last}".constantize.where(:userId => session.userId).first
|
8
|
+
|
9
|
+
if !@db_session
|
10
|
+
dbs = "Db#{self.class.to_s.split(':').last}".constantize.new
|
11
|
+
dbs.sessionId = session.sessionId
|
12
|
+
dbs.userId = session.userId
|
13
|
+
dbs.save!
|
14
|
+
@db_session = dbs
|
15
|
+
@new_flag = true
|
16
|
+
else
|
17
|
+
@new_flag = false
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def imagine request
|
22
|
+
@request = request
|
23
|
+
case @request.type
|
24
|
+
when 'LaunchRequest'
|
25
|
+
# Prepare system
|
26
|
+
card = response_card 'Dreaming God'
|
27
|
+
ssml_response(speak('Greetings User'), card, false)
|
28
|
+
when 'IntentRequest'
|
29
|
+
@intent = Alexagram::Intent.new(@request)
|
30
|
+
intent_name = @intent.name.underscore
|
31
|
+
case intent_name
|
32
|
+
when 'list_rows'
|
33
|
+
table_name = @intent.slots['table']['value'] #people
|
34
|
+
if !table_name
|
35
|
+
result = "What is the name of the table that you want to list?"
|
36
|
+
card = response_card result
|
37
|
+
ssml_response(speak(result), card, false)
|
38
|
+
else
|
39
|
+
names = ""
|
40
|
+
result = "Db#{(table_name.capitalize.singularize)}".constantize.all.limit(3)
|
41
|
+
result.each do |r|
|
42
|
+
names << "#{result.name},"
|
43
|
+
end
|
44
|
+
names = "#{table_name} is empty" if names.length == 0
|
45
|
+
res = "Here is the list of #{table_name}, #{names}"
|
46
|
+
card = response_card res
|
47
|
+
ssml_response(speak(res), card, false)
|
48
|
+
end
|
49
|
+
when 'create_person'
|
50
|
+
result = ""
|
51
|
+
table_name = intent_name.split('_').last.pluralize
|
52
|
+
name = @intent.slots['personname']['value'] #bob
|
53
|
+
person = @intent.slots['person']['value'] #man
|
54
|
+
if !name
|
55
|
+
result = "What was the name of the #{person}"
|
56
|
+
else
|
57
|
+
dbp = "Db#{(table_name.capitalize.singularize)}".constantize.new
|
58
|
+
dbp.label = name
|
59
|
+
dbp.people_type = person
|
60
|
+
dbp.save
|
61
|
+
result = "Ok. #{name} is a #{person}"
|
62
|
+
end
|
63
|
+
card = response_card result
|
64
|
+
ssml_response(speak("#{result}"), card, false)
|
65
|
+
when 'create_place'
|
66
|
+
result = ""
|
67
|
+
table_name = intent_name.split('_').last.pluralize
|
68
|
+
name = @intent.slots['placename']['value'] # bahamas
|
69
|
+
place = @intent.slots['place']['value'] # park
|
70
|
+
if !name
|
71
|
+
result = "What was the name of the #{place}"
|
72
|
+
else
|
73
|
+
dbp = "Db#{(table_name.capitalize.singularize)}".constantize.new
|
74
|
+
dbp.label = name
|
75
|
+
dbp.place_type = place
|
76
|
+
dbp.save
|
77
|
+
result = "Ok. #{name} is a #{place}"
|
78
|
+
end
|
79
|
+
card = response_card result
|
80
|
+
ssml_response(speak("#{result}"), card, false)
|
81
|
+
when 'create_thing'
|
82
|
+
result = ""
|
83
|
+
table_name = intent_name.split('_').last.pluralize
|
84
|
+
name = @intent.slots['thingname']['value'] # bananna
|
85
|
+
thing = @intent.slots['thing']['value'] # vegetable
|
86
|
+
if !name
|
87
|
+
result = "What was the name of the #{thing}"
|
88
|
+
else
|
89
|
+
dbp = "Db#{(table_name.capitalize.singularize)}".constantize.new
|
90
|
+
dbp.label = name
|
91
|
+
dbp.thing_type = thing
|
92
|
+
dbp.save
|
93
|
+
result = "Ok. #{name} is a #{thing}"
|
94
|
+
end
|
95
|
+
card = response_card result
|
96
|
+
ssml_response(speak("#{result}"), card, false)
|
97
|
+
when 'select_row'
|
98
|
+
column_a = @intent.slots['columna']['value'] #all
|
99
|
+
case column_a
|
100
|
+
when 'thing type'
|
101
|
+
column_a = 'thing_type'
|
102
|
+
when 'person type'
|
103
|
+
column_a = 'person_type'
|
104
|
+
when 'place type'
|
105
|
+
column_a = 'place_type'
|
106
|
+
else
|
107
|
+
column_a = (column_a == 'all' ? '*' : "'#{column_a}'")
|
108
|
+
end
|
109
|
+
table_name = @intent.slots['table']['value'] #people
|
110
|
+
column_b = @intent.slots['columnb']['value'] #name
|
111
|
+
compare_value = @intent.slots['comparevalue']['value'] #bob
|
112
|
+
sql_string = "SELECT #{column_a.capitalize} FROM db_#{table_name} WHERE #{column_b} = '#{compare_value}'"
|
113
|
+
result = "Db#{(table_name.capitalize.singularize)}".constantize.find_by_sql(sql_string)
|
114
|
+
names = ""
|
115
|
+
result.each do |r|
|
116
|
+
names << "#{r.send(column_b)}, "
|
117
|
+
end
|
118
|
+
names = "#{table_name} table is empty" if names.length == 0
|
119
|
+
card = response_card 'Dreaming God'
|
120
|
+
ssml_response(speak("I have found the following, #{names}"), card, false)
|
121
|
+
when 'update_row'
|
122
|
+
table_name = @intent.slots['table']['value'] #people
|
123
|
+
column_a = @intent.slots['columna']['value'] #label
|
124
|
+
value_a = @intent.slots['valuea']['value'] #joe
|
125
|
+
column_b = @intent.slots['columnb']['value'] #label
|
126
|
+
compare_value = @intent.slots['comparevalue']['value'] #bob
|
127
|
+
|
128
|
+
case column_a
|
129
|
+
when 'thing type'
|
130
|
+
column_a = 'thing_type'
|
131
|
+
when 'person type'
|
132
|
+
column_a = 'person_type'
|
133
|
+
when 'place type'
|
134
|
+
column_a = 'place_type'
|
135
|
+
else
|
136
|
+
column_a = (column_a == 'all' ? '*' : "'#{column_a}'")
|
137
|
+
end
|
138
|
+
|
139
|
+
sql_string = "UPDATE db_#{table_name} SET #{column_a} = '#{value_a}' WHERE #{column_b} = '#{compare_value}'"
|
140
|
+
result = "Db#{(table_name.capitalize.singularize)}".constantize.find_by_sql(sql_string)
|
141
|
+
res = "I have updated the database where #{column_b} is equal to #{compare_value}"
|
142
|
+
card = response_card res
|
143
|
+
ssml_response(speak(res), card, false)
|
144
|
+
when 'destroy_row'
|
145
|
+
table_name = @intent.slots['table']['value'] #people
|
146
|
+
column = @intent.slots['column']['value'] #label
|
147
|
+
compare_value = @intent.slots['comparevalue']['value'] #bob
|
148
|
+
|
149
|
+
case column
|
150
|
+
when 'thing type'
|
151
|
+
column = 'thing_type'
|
152
|
+
when 'person type'
|
153
|
+
column = 'person_type'
|
154
|
+
when 'place type'
|
155
|
+
column = 'place_type'
|
156
|
+
else
|
157
|
+
column = (column == 'all' ? '*' : "'#{column}'")
|
158
|
+
end
|
159
|
+
|
160
|
+
sql_string = "DELETE FROM db_#{table_name} where #{column} = '#{compare_value}'"
|
161
|
+
"Db#{(table_name.capitalize.singularize)}".constantize.find_by_sql(sql_string)
|
162
|
+
res = "I have destroyed rows from the database where #{column} is equal to #{compare_value}"
|
163
|
+
card = response_card res
|
164
|
+
ssml_response(speak(res), card, false)
|
165
|
+
else
|
166
|
+
end
|
167
|
+
|
168
|
+
when 'SessionEndedRequest'
|
169
|
+
DbSession.detroy(@db_session.id.to_i)
|
170
|
+
result = "End of line"
|
171
|
+
card = response_card result
|
172
|
+
ssml_response(speak(result), card, true)
|
173
|
+
else
|
174
|
+
#
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
|
179
|
+
def is_new?
|
180
|
+
@new_flag
|
181
|
+
end
|
182
|
+
|
183
|
+
|
184
|
+
def ssml_response(text, card, end_session=true)
|
185
|
+
r = {
|
186
|
+
"version" => "1.0",
|
187
|
+
"sessionAttributes" => { },
|
188
|
+
"response" => {
|
189
|
+
"outputSpeech" => {
|
190
|
+
"type" => "SSML",
|
191
|
+
"ssml" => text
|
192
|
+
},
|
193
|
+
"shouldEndSession" => end_session
|
194
|
+
}
|
195
|
+
}
|
196
|
+
r["response"]["card"] = card if card
|
197
|
+
r.as_json
|
198
|
+
end
|
199
|
+
|
200
|
+
def response_card text=nil
|
201
|
+
{
|
202
|
+
"type" => "Simple",
|
203
|
+
"title" => "Minerva Database",
|
204
|
+
"content" => "#{text ||= 'Hello World'}"
|
205
|
+
}
|
206
|
+
end
|
207
|
+
|
208
|
+
# somesite.com/file.mp3
|
209
|
+
def audio url
|
210
|
+
"<audio src=\"https://#{url}\" />"
|
211
|
+
end
|
212
|
+
|
213
|
+
# => 3s
|
214
|
+
def break length
|
215
|
+
"<break time=\"#{length}\"/> "
|
216
|
+
end
|
217
|
+
|
218
|
+
def paragraph text
|
219
|
+
"<p>#{text}</p>"
|
220
|
+
end
|
221
|
+
|
222
|
+
def sentence text
|
223
|
+
"<s>#{text}</s>"
|
224
|
+
end
|
225
|
+
|
226
|
+
|
227
|
+
def speak text
|
228
|
+
"<speak>#{text}</speak>"
|
229
|
+
end
|
230
|
+
|
231
|
+
end
|
232
|
+
|
233
|
+
end
|
metadata
ADDED
@@ -0,0 +1,179 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dreaming_god
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Rodney Degracia
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-03-30 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.14'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.14'
|
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
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: standalone_migrations
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '5.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '5.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: sqlite3
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.3'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.3'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: database_cleaner
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1.5'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '1.5'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: alexagram
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '1.0'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '1.0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: activerecord
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '5.0'
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '5.0'
|
125
|
+
description: Manipulate a database using Amazon Alexa skill voice commands, eventually
|
126
|
+
to be used to create syllogisms
|
127
|
+
email:
|
128
|
+
- rdegraci@gmail.com
|
129
|
+
executables: []
|
130
|
+
extensions: []
|
131
|
+
extra_rdoc_files: []
|
132
|
+
files:
|
133
|
+
- ".gitignore"
|
134
|
+
- ".rspec"
|
135
|
+
- ".rvmrc"
|
136
|
+
- ".travis.yml"
|
137
|
+
- Gemfile
|
138
|
+
- LICENSE.txt
|
139
|
+
- README.md
|
140
|
+
- Rakefile
|
141
|
+
- bin/console
|
142
|
+
- bin/setup
|
143
|
+
- db/config.yml
|
144
|
+
- db/development.sqlite3
|
145
|
+
- db/migrate/20170321162704_create_db_sessions.rb
|
146
|
+
- db/migrate/20170322154419_create_db_people.rb
|
147
|
+
- db/migrate/20170330032303_create_db_places.rb
|
148
|
+
- db/migrate/20170330042636_create_db_things.rb
|
149
|
+
- db/schema.rb
|
150
|
+
- dreaming_god.gemspec
|
151
|
+
- lib/dreaming_god.rb
|
152
|
+
- lib/dreaming_god/session.rb
|
153
|
+
- lib/dreaming_god/version.rb
|
154
|
+
homepage: https://www.github.com/rdegraci/dreaming_god
|
155
|
+
licenses:
|
156
|
+
- MIT
|
157
|
+
metadata:
|
158
|
+
allowed_push_host: https://rubygems.org
|
159
|
+
post_install_message:
|
160
|
+
rdoc_options: []
|
161
|
+
require_paths:
|
162
|
+
- lib
|
163
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
164
|
+
requirements:
|
165
|
+
- - ">="
|
166
|
+
- !ruby/object:Gem::Version
|
167
|
+
version: '0'
|
168
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
169
|
+
requirements:
|
170
|
+
- - ">="
|
171
|
+
- !ruby/object:Gem::Version
|
172
|
+
version: '0'
|
173
|
+
requirements: []
|
174
|
+
rubyforge_project:
|
175
|
+
rubygems_version: 2.4.8
|
176
|
+
signing_key:
|
177
|
+
specification_version: 4
|
178
|
+
summary: An Alexa voice skill bridge to a database
|
179
|
+
test_files: []
|