amazonecho 1.0.7

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: aa761a052362e5453b8433aa37a807f87f2c22b6
4
+ data.tar.gz: 6877f5ce0da769ecc4e3632ddd74160fab306882
5
+ SHA512:
6
+ metadata.gz: a641f031edd169e68e04b08d0d8f1824a4ae02434c5417c066ed56c46e6f0c15c2f21e9386eb861e9efcf093fddad7013ea601bf230c7f9770c8613b6b53d002
7
+ data.tar.gz: 16d2bff6b808e29eba40ee44bee29371b0d8047367ef6804c3db66c86917b3565f0a1b48f937e603ddf0a0b48b71c8961f74715b3c7fcc5a81360d98bc59c776
@@ -0,0 +1,17 @@
1
+ class AlexaResponder
2
+ def self.alexa_params(params)
3
+ params.permit!
4
+ end
5
+
6
+ def self.responds_to_alexa_requests(params)
7
+ alexa = AmazonEcho.new(AlexaResponder.alexa_params(params))
8
+ AmazonEcho.intention_selector(alexa)
9
+ puts "\n\n\n\n"
10
+ pp alexa.res
11
+ puts "\n\n\n\n"
12
+ alexa.res
13
+ end
14
+ end
15
+
16
+
17
+ require 'pp'
data/lib/amazonecho.rb ADDED
@@ -0,0 +1,82 @@
1
+ class AmazonEcho
2
+ attr_accessor :session_attributes, :response, :res
3
+ attr_reader :app_id, :intent, :session_new, :slots
4
+
5
+ def initialize(args={})
6
+ @app_id = Initializable.app_id(args)
7
+ @session_new = Initializable.session_new(args)
8
+ @intent = Initializable.parse_intent(args)
9
+ @slots = Initializable.slots(args)
10
+ @res = Initializable.build_response(args)
11
+ @session_attributes = Initializable.session_attributes(args)
12
+ end
13
+
14
+
15
+ def session
16
+ self.session_attributes[:session]
17
+ end
18
+
19
+ def self.intention_selector(alexa)
20
+ Responsible.slots_passer(alexa)
21
+ end
22
+
23
+ def self.verify?(id)
24
+ id == ENV['APP_ID']
25
+ end
26
+
27
+ def statement(text)
28
+ self.text(text)
29
+ self.end_session(true)
30
+ self
31
+ end
32
+
33
+ def question(text)
34
+ self.text(text)
35
+ self.end_session(false)
36
+ self.set_session
37
+ self
38
+ end
39
+
40
+ def reprompt(text)
41
+ if Responsible.ssml?(text)
42
+ @res[:response][:reprompt] = {outputSpeech: {type: "SSML", ssml: text}}
43
+ else
44
+ @res[:response][:reprompt] = {outputSpeech: {type: "PlainText", text: text}}
45
+ end
46
+
47
+ self
48
+ end
49
+
50
+
51
+ def card(type, args={})
52
+ card = Cardable.new(type,args)
53
+ @res[:response][:card] = card.build_response
54
+ end
55
+
56
+
57
+ # private
58
+
59
+ def end_session(boolean)
60
+ self.res[:response][:shouldEndSession] = boolean
61
+ end
62
+
63
+ def text(text)
64
+ if Responsible.ssml?(text)
65
+ @res[:response][:outputSpeech] = {type: "SSML", ssml: text}
66
+ else
67
+ @res[:response][:outputSpeech] = {type: "PlainText", text: text}
68
+ end
69
+ self
70
+ end
71
+
72
+ def set_session
73
+ self.session_attributes.each do |key,value|
74
+ @res[:sessionAttributes][:session][key] = value
75
+ end
76
+ end
77
+ end
78
+
79
+ require 'amazonecho/initializable'
80
+ require 'amazonecho/responsible'
81
+ require 'amazonecho/cardable'
82
+ require 'alexa_responder'
@@ -0,0 +1,36 @@
1
+ class AmazonEcho::Cardable
2
+ attr_accessor :type, :title, :content, :text, :small_img, :large_img
3
+ def initialize(type, args={})
4
+ case type
5
+ when "Standard"
6
+ @type = "Standard"
7
+ @title = args.fetch(:title, nil)
8
+ @content = args.fetch(:content, nil)
9
+ @text = args.fetch(:text, nil)
10
+ when "Simple"
11
+ @type = "Simple"
12
+ @title = args.fetch(:title, nil)
13
+ when "LinkAccount"
14
+ @type = "LinkAccount"
15
+ end
16
+ @small_img = args.fetch(:small_img, nil)
17
+ @large_img = args.fetch(:large_img, nil)
18
+ end
19
+
20
+ def build_response
21
+ card = {type: self.type}
22
+ case self.type
23
+ when "Simple"
24
+ unless self.title == nil then card[:title] = self.title end
25
+ unless self.content == nil then card[:content] = self.content end
26
+ unless self.text == nil then card[:text] = self.text end
27
+ when "Standard"
28
+ unless self.title == nil then card[:title] = self.title end
29
+ when "LinkAccount"
30
+ end
31
+ unless self.small_img == nil && self.large_img == nil then card[:image] = {} end
32
+ unless self.small_img == nil then card[:image][:smallImgUrl] = self.small_img end
33
+ unless self.large_img == nil then card[:image][:largeImageUrl] = self.large_img end
34
+ card
35
+ end
36
+ end
@@ -0,0 +1,39 @@
1
+ class AmazonEcho::Initializable
2
+ def self.parse_intent(args)
3
+ output = args[:request][:intent][:name].downcase
4
+ output.slice!("intent")
5
+ output
6
+ end
7
+
8
+
9
+ def self.app_id(args)
10
+ args[:session][:application][:applicationId]
11
+ end
12
+
13
+ def self.session_attributes(args)
14
+ attributes = args[:session][:attributes][:session]
15
+ attributes == nil ? {} : attributes
16
+ end
17
+
18
+ def self.session_new(args)
19
+ args[:session][:attributes]
20
+ end
21
+
22
+ def self.slots(args)
23
+ slots = args[:request][:intent][:slots]
24
+ slots == nil ? [] :
25
+ slots.each_with_object([]) { | (key, value), arr| arr << value["value"]}
26
+ end
27
+
28
+ def self.build_response(args)
29
+ {
30
+ version: args[:version],
31
+ sessionAttributes: {
32
+ session:{}
33
+ },
34
+ response: {
35
+ shouldEndSession: nil
36
+ }
37
+ }
38
+ end
39
+ end
@@ -0,0 +1,33 @@
1
+ class AmazonEcho::Responsible
2
+ def self.ssml?(text)
3
+ text.include?('<speak>') ? true : false
4
+ end
5
+
6
+ def self.slots_passer(alexa)
7
+ slots = alexa.slots
8
+ case slots.length
9
+ when 0
10
+ send("#{alexa.intent}", alexa)
11
+ when 1
12
+ send("#{alexa.intent}", alexa, slots[0])
13
+ when 2
14
+ send("#{alexa.intent}", alexa, slots[0], slots[1])
15
+ when 3
16
+ send("#{alexa.intent}", alexa, slots[0], slots[1], slots[2])
17
+ when 4
18
+ send("#{alexa.intent}", alexa, slots[0], slots[1], slots[2], slots[3])
19
+ when 5
20
+ send("#{alexa.intent}", alexa, slots[0], slots[1], slots[2], slots[3], slots[4])
21
+ when 6
22
+ send("#{alexa.intent}", alexa, slots[0], slots[1], slots[2], slots[3], slots[4], slots[5])
23
+ when 7
24
+ send("#{alexa.intent}", alexa, slots[0], slots[1], slots[2], slots[3], slots[4], slots[5], slots[6])
25
+ when 8
26
+ send("#{alexa.intent}", alexa, slots[0], slots[1], slots[2], slots[3], slots[4], slots[5], slots[6], slots[7])
27
+ when 9
28
+ send("#{alexa.intent}", alexa, slots[0], slots[1], slots[2], slots[3], slots[4], slots[5], slots[6], slots[7], slots[8])
29
+ when 10
30
+ send("#{alexa.intent}", alexa, slots[0], slots[1], slots[2], slots[3], slots[4], slots[5], slots[6], slots[7], slots[8], slots[9])
31
+ end
32
+ end
33
+ end
metadata ADDED
@@ -0,0 +1,48 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: amazonecho
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.7
5
+ platform: ruby
6
+ authors:
7
+ - Matt Weingarten
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-02-24 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Creating Alexa skills made easy
14
+ email: matt@weingarten.org
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/alexa_responder.rb
20
+ - lib/amazonecho.rb
21
+ - lib/amazonecho/cardable.rb
22
+ - lib/amazonecho/initializable.rb
23
+ - lib/amazonecho/responsible.rb
24
+ homepage: https://github.com/mattweingarten/amazonecho
25
+ licenses:
26
+ - MIT
27
+ metadata: {}
28
+ post_install_message:
29
+ rdoc_options: []
30
+ require_paths:
31
+ - lib
32
+ required_ruby_version: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: '0'
37
+ required_rubygems_version: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ requirements: []
43
+ rubyforge_project:
44
+ rubygems_version: 2.5.1
45
+ signing_key:
46
+ specification_version: 4
47
+ summary: Creating Alexa skills made easy
48
+ test_files: []