alexa_rubykit 0.0.7 → 0.0.9

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9a95151aead793b4d6f509c8c5507bbef7f22528
4
- data.tar.gz: fb349daf3f7a7d333d42ac33bf4be1cab78a81eb
3
+ metadata.gz: 82300a157ad72bda1af4da4ae9eebd461472bd96
4
+ data.tar.gz: 2973c59a6181e768dce7243292a2ae07c8d0aa52
5
5
  SHA512:
6
- metadata.gz: f526deea3336eed5b3a333da266326331547f18f4887c33fb7240e856c0fa6478a2361802f7bc18b8420b74e6c4169781f6e3874e438004ee306a6d9097ad560
7
- data.tar.gz: 03d2474089aa50cbea25df40d77d0d13ef2c504383a05fa8c3a0174aa22c96892acd199f39ec55c792d62be1c7361ff8e109c94d1fe41f526e05a8af48ecf1e9
6
+ metadata.gz: 468b2f0c87bc390ec889b006444d26df73e8d2dc675a8bf592b680f2b31e5be85ec738f8c3725c9aff9d165e3dedaf0c8ec7592ea2a266b6a6f274e4ba461bad
7
+ data.tar.gz: c1f7baf023b9b4af6f34c628de8cc1976e7da7efe47eabcedb079be7ba817c6d2c389518dbb5ec617f5010854934d3e80270daf9733ada407ed55a460f5db67f
data/Gemfile CHANGED
@@ -1,9 +1,4 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in alexa_rubykit.gemspec
4
- #gemspec
5
-
6
- gem "bundler", "~> 1.7"
7
- gem "rake", "~> 10.0"
8
- gem "sinatra", "~> 1.4"
9
- gem 'alexa_rubykit', "~> 0.0.7"
4
+ gemspec
data/Gemfile.lock CHANGED
@@ -1,14 +1,32 @@
1
- GEM
2
- remote: https://rubygems.org/
1
+ PATH
2
+ remote: .
3
3
  specs:
4
- alexa_rubykit (0.0.6)
4
+ alexa_rubykit (0.0.9)
5
5
  bundler (~> 1.7)
6
6
  rake (~> 10.0)
7
7
  sinatra (~> 1.4)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ diff-lcs (1.2.5)
8
13
  rack (1.6.0)
9
14
  rack-protection (1.5.3)
10
15
  rack
11
- rake (10.3.2)
16
+ rake (10.4.2)
17
+ rspec (3.2.0)
18
+ rspec-core (~> 3.2.0)
19
+ rspec-expectations (~> 3.2.0)
20
+ rspec-mocks (~> 3.2.0)
21
+ rspec-core (3.2.3)
22
+ rspec-support (~> 3.2.0)
23
+ rspec-expectations (3.2.1)
24
+ diff-lcs (>= 1.2.0, < 2.0)
25
+ rspec-support (~> 3.2.0)
26
+ rspec-mocks (3.2.1)
27
+ diff-lcs (>= 1.2.0, < 2.0)
28
+ rspec-support (~> 3.2.0)
29
+ rspec-support (3.2.2)
12
30
  sinatra (1.4.6)
13
31
  rack (~> 1.4)
14
32
  rack-protection (~> 1.4)
@@ -19,7 +37,6 @@ PLATFORMS
19
37
  ruby
20
38
 
21
39
  DEPENDENCIES
22
- alexa_rubykit (~> 0.0.6)
23
- bundler (~> 1.7)
24
- rake (~> 10.0)
25
- sinatra (~> 1.4)
40
+ alexa_rubykit!
41
+ rspec (~> 3.2.0)
42
+ rspec-mocks (~> 3.2.0)
data/README.md CHANGED
@@ -1,10 +1,20 @@
1
1
  # AlexaRubykit
2
2
 
3
- This gem implements a quick back-end service for deploying applications for Amazon's Echo (Alexa), the gem,
4
- and samples are provided as-is and are in current development.
3
+ This gem implements a quick back-end service for deploying applications for Amazon's Echo (Alexa).
5
4
 
6
5
  ## Installation
7
6
 
7
+ ### Sample Application
8
+
9
+ For a sample application video tutorial, check
10
+
11
+ <a href="http://www.youtube.com/watch?feature=player_embedded&v=PwZf506UKHo" target="_blank"><img src="http://img.youtube.com/vi/PwZf506UKHo/0.jpg"
12
+ alt="Running a sample Rubykit Demo" width="240" height="180" border="5" /></a>
13
+
14
+ Samples are provided by the alexa_rubyengine project: https://github.com/damianFC/alexa_rubyengine
15
+
16
+ ### For Ruby Projects:
17
+
8
18
  Add this line to your application's Gemfile:
9
19
 
10
20
  ```ruby
@@ -21,16 +31,49 @@ Or install it yourself as:
21
31
 
22
32
  ## Usage
23
33
 
24
- For running the sample "say" application:
25
- * Configure your endpoint for SSL and load the certificate in the developer portal.
26
- * Execute alexa_rubyengine under the bin folder
27
- Sinatra will run in the background and serve a say command when it receives a LoginRequest command from
28
- the Alexa app.
34
+ This Gem provides methods to create and handle request and response objects to be used in your container of choice.
35
+
36
+ Sample usage:
37
+
38
+ ```ruby
39
+ require 'alexa_rubykit'
40
+ response = AlexaRubykit::Response.new
41
+ response.add_speech('Ruby is running ready!')
42
+ response.build_response
43
+ ```
44
+
45
+ Will generate a valid outputspeech response in JSON format:
46
+
47
+ ``` JSON
48
+ $ {"version":"1.0","response":{"outputSpeech":{"type":"PlainText","text":"Ruby is running ready!"},"shouldEndSession":true}}
49
+ ```
50
+
51
+ ## Troubleshooting
52
+
53
+ There are two sources of troubleshooting information: the Amazon Echo app/website and the EBS logs that you can get from
54
+ the management console.
55
+ - "Error in SSL handshake" : Make sure your used the FQDN when you generated the SSL and it's also the active SSL in EBS.
56
+ - "Error communicating with the application" : Query the EBS logs from the management console and create an issue on GitHub.
29
57
 
30
58
  ## Contributing
31
59
 
60
+ 1. Decide to work on the "dev" (unstable) branch or "master" (stable)
32
61
  1. Fork it ( https://github.com/[my-github-username]/alexa_rubykit/fork )
33
62
  2. Create your feature branch (`git checkout -b my-new-feature`)
34
63
  3. Commit your changes (`git commit -am 'Add some feature'`)
35
64
  4. Push to the branch (`git push origin my-new-feature`)
36
65
  5. Create a new Pull Request
66
+
67
+ All development is done in the "dev" branch before being merged to master. Applications can use the developer
68
+ environment by adding the following line to their Gemfile:
69
+
70
+ ```ruby
71
+ gem 'alexa_rubykit', :git => 'https://github.com/damianFC/alexa-rubykit.git', :branch => 'dev'
72
+ ```
73
+
74
+ To use the stable/master branch, rename 'dev' to 'master' or remove :branch all together.
75
+
76
+
77
+
78
+ # <a name="team-members"></a>Team Members
79
+ * "Damian Finol" <damian.finol@gmail.com>
data/lib/alexa_rubykit.rb CHANGED
@@ -1,6 +1,19 @@
1
1
  require 'alexa_rubykit/request'
2
+ require 'alexa_rubykit/version'
3
+ require 'alexa_rubykit/response'
4
+
2
5
  module AlexaRubykit
3
6
  def self.print_json(json)
4
7
  p json
5
8
  end
9
+
10
+ def self.print_version
11
+ p AlexaRubykit::VERSION
12
+ end
13
+
14
+ # Returns true if all the Alexa request objects are set.
15
+ def self.valid_alexa?(request_json)
16
+ !request_json.nil? || !request_json['session'].nil? ||
17
+ !request_json['version'].nil? || !request_json['request'].nil?
18
+ end
6
19
  end
@@ -6,14 +6,15 @@ module AlexaRubykit
6
6
  class Request
7
7
  require 'json'
8
8
  require 'sinatra'
9
- attr_accessor :version, :session_return, :response, :shouldEndSession
9
+ require 'alexa_rubykit'
10
+ attr_accessor :version, :session_return, :response, :shouldEndSession, :type
10
11
 
11
12
  @request = ''
12
13
  @type = ''
13
14
  def initialize(json_request)
14
- halt 500 if json_request.nil?
15
+ halt 500 unless AlexaRubykit.valid_alexa?(json_request)
15
16
  @request = json_request
16
- case @request['type']
17
+ case @request['request']['type']
17
18
  when /Launch/
18
19
  @type = 'LAUNCH'
19
20
  when /Intent/
@@ -24,32 +25,5 @@ module AlexaRubykit
24
25
  halt 500
25
26
  end
26
27
  end
27
-
28
- # Builds a response.
29
- # Takes the version, response and should_end_session variables and builds a JSON object.
30
- def build_response
31
- # Need to set all 3 parameters or the response is invalid
32
- halt 500 if @version.nil? || @response.nil? || @shouldEndSession.nil?
33
- response = Hash.new
34
- response[:version] = @version
35
- response[:sessionAttributes] = @session_return
36
- response[:response] = @response
37
- response.to_json
38
- end
39
-
40
- # Creates a outputspeech JSON object for responding with voice.
41
- # Data type:
42
- #"outputSpeech": {
43
- # "type": "string",
44
- # "text": "string"
45
- #}
46
- def say_response(speech)
47
- output_speech = { :type => 'PlainText', :text => speech }
48
- @response = { :outputSpeech => output_speech, :shouldEndSession => @shouldEndSession }
49
- end
50
-
51
- def add_session(session)
52
- @session_return = { :new => false, :sessionId => session}
53
- end
54
28
  end
55
29
  end
@@ -0,0 +1,66 @@
1
+ module AlexaRubykit
2
+ class Response
3
+ require 'json'
4
+ attr_accessor :version, :session, :response_object, :session_attributes, :speech, :response
5
+
6
+ # Every response needs a shouldendsession and a version attribute
7
+ # We initialize version to 1.0, use add_version to set your own.
8
+ def initialize(version = '1.0')
9
+ @session_attributes = Hash.new
10
+ @version = version
11
+ end
12
+
13
+ # Adds a key,value pair to the session object.
14
+ def add_session_attribute(key, value)
15
+ @session_attributes[key.to_sym] = value
16
+ end
17
+
18
+ def add_speech(speech_text)
19
+ @speech = { :type => 'PlainText', :text => speech_text }
20
+ @speech
21
+ end
22
+
23
+ # Adds a speech to the object, also returns a outputspeech object.
24
+ def say_response(speech, end_session = true)
25
+ output_speech = add_speech(speech)
26
+ { :outputSpeech => output_speech, :shouldEndSession => end_session }
27
+ end
28
+
29
+
30
+ # Creates a session object. We pretty much only use this in testing.
31
+ def build_session
32
+ # If it's empty assume user doesn't need session attributes.
33
+ @session_attributes = Hash.new if @session_attributes.nil?
34
+ @session = { :sessionAttributes => @session_attributes }
35
+ @session
36
+ end
37
+
38
+ # The response object (with outputspeech, cards and session end)
39
+ # Should rename this, but Amazon picked their names.
40
+ # The only mandatory field is end_session which we default to true.
41
+ def build_response_object(session_end = true)
42
+ @response = Hash.new
43
+ @response[:outputSpeech] = @speech unless @speech.nil?
44
+ # TODO: We need cards too
45
+ #response[:card] = @cards
46
+ @response[:shouldEndSession] = session_end
47
+ @response
48
+ end
49
+
50
+ # Builds a response.
51
+ # Takes the version, response and should_end_session variables and builds a JSON object.
52
+ def build_response
53
+ response_object = build_response_object
54
+ response = Hash.new
55
+ response[:version] = @version
56
+ response[:sessionAttributes] = @session_attributes unless @session_attributes.empty?
57
+ response[:response] = response_object
58
+ response.to_json
59
+ end
60
+
61
+ # TODO: Update this.
62
+ def to_s
63
+ "Version => #{@version}, SessionObj => #{@session}, Response => #{@response}"
64
+ end
65
+ end
66
+ end
@@ -1,3 +1,3 @@
1
1
  module AlexaRubykit
2
- VERSION = '0.0.7'
2
+ VERSION = '0.0.9'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alexa_rubykit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Damian Finol
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-25 00:00:00.000000000 Z
11
+ date: 2015-05-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,11 +52,38 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '1.4'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 3.2.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 3.2.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec-mocks
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 3.2.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 3.2.0
55
83
  description: Alexa Ruby Kit with examples
56
84
  email:
57
85
  - damian.finol@gmail.com
58
- executables:
59
- - alexa_rubyengine.rb
86
+ executables: []
60
87
  extensions: []
61
88
  extra_rdoc_files: []
62
89
  files:
@@ -65,12 +92,11 @@ files:
65
92
  - LICENSE.txt
66
93
  - README.md
67
94
  - Rakefile
68
- - bin/alexa_rubyengine.rb
69
- - config.ru
70
95
  - lib/alexa_rubykit.rb
71
96
  - lib/alexa_rubykit/request.rb
97
+ - lib/alexa_rubykit/response.rb
72
98
  - lib/alexa_rubykit/version.rb
73
- homepage: ''
99
+ homepage: https://github.com/damianFC/alexa-rubykit
74
100
  licenses:
75
101
  - MIT
76
102
  metadata: {}
@@ -1,20 +0,0 @@
1
- # Alexa RubyEngine
2
- # This Engine receives and responds to Amazon Echo's (Alexa) JSON requests.
3
- require 'sinatra'
4
- require 'json'
5
- require 'alexa_rubykit'
6
-
7
- #enable :sessions
8
- post '/' do
9
- content_type 'application/json'
10
- # Check that it's a valid Alexa request
11
- request_json = JSON.parse(request.body.read.to_s)
12
- halt 500 if request_json['session'].nil? || request_json['version'].nil? || request_json['request'].nil?
13
- #
14
- request = AlexaRubykit::Request.new(request_json['request'])
15
- request.version = '1.0'
16
- request.add_session(request_json['session']['sessionId'])
17
- request.shouldEndSession = true
18
- request.say_response('Hello, this is a test')
19
- request.build_response
20
- end
data/config.ru DELETED
@@ -1,2 +0,0 @@
1
- require './bin/alexa_rubyengine'
2
- run Sinatra::Application