ralyxa 1.3.0 → 1.4.0
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 +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +22 -0
- data/lib/ralyxa/card.rb +33 -21
- data/lib/ralyxa/handler.rb +4 -0
- data/lib/ralyxa/request.rb +9 -1
- data/lib/ralyxa/user.rb +21 -0
- data/lib/ralyxa/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6aa4014123fdf96c66aafea914bbf45fc005234d
|
4
|
+
data.tar.gz: 9f61bfe7853045176e0b1fe46d2cb525fd5d1077
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 217f26ef4be39c6e7b80d1666e6d7a9fb5361aeb41e8419e8446a92819ae5b2bd5fb1a3a3ed6f62b17a13171a24d607a810f4847464481480e8680c3528ae1ac
|
7
|
+
data.tar.gz: 5e40b794bd024fb2c8b8306b23bf09a423930fd72f825810bf7616443d920ef5f2120aa2a966dc84376fe85df9bb9045fa0c05286ed7dec873dfb76d2ee7575c
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -91,6 +91,16 @@ intent "ReadFromSession" do
|
|
91
91
|
end
|
92
92
|
```
|
93
93
|
|
94
|
+
##### Reading the session user
|
95
|
+
|
96
|
+
You can read the session user's `userId` and `accessToken`, and check that the `accessToken` exists:
|
97
|
+
|
98
|
+
```ruby
|
99
|
+
request.user_id #=> returns the `userId` value from the request session
|
100
|
+
request.user_access_token # => returns the `accessToken` value from the request session
|
101
|
+
request.user_access_token_exists? # => true if the user has an access token, false if not
|
102
|
+
```
|
103
|
+
|
94
104
|
> Go check out the `Alexa::Request` object to see what else you can do with the `request`.
|
95
105
|
|
96
106
|
##### Ending sessions
|
@@ -143,6 +153,18 @@ end
|
|
143
153
|
|
144
154
|
> Card images must be under 2MB and available at an SSL-enabled (HTTPS) endpoint.
|
145
155
|
|
156
|
+
##### Account Linking
|
157
|
+
|
158
|
+
You can ask Alexa to send a [`LinkAccount`](https://developer.amazon.com/blogs/post/Tx3CX1ETRZZ2NPC/Alexa-Account-Linking-5-Steps-to-Seamlessly-Link-Your-Alexa-Skill-with-Login-wit) card for the user to authenticate via OAuth:
|
159
|
+
|
160
|
+
```ruby
|
161
|
+
intent "SendAccountLinkingCard" do
|
162
|
+
tell("Please authorize via the Alexa app.", card: link_account_card)
|
163
|
+
end
|
164
|
+
```
|
165
|
+
|
166
|
+
After completing authentication, the user's access token is available via `request.user_access_token`. You can check for its existence with `request.user_access_token_exists?`.
|
167
|
+
|
146
168
|
## Development
|
147
169
|
|
148
170
|
After checking out the repo, run `bundle install` to install dependencies. Then, run `rspec` to run the tests. You can also run `irb` for an interactive prompt that will allow you to experiment.
|
data/lib/ralyxa/card.rb
CHANGED
@@ -2,57 +2,69 @@ require_relative './errors'
|
|
2
2
|
|
3
3
|
module Ralyxa
|
4
4
|
class Card
|
5
|
-
|
6
|
-
|
5
|
+
LINK_ACCOUNT_CARD_TYPE = "LinkAccount"
|
6
|
+
SIMPLE_CARD_TYPE = "Simple"
|
7
|
+
STANDARD_CARD_TYPE = "Standard"
|
7
8
|
|
8
|
-
def initialize(
|
9
|
-
@
|
10
|
-
@body = body
|
11
|
-
@image_url = image_url
|
9
|
+
def initialize(options)
|
10
|
+
@options = options
|
12
11
|
end
|
13
12
|
|
14
13
|
def self.as_hash(title, body, image_url = nil)
|
15
|
-
new(title, body, image_url).to_h
|
14
|
+
new(title: title, body: body, image_url: image_url).to_h
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.link_account
|
18
|
+
new(link_account: true).to_h
|
16
19
|
end
|
17
20
|
|
18
21
|
def to_h
|
19
22
|
Hash.new.tap do |card|
|
20
23
|
set_type(card)
|
21
|
-
card[:title]
|
22
|
-
set_body(card)
|
23
|
-
set_image(card) if @image_url
|
24
|
+
set_title(card) if @options[:title]
|
25
|
+
set_body(card) if @options[:body]
|
26
|
+
set_image(card) if @options[:image_url]
|
24
27
|
end
|
25
28
|
end
|
26
29
|
|
27
30
|
private
|
28
31
|
|
29
32
|
def set_type(card)
|
30
|
-
card[:type] =
|
31
|
-
card[:type]
|
33
|
+
return card[:type] = LINK_ACCOUNT_CARD_TYPE if link_account?
|
34
|
+
card[:type] = SIMPLE_CARD_TYPE if simple?
|
35
|
+
card[:type] = STANDARD_CARD_TYPE if standard?
|
36
|
+
end
|
37
|
+
|
38
|
+
def set_title(card)
|
39
|
+
card[:title] = @options[:title]
|
32
40
|
end
|
33
41
|
|
34
42
|
def set_body(card)
|
35
|
-
card[:content] = @body if simple?
|
36
|
-
card[:text] = @body if standard?
|
43
|
+
card[:content] = @options[:body] if simple?
|
44
|
+
card[:text] = @options[:body] if standard?
|
37
45
|
end
|
38
46
|
|
39
47
|
def set_image(card)
|
40
|
-
raise UnsecureUrlError.new("Card images must be available at an SSL-enabled (HTTPS) endpoint. Your current image url is: #{ @image_url }") unless secure?
|
48
|
+
raise UnsecureUrlError.new("Card images must be available at an SSL-enabled (HTTPS) endpoint. Your current image url is: #{ @options[:image_url] }") unless secure?
|
41
49
|
card[:image] = Hash.new
|
42
|
-
card[:image][:smallImageUrl] = @image_url
|
43
|
-
card[:image][:largeImageUrl] = @image_url
|
50
|
+
card[:image][:smallImageUrl] = @options[:image_url]
|
51
|
+
card[:image][:largeImageUrl] = @options[:image_url]
|
52
|
+
end
|
53
|
+
|
54
|
+
def link_account?
|
55
|
+
!!@options[:link_account]
|
44
56
|
end
|
45
57
|
|
46
58
|
def simple?
|
47
|
-
!@image_url
|
59
|
+
!@options[:image_url]
|
48
60
|
end
|
49
61
|
|
50
62
|
def standard?
|
51
|
-
!!@image_url
|
63
|
+
!!@options[:image_url]
|
52
64
|
end
|
53
65
|
|
54
|
-
def secure?
|
55
|
-
URI.parse(
|
66
|
+
def secure?
|
67
|
+
URI.parse(@options[:image_url]).scheme == "https"
|
56
68
|
end
|
57
69
|
end
|
58
70
|
end
|
data/lib/ralyxa/handler.rb
CHANGED
data/lib/ralyxa/request.rb
CHANGED
@@ -1,11 +1,19 @@
|
|
1
1
|
require 'json'
|
2
|
+
require 'forwardable'
|
3
|
+
require_relative './user'
|
2
4
|
|
3
5
|
module Ralyxa
|
4
6
|
class Request
|
7
|
+
extend Forwardable
|
5
8
|
INTENT_REQUEST_TYPE = "IntentRequest".freeze
|
6
9
|
|
7
|
-
|
10
|
+
def_delegator :@user, :id, :user_id
|
11
|
+
def_delegator :@user, :access_token, :user_access_token
|
12
|
+
def_delegator :@user, :access_token_exists?, :user_access_token_exists?
|
13
|
+
|
14
|
+
def initialize(original_request, user_class = Ralyxa::User)
|
8
15
|
@request = JSON.parse(original_request.body.read)
|
16
|
+
@user = user_class.build(@request)
|
9
17
|
end
|
10
18
|
|
11
19
|
def intent_name
|
data/lib/ralyxa/user.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
module Ralyxa
|
2
|
+
class User
|
3
|
+
attr_reader :id, :access_token
|
4
|
+
|
5
|
+
def initialize(id:, access_token: nil)
|
6
|
+
@id = id
|
7
|
+
@access_token = access_token
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.build(request)
|
11
|
+
new(
|
12
|
+
id: request.dig(:session, :user, :userId),
|
13
|
+
access_token: request.dig(:session, :user, :accessToken)
|
14
|
+
)
|
15
|
+
end
|
16
|
+
|
17
|
+
def access_token_exists?
|
18
|
+
!!@access_token
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/ralyxa/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ralyxa
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Morgan
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-05-
|
11
|
+
date: 2017-05-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -80,6 +80,7 @@ files:
|
|
80
80
|
- lib/ralyxa/response.rb
|
81
81
|
- lib/ralyxa/response_builder.rb
|
82
82
|
- lib/ralyxa/skill.rb
|
83
|
+
- lib/ralyxa/user.rb
|
83
84
|
- lib/ralyxa/version.rb
|
84
85
|
- pkg/ralyxa-1.0.0.gem
|
85
86
|
- ralyxa.gemspec
|