alexa_ruby 0.2.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +0 -1
- data/Gemfile.lock +24 -21
- data/README.md +26 -14
- data/Rakefile +6 -4
- data/lib/alexa_ruby/alexa.rb +52 -0
- data/lib/alexa_ruby/request/audio_player_request.rb +18 -25
- data/lib/alexa_ruby/request/base_request/context/device.rb +28 -0
- data/lib/alexa_ruby/request/base_request/context/user.rb +28 -0
- data/lib/alexa_ruby/request/base_request/context.rb +45 -0
- data/lib/alexa_ruby/request/base_request/session.rb +60 -0
- data/lib/alexa_ruby/request/base_request.rb +53 -0
- data/lib/alexa_ruby/request/intent_request/slot.rb +28 -11
- data/lib/alexa_ruby/request/intent_request.rb +41 -42
- data/lib/alexa_ruby/request/launch_request.rb +3 -10
- data/lib/alexa_ruby/request/session_ended_request.rb +12 -12
- data/lib/alexa_ruby/response/audio_player.rb +25 -32
- data/lib/alexa_ruby/response/card.rb +67 -12
- data/lib/alexa_ruby/response.rb +155 -127
- data/lib/alexa_ruby/version.rb +1 -1
- data/lib/alexa_ruby.rb +40 -66
- data/spec/request_spec.rb +197 -0
- data/spec/response_spec.rb +201 -0
- data/spec/spec_helper.rb +7 -0
- metadata +57 -19
- data/lib/alexa_ruby/request.rb +0 -28
- data/lib/alexa_ruby/session.rb +0 -55
data/lib/alexa_ruby/request.rb
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
require 'alexa_ruby/session'
|
2
|
-
|
3
|
-
# AlexaRuby implements a back-end service for interaction with Amazon Alexa API
|
4
|
-
module AlexaRuby
|
5
|
-
# Abstract request class
|
6
|
-
class Request
|
7
|
-
attr_accessor :version, :type, :session, :json # global
|
8
|
-
attr_accessor :request_id, :locale # on request
|
9
|
-
|
10
|
-
# Initialize new request object and set object parameters
|
11
|
-
#
|
12
|
-
# @param json [JSON] valid JSON request from Amazon
|
13
|
-
def initialize(json)
|
14
|
-
@request_id = json[:request][:requestId]
|
15
|
-
if @request_id.nil?
|
16
|
-
raise ArgumentError, 'Request ID should exist on all Requests'
|
17
|
-
end
|
18
|
-
@version = json[:version]
|
19
|
-
@locale = json[:request][:locale]
|
20
|
-
@json = json
|
21
|
-
|
22
|
-
return if @type == :audio_player
|
23
|
-
|
24
|
-
# TODO: We probably need better session handling
|
25
|
-
@session = AlexaRuby::Session.new(json[:session])
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
data/lib/alexa_ruby/session.rb
DELETED
@@ -1,55 +0,0 @@
|
|
1
|
-
module AlexaRuby
|
2
|
-
# Class handles the session object in request
|
3
|
-
class Session
|
4
|
-
attr_accessor :new, :session_id, :attributes, :user
|
5
|
-
|
6
|
-
# Initialize new user session
|
7
|
-
#
|
8
|
-
# @param session [JSON] part of json request from Amazon with user session
|
9
|
-
def initialize(session)
|
10
|
-
if session.nil? || session[:new].nil? || session[:sessionId].nil?
|
11
|
-
raise ArgumentError, 'Invalid Session'
|
12
|
-
end
|
13
|
-
|
14
|
-
@new = session[:new]
|
15
|
-
@session_id = session[:sessionId]
|
16
|
-
@attributes = session[:attributes].nil? ? {} : session[:attributes]
|
17
|
-
@user = session[:user]
|
18
|
-
end
|
19
|
-
|
20
|
-
# Is it a new user session?
|
21
|
-
#
|
22
|
-
# @return [Boolean]
|
23
|
-
def new?
|
24
|
-
@new
|
25
|
-
end
|
26
|
-
|
27
|
-
# Is user defined?
|
28
|
-
#
|
29
|
-
# @return [Boolean]
|
30
|
-
def user_defined?
|
31
|
-
!@user.nil? || !@user[:userId].nil?
|
32
|
-
end
|
33
|
-
|
34
|
-
# Get user ID
|
35
|
-
#
|
36
|
-
# @return [String] Amazon user ID
|
37
|
-
def user_id
|
38
|
-
@user[:userId] if @user
|
39
|
-
end
|
40
|
-
|
41
|
-
# Get user access token
|
42
|
-
#
|
43
|
-
# @return [String] Amazon user access token
|
44
|
-
def access_token
|
45
|
-
@user[:accessToken] if @user
|
46
|
-
end
|
47
|
-
|
48
|
-
# Session attributes present?
|
49
|
-
#
|
50
|
-
# @return [Boolean]
|
51
|
-
def attributes?
|
52
|
-
!@attributes.empty?
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|