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.
@@ -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
@@ -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