alexa-rails 0.1.7 → 2.0.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/README.md +11 -8
- data/app/views/alexa/output/cards/_simple.json.erb +1 -1
- data/app/views/alexa/permission_consents/device_address.text.erb +5 -1
- data/lib/alexa-rails.rb +14 -2
- data/lib/alexa/configuration.rb +11 -0
- data/lib/alexa/device.rb +14 -18
- data/lib/alexa/request.rb +1 -1
- data/lib/alexa/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 679d2d2731372782d8475c8fc1fd1e34649270aa88a6c5ff47a3a4f9ed2bff11
|
4
|
+
data.tar.gz: 3b2f0968c98fc26e92ce8ece3b519c97115eb562e02903ccfbc56d5e19676df4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c980eca419ad58dafaad43473f953868c49b10d7692fdb81a14c79a978111be27c0ada1123b6c17c401a70788f2083d402b5082e88f2873f22a6520283579be0
|
7
|
+
data.tar.gz: ba6c9e3c01f4be64c4e7891c80457684ad33ad6da2ad515e7cb11815159641e8e10dc0bbb8fe004c428c733d097e7c4b4c886f28651175f9c5fc26d38ccdf52b
|
data/README.md
CHANGED
@@ -22,18 +22,21 @@ $ rake db:migrate
|
|
22
22
|
|
23
23
|
### Configuration
|
24
24
|
|
25
|
-
|
26
|
-
|
25
|
+
Add `config/initializers/alexa.rb` and add the following configuration
|
27
26
|
|
28
27
|
```ruby
|
29
|
-
|
28
|
+
Alexa.configure do |config|
|
29
|
+
# Location permissions type
|
30
|
+
config.location_permission_type = :country_and_postal_code # or full_address
|
30
31
|
|
31
|
-
|
32
|
-
|
33
|
-
"amzn1.ask.skill.xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx"
|
34
|
-
]
|
32
|
+
# Default title used on the display cards for your skill
|
33
|
+
config.default_card_title = "My Alexa skill"
|
35
34
|
|
36
|
-
|
35
|
+
# Add ID of your skills. Used for request verification
|
36
|
+
config.skill_ids = [
|
37
|
+
"amzn1.ask.skill.xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx"
|
38
|
+
]
|
39
|
+
end
|
37
40
|
```
|
38
41
|
|
39
42
|
Mount the engine for routes handling in your routes
|
@@ -1,5 +1,5 @@
|
|
1
1
|
{
|
2
2
|
"type": "Simple",
|
3
|
-
"title": "<%= (content_for(:card_title) ||
|
3
|
+
"title": "<%= (content_for(:card_title) || Alexa.configuration.default_card_title).strip %>",
|
4
4
|
"content": <%= raw content.strip.to_json %>
|
5
5
|
}
|
@@ -3,5 +3,9 @@
|
|
3
3
|
<% end %>
|
4
4
|
|
5
5
|
<% content_for :permissions_scope do %>
|
6
|
-
|
6
|
+
<% if Alexa.configuration.location_permission_type == :country_and_postal_code %>
|
7
|
+
read::alexa:device:all:address:country_and_postal_code
|
8
|
+
<% else %>
|
9
|
+
read::alexa:device:all:address
|
10
|
+
<% end %>
|
7
11
|
<% end %>
|
data/lib/alexa-rails.rb
CHANGED
@@ -6,6 +6,7 @@ require 'alexa/response'
|
|
6
6
|
require 'alexa/session'
|
7
7
|
require 'alexa/slot'
|
8
8
|
require 'alexa/version'
|
9
|
+
require 'alexa/configuration'
|
9
10
|
require 'alexa/responses/bye'
|
10
11
|
require 'alexa/responses/delegate'
|
11
12
|
require 'alexa/responses/permission_consents/device_address'
|
@@ -13,7 +14,18 @@ require 'alexa/intent_handlers/base'
|
|
13
14
|
require_relative '../app/models/alexa/user'
|
14
15
|
require_relative '../app/models/alexa/usage'
|
15
16
|
|
16
|
-
|
17
17
|
module Alexa
|
18
|
-
#
|
18
|
+
# Manage configuration following the pattern from:
|
19
|
+
# https://brandonhilkert.com/blog/ruby-gem-configuration-patterns/
|
20
|
+
class << self
|
21
|
+
attr_writer :configuration
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.configuration
|
25
|
+
@_configuration ||= Alexa::Configuration.new
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.configure
|
29
|
+
yield(configuration)
|
30
|
+
end
|
19
31
|
end
|
data/lib/alexa/device.rb
CHANGED
@@ -28,33 +28,29 @@ module Alexa
|
|
28
28
|
# Makes an API to amazon alexa's device location service and returns the
|
29
29
|
# location hash
|
30
30
|
def location
|
31
|
-
@_location ||=
|
31
|
+
@_location ||= begin
|
32
|
+
if Alexa.configuration.location_permission_type == :full_address
|
33
|
+
get_address
|
34
|
+
elsif Alexa.configuration.location_permission_type == :country_and_postal_code
|
35
|
+
get_address(only: :country_and_postal_code)
|
36
|
+
end
|
37
|
+
end
|
32
38
|
end
|
33
39
|
|
34
40
|
private
|
35
41
|
|
36
|
-
def
|
42
|
+
def get_address(only: nil)
|
37
43
|
url = "#{@context.api_endpoint}/v1/devices/#{id}/settings/address"
|
44
|
+
url = url + "/countryAndPostalCode" if only == :country_and_postal_code
|
38
45
|
conn = Faraday.new(url: url) do |conn|
|
39
|
-
conn.options["open_timeout"] =
|
40
|
-
conn.options["timeout"] =
|
46
|
+
conn.options["open_timeout"] = 20
|
47
|
+
conn.options["timeout"] = 10
|
41
48
|
conn.adapter :net_http
|
42
49
|
conn.headers["Authorization"] = "Bearer #{@context.api_access_token}"
|
43
50
|
end
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
return JSON.parse(resp.body)
|
48
|
-
end
|
49
|
-
rescue Faraday::ConnectionFailed, JSON::ParserError => e
|
50
|
-
Raven.capture_exception(
|
51
|
-
e,
|
52
|
-
extra: {
|
53
|
-
deviceId: id,
|
54
|
-
apiEndPoint: @context.api_endpoint
|
55
|
-
}
|
56
|
-
)
|
57
|
-
return {}
|
51
|
+
resp = conn.get
|
52
|
+
if resp.status == 200
|
53
|
+
return JSON.parse(resp.body)
|
58
54
|
end
|
59
55
|
end
|
60
56
|
end
|
data/lib/alexa/request.rb
CHANGED
data/lib/alexa/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: alexa-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sri Vishnu Totakura
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-07-
|
11
|
+
date: 2018-07-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -72,6 +72,7 @@ files:
|
|
72
72
|
- app/views/layouts/alexa/application.html.erb
|
73
73
|
- config/routes.rb
|
74
74
|
- lib/alexa-rails.rb
|
75
|
+
- lib/alexa/configuration.rb
|
75
76
|
- lib/alexa/context.rb
|
76
77
|
- lib/alexa/device.rb
|
77
78
|
- lib/alexa/engine.rb
|